/* ── Themes ── */
:root, [data-theme="dark"] {
    --bg: #0f1117;
    --bg-surface: #161b22;
    --bg-surface-2: #1c2128;
    --border: #30363d;
    --border-row: #21262d;
    --text: #c9d1d9;
    --text-muted: #8b949e;
    --text-dim: #484f58;
    --accent: #58a6ff;
    --service-color: #79c0ff;
}
[data-theme="light"] {
    --bg: #f6f8fa;
    --bg-surface: #ffffff;
    --bg-surface-2: #f0f2f5;
    --border: #d0d7de;
    --border-row: #e8ecf0;
    --text: #1f2328;
    --text-muted: #57606a;
    --text-dim: #a0a7b0;
    --accent: #0969da;
    --service-color: #0550ae;
}

/* ── Reset ── */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', system-ui, sans-serif;
    font-size: 14px;
    transition: background 0.2s, color 0.2s;
}

/* ── Header ── */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 24px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-logo { width: 28px; height: 28px; flex-shrink: 0; }
.header-title {
    font-size: 18px; font-weight: 700;
    color: var(--accent); letter-spacing: 1px; text-decoration: none;
}
.header-title:hover { opacity: 0.85; }
.header-right { display: flex; gap: 14px; align-items: center; color: var(--text-muted); font-size: 13px; }
.user-name { color: var(--text-muted); }
.logout-link { color: var(--accent); text-decoration: none; }
.logout-link:hover { text-decoration: underline; }
.btn-nav {
    color: var(--text); text-decoration: none; font-size: 13px;
    padding: 4px 12px; border: 1px solid var(--border); border-radius: 6px;
    transition: border-color 0.15s, background 0.15s;
}
.btn-nav:hover { border-color: var(--accent); background: var(--bg-surface-2); }
#theme-toggle {
    background: none; border: 1px solid var(--border); border-radius: 6px;
    cursor: pointer; font-size: 16px; padding: 2px 8px; line-height: 1.6;
    transition: border-color 0.15s;
}
#theme-toggle:hover { border-color: var(--accent); }

/* ── Main ── */
main { padding: 16px 24px; }

/* ═══════════════════════════════════════════════════════════════════════════
   FILTER BAR + TABLE — общая сетка колонок:
   dt(170px) | svc(88px) | defcon(105px) | logtext(1fr) | other(215px) | reset(auto)
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Filter bar ── */
.filter-bar {
    display: grid;
    grid-template-columns: 170px 88px 105px 1fr 215px auto;
    align-items: end;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 6px 6px 0 0;
    border-bottom: none;
    padding: 10px 0;
}

.filter-spacer { /* пустая ячейка под # */ }

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 14px; /* совпадает с padding таблицы */
}
.filter-group label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    white-space: nowrap;
}
.filter-group input[type="text"] {
    width: 100%;
    background: var(--bg-surface-2);
    border: 1px solid var(--border);
    border-radius: 5px;
    color: var(--text);
    font-size: 13px;
    padding: 4px 8px;
    outline: none;
    transition: border-color 0.15s;
}
.filter-group input[type="text"]:focus { border-color: var(--accent); }

.filter-reset-group { justify-content: flex-end; }
.btn-reset {
    background: none; border: 1px solid var(--border); border-radius: 5px;
    color: var(--text-muted); cursor: pointer; font-size: 13px; padding: 4px 12px;
    transition: border-color 0.15s, color 0.15s; white-space: nowrap;
}
.btn-reset:hover { border-color: var(--accent); color: var(--text); }

