/* MS — design tokens and shared components. Tailwind (CDN) handles layout utilities;
   colours go through the variables below so light and dark stay in one place. */

:root {
  --bg: #f5f7f7;
  --surface: #ffffff;
  --surface-2: #f1f5f6;
  --surface-3: #e8eef0;
  --text: #1e293b;
  --text-2: #334155;
  --muted: #64748b;
  --faint: #94a3b8;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --brand: #1f7a7a;
  --brand-strong: #176363;
  --brand-soft: #e8f4f4;
  --brand-ink: #114c4c;
  --ok: #047857;   --ok-soft: #ecfdf5;   --ok-line: #a7f3d0;
  --warn: #b45309; --warn-soft: #fffbeb; --warn-line: #fde68a;
  --bad: #b91c1c;  --bad-soft: #fef2f2;  --bad-line: #fecaca;
  --ring: rgb(31 122 122 / .25);
  --shadow: 0 1px 2px rgb(15 23 42 / .04), 0 1px 3px rgb(15 23 42 / .06);
  --shadow-lg: 0 10px 30px -10px rgb(15 23 42 / .25);
  --zebra: #fafbfc;
  --hover: #f0f7f7;
}

.dark {
  color-scheme: dark;
  --bg: #0b1213;
  --surface: #111b1c;
  --surface-2: #162324;
  --surface-3: #1d2d2e;
  --text: #e2e8f0;
  --text-2: #cbd5e1;
  --muted: #94a3b8;
  --faint: #64748b;
  --border: #223435;
  --border-strong: #2f4647;
  --brand: #2a9d9d;
  --brand-strong: #38b2b2;
  --brand-soft: #15302f;
  --brand-ink: #9fd9d9;
  --ok: #34d399;   --ok-soft: #0a2a20;   --ok-line: #14532d;
  --warn: #fbbf24; --warn-soft: #2a210c; --warn-line: #713f12;
  --bad: #f87171;  --bad-soft: #2c1416;  --bad-line: #7f1d1d;
  --ring: rgb(56 178 178 / .3);
  --shadow: 0 1px 2px rgb(0 0 0 / .3);
  --shadow-lg: 0 10px 30px -10px rgb(0 0 0 / .6);
  --zebra: #131f20;
  --hover: #1a2a2b;
}

body.app { background: var(--bg); color: var(--text); }

/* Map the handful of Tailwind colour utilities the templates use onto the tokens in dark mode. */
.dark .bg-white { background: var(--surface); }
.dark .bg-slate-50 { background: var(--surface-2); }
.dark .bg-slate-100 { background: var(--surface-3); }
.dark .text-slate-800, .dark .text-slate-700 { color: var(--text); }
.dark .text-slate-600, .dark .text-slate-500 { color: var(--muted); }
.dark .text-slate-400 { color: var(--faint); }
.dark .border-slate-200, .dark .border-slate-300 { border-color: var(--border-strong); }
.dark .bg-red-50 { background: var(--bad-soft); }
.dark .text-red-700, .dark .text-red-800 { color: var(--bad); }
.dark .bg-emerald-50 { background: var(--ok-soft); }
.dark .text-emerald-700, .dark .text-emerald-800 { color: var(--ok); }
.dark .bg-amber-50 { background: var(--warn-soft); }
.dark .text-amber-700, .dark .text-amber-800 { color: var(--warn); }
.dark .border-amber-300 { border-color: var(--warn-line); }
.dark .text-brand-600, .dark .text-brand-700 { color: var(--brand-ink); }
.dark .bg-brand-50 { background: var(--brand-soft); }
.dark .from-brand-50 { --tw-gradient-from: var(--bg) var(--tw-gradient-from-position); --tw-gradient-to: rgb(0 0 0 / 0) var(--tw-gradient-to-position); --tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to); }
.dark .to-slate-100 { --tw-gradient-to: var(--surface-2) var(--tw-gradient-to-position); }

/* ---------- basics ---------- */
[x-cloak] { display: none !important; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.text-muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }
[dir=ltr] .flip-ltr { transform: scaleX(-1); }

