/* 1. CSS Variables (Design System) */
:root {
    /* Colors */
    --color-primary: #3498db;
    --color-success: #2ecc71;
    --color-error: #e74c3c;
    --color-bg-main: #f0f2f5;
    --color-bg-panel: #ffffff;
    --color-text-primary: #333333;
    --color-text-secondary: #666666;
    --color-border: #dee2e6;
    --color-debug-bg: #1e1e1e;
    --color-debug-text: #d4d4d4;

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;

    /* Typography */
    --font-family-base: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    --font-size-xs: 0.75rem;
    /* 12px */
    --font-size-sm: 0.875rem;
    /* 14px */
    --font-size-base: 1rem;
    /* 16px */
    --font-size-lg: 1.25rem;
    /* 20px */
    --font-size-xl: 2.5rem;
    /* 40px */

    /* Layout */
    --panel-left-width: 200px;
    --panel-right-width: 280px;
    --header-height: 40px;
    --status-bar-height: 30px;

    /* Borders */
    --border-radius-sm: 4px;
    --border-radius-md: 6px;
    --box-shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);

    /* Animations */
    --transition-base: 200ms ease-in-out;
}

/* 2. Global Resets & Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
}

body {
    font-family: var(--font-family-base);
    background-color: var(--color-bg-main);
    color: var(--color-text-primary);
    font-size: var(--font-size-sm);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* 3. Main Layout */
.app-header {
    height: var(--header-height);
    background-color: var(--color-bg-panel);
    box-shadow: var(--box-shadow-sm);
    padding: 0 var(--spacing-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    z-index: 10;
}

.app-main {
    flex-grow: 1;
    display: grid;
    grid-template-columns: var(--panel-left-width) 1fr var(--panel-right-width);
    gap: var(--spacing-sm);
    padding: var(--spacing-sm);
    min-height: 0;
    /* Crucial for child scrolling */
}

.status-bar {
    height: var(--status-bar-height);
    background-color: #2c3e50;
    color: white;
    padding: 0 var(--spacing-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: var(--font-size-xs);
    flex-shrink: 0;
}

/* Panel Structure */
.mode-selector,
.center-panel,
.debug-panel {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    min-height: 0;
}

.mode-selector,
.debug-panel {
    background-color: var(--color-bg-panel);
    border-radius: var(--border-radius-md);
    padding: var(--spacing-sm);
    box-shadow: var(--box-shadow-sm);
}

.center-panel>section {
    background-color: var(--color-bg-panel);
    border-radius: var(--border-radius-md);
    padding: var(--spacing-md);
    box-shadow: var(--box-shadow-sm);
    display: flex;
    flex-direction: column;
}

/* 4. Component Styles */

/* Header */
.app-header__title {
    font-size: var(--font-size-lg);
    font-weight: 600;
}

.app-header__status {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--color-success);
    transition: background-color var(--transition-base);
}

.status-indicator--initializing {
    background-color: #f39c12;
    animation: pulse 1s infinite;
}

.status-indicator--ready {
    background-color: var(--color-success);
}

.status-indicator--error {
    background-color: var(--color-error);
}

@keyframes pulse {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }

    100% {
        opacity: 1;
    }
}

/* Mode Selector (Left Panel) */
.mode-selector__title {
    font-size: var(--font-size-base);
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--spacing-sm);
}

.mode-selector__list {
    list-style: none;
    overflow-y: auto;
    flex-grow: 1;
}

.mode-selector__item {
    padding: var(--spacing-sm);
    margin-bottom: var(--spacing-xs);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    transition: all var(--transition-base);
    border: 1px solid transparent;
}

.mode-selector__item:hover {
    background-color: var(--color-bg-main);
    transform: translateX(5px);
}

.mode-selector__item--active {
    background-color: var(--color-primary);
    color: white;
    border-color: var(--color-primary);
}

.mode-selector__name {
    font-size: var(--font-size-sm);
    font-weight: 600;
    margin-bottom: var(--spacing-xs);
}

.mode-selector__description {
    font-size: var(--font-size-xs);
    opacity: 0.8;
}

/* Time Display (Center Panel) */
.time-display {
    flex-grow: 1;
}

