:root {
  --mat-bg: #f4f6f9;
  --mat-surface: #fff;
  --mat-surface-muted: #f7f9fc;
  --mat-text: #1f3047;
  --mat-heading: #17375f;
  --mat-primary: #0b4b8f;
  --mat-primary-strong: #083c75;
  --mat-primary-soft: #edf4fb;
  --mat-accent: #6f0000;
  --mat-accent-deep: #4f0000;
  --mat-muted: #64748b;
  --mat-border: #dce4ee;
  --mat-border-strong: #c7d5e5;
  --mat-focus: #d79b2b;
  --mat-success: #216339;
  --mat-success-bg: #e8f6ec;
  --mat-warning: #8c510b;
  --mat-warning-bg: #fff4df;
  --mat-danger: #a13c32;
  --mat-danger-bg: #fff0ee;
  --mat-radius: 12px;
  --mat-shadow: 0 1px 2px rgba(31, 48, 71, .06), 0 6px 16px rgba(31, 48, 71, .05);
  color: var(--mat-text);
  background: var(--mat-bg);
  font-family: "Plus Jakarta Sans", Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--mat-bg); color: var(--mat-text); line-height: 1.5; }
button, input, select { font: inherit; }
button { min-height: 38px; border: 1px solid var(--mat-primary); border-radius: 8px; padding: 9px 14px; background: var(--mat-primary); color: #fff; cursor: pointer; font-size: 12px; font-weight: 700; transition: background-color .15s ease, border-color .15s ease, box-shadow .15s ease, transform .15s ease; }
button:hover { border-color: var(--mat-primary-strong); background: var(--mat-primary-strong); transform: translateY(-1px); }
button:disabled { cursor: wait; opacity: .58; transform: none; }
button.quiet { border-color: var(--mat-border-strong); background: #f1f5f9; color: var(--mat-primary); }
button.quiet:hover { border-color: #9eb8d3; background: var(--mat-primary-soft); color: var(--mat-heading); }
button:focus-visible, input:focus-visible, select:focus-visible, dialog:focus-visible { outline: 3px solid var(--mat-focus); outline-offset: 2px; }
h1, h2, h3, p { overflow-wrap: anywhere; }
h1, h2, h3 { color: var(--mat-heading); line-height: 1.3; }
h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -.025em; }
h2 { margin: 0 0 12px; font-size: 17px; font-weight: 800; }
h3 { margin: 0 0 8px; font-size: 15px; font-weight: 800; }
p { margin-top: 0; }
.hint, .muted { color: var(--mat-muted); }
.hint { line-height: 1.6; }
.eyebrow, .intro-eyebrow { color: var(--mat-primary); font-size: 10px; font-weight: 800; letter-spacing: .14em; line-height: 1.3; }

.site-header { background: linear-gradient(115deg, var(--mat-accent) 0%, #7b1212 54%, var(--mat-accent-deep) 100%); box-shadow: 0 3px 14px rgba(79, 0, 0, .18); color: #fff; padding: 15px max(16px, calc((100% - 1440px) / 2)); }
.header-inner { display: flex; align-items: center; justify-content: space-between; gap: 18px; max-width: 1440px; margin: 0 auto; }
.brand-block { min-width: 0; flex: 1 1 auto; }
.site-header p { margin: 0; color: #e9c5c5; }
.site-header .brand-block > p:first-child { margin-bottom: 6px; color: #f1dede; font-size: 10px; font-weight: 700; letter-spacing: .16em; }
.site-header h1 { color: #fff; font-size: 22px; }
.site-header .account { margin-top: 7px; color: #f0dada; font-size: 12px; }
.header-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 5px; max-width: 58%; }
.site-header button { min-height: 34px; border-color: rgba(255, 255, 255, .2); background: rgba(255, 255, 255, .1); color: #fff; padding: 7px 10px; font-size: 11px; }
.site-header button:hover { border-color: rgba(255, 255, 255, .35); background: rgba(255, 255, 255, .2); }
.site-header button#add { border-color: #fff; background: #fff; color: var(--mat-accent); }
.site-header button#add:hover { background: #fff5f5; }
.dashboard-main { max-width: 1440px; margin: 0 auto; padding: 22px 24px 46px; }
.dashboard-main > section, .dashboard-main > .cards { margin-bottom: 20px; }
.dashboard-intro { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 20px; padding: 0 2px; }
.dashboard-intro h2 { margin: 0; font-size: 20px; }
.dashboard-intro p:not(.intro-eyebrow) { margin: 5px 0 0; color: var(--mat-muted); font-size: 12px; }
.intro-eyebrow { margin: 0 0 5px; }
.toolbar { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 9px; }
.month-filter { min-width: 174px; margin: 0; color: var(--mat-muted); font-size: 11px; font-weight: 700; }

.card, .panel { min-width: 0; border: 1px solid var(--mat-border); border-radius: var(--mat-radius); background: var(--mat-surface); box-shadow: var(--mat-shadow); }
.panel { margin-bottom: 20px; padding: 18px; }
.panel > h2, .panel-head h2 { color: var(--mat-heading); font-size: 16px; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 16px; }
.panel-head h2 { margin-bottom: 0; }
.panel-head .hint { margin: 4px 0 0; font-size: 12px; }
label { display: block; margin: 15px 0; color: var(--mat-text); font-size: 12px; font-weight: 700; }
input, select { display: block; width: 100%; min-height: 42px; margin-top: 7px; border: 1px solid var(--mat-border-strong); border-radius: 8px; padding: 10px 11px; background: #fff; color: var(--mat-text); }
input:hover, select:hover { border-color: #9eb8d3; }
input[type="checkbox"] { display: inline-block; width: auto; min-height: 0; margin: 0 6px 0 0; accent-color: var(--mat-primary); vertical-align: middle; }
input[type="file"] { padding: 8px 10px; }
select[multiple] { min-height: 120px; }
.month-filter select, .compare-controls select { margin-top: 6px; }
.dates, .compare-controls { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.compare-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); margin: 0 0 16px; }
.compare-controls label { margin: 0; border: 1px solid var(--mat-border); border-radius: 9px; padding: 12px 14px; background: #f8fbfe; color: var(--mat-heading); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); align-items: stretch; gap: 12px; margin-bottom: 20px; }
.source-card { display: flex; flex-direction: column; min-width: 0; padding: 15px; transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease; }
.source-card:hover { border-color: #8eadd0; box-shadow: 0 6px 16px rgba(8, 47, 96, .1); transform: translateY(-2px); }
.source-card.is-selected { border-color: #7da5cc; box-shadow: 0 0 0 3px rgba(11, 75, 143, .12), var(--mat-shadow); }
.source-card-meta { margin: 0 0 8px; color: var(--mat-primary); font-size: 12px; font-weight: 700; }
.source-card-title { margin: 0 0 9px; color: var(--mat-heading); font-size: 17px; }
.source-card-url { max-height: 2.9em; margin: 0 0 8px; overflow: auto; overflow-wrap: anywhere; word-break: break-word; font-size: 12px; line-height: 1.45; }
.source-card-range { margin: 0 0 9px; color: var(--mat-text); font-size: 13px; font-weight: 700; }
.source-card-status { align-self: flex-start; margin: 0 0 10px; border: 1px solid var(--mat-border-strong); border-radius: 999px; padding: 4px 9px; background: #f2f6fa; color: #35516f; font-size: 12px; font-weight: 700; line-height: 1.2; }
.source-card-status.success { border-color: #a8d5b9; background: var(--mat-success-bg); color: var(--mat-success); }
.source-card-status.queued, .source-card-status.running { border-color: #a9c8e7; background: #eaf3fd; color: #174b7d; }
.source-card-status.auth_required, .source-card-status.auth_blocked, .source-card-status.invalid_credentials, .source-card-status.authentication_failed, .source-card-status.partial, .source-card-status.error, .source-card-status.needs_inspection { border-color: #edc878; background: var(--mat-warning-bg); color: var(--mat-warning); }
.source-card-message { min-height: 2.9em; margin: 0 0 7px; overflow-wrap: anywhere; font-size: 12px; line-height: 1.45; }
.source-card-updated { margin: 0; color: var(--mat-muted); font-size: 11px; }
.source-card .warn { margin: 11px 0 0; }
.actions { display: flex; flex-wrap: wrap; align-items: stretch; gap: 6px; margin-top: auto; padding-top: 12px; }
.actions button { min-height: 34px; flex: 1 1 auto; padding: 8px 10px; font-size: 11px; }
.source-card-detail { border-color: #9eb8d3; background: #fff; color: var(--mat-primary); }
.source-card-detail:hover { background: var(--mat-primary-soft); color: var(--mat-heading); }

.empty, .loading-state { border: 1px dashed #b9c9dc; border-radius: 10px; padding: 28px 18px; background: var(--mat-surface); color: var(--mat-muted); text-align: center; }
.loading-state { border-style: solid; background: var(--mat-primary-soft); color: var(--mat-primary); }
.warn, #message:not(:empty), #loginError:not(:empty) { border: 1px solid #edcf87; border-radius: 9px; background: var(--mat-warning-bg); color: var(--mat-warning); }
.warn { margin: 12px 0; padding: 11px 13px; line-height: 1.5; }
#message:not(:empty) { margin-bottom: 16px; padding: 12px 14px; box-shadow: 0 2px 8px rgba(127, 82, 13, .05); }
.status { display: inline-block; border: 1px solid var(--mat-border); border-radius: 999px; padding: 5px 10px; background: #f3f6f9; font-size: 11px; font-weight: 700; }
.success { border-color: #a8d5b9; background: var(--mat-success-bg); color: var(--mat-success); }
.error, .auth_required, .needs_inspection, .partial { border-color: #edcf87; background: var(--mat-warning-bg); color: var(--mat-warning); }

.scroll, .standard-table-wrap, .admicro-table-wrap, .comparison-table-wrap { max-width: 100%; overflow-x: auto; border: 1px solid var(--mat-border-strong); border-radius: 10px; background: #fff; box-shadow: 0 2px 8px rgba(31, 48, 71, .05); -webkit-overflow-scrolling: touch; }
table { width: 100%; min-width: 560px; border-collapse: separate; border-spacing: 0; color: var(--mat-text); font-size: 12px; }
th, td { padding: 12px 14px; border-right: 1px solid #d8e1ec; border-bottom: 1px solid #e4eaf1; vertical-align: middle; line-height: 1.35; }
th { background: var(--mat-heading); color: #fff; font-size: 11px; font-weight: 700; text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th:last-child, td:last-child { border-right: 0; }
td { text-align: right; white-space: nowrap; }
tbody tr:nth-child(even) td { background: #f7f9fc; }
tbody tr:hover td { background: #edf5fc; }
tbody tr:last-child td { border-bottom: 0; }
.group td { background: #e3edf8; color: var(--mat-heading); font-weight: 800; text-align: left; white-space: normal; }
.sum td, .source-total td { background: #edf3fa; font-weight: 800; }
.summary-panel { padding: 18px; }
.summary-panel h2 { margin-bottom: 14px; }
#summary.scroll { overflow-x: auto; }
#summary .summary-table { min-width: 760px; }
#summary .summary-table thead th:first-child { min-width: 230px; }
#summary .summary-table tbody td:first-child { white-space: normal; overflow-wrap: anywhere; }
#summary .summary-table .summary-group-row td { border-top: 2px solid #8eadd0; background: #dbeafe; }
#summary .summary-table .summary-total-row td { border-top: 2px solid #8eadd0; background: #e7f0fb; color: var(--mat-heading); }

#cards .aggregate-card { width: 100%; min-width: 0; max-width: 620px; justify-self: start; border: 1px solid var(--mat-border-strong); border-left: 4px solid var(--mat-accent); border-radius: var(--mat-radius); padding: 16px 18px; background: linear-gradient(135deg, #fff 0%, #f7fbff 100%); color: var(--mat-heading); text-align: left; box-shadow: var(--mat-shadow); }
#cards .aggregate-card:hover { border-color: #9eb8d3; border-left-color: var(--mat-accent); background: linear-gradient(135deg, #fff 0%, #f2f8fd 100%); }
#cards .aggregate-card:focus-visible { outline: 3px solid var(--mat-focus); outline-offset: 3px; }
.aggregate-card-kicker { display: block; color: var(--mat-primary); font-size: 10px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.aggregate-card-title { display: block; margin: 3px 0 2px; color: var(--mat-heading); font-size: 19px; font-weight: 800; }
.aggregate-card-period { display: block; color: var(--mat-muted); font-size: 12px; }
.aggregate-card-kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 13px 0 10px; }
.aggregate-card-kpis span { display: flex; flex-direction: column; gap: 3px; padding: 9px 11px; border: 1px solid #d7e3ef; border-radius: 8px; background: #fff; }
.aggregate-card-kpis b { color: var(--mat-heading); font-size: 19px; line-height: 1.15; white-space: nowrap; }
.aggregate-card-kpis small, .aggregate-card-state { color: var(--mat-muted); font-size: 10px; }
.aggregate-card-state { display: block; margin: 0; font-size: 11px; }
.aggregate-detail-empty { margin-top: 22px; }
.aggregate-source-table { min-width: 920px; }
.aggregate-daily-table { min-width: 680px; }

.comparison-panel .compare-status-summary { display: grid; gap: 8px; margin: 0 0 18px; border: 1px solid #c7d8e9; border-radius: 8px; padding: 13px 15px; background: #f7fbff; }
.compare-status-line { display: flex; align-items: center; gap: 9px; min-width: 0; line-height: 1.4; }
.compare-status-line > span:last-child { overflow-wrap: anywhere; }
.compare-status-note { margin-top: 2px; font-size: 12px; }
.compare-side-badge { display: inline-flex; flex: 0 0 auto; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 7px; color: #fff; font-size: 13px; font-weight: 800; line-height: 1; }
.compare-side-a { background: var(--mat-primary); }
.compare-side-b { background: #9b3d36; }
.compare-missing-selection { margin: 0; }
.compare-report-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin: 0 0 18px; }
.compare-report-card { min-width: 0; border: 1px solid var(--mat-border); border-radius: 10px; padding: 17px; background: #fff; box-shadow: 0 3px 9px rgba(31, 48, 71, .05); }
.compare-report-card-a { border-top: 4px solid var(--mat-primary); }
.compare-report-card-b { border-top: 4px solid #9b3d36; }
.compare-card-heading { display: flex; align-items: center; gap: 9px; min-width: 0; margin-bottom: 10px; }
.compare-card-heading h3 { min-width: 0; margin: 0; font-size: 17px; }
.compare-card-source { margin: 0 0 9px; color: #4d6580; font-size: 12px; font-weight: 700; }
.compare-card-range { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 13px; font-weight: 700; }
.comparison-table { min-width: 780px; }
.comparison-table thead th:first-child { text-align: left; }
.comparison-table tbody th[scope="row"] { background: #fff; color: var(--mat-heading); text-align: left; white-space: normal; }
.comparison-table .comparison-delta, .comparison-table .comparison-percent { font-weight: 800; }
.comparison-table tr.comparison-increase .comparison-delta, .comparison-table tr.comparison-increase .comparison-percent { background: var(--mat-success-bg); color: var(--mat-success); }
.comparison-table tr.comparison-decrease .comparison-delta, .comparison-table tr.comparison-decrease .comparison-percent { background: var(--mat-danger-bg); color: var(--mat-danger); }
.comparison-table tr.comparison-flat .comparison-delta, .comparison-table tr.comparison-flat .comparison-percent { background: #f2f5f8; color: #53677d; }
.comparison-table tr.comparison-unavailable .comparison-delta, .comparison-table tr.comparison-unavailable .comparison-percent { background: var(--mat-warning-bg); color: var(--mat-warning); }

.standard-detail, .admicro-detail { display: grid; gap: 22px; }
.standard-section, .admicro-section { min-width: 0; }
.standard-section-heading, .admicro-section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.standard-section-heading h3, .admicro-section-heading h3 { margin: 0; }
.standard-section-note, .admicro-section-note { margin: 4px 0 0; color: var(--mat-muted); font-size: 12px; }
.standard-kpi-section, .admicro-kpi-section { border: 1px solid var(--mat-border); border-radius: 10px; padding: 16px; background: var(--mat-surface-muted); }
.standard-report-cards, .report-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.admicro-kpi-section .report-cards { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.standard-report-cards article, .report-cards article { min-width: 0; border: 1px solid var(--mat-border); border-radius: 8px; padding: 12px 14px; background: #fff; }
.standard-report-cards strong, .report-cards strong { display: block; color: var(--mat-muted); font-size: 11px; }
.standard-report-cards b, .report-cards b { display: block; margin-top: 4px; color: var(--mat-heading); font-size: 21px; line-height: 1.2; overflow-wrap: anywhere; }
.standard-report-table, .admicro-table { min-width: 660px; }
.standard-detail .creative-table, .admicro-detail .creative-table { min-width: 780px; }
.standard-detail .creative-table td:first-child { min-width: 230px; white-space: normal; overflow-wrap: anywhere; }
.admicro-detail .region-table, .admicro-detail .domain-table { min-width: 720px; }
.job-item, .session-item { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid #e4eaf1; }
.job-item:last-child, .session-item:last-child { border-bottom: 0; }
.job-item p, .session-item p { margin: 7px 0; line-height: 1.5; overflow-wrap: anywhere; }
.job-item small { color: var(--mat-muted); }
.job-item button { flex: none; }
.session-item { display: block; }
.session-item code { display: block; margin-top: 10px; border-radius: 7px; padding: 12px; background: #f3f6fa; overflow-wrap: anywhere; font-size: 12px; }
.grant-sources { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 8px; margin: 15px 0; }
.grant-option { display: flex; align-items: flex-start; gap: 9px; margin: 0; border: 1px solid var(--mat-border); border-radius: 9px; padding: 11px; background: #fbfcfe; }
.grant-option input { flex: 0 0 auto; width: auto; min-height: 0; margin: 3px 0 0; }
code { border-radius: 7px; background: #f3f6fa; }

dialog.editor-dialog { width: min(620px, calc(100% - 24px)); max-width: 620px; border: 1px solid var(--mat-border); border-radius: 14px; padding: 24px; background: var(--mat-surface); box-shadow: 0 22px 60px rgba(31, 48, 71, .22); }
dialog::backdrop { background: rgba(23, 55, 95, .48); backdrop-filter: blur(2px); }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.dialog-head h2 { margin-bottom: 0; }
#previewText { min-height: 1.5em; margin-top: 12px; line-height: 1.7; overflow-wrap: anywhere; }

.login-wrap { display: grid; min-height: 100vh; place-items: center; padding: 24px; background: radial-gradient(circle at 50% 0%, #fff 0, var(--mat-bg) 48%, #e8edf4 100%); }
.login-wrap .panel { width: min(100%, 460px); padding: 30px; }
.login-wrap .eyebrow { margin: 0 0 8px; }
.login-wrap h1 { margin-bottom: 8px; font-size: 26px; }
.login-wrap .hint { margin-bottom: 24px; }
.login-wrap form button { width: 100%; margin-top: 6px; }
#loginError:not(:empty) { margin: 0 0 14px; padding: 12px; }

@media (min-width: 1100px) { #cards .aggregate-card { max-width: none; } }
@media (max-width: 900px) {
  .header-inner { align-items: flex-start; flex-direction: column; gap: 12px; }
  .header-actions { justify-content: flex-start; max-width: none; width: 100%; }
  .dashboard-main { padding: 22px 16px 36px; }
  .standard-report-cards, .admicro-kpi-section .report-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 650px) {
  .site-header { padding: 15px 16px; }
  .site-header h1 { font-size: 20px; }
  .header-actions { gap: 5px; }
  .site-header button { padding: 7px 9px; }
  .dashboard-main { padding: 18px 12px 30px; }
  .dashboard-intro { display: block; }
  .dashboard-intro h2 { font-size: 18px; }
  .toolbar { margin-top: 15px; }
  .month-filter { min-width: 0; flex: 1; }
  .panel { padding: 15px; }
  .panel-head { display: block; }
  .panel-head > button { margin-top: 10px; }
  .cards { grid-template-columns: 1fr; gap: 10px; }
  .source-card { padding: 16px; }
  .dates, .compare-controls, .compare-report-cards { grid-template-columns: 1fr; }
  .compare-report-card { padding: 15px; }
  .standard-report-cards, .admicro-kpi-section .report-cards { gap: 8px; }
  .standard-report-cards article, .report-cards article { padding: 11px 10px; }
  .standard-report-cards b, .report-cards b { font-size: 19px; }
  .editor-dialog { padding: 18px; }
  .login-wrap { padding: 14px; }
  .login-wrap .panel { padding: 22px; }
  .login-wrap h1 { font-size: 23px; }
}
@media (max-width: 360px) { .standard-report-cards, .admicro-kpi-section .report-cards { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: .001ms !important; }
  button:hover, .source-card:hover { transform: none; }
}
