* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #f5f6fa;
    --sidebar-bg: #2c3e50;
    --sidebar-text: #ecf0f1;
    --card-bg: #fff;
    --text: #2c3e50;
    --text-muted: #7f8c8d;
    --primary: #6c5ce7;
    --primary-hover: #5a4bd1;
    --accent: #00b894;
    --border: #dfe6e9;
    --highlight: #ebf5fb;
    --highlight-alt: #eafaf1;
    --row-hover: #f8f9fa;
    --connect-bg: #6c5ce7;
    --connect-hover: #5a4bd1;
}

[data-theme="red"] {
    --bg: #f5f6fa;
    --sidebar-bg: #B31B1B;
    --sidebar-text: #ecf0f1;
    --card-bg: #fff;
    --text: #2c3e50;
    --text-muted: #7f8c8d;
    --primary: #B31B1B;
    --primary-hover: #8B1515;
    --accent: #D4443B;
    --border: #dfe6e9;
    --highlight: #fdecea;
    --highlight-alt: #fef5f4;
    --row-hover: #f8f9fa;
    --connect-bg: #5C0A0A;
    --connect-hover: #3D0707;
}

[data-theme="dark"] {
    --bg: #1e1e1e;
    --sidebar-bg: #161616;
    --sidebar-text: #d4d4d4;
    --card-bg: #2d2d2d;
    --text: #d4d4d4;
    --text-muted: #999;
    --primary: #6c9bef;
    --primary-hover: #5581d4;
    --accent: #5cb9a0;
    --border: #444;
    --highlight: #2a3a4a;
    --highlight-alt: #2a3d36;
    --row-hover: #333;
    --connect-bg: #3a3a3a;
    --connect-hover: #4a4a4a;
}

body { font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); }

