/* ==========================================================================
   Метеостанция «Север» — единая тема оформления
   Три варианта: dark (тёмная «стекло»), light (светлая минималистичная),
   panel (приборная панель). Переключение — theme.js, выбор в localStorage.

   Файл подключается ПОСЛЕ встроенных стилей страницы, поэтому правила
   того же уровня специфичности перекрывают исходные цвета.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Токены тем
   -------------------------------------------------------------------------- */

html[data-theme="dark"] {
    color-scheme: dark;

    --bg:            #08121a;
    --bg-image:      radial-gradient(1100px 600px at 8% -10%, rgba(79, 209, 197, .20), transparent 62%),
                     radial-gradient(900px 520px at 96% 0%, rgba(255, 200, 87, .13), transparent 58%),
                     linear-gradient(160deg, #071019 0%, #0d1c28 52%, #0a1a1f 100%);

    --surface:       rgba(255, 255, 255, .055);
    --surface-solid: #0f1d29;
    --surface-2:     rgba(255, 255, 255, .05);
    --surface-3:     rgba(255, 255, 255, .028);
    --header-bg:     rgba(255, 255, 255, .04);
    --chip-bg:       rgba(255, 255, 255, .07);

    --text:          #e9f2f8;
    --text-muted:    #9db2c2;
    --text-dim:      #6f8798;

    --accent:        #ffc857;
    --accent-hover:  #ffd77a;
    --accent-text:   #0a1620;

    --border:        rgba(255, 255, 255, .10);
    --shadow:        0 24px 60px rgba(0, 0, 0, .45);

    --ok:            #3ddc97;
    --warn:          #ffc857;
    --err:           #ff6b6b;
    --ok-bg:         rgba(61, 220, 151, .12);
    --warn-bg:       rgba(255, 200, 87, .13);
    --err-bg:        rgba(255, 107, 107, .13);

    --mono-bg:       rgba(0, 0, 0, .38);
    --mono-fg:       #ffd76a;

    --radius:        24px;
    --radius-sm:     14px;
    --blur:          blur(16px);
}

html[data-theme="light"] {
    color-scheme: light;

    --bg:            #f4f7fb;
    --bg-image:      none;

    --surface:       #ffffff;
    --surface-solid: #ffffff;
    --surface-2:     #f7f9fc;
    --surface-3:     #eef3f9;
    --header-bg:     #ffffff;
    --chip-bg:       #eef3f9;

    --text:          #0f1e28;
    --text-muted:    #5b7080;
    --text-dim:      #7d90a1;

    --accent:        #0f766e;
    --accent-hover:  #0d9488;
    --accent-text:   #ffffff;

    --border:        #e2eaf3;
    --shadow:        0 10px 30px rgba(15, 40, 60, .08);

    --ok:            #12805a;
    --warn:          #b45309;
    --err:           #dc2626;
    --ok-bg:         #e8f7ef;
    --warn-bg:       #fdf3e3;
    --err-bg:        #fdeaea;

    --mono-bg:       #0f1e28;
    --mono-fg:       #b8f07a;

    --radius:        18px;
    --radius-sm:     12px;
    --blur:          none;
}

html[data-theme="panel"] {
    color-scheme: dark;

    --bg:            #070b08;
    --bg-image:      linear-gradient(rgba(74, 222, 128, .045) 1px, transparent 1px) 0 0 / 100% 28px,
                     linear-gradient(90deg, rgba(74, 222, 128, .045) 1px, transparent 1px) 0 0 / 28px 100%,
                     radial-gradient(820px 420px at 50% -12%, rgba(74, 222, 128, .12), transparent 70%),
                     #070b08;

    --surface:       #0d1510;
    --surface-solid: #0d1510;
    --surface-2:     #0a120d;
    --surface-3:     #08100b;
    --header-bg:     #0a120d;
    --chip-bg:       #0b1a12;

    --text:          #c9f5d8;
    --text-muted:    #7fbf97;
    --text-dim:      #5e8f70;

    --accent:        #4ade80;
    --accent-hover:  #86efac;
    --accent-text:   #05130b;

    --border:        #1d3326;
    --shadow:        0 0 0 1px rgba(74, 222, 128, .07), 0 20px 50px rgba(0, 0, 0, .6);

    --ok:            #4ade80;
    --warn:          #fbbf24;
    --err:           #f87171;
    --ok-bg:         rgba(74, 222, 128, .10);
    --warn-bg:       rgba(251, 191, 36, .10);
    --err-bg:        rgba(248, 113, 113, .10);

    --mono-bg:       #04100a;
    --mono-fg:       #7cffb2;

    --radius:        10px;
    --radius-sm:     8px;
    --blur:          none;
}

/* --------------------------------------------------------------------------
   2. База
   -------------------------------------------------------------------------- */

html { min-height: 100%; }

body {
    background-color: var(--bg) !important;
    background-image: var(--bg-image) !important;
    background-attachment: fixed;
    color: var(--text);
    transition: background-color .25s ease, color .25s ease;
}

::selection { background: var(--accent); color: var(--accent-text); }

/* --------------------------------------------------------------------------
   3. Общие компоненты
   -------------------------------------------------------------------------- */

.card {
    background: var(--surface) !important;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    -webkit-backdrop-filter: var(--blur);
    backdrop-filter: var(--blur);
    color: var(--text);
}

.header {
    background: var(--header-bg) !important;
    color: var(--text) !important;
    border-bottom: 1px solid var(--border);
}

.header h1 { color: var(--text); }
.header h1 i { color: var(--accent) !important; }
.header p { color: var(--text-muted) !important; }

.content { color: var(--text); }

/* Внутренние блоки */
.param,
.stat-card,
.stat,
.chart-wrapper,
.log-card,
.form-section {
    background: var(--surface-2) !important;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.param:hover { background: var(--surface-3) !important; }

.param-label { color: var(--text) !important; }
.param-value { color: var(--accent) !important; }
.param-value small { color: var(--text-dim) !important; }
.param-value.old-data { color: var(--text-dim) !important; }

.metar {
    background: var(--mono-bg) !important;
    color: var(--mono-fg) !important;
    border: 1px solid var(--border);
}

.status { color: var(--text-muted); }
.online  { color: var(--ok) !important; }
.offline { color: var(--err) !important; }
.warning { color: var(--warn) !important; }

/* Баннеры */
.error-banner {
    background: var(--err-bg) !important;
    border-left-color: var(--err) !important;
    color: var(--text) !important;
}
.warning-banner {
    background: var(--warn-bg) !important;
    border-left-color: var(--warn) !important;
    color: var(--text) !important;
}

/* Подвал */
.footer {
    background: var(--surface-3) !important;
    color: var(--text-muted) !important;
    border-top: 1px solid var(--border);
}

/* Кнопки */
button {
    background: var(--accent);
    color: var(--accent-text);
    transition: background .15s, transform .15s, color .15s;
}
button:hover { background: var(--accent-hover); }

.logout-btn,
.clear-btn,
.btn-danger {
    background: var(--err) !important;
    color: #fff !important;
}
.logout-btn:hover,
.clear-btn:hover,
.btn-danger:hover { filter: brightness(1.08); }

.back-link {
    background: var(--accent) !important;
    color: var(--accent-text) !important;
}

.admin-badge {
    background: var(--err) !important;
    color: #fff !important;
}

/* --------------------------------------------------------------------------
   4. Главная страница
   -------------------------------------------------------------------------- */

#content > div[style*="text-align: center"] { color: var(--text-muted) !important; }

/* --------------------------------------------------------------------------
   5. Графики
   -------------------------------------------------------------------------- */

.stats { background: transparent !important; }

.stat-value { color: var(--accent) !important; }
.stat-label { color: var(--text-muted) !important; }

.weather-legend {
    background: var(--surface-3) !important;
    border-bottom: 1px solid var(--border) !important;
}
.legend-item { color: var(--text-muted); }
.legend-color { border: 1px solid var(--border); }

.chart-wrapper { padding: 15px; }
.chart-title { color: var(--text) !important; }

.period-switch { background: var(--chip-bg) !important; }
.period-btn { color: var(--text-muted) !important; }
.period-btn:hover { color: var(--text) !important; }
.period-btn.active {
    background: var(--accent) !important;
    color: var(--accent-text) !important;
}

.export-btn {
    background: var(--surface-2) !important;
    color: var(--text) !important;
    border: 1px solid var(--border);
}
.export-btn:hover { background: var(--surface-3) !important; }

.no-data { color: var(--text-muted) !important; }
.period-note { color: var(--text-dim) !important; }

/* --------------------------------------------------------------------------
   6. История посещений
   -------------------------------------------------------------------------- */

.stat {
    background: var(--chip-bg) !important;
    color: var(--text) !important;
}

.filters {
    background: var(--surface) !important;
    border-bottom: 1px solid var(--border) !important;
}
.filters select,
.filters input {
    background: var(--surface-2) !important;
    color: var(--text) !important;
    border: 1px solid var(--border) !important;
}
.filters select option { background: var(--surface-solid); color: var(--text); }
.filters button { background: var(--accent) !important; color: var(--accent-text) !important; }

.log-card { border-left: 4px solid var(--border); }
.log-card.success { border-left-color: var(--ok); }
.log-card.failed  { border-left-color: var(--err); }
.log-card.logout  { border-left-color: var(--text-dim); }

.log-time { color: var(--text-dim) !important; }
.log-details { color: var(--text) !important; }
.log-details span { background: var(--surface-3) !important; color: var(--text) !important; }
.log-details i { color: var(--accent) !important; }

.badge-success { background: var(--ok) !important; color: #04120c !important; }
.badge-failed  { background: var(--err) !important; color: #fff !important; }
.badge-logout  { background: var(--text-dim) !important; color: #fff !important; }

.empty-state { color: var(--text-muted) !important; }

/* --------------------------------------------------------------------------
   7. Вход
   -------------------------------------------------------------------------- */

.login-card {
    background: var(--surface) !important;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    border-radius: var(--radius);
    -webkit-backdrop-filter: var(--blur);
    backdrop-filter: var(--blur);
    color: var(--text);
}
.login-card h1 { color: var(--text) !important; }
.login-card p { color: var(--text-muted) !important; }

input {
    background: var(--surface-2) !important;
    color: var(--text) !important;
    border: 1px solid var(--border) !important;
}
input::placeholder { color: var(--text-dim); }
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.error { color: var(--err) !important; }
.info { color: var(--text-dim) !important; }

/* --------------------------------------------------------------------------
   8. Админ-панель
   -------------------------------------------------------------------------- */

.form-title { color: var(--text) !important; }
.form-group label { color: var(--text-muted) !important; }
.form-group input,
.form-group select {
    background: var(--surface-2) !important;
    color: var(--text) !important;
    border: 1px solid var(--border) !important;
}

.user-row {
    background: var(--surface-3) !important;
    border: 1px solid var(--border) !important;
}
.user-name { color: var(--text) !important; }
.user-role {
    background: var(--chip-bg) !important;
    color: var(--text-muted) !important;
}
.user-role.role-admin {
    background: var(--warn-bg) !important;
    color: var(--warn) !important;
}

.message { border-radius: var(--radius-sm); }
.message-success {
    background: var(--ok-bg) !important;
    color: var(--text) !important;
    border-left: 4px solid var(--ok);
}
.message-error {
    background: var(--err-bg) !important;
    color: var(--text) !important;
    border-left: 4px solid var(--err);
}

.btn-small { border-radius: 40px; }


/* Кнопки и плашки админки заданы inline — перекрываем адресно */
.user-actions a.btn-small {
    background: var(--accent) !important;
    color: var(--accent-text) !important;
}
.user-actions span[style*="e2e8f0"] {
    background: var(--surface-3) !important;
    color: var(--text-muted) !important;
    border: 1px solid var(--border);
}

/* Стрелка выпадающих списков: системная чёрная не видна на тёмном фоне */
.filters select,
.form-group select {
    -webkit-appearance: none;
    appearance: none;
    background-color: var(--surface-2) !important;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--text-muted) 50%),
        linear-gradient(135deg, var(--text-muted) 50%, transparent 50%) !important;
    background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50% !important;
    background-size: 5px 5px, 5px 5px !important;
    background-repeat: no-repeat !important;
    padding-right: 36px;
}

/* --------------------------------------------------------------------------
   9. Приборная панель: моноширинные цифры
   -------------------------------------------------------------------------- */

html[data-theme="panel"] .stat-value,
html[data-theme="panel"] .param-value,
html[data-theme="panel"] .metar,
html[data-theme="panel"] .log-time,
html[data-theme="panel"] .user-name {
    font-family: ui-monospace, 'SFMono-Regular', 'Courier New', monospace;
    letter-spacing: .02em;
}

html[data-theme="panel"] .card { border-radius: var(--radius); }

html[data-theme="panel"] .header h1 {
    text-transform: uppercase;
    letter-spacing: .08em;
    font-size: 1.05rem;
}

/* --------------------------------------------------------------------------
   10. Переключатель темы
   -------------------------------------------------------------------------- */

.theme-switch {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 9999;
    display: flex;
    gap: 4px;
    padding: 5px;
    background: var(--surface-solid);
    border: 1px solid var(--border);
    border-radius: 40px;
    box-shadow: var(--shadow);
    -webkit-backdrop-filter: var(--blur);
    backdrop-filter: var(--blur);
    opacity: .55;
    transition: opacity .2s ease;
}
.theme-switch:hover { opacity: 1; }

.theme-btn {
    width: 34px;
    height: 34px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent !important;
    color: var(--text-muted) !important;
    font-size: .95rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.theme-btn:hover { background: var(--surface-2) !important; }
.theme-btn svg { display: block; }

.theme-sep {
    width: 1px;
    height: 20px;
    align-self: center;
    background: var(--border);
    margin: 0 2px;
}
.theme-btn.active {
    background: var(--accent) !important;
    color: var(--accent-text) !important;
}

@media (max-width: 600px) {
    .theme-switch { right: 10px; bottom: 10px; opacity: .85; }
    .theme-btn { width: 30px; height: 30px; }
}

/* --------------------------------------------------------------------------
   11. Мобильный режим: вместо планки — одна круглая кнопка
   -------------------------------------------------------------------------- */

.cycle-btn { display: none !important; }

@media (max-width: 700px) {
    /* место под плавающую кнопку, чтобы она не перекрывала содержимое */
    body { padding-bottom: 84px !important; }

    .theme-switch {
        right: 12px;
        bottom: 12px;
        padding: 4px;
        border-radius: 50%;
        opacity: .55;
        transition: opacity .2s ease, transform .2s ease;
    }
    .theme-switch:active { opacity: 1; }

    .theme-switch .theme-btn,
    .theme-switch .theme-sep { display: none !important; }

    .theme-switch .cycle-btn {
        display: flex !important;
        width: 42px;
        height: 42px;
        font-size: 1.05rem;
        border-radius: 50%;
    }

    .theme-switch.is-hidden {
        opacity: 0 !important;
        pointer-events: none;
        transform: translateY(10px);
    }
}