/* ---------- cards & page header ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: .9rem; padding: 1.25rem; box-shadow: var(--shadow); }
a.card { transition: border-color .15s, box-shadow .15s, transform .15s; }
a.card:hover { border-color: var(--brand); box-shadow: var(--shadow-lg); }
.page-sub { color: var(--muted); font-size: .875rem; }
.chip { display: inline-flex; align-items: center; gap: .35rem; border-radius: 999px; padding: .2rem .65rem; font-size: .78rem;
        background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; border-radius: .55rem; padding: .5rem 1rem;
       font-weight: 500; font-size: .9rem; line-height: 1.25rem; border: 1px solid transparent; transition: background .15s, color .15s, box-shadow .15s; cursor: pointer; }
.btn:disabled, .btn[aria-busy=true] { opacity: .7; cursor: progress; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: var(--shadow); }
.btn-primary:hover { background: var(--brand-strong); }
.btn-soft { background: var(--brand-soft); color: var(--brand-ink); }
.btn-soft:hover { background: var(--surface-3); }
.btn-ghost { background: transparent; color: var(--text-2); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--bad-soft); color: var(--bad); border-color: var(--bad-line); }
.btn-danger:hover { background: var(--bad); color: #fff; }
.btn-danger-solid { background: var(--bad); color: #fff; }
.btn-danger-solid:hover { filter: brightness(.92); }
.btn-sm { padding: .3rem .7rem; font-size: .8rem; }

.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 2rem; height: 2rem; border-radius: .5rem;
            color: var(--muted); transition: background .15s, color .15s; }
.icon-btn:hover { background: var(--surface-3); color: var(--brand-ink); }
.icon-btn.danger:hover { background: var(--bad-soft); color: var(--bad); }

/* loading spinner shown on a submitting button */
.is-loading { position: relative; color: transparent !important; pointer-events: none; }
.is-loading::after { content: ""; position: absolute; inset: 0; margin: auto; width: 1rem; height: 1rem; border-radius: 50%;
                     border: 2px solid currentColor; border-color: rgb(255 255 255 / .9) rgb(255 255 255 / .9) transparent transparent;
                     animation: spin .7s linear infinite; }
.btn-soft.is-loading::after, .btn-ghost.is-loading::after, .icon-btn.is-loading::after { border-color: var(--brand) var(--brand) transparent transparent; }
.htmx-request.btn, .htmx-request .btn[type=submit] { opacity: .7; cursor: progress; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- segmented control (filters) ---------- */
.seg { display: inline-flex; gap: .25rem; padding: .25rem; border-radius: .7rem; background: var(--surface-2); border: 1px solid var(--border); }
.seg a { display: inline-flex; align-items: center; gap: .4rem; padding: .35rem .85rem; border-radius: .5rem; font-size: .85rem; color: var(--muted); }
.seg a:hover { color: var(--text); }
.seg a[aria-current] { background: var(--surface); color: var(--brand-ink); font-weight: 600; box-shadow: var(--shadow); }
.seg .count { font-size: .72rem; padding: 0 .4rem; border-radius: 999px; background: var(--surface-3); }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: .25rem; border-radius: 999px; padding: .1rem .55rem; font-size: .74rem; font-weight: 500;
         border: 1px solid transparent; white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-line); }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-line); }
.badge-bad { background: var(--bad-soft); color: var(--bad); border-color: var(--bad-line); }
.badge-muted { background: var(--surface-2); color: var(--muted); border-color: var(--border); }
.badge-brand { background: var(--brand-soft); color: var(--brand-ink); }

/* ---------- forms ---------- */
.field label { display: block; font-size: .85rem; color: var(--text-2); margin-bottom: .3rem; font-weight: 500; }
.field .req { color: var(--bad); margin-inline-start: .15rem; }
.field input:not([type=checkbox]):not([type=radio]):not([type=file]), .field select, .field textarea,
input.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--border-strong); border-radius: .55rem; padding: .5rem .75rem; background: var(--surface); color: var(--text);
  transition: border-color .15s, box-shadow .15s; }
