/* Law Office System. Logical properties throughout so Arabic (RTL) and English (LTR) share one stylesheet. */
@font-face { font-family: "Plex Arabic"; font-weight: 400; font-display: swap; src: url("/fonts/ibm-plex-sans-arabic-arabic-400-normal.woff2") format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0898-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: "Plex Arabic"; font-weight: 500; font-display: swap; src: url("/fonts/ibm-plex-sans-arabic-arabic-500-normal.woff2") format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0898-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: "Plex Arabic"; font-weight: 600; font-display: swap; src: url("/fonts/ibm-plex-sans-arabic-arabic-600-normal.woff2") format("woff2"); unicode-range: U+0600-06FF, U+0750-077F, U+0870-088E, U+0890-0891, U+0898-08E1, U+08E3-08FF, U+200C-200E, U+2010-2011, U+204F, U+2E41, U+FB50-FDFF, U+FE70-FE74, U+FE76-FEFC; }
@font-face { font-family: "Plex Arabic"; font-weight: 400; font-display: swap; src: url("/fonts/ibm-plex-sans-arabic-latin-400-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Plex Arabic"; font-weight: 500; font-display: swap; src: url("/fonts/ibm-plex-sans-arabic-latin-500-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Plex Arabic"; font-weight: 600; font-display: swap; src: url("/fonts/ibm-plex-sans-arabic-latin-600-normal.woff2") format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

/* ---------- tokens ----------
   Surfaces, borders and text are neutral greys, so the only colour in the frame is the office's
   own (set per office; the teal below is the default). Spacing sits on a 4px grid. Three text
   roles: --ink, --ink-2, --muted. --brand fills things; --brand-ink is the same colour made safe
   to use as text. */
:root {
  color-scheme: light;
  --page: #f6f6f7; --surface: #ffffff; --surface-2: #f3f3f5; --surface-3: #e9e9ec;
  --line: #e4e4e7; --line-strong: #8c8c93;
  --ink: #18181b; --ink-2: #4b4b52; --muted: #6e6e76;
  --brand: #17607d; --brand-strong: #0f4760; --brand-soft: #e7f0f3; --brand-ink: #17607d; --on-brand: #ffffff;
  --good: #0a7d2c; --good-soft: #e3f4e7; --warn: #8a5a00; --warn-soft: #fdf1d6; --bad: #b3261e; --bad-soft: #fbe6e4; --info-soft: var(--brand-soft);
  --series-1: #2a78d6; --series-2: #eb6834; --series-quiet: #c9c9cf; --grid: #ececef; --axis: #c9c9cf;
  --shadow-sm: 0 1px 2px rgb(0 0 0 / 5%);
  --shadow: 0 1px 2px rgb(0 0 0 / 5%), 0 8px 24px rgb(0 0 0 / 8%);
  --radius: 12px; --radius-sm: 8px; --side: 256px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  font-family: "Plex Arabic", "Segoe UI", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #131314; --surface: #19191b; --surface-2: #212124; --surface-3: #2b2b2f;
    --line: #2c2c30; --line-strong: #74747c;
    --ink: #ededee; --ink-2: #a8a8ae; --muted: #8d8d94;
    --brand: #6cb6d1; --brand-strong: #8fcbe0; --brand-soft: #1b2e36; --brand-ink: #7fc1da; --on-brand: #08222c;
    --good: #5fcf7a; --good-soft: #143222; --warn: #f0c060; --warn-soft: #3a2e10; --bad: #ff8a80; --bad-soft: #3d1c1a;
    --series-1: #3987e5; --series-2: #d95926; --series-quiet: #4a4a50; --grid: #26262a; --axis: #3d3d43;
    --shadow-sm: none;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 12px 32px rgb(0 0 0 / 35%);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #131314; --surface: #19191b; --surface-2: #212124; --surface-3: #2b2b2f;
  --line: #2c2c30; --line-strong: #74747c;
  --ink: #ededee; --ink-2: #a8a8ae; --muted: #8d8d94;
  --brand: #6cb6d1; --brand-strong: #8fcbe0; --brand-soft: #1b2e36; --brand-ink: #7fc1da; --on-brand: #08222c;
  --good: #5fcf7a; --good-soft: #143222; --warn: #f0c060; --warn-soft: #3a2e10; --bad: #ff8a80; --bad-soft: #3d1c1a;
  --series-1: #3987e5; --series-2: #d95926; --series-quiet: #4a4a50; --grid: #26262a; --axis: #3d3d43;
  --shadow-sm: none;
  --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 12px 32px rgb(0 0 0 / 35%);
}

*, *::before, *::after { box-sizing: border-box; }
html { font-size: 100%; }
body { margin: 0; background: var(--page); color: var(--ink); line-height: 1.55; font-size: 0.9375rem; -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: 1.5rem; font-weight: 600; line-height: 1.25; text-wrap: balance; }
h2 { font-size: 1rem; font-weight: 500; line-height: 1.4; }
h3 { font-size: 0.9375rem; font-weight: 500; }
a { color: var(--brand-ink); text-underline-offset: 3px; }
button, input, select, textarea { font: inherit; font-size: max(1rem, 1em); color: inherit; }
:focus-visible { outline: 2px solid var(--brand-ink); outline-offset: 2px; border-radius: 4px; }
.visually-hidden { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; inset-inline-start: 8px; inset-block-start: -60px; background: var(--brand); color: var(--on-brand); padding: 8px 16px; border-radius: 8px; z-index: 50; }
.skip:focus { inset-block-start: 8px; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
/* Numbers and codes always read left-to-right, but stay on the reading side of the page in Arabic. */
[dir="rtl"] :is(td, th, div, dd, p, code).num { text-align: right; }
[dir="rtl"] td.right.num, [dir="rtl"] td.right .num { text-align: left; }
.muted { color: var(--muted); }
.small { font-size: 0.8125rem; }
[hidden] { display: none !important; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: var(--side) minmax(0, 1fr); min-block-size: 100dvh; }
.side { background: var(--surface); border-inline-end: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; inset-block-start: 0; block-size: 100dvh; }
.brand { display: flex; align-items: center; gap: 12px; padding: 16px; block-size: 72px; border-block-end: 1px solid var(--line); }
.brand img { inline-size: 40px; block-size: 40px; border-radius: 8px; object-fit: contain; background: #fff; flex: none; }
.brand > div { min-inline-size: 0; }
.brand b { display: block; font-size: 0.875rem; font-weight: 500; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand span { font-size: 0.75rem; color: var(--muted); }
/* Navigation is the densest part: one row height, one gap, icons in one column. */
.nav { flex: 1; overflow-y: auto; padding: 8px 12px 16px; overscroll-behavior: contain; display: grid; gap: 2px; align-content: start; }
.nav h3 { font-size: 0.75rem; color: var(--muted); font-weight: 400; padding: 20px 12px 6px; }
.nav a { position: relative; display: flex; align-items: center; gap: 12px; padding: 0 12px; border-radius: 8px; color: var(--ink-2); text-decoration: none; font-size: 0.875rem; min-block-size: 36px; transition: background-color 140ms var(--ease), color 140ms var(--ease); }
.nav a .icon { color: var(--muted); }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--surface-2); color: var(--ink); font-weight: 500; }
.nav a[aria-current="page"] .icon { color: var(--brand-ink); }
.nav a[aria-current="page"]::before { content: ""; position: absolute; inset-block: 8px; inset-inline-start: 0; inline-size: 3px; border-radius: 2px; background: var(--brand); }
.nav a .count { margin-inline-start: auto; background: var(--surface-3); color: var(--ink-2); border-radius: 6px; font-size: 0.75rem; font-variant-numeric: tabular-nums; padding: 0 6px; min-inline-size: 20px; block-size: 20px; line-height: 20px; text-align: center; }
.icon { inline-size: 18px; block-size: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.side-foot { border-block-start: 1px solid var(--line); padding: 12px; display: grid; gap: 12px; }
.who { display: flex; align-items: center; gap: 12px; min-inline-size: 0; padding-inline: 4px; }
.avatar { inline-size: 32px; block-size: 32px; border-radius: 50%; background: var(--surface-3); color: var(--ink-2); display: grid; place-items: center; font-weight: 500; font-size: 0.875rem; flex: none; }
.who div { min-inline-size: 0; }
.who b, .who span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who b { font-size: 0.8125rem; font-weight: 500; }
.who span { font-size: 0.75rem; color: var(--muted); }
.side-actions { display: flex; gap: 4px; }
.side-actions .btn { flex: 1; }

.main { min-inline-size: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 0 32px; min-block-size: 64px; background: var(--surface); border-block-end: 1px solid var(--line); position: sticky; inset-block-start: 0; z-index: 5; }
.topbar .menu-btn { display: none; }
/* A Super Admin inside an office: a bar above the top bar says so on every screen, and stays in view. */
.top-stack { position: sticky; inset-block-start: 0; z-index: 5; }
.top-stack .topbar { position: static; }
.inside-bar { display: flex; align-items: center; gap: 12px; padding: 8px 32px; background: var(--warn-soft); color: var(--ink); font-size: 0.8125rem; border-block-end: 1px solid var(--line); }
.inside-bar > .icon { color: var(--warn); }
.inside-bar > span { flex: 1; min-inline-size: 0; }
.inside-bar > .btn { flex: none; }
.global-search { position: relative; flex: 1; max-inline-size: 520px; }
.global-search input[type="search"] { inline-size: 100%; padding-inline-start: 40px; background: var(--surface-2); border-color: transparent; }
.global-search input[type="search"]:focus { background: var(--surface); border-color: var(--line-strong); }
.global-search .icon { position: absolute; inset-inline-start: 12px; inset-block-start: 50%; translate: 0 -50%; color: var(--muted); pointer-events: none; }
.search-results { position: absolute; inset-inline: 0; inset-block-start: calc(100% + 8px); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); max-block-size: 60vh; overflow: auto; z-index: 20; padding: 4px; }
.search-results a { display: block; padding: 8px 12px; border-radius: 8px; text-decoration: none; color: var(--ink); }
.search-results a:hover, .search-results a:focus-visible { background: var(--surface-2); }
.search-results small { color: var(--muted); display: block; }
.content:focus, .content:focus-visible { outline: none; }
.content { padding: 28px 32px 64px; max-inline-size: 1480px; inline-size: 100%; margin-inline: auto; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-block-end: 20px; }
.page-head > div:first-child { flex: 1 1 340px; min-inline-size: min(100%, 300px); }
.page-head p { color: var(--muted); margin-block-start: 4px; font-size: 0.875rem; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-block-size: 36px; padding: 4px 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); cursor: pointer; text-decoration: none; font-size: 0.875rem; font-weight: 500; white-space: nowrap; transition: background-color 140ms var(--ease), border-color 140ms var(--ease), color 140ms var(--ease); }
.btn:hover { background: var(--surface-2); border-color: var(--line-strong); }
.btn:active { scale: 0.98; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn.danger { color: var(--bad); }
.btn.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
:root[data-theme="dark"] .btn.danger.solid { color: #2b0b09; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.danger.solid { color: #2b0b09; } }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); border-color: transparent; }
.btn.sm { min-block-size: 28px; padding: 0 12px; font-size: 0.8125rem; border-radius: 6px; }
.btn.icon-only { padding: 4px; min-inline-size: 36px; }
.btn.sm.icon-only { min-inline-size: 28px; padding: 0; }
.btn[disabled] { opacity: 0.55; cursor: progress; }
.btn.ai { border-color: var(--line); color: var(--ink); background: var(--surface); }
.btn.ai .icon { color: var(--brand-ink); }

input:not([type="checkbox"], [type="radio"], [type="file"], [type="color"]), select, textarea { inline-size: 100%; min-block-size: 40px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); transition: border-color 140ms var(--ease); }
textarea { min-block-size: 96px; resize: vertical; line-height: 1.6; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--brand); inline-size: 18px; block-size: 18px; margin: 0; flex: none; }
input:user-invalid, select:user-invalid, textarea:user-invalid, [aria-invalid="true"] { border-color: var(--bad); outline-color: var(--bad); }
label { font-weight: 500; font-size: 0.8125rem; }
.field { display: grid; gap: 4px; align-content: start; }
.field .hint { font-size: 0.8125rem; color: var(--muted); font-weight: 400; }
.field .req { color: var(--bad); }
.field > .label { font-weight: 500; font-size: 0.8125rem; }
.check { display: flex; align-items: center; gap: 8px; min-block-size: 40px; }
.check label { font-weight: 400; font-size: 0.9375rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .wide { grid-column: 1 / -1; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px 20px; margin: 0; min-inline-size: 0; background: var(--surface); }
legend { font-weight: 500; padding-inline: 8px; font-size: 0.9375rem; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-block-end: 12px; }
.toolbar search { flex: 1 1 240px; max-inline-size: 360px; }
.toolbar select { inline-size: auto; min-inline-size: 152px; max-inline-size: 220px; }

/* ---------- cards, tables ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card.pad { padding: 20px; }
.card-head { display: flex; align-items: center; gap: 12px; padding: 12px 20px; min-block-size: 56px; border-block-end: 1px solid var(--line); flex-wrap: wrap; }
.card-head h2 { flex: 1; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.stack { display: grid; gap: 16px; }

.table-wrap { overflow: auto; container-type: inline-size; border-radius: var(--radius); }
table { inline-size: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.875rem; }
th, td { padding: 12px 16px; text-align: start; border-block-end: 1px solid var(--line); vertical-align: middle; }
thead th { position: sticky; inset-block-start: 0; z-index: 1; background: var(--surface); font-weight: 500; font-size: 0.8125rem; color: var(--muted); white-space: nowrap; padding-block: 8px; }
thead th button { all: unset; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
thead th button:focus-visible { outline: 2px solid var(--brand-ink); outline-offset: 2px; }
tbody tr:last-child td { border-block-end: 0; }
tbody tr.clickable { cursor: pointer; transition: background-color 120ms var(--ease); }
tbody tr.clickable:hover { background: var(--surface-2); }
td.right, th.right { text-align: end; }
td.tight { inline-size: 1%; white-space: nowrap; }
td .row-actions { display: flex; gap: 4px; justify-content: flex-end; }
tfoot td { font-weight: 500; background: var(--surface-2); border-block-end: 0; }
.cell-clip { max-inline-size: 30ch; min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
@container (width < 620px) {
  table.stackable, table.stackable tbody, table.stackable tr, table.stackable td { display: block; }
  table.stackable thead { display: none; }
  table.stackable tr { padding: 8px 4px; border-block-end: 1px solid var(--line); }
  table.stackable td { border: 0; padding: 4px 12px; text-align: start; inline-size: auto; }
  table.stackable td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: 0.8125rem; }
  table.stackable td .row-actions { justify-content: flex-start; padding-block-start: 4px; }
  .cell-clip { max-inline-size: none; white-space: normal; display: inline; }
}
.pager { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-block-start: 1px solid var(--line); font-size: 0.8125rem; color: var(--muted); }
.pager .sp { flex: 1; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 0 8px; min-block-size: 22px; border-radius: 6px; font-size: 0.75rem; font-weight: 500; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.info { background: var(--brand-soft); color: var(--brand-ink); border-color: transparent; }

.empty { padding: 40px 20px; text-align: center; color: var(--muted); display: grid; gap: 12px; justify-items: center; font-size: 0.875rem; }
.empty .icon { inline-size: 28px; block-size: 28px; opacity: 0.6; }
.notice { display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink); font-size: 0.875rem; }
.notice.warn { background: var(--warn-soft); border-color: transparent; }
.notice.bad { background: var(--bad-soft); border-color: transparent; }
.notice .icon { margin-block-start: 2px; color: var(--muted); }
.error-text { color: var(--bad); font-size: 0.875rem; min-block-size: 1.3em; }
.spinner { inline-size: 18px; block-size: 18px; border-radius: 50%; border: 2px solid var(--line); border-block-start-color: var(--brand-ink); animation: spin 0.8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { rotate: 360deg; } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } .btn, .nav a, tbody tr.clickable, input, select, textarea { transition: none; } .btn:active { scale: 1; } }
.loading { display: flex; gap: 12px; align-items: center; justify-content: center; padding: 40px; color: var(--muted); }
.ai-wait .loading { padding-block-end: 12px; font-variant-numeric: tabular-nums; }
.ai-wait > p { margin: 0; padding: 0 24px 32px; text-align: center; }
.msg > p.small { margin: 8px 0 0; }

/* ---------- dashboard and statistics ---------- */
/* A figure card is a label, one number and what it compares to. Nothing decorative. */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 16px 20px; text-decoration: none; color: inherit; display: grid; gap: 4px; align-content: start; min-block-size: 104px; transition: border-color 140ms var(--ease); }
a.tile:hover { border-color: var(--line-strong); }
.tile .label { font-size: 0.8125rem; color: var(--ink-2); }
.tile .value { font-size: 1.75rem; font-weight: 600; line-height: 1.15; }
.tile .value small { font-size: 0.8125rem; font-weight: 400; color: var(--muted); }
.tile .delta { font-size: 0.75rem; color: var(--muted); }
.tile .delta.up { color: var(--good); } .tile .delta.down { color: var(--bad); }
.dash-main { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.dash-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 16px; align-items: start; }
@media (max-width: 1100px) { .dash-main { grid-template-columns: minmax(0, 1fr); } }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 12px; align-items: flex-start; padding: 12px 20px; border-block-end: 1px solid var(--line); }
.list li:last-child { border-block-end: 0; }
.list a { color: inherit; text-decoration: none; flex: 1; min-inline-size: 0; }
.list a:hover b { text-decoration: underline; }
.list b { font-weight: 500; display: block; font-size: 0.875rem; }
.list small { color: var(--muted); font-size: 0.8125rem; }
.dot { inline-size: 8px; block-size: 8px; border-radius: 50%; margin-block-start: 8px; flex: none; background: var(--muted); }
.dot.urgent { background: var(--bad); } .dot.soon { background: #d99a00; } .dot.info { background: var(--brand); }
.date-chip { flex: none; inline-size: 48px; text-align: center; border: 1px solid var(--line); border-radius: 8px; padding: 4px 0; line-height: 1.2; background: var(--surface-2); }
.date-chip b { font-size: 1rem; font-weight: 600; } .date-chip small { font-size: 0.6875rem; }
/* The file number, set like the tab on a court file: the one detail this system keeps everywhere. */
.docket { display: inline-block; font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; font-size: 0.75rem; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 6px; line-height: 20px; white-space: nowrap; }

.chart { padding: 8px 20px 16px; }
.chart svg { inline-size: 100%; block-size: auto; display: block; overflow: visible; }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; font-variant-numeric: tabular-nums; }
.chart .val { fill: var(--ink-2); }
.chart .bar, .chart .hit { cursor: default; }
.chart .bar:hover, .chart .bar:focus-visible { opacity: 0.8; outline: none; }
.legend { display: flex; gap: 16px; font-size: 0.8125rem; color: var(--ink-2); padding: 12px 20px 0; flex-wrap: wrap; }
.legend i { inline-size: 10px; block-size: 10px; border-radius: 3px; display: inline-block; margin-inline-end: 6px; }
.tip { position: fixed; z-index: 60; background: var(--ink); color: var(--surface); padding: 4px 8px; border-radius: 6px; font-size: 0.8125rem; pointer-events: none; max-inline-size: min(420px, calc(100vw - 12px)); font-variant-numeric: tabular-nums; }
/* Ranked list with thin bars: for shares and comparisons that do not need a chart of their own. */
.hbars { display: grid; gap: 12px; padding: 16px 20px 20px; }
.hbar { display: grid; grid-template-columns: minmax(96px, 30%) 1fr auto; gap: 12px; align-items: center; font-size: 0.875rem; }
.hbar > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .track { block-size: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hbar .fill { block-size: 100%; background: var(--series-quiet); border-radius: 4px; }
.hbar:first-child .fill { background: var(--brand); }
.hbars.flat .hbar:first-child .fill { background: var(--series-quiet); }
.period { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.period select, .period input { inline-size: auto; min-block-size: 36px; padding-block: 4px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; padding: 2px; background: var(--surface); gap: 2px; }
.seg button { all: unset; cursor: pointer; padding: 0 12px; min-block-size: 30px; display: inline-flex; align-items: center; border-radius: 6px; font-size: 0.8125rem; color: var(--ink-2); white-space: nowrap; }
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--surface-3); color: var(--ink); font-weight: 500; }
.seg button:focus-visible { outline: 2px solid var(--brand-ink); outline-offset: 1px; }
.section-title { font-size: 0.8125rem; color: var(--muted); font-weight: 400; margin-block: 16px 0; }

/* ---------- details ---------- */
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(208px, 1fr)); gap: 12px 20px; }
.kv div { min-inline-size: 0; }
.kv dt { font-size: 0.75rem; color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.kv .wide { grid-column: 1 / -1; }
dl { margin: 0; }
.tabs { display: flex; gap: 4px; border-block-end: 1px solid var(--line); overflow-x: auto; margin-block-end: 16px; }
.tabs button { all: unset; padding: 8px 12px; cursor: pointer; color: var(--ink-2); border-block-end: 2px solid transparent; white-space: nowrap; font-size: 0.875rem; }
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] { color: var(--ink); border-color: var(--brand); font-weight: 500; }
.tabs button:focus-visible { outline: 2px solid var(--brand-ink); outline-offset: -2px; }
.prose { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.85; }
.rich { line-height: 1.8; overflow-wrap: anywhere; }
.rich h4 { font-size: 1rem; font-weight: 500; margin-block: 12px 4px; }
.rich p { margin-block: 8px; }
.rich ul, .rich ol { margin-block: 8px; padding-inline-start: 24px; }
.steps { margin: 0; padding-inline-start: 24px; display: grid; gap: 4px; font-size: 0.875rem; }
.ai-out { border: 1px solid var(--line); border-inline-start: 3px solid var(--brand); background: var(--surface); border-radius: var(--radius-sm); padding: 16px 20px; }
.ai-out .meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-size: 0.75rem; color: var(--muted); margin-block-end: 8px; }
.basis { display: flex; gap: 8px; align-items: flex-start; font-size: 0.8125rem; color: var(--muted); margin-block-start: 12px; }
.basis .icon { inline-size: 16px; block-size: 16px; margin-block-start: 2px; }
.basis.none { color: var(--warn); }
.basis.review > div { min-inline-size: 0; }
.basis.review ul { margin: 4px 0 0; padding-inline-start: 18px; }
.basis.review details { margin-block-start: 6px; }
.basis.review summary { cursor: pointer; }
.sources { margin-block-start: 12px; padding-block-start: 12px; border-block-start: 1px solid var(--line); font-size: 0.8125rem; }
.sources ol { margin: 4px 0 0; padding-inline-start: 24px; }

