:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-card: #222222;
    --text-primary: #ffffff;
    --text-secondary: #aaaaaa;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --border-radius: 16px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.5;
}

.container { max-width: 800px; margin: 0 auto; padding: 20px; }

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0;
    margin-bottom: 20px;
}

header h1 {
    font-size: 1.8rem;
    font-weight: 700;
    background: linear-gradient(135deg, #6366f1, #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

#clock { font-size: 2rem; font-weight: 600; color: var(--text-secondary); }

.quick-actions {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
    margin-bottom: 24px;
}

.action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 20px 16px;
    border: none;
    border-radius: var(--border-radius);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.action-btn .icon { font-size: 1.8rem; }
.action-btn.home { background: linear-gradient(135deg, #22c55e, #16a34a); color: white; }
.action-btn.away { background: linear-gradient(135deg, #6366f1, #4f46e5); color: white; }
.action-btn.postpone { background: linear-gradient(135deg, #f59e0b, #d97706); color: white; }
.action-btn:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.action-btn:active { transform: translateY(0); }

.schedule-panel {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
}

.schedule-panel h2 { font-size: 1.2rem; color: var(--text-primary); }

.schedule-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.schedule-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.schedule-item { display: flex; flex-direction: column; gap: 8px; }
.schedule-item label { font-size: 0.9rem; color: var(--text-secondary); }

.schedule-item input[type="time"] {
    padding: 12px 16px;
    border: 2px solid #333;
    border-radius: 12px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1.2rem;
    font-weight: 600;
    outline: none;
    transition: border-color 0.2s;
}

.schedule-item input[type="time"]:focus { border-color: var(--accent); }

.schedule-status {
    margin-top: 16px;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-radius: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-align: center;
}

.schedule-status.active { color: var(--success); }

.devices-section h2 { font-size: 1.2rem; margin-bottom: 16px; color: var(--text-primary); }
.devices-grid { display: grid; gap: 16px; }

.device-card {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 24px;
    box-shadow: var(--shadow);
}

.device-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.device-name { font-size: 1.1rem; font-weight: 600; }
.device-status { font-size: 1.5rem; }
.device-status.connected { color: var(--success); }
.device-status.disconnected { color: var(--danger); }

.toggle-control {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.switch { position: relative; width: 56px; height: 28px; }
.switch input { opacity: 0; width: 0; height: 0; }

.switch .slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #333;
    border-radius: 28px;
    transition: 0.3s;
}

.switch .slider:before {
    content: "";
    position: absolute;
    height: 22px;
    width: 22px;
    left: 3px;
    bottom: 3px;
    background: white;
    border-radius: 50%;
    transition: 0.3s;
}

.switch input:checked+.slider { background: var(--accent); }
.switch input:checked+.slider:before { transform: translateX(28px); }

.temp-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    background: linear-gradient(135deg, #1e3a5f, #2d4a6f);
    border-radius: 12px;
    margin-bottom: 16px;
}

.room-temp { font-size: 2.5rem; font-weight: 700; color: #60a5fa; }
.temp-label { font-size: 0.8rem; color: var(--text-secondary); margin-top: 4px; }
.range-control { margin-top: 12px; }
.range-control label { display: block; font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 8px; }

.temp-input {
    width: 60px;
    padding: 10px;
    border: 2px solid #333;
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1rem;
    font-weight: 600;
    text-align: center;
    outline: none;
}

.temp-input:focus { border-color: var(--accent); }

.temp-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.temp-btn:hover { background: var(--accent-hover); }

.brightness-control { margin-top: 16px; }
.brightness-control label { display: block; font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 8px; }

.brightness-control input[type="range"] {
    width: 100%;
    height: 8px;
    background: linear-gradient(to right, #333, #fff);
    border-radius: 4px;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}

.brightness-control input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.color-control { margin-top: 16px; }
.color-control label { display: block; font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 8px; }

.color-control input[type="color"] {
    width: 100%;
    height: 44px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    background: transparent;
}

.presets { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }

.preset-btn {
    padding: 12px;
    border: none;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.preset-btn:hover { transform: scale(1.02); box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3); }
.preset-btn:active { transform: scale(0.98); }
.preset-btn.morning { background: linear-gradient(135deg, #ff9a56, #ffcc80); color: #333; }
.preset-btn.day { background: linear-gradient(135deg, #4fc3f7, #81d4fa); color: #333; }
.preset-btn.evening { background: linear-gradient(135deg, #7c4dff, #b388ff); color: white; }
.preset-btn.red { background: linear-gradient(135deg, #ff1744, #ff5252); color: white; }

.red-palette { margin-top: 16px; }
.red-palette label { display: block; font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 8px; }
.red-shades { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }

.shade-btn {
    width: 100%;
    aspect-ratio: 1;
    border: 2px solid transparent;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.shade-btn:hover { transform: scale(1.1); border-color: white; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4); }
.shade-btn:active { transform: scale(0.95); }

.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-card);
    color: var(--text-primary);
    padding: 14px 28px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    font-weight: 500;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
}

.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }

.loading { text-align: center; padding: 40px; color: var(--text-secondary); }

/* Music Panel */
.music-panel {
    background: var(--bg-card);
    border-radius: var(--border-radius);
    padding: 24px;
    margin-top: 24px;
    box-shadow: var(--shadow);
}

.music-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.music-header h2 { font-size: 1.2rem; font-weight: 600; color: var(--text-primary); }

.music-status-badge {
    font-size: 0.8rem;
    padding: 4px 12px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
}

.music-status-badge.playing { background: rgba(34, 197, 94, 0.2); color: #4ade80; }
.music-status-badge.paused  { background: rgba(245, 158, 11, 0.2); color: #fbbf24; }

.music-controls { display: flex; gap: 10px; margin-bottom: 16px; }

.music-btn {
    flex: 1;
    padding: 12px 8px;
    border-radius: 10px;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: opacity 0.2s, transform 0.1s;
}

.music-btn:hover { opacity: 0.85; }
.music-btn:active { transform: scale(0.97); }
.music-btn.play  { background: rgba(34, 197, 94, 0.25); color: #4ade80; }
.music-btn.pause { background: rgba(245, 158, 11, 0.2);  color: #fbbf24; }
.music-btn.stop  { background: rgba(239, 68, 68, 0.2);   color: #f87171; }

.music-volume-row { display: flex; align-items: center; gap: 10px; }

.music-volume-row input[type=range] {
    flex: 1;
    height: 6px;
    accent-color: #a78bfa;
    cursor: pointer;
}

.vol-label { font-size: 0.85rem; color: var(--text-secondary); min-width: 36px; }

/* Timer */
.music-timer-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 14px;
    flex-wrap: wrap;
}

.timer-label { font-size: 0.82rem; color: var(--text-secondary); white-space: nowrap; }

.timer-btn {
    padding: 7px 12px;
    border: 1px solid rgba(167, 139, 250, 0.3);
    border-radius: 8px;
    background: rgba(167, 139, 250, 0.1);
    color: #c4b5fd;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.timer-btn:hover  { background: rgba(167, 139, 250, 0.25); border-color: rgba(167, 139, 250, 0.6); }
.timer-btn:active { transform: scale(0.96); }
.timer-btn.active { background: rgba(167, 139, 250, 0.3); border-color: #a78bfa; color: #a78bfa; }

.timer-status {
    margin-top: 8px;
    padding: 7px 12px;
    background: rgba(167, 139, 250, 0.12);
    border-radius: 8px;
    font-size: 0.82rem;
    color: #c4b5fd;
    text-align: center;
}

/* Responsive */
@media (max-width: 600px) {
    .container { padding: 16px; }
    header h1 { font-size: 1.4rem; }
    #clock { font-size: 1.5rem; }

    .quick-actions { grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
    .action-btn { padding: 14px 8px; font-size: 0.8rem; gap: 6px; }
    .action-btn .icon { font-size: 1.4rem; }

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

    .music-controls { gap: 8px; }
    .music-btn { padding: 14px 4px; font-size: 0.82rem; }

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

/* Music Settings */
.music-settings {
    margin-top: 12px;
    border-top: 1px solid var(--border);
    padding-top: 10px;
}
.music-settings summary {
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-secondary);
    user-select: none;
    padding: 4px 0;
}
.music-settings summary:hover { color: var(--text-primary); }
.settings-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 10px;
}
.settings-grid label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.settings-grid label span {
    display: flex;
    align-items: center;
    gap: 4px;
}
.settings-grid input[type="number"] {
    width: 60px;
    background: var(--bg-input, #2a2a2a);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    padding: 4px 8px;
    font-size: 0.9rem;
    text-align: center;
}

/* ===== Global Log ===== */
.log-section {
    margin: 24px auto 0;
    max-width: 860px;
    padding: 0 16px 32px;
}
.log-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}
.log-header h2 {
    margin: 0;
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 500;
}
.log-live-dot {
    width: 8px; height: 8px;
    background: #3fb950;
    border-radius: 50%;
    flex-shrink: 0;
    transition: opacity .3s;
}
.log-live-dot.blink { opacity: 0; }
.log-clear-btn {
    margin-left: auto;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 0.75rem;
    padding: 3px 10px;
    cursor: pointer;
}
.log-clear-btn:hover { color: var(--text-primary); border-color: var(--text-secondary); }
.log-body {
    background: #0d1117;
    border: 1px solid #30363d;
    border-radius: 10px;
    padding: 12px 16px;
    height: 280px;
    overflow-y: auto;
    font-family: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 0.78rem;
    line-height: 1.6;
    scroll-behavior: smooth;
}
.log-body::-webkit-scrollbar { width: 6px; }
.log-body::-webkit-scrollbar-track { background: transparent; }
.log-body::-webkit-scrollbar-thumb { background: #30363d; border-radius: 3px; }
.log-line {
    display: flex;
    gap: 12px;
    padding: 1px 0;
}
.log-line:hover { background: rgba(255,255,255,.03); border-radius: 4px; }
.log-ts {
    color: #484f58;
    flex-shrink: 0;
    font-size: 0.72rem;
    padding-top: 1px;
}
.log-msg { word-break: break-word; }

/* Test button */
.timer-btn.test-btn {
    background: #1f3a2a;
    color: #3fb950;
    border-color: #238636;
}
.timer-btn.test-btn:hover { background: #238636; color: #fff; }

@media (max-width: 600px) {
    .log-body { height: 200px; font-size: 0.72rem; }
}

/* Music error banner */
.music-error {
    background: rgba(248, 81, 73, 0.15);
    border: 1px solid #f85149;
    border-radius: 8px;
    color: #f85149;
    padding: 10px 14px;
    margin-top: 10px;
    font-size: 0.85rem;
    font-weight: 500;
}

/* Toggle switch for settings */
.toggle-label { display:flex; align-items:center; justify-content:space-between; }
.toggle-label span { position:relative; display:inline-flex; align-items:center; gap:8px; }
.toggle-label input[type="checkbox"] { opacity:0; width:0; height:0; position:absolute; }
.toggle-slider {
    width:40px; height:22px; background:#555; border-radius:11px;
    position:relative; cursor:pointer; transition:background .2s;
}
.toggle-slider::after {
    content:''; position:absolute; top:3px; left:3px;
    width:16px; height:16px; background:#fff; border-radius:50%;
    transition:transform .2s;
}
.toggle-label input[type="checkbox"]:checked + .toggle-slider { background:#4ade80; }
.toggle-label input[type="checkbox"]:checked + .toggle-slider::after { transform:translateX(18px); }
