:root {
    color-scheme: dark;
    --background: #11151c;
    --surface: #1a202a;
    --surface-soft: #202734;
    --border: rgba(255, 255, 255, 0.09);
    --text: #f5f7fa;
    --muted: #98a3b3;
    --accent: #52d3b0;
    --accent-soft: rgba(82, 211, 176, 0.14);
    --danger-1: #ff4b3e;
    --danger-2: #e7857d;
    --positive-1: #58b7a2;
    --positive-2: #5db362;
    --neutral: #97979a;
    --shadow: 0 18px 45px rgba(0, 0, 0, 0.24);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--background);
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
        "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at top right, rgba(82, 211, 176, 0.08), transparent 32rem),
        var(--background);
    color: var(--text);
}

button,
select,
input {
    font: inherit;
}

.dashboard {
    width: min(1680px, calc(100% - 40px));
    margin: 0 auto;
    padding: 42px 0 32px;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 26px;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--accent);
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 5px;
    font-size: clamp(2rem, 4vw, 3.15rem);
    line-height: 1;
    letter-spacing: -0.045em;
}

.subtitle,
.section-heading p {
    margin-bottom: 0;
    color: var(--muted);
}

.live-status {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    margin-top: 8px;
    padding: 9px 13px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--muted);
    font-size: 0.9rem;
    box-shadow: var(--shadow);
}

.live-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 6px var(--accent-soft);
}

.card {
    border: 1px solid var(--border);
    border-radius: 20px;
    background: linear-gradient(180deg, rgba(255,255,255,0.02), transparent), var(--surface);
    box-shadow: var(--shadow);
}

.page-tabs {
    display: flex;
    gap: 6px;
    margin: -8px 0 18px;
    padding: 4px;
    width: fit-content;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface);
}

.page-tab {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    padding: 0 15px;
    border-radius: 10px;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 700;
}

.page-tab:hover {
    color: var(--text);
}

.page-tab.active {
    background: var(--accent);
    color: #08251e;
}

.toolbar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    align-items: stretch;
    padding: 22px;
    margin-bottom: 18px;
}

.field label,
.field-label {
    display: block;
    margin-bottom: 9px;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

select {
    width: 100%;
    min-height: 48px;
    padding: 0 42px 0 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-soft);
    color: var(--text);
    outline: none;
}

select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

.creative-picker { position: relative; }

.creative-picker summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 48px;
    padding: 0 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-soft);
    color: var(--text);
    cursor: pointer;
    list-style: none;
}

.creative-picker summary::-webkit-details-marker { display: none; }
.creative-picker summary::after { content: "⌄"; margin-left: 12px; color: var(--muted); }
.creative-picker[open] summary { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.creative-options {
    position: absolute;
    z-index: 20;
    top: calc(100% + 8px);
    right: 0;
    left: 0;
    max-height: 360px;
    overflow-y: auto;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #202734;
    box-shadow: 0 22px 55px rgba(0, 0, 0, 0.46);
}

.group-field .creative-options {
    right: auto;
    width: min(560px, calc(100vw - 48px));
    max-height: 520px;
    padding: 10px;
}

.creative-option {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    min-height: 42px;
    padding: 7px 9px;
    border-radius: 9px;
    cursor: pointer;
}

.creative-option:hover { background: rgba(255, 255, 255, 0.05); }
.creative-option input { accent-color: var(--accent); }
.creative-option small { color: var(--muted); font-variant-numeric: tabular-nums; }
.creative-option-all { font-weight: 800; }
.creative-divider { height: 1px; margin: 6px 4px; background: var(--border); }

.survey-type-section {
    margin-top: 10px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.018);
}

.survey-type-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    background: rgba(82, 211, 176, 0.07);
}

.survey-type-heading strong {
    color: var(--accent);
    font-size: 0.78rem;
    letter-spacing: 0.035em;
    text-transform: uppercase;
}

.survey-type-heading small {
    flex: 0 0 auto;
    color: var(--muted);
}

.group-option {
    min-height: 52px;
    padding: 9px 12px;
}

