:root {
  color-scheme: light;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --background: #f4f6f6;
  --surface: #ffffff;
  --surface-muted: #edf1f1;
  --text: #202728;
  --text-muted: #5d6869;
  --border: #cdd5d5;
  --border-strong: #9da9aa;
  --cyan: #087f8c;
  --cyan-dark: #075e68;
  --mint: #17785b;
  --mint-soft: #dcefe8;
  --amber: #8a5b00;
  --amber-soft: #fff0c7;
  --coral: #b33b32;
  --coral-soft: #fae3e0;
}

* { box-sizing: border-box; }
html { background: var(--background); }
body { margin: 0; min-width: 0; background: var(--background); color: var(--text); font-size: 15px; line-height: 1.5; }
button, input, select { font: inherit; }
a { color: var(--cyan-dark); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--cyan-dark); outline-offset: 2px; }

.topbar { position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar__inner { display: flex; align-items: center; justify-content: space-between; min-height: 56px; max-width: 1440px; margin: 0 auto; padding: 0 24px; }
.brand { color: var(--text); font-size: 17px; font-weight: 700; text-decoration: none; }
.account { display: flex; align-items: center; gap: 12px; color: var(--text-muted); }
.navigation { display: flex; max-width: 1440px; margin: 0 auto; padding: 0 24px; overflow-x: auto; scrollbar-width: thin; }
.navigation a { flex: 0 0 auto; padding: 10px 14px 9px; border-bottom: 3px solid transparent; color: var(--text-muted); font-weight: 600; text-decoration: none; }
.navigation a:hover { color: var(--text); background: var(--surface-muted); }
.navigation a[aria-current="page"] { border-bottom-color: var(--cyan); color: var(--text); }

.dashboard { width: min(100%, 1440px); margin: 0 auto; padding: 24px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 24px; }
h1 { margin: 0; font-size: 28px; line-height: 1.2; letter-spacing: 0; }
h2 { margin: 0 0 10px; font-size: 18px; line-height: 1.3; letter-spacing: 0; }
h3 { margin: 0 0 8px; font-size: 15px; letter-spacing: 0; }
section + section { margin-top: 28px; }
.period-control, .report-filters { display: flex; align-items: center; gap: 8px; }
.period-control label, .report-filters label { font-weight: 650; }
.filter-submit { min-height: 40px; }
select, input { min-height: 40px; border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface); color: var(--text); padding: 7px 34px 7px 10px; }

