/* ==========================================================================
   IFS XBRL Utility — stylesheet
   Light and dark themes are both defined on :root so the page never depends on
   a media query alone; [data-theme] set by theme.js wins in both directions.
   ========================================================================== */

:root {
  --navy: #0b2545;
  --navy-600: #123a63;
  --teal: #1b998b;
  --teal-dark: #157a6e;
  --amber: #c77e23;
  --red: #b42318;

  --bg: #f5f7fa;
  --bg-elevated: #ffffff;
  --bg-sunken: #eef1f6;
  --surface-hover: #f7f9fc;
  --text: #101828;
  --text-muted: #667085;
  --text-inverse: #ffffff;
  --border: #dfe4ec;
  --border-strong: #c3ccda;
  --accent: var(--teal);
  --focus: #2563eb;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px -12px rgba(16, 24, 40, .18);
  --wrap: 1120px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117;
    --bg-elevated: #161b22;
    --bg-sunken: #10151c;
    --surface-hover: #1c2330;
    --text: #e6edf3;
    --text-muted: #97a3b6;
    --border: #262d38;
    --border-strong: #3a434f;
    --navy: #0e2340;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -12px rgba(0, 0, 0, .6);
  }
}

:root[data-theme="dark"] {
  --bg: #0d1117;
  --bg-elevated: #161b22;
  --bg-sunken: #10151c;
  --surface-hover: #1c2330;
  --text: #e6edf3;
  --text-muted: #97a3b6;
  --border: #262d38;
  --border-strong: #3a434f;
  --navy: #0e2340;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -12px rgba(0, 0, 0, .6);
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; letter-spacing: -.011em; }
h1 { font-size: clamp(1.6rem, 1.2rem + 1.4vw, 2.2rem); }
h2 { font-size: 1.2rem; }
p { margin: 0 0 1rem; }
p:last-child { margin-bottom: 0; }
a { color: var(--teal-dark); }
:root[data-theme="dark"] a, :root:not([data-theme="light"]) a { color: var(--teal); }

.wrap { width: 100%; max-width: var(--wrap); margin: 0 auto; padding: 0 clamp(1rem, 4vw, 2rem); }
.muted { color: var(--text-muted); font-size: .9rem; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--navy); color: #fff; padding: .6rem 1rem;
}
.skip-link:focus { left: .5rem; top: .5rem; }

