:root {
    color-scheme: light;
    --bg: #f3f5f4;
    --sidebar: #111c19;
    --sidebar-soft: #1a2b26;
    --surface: #ffffff;
    --surface-soft: #edf3f1;
    --text: #17201c;
    --muted: #65736d;
    --line: #dbe4df;
    --accent: #0f766e;
    --accent-strong: #0b5d56;
    --blue: #2454a6;
    --shadow: 0 16px 42px rgba(21, 36, 31, 0.09);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--text);
}

button,
input,
select {
    font: inherit;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: radial-gradient(circle at 50% 20%, #214840 0, #111b18 42%, #0d1211 100%);
}

.login-shell {
    width: min(360px, calc(100vw - 32px));
}

.login-form {
    display: grid;
    gap: 14px;
}

.login-logo {
    width: 182px;
    height: auto;
    justify-self: center;
    margin-bottom: 18px;
}

.login-input,
.login-button,
.select {
    border: 1px solid transparent;
    border-radius: 8px;
}

.text-input {
    height: 40px;
    min-width: 220px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
}

.primary-button {
    min-height: 40px;
    padding: 0 14px;
    border: 0;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    font-weight: 700;
}

.login-input {
    width: 100%;
    height: 48px;
    padding: 0 16px;
    background: rgba(255, 255, 255, 0.96);
    color: #0f1715;
    outline: none;
}

.login-input:focus,
.select:focus {
    border-color: #66c4b9;
    box-shadow: 0 0 0 3px rgba(102, 196, 185, 0.24);
}

.login-button {
    height: 48px;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    font-weight: 700;
}

.login-error {
    color: #ffd9d9;
    text-align: center;
    min-height: 24px;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 18px 14px;
    background: var(--sidebar);
    color: #eaf2ef;
}

.brand {
    display: grid;
    gap: 10px;
    align-items: center;
    color: inherit;
    text-decoration: none;
    padding: 8px 10px 22px;
}

.brand img {
    width: 136px;
    height: auto;
}

.brand span {
    color: #9fb4ad;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.side-nav {
    display: grid;
    gap: 5px;
}

.side-bottom {
    display: grid;
    gap: 5px;
    margin-top: auto;
}

.nav-item {
    width: 100%;
    min-height: 42px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #dce8e4;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.nav-item::before {
    content: "";
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    background: currentColor;
    mask: var(--icon-url) center / contain no-repeat;
    -webkit-mask: var(--icon-url) center / contain no-repeat;
    opacity: 0.9;
}

.nav-item[data-icon="activity"] { --icon-url: url("/assets/vendor/lucide-icons/activity.svg"); }
.nav-item[data-icon="chart-line"] { --icon-url: url("/assets/vendor/lucide-icons/chart-line.svg"); }
.nav-item[data-icon="file-text"] { --icon-url: url("/assets/vendor/lucide-icons/file-text.svg"); }
.nav-item[data-icon="globe-2"] { --icon-url: url("/assets/vendor/lucide-icons/globe-2.svg"); }
.nav-item[data-icon="monitor"] { --icon-url: url("/assets/vendor/lucide-icons/monitor.svg"); }
.nav-item[data-icon="settings"] { --icon-url: url("/assets/vendor/lucide-icons/settings.svg"); }
.nav-item[data-icon="log-out"] { --icon-url: url("/assets/vendor/lucide-icons/log-out.svg"); }

.nav-item:hover,
.nav-item.is-active {
    background: var(--sidebar-soft);
    color: #fff;
}

.workspace {
    min-width: 0;
    padding: 24px;
}

.workspace-header {
    min-height: 72px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
}

.filters {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.toggle-filter {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    font-size: 14px;
    cursor: pointer;
}

.toggle-filter input {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

.select {
    min-width: 162px;
    height: 40px;
    padding: 0 34px 0 12px;
    background: #fff;
    color: var(--text);
    border-color: var(--line);
}

.kicker {
    margin: 0 0 5px;
    color: var(--accent-strong);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

h1,
h2 {
    margin: 0;
    line-height: 1.15;
}

h1 {
    font-size: clamp(28px, 4vw, 42px);
}

h2 {
    font-size: 19px;
}

.view {
    display: none;
}

.view.is-active {
    display: block;
}

.section-head {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 14px;
}

.meta {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
}

.metric-row {
    display: grid;
    grid-template-columns: repeat(5, minmax(136px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.metric {
    min-height: 92px;
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.metric span {
    display: block;
    color: var(--muted);
    font-size: 13px;
}

.metric strong {
    display: block;
    margin-top: 8px;
    font-size: clamp(22px, 2.4vw, 34px);
}

.live-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(380px, 0.85fr);
    gap: 16px;
}

.map-panel,
.table-panel,
.chart {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.map-panel {
    position: relative;
    min-height: 560px;
    overflow: hidden;
}

.live-map {
    width: 100%;
    height: 560px;
    background: #dfe9e5;
}

.visitor-marker {
    min-width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    padding: 0 7px;
    border: 3px solid #fff;
    border-radius: 999px;
    background: var(--marker-bg, var(--accent));
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    box-shadow: 0 8px 22px rgba(11, 43, 39, 0.28);
}

.visitor-marker.marker-human {
    --marker-bg: #0f766e;
}

.visitor-marker.marker-crawler {
    --marker-bg: #2454a6;
}

.visitor-marker.marker-bot {
    --marker-bg: #b45309;
}

.visitor-marker.marker-unknown {
    --marker-bg: #64748b;
}

.visitor-marker.marker-mixed {
    border-color: #f8fafc;
}

.traffic-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    max-width: 180px;
    padding: 4px 8px;
    border-radius: 999px;
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    vertical-align: middle;
}

.traffic-badge small {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
    font-weight: 700;
    opacity: 0.92;
}

.consent-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: 6px;
    padding: 4px 7px;
    border-radius: 999px;
    background: #25634c;
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
    vertical-align: middle;
}

.consent-badge small {
    font-size: 10px;
    font-weight: 700;
    opacity: 0.9;
}

.signal-stack {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.signal-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 7px;
    border-radius: 999px;
    color: #fff;
    font-size: 11px;
    font-weight: 800;
    line-height: 1;
}

.signal-badge small {
    font-size: 10px;
    font-weight: 800;
    opacity: 0.92;
}

.signal-session { background: #64748b; }
.signal-low { background: #0f766e; }
.signal-medium { background: #8a4b0f; }
.signal-high { background: #8f1d2c; }

.traffic-human { background: #0f766e; }
.traffic-crawler { background: #2454a6; }
.traffic-bot { background: #b45309; }
.traffic-unknown { background: #64748b; }

.map-legend {
    position: absolute;
    left: 12px;
    bottom: 26px;
    z-index: 2;
    display: flex;
    flex-wrap: wrap;
    gap: 8px 12px;
    max-width: calc(100% - 24px);
    padding: 8px 10px;
    border: 1px solid rgba(219, 228, 223, 0.9);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.94);
    color: var(--text);
    font-size: 12px;
    font-weight: 700;
    box-shadow: 0 10px 28px rgba(21, 36, 31, 0.12);
}

.map-legend span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    display: inline-block;
}

.legend-human { background: #0f766e; }
.legend-crawler { background: #2454a6; }
.legend-bot { background: #b45309; }
.legend-unknown { background: #64748b; }
.legend-mixed { background: conic-gradient(#0f766e 0 90deg, #2454a6 90deg 180deg, #b45309 180deg 270deg, #64748b 270deg 360deg); }

.table-panel {
    min-width: 0;
    padding: 16px;
}

.table-panel h2 {
    margin-bottom: 12px;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

th,
td {
    padding: 10px 9px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

th {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

td.number,
th.number {
    text-align: right;
}

.flag {
    width: 24px;
    height: 18px;
    object-fit: cover;
    border-radius: 3px;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
    vertical-align: middle;
    margin-right: 8px;
}

.chart {
    min-height: 330px;
    padding: 14px;
}

.chart svg {
    width: 100%;
    height: 300px;
    display: block;
}

.split {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.thirds {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.empty,
.loading {
    margin: 0;
    color: var(--muted);
    padding: 16px 0;
}

.loading-panel {
    grid-column: 1 / -1;
    min-height: 96px;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
}

.chart .loading-panel,
.table-wrap .loading-panel,
.settings-grid .loading-panel {
    min-height: 120px;
    box-shadow: none;
}

.spinner {
    width: 28px;
    height: 28px;
    flex: 0 0 28px;
    border: 3px solid #c7d4ce;
    border-top-color: var(--accent);
    border-radius: 999px;
    animation: spin 0.8s linear infinite;
}

.loading-panel strong,
.loading-panel small {
    display: block;
}

.loading-panel small {
    margin-top: 4px;
    color: var(--muted);
    font-size: 13px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.path-cell,
.source-cell {
    max-width: 430px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.domain-path {
    min-width: 0;
}

.domain-path strong,
.domain-path small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.domain-path strong {
    font-size: 13px;
}

.domain-path small {
    margin-top: 3px;
    color: var(--muted);
    font-size: 11px;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(180px, 1fr));
    gap: 12px;
}

.settings-panel {
    margin-top: 16px;
}

.exclusion-form {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin: 0 0 14px;
}

.link-button {
    border: 0;
    background: transparent;
    color: var(--accent-strong);
    cursor: pointer;
    font-weight: 700;
    padding: 0;
}

.setting-tile {
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
}

.setting-tile span {
    display: block;
    color: var(--muted);
    font-size: 13px;
}

.setting-tile strong {
    display: block;
    margin-top: 6px;
    font-size: 18px;
}

@media (max-width: 1120px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
        flex-direction: row;
        align-items: center;
        gap: 10px;
        overflow-x: auto;
    }

    .brand {
        padding: 6px 10px;
        min-width: 155px;
    }

    .side-nav,
    .side-bottom {
        display: flex;
        gap: 6px;
        margin: 0;
    }

    .nav-item {
        white-space: nowrap;
    }

    .workspace-header,
    .live-grid,
    .split,
    .thirds {
        grid-template-columns: 1fr;
    }

    .live-grid {
        display: grid;
    }
}

@media (max-width: 760px) {
    .workspace {
        padding: 16px;
    }

    .workspace-header {
        flex-direction: column;
    }

    .filters,
    .select,
    .toggle-filter,
    .text-input,
    .primary-button {
        width: 100%;
    }

    .metric-row,
    .settings-grid {
        grid-template-columns: 1fr;
    }

    .map-panel,
    .live-map {
        min-height: 380px;
        height: 380px;
    }
}