.group-option + .group-option {
    border-top: 1px solid rgba(255, 255, 255, 0.045);
    border-radius: 0;
}

.group-option-name {
    min-width: 0;
    overflow-wrap: anywhere;
    color: var(--text);
    font-size: 0.94rem;
}

.group-count {
    min-width: 94px;
    padding: 5px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.065);
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 700;
    text-align: center;
    white-space: nowrap;
}

.creative-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 18px;
    margin-top: 9px;
    color: var(--muted);
    font-size: 0.82rem;
}

.period-buttons {
    display: flex;
    gap: 6px;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--surface-soft);
}

.period-button {
    min-height: 40px;
    padding: 0 14px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: 160ms ease;
}

.period-button:hover {
    color: var(--text);
}

.period-button.active {
    background: var(--accent);
    color: #08251e;
    font-weight: 800;
}

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

.metric-card {
    min-height: 154px;
    padding: 23px;
    display: flex;
    flex-direction: column;
}

.metric-label {
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 700;
}

.metric-value {
    margin: auto 0 7px;
    font-size: clamp(2rem, 4vw, 3rem);
    line-height: 1;
    letter-spacing: -0.04em;
}

.metric-hint {
    color: var(--muted);
    font-size: 0.8rem;
}

.distribution {
    padding: 25px;
}

.period-field {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 20px;
    align-items: center;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

.period-field .field-label {
    margin: 0;
}

.period-field .period-button {
    flex: 1 1 0;
}

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

.live-metric {
    border-color: rgba(82, 211, 176, 0.3);
}

.chart-card,
.domain-section,
.performance-section {
    padding: 25px;
    margin-bottom: 18px;
}

.selection-fields {
    display: grid;
    grid-template-columns: minmax(240px, 0.85fr) minmax(320px, 1.15fr) minmax(360px, 1.4fr);
    gap: 20px;
    align-items: start;
}

.chart-wrap {
    position: relative;
    min-height: 290px;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 15px;
    background: var(--surface-soft);
}

.chart-wrap svg {
    display: block;
    width: 100%;
    min-width: 640px;
    height: 290px;
}

.chart-grid {
    stroke: rgba(255, 255, 255, 0.08);
    stroke-width: 1;
}

.chart-label {
    fill: var(--muted);
    font-size: 11px;
}

.chart-area {
    fill: rgba(82, 211, 176, 0.12);
}

.chart-line {
    fill: none;
    stroke: var(--accent);
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.chart-empty {
    min-height: 290px;
    display: grid;
    place-items: center;
    color: var(--muted);
}

.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 15px;
}

.domain-table {
    width: 100%;
    min-width: 820px;
    border-collapse: collapse;
}

.domain-table th,
.domain-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
}

.domain-table th {
    color: var(--muted);
    background: var(--surface-soft);
    font-size: 0.76rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.table-sort {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    font-weight: 800;
    letter-spacing: inherit;
    text-transform: inherit;
    cursor: pointer;
}

.numeric .table-sort {
    justify-content: flex-end;
    width: 100%;
}

.table-sort:hover,
[aria-sort="ascending"] .table-sort,
[aria-sort="descending"] .table-sort {
    color: var(--text);
}

.table-sort span {
    min-width: 0.8em;
    color: var(--accent);
}

.domain-table tbody tr:last-child td {
    border-bottom: 0;
}

.domain-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.025);
}