/* ---------- smart inbox ---------- */
.drop { border: 1px dashed var(--line-strong); border-radius: var(--radius); padding: 28px 20px; text-align: center; background: var(--surface); display: grid; gap: 8px; justify-items: center; }
.drop.over { border-color: var(--brand); background: var(--brand-soft); }
.sugg { border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: grid; gap: 8px; background: var(--surface-2); }
.sugg-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sugg-head b { flex: 1; font-weight: 500; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }

/* ---------- assistant ---------- */
.chat { display: grid; grid-template-rows: 1fr auto; block-size: min(72dvh, 760px); }
.chat-log { overflow-y: auto; padding: 20px; display: grid; gap: 12px; align-content: start; overscroll-behavior: contain; }
.msg { max-inline-size: min(100%, 760px); padding: 12px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); }
.msg.user { justify-self: end; background: var(--brand-soft); border-color: transparent; }
.chat-input { display: flex; gap: 8px; padding: 12px; border-block-start: 1px solid var(--line); align-items: flex-end; }
.chat-input textarea { min-block-size: 44px; max-block-size: 160px; }

/* ---------- permission grid, option cards ---------- */
.perm-grid th:first-child, .perm-grid td:first-child { position: sticky; inset-inline-start: 0; background: var(--surface); }
.perm-grid td { text-align: center; }
.perm-grid td:first-child { text-align: start; font-weight: 500; }
.perm-grid tr.group td { background: var(--surface-2); font-size: 0.75rem; color: var(--muted); text-align: start; font-weight: 500; }
.option-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.option-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; cursor: pointer; background: var(--surface); transition: border-color 140ms var(--ease); }
.option-card b { font-weight: 500; }
.option-card:has(input:checked) { border-color: var(--brand); box-shadow: inset 0 0 0 1px var(--brand); }
.option-card:has(input:disabled) { opacity: 0.6; cursor: not-allowed; }
.option-card span { grid-column: 2; font-size: 0.8125rem; color: var(--ink-2); }