:where(a, button, input, select, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

/* --- header ------------------------------------------------------------- */

.site-header {
  background: var(--navy);
  color: #fff;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; min-height: 64px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .7rem; color: #fff; text-decoration: none; }
.brand-mark {
  display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: 9px;
  background: var(--teal); color: #fff;
  font-weight: 700; font-size: .82rem; letter-spacing: .04em;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 1rem; }
.brand-text small { font-size: .74rem; opacity: .72; }

.site-nav { display: flex; align-items: center; gap: .35rem; }
.nav-link {
  color: rgba(255, 255, 255, .82);
  text-decoration: none; font-size: .9rem;
  padding: .4rem .7rem; border-radius: var(--radius-sm);
}
.nav-link:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.nav-link.is-active { background: rgba(255, 255, 255, .16); color: #fff; }
.inline-form { display: inline; }

.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center;
  background: rgba(255, 255, 255, .1); border: 0; border-radius: var(--radius-sm);
  cursor: pointer; color: #fff;
}
.icon-btn:hover { background: rgba(255, 255, 255, .2); }
.theme-icon { width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: inset -5px -3px 0 0 var(--navy); }
:root[data-theme="light"] .theme-icon { box-shadow: 0 0 0 2px rgba(255,255,255,.55); background: #ffd166; }

/* --- layout blocks ------------------------------------------------------ */

main { flex: 1; padding: clamp(1.5rem, 4vw, 2.75rem) 0 3rem; }

.hero { margin-bottom: 1.75rem; max-width: 62ch; }
.hero-compact { margin-bottom: 1.25rem; }
.lede { color: var(--text-muted); font-size: 1.02rem; }

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(1.1rem, 3vw, 1.75rem);
  margin-bottom: 1.25rem;
}

.stack { display: flex; flex-direction: column; gap: 1.1rem; }
.stack-tight { gap: .75rem; }
.actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.actions-inline { margin: 0; }

/* --- forms -------------------------------------------------------------- */

.field { display: flex; flex-direction: column; gap: .35rem; }
.field-label { font-size: .85rem; font-weight: 600; color: var(--text); }
.field-hint { font-size: .8rem; color: var(--text-muted); }

.input {
  width: 100%;
  font: inherit; font-size: .95rem;
  color: var(--text); background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: .62rem .75rem;
  transition: border-color .15s, box-shadow .15s;
}
.input:hover { border-color: var(--text-muted); }
.input:focus { border-color: var(--focus); box-shadow: 0 0 0 3px rgba(37, 99, 235, .15); outline: none; }
select.input { cursor: pointer; }

.checkbox { display: flex; align-items: flex-start; gap: .55rem; font-size: .88rem; color: var(--text-muted); cursor: pointer; }
.checkbox input { margin-top: .2rem; accent-color: var(--teal); width: 16px; height: 16px; }

.options { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 1rem; margin: 0; background: var(--bg-sunken); }
.options legend { padding: 0 .4rem; }
.options-grid { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: .8rem; }

.btn {
  font: inherit; font-size: .93rem; font-weight: 600;
  padding: .62rem 1.15rem; border-radius: var(--radius-sm);
  border: 1px solid transparent; cursor: pointer;
  display: inline-flex; align-items: center; gap: .45rem;
  text-decoration: none; transition: background .15s, border-color .15s, transform .06s;
}
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover:not([disabled]) { background: var(--teal-dark); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover:not([disabled]) { background: var(--surface-hover); }
.site-header .btn-ghost { color: #fff; border-color: rgba(255,255,255,.28); }
.site-header .btn-ghost:hover { background: rgba(255,255,255,.14); }
.btn-sm { font-size: .82rem; padding: .38rem .8rem; }
.btn-block { width: 100%; justify-content: center; }

/* --- tabs --------------------------------------------------------------- */

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.35rem; overflow-x: auto; }
.tab {
  font: inherit; font-size: .92rem; font-weight: 600;
  background: none; border: 0; border-bottom: 2px solid transparent;
  color: var(--text-muted); padding: .65rem .9rem; cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--teal-dark); border-bottom-color: var(--teal); }
:root[data-theme="dark"] .tab.is-active { color: var(--teal); }
.panel { display: none; }
.panel.is-active { display: block; }

.chips { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin-top: -.4rem; }
.chips-label { font-size: .82rem; color: var(--text-muted); }
.chip {
  font: inherit; font-size: .8rem; padding: .22rem .6rem; cursor: pointer;
  background: var(--bg-sunken); border: 1px solid var(--border); border-radius: 999px; color: var(--text);
}
.chip:hover { border-color: var(--teal); color: var(--teal-dark); }

/* --- dropzone ----------------------------------------------------------- */

.dropzone {
  border: 2px dashed var(--border-strong); border-radius: var(--radius);
  padding: 2rem 1rem; text-align: center; cursor: pointer;
  background: var(--bg-sunken); transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.is-dragging { border-color: var(--teal); background: var(--surface-hover); }
.dropzone-title { font-weight: 600; margin-bottom: .3rem; }
.dropzone-hint { font-size: .84rem; color: var(--text-muted); margin: 0; }
.dropzone-file { margin: .8rem 0 0; font-size: .88rem; font-weight: 600; color: var(--teal-dark); word-break: break-all; }
:root[data-theme="dark"] .dropzone-file { color: var(--teal); }

/* --- alerts ------------------------------------------------------------- */

.alert {
  border-radius: var(--radius-sm); padding: .7rem .9rem; font-size: .88rem;
  border: 1px solid var(--border); background: var(--bg-sunken); margin: 1rem 0 0;
}
.alert-error { border-color: rgba(180, 35, 24, .35); background: rgba(180, 35, 24, .08); color: var(--red); }
.alert-warn { border-color: rgba(199, 126, 35, .38); background: rgba(199, 126, 35, .09); }
.alert-ok { border-color: rgba(27, 153, 139, .35); background: rgba(27, 153, 139, .08); }
:root[data-theme="dark"] .alert-error { color: #ff9a90; }

/* --- progress ----------------------------------------------------------- */

.progress-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.progress-head h2 { margin: 0; font-size: 1.02rem; }
.progress-track { height: 8px; border-radius: 999px; background: var(--bg-sunken); overflow: hidden; margin: .9rem 0 .6rem; }
.progress-bar { height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, var(--teal), var(--navy-600)); transition: width .35s ease; }
.progress-card.is-failed .progress-bar { background: var(--red); }

/* --- results ------------------------------------------------------------ */

.result-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.result-head h2 { margin-bottom: .2rem; }
.badges { display: flex; gap: .4rem; flex-wrap: wrap; }
.badge {
  font-size: .76rem; font-weight: 600; padding: .25rem .6rem; border-radius: 999px;
  background: var(--bg-sunken); border: 1px solid var(--border); color: var(--text-muted);
}
.badge-good { border-color: rgba(27,153,139,.4); color: var(--teal-dark); background: rgba(27,153,139,.1); }
.badge-warn { border-color: rgba(199,126,35,.4); color: var(--amber); background: rgba(199,126,35,.1); }
:root[data-theme="dark"] .badge-good { color: var(--teal); }

.downloads { display: flex; gap: .55rem; flex-wrap: wrap; margin-bottom: 1rem; }

.check-list { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: .8rem; }
.check {
  font-size: .78rem; padding: .25rem .6rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-sunken);
}
.check-pass { border-color: rgba(27,153,139,.35); }
.check-fail { border-color: rgba(180,35,24,.4); color: var(--red); background: rgba(180,35,24,.07); }

/* --- tables ------------------------------------------------------------- */

.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.statement-table { width: 100%; border-collapse: collapse; font-size: .875rem; min-width: 640px; }
.statement-table th, .statement-table td { padding: .5rem .75rem; text-align: left; border-bottom: 1px solid var(--border); }
.statement-table thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--bg-sunken); font-size: .78rem; text-transform: uppercase;
  letter-spacing: .04em; color: var(--text-muted); white-space: nowrap;
}
.statement-table tbody tr:hover { background: var(--surface-hover); }
.statement-table td.value { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.statement-table th.value { text-align: right; }
.statement-table .row-subtotal { font-weight: 700; background: var(--bg-sunken); }
.statement-table .row-subtotal td { border-top: 1px solid var(--border-strong); }
.statement-table .row-missing td.item { color: var(--text-muted); }
.item-indent-1 { padding-left: 1.9rem !important; }
.cell-empty { color: var(--border-strong); }
.cell-negative { color: var(--red); }
:root[data-theme="dark"] .cell-negative { color: #ff9a90; }
.concept { font-family: var(--mono); font-size: .74rem; color: var(--text-muted); word-break: break-all; }
.coverage-table td { vertical-align: top; }
.admin-table { min-width: 720px; }
.truncate { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.error-text { font-size: .76rem; color: var(--red); white-space: normal; max-width: 40ch; }

.table-legend { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; font-size: .78rem; color: var(--text-muted); margin: .75rem 0 0; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; margin-left: .7rem; }
.legend-dot:first-child { margin-left: 0; }
.legend-tagged { background: var(--teal); }
.legend-derived { background: var(--amber); }
.legend-missing { background: var(--border-strong); }

.tag { font-size: .68rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.tag-tagged { color: var(--teal-dark); }
.tag-derived { color: var(--amber); }
.tag-missing { color: var(--text-muted); }
:root[data-theme="dark"] .tag-tagged { color: var(--teal); }

.pill { display: inline-block; font-size: .72rem; font-weight: 600; padding: .12rem .5rem; border-radius: 999px; border: 1px solid var(--border); }
.pill-done { color: var(--teal-dark); border-color: rgba(27,153,139,.4); background: rgba(27,153,139,.1); }
.pill-failed { color: var(--red); border-color: rgba(180,35,24,.4); background: rgba(180,35,24,.08); }
.pill-running, .pill-queued { color: var(--amber); border-color: rgba(199,126,35,.4); background: rgba(199,126,35,.1); }
.pill-cache { color: var(--text-muted); }

/* --- disclosure --------------------------------------------------------- */

.disclosure summary { cursor: pointer; font-size: .92rem; padding: .2rem 0; }
.disclosure summary::marker { color: var(--text-muted); }
.disclosure[open] summary { margin-bottom: .9rem; }

/* --- stats -------------------------------------------------------------- */

.stat-grid { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 1.25rem; }
.stat { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.stat-value { display: block; font-size: 1.55rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.15; }
.stat-label { display: block; font-size: .78rem; color: var(--text-muted); margin-top: .2rem; }
.stat-warn .stat-value { color: var(--amber); }

/* --- login -------------------------------------------------------------- */

.login-layout { display: grid; gap: 1.5rem; grid-template-columns: minmax(0, 1fr); align-items: start; max-width: 940px; margin: 0 auto; }
@media (min-width: 820px) { .login-layout { grid-template-columns: 400px minmax(0, 1fr); gap: 2.5rem; } }
.login-card { margin-bottom: 0; }
.login-card h1 { font-size: 1.5rem; }
.hint { font-size: .8rem; color: var(--text-muted); margin: 1rem 0 0; }
.login-aside h2 { font-size: 1.05rem; margin-bottom: .9rem; }
.feature-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1rem; }
.feature-list li { font-size: .88rem; color: var(--text-muted); border-left: 2px solid var(--teal); padding-left: .9rem; }
.feature-list strong { display: block; color: var(--text); font-size: .95rem; margin-bottom: .15rem; }

/* --- error page --------------------------------------------------------- */

.error-card { max-width: 560px; margin: 2rem auto; text-align: center; }
.error-code { font-size: 3rem; font-weight: 800; color: var(--border-strong); margin: 0; line-height: 1; }
.error-card .actions { justify-content: center; margin-top: 1.25rem; }

/* --- footer ------------------------------------------------------------- */

.site-footer { border-top: 1px solid var(--border); background: var(--bg-elevated); padding: 1.5rem 0; }
.footer-inner p { margin: 0 0 .3rem; font-size: .85rem; }
.footer-inner .muted { font-size: .8rem; max-width: 75ch; }

@media (max-width: 640px) {
  .header-inner { min-height: 56px; padding-top: .5rem; padding-bottom: .5rem; }
  .brand-text small { display: none; }
  .nav-link { padding: .35rem .5rem; }
  .card { padding: 1.05rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

@media print {
  .site-header, .site-footer, .tabs, .downloads, .actions, .progress-card { display: none !important; }
  .card { box-shadow: none; border: 0; }
  .table-scroll { overflow: visible; border: 0; }
}

.proxy-table { min-width: 0; }
.proxy-table td:first-child { width: 200px; color: var(--text-muted); }
.proxy-table code { font-family: var(--mono); font-size: .82rem; word-break: break-all; }