.field input:focus, .field select:focus, .field textarea:focus, .input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }
.field [aria-invalid=true] { border-color: var(--bad) !important; }
.field [aria-invalid=true]:focus { box-shadow: 0 0 0 3px rgb(185 28 28 / .2) !important; }
.field .help { color: var(--muted); font-size: .78rem; margin-top: .25rem; }
.field-error, .errorlist { color: var(--bad); font-size: .8rem; margin-top: .3rem; }
.error-summary { display: flex; gap: .6rem; align-items: flex-start; border: 1px solid var(--bad-line); background: var(--bad-soft); color: var(--bad);
                 border-radius: .7rem; padding: .75rem 1rem; margin-bottom: 1rem; font-size: .9rem; }
.form-section-title { font-weight: 600; color: var(--text); margin-bottom: .9rem; display: flex; align-items: center; gap: .5rem; }
.tab-dot { width: .45rem; height: .45rem; border-radius: 999px; background: var(--bad); display: inline-block; }

/* ---------- tables ---------- */
/* NB: Tailwind also has a `.grid` utility (display:grid); `table.grid` wins on specificity and keeps real table layout. */
.table-wrap { overflow: auto; max-height: calc(100vh - 14rem); border-radius: .9rem; }
table.grid { display: table; width: 100%; border-collapse: separate; border-spacing: 0; font-size: .875rem; }
table.grid th { position: sticky; top: 0; z-index: 2; background: var(--surface-2); color: var(--text-2); font-weight: 600; font-size: .8rem;
                text-align: start; padding: .6rem .6rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.grid td { padding: .45rem .6rem; border-bottom: 1px solid var(--border); }
table.grid tbody tr:nth-child(even) td { background: var(--zebra); }
table.grid tbody tr:hover td { background: var(--hover); }
table.grid tfoot td { position: sticky; bottom: 0; z-index: 1; background: var(--surface-2); font-weight: 700; border-top: 2px solid var(--border-strong); border-bottom: 0; }
table.grid tr.dim td { color: var(--faint); }
table.grid td.actions { white-space: nowrap; text-align: end; }
table.grid th.text-end { text-align: end; }

/* numbers are always LTR; align them (and their headers) to the line end of the page direction */
.num { font-variant-numeric: tabular-nums; direction: ltr; text-align: right; }
[dir=rtl] .num { text-align: left; }
table.grid th.num { direction: inherit; }
[dir=rtl] table.grid th.num { text-align: left; }
[dir=ltr] table.grid th.num { text-align: right; }
[dir=rtl] .num-start { text-align: right; } [dir=ltr] .num-start { text-align: left; }
[dir=rtl] .indent-end { padding-left: var(--d); } [dir=ltr] .indent-end { padding-right: var(--d); }

/* ---------- empty state ---------- */
.empty { text-align: center; padding: 3rem 1.5rem; }
.empty .empty-icon { width: 3.25rem; height: 3.25rem; margin: 0 auto 1rem; border-radius: 1rem; display: grid; place-items: center;
                     background: var(--brand-soft); color: var(--brand); }
.empty h2 { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.empty p { color: var(--muted); max-width: 34rem; margin: .4rem auto 1.25rem; line-height: 1.8; font-size: .9rem; }

/* ---------- KPI tiles ---------- */
.kpi { display: flex; gap: .9rem; align-items: flex-start; }
.kpi .kpi-icon { flex: none; width: 2.6rem; height: 2.6rem; border-radius: .75rem; display: grid; place-items: center; }
.kpi .kpi-label { color: var(--muted); font-size: .85rem; }
.kpi .kpi-value { font-size: 1.7rem; font-weight: 700; line-height: 1.2; margin-top: .15rem; font-variant-numeric: tabular-nums; }
.kpi .kpi-hint { font-size: .76rem; color: var(--faint); margin-top: .2rem; display: flex; align-items: center; gap: .2rem; }
.tone-neutral .kpi-icon { background: var(--brand-soft); color: var(--brand); }
.tone-ok .kpi-icon { background: var(--ok-soft); color: var(--ok); }
.tone-ok .kpi-value { color: var(--ok); }
.tone-warn .kpi-icon { background: var(--warn-soft); color: var(--warn); }
.tone-warn .kpi-value { color: var(--warn); }
.tone-bad .kpi-icon { background: var(--bad-soft); color: var(--bad); }
.tone-bad .kpi-value { color: var(--bad); }
.tone-muted { opacity: .75; }
.tone-muted .kpi-icon { background: var(--surface-2); color: var(--faint); }

/* checklist */
.steps li { display: flex; align-items: center; gap: .75rem; padding: .6rem .25rem; border-bottom: 1px dashed var(--border); }
.steps li:last-child { border-bottom: 0; }
.steps .done { color: var(--ok); }
.steps .todo { color: var(--faint); }
.steps .done-text { color: var(--muted); }
.progress { height: .4rem; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--brand); border-radius: inherit; transition: width .4s; }

/* ---------- toasts ---------- */
.toasts { position: fixed; top: 1rem; inset-inline-end: 1rem; z-index: 60; display: flex; flex-direction: column; gap: .5rem; width: min(24rem, calc(100vw - 2rem)); }
.toast { display: flex; gap: .65rem; align-items: flex-start; padding: .75rem .9rem; border-radius: .75rem; background: var(--surface);
         border: 1px solid var(--border); border-inline-start-width: 4px; box-shadow: var(--shadow-lg); font-size: .9rem; color: var(--text); }
.toast-ok { border-inline-start-color: var(--ok); } .toast-ok .toast-icon { color: var(--ok); }
.toast-bad { border-inline-start-color: var(--bad); } .toast-bad .toast-icon { color: var(--bad); }
.toast-warn { border-inline-start-color: var(--warn); } .toast-warn .toast-icon { color: var(--warn); }
.toast .toast-close { margin-inline-start: auto; color: var(--faint); border-radius: .4rem; }
.toast .toast-close:hover { color: var(--text); }

/* ---------- confirm dialog ---------- */
dialog.confirm { border: 1px solid var(--border); border-radius: 1rem; padding: 0; width: min(26rem, calc(100vw - 2rem));
                 background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
dialog.confirm::backdrop { background: rgb(15 23 42 / .45); backdrop-filter: blur(2px); }
dialog.confirm .confirm-icon { width: 2.6rem; height: 2.6rem; border-radius: 999px; display: grid; place-items: center; background: var(--bad-soft); color: var(--bad); flex: none; }

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

/* checkbox wrapped in an icon button (formset DELETE): hide the box, keep it focusable */
.icon-btn { position: relative; }
.icon-btn input[type=checkbox] { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; }
.icon-btn:has(input:focus-visible) { outline: 2px solid var(--brand); outline-offset: 2px; }
.icon-btn:has(input:checked) { background: var(--bad); color: #fff; }

/* wide tables: keep the status/actions column pinned to the inline end while scrolling sideways */
table.grid .sticky-end { position: sticky; inset-inline-end: 0; z-index: 1; background: var(--surface); box-shadow: inset 1px 0 0 var(--border); }
[dir=ltr] table.grid .sticky-end { box-shadow: inset 1px 0 0 var(--border); }
[dir=rtl] table.grid .sticky-end { box-shadow: inset -1px 0 0 var(--border); }
table.grid th.sticky-end { z-index: 3; background: var(--surface-2); }
table.grid tfoot td.sticky-end { z-index: 2; background: var(--surface-2); }
table.grid tbody tr:nth-child(even) td.sticky-end { background: var(--zebra); }
table.grid tbody tr:hover td.sticky-end { background: var(--hover); }

/* ---------- financial statements (report layout) ---------- */
.stm { max-width: 56rem; margin-inline: auto; padding: 2rem 2.25rem; }
.stm-head { text-align: center; margin-bottom: 1.5rem; line-height: 1.7; }
.stm-co { font-size: 1.25rem; font-weight: 800; }
.stm-title { font-size: 1.05rem; font-weight: 700; color: var(--brand-ink); }
.stm-period, .stm-cur { color: var(--muted); font-size: .875rem; }
.stm-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.stm-table th { font-weight: 700; padding: .5rem .6rem; border-bottom: 2px solid var(--text); white-space: nowrap; }
.stm-table th.stm-label { text-align: start; }
.stm-table td { padding: .42rem .6rem; }
.stm-table .num { font-variant-numeric: tabular-nums; width: 9.5rem; }
.stm-note { width: 4.5rem; text-align: center !important; color: var(--brand); font-weight: 600; }
.stm-h td { font-weight: 700; padding-top: 1rem; color: var(--text); }
.stm-h-top td { font-size: 1rem; text-decoration: underline; text-underline-offset: 6px; text-decoration-color: var(--border-strong); }
.stm-line td.stm-label { padding-inline-start: 1.25rem; }
.stm-line:hover td { background: var(--hover); }
.stm-total td { font-weight: 700; }
.stm-total td.num { border-top: 1px solid var(--text); }
.stm-strong td.num { border-bottom: 3px double var(--text); }
.stm-foot { margin-top: 2rem; padding-top: .75rem; border-top: 1px solid var(--border); color: var(--muted); font-size: .8rem; text-align: center; }

@media print {
  aside, .no-print, .toasts, dialog { display: none !important; }
  body.app { background: #fff; }
  main { padding: 0 !important; }
  .card.stm { border: 0; box-shadow: none; max-width: none; padding: 0; }
}
.stm-eq td.stm-label { min-width: 15rem; }

/* notes document */
.ntx { margin-bottom: 1.25rem; line-height: 2; }
.ntx p, .npara { margin: .15rem 0; line-height: 2; text-align: justify; }
.nth { font-weight: 700; margin-top: .9rem; color: var(--text); }
.nblk { margin-top: 1.75rem; break-inside: avoid; }
.nblk h2.nth { font-size: 1rem; color: var(--brand-ink); }
.nsub { font-weight: 700; margin: .5rem 0; }
.ntab { margin-top: .5rem; font-size: .88rem; }
.ntab .num { width: auto; min-width: 7.5rem; }
.report-doc .rep-sign { text-align: end; margin: 0; }

/* ---------- sidebar menu scrolling ---------- */
.nav-scroll {
  overscroll-behavior: contain;
  scrollbar-width: thin;                                   /* Firefox */
  scrollbar-color: rgb(255 255 255 / .16) transparent;
  scrollbar-gutter: stable;
  /* soften the cut-off at the top and bottom edges */
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 14px, #000 calc(100% - 18px), transparent 100%);
          mask-image: linear-gradient(to bottom, transparent 0, #000 14px, #000 calc(100% - 18px), transparent 100%);
}
.nav-scroll:hover { scrollbar-color: rgb(255 255 255 / .32) transparent; }
.nav-scroll::-webkit-scrollbar { width: 6px; }
.nav-scroll::-webkit-scrollbar-track { background: transparent; }
.nav-scroll::-webkit-scrollbar-button { display: none; height: 0; }
.nav-scroll::-webkit-scrollbar-thumb { background: rgb(255 255 255 / .16); border-radius: 999px; }
.nav-scroll:hover::-webkit-scrollbar-thumb { background: rgb(255 255 255 / .32); }

/* only the content area scrolls (the page itself does not), so no browser scrollbar sits beside the menu */
.app-main {
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}
.app-main::-webkit-scrollbar { width: 10px; }
.app-main::-webkit-scrollbar-track { background: transparent; }
.app-main::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 3px solid var(--bg); }
.app-main::-webkit-scrollbar-thumb:hover { background: var(--faint); }
@media print {
  .app-shell { display: block; height: auto; overflow: visible; }
  .app-main { overflow: visible; }
}

/* native file pickers styled like the app's soft buttons (their wording comes from the browser's language) */
input[type=file] { font-size: .85rem; color: var(--muted); max-width: 100%; }
input[type=file]::file-selector-button {
  margin-inline-end: .6rem; border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text-2);
  border-radius: .5rem; padding: .35rem .8rem; font: inherit; cursor: pointer; transition: background .15s;
}
input[type=file]::file-selector-button:hover { background: var(--surface-3); }