.time-display__clock {
    text-align: center;
    margin-bottom: var(--spacing-md);
}

.time-display__value {
    font-size: var(--font-size-xl);
    font-variant-numeric: tabular-nums;
    font-weight: 300;
    line-height: 1;
}

.time-display__label {
    font-size: var(--font-size-base);
    color: var(--color-text-secondary);
    margin-top: var(--spacing-xs);
}

/* Info Grid */
.info-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--spacing-sm);
}

.info-card {
    background-color: var(--color-bg-main);
    padding: var(--spacing-sm);
    border-radius: var(--border-radius-sm);
    text-align: center;
}

.info-card__label {
    font-size: var(--font-size-xs);
    text-transform: uppercase;
    color: var(--color-text-secondary);
}

.info-card__value {
    font-size: var(--font-size-lg);
    font-weight: 600;
    margin-top: var(--spacing-xs);
}

/* Timeline (Center Panel) */
.timeline {
    justify-content: center;
}

.timeline__title {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-bottom: var(--spacing-sm);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.timeline__container {
    height: 40px;
    background-color: var(--color-bg-main);
    border-radius: var(--border-radius-md);
    position: relative;
    overflow: hidden;
    width: 100%;
    margin-top: 20px;
    /* 時刻ラベル用のスペース */
}

.timeline__current {
    position: absolute;
    width: 2px;
    height: 100%;
    background: var(--color-error);
    top: 0;
    z-index: 10;
    box-shadow: 0 0 4px rgba(231, 76, 60, 0.5);
    transition: left 1s linear;
}

/* Timeline hour marks */
.timeline-hours {
    position: absolute;
    width: 100%;
    height: 20px;
    top: -20px;
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
}

.hour-mark {
    position: absolute;
    transform: translateX(-50%);
    font-weight: 600;
}

/* Timeline segments */
.timeline-segment {
    position: absolute;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: var(--font-size-xs);
    font-weight: 600;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    transition: all 0.3s ease;
}

.timeline-segment:hover {
    filter: brightness(1.1);
    transform: scaleY(1.05);
    z-index: 5;
}

/* Timeline Segment Colors - These are fallbacks or for non-gradient modes */
.timeline-segment--designed {
    background-color: #3498DB;
}

.timeline-segment--another {
    background-color: #95A5A6;
}

.timeline-segment--core {
    background-color: #2874A6;
}

.timeline-segment--morning,
.timeline-segment--evening {
    background-color: #85C1E9;
}

.timeline-segment--activity {
    background-color: #5DADE2;
}

/* Solar mode uses inline styles for gradients, but we can define a fallback */
.timeline-segment--day {
    background-color: #F39C12;
}

.timeline-segment--night {
    background-color: #34495E;
}

/* Config Panel (Center Panel) */
.config-panel {
    flex-grow: 1;
}

.tab-list {
    display: flex;
    gap: var(--spacing-xs);
    margin-bottom: var(--spacing-md);
    border-bottom: 1px solid var(--color-border);
}

.tab-list__item {
    padding: var(--spacing-sm) var(--spacing-md);
    cursor: pointer;
    border: none;
    background: none;
    border-bottom: 2px solid transparent;
    font-size: var(--font-size-sm);
    transition: all var(--transition-base);
}

.tab-list__item:hover {
    background-color: var(--color-bg-main);
}

.tab-list__item[aria-selected="true"],
.tab-list__item--active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
}

.config-panel__content {
    flex-grow: 1;
    overflow-y: auto;
}

.config-panel__actions {
    display: flex;
    gap: var(--spacing-sm);
    margin-top: var(--spacing-md);
    padding-top: var(--spacing-md);
    border-top: 1px solid var(--color-border);
}

/* Debug Panel (Right Panel) */
.debug-panel {
    font-size: var(--font-size-xs);
}

.debug-panel__title {
    font-size: var(--font-size-base);
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid var(--color-border);
    margin-bottom: var(--spacing-sm);
}

.debug-panel__stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--spacing-sm);
    margin-bottom: var(--spacing-md);
    padding: var(--spacing-sm);
    background-color: var(--color-bg-main);
    border-radius: var(--border-radius-sm);
}

