:root {
    color-scheme: dark;
    --bg: #07101f;
    --surface: #0e1a2d;
    --surface-2: #13213a;
    --border: rgba(148, 163, 184, .16);
    --text: #e5edf8;
    --muted: #91a2b9;
    --primary: #6366f1;
    --primary-hover: #7c7ff3;
    --success: #14b8a6;
    --danger: #fb7185;
    --shadow: 0 18px 55px rgba(0, 0, 0, .24);
}

* { box-sizing: border-box; }
html { font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
body { margin: 0; min-height: 100vh; background: radial-gradient(circle at 10% 0%, rgba(99, 102, 241, .13), transparent 35%), var(--bg); }
a { color: inherit; }
button, input, select { font: inherit; }
code { color: #c4b5fd; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.eyebrow { margin: 0 0 .45rem; text-transform: uppercase; letter-spacing: .14em; font-size: .72rem; font-weight: 800; color: #a5b4fc; }
.muted { color: var(--muted); line-height: 1.65; }
.break-word { overflow-wrap: anywhere; word-break: break-word; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { text-align: center; color: var(--muted); padding: 2rem !important; }

.button { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; min-height: 44px; padding: .72rem 1rem; border: 0; border-radius: 10px; background: var(--primary); color: white; font-weight: 750; text-decoration: none; cursor: pointer; transition: .18s ease; }
.button:hover { background: var(--primary-hover); transform: translateY(-1px); }
.button.secondary { background: rgba(148, 163, 184, .1); border: 1px solid var(--border); }
.button.secondary:hover { background: rgba(148, 163, 184, .17); }
.button.compact { min-height: 38px; padding: .55rem .8rem; border-radius: 8px; font-size: .88rem; }
.button.full { width: 100%; }
.text-link { display: block; margin-top: 1.2rem; color: #a5b4fc; text-align: center; text-decoration: none; }
.text-link:hover { text-decoration: underline; }

.auth-page, .public-page { display: grid; place-items: center; padding: 1.25rem; }
.auth-card, .public-card { width: min(100%, 520px); padding: clamp(1.4rem, 4vw, 2.5rem); border: 1px solid var(--border); border-radius: 20px; background: rgba(14, 26, 45, .92); box-shadow: var(--shadow); backdrop-filter: blur(16px); }
.auth-card h1, .public-card h1 { margin: 0; font-size: clamp(1.7rem, 4vw, 2.35rem); letter-spacing: -.04em; }
.auth-card form { display: grid; gap: 1rem; margin-top: 1.4rem; }
label { display: grid; gap: .42rem; color: #cbd5e1; font-size: .88rem; font-weight: 650; }
input, select { width: 100%; border: 1px solid var(--border); border-radius: 9px; background: rgba(7, 16, 31, .74); color: var(--text); padding: .68rem .75rem; outline: none; }
input:focus, select:focus { border-color: rgba(99, 102, 241, .8); box-shadow: 0 0 0 3px rgba(99, 102, 241, .14); }
.alert { margin: 1.1rem 0; padding: .85rem 1rem; border-radius: 10px; line-height: 1.5; }
.alert.error { color: #fecdd3; background: rgba(190, 24, 93, .16); border: 1px solid rgba(251, 113, 133, .25); }
.alert.success { color: #99f6e4; background: rgba(13, 148, 136, .15); border: 1px solid rgba(45, 212, 191, .24); }
.alert.info { color: #bfdbfe; background: rgba(37, 99, 235, .14); border: 1px solid rgba(96, 165, 250, .24); }
.visitor-details { margin: 1.5rem 0; display: grid; gap: .8rem; }
.visitor-details div { padding: .9rem 1rem; border: 1px solid var(--border); border-radius: 10px; background: rgba(7, 16, 31, .46); }
.visitor-details dt { color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; }
.visitor-details dd { margin: .35rem 0 0; line-height: 1.5; }

.topbar { position: sticky; top: 0; z-index: 20; min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .85rem max(1rem, calc((100vw - 1500px) / 2)); border-bottom: 1px solid var(--border); background: rgba(7, 16, 31, .86); backdrop-filter: blur(18px); }
.topbar h1 { margin: 0; font-size: 1.18rem; letter-spacing: -.02em; }
.topbar-actions { display: flex; align-items: center; gap: .8rem; }
.topbar-actions form { margin: 0; }
.admin-name { color: var(--muted); font-size: .88rem; }
.dashboard-shell { width: min(1500px, calc(100% - 2rem)); margin: 0 auto; padding: 1.4rem 0 3rem; }
.panel { border: 1px solid var(--border); border-radius: 15px; background: rgba(14, 26, 45, .84); box-shadow: 0 12px 38px rgba(0, 0, 0, .14); }
.toolbar { display: flex; justify-content: space-between; gap: 1rem; padding: .9rem; }
.filter-form, .toolbar-actions { display: flex; align-items: end; flex-wrap: wrap; gap: .7rem; }
.filter-form label { min-width: 120px; }
.filter-form .custom-date { display: none; }
.filter-form .custom-date.visible { display: grid; }
.period-label { margin: .9rem .2rem; color: var(--muted); font-size: .9rem; }

.kpi-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: .85rem; }
.kpi-card { min-width: 0; padding: 1rem; border: 1px solid var(--border); border-radius: 14px; background: linear-gradient(155deg, rgba(19, 33, 58, .92), rgba(14, 26, 45, .8)); }
.kpi-card span { display: block; color: var(--muted); font-size: .78rem; font-weight: 700; }
.kpi-card strong { display: block; margin: .45rem 0 .3rem; font-size: clamp(1.35rem, 2.4vw, 2rem); letter-spacing: -.045em; font-variant-numeric: tabular-nums; }
.kpi-card small { display: block; color: #71839d; font-size: .72rem; line-height: 1.4; }

.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem; margin-top: .9rem; }
.chart-card { min-width: 0; padding: 1rem; }
.chart-wide { grid-column: 1 / -1; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .85rem; }
.panel-heading h2 { margin: 0; font-size: 1rem; letter-spacing: -.015em; }
.panel-heading p { margin: .25rem 0 0; color: var(--muted); font-size: .78rem; line-height: 1.45; }
.chart-container { position: relative; height: 310px; }
.chart-container.tall { height: 360px; }

.data-grid { display: grid; grid-template-columns: 1.2fr 1fr .8fr; gap: .9rem; margin-top: .9rem; }
.table-card { min-width: 0; padding: 1rem; }
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: .82rem; }
th, td { padding: .7rem .75rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { position: sticky; top: 0; z-index: 1; background: #13213a; color: #aebdd1; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: rgba(148, 163, 184, .035); }
.logs-panel { margin-top: .9rem; padding: 1rem; }
.logs-heading { align-items: end; }
.search-field { width: min(320px, 100%); }
.wide-table { max-height: 620px; }
.wide-table table { min-width: 1420px; }
.ua-cell { max-width: 420px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.storage-status { margin-top: .9rem; padding: 1rem; display: grid; grid-template-columns: repeat(3, 1fr); gap: .8rem; }
.storage-status div { display: flex; justify-content: space-between; gap: .8rem; padding: .8rem; border-radius: 9px; background: rgba(7, 16, 31, .45); }
.storage-status span { color: var(--muted); }

@media (max-width: 1180px) {
    .kpi-grid { grid-template-columns: repeat(3, 1fr); }
    .data-grid { grid-template-columns: 1fr 1fr; }
    .data-grid .table-card:last-child { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
    .topbar { position: static; }
    .admin-name { display: none; }
    .dashboard-shell { width: min(100% - 1rem, 1500px); padding-top: .7rem; }
    .toolbar { align-items: stretch; }
    .toolbar, .filter-form, .toolbar-actions { flex-direction: column; }
    .toolbar-actions .button, .filter-form .button { width: 100%; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .chart-grid, .data-grid { grid-template-columns: 1fr; }
    .chart-wide, .data-grid .table-card:last-child { grid-column: auto; }
    .chart-container, .chart-container.tall { height: 290px; }
    .logs-heading { align-items: stretch; flex-direction: column; }
    .search-field { width: 100%; }
    .storage-status { grid-template-columns: 1fr; }
}
@media (max-width: 440px) {
    .kpi-grid { grid-template-columns: 1fr; }
    .topbar { padding: .75rem; }
}
