:root {
    --bg-color: #f0f2f5;
    --card-bg: #ffffff;
    --card-border: #e0e0e0;
    --text-main: #202124;
    --text-secondary: #5f6368;
    --accent-color: #1a73e8;

    --zone-work: #ffffff;
    --zone-rest: #ebebeb;
    --text-rest: #5f6368;

    --grid-border: rgba(0,0,0,0.08);
    --cell-border: #f0f0f0;

    --temp-gradient: linear-gradient(to top, #3f51b5, #2196f3, #4caf50, #ff9800, #f44336);
    --red-line: #1a73e8;
    --header-height: 72px;

    --modal-bg: #ffffff;
    --modal-border: #eee;
    --input-bg: #ffffff;
    --input-border: #ccc;
    --btn-secondary-bg: #e0e0e0;
    --btn-secondary-color: #202124;
    --chip-bg: rgba(255,255,255,0.95);
    --chip-border: #e0e0e0;
    --instructions-bg: #f8f9fa;
    --instructions-border: #e8eaed;
}

/* ─── Dark theme ─────────────────────────────────────────────────────────── */
body.dark {
    --bg-color: #18191d;
    --card-bg: #25262b;
    --card-border: #3a3b42;
    --text-main: #e0e0e0;
    --text-secondary: #9a9a9a;
    --accent-color: #5b9cf4;

    --zone-work: #2c2d34;
    --zone-rest: #1f2026;
    --text-rest: #7a7a7a;

    --grid-border: rgba(255,255,255,0.05);
    --cell-border: #33343c;

    --temp-gradient: linear-gradient(to top, #3f51b5, #2196f3, #4caf50, #ff9800, #f44336);
    --red-line: #5b9cf4;

    --modal-bg: #25262b;
    --modal-border: #3a3b42;
    --input-bg: #1e1f26;
    --input-border: #3a3b42;
    --btn-secondary-bg: #35363e;
    --btn-secondary-color: #e0e0e0;
    --chip-bg: rgba(37,38,43,0.97);
    --chip-border: #3a3b42;
    --instructions-bg: #1e1f26;
    --instructions-border: #3a3b42;
}

/* ─── Base ───────────────────────────────────────────────────────────────── */
body {
    font-family: 'Roboto', sans-serif;
    background-color: var(--bg-color);
    margin: 0; padding: 20px;
    height: 100vh; box-sizing: border-box;
    display: flex; flex-direction: column;
    overflow: hidden;
    transition: background-color 0.25s;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 20px;
    height: 100%;
    overflow: hidden;
}

.panel {
    background: var(--card-bg);
    border-radius: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24);
    display: flex; flex-direction: column;
    overflow: hidden; position: relative;
    transition: background-color 0.25s;
}

/* ─── Panel headers ──────────────────────────────────────────────────────── */
.panel-header-container {
    height: var(--header-height);
    border-bottom: 1px solid var(--card-border);
    background: var(--card-bg);
    display: flex; align-items: center;
    box-sizing: border-box;
    transition: background-color 0.25s, border-color 0.25s;
}
.time-header-container { overflow-x: hidden; }

.weather-header-labels {
    width: 100%; display: flex; justify-content: space-between;
    padding: 0 45px; box-sizing: border-box;
    font-size: 1.1rem; font-weight: 700; color: var(--text-main);
}

.time-header-row { display: flex; width: max-content; min-width: 100%; height: 100%; }
#time-grid { display: flex; flex-direction: column; height: 100%; width: max-content; min-width: 100%; box-sizing: border-box; }
.grid-row { flex: 1; display: flex; width: 100%; position: relative; box-sizing: border-box; border-top: 1px solid var(--grid-border); }
.grid-row:first-child { border-top: none; }

.header-cell, .grid-cell {
    flex: 1 0 120px;
    text-align: center; display: flex; flex-direction: column; justify-content: center;
    border-right: 1px solid var(--cell-border);
    padding: 0 5px; position: relative; box-sizing: border-box;
}
.header-cell:last-child, .grid-cell:last-child { border-right: none; }

.h-city { font-weight: 700; font-size: 0.95rem; color: var(--text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.h-tz   { font-size: 0.75rem; color: var(--text-secondary); margin-top: 2px; }
.h-time { font-size: 1.0rem; color: var(--accent-color); font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }

.header-cell.local-tz { background-color: rgba(26, 115, 232, 0.1); }
.header-cell.local-tz .h-city { color: var(--accent-color); }
body.dark .header-cell.local-tz { background-color: rgba(91, 156, 244, 0.1); }

/* ─── Weather body ───────────────────────────────────────────────────────── */
.weather-body { flex: 1; position: relative; padding: 20px 0; overflow: hidden; }
.thermometer-container { position: relative; width: 100%; height: 100%; }
.central-rail { position: absolute; left: 50%; transform: translateX(-50%); width: 8px; height: 100%; background: var(--temp-gradient); border-radius: 4px; z-index: 5; }
.tick-line  { position: absolute; height: 1px; background-color: var(--card-border); width: 75px; z-index: 1; }
.tick-line.left  { right: 50%; margin-right: 4px; }
.tick-line.right { left:  50%; margin-left:  4px; }
.tick-label { position: absolute; font-size: 0.8rem; color: var(--text-secondary); transform: translateY(-50%); font-weight: 500; }
.tick-label.left  { left: 40px;  text-align: left;  }
.tick-label.right { right: 40px; text-align: right; }

.city-chip {
    position: absolute; left: 50%; transform: translate(-50%, -50%);
    background: var(--chip-bg);
    padding: 6px 14px; border-radius: 20px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    font-size: 0.85rem; font-weight: 500; white-space: nowrap;
    z-index: 20; border: 1px solid var(--chip-border);
    transition: top 0.5s cubic-bezier(0.25, 0.8, 0.25, 1);
    display: flex; align-items: center; gap: 6px;
    color: var(--text-main);
}

/* ─── Time grid body ─────────────────────────────────────────────────────── */
.time-grid-container { flex: 1; position: relative; display: flex; flex-direction: column; overflow-x: auto; overflow-y: hidden; }

.grid-cell { font-size: 0.8rem; background-color: var(--zone-work); color: var(--text-main); }
.grid-cell.rest-zone { background-color: var(--zone-rest); color: var(--text-rest); }
.time-label { position: absolute; top: 0; left: 50%; transform: translate(-50%, -50%); background-color: inherit; padding: 0 4px; border-radius: 4px; z-index: 2; }

#red-line { position: absolute; left: 0; height: 2px; background: var(--red-line); z-index: 50; pointer-events: none; box-shadow: 0 1px 4px rgba(26,115,232,0.4); transition: top 1s linear; }
#red-line::before { content: ''; position: absolute; left: -5px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--red-line); }

/* ─── Events ─────────────────────────────────────────────────────────────── */
#events-layer { position: absolute; top: 0; bottom: 0; left: 0; pointer-events: none; z-index: 10; }
.calendar-event {
    position: absolute; border-radius: 6px; padding: 3px 6px;
    font-size: 0.75rem; font-weight: 500; color: #fff; box-sizing: border-box;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    pointer-events: auto; cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.nav-arrow { background: none; border: none; cursor: pointer; color: var(--text-secondary); font-size: 1.1rem; font-weight: bold; padding: 0 5px; }

/* ─── Panel footer ───────────────────────────────────────────────────────── */
.panel-footer {
    height: 60px;
    background: var(--card-bg);
    border-top: 1px solid var(--card-border);
    display: flex; justify-content: center; align-items: center;
    flex-shrink: 0; position: relative;
    transition: background-color 0.25s, border-color 0.25s;
}
.time-footer { justify-content: center; padding: 0 20px; }
.footer-center { display: flex; align-items: center; }

/* Gear: bottom-left */
.settings-btn {
    background: var(--btn-secondary-bg);
    border: none; border-radius: 50%;
    width: 36px; height: 36px;
    color: var(--text-secondary);
    cursor: pointer; display: flex; justify-content: center; align-items: center;
    transition: background 0.2s, color 0.2s;
    position: absolute; left: 20px;
}
.settings-btn:hover { background: var(--card-border); color: var(--text-main); }

/* Dark/light toggle: bottom-right */
.footer-right {
    position: absolute; right: 20px;
    display: flex; align-items: center; gap: 0;
}
.theme-icon { font-size: 1rem; line-height: 1; color: var(--text-secondary); }

/* ─── Toggle switches ────────────────────────────────────────────────────── */
.toggle-switch { position: relative; display: inline-block; width: 48px; height: 24px; margin: 0 10px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .4s; border-radius: 24px; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--accent-color); }
input:checked + .slider:before { transform: translateX(24px); }

/* Dark mode: restore blue-on for settings toggles (fix specificity order) */
body.dark .slider { background-color: #555; }
body.dark input:checked + .slider { background-color: var(--accent-color); }

/* Plain toggles on main page (°C/°F, 24h/12h, theme) — always gray, no accent.
   Needs higher specificity than body.dark rules above, so include both states. */
.toggle-plain .slider,
.toggle-plain input:checked + .slider { background-color: #a8acb0; }
body.dark .toggle-plain .slider,
body.dark .toggle-plain input:checked + .slider { background-color: #5e6068; }

.toggle-text { font-size: 0.85rem; font-weight: 500; color: var(--text-secondary); }

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn { padding: 8px 16px; border: none; border-radius: 6px; cursor: pointer; font-weight: 500; font-family: inherit; transition: opacity 0.2s; }
.btn:hover { opacity: 0.85; }
.btn-secondary { background: var(--btn-secondary-bg); color: var(--btn-secondary-color); }
.btn-primary   { background: var(--accent-color); color: white; }
.btn-danger    { background: #fce8e6; color: #c5221f; }
.btn-sm        { padding: 4px 10px; font-size: 0.8rem; }
body.dark .btn-danger { background: #3d1f1e; color: #f28b82; }

/* ─── Modal: two-column layout ───────────────────────────────────────────── */
.modal {
    border: none; border-radius: 12px; padding: 0;
    box-shadow: 0 4px 24px rgba(0,0,0,0.25);
    width: min(860px, 95vw);
    max-height: 90vh;
    background: var(--modal-bg);
}
.modal::backdrop { background: rgba(0,0,0,0.5); }

.modal-content {
    display: flex; flex-direction: column;
    height: min(680px, 85vh);
    max-height: 85vh;
    background: var(--modal-bg);
    border-radius: 12px;
}

.modal-columns {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.modal-col {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    min-width: 0;
    background: var(--modal-bg);
}

#col-timezones { border-right: 1px solid var(--modal-border); }

/* Both columns: title on row 1, action buttons on row 2 */
#col-timezones .col-header,
#col-calendar .col-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
}

/* Column headers */
.col-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding-bottom: 10px;
    margin-bottom: 10px;
}
.col-header h3 { margin: 0; font-size: 1rem; color: var(--text-main); line-height: 1.4; }
.col-header-actions { display: flex; gap: 6px; flex-shrink: 0; padding-top: 1px; }

/* List items: no dividers, consistent height */
.city-toggles-grid { display: grid; grid-template-columns: 1fr; gap: 4px; padding-bottom: 10px; }
.city-toggle-item {
    display: flex; justify-content: space-between; align-items: center;
    font-size: 0.9rem;
    min-height: 40px;
    padding: 0 2px;
}

.city-name-label { flex: 1; font-weight: 500; color: var(--text-main); display: flex; align-items: center; }
.hours-input-group { display: flex; gap: 6px; align-items: center; margin-right: 12px; }
.hours-input-group input {
    width: 42px; padding: 3px; text-align: center;
    border: 1px solid var(--input-border);
    border-radius: 4px; font-family: inherit; font-size: 0.85rem;
    background: var(--input-bg); color: var(--text-main);
}

/* Modal footer */
.modal-actions {
    padding: 12px 24px 20px 24px;
    display: flex; justify-content: flex-end; gap: 10px;
    background: var(--modal-bg);
    border-top: 1px solid var(--modal-border);
    flex-shrink: 0;
    border-radius: 0 0 12px 12px;
}

/* ─── Calendar column ────────────────────────────────────────────────────── */

.cal-sync-title {
    cursor: pointer;
    display: flex; align-items: flex-start; gap: 4px;
    margin: 0; font-size: 1rem; color: var(--text-main);
    user-select: none; transition: color 0.15s;
    line-height: 1.3;
}
.cal-sync-title:hover { color: var(--accent-color); }

.expand-icon {
    display: inline-block; flex-shrink: 0;
    font-size: 1.2rem; line-height: 1.3;
    font-weight: 400; transition: transform 0.2s;
    color: var(--text-secondary);
}
.expand-icon.open { transform: rotate(90deg); }

/* Instructions panel */
.cal-instructions {
    background: var(--instructions-bg);
    border: 1px solid var(--instructions-border);
    border-radius: 8px;
    padding: 14px 16px;
    margin-bottom: 14px;
    font-size: 0.83rem; line-height: 1.6;
    color: var(--text-main);
}
.cal-instructions p { margin: 0 0 10px 0; }
.cal-instructions .setup-summary { font-weight: 500; }
.cal-instructions .setup-security { color: var(--text-secondary); font-size: 0.79rem; }
.cal-instructions ol { margin: 8px 0 12px 16px; padding: 0; }
.cal-instructions ol li { margin-bottom: 6px; }
.cal-instructions a { color: var(--accent-color); }
.cal-instructions code { background: var(--btn-secondary-bg); border-radius: 3px; padding: 1px 5px; font-size: 0.8rem; color: var(--text-main); }
.cal-instructions strong { font-weight: 600; }
.cal-instructions kbd { background: var(--btn-secondary-bg); border-radius: 3px; padding: 1px 5px; font-size: 0.8rem; color: var(--text-main); border: 1px solid var(--input-border); }

.script-block { position: relative; background: #1e1e2e; border-radius: 6px; padding: 12px; margin-top: 4px; }
.script-block pre { margin: 0; color: #cdd6f4; font-family: 'Courier New', Consolas, monospace; font-size: 0.71rem; line-height: 1.5; overflow-x: auto; max-height: 180px; white-space: pre; }
.copy-btn { position: absolute; top: 8px; right: 8px; background: rgba(255,255,255,0.1); color: #cdd6f4; border: none; border-radius: 4px; padding: 3px 9px; font-size: 0.75rem; cursor: pointer; font-family: inherit; transition: background 0.15s; }
.copy-btn:hover { background: rgba(255,255,255,0.2); }

/* Connect form */
.connect-form { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.connect-form input {
    padding: 8px 10px;
    border: 1px solid var(--input-border);
    border-radius: 6px; font-family: inherit; font-size: 0.85rem;
    width: 100%; box-sizing: border-box; outline: none;
    background: var(--input-bg); color: var(--text-main);
    transition: border-color 0.15s;
}
.connect-form input:focus { border-color: var(--accent-color); }
.connect-status { font-size: 0.82rem; color: var(--text-secondary); min-height: 18px; }
.connect-status.error { color: #c5221f; }
body.dark .connect-status.error { color: #f28b82; }

/* Calendar controls (connected state) */
.cal-controls { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
    .modal-columns { flex-direction: column; overflow-y: auto; }
    .modal-col { overflow-y: visible; }
    #col-timezones { border-right: none; border-bottom: 1px solid var(--modal-border); }
}