/* ---------- dialogs, toasts ---------- */
dialog { border: 1px solid var(--line); border-radius: 16px; padding: 0; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); inline-size: min(640px, calc(100vw - 24px)); max-block-size: calc(100dvh - 32px); }
dialog.wide { inline-size: min(980px, calc(100vw - 24px)); }
dialog[open] { display: flex; flex-direction: column; }
dialog:modal { overscroll-behavior: contain; }
dialog::backdrop { background: rgb(10 10 12 / 55%); overflow: hidden; overscroll-behavior: contain; }
.dlg-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-block-end: 1px solid var(--line); }
.dlg-head h2 { flex: 1; }
.dlg-body { padding: 20px; overflow-y: auto; display: grid; gap: 16px; grid-auto-rows: max-content; align-content: start; }
.dlg-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 20px; border-block-start: 1px solid var(--line); flex-wrap: wrap; align-items: center; }
.dlg-foot .error-text { flex: 1; min-inline-size: 180px; }
dialog form { display: contents; }

/* The whole region is one popover pinned to the corner of the window, so messages stay in view
   wherever the page is scrolled and sit above any open dialog. */
#toasts { position: fixed; inset: auto; inset-block-end: 16px; inset-inline-end: 16px; margin: 0; padding: 0; border: 0; background: transparent; color: inherit; overflow: visible; display: grid; gap: 8px; z-index: 100; inline-size: min(380px, calc(100vw - 32px)); block-size: auto; pointer-events: none; }
.toast { pointer-events: auto; display: flex; gap: 12px; align-items: flex-start; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); box-shadow: var(--shadow); font-size: 0.875rem; }
.toast > .icon { color: var(--good); margin-block-start: 2px; }
.toast.bad { border-color: var(--bad); }
.toast.bad > .icon { color: var(--bad); }
.toast p { flex: 1; overflow-wrap: anywhere; }