/* ── Dropdown (сервис / критичность) ── */
.dropdown { position: relative; }
.dropdown-btn {
    width: 100%;
    background: var(--bg-surface-2); border: 1px solid var(--border); border-radius: 5px;
    color: var(--text); cursor: pointer; font-size: 13px; padding: 4px 8px;
    text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    transition: border-color 0.15s;
}
.dropdown-btn:hover, .dropdown.open .dropdown-btn { border-color: var(--accent); }
.dropdown-menu {
    display: none; position: absolute; top: calc(100% + 4px); left: 0;
    background: var(--bg-surface); border: 1px solid var(--border); border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.4); z-index: 100; min-width: 130px; padding: 4px 0;
}
.dropdown.open .dropdown-menu { display: block; }
.dd-item {
    display: flex; align-items: center; gap: 8px; padding: 5px 12px;
    cursor: pointer; font-size: 13px; transition: background 0.1s;
}
.dd-item:hover { background: var(--bg-surface-2); }
.dd-item input[type="checkbox"] { cursor: pointer; accent-color: var(--accent); }
.dd-item.defcon-High { color: #ff7b72; }
.dd-item.defcon-Std  { color: #e3b341; }
.dd-item.defcon-Low  { color: #7ee787; }
[data-theme="light"] .dd-item.defcon-High { color: #e5393d; }
[data-theme="light"] .dd-item.defcon-Std  { color: #d4920a; }
[data-theme="light"] .dd-item.defcon-Low  { color: #2da44e; }

/* ── Datepicker button ── */
.datepicker-wrap { position: relative; }
.datepicker-btn {
    display: flex; align-items: center; gap: 6px; width: 100%;
    background: var(--bg-surface-2); border: 1px solid var(--border); border-radius: 5px;
    color: var(--text); cursor: pointer; font-size: 13px; padding: 4px 8px;
    text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    transition: border-color 0.15s;
}
.datepicker-btn:hover { border-color: var(--accent); }

/* ── Results count ── */
.results-count {
    font-size: 12px; color: var(--text-muted);
    padding: 5px 0 4px 14px;
    min-height: 20px;
}

/* ── Table ── */
table {
    width: 100%; table-layout: fixed; border-collapse: collapse;
    background: var(--bg-surface); border: 1px solid var(--border);
    border-radius: 0 0 6px 6px;
}

/* Colgroup widths — зеркалят grid-template-columns filter-bar */
col.col-dt     { width: 170px; }
col.col-svc    { width: 88px; }
col.col-defcon { width: 105px; }
col.col-logtext { /* auto / 1fr */ }
col.col-other  { width: 215px; }

thead th {
    background: var(--bg-surface-2); padding: 8px 14px; text-align: left;
    color: var(--text-muted); font-weight: 600; border-bottom: 1px solid var(--border);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
tbody tr { border-bottom: 1px solid var(--border-row); transition: background 0.1s; }
tbody tr:hover { background: var(--bg-surface-2); }
tbody tr:last-child { border-bottom: none; }

td { padding: 8px 14px; vertical-align: top; overflow: hidden; }
td.dt { color: var(--text-muted); white-space: nowrap; font-family: monospace; font-size: 13px; }
td.service { color: var(--service-color); white-space: nowrap; }
td.logtext { word-break: break-word; }
td.otherinfo { color: var(--text-muted); word-break: break-word; font-size: 13px; }

/* ── Severity colors ── */
td.defcon { text-align: center; font-weight: bold; white-space: nowrap; }
tr.defcon-High td.defcon { color: #e5393d; }
tr.defcon-Std td.defcon  { color: #d4920a; }
tr.defcon-Low td.defcon  { color: #2da44e; }
[data-theme="dark"] tr.defcon-High td.defcon { color: #ff7b72; }
[data-theme="dark"] tr.defcon-Std td.defcon  { color: #e3b341; }
[data-theme="dark"] tr.defcon-Low td.defcon  { color: #7ee787; }
tr.defcon-High { border-left: 3px solid #e5393d; }
tr.defcon-Std  { border-left: 3px solid #d4920a; }
[data-theme="dark"] tr.defcon-High { border-left-color: #ff7b72; }
[data-theme="dark"] tr.defcon-Std  { border-left-color: #e3b341; }

td.empty { text-align: center; color: var(--text-dim); padding: 40px; }

/* ══════════════════════════════════════════════════════════════════════════
   CALENDAR POPUP — 3 месяца
   ══════════════════════════════════════════════════════════════════════════ */
.datepicker-popup {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 28px rgba(0,0,0,0.5);
    z-index: 200;
    width: 810px;
    padding: 0 0 12px 0;
    user-select: none;
    overflow: hidden;
}

.cal-months-container {
    display: grid;
    grid-template-columns: 1fr 1px 1fr 1px 1fr;
}
.cal-sep { background: var(--border); margin: 8px 0; }

.cal-month-panel { padding: 14px 12px 8px; }

.cal-header {
    display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px;
}
.cal-month-label { font-size: 13px; font-weight: 600; color: var(--text); }
.cal-nav {
    background: none; border: 1px solid transparent; border-radius: 5px;
    color: var(--text-muted); cursor: pointer; font-size: 18px; line-height: 1;
    width: 26px; height: 26px; display: flex; align-items: center; justify-content: center;
    transition: border-color 0.15s, color 0.15s;
}
.cal-nav:hover { border-color: var(--border); color: var(--text); }
.cal-nav-ph { width: 26px; height: 26px; } /* placeholder для выравнивания */

.cal-weekdays {
    display: grid; grid-template-columns: repeat(7, 1fr); margin-bottom: 2px;
}
.cal-weekdays span {
    text-align: center; font-size: 11px; color: var(--text-muted); padding: 2px 0 5px;
}
.cal-weekdays .weekend { color: var(--text-dim); }

.cal-body { cursor: pointer; }
.cal-row { display: grid; grid-template-columns: repeat(7, 1fr); }

.cal-day {
    position: relative; text-align: center; font-size: 12px; color: var(--text);
    padding: 5px 0; border-radius: 0; z-index: 1;
}
.cal-day.weekend { color: var(--text-muted); }
.cal-day.cal-empty { pointer-events: none; }

/* Today dot */
.cal-day.today::after {
    content: ''; position: absolute; bottom: 2px; left: 50%; transform: translateX(-50%);
    width: 3px; height: 3px; border-radius: 50%; background: var(--accent);
}

/* Plain hover */
.cal-day:not(.range-start):not(.range-end):not(.in-range):not(.cal-empty):hover {
    background: var(--bg-surface-2); border-radius: 50%;
}

/* Filled circle: start / end / hover-preview */
.cal-day.range-start::before,
.cal-day.range-end::before,
.cal-day.hover-preview::before {
    content: ''; position: absolute; inset: 1px; border-radius: 50%;
    background: var(--accent); z-index: -1;
}
.cal-day.range-start,
.cal-day.range-end,
.cal-day.hover-preview { color: #fff !important; font-weight: 600; }
.cal-day.hover-preview::before { opacity: 0.6; }

/* Single day */
.cal-day.single-day::before {
    content: ''; position: absolute; inset: 1px; border-radius: 50%;
    background: var(--accent); z-index: -1;
}
.cal-day.single-day { background: none !important; color: #fff !important; font-weight: 600; }

/* Range fill */
.cal-day.in-range {
    background: color-mix(in srgb, var(--accent) 16%, transparent);
    border-radius: 0;
}

/* Half-bg caps at start/end of range */
.cal-row .cal-day.range-start:not(.single-day) {
    background: linear-gradient(to right,
        transparent 50%,
        color-mix(in srgb, var(--accent) 16%, transparent) 50%);
}
.cal-row .cal-day.range-end:not(.single-day),
.cal-row .cal-day.hover-preview:not(.range-start) {
    background: linear-gradient(to left,
        transparent 50%,
        color-mix(in srgb, var(--accent) 16%, transparent) 50%);
}

/* Rounded ends on in-range rows */
.cal-row .cal-day.in-range:first-child { border-radius: 50% 0 0 50%; }
.cal-row .cal-day.in-range:last-child  { border-radius: 0 50% 50% 0; }

/* Calendar footer */
.cal-footer {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 14px 0;
    border-top: 1px solid var(--border);
    margin-top: 4px;
}
.cal-foot-btn {
    background: none; border: 1px solid var(--border); border-radius: 5px;
    color: var(--text-muted); cursor: pointer; font-size: 12px; padding: 3px 10px;
    transition: border-color 0.15s, color 0.15s;
}
.cal-foot-btn:hover { border-color: var(--accent); color: var(--text); }
.cal-clear { color: #cf222e !important; border-color: rgba(207,34,46,.3) !important; }
.cal-clear:hover { border-color: #cf222e !important; }
.cal-hint { font-size: 11px; color: var(--text-muted); margin-left: auto; opacity: 0.7; }

/* ── Login page ── */
.login-wrap {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; min-height: 100vh; gap: 16px;
}
.login-wrap h1 { font-size: 32px; color: var(--accent); letter-spacing: 2px; }
.login-wrap p { color: var(--text-muted); margin-bottom: 8px; }
.btn-google {
    display: flex; align-items: center; gap: 10px; background: #fff; color: #3c4043;
    font-weight: 500; font-size: 14px; padding: 10px 20px; border-radius: 4px;
    text-decoration: none; transition: box-shadow 0.15s;
}
.btn-google:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.4); }

/* ── Admin page ── */
.admin-wrap { max-width: 900px; margin: 32px auto; padding: 0 24px; }
.admin-wrap h2 {
    font-size: 20px; color: var(--accent); margin-bottom: 20px;
    padding-bottom: 10px; border-bottom: 1px solid var(--border);
}
.admin-section {
    background: var(--bg-surface); border: 1px solid var(--border);
    border-radius: 6px; padding: 20px; margin-bottom: 20px;
}
.admin-section h3 { font-size: 15px; color: var(--text); margin-bottom: 14px; }
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th {
    text-align: left; color: var(--text-muted); font-size: 12px; text-transform: uppercase;
    padding: 6px 10px; border-bottom: 1px solid var(--border);
}
.admin-table td { padding: 8px 10px; border-bottom: 1px solid var(--border-row); font-size: 13px; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-td-muted { color: var(--text-muted); font-family: monospace; font-size: 13px; }
.admin-td-action { width: 40px; text-align: center; }
.admin-td-empty { color: var(--text-dim); padding: 20px; text-align: center; }

.btn-delete {
    background: none; border: none; cursor: pointer;
    color: var(--text-dim); font-size: 15px; font-weight: 600;
    width: 26px; height: 26px; border-radius: 4px; line-height: 1;
    transition: color 0.15s, background 0.15s;
}
.btn-delete:hover { color: #e5393d; background: rgba(229,57,61,.1); }

/* Add form */
.admin-add-form { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.admin-add-fields { display: flex; gap: 12px; flex: 1; min-width: 0; flex-wrap: wrap; }
.admin-field { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 180px; }
.admin-field label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; }
.admin-field input {
    background: var(--bg-surface-2); border: 1px solid var(--border); border-radius: 5px;
    color: var(--text); font-size: 13px; padding: 6px 10px; outline: none;
    transition: border-color 0.15s;
}
.admin-field input:focus { border-color: var(--accent); }

.btn-add {
    background: var(--accent); border: none; border-radius: 5px; color: #fff;
    cursor: pointer; font-size: 13px; font-weight: 500; padding: 6px 18px;
    white-space: nowrap; transition: opacity 0.15s;
}
.btn-add:hover { opacity: 0.85; }

/* ── Pagination widget (fixed bottom-right) ── */
.pagination-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    align-items: center;
    gap: 2px;
    background: color-mix(in srgb, var(--bg-surface) 85%, transparent);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px;
    box-shadow: 0 2px 16px rgba(0,0,0,0.25);
    z-index: 500;
}
.pag-btn {
    display: flex; align-items: center; justify-content: center;
    width: 30px; height: 30px;
    background: none; border: none; border-radius: 5px;
    color: var(--text-muted); cursor: pointer; font-size: 18px; line-height: 1;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}
.pag-btn:hover { background: var(--bg-surface-2); color: var(--text); }
.pag-btn.pag-disabled { opacity: 0.25; cursor: default; pointer-events: none; }
.pag-info { font-size: 12px; color: var(--text-muted); padding: 0 4px; white-space: nowrap; }
.pag-sep { width: 1px; height: 18px; background: var(--border); margin: 0 2px; flex-shrink: 0; }

/* Alerts */
.admin-alert {
    border-radius: 6px; font-size: 13px; margin-bottom: 16px; padding: 10px 14px;
    border: 1px solid;
}
.admin-alert-error   { background: rgba(229,57,61,.1);  border-color: rgba(229,57,61,.4);  color: #e5393d; }
.admin-alert-success { background: rgba(45,164,78,.1);  border-color: rgba(45,164,78,.4);  color: #2da44e; }