.domain-table .numeric {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.domain-name {
    max-width: 330px;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
    font-weight: 700;
}

.creative-name {
    color: var(--text);
    font-weight: 700;
}

.empty-cell {
    color: var(--muted);
    text-align: center !important;
}

.table-note {
    margin: 12px 2px 0;
    color: var(--muted);
    font-size: 0.78rem;
}

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

.section-heading h2 {
    margin-bottom: 5px;
    font-size: 1.3rem;
}

.vote-list {
    display: grid;
    gap: 13px;
}

.vote-row {
    display: grid;
    grid-template-columns: minmax(230px, 1fr) auto;
    gap: 10px 22px;
    align-items: center;
    padding: 15px 16px;
    border: 1px solid var(--border);
    border-radius: 15px;
    background: var(--surface-soft);
}

.vote-copy {
    display: flex;
    align-items: center;
    gap: 13px;
    min-width: 0;
}

.vote-number {
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    font-weight: 900;
}

.vote-label {
    font-weight: 720;
}

.vote-values {
    display: flex;
    align-items: baseline;
    justify-content: flex-end;
    gap: 12px;
    min-width: 128px;
}

.vote-values strong {
    font-size: 1.2rem;
}

.vote-values span {
    min-width: 58px;
    color: var(--muted);
    text-align: right;
}

.bar-track {
    grid-column: 1 / -1;
    height: 8px;
    overflow: hidden;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.075);
}

.bar-fill {
    width: 0;
    height: 100%;
    border-radius: inherit;
    transition: width 350ms ease;
}

.vote-row[data-tone="negative-strong"] .vote-number,
.vote-row[data-tone="negative-strong"] .bar-fill {
    background: var(--danger-1);
}

.vote-row[data-tone="negative"] .vote-number,
.vote-row[data-tone="negative"] .bar-fill {
    background: var(--danger-2);
}

.vote-row[data-tone="neutral"] .vote-number,
.vote-row[data-tone="neutral"] .bar-fill {
    background: var(--neutral);
}

.vote-row[data-tone="positive"] .vote-number,
.vote-row[data-tone="positive"] .bar-fill {
    background: var(--positive-1);
}

.vote-row[data-tone="strong-positive"] .vote-number,
.vote-row[data-tone="strong-positive"] .bar-fill {
    background: var(--positive-2);
}

.dashboard-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 17px 4px 0;
    color: var(--muted);
    font-size: 0.82rem;
}

.separator {
    padding: 0 6px;
}

.toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.toggle input {
    accent-color: var(--accent);
}

.message {
    margin-top: 18px;
    padding: 14px 16px;
    border: 1px solid rgba(255, 174, 66, 0.35);
    border-radius: 12px;
    background: rgba(255, 174, 66, 0.09);
    color: #ffd59b;
}

.hidden {
    display: none;
}

.is-loading .metric-value,
.is-loading .vote-values {
    opacity: 0.68;
}

@media (max-width: 960px) {
    .toolbar {
        grid-template-columns: 1fr;
        align-items: stretch;
    }

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

    .period-buttons {
        flex-wrap: wrap;
    }

    .selection-fields {
        grid-template-columns: 1fr 1fr;
    }

    .creative-field {
        grid-column: 1 / -1;
    }
}

@media (max-width: 620px) {
    .dashboard {
        width: min(100% - 24px, 1240px);
        padding-top: 24px;
    }

    .page-header,
    .dashboard-footer {
        align-items: flex-start;
        flex-direction: column;
    }

    .metrics {
        grid-template-columns: 1fr;
    }

    .toolbar,
    .distribution,
    .chart-card,
    .domain-section,
    .performance-section {
        padding: 17px;
    }

    .selection-fields {
        grid-template-columns: 1fr;
    }

    .creative-field {
        grid-column: 1;
    }

    .period-field {
        grid-template-columns: 1fr;
        gap: 9px;
    }

    .page-tabs {
        width: 100%;
    }

    .page-tab {
        flex: 1;
        justify-content: center;
        text-align: center;
    }

    .period-button {
        flex: 1 1 45%;
    }

    .vote-row {
        grid-template-columns: 1fr;
    }

    .vote-values {
        justify-content: flex-start;
        padding-left: 47px;
    }

    .bar-track {
        grid-column: 1;
    }

    .separator {
        display: none;
    }

    #nextUpdate {
        display: block;
        margin-top: 4px;
    }
}


.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logout-link {
    display: inline-flex;
    align-items: center;
    min-height: 38px;
    padding: 0 13px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.88rem;
}

.logout-link:hover {
    color: var(--text);
    border-color: rgba(255, 255, 255, 0.18);
}

@media (max-width: 620px) {
    .header-actions {
        width: 100%;
        justify-content: space-between;
    }
}
