* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --bg:         #0a0e14;
    --surface:    #111821;
    --surface-2:  #16202b;
    --border:     #1e2833;
    --text:       #e6e6e6;
    --text-dim:   #8899aa;
    --text-faint: #4a5a6a;
    --accent:     #6b9fd8;
    --green:      #4ade80;
    --red:        #ff6b6b;
    --yellow:     #fbbf24;
    --dim:        0;
}

html, body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', -apple-system, system-ui, sans-serif;
    height: 100%;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    overscroll-behavior: none;
}

/* -------- Layout -------- */

.app {
    display: grid;
    height: 100vh;
    height: 100dvh;
    padding: max(0.6rem, env(safe-area-inset-top))
             max(0.8rem, env(safe-area-inset-right))
             max(0.6rem, env(safe-area-inset-bottom))
             max(0.8rem, env(safe-area-inset-left));
    gap: 0.7rem;
}

@media (orientation: portrait) {
    .app {
        grid-template-rows: auto 1fr auto;
        grid-template-areas: "header" "content" "sidebar";
    }
    .sidebar {
        flex-direction: row;
        gap: 0.5rem;
        flex-wrap: wrap;
    }
    .sidebar-section { flex: 1; min-width: 0; }
    .sidebar-section.info { display: none; }
}

@media (orientation: landscape) {
    .app {
        grid-template-columns: 1fr 260px;
        grid-template-rows: auto 1fr;
        grid-template-areas: "header header" "content sidebar";
    }
    .sidebar {
        flex-direction: column;
        overflow-y: auto;
    }
}

.header { grid-area: header; display: flex; align-items: center; gap: 0.8rem; }
.content { grid-area: content; overflow-y: auto; min-height: 0; display: flex; }
.sidebar { grid-area: sidebar; display: flex; gap: 0.7rem; }

/* -------- Header -------- */

.tabs {
    display: flex;
    gap: 0.25rem;
    flex: 1;
    overflow-x: auto;
    scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-dim);
    padding: 0.5rem 0.9rem;
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
    transition: all 0.15s;
}
.tab span { display: none; }
@media (min-width: 500px) { .tab span { display: inline; } }
.tab.active { background: var(--surface-2); color: var(--text); border-color: var(--accent); }
.tab:active { transform: scale(0.96); }

.header-right { display: flex; align-items: center; gap: 0.5rem; }

.night-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-dim);
    width: 36px;
    height: 36px;
    border-radius: 10px;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.night-btn:active { background: var(--surface-2); }

.connection {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--red);
    transition: background 0.3s;
}
.connection.online  { background: var(--green); }
.connection.offline { background: var(--red); }

/* -------- Content panes -------- */

.pane {
    display: none;
    width: 100%;
    gap: 0.8rem;
    flex-direction: column;
}
.pane.active { display: flex; }

/* -------- Часы -------- */

.pane[data-pane="clock"] {
    justify-content: center;
    align-items: center;
}

.clock-main { text-align: center; }

.time {
    font-size: clamp(4rem, 20vw, 12rem);
    font-weight: 200;
    font-variant-numeric: tabular-nums;
    line-height: 1;
    background: linear-gradient(180deg, #fff 0%, #6b9fd8 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

@media (orientation: landscape) {
    .time { font-size: clamp(4rem, 14vw, 9rem); }
}

.date {
    font-size: clamp(0.9rem, 3vw, 1.3rem);
    color: var(--text-dim);
    margin-top: 0.5rem;
    text-transform: capitalize;
}

.clock-footer {
    margin-top: 1.5rem;
    color: var(--text-dim);
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    justify-content: center;
}

/* -------- Погода -------- */

.weather-hero {
    display: flex;
    align-items: center;
    gap: 1.2rem;
    padding: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
}

.weather-icon-lg { font-size: clamp(3rem, 10vw, 4.5rem); line-height: 1; }
.weather-temp-lg { font-size: clamp(2rem, 7vw, 3rem); font-weight: 300; font-variant-numeric: tabular-nums; line-height: 1; }
.weather-desc-lg { font-size: 1rem; color: var(--text-dim); margin-top: 0.3rem; }

.forecast-list {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    scrollbar-width: none;
    flex: 1;
    align-items: stretch;
}
.forecast-list::-webkit-scrollbar { display: none; }

.forecast-day {
    flex: 1 0 90px;
    max-width: 140px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    padding: 0.8rem 0.6rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.fc-dow { font-size: 0.8rem; color: var(--text-dim); text-transform: uppercase; }
.fc-icon { font-size: 2rem; line-height: 1; }
.fc-temp { display: flex; gap: 0.4rem; font-size: 1rem; font-variant-numeric: tabular-nums; }
.fc-max { color: #fff; font-weight: 500; }
.fc-min { color: var(--text-faint); }
.fc-date { font-size: 0.7rem; color: var(--text-faint); }

/* -------- Система -------- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.6rem;
}
@media (min-width: 600px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }

.stat-card, .bar-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.7rem 0.9rem;
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.3rem;
}

.stat-value { font-size: 1.3rem; font-weight: 500; font-variant-numeric: tabular-nums; }
.stat-value.small { font-size: 0.95rem; word-break: break-all; }

.bar { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; margin-top: 0.5rem; }
.bar-fill { height: 100%; background: var(--accent); width: 0; transition: width 0.4s, background 0.3s; }
.bar-fill.warning { background: var(--yellow); }
.bar-fill.danger  { background: var(--red); }

/* -------- Устройства -------- */

.device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.6rem;
    align-content: start;
}

.device-btn {
    aspect-ratio: 1.2;
    min-height: 80px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    color: var(--text);
    font-family: inherit;
    font-size: 0.95rem;
    padding: 0.8rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}
.device-btn.placeholder {
    color: var(--text-faint);
    border-style: dashed;
    cursor: default;
    grid-column: 1 / -1;
}

/* -------- Sidebar -------- */

.sidebar-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.7rem 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sidebar-label {
    font-size: 0.75rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.dim-slider {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: var(--bg);
    border-radius: 3px;
    outline: none;
}
.dim-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
}
.dim-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    border: none;
}

.dim-value { font-size: 0.8rem; color: var(--text-dim); text-align: right; font-variant-numeric: tabular-nums; }

.action-btn {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.6rem 0.8rem;
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    text-align: left;
}
.action-btn:active { transform: scale(0.97); background: var(--border); }

.sidebar-section.info { font-size: 0.8rem; color: var(--text-dim); gap: 0.3rem; }
.info-row { display: flex; justify-content: space-between; gap: 0.5rem; }

/* -------- Dim overlay -------- */

.dim-overlay {
    position: fixed;
    inset: 0;
    background: #000;
    opacity: var(--dim);
    pointer-events: none;
    z-index: 9999;
    transition: opacity 0.2s;
}