.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
    width: 220px; background: var(--sidebar-bg); color: var(--sidebar-text);
    display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0; z-index: 10;
}
.sidebar-header { padding: 1.2rem 1rem; display: flex; align-items: center; gap: 0.5rem; border-bottom: 1px solid rgba(255,255,255,0.1); }
.logo-img { width: 73px; height: 73px; object-fit: contain; }
.logo-text { font-size: 1.1rem; font-weight: 700; letter-spacing: 0.02em; }
.nav-items { flex: 1; padding: 0.8rem 0; }
.nav-btn {
    display: flex; align-items: center; gap: 0.6rem; width: 100%; padding: 0.7rem 1.2rem;
    background: none; border: none; color: var(--sidebar-text); font-size: 0.9rem; cursor: pointer;
    transition: background 0.15s; text-align: left;
}
.nav-btn:hover { background: rgba(255,255,255,0.08); }
.nav-btn.active { background: rgba(255,255,255,0.15); font-weight: 600; }
.nav-icon { width: 24px; height: 24px; object-fit: contain; vertical-align: middle; filter: invert(1) brightness(2); }
.sidebar-footer { padding: 1rem; border-top: 1px solid rgba(255,255,255,0.1); }
.connection-status { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.6rem; font-size: 0.82rem; }
.conn-icon { object-fit: contain; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.disconnected { background: #e74c3c; }
.dot.connected { background: #2ecc71; }
.btn-connect {
    width: 100%; padding: 0.5rem; background: var(--connect-bg); color: #fff; border: none;
    border-radius: 6px; cursor: pointer; font-size: 0.85rem; font-weight: 600; transition: background 0.15s;
}
.btn-connect:hover { background: var(--connect-hover); }
.device-info { font-size: 0.75rem; color: rgba(255,255,255,0.5); margin-top: 0.5rem; word-break: break-all; }
.app-version { font-size: 0.7rem; color: rgba(255,255,255,0.3); margin-top: 0.4rem; }

/* Theme Picker */
.theme-picker { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.6rem; }
.theme-picker-label { font-size: 0.75rem; color: rgba(255,255,255,0.6); }
.theme-swatch {
    width: 20px; height: 20px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.3);
    cursor: pointer; transition: border-color 0.15s, transform 0.15s;
}
.theme-swatch:hover { transform: scale(1.15); }
.theme-swatch.active { border-color: #fff; box-shadow: 0 0 4px rgba(255,255,255,0.5); }
.theme-swatch[data-theme="blue"] { background: #6c5ce7; }
.theme-swatch[data-theme="red"] { background: #B31B1B; }
.theme-swatch[data-theme="dark"] { background: #333; }

/* PWA status */
.pwa-status { font-size: 0.72rem; color: rgba(255,255,255,0.4); margin-top: 0.3rem; }
.pwa-status.stale { color: #f39c12; }

/* Content */
.content { margin-left: 220px; flex: 1; padding: 1.5rem 2rem; max-width: 900px; }
.page { display: none; }
.page.active { display: block; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.2rem; }
.page-header h1 { font-size: 1.4rem; font-weight: 700; color: var(--text); }

/* Time toggle */
.time-toggle { display: flex; align-items: center; gap: 0.4rem; }
.toggle-label { font-size: 0.8rem; color: var(--text-muted); }
.switch { position: relative; display: inline-block; width: 36px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0;
    background: #ccc; border-radius: 20px; transition: 0.2s;
}
.slider:before {
    content: ""; position: absolute; height: 14px; width: 14px; left: 3px; bottom: 3px;
    background: #fff; border-radius: 50%; transition: 0.2s;
}
input:checked + .slider { background: var(--primary); }
input:checked + .slider:before { transform: translateX(16px); }

/* Summary table */
.summary-table-wrap { background: var(--card-bg); border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); overflow: hidden; }
.summary-table { width: 100%; border-collapse: collapse; }
.summary-table td { padding: 0.55rem 1rem; font-size: 0.92rem; border-bottom: 1px solid var(--border); }
.summary-table td:first-child { font-weight: 600; color: var(--text); white-space: nowrap; width: 1%; }
.summary-table td:last-child { color: var(--text-muted); }
.summary-table tr.highlight td { background: var(--highlight); }
.summary-table tr.highlight-alt td { background: var(--highlight-alt); }
.summary-table tr.spacer td { padding: 0.2rem; border: none; background: transparent; }
.summary-table tr.section-header td { font-weight: 700; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--primary); padding-top: 0.8rem; background: transparent; border-bottom: 2px solid var(--primary); }
.placeholder-row td { text-align: center; color: var(--text-muted); padding: 3rem 1rem; font-style: italic; }

/* Cards */
.card { background: var(--card-bg); border-radius: 10px; box-shadow: 0 1px 4px rgba(0,0,0,0.06); padding: 1.2rem 1.4rem; margin-bottom: 1rem; }
.card h2 { font-size: 1rem; font-weight: 700; margin-bottom: 0.8rem; color: var(--text); }

/* Device clock display */
.device-clock { font-size: 2.4rem; font-weight: 300; font-family: 'Cascadia Code', 'Fira Code', monospace; color: var(--primary); }
.device-date { font-size: 0.95rem; color: var(--text-muted); margin-top: 0.2rem; }
.system-clock { font-size: 2.4rem; font-weight: 300; font-family: 'Cascadia Code', 'Fira Code', monospace; color: var(--text-muted); }
.system-date { font-size: 0.95rem; color: var(--text-muted); margin-top: 0.2rem; }

/* Forms */
.form-row { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.input-field { padding: 0.5rem 0.7rem; border: 1px solid var(--border); border-radius: 6px; font-size: 0.9rem; font-family: monospace; }
.btn {
    padding: 0.5rem 1rem; border: none; border-radius: 6px; cursor: pointer;
    font-size: 0.85rem; font-weight: 600; transition: all 0.15s;
}
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--accent); color: #fff; }
.btn-secondary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover:not(:disabled) { background: var(--highlight); border-color: var(--primary); }
.btn-grid { display: flex; flex-wrap: wrap; gap: 0.4rem; }

/* Raw output */
.raw-output {
    background: #1e272e; color: #d2dae2; padding: 1rem; border-radius: 8px;
    font-family: 'Cascadia Code', 'Fira Code', monospace; font-size: 0.8rem;
    white-space: pre-wrap; word-break: break-all; max-height: 300px; overflow-y: auto; line-height: 1.5;
}
.log-output { max-height: 200px; }

/* Settings form elements */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 600; color: var(--text); margin-bottom: 0.3rem; }
.slider-row { display: flex; align-items: center; gap: 1rem; }
.range-input { flex: 1; accent-color: var(--primary); height: 6px; cursor: pointer; }
.slider-value { font-family: 'Cascadia Code', 'Fira Code', monospace; font-size: 0.9rem; min-width: 80px; color: var(--primary); font-weight: 600; }
.select-field { padding: 0.45rem 0.7rem; border: 1px solid var(--border); border-radius: 6px; font-size: 0.9rem; background: var(--card-bg); color: var(--text); min-width: 150px; }
.input-hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.2rem; }
.tick-labels { display: flex; justify-content: space-between; font-size: 0.7rem; color: var(--text-muted); padding: 0 8px; margin-top: 0.2rem; width: calc(100% - 90px); }
.tick-labels span { text-align: center; min-width: 0; flex: 1; }

/* Radio button group for sample rate */
.radio-group { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; }
.radio-option { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.9rem; font-weight: 400; cursor: pointer; margin-bottom: 0; }
.radio-option input[type="radio"] { accent-color: var(--primary); cursor: pointer; margin: 0; }

/* Location page */
.location-current { font-size: 0.95rem; color: var(--text); line-height: 1.6; }
#map { border: 1px solid var(--border); }
#map .leaflet-control-attribution { font-size: 0.65rem; }

/* Toast notification */
.toast {
    position: fixed; top: 1.2rem; right: 1.2rem; z-index: 1000;
    padding: 0.7rem 1.2rem; border-radius: 8px; font-size: 0.9rem; font-weight: 600;
    color: #fff; opacity: 0; transform: translateY(-10px);
    transition: opacity 0.3s, transform 0.3s; pointer-events: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: var(--accent); }
.toast.error { background: #e74c3c; }

/* Save button states */
.btn.saving { opacity: 0.7; cursor: wait; }
.btn.saved { background: var(--accent); }

/* Pulsing attention animation for unsaved changes */
@keyframes pulse-attention {
    0%   { box-shadow: 0 0 6px rgba(180, 160, 255, 0.4); }
    50%  { box-shadow: 0 0 20px rgba(180, 160, 255, 1); }
    100% { box-shadow: 0 0 6px rgba(180, 160, 255, 0.4); }
}
.btn-save-device {
    width: 100%; padding: 0.55rem; margin-bottom: 0.8rem;
    background: var(--primary); color: #fff; border: none;
    border-radius: 6px; cursor: pointer; font-size: 0.85rem; font-weight: 700;
    animation: pulse-attention 1.5s ease-in-out infinite;
    transition: background 0.15s;
}
.btn-save-device:hover { background: var(--primary-hover); }
.btn-save-device.saving { opacity: 0.7; cursor: wait; animation: none; }
.btn-save-device.saved { background: var(--accent); animation: none; }

/* Disconnect placeholder for all pages */
.disconnect-placeholder {
    text-align: center; color: var(--text-muted); padding: 4rem 1rem;
    font-size: 1rem; font-style: italic;
}

/* Device content visibility — toggled by JS */
.dev-content.hidden { display: none; }
.dev-hide { display: none; }
.dev-hide.visible { display: block; }

/* Cache warning banner */
.cache-warning {
    background: #fff3cd; color: #856404; border: 1px solid #ffc107;
    border-radius: 8px; padding: 0.7rem 1rem; margin-bottom: 1rem;
    font-size: 0.85rem; line-height: 1.4;
}

/* Schedule page */
.arb-entry { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.time-hour { width: 78px; padding: 0.35rem 0.4rem; font-size: 0.85rem; }
.time-min { width: 58px; padding: 0.35rem 0.4rem; font-size: 0.85rem; }
.time-colon { font-weight: 700; font-size: 1rem; margin: 0 1px; }

/* Page header with multiple right-side items */
.page-header-right { display: flex; align-items: center; gap: 1rem; }

/* Wider time inputs for AM/PM display */
.arb-entry .input-field[type="time"] { width: 140px; }

/* Schedule Summary Calendar */
.cal-estimation-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 1rem; margin-bottom: 0.5rem; }
.cal-est-label { font-size: 0.82rem; color: var(--text); display: inline-flex; align-items: center; gap: 0.35rem; }
.cal-est-select { font-size: 0.82rem; padding: 0.2rem 0.4rem; border: 1px solid var(--border); border-radius: 4px; background: var(--card-bg); color: var(--text); }
.cal-runtime-info { font-size: 0.82rem; color: var(--text-muted); padding: 0.25rem 0; margin-bottom: 0.3rem; }
.cal-nav { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-bottom: 0.5rem; }
.cal-nav-btn { padding: 0.3rem 0.7rem; font-size: 1rem; line-height: 1; }
.cal-month-label { font-size: 1.15rem; font-weight: 700; color: var(--text); min-width: 180px; text-align: center; }
.cal-legend { display: flex; flex-wrap: wrap; gap: 0.8rem; padding: 0.6rem 0 0.2rem; }
.cal-legend-item { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.78rem; color: var(--text); }
.cal-legend-swatch { display: inline-block; width: 14px; height: 14px; border-radius: 2px; border: 1px solid #ccc; }
.cal-tooltip {
    display: none; position: absolute; background: rgba(44,62,80,0.92); color: #fff;
    padding: 0.3rem 0.6rem; border-radius: 5px; font-size: 0.78rem; pointer-events: none;
    white-space: nowrap; z-index: 20;
}
