:root {
    color-scheme: light;
    --ivory: #faf8f5;
    --charcoal: #111111;
    --charcoal-soft: #2a2a28;
    --sand: #e8e1d6;
    --taupe: #8e877c;
    --gold: #a99570;
    --stone-light: #cfc2a6;
    --stone-wash: #f3eee3;
    --white: #ffffff;
    --up: #177a5b;
    --down: #ba4718;
    --up-bg: #e3f0ea;
    --down-bg: #f7e6dd;
    --line: #e8e1d6;
    --font-sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --font-display: "Cormorant Garamond", Georgia, serif;
    --radius: 2px;
    --form-control-height: 34px;
}

*, *::before, *::after { box-sizing: border-box; }
html { min-width: 320px; }
body { margin: 0; background: var(--ivory); color: var(--charcoal); font-family: var(--font-sans); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
button, input, select { font-family: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.muted { color: var(--taupe); }

.login-shell { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 400px; padding: 48px 44px 40px; border: 1px solid var(--sand); border-radius: var(--radius); background: var(--white); box-shadow: 0 1px 2px rgba(17, 17, 17, .04); }
.wordmark { display: block; width: 210px; height: auto; margin: 0 auto 8px; }
.login-sub { margin: 0 0 32px; color: var(--taupe); font-size: 11px; letter-spacing: .22em; text-align: center; text-transform: uppercase; }
.field { margin-bottom: 16px; }
label.field, .field > label, .field-label { display: block; color: var(--taupe); font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.field > label, .field-label { margin-bottom: 6px; }
label.field > input { width: 100%; margin-top: 6px; }
.field > input, .field > select { width: 100%; }
.login-error { margin: 0 0 16px; padding: 9px 12px; border: 1px solid var(--down); border-radius: var(--radius); background: var(--down-bg); color: var(--down); font-size: 13px; }
.login-error:empty { display: none; }

input, select { min-width: 0; padding: 6px 10px; border: 1px solid var(--sand); border-radius: var(--radius); background: var(--white); color: var(--charcoal); font-size: 13px; }
input:focus, select:focus { outline: 2px solid var(--gold); outline-offset: 0; }
button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px; border: 1px solid var(--charcoal); border-radius: var(--radius); background: var(--charcoal); color: var(--ivory); font-size: 13px; font-weight: 600; letter-spacing: .04em; }
button:hover { background: var(--charcoal-soft); }
button[disabled] { cursor: wait; opacity: .55; }
.primary { border-color: var(--charcoal); background: var(--charcoal); color: var(--ivory); }
.primary:hover { background: var(--charcoal-soft); }
.secondary { border-color: var(--sand); background: transparent; color: var(--charcoal); }
.secondary:hover { border-color: var(--charcoal); background: transparent; }
.danger { border-color: var(--down); background: transparent; color: var(--down); }
.danger:hover { background: var(--down-bg); }
.small { padding: 6px 12px; font-size: 12px; }
.block { width: 100%; margin-top: 8px; }
input:not([type="checkbox"]),
select,
button.primary,
button.secondary,
.segment,
.controls .check-control { height: var(--form-control-height); }
button.primary, button.secondary { padding-block: 6px; }

.app-shell { min-height: 100vh; }
.bar { display: flex; align-items: center; gap: 20px; height: 58px; padding: 0 26px; background: var(--charcoal); color: var(--ivory); }
.bar-brand { display: flex; align-items: baseline; gap: 9px; user-select: none; }
.bar-brand .aurev { font-size: 17px; font-weight: 500; letter-spacing: .34em; }
.bar-brand .media { color: var(--stone-light); font-size: 9px; font-weight: 600; letter-spacing: .42em; }
.tabs { display: flex; align-self: stretch; gap: 4px; margin-left: 26px; }
.tabs .tab { padding: 19px 14px 17px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: #b9b4aa; font-size: 13px; font-weight: 600; letter-spacing: 0; }
.tabs .tab:hover { background: transparent; color: var(--ivory); }
.tabs .tab.active { border-bottom-color: var(--gold); color: var(--ivory); }
.bar-right { display: flex; align-items: center; gap: 14px; margin-left: auto; font-size: 13px; }
.role-chip { padding: 3px 9px; border: 1px solid #3b3b38; border-radius: 999px; background: var(--charcoal-soft); color: var(--stone-light); font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.bar-right .logout { padding: 6px 12px; border: 1px solid #3b3b38; background: transparent; color: #b9b4aa; font-size: 12px; }
.bar-right .logout:hover { border-color: var(--taupe); background: transparent; color: var(--ivory); }

.dashboard-main { width: 100%; margin: 0 auto; padding: 26px 0 70px; }
.dashboard-main > section { width: min(1280px, 100%); margin: 0 auto; padding-inline: 26px; }
.dashboard-main > #reports-view { width: min(1280px, 100%); }
.dashboard-main > #reports-view.reports-admin { width: min(1600px, 100%); }
h1.page { margin: 0 0 2px; font-family: var(--font-display); font-size: 27px; font-weight: 600; }
.page-sub { margin: 0 0 20px; color: var(--taupe); font-size: 13px; }
.section-title { margin: 0 0 2px; font-family: var(--font-display); font-size: 23px; font-weight: 600; }
.section-heading, .card-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; }

.controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin: 0 0 18px; padding: 14px 16px; border: 1px solid var(--sand); border-radius: var(--radius); background: var(--white); }
.control { display: block; margin: 0; color: var(--taupe); font-size: 10px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.control > span, .control-label, .control .form-label { display: block; margin-bottom: 5px; }
.control input, .control select { display: block; color: var(--charcoal); letter-spacing: 0; text-transform: none; }
.controls button, .controls input, .controls select { line-height: normal; }
#report-search { width: 150px; }
.segment { display: inline-flex; overflow: hidden; border: 1px solid var(--sand); border-radius: var(--radius); }
.segment button { height: 100%; padding: 0 14px; border: 0; border-radius: 0; background: var(--white); color: var(--taupe); font-size: 12px; font-weight: 600; letter-spacing: 0; }
.segment button:hover { color: var(--charcoal); }
.segment button.active { background: var(--charcoal); color: var(--ivory); }
label.check-control { display: inline-flex; align-items: center; gap: 7px; padding: 8px 2px; font-size: 13px; user-select: none; }
.check-control input { margin: 0; }
.control-spacer { flex: 1; }

.live-banner { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; padding: 11px 15px; border: 1px solid var(--stone-light); border-radius: var(--radius); background: var(--stone-wash); color: #5c5240; font-size: 12.5px; }
.live-dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); animation: pulse 1.6s ease infinite; }
.error-banner { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; padding: 12px 16px; border: 1px solid var(--down); border-radius: var(--radius); background: var(--down-bg); color: var(--down); }
.error-banner .primary { margin-left: auto; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { min-width: 0; padding: 13px 15px 11px; border: 1px solid var(--sand); border-radius: var(--radius); background: var(--white); }
.kpi.emphasis { border-top: 2px solid var(--gold); }
.kpi-label { color: var(--taupe); font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.kpi-value { margin-top: 3px; font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.skeleton { height: 13px; border-radius: var(--radius); background: linear-gradient(90deg, var(--sand), #f3efe8, var(--sand)); background-size: 200% 100%; animation: shimmer 1.1s ease infinite; }

.table-wrap { overflow: auto; border: 1px solid var(--sand); border-radius: var(--radius); background: var(--white); }
table { width: 100%; min-width: 900px; border-collapse: collapse; }
thead th { position: sticky; top: 0; padding: 10px 12px; background: var(--charcoal); color: var(--ivory); font-size: 10.5px; font-weight: 700; letter-spacing: .09em; text-align: right; text-transform: uppercase; white-space: nowrap; }
thead th.text, tbody td.text, tfoot td.text { text-align: left; }
.sort-button { padding: 0; border: 0; background: transparent; color: inherit; font-size: inherit; font-weight: inherit; letter-spacing: inherit; text-transform: inherit; }
.sort-button:hover { background: transparent; color: var(--stone-light); }
.sort-direction { margin-left: 4px; color: var(--stone-light); }
tbody td { padding: 8px 12px; border-top: 1px solid #f1ede6; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
#report-table tbody td { white-space: normal; }
tbody tr:hover td { background: #fcfaf6; }
tbody tr.flagged td { background: var(--stone-wash); }
tbody tr.flagged td:first-child { box-shadow: inset 3px 0 0 var(--gold); }
tbody tr.flagged:hover td { background: #ece5d6; }
tfoot td { padding: 10px 12px; border-top: 2px solid var(--charcoal); background: var(--ivory); font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.campaign-id { margin-left: 5px; color: var(--taupe); font-size: 11px; }
.flag-ico { display: inline-flex; align-items: center; gap: 5px; margin-left: 6px; color: #7a6b4f; font-size: 11px; font-weight: 700; }
.metric-delta-group { display: inline-block; white-space: nowrap; }
.delta { margin-left: 6px; padding: 1px 5px; border-radius: var(--radius); font-size: 11px; font-weight: 700; vertical-align: baseline; white-space: nowrap; }
.delta.up { background: var(--up-bg); color: var(--up); }
.delta.down { background: var(--down-bg); color: var(--down); }

.state { padding: 56px 20px; color: var(--taupe); text-align: center; }
.state h2 { margin: 0 0 6px; color: var(--charcoal); font-family: var(--font-display); font-size: 20px; font-weight: 600; }
.state p { margin: 0 0 14px; font-size: 13px; }
.spinner { display: block; width: 26px; height: 26px; margin: 0 auto 14px; border: 3px solid var(--sand); border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; }

.tracking-links { margin-top: 28px; }
.tracking-links a { color: var(--charcoal); overflow-wrap: anywhere; text-decoration-color: var(--gold); text-underline-offset: 3px; }
.status { min-height: 21px; color: var(--taupe); }
.status[data-tone="error"] { color: var(--down); }
.status[data-tone="success"] { color: var(--up); }

.admin-section { display: block; }
.admin-controls { padding-block: 10px; }
.admin-table-wrap { min-height: 74px; }
.admin-table { min-width: 900px; }
.admin-table .mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; }
.admin-collection-state { padding-block: 42px; }
.table-actions, .setup-status { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.linkbtn { display: inline-flex; height: auto; min-height: 0; padding: 2px 4px; border: 0; background: none; color: var(--charcoal); font-size: 12.5px; font-weight: 400; letter-spacing: 0; text-decoration: underline; text-underline-offset: 3px; }
.linkbtn:hover { background: none; color: var(--taupe); }
.linkbtn[disabled] { cursor: wait; opacity: .55; }
.resource-list { display: grid; gap: 12px; }
.resource-card { display: grid; gap: 12px; padding: 16px; border: 1px solid var(--sand); border-radius: var(--radius); background: var(--white); }
.resource-card > strong { font-family: var(--font-display); font-size: 18px; font-weight: 600; }
.badge { display: inline-flex; padding: 2px 8px; border-radius: 999px; font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.badge.on { background: var(--up-bg); color: var(--up); }
.badge.off { background: var(--sand); color: var(--taupe); }
.badge.warn { background: var(--stone-wash); color: #7a6b4f; }

dialog { width: 92%; max-width: 420px; padding: 0; border: 1px solid var(--sand); border-radius: var(--radius); background: var(--white); color: var(--charcoal); }
dialog::backdrop { background: rgba(17, 17, 17, .45); }
.admin-dialog-wide { max-width: 680px; }
.dlg-head { padding: 14px 20px; background: var(--charcoal); color: var(--ivory); font-family: var(--font-display); font-size: 19px; font-weight: 600; }
.dlg-body { padding: 20px; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 0 20px 20px; }
.dialog-form .dlg-foot { padding: 0; }
.dialog-intro { margin: 0 0 16px; font-size: 13px; }
.dialog-identity { margin: 0 0 12px; color: var(--taupe); font-size: 12px; }
.provider-section { padding: 16px 0; border-top: 1px solid var(--line); }
.provider-section:first-of-type { padding-top: 0; border-top: 0; }
.provider-section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.provider-section-heading h2 { margin: 0; font-family: var(--font-display); font-size: 18px; font-weight: 600; }
.provider-form { display: grid; gap: 0; }
.provider-form > button { justify-self: start; }
.provider-note { margin: 0; }
.dialog-value { display: block; min-width: 0; max-width: 100%; padding: 9px 11px; border: 1px solid var(--sand); border-radius: var(--radius); background: var(--ivory); color: var(--charcoal); overflow-wrap: anywhere; user-select: all; }
.provider-dialog-foot { padding: 4px 0 0; }
.temp-pass { padding: 10px 14px; border: 1px dashed var(--gold); border-radius: var(--radius); background: var(--ivory); font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 16px; letter-spacing: .06em; text-align: center; }
.credential-dialog-head { position: relative; padding-right: 52px; }
.credential-close { position: absolute; top: 10px; right: 12px; padding: 2px 7px; border: 0; background: transparent; color: var(--stone-light); font-size: 22px; line-height: 1; }
.credential-close:hover { background: transparent; color: var(--ivory); }
.credential-context { margin: 0 0 12px; font-size: 13px; font-weight: 700; }
.credential-note { margin: 0 0 8px; font-size: 13px; }
.credential-generated { margin: 0 0 14px; font-size: 12px; }
.credential-username { display: block; margin-bottom: 12px; overflow-wrap: anywhere; user-select: all; }
.credential-label { display: block; margin-bottom: 5px; font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; }
.credential-password { display: block; overflow-wrap: anywhere; user-select: all; }
.credential-copy-status { display: block; min-height: 21px; margin-top: 10px; }
.clipboard-helper { position: fixed; top: 0; left: -10000px; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.toast { position: fixed; z-index: 1000; top: 18px; left: 50%; display: flex; align-items: center; gap: 12px; width: max-content; max-width: min(560px, calc(100vw - 32px)); min-height: 0; margin: 0; padding: 11px 14px; border: 1px solid var(--sand); border-radius: var(--radius); background: var(--white); box-shadow: 0 8px 28px rgba(17, 17, 17, .16); color: var(--charcoal); transform: translateX(-50%); }
.toast[data-tone="error"] { border-color: var(--down); background: var(--down-bg); color: var(--down); }
.toast[data-tone="success"] { border-color: var(--up); color: var(--up); }
.toast-close { flex: 0 0 auto; padding: 0 2px; border: 0; background: transparent; color: inherit; font-size: 20px; line-height: 1; }
.toast-close:hover { background: transparent; }

.foot { display: flex; gap: 14px; width: min(1280px, 100%); margin: 0 auto; padding: 0 26px 30px; color: var(--taupe); font-size: 11.5px; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { to { background-position: -200% 0; } }

@media (min-width: 1280px) {
    #reports-view .kpis { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); }
}

@media (max-width: 900px) {
    .bar { flex-wrap: wrap; height: auto; min-height: 58px; padding: 10px 16px 0; }
    .tabs { order: 3; width: 100%; margin-left: 0; overflow-x: auto; }
    .tabs .tab { padding-top: 10px; }
    .bar-right { margin-left: auto; }
    .dashboard-main { padding: 18px 0 60px; }
    .dashboard-main > section { padding-inline: 14px; }
    .foot { flex-wrap: wrap; padding: 0 14px 24px; }
}

@media (max-width: 560px) {
    .login-card { padding: 38px 26px 32px; }
    .bar-brand { width: 100%; }
    .bar-right { width: 100%; margin: 0; padding-bottom: 8px; }
    .bar-right .logout { margin-left: auto; }
    .controls { align-items: stretch; }
    .control, .control input, .control select, .segment { width: 100%; }
    #report-search { width: 100%; }
    .segment button { flex: 1; }
    .check-control { width: 100%; }
}
