/* ============================================================
   Thin theme layer over Bootstrap 5.
   Every colour here was checked for WCAG AA contrast against the
   surface it actually renders on — see mockup/index.html, where
   the same tokens were validated before being lifted across.
   Bootstrap's own --bs-secondary (#6c757d) and the default muted
   grey both fall below 4.5:1 for text, hence --muted-text.
   ============================================================ */
:root {
  color-scheme: light;

  /* Bootstrap core overrides */
  --bs-body-font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  --bs-body-font-size: .875rem;
  --bs-body-bg: #f9f9f7;
  --bs-body-color: #0b0b0b;
  --bs-secondary-color: #52514e;
  --bs-border-color: #e1e0d9;
  --bs-border-radius: .5rem;
  --bs-primary: #184f95;              /* 8.1:1 on white; Bootstrap's #0d6efd is 4.3:1 */
  --bs-primary-rgb: 24, 79, 149;
  --bs-link-color: #184f95;
  --bs-link-hover-color: #0d366b;
  /* What Bootstrap 5.3 actually reads for <a>. */
  --bs-link-color-rgb: 24, 79, 149;
  --bs-link-hover-color-rgb: 13, 54, 107;

  /* project tokens */
  --surface: #fcfcfb;
  --muted-text: #6b6963;              /* 5.35:1 — greys that carry meaning */
  --accent-weak: #cde2fb;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --success-text: #006300;
}

body { background: var(--bs-body-bg); }

.card { --bs-card-bg: var(--surface); --bs-card-border-color: rgba(11, 11, 11, .10); }

.btn-primary {
  --bs-btn-bg: #184f95; --bs-btn-border-color: #184f95;
  --bs-btn-hover-bg: #0d366b; --bs-btn-hover-border-color: #0d366b;
  --bs-btn-active-bg: #0d366b; --bs-btn-active-border-color: #0d366b;
}