.debug-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.debug-stat__label {
    font-size: var(--font-size-xs);
    color: var(--color-text-secondary);
    text-transform: uppercase;
}

.debug-stat__value {
    font-size: var(--font-size-base);
    font-weight: 600;
    color: var(--color-primary);
}

.debug-panel__console {
    flex-grow: 1;
    font-family: 'Courier New', monospace;
    background-color: var(--color-debug-bg);
    color: var(--color-debug-text);
    padding: var(--spacing-sm);
    border-radius: var(--border-radius-sm);
    overflow-y: auto;
}

/* Debug Console Entries */
.debug-entry {
    margin-bottom: var(--spacing-sm);
    padding-bottom: var(--spacing-sm);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    font-size: var(--font-size-xs);
}

.debug-entry:last-child {
    border-bottom: none;
}

.debug-entry__time {
    color: #569CD6;
    margin-right: var(--spacing-sm);
}

.debug-entry__event {
    color: #4EC9B0;
    font-weight: 600;
    margin-right: var(--spacing-sm);
}

.debug-entry__message {
    color: var(--color-debug-text);
}

.debug-entry__data {
    margin-top: var(--spacing-xs);
    padding: var(--spacing-xs);
    background-color: rgba(255, 255, 255, 0.05);
    border-radius: var(--border-radius-sm);
    font-size: 0.7rem;
    color: #DCDCAA;
    overflow-x: auto;
}

/* Error entries - styled via JavaScript by adding a class */
.debug-entry--error .debug-entry__event {
    color: #F48771;
}

/* Status Bar */
.status-bar__item {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

/* 5. Shared Components */

/* Buttons */
.btn {
    padding: var(--spacing-sm) var(--spacing-md);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    font-size: var(--font-size-sm);
    cursor: pointer;
    background-color: var(--color-bg-panel);
    transition: all var(--transition-base);
}

.btn:hover {
    border-color: #999;
}

.btn--primary {
    background-color: var(--color-primary);
    border-color: var(--color-primary);
    color: white;
}

.btn--primary:hover {
    background-color: #2980b9;
    border-color: #2980b9;
}

/* Forms */
.config-group {
    margin-bottom: var(--spacing-md);
}

.config-group label {
    display: block;
    font-weight: 600;
    margin-bottom: var(--spacing-sm);
    font-size: var(--font-size-sm);
}

.config-group input,
.config-group select {
    width: 100%;
    padding: var(--spacing-sm);
    border: 1px solid var(--color-border);
    border-radius: var(--border-radius-sm);
    font-size: var(--font-size-sm);
}

/* noUiSlider Custom Styles */
.config-slider {
    margin: var(--spacing-md) 0;
}

.noUi-target {
    background: var(--color-bg-main);
    border: none;
    box-shadow: none;
}

.noUi-connect {
    background: var(--color-primary);
}

.noUi-handle {
    border: 2px solid var(--color-primary);
    background: white;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.noUi-handle:before,
.noUi-handle:after {
    display: none;
}

.noUi-tooltip {
    background: var(--color-text-primary);
    border: none;
    color: white;
    font-size: var(--font-size-xs);
}

/* Info Box */
.info-box {
    background-color: var(--color-bg-main);
    padding: var(--spacing-md);
    border-radius: var(--border-radius-sm);
}

.info-box p {
    margin-bottom: var(--spacing-xs);
}

.info-box p:last-child {
    margin-bottom: 0;
}

/* 6. Utility Classes */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.mode-selector__item--loading {
    text-align: center;
    color: var(--color-text-secondary);
}


/* 7. Responsive Design */
@media (max-width: 1200px) {
    .app-main {
        grid-template-columns: 1fr var(--panel-right-width);
    }

    .mode-selector {
        display: none;
        /* Or handle with a menu button */
    }

    .info-grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 768px) {
    body {
        overflow: auto;
    }

    .app-main {
        grid-template-columns: 1fr;
    }

    .debug-panel {
        display: none;
        /* Or handle with a toggle */
    }

    .time-display__value {
        font-size: 3rem;
    }
}