:root {
    color-scheme: light;
    --bg: #f7f8fb;
    --panel: #ffffff;
    --panel-soft: #f1f5f9;
    --text: #18202f;
    --muted: #677084;
    --line: #e3e7ee;
    --primary: #2563eb;
    --primary-strong: #1d4ed8;
    --success: #0f9f6e;
    --danger: #d64545;
    --warning: #c47a00;
    --shadow: 0 14px 36px rgba(24, 32, 47, 0.08);
}

html[data-theme="dark"] {
    color-scheme: dark;
    --bg: #101217;
    --panel: #181b22;
    --panel-soft: #202530;
    --text: #edf1f7;
    --muted: #a6afc0;
    --line: #2a303b;
    --primary: #6ea8ff;
    --primary-strong: #8bb8ff;
    --shadow: 0 14px 36px rgba(0, 0, 0, 0.24);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    letter-spacing: 0;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
select,
textarea {
    font: inherit;
}

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

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 24px 18px;
    background: var(--panel);
    border-right: 1px solid var(--line);
}

.brand,
.nav a,
.topbar,
.panel-head,
.topbar-actions {
    display: flex;
    align-items: center;
}

.brand {
    gap: 10px;
    font-weight: 800;
    margin-bottom: 34px;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    color: #fff;
    background: linear-gradient(135deg, #2563eb, #0f9f6e);
}

.nav {
    display: grid;
    gap: 6px;
}

.nav a {
    min-height: 42px;
    padding: 0 12px;
    border-radius: 8px;
    color: var(--muted);
    font-weight: 650;
}

.nav a.active,
.nav a:hover {
    color: var(--text);
    background: var(--panel-soft);
}

.logout-form {
    position: absolute;
    left: 18px;
    right: 18px;
    bottom: 20px;
}

.main {
    min-width: 0;
    padding: 28px;
}

.topbar {
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 24px;
}

.topbar h1,
.analysis-band h2,
.chart-panel h3,
.settings-panel h2,
.table-panel h2,
.table-panel h3 {
    margin: 0;
}

.topbar h1 {
    font-size: clamp(24px, 3vw, 34px);
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--primary);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.topbar-actions {
    gap: 10px;
}

.user-pill,
.status {
    padding: 7px 10px;
    border-radius: 999px;
    background: var(--panel-soft);
    color: var(--muted);
    font-size: 13px;
}

.analysis-band {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 22px;
    align-items: center;
    padding: 22px;
    margin-bottom: 18px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.analysis-list {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    padding: 0;
    margin: 0;
    list-style: none;
}

.analysis-list li {
    padding: 12px;
    border-radius: 8px;
    background: var(--panel-soft);
    color: var(--text);
    font-size: 14px;
}

.filter-bar {
    display: grid;
    grid-template-columns: repeat(7, minmax(130px, 1fr));
    gap: 12px;
    align-items: end;
    padding: 16px;
    margin-bottom: 18px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    min-height: 40px;
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--text);
}

select[multiple] {
    min-height: 40px;
    max-height: 92px;
}

.primary-button,
.secondary-button,
.ghost-button,
.icon-button {
    display: inline-grid;
    place-items: center;
    min-height: 40px;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 800;
}

.primary-button {
    padding: 0 16px;
    color: #fff;
    background: var(--primary);
}

.primary-button:hover {
    background: var(--primary-strong);
}

.secondary-button,
.ghost-button {
    padding: 0 14px;
    color: var(--text);
    background: var(--panel-soft);
}

.icon-button {
    width: 40px;
    color: var(--muted);
    background: var(--panel-soft);
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

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

.metric-card {
    padding: 18px;
}

.metric-card .label {
    color: var(--muted);
    font-size: 13px;
    font-weight: 750;
}

.metric-card .value {
    margin: 8px 0 10px;
    font-size: clamp(24px, 4vw, 34px);
    font-weight: 850;
}

.metric-card .changes {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    color: var(--muted);
    font-size: 12px;
}

.change-up {
    color: var(--success);
}

.change-down {
    color: var(--danger);
}

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

.chart-panel {
    min-height: 340px;
    padding: 16px;
}

.chart-panel.wide {
    grid-column: 1 / -1;
}

.panel-head {
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.chart-panel canvas {
    width: 100%;
    max-height: 270px;
}

.weekday-heatmap {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 10px;
}

.heat-cell {
    min-height: 86px;
    padding: 12px;
    border-radius: 8px;
    background: var(--panel-soft);
}

.heat-cell strong {
    display: block;
    margin-bottom: 8px;
}

.heat-cell span {
    display: block;
    color: var(--muted);
    font-size: 12px;
}

.table-panel {
    margin-top: 16px;
    padding: 16px;
}

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

table {
    width: 100%;
    border-collapse: collapse;
    white-space: nowrap;
}

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

th {
    color: var(--muted);
    font-size: 12px;
    cursor: pointer;
}

.muted {
    color: var(--muted);
}

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

.settings-panel {
    display: grid;
    gap: 14px;
    padding: 18px;
}

.notice {
    margin-bottom: 16px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    font-weight: 750;
}

.notice.success {
    border-color: color-mix(in srgb, var(--success), var(--line) 68%);
    color: var(--success);
}

.saved-badge {
    display: inline-flex;
    align-items: center;
    justify-self: start;
    min-height: 22px;
    margin-left: 8px;
    padding: 2px 8px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--success), transparent 86%);
    color: var(--success);
    font-size: 12px;
    font-weight: 800;
    vertical-align: middle;
}

.saved-badge.empty {
    background: var(--panel-soft);
    color: var(--muted);
}

.masked-value {
    display: inline-flex;
    align-items: center;
    justify-self: start;
    min-height: 22px;
    margin-left: 8px;
    padding: 2px 8px;
    border-radius: 6px;
    background: var(--panel-soft);
    color: var(--muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 12px;
    font-weight: 850;
    letter-spacing: 0;
    vertical-align: middle;
}

.settings-panel.narrow {
    max-width: 720px;
    margin-top: 16px;
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.checkbox-row input {
    width: auto;
    min-height: auto;
}

.status.success {
    color: var(--success);
}

.status.failed {
    color: var(--danger);
}

.chart-modal {
    width: min(1120px, calc(100vw - 36px));
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--text);
}

.modal-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.chart-modal canvas {
    width: 100%;
    min-height: 520px;
}

.guest-body {
    display: grid;
    place-items: center;
    padding: 28px;
}

.login-panel {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(320px, 420px);
    gap: 36px;
    align-items: center;
    width: min(980px, 100%);
}

.login-copy h1 {
    margin: 0 0 14px;
    font-size: clamp(34px, 6vw, 58px);
    line-height: 1.05;
}

.login-copy p:last-child {
    color: var(--muted);
    font-size: 17px;
    line-height: 1.8;
}

.login-card {
    display: grid;
    gap: 16px;
    padding: 24px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.form-error {
    margin: 0;
    padding: 10px;
    border-radius: 8px;
    color: var(--danger);
    background: rgba(214, 69, 69, 0.1);
}

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

    .sidebar {
        position: static;
        height: auto;
        display: flex;
        gap: 14px;
        align-items: center;
        overflow-x: auto;
    }

    .brand {
        margin: 0;
    }

    .nav {
        display: flex;
    }

    .logout-form {
        position: static;
        margin-left: auto;
    }

    .filter-bar,
    .analysis-band {
        grid-template-columns: 1fr 1fr;
    }

    .analysis-list {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 760px) {
    .main {
        padding: 18px;
    }

    .topbar,
    .sidebar,
    .login-panel {
        align-items: stretch;
        flex-direction: column;
        grid-template-columns: 1fr;
    }

    .filter-bar,
    .analysis-band,
    .analysis-list,
    .card-grid,
    .chart-grid,
    .settings-grid,
    .weekday-heatmap {
        grid-template-columns: 1fr;
    }

    .chart-panel {
        min-height: 300px;
    }
}