.navbar { background: var(--surface); border-bottom: 1px solid rgba(11, 11, 11, .10); }
.nav-pills { --bs-nav-pills-link-active-bg: var(--accent-weak); --bs-nav-pills-link-active-color: #184f95; }
.nav-pills .nav-link { color: var(--bs-secondary-color); }
.nav-pills .nav-link.active { font-weight: 600; }
.nav-pills .nav-link { transition: background-color .15s, color .15s; white-space: nowrap; }
.nav-pills .nav-link:not(.active):hover,
.nav-pills .nav-link:not(.active):focus-visible,
.nav-pills .nav-link.show:not(.active) { background: #efeee9; color: var(--bs-body-color); }
.nav-pills .nav-link.active:hover { background: #bcd7f8; }

/* The Stammdaten menu speaks the same language as the pills. */
.dropdown-menu {
  --bs-dropdown-link-hover-bg: #efeee9;
  --bs-dropdown-link-active-bg: var(--accent-weak);
  --bs-dropdown-link-active-color: #184f95;
  --bs-dropdown-font-size: .875rem;
}
.dropdown-item.active { font-weight: 600; }

/* Profil and Abmelden, right of the menu: the same hover as the pills. */
.site-account .nav-link {
  color: var(--bs-secondary-color); text-decoration: none; border-radius: var(--bs-nav-pills-border-radius, .375rem);
  transition: background-color .15s, color .15s;
}
.site-account .nav-link:hover, .site-account .nav-link:focus-visible { background: #efeee9; color: var(--bs-body-color); }
.site-account .nav-link.active { background: var(--accent-weak); color: #184f95; font-weight: 600; }

.table { --bs-table-bg: var(--surface); --bs-table-hover-bg: #faf9f6; }
.table > thead th {
  font-size: .6875rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted-text); font-weight: 600; border-bottom-color: var(--bs-border-color);
}

/* Bootstrap's .text-muted is too light once the grey carries meaning. */
.text-muted { color: var(--muted-text) !important; }

/* Bootstrap's --bs-code-color (#d63384) is 4.38:1 on this surface — just under AA. */
:root { --bs-code-color: #a02c68; }
.small-sub { display: block; color: var(--muted-text); font-size: .72rem; line-height: 1.3; }
.ledger-provider { font-weight: 600; }

/* Links in the page body: link-coloured, underlined only on hover. */
main a { text-decoration: none; }
main a:not(.btn):not(.badge):not(.page-link):not(.nav-link):not(.stretched-link):hover { text-decoration: underline; text-underline-offset: .2em; }

.person-card-header { position: relative; background: transparent; transition: background-color .15s; }
.person-card-header:hover { background: var(--accent-weak); }

/* Columns of figures align; standalone stat values stay proportional. */
.num { text-align: right; font-variant-numeric: tabular-nums; }
.stat-value { white-space: nowrap; letter-spacing: -.02em; }

.progress { --bs-progress-bg: var(--accent-weak); --bs-progress-height: .5rem; --bs-progress-bar-bg: #184f95; }
.progress.is-na { --bs-progress-bg: var(--bs-border-color); }
.progress.is-full { --bs-progress-bar-bg: var(--good); }

/* ---- status: icon + colour + label, never colour alone ---- */
.status { display: inline-flex; align-items: center; gap: .375rem; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.status .ic { font-size: 15px; line-height: 1; flex: none; }
.st-overdue .ic { color: var(--critical); }            .st-overdue { color: #a32e2e; }
.st-filed   .ic { color: var(--warning); }             .st-filed   { color: #7a5800; }
.st-open    .ic { color: var(--serious); }             .st-open    { color: #9a4a24; }
.st-settled .ic { color: var(--good); }                .st-settled { color: var(--success-text); }
.st-direct  .ic { color: var(--bs-secondary-color); }  .st-direct  { color: var(--bs-secondary-color); }

/* ---- provenance of every extracted value ---- */
.prov {
  font-size: .625rem; font-weight: 600; letter-spacing: .03em; text-transform: uppercase;
  padding: .125rem .375rem; border-radius: .25rem; border: 1px solid rgba(11, 11, 11, .10);
  background: var(--bs-body-bg); color: var(--bs-secondary-color); min-width: 58px; text-align: center;
}
.prov-rule   { background: #eef4ec; border-color: #cfe0ca; color: #2f5c28; }
.prov-qr     { background: #eaf1fb; border-color: #c8dbf5; color: #184f95; }
.prov-model  { background: #fdf3e3; border-color: #f0dcb4; color: #7a5800; }
.prov-manual { background: #f4eef8; border-color: #ddd0e8; color: #5b3a75; }
.prov-calc   { background: var(--bs-body-bg); }
.prov-missing { background: var(--serious); border-color: var(--serious); color: #4a1f0a; }

/* ---- review split ---- */
.field {
  display: grid; grid-template-columns: 1fr auto auto; gap: .5rem; align-items: center;
  padding: .5rem 1rem; border-left: 3px solid transparent;
}
.field:hover { background: #faf9f6; }
.field.is-focus { background: #f2f7fe; border-left-color: #184f95; }
.field.is-low { background: #fffaf0; border-left-color: var(--warning); }
.field.is-missing { background: #fdf1ef; border-left-color: #d93025; }
.field.is-missing .k { color: #b3261e; font-weight: 600; }
.field.is-missing.is-focus { border-left-color: #184f95; }
.field[data-path] { cursor: text; }
.date-picker { position: relative; flex-wrap: nowrap; min-width: 9.5rem; }
/* The wrapper moved the input away from its ActiveForm error message. */
.date-picker:has(.is-invalid) ~ .invalid-feedback { display: block; }
.date-picker-native { position: absolute; right: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.edit-error { grid-column: 1 / -1; color: #b3261e; font-size: .75rem; text-align: right; }
.field .k { color: var(--bs-secondary-color); }
.field .v { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
.field .v.is-text { font-variant-numeric: normal; }

.dropzone {
  border: 2px dashed #c3c2b7; border-radius: .5rem; background: var(--surface);
  padding: 2.5rem 1rem; text-align: center;
}
.dropzone.is-dragover { border-color: #184f95; background: #f2f7fe; }

/* As on kochfamily.ch: the navbar's surface and hairline, mirrored at the bottom. */
.pdf-download { color: var(--muted-text); vertical-align: -2px; }
.pdf-download:hover { color: #184f95; }
/* All pages stacked; at 100 % each fits the dialog, so one scrolls page by page.
   A fixed height, not a max: the dialog keeps its size while zooming, and the
   controls stay under the mouse. */
.pdf-lightbox .pdf-scroll { height: calc(100dvh - 9rem); overflow: auto; }
.pdf-lightbox .pdf-scroll img { max-height: calc(100dvh - 11rem); box-shadow: 0 0 0 1px var(--bs-border-color); }
.pdf-lightbox .pdf-scroll img + img, .pdf-pages img + img { margin-top: .75rem; }
.pdf-pages img + img { border-top: 1px solid var(--bs-border-color); }
/* Pages are dragged with the mouse at any zoom (app.js). */
.pdf-scroll img, .pdf-pages img { cursor: grab; }
.is-dragging, .is-dragging img { cursor: grabbing; user-select: none; }

/* The footer sits at the bottom of short pages. dvh, not vh: on phones 100vh is
   the height with the browser bars hidden, which pushes the footer out of view. */
body { min-height: 100vh; min-height: 100dvh; }

/* ---- Navigation: inline from lg, a drawer from the right below ---------------- */

.site-nav { display: flex; align-items: center; flex: 1; min-width: 0; }
.site-burger { display: none; }
/* The app name shows except between lg and xl, where the full menu needs the room.
   On a narrow phone it shortens with an ellipsis instead of pushing the burger out. */
.site-brand { min-width: 0; flex: 0 1 auto; }
.site-title { min-width: 0; }

@media (max-width: 991.98px) {
  .site-burger {
    display: grid; place-items: center; margin-left: auto; position: relative; z-index: 3;
    border: 0; background: none; padding: .4rem; border-radius: .375rem; color: var(--bs-body-color);
  }
  .site-burger:hover { background: #efeee9; }
  .site-burger .bi { font-size: 22px; line-height: 1; }
  .site-burger .icon-close,
  .site-burger[aria-expanded="true"] .icon-open { display: none; }
  .site-burger[aria-expanded="true"] .icon-close { display: block; }

  .site-nav {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 2; width: min(320px, 85vw);
    flex-direction: column; align-items: stretch; padding: 64px 1rem 1rem;
    background: var(--surface); box-shadow: -8px 0 24px rgba(11, 11, 11, .12); overflow-y: auto;
    translate: 100% 0; visibility: hidden; transition: translate .3s ease, visibility 0s .3s;
  }
  .site-nav.is-open { translate: 0 0; visibility: visible; transition: translate .3s ease; }
  .site-header::before {
    content: ''; position: fixed; inset: 0; z-index: 1; background: rgba(11, 11, 11, .35);
    opacity: 0; visibility: hidden; transition: opacity .3s ease, visibility 0s .3s;
  }
  .site-header.is-open::before { opacity: 1; visibility: visible; transition: opacity .3s ease; }
  body.nav-open { overflow: hidden; }

  .site-nav .nav { flex-direction: column; align-items: stretch; gap: .125rem; margin: 0 !important; }
  .site-nav .nav-link { padding: .6rem .75rem !important; font-size: .9375rem; }
  /* In the drawer Stammdaten is a heading with its entries listed below, no toggle. */
  .site-nav .dropdown-toggle { pointer-events: none; }
  .site-nav .dropdown-toggle::after { display: none; }
  .site-nav .dropdown-menu {
    position: static; display: block; float: none; border: 0; border-left: 2px solid var(--bs-border-color);
    border-radius: 0; box-shadow: none; background: none; margin: 0 0 0 .75rem; padding: 0 0 0 .5rem;
  }
  .site-nav .dropdown-item { padding: .5rem .75rem; border-radius: .375rem; }
  .site-account { flex-direction: column; align-items: stretch !important; margin: 1rem 0 0 !important; padding-top: 1rem; border-top: 1px solid var(--bs-border-color); }
  .site-account .nav-link { text-align: left; width: 100%; padding: .6rem .75rem !important; font-size: .9375rem; }
}

@media (prefers-reduced-motion: reduce) {
  .site-nav, .site-header::before { transition: none !important; }
}

.site-footer {
  flex-shrink: 0;
  border-top: 1px solid rgba(11, 11, 11, .10);
  background: var(--surface);
  color: var(--muted-text);
  padding: 1.25rem 0;
  font-size: .8125rem;
}

kbd {
  font-size: .6875rem; background: var(--bs-body-bg); border: 1px solid #c3c2b7;
  border-bottom-width: 2px; border-radius: .25rem; padding: .05rem .3rem;
  color: var(--bs-secondary-color);
}

/* ============================================================
   Dark theme: the profile page's choice, or the system setting
   (abilitynet\account\Theme sets data-bs-theme on <html>). The
   same roles as above, re-picked for a dark surface; text tokens
   keep at least 4.5:1 against --surface.
   ============================================================ */
[data-bs-theme="dark"] {
  color-scheme: dark;

  --bs-body-bg: #161615;
  --bs-body-color: #ecebe6;
  --bs-secondary-color: #b4b2aa;
  --bs-border-color: #3a3935;
  --bs-primary: #7fb0ec;
  --bs-primary-rgb: 127, 176, 236;
  --bs-link-color: #8dbaf0;
  --bs-link-hover-color: #b5d2f6;
  --bs-link-color-rgb: 141, 186, 240;
  --bs-link-hover-color-rgb: 181, 210, 246;
  --bs-code-color: #f08cc0;

  --surface: #1f1f1d;
  --muted-text: #a8a69e;
  --accent-weak: #1e3a5f;
  --good: #3fbf3f;
  --warning: #f2b630;
  --serious: #ec835a;
  --critical: #e05a5a;
  --success-text: #6fd36f;
  --hover-bg: #2a2a27;
  --active-text: #cfe2fb;
  --hairline: rgba(255, 255, 255, .10);
}

[data-bs-theme="dark"] .card { --bs-card-border-color: var(--hairline); }
[data-bs-theme="dark"] .navbar,
[data-bs-theme="dark"] .site-footer { border-color: var(--hairline); }
[data-bs-theme="dark"] .nav-pills { --bs-nav-pills-link-active-color: var(--active-text); }
[data-bs-theme="dark"] .nav-pills .nav-link:not(.active):hover,
[data-bs-theme="dark"] .nav-pills .nav-link:not(.active):focus-visible,
[data-bs-theme="dark"] .nav-pills .nav-link.show:not(.active),
[data-bs-theme="dark"] .site-account .nav-link:hover,
[data-bs-theme="dark"] .site-account .nav-link:focus-visible,
[data-bs-theme="dark"] .site-burger:hover { background: var(--hover-bg); }
[data-bs-theme="dark"] .nav-pills .nav-link.active:hover { background: #26476f; }
[data-bs-theme="dark"] .site-account .nav-link.active { color: var(--active-text); }
[data-bs-theme="dark"] .dropdown-menu {
  --bs-dropdown-link-hover-bg: var(--hover-bg);
  --bs-dropdown-link-active-color: var(--active-text);
}
[data-bs-theme="dark"] .table { --bs-table-hover-bg: #252523; }
[data-bs-theme="dark"] .progress { --bs-progress-bar-bg: var(--bs-primary); }

[data-bs-theme="dark"] .st-overdue { color: #f08a8a; }
[data-bs-theme="dark"] .st-filed   { color: #e8c15a; }
[data-bs-theme="dark"] .st-open    { color: #f0a27a; }

[data-bs-theme="dark"] .prov         { border-color: var(--hairline); }
[data-bs-theme="dark"] .prov-rule    { background: #1f3320; border-color: #2f5c28; color: #a8d8a0; }
[data-bs-theme="dark"] .prov-qr      { background: #152a45; border-color: #24497a; color: #9cc3f0; }
[data-bs-theme="dark"] .prov-model   { background: #3a2c10; border-color: #6b5320; color: #f0cf80; }
[data-bs-theme="dark"] .prov-manual  { background: #2e2338; border-color: #4d3a5e; color: #d3b8e8; }

[data-bs-theme="dark"] .field:hover { background: #252523; }
[data-bs-theme="dark"] .field.is-focus,
[data-bs-theme="dark"] .field.is-missing.is-focus { background: #172840; border-left-color: var(--bs-primary); }
[data-bs-theme="dark"] .field.is-low { background: #2e2614; }
[data-bs-theme="dark"] .field.is-missing { background: #3a1d1a; }
[data-bs-theme="dark"] .field.is-missing .k,
[data-bs-theme="dark"] .edit-error { color: #f2a19b; }

[data-bs-theme="dark"] .dropzone,
[data-bs-theme="dark"] kbd { border-color: #55534d; }
[data-bs-theme="dark"] .dropzone.is-dragover { background: #172840; border-color: var(--bs-primary); }
[data-bs-theme="dark"] .pdf-download:hover { color: var(--bs-link-color); }