/* ---------- sign-in ---------- */
.auth { min-block-size: 100dvh; display: grid; place-items: center; padding: 20px; }
.auth-card { inline-size: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 32px 32px 24px; box-shadow: var(--shadow); display: grid; gap: 16px; }
.auth-card img { inline-size: 96px; block-size: 96px; object-fit: contain; border-radius: 16px; justify-self: center; background: #fff; }
.auth-card h1 { text-align: center; font-size: 1.25rem; }
.auth-card .sub { text-align: center; color: var(--muted); font-size: 0.875rem; margin-block-start: -12px; }
.auth-card .lead { text-align: center; color: var(--ink-2); font-size: 0.9375rem; text-wrap: balance; }
.auth-foot { display: flex; justify-content: center; gap: 8px; }

/* ---------- invoice sheet / print ---------- */
.sheet { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 32px; max-inline-size: 860px; }
.sheet-head { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; border-block-end: 2px solid var(--brand); padding-block-end: 16px; margin-block-end: 16px; }
.sheet-head img { inline-size: 84px; block-size: 84px; object-fit: contain; }
.totals { margin-inline-start: auto; inline-size: min(320px, 100%); display: grid; gap: 4px; margin-block-start: 12px; }
.totals div { display: flex; justify-content: space-between; gap: 16px; }
.totals .grand { font-weight: 600; font-size: 1.125rem; border-block-start: 1px solid var(--line); padding-block-start: 8px; }
.lines input { min-block-size: 36px; }
.lines td { padding: 4px 6px; border: 0; }

/* ---------- logos, sign-in links, office colour ---------- */
.mark { display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-ink); border-radius: 16px; flex: none; }
.auth-card .mark { inline-size: 80px; block-size: 80px; justify-self: center; }
.auth-card .mark .icon { inline-size: 40px; block-size: 40px; }
.brand .mark { inline-size: 40px; block-size: 40px; border-radius: 8px; }
.brand .mark .icon { inline-size: 22px; block-size: 22px; }
.link-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.link-row input { flex: 1 1 260px; inline-size: auto; min-inline-size: 0; }
.logo-row { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.logo-preview img, .logo-preview .mark { inline-size: 84px; block-size: 84px; border-radius: 12px; }
.logo-preview img { object-fit: contain; background: #fff; border: 1px solid var(--line); display: block; }
.logo-preview .mark .icon { inline-size: 38px; block-size: 38px; }
.logo-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.office-cell { display: flex; gap: 12px; align-items: center; min-inline-size: 200px; }
.office-cell img, .office-cell .mark { inline-size: 36px; block-size: 36px; border-radius: 8px; }
.office-cell img { object-fit: contain; background: #fff; border: 1px solid var(--line); flex: none; }
.office-cell .mark .icon { inline-size: 20px; block-size: 20px; }
.row-buttons { display: flex; gap: 4px; justify-content: flex-end; align-items: center; }
.admin-line { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.admin-line > span { overflow-wrap: break-word; min-inline-size: 0; }
.admin-line > .row-buttons { flex: none; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.swatch { all: unset; cursor: pointer; inline-size: 32px; block-size: 32px; border-radius: 8px; background: var(--c); box-shadow: inset 0 0 0 1px rgb(0 0 0 / 12%); display: grid; place-items: center; color: #fff; }
.swatch .icon { inline-size: 16px; block-size: 16px; opacity: 0; stroke-width: 2.5; }
.swatch[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--ink); }
.swatch[aria-pressed="true"] .icon { opacity: 1; }
.swatch.pale { color: #18181b; }
.swatch:focus-visible { outline: 2px solid var(--brand-ink); outline-offset: 3px; }
input[type="color"] { inline-size: 40px; block-size: 32px; padding: 0; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); cursor: pointer; }
.preview-strip { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--page); }

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: fixed; inset-block: 0; inset-inline-start: 0; inline-size: min(300px, 86vw); z-index: 40; translate: -105% 0; transition: translate 200ms var(--ease); box-shadow: var(--shadow); }
  [dir="rtl"] .side { translate: 105% 0; }
  .shell.nav-open .side { translate: 0 0; }
  .shell.nav-open::after { content: ""; position: fixed; inset: 0; background: rgb(10 10 12 / 45%); z-index: 30; }
  .topbar .menu-btn { display: inline-flex; }
  .topbar { padding-inline: 16px; min-block-size: 56px; }
  .inside-bar { padding-inline: 16px; flex-wrap: wrap; }
  .content { padding: 20px 16px 64px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .sheet { padding: 20px 16px; }
  .nav a { min-block-size: 44px; }
}
/* Phones: thumb-sized targets, two figures per row, dialogs as sheets from the bottom edge. */
@media (max-width: 640px) {
  h1 { font-size: 1.25rem; }
  .page-head { align-items: stretch; gap: 12px; margin-block-end: 16px; }
  .page-head > div:first-child { flex-basis: 100%; }
  .page-head .actions { inline-size: 100%; }
  .page-head .actions > .btn, .page-head .actions > a.btn { flex: 1 1 auto; }
  .btn { min-block-size: 44px; }
  .btn.sm { min-block-size: 36px; }
  .btn.icon-only { min-inline-size: 44px; }
  .btn.sm.icon-only { min-inline-size: 36px; }
  input:not([type="checkbox"], [type="radio"], [type="file"], [type="color"]), select, textarea { min-block-size: 44px; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile { padding: 12px 16px; min-block-size: 88px; }
  .tile .value { font-size: 1.375rem; }
  .card.pad, fieldset { padding: 16px; }
  .card-head { padding: 12px 16px; }
  .list li { padding: 12px 16px; }
  .chart { padding: 8px 12px 12px; }
  .legend, .hbars { padding-inline: 16px; }
  .hbar { grid-template-columns: minmax(80px, 38%) 1fr auto; gap: 8px; }
  .toolbar search { flex-basis: 100%; max-inline-size: none; }
  .toolbar select { flex: 1 1 140px; max-inline-size: none; }
  .period, .period .seg { inline-size: 100%; }
  .seg { overflow-x: auto; }
  .seg button { flex: 1 0 auto; justify-content: center; min-block-size: 40px; }
  .link-row input { flex-basis: 100%; }
  .link-row .btn { flex: 1 1 auto; }
  .row-buttons { justify-content: flex-start; flex-wrap: wrap; }
  .option-cards { grid-template-columns: minmax(0, 1fr); }
  .swatch { inline-size: 40px; block-size: 40px; }
  input[type="color"] { inline-size: 48px; block-size: 40px; }
  dialog, dialog.wide { inline-size: 100vw; max-inline-size: 100vw; max-block-size: 92dvh; margin: auto 0 0; border-radius: 16px 16px 0 0; border-inline: 0; border-block-end: 0; }
  .dlg-head, .dlg-body { padding-inline: 16px; }
  .dlg-foot { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
  .dlg-foot .btn { flex: 1 1 auto; }
  .dlg-foot .error-text { flex-basis: 100%; }
  #toasts { inset-inline: 12px; inline-size: auto; inset-block-end: calc(12px + env(safe-area-inset-bottom)); }
  .auth { padding: 16px; align-items: start; padding-block-start: 12dvh; }
  .auth-card { padding: 24px 20px 20px; }
  .side-foot { padding-block-end: calc(12px + env(safe-area-inset-bottom)); }
  .chat { block-size: calc(100dvh - 190px); }
  .totals { inline-size: 100%; }
  .sheet-head img { inline-size: 64px; block-size: 64px; }
}
@media (prefers-reduced-motion: reduce) { .side { transition: none; } }

@media print {
  .side, .topbar, .no-print, #toasts, .skip { display: none !important; }
  .shell { display: block; }
  body { background: #fff; color: #000; }
  .content { padding: 0; max-inline-size: none; }
  .sheet { border: 0; padding: 0; max-inline-size: none; }
  .card, .tile { border: 0; box-shadow: none; }
  .tile { border: 1px solid #ccc; }
  .dash-main, .dash-row { display: block; }
  .dash-main > *, .dash-row > * { break-inside: avoid; margin-block-end: 12px; }
}