.button { min-height: 38px; border: 1px solid var(--cyan-dark); border-radius: 6px; background: var(--cyan); color: #fff; padding: 7px 12px; font-weight: 650; cursor: pointer; }
.button:hover { background: var(--cyan-dark); }
.button:disabled { cursor: wait; opacity: .62; }
.button[aria-pressed="true"] { border-color: var(--text); font-weight: 750; }
.button--quiet { border-color: var(--border-strong); background: var(--surface); color: var(--text); }
.button--quiet:hover { background: var(--surface-muted); }
.button--success { border-color: #116248; background: var(--mint); }
.button--success:hover { background: #116248; }
.button--danger { border-color: #8e2f28; background: var(--coral); }
.button--danger:hover { background: #8e2f28; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 28px; }
.metric { min-height: 132px; padding: 16px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.metric h2 { color: var(--text-muted); font-size: 14px; font-weight: 650; }
.metric__value { margin: 12px 0 4px; font-size: 28px; font-weight: 720; line-height: 1; }
.metric__change { margin: 0; color: var(--mint); font-size: 13px; font-weight: 650; }
.metric__change--negative { color: var(--coral); }
.metric__status { display: inline-block; margin: 12px 0 0; font-size: 20px; font-weight: 700; }
.status--ok { color: var(--mint); }
.status--unknown { color: var(--amber); }

.table-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 28px 20px; }
.table-grid > section { min-width: 0; }
.table-grid section + section { margin-top: 0; }
.table-scroll { max-width: 100%; overflow-x: auto; border: 1px solid var(--border); background: var(--surface); }
table { width: 100%; min-width: 520px; border-collapse: collapse; }
caption { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
thead th { background: var(--surface-muted); color: var(--text-muted); font-size: 13px; font-weight: 700; }
tbody tr:last-child > * { border-bottom: 0; }
tbody th { font-weight: 600; }
.number { text-align: right; font-variant-numeric: tabular-nums; }
.warning { color: var(--amber); font-weight: 700; background: var(--amber-soft); }
.failure { color: var(--coral); font-weight: 700; background: var(--coral-soft); }

.quota-panel { padding: 16px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.quota-panel__header { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.quota-panel__header p { margin: 3px 0 0; color: var(--text-muted); }
.quota-panel__value { color: var(--text) !important; font-size: 28px; font-weight: 720; line-height: 1; }
.quota-progress { width: 100%; height: 14px; margin-top: 16px; accent-color: var(--cyan); }
.quota-breakdown { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 12px; color: var(--text-muted); font-size: 13px; }
.quota-breakdown strong { color: var(--text); }
.quota-reset-count, .quota-message { min-height: 20px; margin: 8px 0 0; color: var(--text-muted); font-size: 13px; }
.quota-message[role="alert"] { color: var(--coral); font-weight: 650; }

.import-tool { padding: 16px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.import-tool__heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; }
.import-tool__heading p { margin: 0; color: var(--text-muted); }
.import-form { display: grid; grid-template-columns: auto minmax(220px, 360px) auto; align-items: center; gap: 8px; }
.import-form label { font-weight: 650; }
.import-form input[type="file"] { width: 100%; padding: 6px 8px; }
.import-message { min-height: 24px; margin: 10px 0; color: var(--text-muted); }
.import-message[role="alert"], .failure-text { color: var(--coral); font-weight: 650; }
.import-history { min-width: 850px; }
.import-status { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--surface-muted); font-size: 13px; font-weight: 700; white-space: nowrap; }
.import-status--ready { background: var(--surface-muted); color: var(--text); }
.import-status--running, .import-status--queued { background: var(--amber-soft); color: var(--amber); }
.import-status--completed { background: var(--mint-soft); color: var(--mint); }
.import-status--failed { background: var(--coral-soft); color: var(--coral); }
.import-details summary { color: var(--cyan-dark); cursor: pointer; font-weight: 650; white-space: nowrap; }
.import-issues { min-width: 280px; max-width: 520px; margin: 8px 0 0; padding-left: 18px; color: var(--text-muted); }
.import-issues li { margin: 4px 0; overflow-wrap: anywhere; }
.import-breakdown { display: block; margin-top: 3px; color: var(--text-muted); white-space: nowrap; }

.context-note, .generated, .result-count { color: var(--text-muted); }
.context-note { margin: -10px 0 24px; }
.generated { margin: 32px 0 0; font-size: 13px; }
.result-count { margin: 12px 0 16px; }
.state { padding: 20px; color: var(--text-muted); text-align: center; }
.state--error { border-left: 4px solid var(--coral); background: var(--coral-soft); color: #7b2822; text-align: left; }

.report-list { display: grid; gap: 16px; }
.report { border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.report__header { display: flex; align-items: start; justify-content: space-between; gap: 16px; padding: 16px; border-bottom: 1px solid var(--border); }
.report__header h2 { margin: 0; overflow-wrap: anywhere; }
.report__summary { display: grid; flex: 0 0 auto; gap: 2px; text-align: right; }
.report__summary strong { color: var(--coral); }
.report__summary span { color: var(--text-muted); font-size: 13px; font-weight: 650; }
.report__body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(320px, 1fr); gap: 24px; padding: 16px; }
.report__body section + section { margin-top: 0; }
.answers { margin: 0 0 12px; padding-left: 24px; }
.answers li { padding: 3px 6px; }
.correct-answer { background: var(--mint-soft); color: #0e5b43; font-weight: 700; }
.details { display: grid; grid-template-columns: 88px minmax(0, 1fr); gap: 6px 12px; margin: 0; }
.details dt { color: var(--text-muted); font-weight: 650; }
.details dd { min-width: 0; margin: 0; overflow-wrap: anywhere; }
.report__actions { display: flex; align-items: center; min-height: 70px; gap: 8px; padding: 16px; border-top: 1px solid var(--border); }
.action-message { min-height: 22px; margin-left: 4px; color: var(--text-muted); }
.action-message[role="alert"] { color: var(--coral); }
.pagination { display: flex; align-items: center; justify-content: center; gap: 20px; margin-top: 20px; }
.pagination a { min-height: 40px; padding: 8px 10px; }

.login-page { display: grid; min-height: 100vh; place-items: center; padding: 24px; }
.login-shell { width: min(100%, 380px); }
.login-shell h1 { margin-bottom: 24px; }
.login-shell form { display: grid; gap: 8px; }
.login-shell input { width: 100%; margin-bottom: 8px; }
.login-shell .button { margin-top: 8px; }
.login-shell [role="alert"] { padding: 10px 12px; border-left: 4px solid var(--coral); background: var(--coral-soft); color: #7b2822; }

@media (max-width: 820px) {
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .table-grid { grid-template-columns: 1fr; }
  .report__body { grid-template-columns: 1fr; }
  .report__body section + section { margin-top: 4px; }
  .import-tool__heading { align-items: stretch; flex-direction: column; gap: 14px; }
  .import-form { grid-template-columns: auto minmax(0, 1fr); }
  .import-form .button { grid-column: 1 / -1; }
}

@media (max-width: 520px) {
  .topbar__inner { min-height: 52px; padding: 0 12px; }
  .account > span { display: none; }
  .navigation { padding: 0 4px; }
  .navigation a { padding: 9px 11px 8px; }
  .dashboard { padding: 18px 12px 24px; }
  .page-heading { align-items: start; margin-bottom: 18px; }
  h1 { font-size: 24px; }
  .period-control { align-items: start; flex-direction: column; gap: 2px; }
  .period-control label { font-size: 13px; }
  .period-control select { min-height: 38px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .metric { min-height: 118px; padding: 12px; }
  .metric__value { font-size: 24px; }
  table { min-width: 480px; }
  .report__header { display: block; }
  .report__summary { margin-top: 8px; text-align: left; }
  .report__body { padding: 12px; }
  .details { grid-template-columns: 76px minmax(0, 1fr); }
  .report__actions { flex-wrap: wrap; min-height: 76px; padding: 12px; }
  .action-message { flex-basis: 100%; margin-left: 0; }
  .import-tool { padding: 12px; }
  .quota-panel { padding: 12px; }
  .quota-panel__header { align-items: stretch; flex-direction: column; }
  .import-form { grid-template-columns: 1fr; }
  .import-form .button { grid-column: auto; }
}

@media (max-width: 340px) {
  .brand { font-size: 15px; }
  .button { padding-right: 10px; padding-left: 10px; }
  .metric h2 { font-size: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
