/* =========================================================================
   LawERP — design system
   RTL-first, Arabic-native. Built around a quiet navy/brass palette because a
   law firm's software should read like its letterhead, not like a dashboard
   demo. Everything is token-driven so a tenant can re-accent the whole app.
   ========================================================================= */

:root {
  /* Neutrals — cool grey with a trace of blue, so borders never look muddy */
  --n-0:   #ffffff;
  --n-25:  #fbfcfd;
  --n-50:  #f6f8fa;
  --n-100: #eef1f5;
  --n-150: #e4e9ef;
  --n-200: #d8dfe8;
  --n-300: #bcc6d4;
  --n-400: #94a1b4;
  --n-500: #6c7b91;
  --n-600: #526176;
  --n-700: #3d4a5c;
  --n-800: #2a3442;
  --n-900: #1a212c;
  --n-950: #11161e;

  /* Brand — deep counsel navy */
  --brand-50:  #eef2fb;
  --brand-100: #d8e0f5;
  --brand-200: #b3c2ea;
  --brand-400: #5d77be;
  --brand-500: #3f5aa6;
  --brand-600: #2f478a;
  --brand-700: #24386e;
  --brand-800: #1b2b55;
  --brand-900: #14203f;

  /* Accent — brass. Used sparingly: active nav, key figures, seals */
  --accent-100: #f7edd8;
  --accent-300: #e2c489;
  --accent-500: #c39a4b;
  --accent-600: #a87f34;
  --accent-700: #866328;

  --ok-50:  #e9f7ef;  --ok-500:  #16a34a;  --ok-700:  #14532d;
  --warn-50:#fdf3e3;  --warn-500:#d97706;  --warn-700:#7c3a06;
  --bad-50: #fdecec;  --bad-500: #dc2626;  --bad-700: #7f1d1d;
  --info-50:#e8f1fb;  --info-500:#2563eb;  --info-700:#1e3a8a;

  /* Semantic surface tokens — the only things components should reference */
  --bg:            var(--n-50);
  --surface:       var(--n-0);
  --surface-muted: var(--n-25);
  --surface-sunk:  var(--n-100);
  --border:        var(--n-150);
  --border-strong: var(--n-200);
  --text:          var(--n-900);
  --text-soft:     var(--n-600);
  --text-faint:    var(--n-400);
  --text-invert:   var(--n-0);
  --brand:         var(--brand-700);
  --brand-soft:    var(--brand-50);
  --accent:        var(--accent-600);
  --sidebar-bg:    var(--brand-900);
  --sidebar-text:  #c3cde4;
  --sidebar-hover: rgba(255, 255, 255, .07);

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --shadow-xs: 0 1px 2px rgba(17, 22, 30, .05);
  --shadow-sm: 0 1px 3px rgba(17, 22, 30, .07), 0 1px 2px rgba(17, 22, 30, .04);
  --shadow-md: 0 4px 12px rgba(17, 22, 30, .08), 0 1px 3px rgba(17, 22, 30, .05);
  --shadow-lg: 0 16px 40px rgba(17, 22, 30, .14), 0 2px 8px rgba(17, 22, 30, .06);

  --sidebar-w: 268px;
  --topbar-h: 62px;

  --font: "IBM Plex Sans Arabic", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-num: "IBM Plex Sans Arabic", ui-monospace, "SF Mono", monospace;

  --ease: cubic-bezier(.32, .72, 0, 1);
}

:root[data-theme="dark"] {
  --bg:            var(--n-950);
  --surface:       #182029;
  --surface-muted: #1d2630;
  --surface-sunk:  #131a22;
  --border:        #28323f;
  --border-strong: #35424f;
  --text:          #e8edf3;
  --text-soft:     #a3b0c0;
  --text-faint:    #6f7e91;
  --brand:         var(--brand-400);
  --brand-soft:    rgba(93, 119, 190, .14);
  --accent:        var(--accent-300);
  --sidebar-bg:    #0f151d;
  --sidebar-text:  #9aa8bd;
  --sidebar-hover: rgba(255, 255, 255, .05);

  --ok-50:  rgba(22,163,74,.14);
  --warn-50:rgba(217,119,6,.14);
  --bad-50: rgba(220,38,38,.14);
  --info-50:rgba(37,99,235,.14);

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, .45);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, .5);
  --shadow-lg: 0 18px 44px rgba(0, 0, 0, .6);
}

/* ---------------------------------------------------------------- reset */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

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

body {
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
img, svg { display: block; max-width: 100%; }
svg { flex: none; }
/* Safety net: an inline icon must never stretch to its container's width. */
.icon { width: 18px; height: 18px; }
table { border-collapse: collapse; width: 100%; }
h1, h2, h3, h4 { line-height: 1.35; font-weight: 600; }

::selection { background: var(--accent-300); color: var(--n-900); }

:focus-visible {
  outline: 2px solid var(--accent-500);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
.btn:focus-visible, .icon-btn:focus-visible, .chip:focus-visible {
  outline: 0;
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent-500);
}

/* Numbers stay Western and aligned, even inside Arabic sentences */
.num, td.num, .stat-value, .money {
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  direction: ltr;
  unicode-bidi: isolate;
  white-space: nowrap;
}

/* ------------------------------------------------------------- scrollbar */
* { scrollbar-width: thin; scrollbar-color: var(--n-300) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--n-300);
  border: 3px solid transparent;
  border-radius: 99px;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--n-400); background-clip: content-box; }
:root[data-theme="dark"] *::-webkit-scrollbar-thumb { background: #33404f; background-clip: content-box; }

/* ================================================================= layout */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: none;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  /* The column itself stretches with the page (so its navy never stops
     mid-page); the inner wrapper is what sticks to the viewport. */
  align-self: stretch;
  min-height: 100vh;
  position: relative;
  z-index: 40;
  border-inline-start: 1px solid rgba(255, 255, 255, .06);
}
.sidebar-inner {
  position: sticky; top: 0;
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
}

.sidebar-brand {
  min-height: var(--topbar-h);
  padding-block: 10px;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 18px;
  flex: none;
  border-bottom: 1px solid rgba(255, 255, 255, .07);
}
.sidebar-mark {
  width: 34px; height: 34px;
  border-radius: 9px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--accent-500), var(--accent-700));
  color: #1a1206;
  flex: none;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.35);
}
.sidebar-brand-text { min-width: 0; }
.sidebar-brand-name {
  color: #fff; font-weight: 600; font-size: 14px; line-height: 1.45;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.sidebar-brand-sub { font-size: 11.5px; color: rgba(255,255,255,.42); letter-spacing: .02em; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 14px 10px 24px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.14); background-clip: content-box; }

.nav-group + .nav-group { margin-top: 4px; }
.nav-group-head {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: 0; background: none; cursor: pointer;
  color: var(--sidebar-text);
  border-radius: var(--radius);
  font-size: 13.5px; font-weight: 500;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.nav-group-head:hover { background: var(--sidebar-hover); color: #fff; }
.nav-group-head .chev { margin-inline-start: auto; opacity: .45; transition: transform .22s var(--ease); }
.nav-group.open .nav-group-head { color: #fff; }
.nav-group.open .chev { transform: rotate(-90deg); }

.nav-items { display: none; padding: 2px 0 6px; }
.nav-group.open .nav-items { display: block; }

.nav-link {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 12px 7px 12px;
  margin-inline-start: 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: rgba(255,255,255,.58);
  position: relative;
  transition: background .14s var(--ease), color .14s var(--ease);
}
.nav-link::before {
  content: ""; position: absolute; inset-inline-start: -10px; top: 50%;
  width: 3px; height: 0; border-radius: 3px; background: var(--accent-500);
  transform: translateY(-50%); transition: height .2s var(--ease);
}
.nav-link:hover { background: var(--sidebar-hover); color: #fff; }
.nav-link.active { background: rgba(255,255,255,.09); color: #fff; font-weight: 500; }
.nav-link.active::before { height: 16px; }
.nav-link .dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .38; flex: none; }

.sidebar-foot {
  flex: none; padding: 10px; border-top: 1px solid rgba(255,255,255,.07);
}

/* --------------------------------------------------------------- content */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h);
  flex: none;
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.crumbs { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--text-faint); min-width: 0; }
.crumbs a:hover { color: var(--text); }
.crumbs .sep { opacity: .5; }
.crumbs .current { color: var(--text); font-weight: 500; }

.topbar-spacer { flex: 1; }

.search-trigger {
  display: flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 12px;
  min-width: 230px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
  color: var(--text-faint);
  font-size: 13px; cursor: pointer;
  transition: border-color .15s var(--ease), background .15s var(--ease);
}
.search-trigger:hover { border-color: var(--border-strong); background: var(--surface); }
.search-trigger kbd {
  margin-inline-start: auto;
  font-family: var(--font-num); font-size: 11px;
  padding: 1px 6px; border-radius: 5px;
  border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text-faint);
}

.icon-btn {
  width: 36px; height: 36px; flex: none;
  display: grid; place-items: center;
  border: 1px solid transparent; border-radius: var(--radius);
  background: none; color: var(--text-soft); cursor: pointer;
  transition: background .15s var(--ease), color .15s var(--ease);
}
.icon-btn:hover { background: var(--surface-sunk); color: var(--text); }

.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--brand); color: #fff;
  font-size: 12.5px; font-weight: 600; flex: none;
  object-fit: cover;
}
.avatar.lg { width: 56px; height: 56px; font-size: 19px; }

.page { padding: 22px 24px 48px; flex: 1; }
.page-narrow { max-width: 980px; margin-inline: auto; }

.page-head {
  display: flex; align-items: flex-start; gap: 16px;
  flex-wrap: wrap; margin-bottom: 20px;
}
.page-title { font-size: 21px; font-weight: 650; letter-spacing: -.01em; }
.page-sub { color: var(--text-soft); font-size: 13.5px; margin-top: 2px; }
.page-actions { margin-inline-start: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ============================================================= components */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}
.card-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.card-title { font-size: 14.5px; font-weight: 600; }
.card-title .muted { font-weight: 400; color: var(--text-faint); }
.card-head .spacer { flex: 1; }
.card-body { padding: 18px; }
.card-body.tight { padding: 0; }
.card-foot {
  padding: 12px 18px; border-top: 1px solid var(--border);
  background: var(--surface-muted);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  display: flex; align-items: center; gap: 8px;
}

/* ------------------------------------------------------------------ grid */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
/* Stat rows hold four or five tiles depending on the viewer's permissions;
   auto-fit keeps the last one from stranding on a row of its own. */
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
/* The form grid is used on its own, so it carries display:grid itself. */
.grid-12 {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 14px 16px;
  align-items: start;
}
.col-1  { grid-column: span 1; }
.col-2  { grid-column: span 2; }
.col-3  { grid-column: span 3; }
.col-4  { grid-column: span 4; }
.col-5  { grid-column: span 5; }
.col-6  { grid-column: span 6; }
.col-7  { grid-column: span 7; }
.col-8  { grid-column: span 8; }
.col-9  { grid-column: span 9; }
.col-10 { grid-column: span 10; }
.col-11 { grid-column: span 11; }
.col-12 { grid-column: span 12; }

/* --------------------------------------------------------------- buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 36px; padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font-size: 13.5px; font-weight: 500;
  cursor: pointer; white-space: nowrap;
  transition: background .14s var(--ease), border-color .14s var(--ease),
              box-shadow .14s var(--ease), transform .06s var(--ease);
}
.btn:hover { background: var(--surface-sunk); border-color: var(--n-300); }
.btn:active { transform: translateY(.5px); }
.btn[disabled], .btn.is-busy { opacity: .55; pointer-events: none; }

.btn-primary {
  background: var(--brand-700); border-color: var(--brand-700); color: #fff;
  box-shadow: var(--shadow-xs);
}
.btn-primary:hover { background: var(--brand-800); border-color: var(--brand-800); }
:root[data-theme="dark"] .btn-primary { background: var(--brand-500); border-color: var(--brand-500); }
:root[data-theme="dark"] .btn-primary:hover { background: var(--brand-400); border-color: var(--brand-400); }

.btn-accent { background: var(--accent-600); border-color: var(--accent-600); color: #fff; }
.btn-accent:hover { background: var(--accent-700); border-color: var(--accent-700); }

.btn-danger { background: var(--bad-500); border-color: var(--bad-500); color: #fff; }
.btn-danger:hover { filter: brightness(.93); }

.btn-ghost { background: none; border-color: transparent; color: var(--text-soft); }
.btn-ghost:hover { background: var(--surface-sunk); color: var(--text); }

.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: var(--radius-sm); }
.btn-icon { width: 36px; padding: 0; }
.btn-sm.btn-icon { width: 30px; }

/* ----------------------------------------------------------------- forms */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 12.5px; font-weight: 500; color: var(--text-soft); }
.field-label .req { color: var(--bad-500); margin-inline-start: 2px; }
.field-hint { font-size: 11.5px; color: var(--text-faint); }
.field-error { font-size: 11.5px; color: var(--bad-500); }

.input, .select, .textarea {
  width: 100%;
  min-height: 38px;
  padding: 7px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
  transition: border-color .14s var(--ease), box-shadow .14s var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--n-300); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-500) 16%, transparent);
}
.input[readonly] { background: var(--surface-sunk); color: var(--text-soft); }
.textarea { min-height: 92px; resize: vertical; line-height: 1.7; }
.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236c7b91' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 10px center;
  background-size: 15px;
  padding-inline-start: 11px;
  padding-inline-end: 32px;
}
.has-error .input, .has-error .select, .has-error .textarea { border-color: var(--bad-500); }

.input-group { display: flex; }
.input-group .input { border-start-end-radius: 0; border-end-end-radius: 0; }
.input-group .addon {
  display: grid; place-items: center; padding: 0 11px;
  border: 1px solid var(--border-strong); border-inline-start: 0;
  border-start-end-radius: var(--radius); border-end-end-radius: var(--radius);
  background: var(--surface-sunk); color: var(--text-faint); font-size: 12.5px;
}

/* switch */
.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  width: 38px; height: 22px; border-radius: 99px;
  background: var(--n-300); position: relative; flex: none;
  transition: background .18s var(--ease);
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; inset-inline-start: 3px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: var(--shadow-xs);
  transition: transform .18s var(--ease);
}
.switch input:checked + .track { background: var(--ok-500); }
.switch input:checked + .track::after { transform: translateX(-16px); }
html[dir="ltr"] .switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-500) 20%, transparent); }
.switch .switch-label { font-size: 13px; }

/* relation picker */
.picker { position: relative; }
.picker-input { padding-inline-end: 30px; }
.picker-clear {
  position: absolute; inset-inline-end: 6px; top: 50%; transform: translateY(-50%);
  border: 0; background: none; color: var(--text-faint); cursor: pointer;
  width: 22px; height: 22px; display: none; place-items: center; border-radius: 5px;
}
.picker.has-value .picker-clear { display: grid; }
.picker-clear:hover { background: var(--surface-sunk); color: var(--text); }
.picker-menu {
  position: absolute; z-index: 60; inset-inline: 0; top: calc(100% + 4px);
  max-height: 260px; overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 4px; display: none;
}
.picker.open .picker-menu { display: block; }
.picker-option {
  padding: 7px 10px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13px;
}
.picker-option:hover, .picker-option.cursor { background: var(--brand-soft); }
.picker-option .hint { display: block; font-size: 11.5px; color: var(--text-faint); }
.picker-empty { padding: 12px; text-align: center; color: var(--text-faint); font-size: 12.5px; }

.form-section {
  grid-column: 1 / -1;
  margin-top: 6px; padding-top: 14px;
  border-top: 1px solid var(--border);
  display: flex; align-items: baseline; gap: 10px;
}
.form-section:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.form-section h4 { font-size: 13px; font-weight: 600; color: var(--brand); }
.form-section .hint { font-size: 12px; color: var(--text-faint); }

/* ----------------------------------------------------------------- table */
.table-wrap { overflow-x: auto; border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.table { font-size: 13.5px; }
.table thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--surface-muted);
  text-align: start;
  font-size: 12px; font-weight: 600; color: var(--text-soft);
  letter-spacing: .01em;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table thead th.sortable { cursor: pointer; user-select: none; }
.table thead th.sortable:hover { color: var(--text); }
.table thead th .sort-mark { opacity: 0; margin-inline-start: 4px; font-size: 10px; }
.table thead th[aria-sort] { color: var(--brand); }
.table thead th[aria-sort] .sort-mark { opacity: 1; }
.table tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tbody tr { transition: background .1s var(--ease); }
.table tbody tr:hover { background: var(--surface-muted); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .cell-title { font-weight: 550; color: var(--text); }
.table .cell-title a:hover { color: var(--brand); text-decoration: underline; text-underline-offset: 3px; }
.table .muted { color: var(--text-faint); }
.table .row-actions { display: flex; gap: 2px; justify-content: flex-end; opacity: .35; transition: opacity .12s var(--ease); }
.table tr:hover .row-actions { opacity: 1; }
.table td.end, .table th.end { text-align: end; }
.table td.center, .table th.center { text-align: center; }

.table-toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.table-search { position: relative; flex: 1; min-width: 200px; max-width: 360px; }
.table-search .input { padding-inline-start: 34px; }
.table-search svg { position: absolute; inset-inline-start: 10px; top: 50%; transform: translateY(-50%); color: var(--text-faint); }

.table-foot {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 11px 14px; border-top: 1px solid var(--border);
  font-size: 12.5px; color: var(--text-soft);
}
.pager { display: flex; gap: 3px; margin-inline-start: auto; }
.pager button, .pager span, .pager a {
  min-width: 30px; height: 30px; padding: 0 8px;
  display: grid; place-items: center;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  background: none; cursor: pointer; font-size: 12.5px;
  font-variant-numeric: tabular-nums;
  color: var(--text-soft);
}
.pager button:hover, .pager a:hover { background: var(--surface-sunk); color: var(--text); }
.pager button.current, .pager a.current { background: var(--brand-700); border-color: var(--brand-700); color: #fff; font-weight: 600; }
.pager span.gap { cursor: default; color: var(--text-faint); }
.pager button[disabled] { opacity: .35; pointer-events: none; }

.empty { padding: 56px 24px; text-align: center; color: var(--text-faint); }
.empty svg { margin: 0 auto 12px; color: var(--n-300); }
.empty h3 { font-size: 15px; color: var(--text-soft); font-weight: 550; margin-bottom: 4px; }
.empty p { font-size: 13px; max-width: 360px; margin: 0 auto 16px; }

/* skeleton shimmer while a table loads */
.skeleton-row td { padding: 14px; }
.skeleton {
  height: 11px; border-radius: 4px;
  background: linear-gradient(90deg, var(--surface-sunk) 25%, var(--border) 37%, var(--surface-sunk) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* --------------------------------------------------------------- badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 99px;
  font-size: 11.5px; font-weight: 550; line-height: 1.7;
  border: 1px solid transparent; white-space: nowrap;
}
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.badge-neutral { background: var(--surface-sunk); color: var(--text-soft); border-color: var(--border); }
.badge-ok      { background: var(--ok-50);   color: var(--ok-500); }
.badge-warn    { background: var(--warn-50); color: var(--warn-500); }
.badge-bad     { background: var(--bad-50);  color: var(--bad-500); }
.badge-info    { background: var(--info-50); color: var(--info-500); }
.badge-brand   { background: var(--brand-soft); color: var(--brand); }
.badge-accent  { background: var(--accent-100); color: var(--accent-700); }
:root[data-theme="dark"] .badge-accent { background: rgba(195,154,75,.16); color: var(--accent-300); }

/* ----------------------------------------------------------------- stats */
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 15px 17px;
  display: flex; align-items: flex-start; gap: 13px;
  box-shadow: var(--shadow-xs);
  position: relative; overflow: hidden;
}
.stat::after {
  content: ""; position: absolute; inset-block: 0; inset-inline-start: 0;
  width: 3px; background: var(--tone, var(--brand-500));
}
.stat-icon { /* the glyph inside is sized by the icon() call */
  width: 38px; height: 38px; flex: none;
  border-radius: 10px; display: grid; place-items: center;
  background: color-mix(in srgb, var(--tone, var(--brand-500)) 12%, transparent);
  color: var(--tone, var(--brand-500));
}
.stat-body { min-width: 0; }
.stat-label { font-size: 12.5px; color: var(--text-soft); }
.stat-value { font-size: 22px; font-weight: 650; letter-spacing: -.02em; line-height: 1.3; }
.stat-meta { font-size: 11.5px; color: var(--text-faint); }
.stat.tone-ok    { --tone: var(--ok-500); }
.stat.tone-warn  { --tone: var(--warn-500); }
.stat.tone-bad   { --tone: var(--bad-500); }
.stat.tone-info  { --tone: var(--info-500); }
.stat.tone-accent{ --tone: var(--accent-600); }

/* ---------------------------------------------------------------- modals */
.overlay {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(17, 22, 30, .45);
  backdrop-filter: blur(3px);
  display: grid; place-items: start center;
  padding: 5vh 16px 16px;
  overflow-y: auto;
  opacity: 0; transition: opacity .18s var(--ease);
}
.overlay.show { opacity: 1; }
.modal {
  width: 100%; max-width: 640px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  transform: translateY(-10px) scale(.985);
  opacity: 0;
  transition: transform .2s var(--ease), opacity .2s var(--ease);
}
.overlay.show .modal { transform: none; opacity: 1; }
.modal.sm { max-width: 460px; }
.modal.lg { max-width: 780px; }
.modal.xl { max-width: 1040px; }
.modal-head {
  display: flex; align-items: center; gap: 12px;
  padding: 15px 20px; border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 15.5px; font-weight: 600; }
.modal-head .close { margin-inline-start: auto; }
.modal-body { padding: 20px; max-height: 66vh; overflow-y: auto; }
.modal-foot {
  padding: 13px 20px; border-top: 1px solid var(--border);
  background: var(--surface-muted);
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
  display: flex; gap: 8px;
}
.modal-foot .spacer { flex: 1; }

/* command palette */
.palette { max-width: 600px; }
.palette .modal-body { padding: 0; max-height: 400px; }
.palette-input {
  width: 100%; border: 0; border-bottom: 1px solid var(--border);
  padding: 16px 20px; font-size: 15px; background: none;
}
.palette-input:focus { outline: none; }
.palette-list { padding: 6px; }
.palette-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius); cursor: pointer;
  font-size: 13.5px;
}
.palette-item .where { margin-inline-start: auto; font-size: 11.5px; color: var(--text-faint); }
.palette-item:hover, .palette-item.cursor { background: var(--brand-soft); }
.palette-item svg { color: var(--text-faint); }

/* --------------------------------------------------------------- toasts */
.toasts {
  position: fixed; inset-block-end: 20px; inset-inline-end: 20px;
  z-index: 100; display: flex; flex-direction: column; gap: 8px;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  min-width: 260px; max-width: 420px;
  padding: 11px 14px;
  background: var(--n-900); color: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  animation: toast-in .24s var(--ease);
}
.toast.ok  { background: var(--ok-700); }
.toast.bad { background: var(--bad-700); }
.toast.out { animation: toast-out .2s var(--ease) forwards; }
@keyframes toast-in  { from { opacity: 0; transform: translateY(10px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }

/* ------------------------------------------------------------------ misc */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab {
  padding: 9px 14px; font-size: 13.5px; color: var(--text-soft);
  border-bottom: 2px solid transparent; white-space: nowrap; cursor: pointer;
  background: none; border-top: 0; border-inline: 0;
  transition: color .14s var(--ease), border-color .14s var(--ease);
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 550; }

.dl { display: grid; grid-template-columns: max-content 1fr; gap: 9px 18px; font-size: 13.5px; }
.dl dt { color: var(--text-faint); font-size: 12.5px; }
.dl dd { color: var(--text); }

.timeline { position: relative; padding-inline-start: 22px; }
.timeline::before {
  content: ""; position: absolute; inset-block: 6px 6px; inset-inline-start: 5px;
  width: 1px; background: var(--border);
}
.timeline-item { position: relative; padding-bottom: 16px; }
.timeline-item::before {
  content: ""; position: absolute; inset-inline-start: -21px; top: 6px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--brand-400);
}
.timeline-item.done::before { background: var(--ok-500); border-color: var(--ok-500); }
.timeline-when { font-size: 11.5px; color: var(--text-faint); }
.timeline-what { font-size: 13.5px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 99px;
  border: 1px solid var(--border-strong); background: var(--surface);
  font-size: 12.5px; cursor: pointer;
}
.chip.on { background: var(--brand-700); border-color: var(--brand-700); color: #fff; }

.alert {
  display: flex; gap: 10px; padding: 12px 14px;
  border-radius: var(--radius); font-size: 13px;
  border: 1px solid transparent;
}
.alert-ok   { background: var(--ok-50);   color: var(--ok-700);   border-color: color-mix(in srgb, var(--ok-500) 28%, transparent); }
.alert-bad  { background: var(--bad-50);  color: var(--bad-700);  border-color: color-mix(in srgb, var(--bad-500) 28%, transparent); }
.alert-warn { background: var(--warn-50); color: var(--warn-700); border-color: color-mix(in srgb, var(--warn-500) 28%, transparent); }
.alert-info { background: var(--info-50); color: var(--info-700); border-color: color-mix(in srgb, var(--info-500) 28%, transparent); }
:root[data-theme="dark"] .alert-ok   { color: #86efac; }
:root[data-theme="dark"] .alert-bad  { color: #fca5a5; }
:root[data-theme="dark"] .alert-warn { color: #fcd34d; }
:root[data-theme="dark"] .alert-info { color: #93c5fd; }

.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; inset-inline-end: 0; top: calc(100% + 6px);
  min-width: 200px; z-index: 50;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 5px; display: none;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-item {
  display: flex; align-items: center; gap: 9px;
  width: 100%; padding: 8px 10px;
  border: 0; background: none; text-align: start;
  border-radius: var(--radius-sm); font-size: 13px; cursor: pointer; color: var(--text);
}
.dropdown-item:hover { background: var(--surface-sunk); }
.dropdown-item.danger { color: var(--bad-500); }
.dropdown-sep { height: 1px; background: var(--border); margin: 5px 0; }
.dropdown-head { padding: 9px 10px 7px; font-size: 12px; color: var(--text-faint); }

/* ---------------------------------------------------------------- login */
.auth {
  min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr;
  background: var(--surface);
}
.auth-aside {
  background:
    radial-gradient(900px 500px at 80% -10%, rgba(195,154,75,.16), transparent 60%),
    linear-gradient(160deg, var(--brand-900), var(--brand-700));
  color: #fff; padding: 48px; display: flex; flex-direction: column;
  position: relative; overflow: hidden;
}
.auth-aside::after {
  content: ""; position: absolute; inset-inline-end: -120px; bottom: -140px;
  width: 460px; height: 460px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,.08);
  box-shadow: 0 0 0 60px rgba(255,255,255,.025);
}
.auth-quote { margin-top: auto; max-width: 420px; position: relative; z-index: 1; }
.auth-quote p { font-size: 19px; line-height: 1.8; font-weight: 300; }
.auth-quote cite { display: block; margin-top: 14px; font-size: 13px; color: rgba(255,255,255,.55); font-style: normal; }
.auth-form { display: grid; place-items: center; padding: 40px 24px; }
.auth-box { width: 100%; max-width: 380px; }
.auth-box h1 { font-size: 23px; margin-bottom: 6px; }
.auth-box .sub { color: var(--text-soft); font-size: 13.5px; margin-bottom: 26px; }

/* --------------------------------------------------------- responsive */
.sidebar-backdrop { display: none; }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .sidebar {
    position: fixed; inset-block: 0; right: 0; left: auto; min-height: 0;
    transform: translateX(100%); transition: transform .24s var(--ease);
    box-shadow: var(--shadow-lg);
    visibility: hidden;
  }
  .sidebar-inner { height: 100%; }
  html[dir="ltr"] .sidebar { left: 0; right: auto; transform: translateX(-100%); }
  body.nav-open .sidebar { visibility: visible; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .sidebar-backdrop {
    display: block; position: fixed; inset: 0; z-index: 39;
    background: rgba(17,22,30,.45);
  }
  .search-trigger { min-width: 0; width: 36px; padding: 0; justify-content: center; }
  .search-trigger span, .search-trigger kbd { display: none; }
  .auth { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
}

@media (max-width: 860px) {
  .grid-12 > [class*="col-"] { grid-column: span 6; }
  .grid-12 > .col-12, .grid-12 > .form-section { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
  .grid-12 > [class*="col-"] { grid-column: 1 / -1; }
  .page { padding: 16px 14px 40px; }
  .topbar { padding: 0 14px; }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .hide-sm { display: none !important; }
  .modal-body { max-height: 70vh; }
}
@media (max-width: 860px) { .hide-md { display: none !important; } }

/* ---------------------------------------------------------------- print */
@media print {
  .sidebar, .topbar, .page-actions, .table-toolbar, .table-foot, .row-actions, .no-print { display: none !important; }
  body { background: #fff; font-size: 11pt; }
  .card { border: 0; box-shadow: none; }
  .page { padding: 0; }
  .table thead th { background: #f1f1f1 !important; -webkit-print-color-adjust: exact; }
  .print-head { display: block !important; margin-bottom: 16px; }
}
.print-head { display: none; }

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

/* ================================================================ reports */
/* Printed reports carry the firm's letterhead; on screen the page header
   already says where you are, so the letterhead stays hidden. */
.letterhead {
  display: flex; align-items: flex-start; gap: 20px;
  padding-bottom: 12px; margin-bottom: 14px;
  border-bottom: 2px double var(--n-800);
}
.letterhead-side { flex: 0 0 200px; text-align: end; }
.letterhead-side.start { text-align: start; }
.letterhead-label { font-size: 10pt; color: var(--text-faint); }
.letterhead-office { font-size: 14pt; font-weight: 700; }
.letterhead-owner { font-size: 10pt; color: var(--text-soft); }
.letterhead-middle { flex: 1; text-align: center; }
.letterhead-title {
  display: inline-block;
  font-size: 13pt; font-weight: 700;
  padding: 4px 16px; border-radius: 4px;
  background: #fff7cc; border: 1px solid #e6d27a;   /* the old report's highlight */
  box-shadow: 2px 2px 0 rgba(0, 0, 0, .12);
}
.letterhead-sub { font-size: 10pt; color: var(--text-soft); margin-top: 6px; }

.print-foot {
  display: none;
  justify-content: space-between; gap: 16px;
  margin-top: 16px; padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 9pt; color: var(--text-soft);
}

.report-note {
  display: flex; align-items: center; gap: 9px;
  padding: 11px 14px; margin-bottom: 14px;
  border-radius: var(--radius);
  background: var(--warn-50); color: var(--warn-700);
  border: 1px solid color-mix(in srgb, var(--warn-500) 28%, transparent);
  font-size: 13px;
}
:root[data-theme="dark"] .report-note { color: #fcd34d; }

/* A grouping band inside the table, the way the old report banded by client. */
.report-table .group-row td {
  padding: 9px 14px;
  background: var(--surface-sunk);
  border-top: 2px solid var(--border-strong);
  border-bottom: 1px solid var(--border-strong);
}
.report-table .group-row:first-child td { border-top: 0; }
.report-table .group-row:hover td { background: var(--surface-sunk); }
.report-group-label {
  display: inline-block; margin-inline-end: 9px;
  font-size: 11.5px; color: var(--text-faint);
  padding: 2px 8px; border-radius: 4px;
  background: var(--surface); border: 1px solid var(--border);
}
.report-group-name { font-size: 14.5px; font-weight: 650; margin-inline-end: 9px; }

.report-table { font-size: 13px; }
.report-table td { vertical-align: top; }
.report-table .day-cell { background: #fffbe6; font-weight: 550; }
:root[data-theme="dark"] .report-table .day-cell { background: rgba(195, 154, 75, .12); }
.report-table .subject { color: var(--text-soft); line-height: 1.6; }
.report-table .circle {
  display: block; font-size: 11px; color: var(--text-faint);
  margin-top: 2px; padding-top: 2px; border-top: 1px dotted var(--border-strong);
}

@media print {
  .print-foot { display: flex; }
  .report-note { display: none; }
  .report-table .group-row { break-after: avoid; break-inside: avoid; }
  .report-table .group-row td { background: #ededed !important; -webkit-print-color-adjust: exact; }
  .report-table tr { break-inside: avoid; }
  .report-table thead { display: table-header-group; }   /* repeat on every page */
  .report-table .day-cell { -webkit-print-color-adjust: exact; }
  .letterhead-title { -webkit-print-color-adjust: exact; }
  .table-wrap { overflow: visible; }
}

/* The overdue strip on the dashboard: loud on purpose, and absent when the
   office is clear. */
.alert-strip { display: flex; gap: 9px; flex-wrap: wrap; margin-bottom: 18px; }
.alert-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px 8px 10px;
  border-radius: 99px;
  background: var(--bad-50);
  border: 1px solid color-mix(in srgb, var(--bad-500) 32%, transparent);
  color: var(--bad-700);
  font-size: 13px; font-weight: 500;
  transition: background .15s var(--ease), transform .06s var(--ease);
}
.alert-chip:hover { background: color-mix(in srgb, var(--bad-500) 16%, transparent); }
.alert-chip:active { transform: translateY(.5px); }
.alert-chip-count {
  min-width: 22px; height: 22px; padding: 0 6px;
  display: grid; place-items: center;
  border-radius: 99px;
  background: var(--bad-500); color: #fff;
  font-size: 12px; font-weight: 700;
}
:root[data-theme="dark"] .alert-chip { color: #fca5a5; }
@media print { .alert-strip { display: none; } }

/* ================================================================= agenda */
.agenda-tabs {
  display: flex; gap: 4px; flex-wrap: wrap;
  margin-bottom: 16px; padding-bottom: 2px;
}
.agenda-tab {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 12px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text-soft);
  font-size: 13px; white-space: nowrap;
  transition: border-color .14s var(--ease), background .14s var(--ease), color .14s var(--ease);
}
.agenda-tab:hover { border-color: var(--n-300); color: var(--text); }
.agenda-tab.active {
  background: var(--brand-700); border-color: var(--brand-700); color: #fff; font-weight: 500;
}
:root[data-theme="dark"] .agenda-tab.active { background: var(--brand-500); border-color: var(--brand-500); }
.agenda-tab.empty { opacity: .55; }
.agenda-tab-count {
  min-width: 20px; padding: 0 6px;
  border-radius: 99px; background: var(--surface-sunk);
  font-size: 11.5px; font-weight: 600;
}
.agenda-tab.active .agenda-tab-count { background: rgba(255, 255, 255, .22); color: #fff; }

.agenda-day { margin-bottom: 12px; overflow: hidden; }
.agenda-day.is-empty { opacity: .55; }
.agenda-day-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  background: var(--surface-muted);
  border-bottom: 1px solid var(--border);
}
.agenda-day-head .spacer { flex: 1; }
.agenda-day-name { font-size: 14.5px; font-weight: 650; }
.agenda-day-date { font-size: 12.5px; color: var(--text-faint); }
.agenda-day-empty { padding: 16px; font-size: 12.5px; color: var(--text-faint); }

.agenda-table { font-size: 12.5px; }
.agenda-table td { vertical-align: top; padding: 8px 10px; }
.agenda-table th { padding: 8px 10px; }
.agenda-table .soft { color: var(--text-soft); line-height: 1.6; }

@media print {
  .agenda-day { break-inside: auto; margin-bottom: 8px; border: 0; }
  .agenda-day.is-empty { display: none; }   /* a blank day wastes a printed line */
  .agenda-day-head { break-after: avoid; background: #ededed !important; -webkit-print-color-adjust: exact; }
  .agenda-table tr { break-inside: avoid; }
  .agenda-table thead { display: table-header-group; }
  .agenda-table { font-size: 8.5pt; }
}

/* A fieldset that only exists to disable a locked form; it takes no box. */
fieldset.contents { display: contents; border: 0; margin: 0; padding: 0; min-width: 0; }

/* ------------------------------------------------------------ printed pages */
.letterhead-logo { max-height: 64px; max-width: 160px; object-fit: contain; display: block; margin-inline-start: auto; margin-bottom: 4px; }
.letterhead-side.start .letterhead-logo { margin-inline-start: 0; }
body.print-page { background: #eef0f3; }
.print-page .print-head { display: block; margin-bottom: 14px; }
.print-toolbar { position: sticky; top: 0; z-index: 5; display: flex; gap: 8px; justify-content: center; padding: 10px; background: #fff; border-bottom: 1px solid var(--border); }
.print-sheet { background: #fff; color: #111; width: 210mm; min-height: 297mm; margin: 16px auto; padding: 14mm 12mm; box-shadow: 0 2px 12px rgba(0,0,0,.08); }
.print-sheet.landscape { width: 297mm; min-height: 210mm; }
.print-sheet .print-foot { display: flex; justify-content: space-between; gap: 12px; margin-top: 18px; padding-top: 8px; border-top: 1px solid #ccc; font-size: 9pt; color: #555; }
.voucher { border: 1.5px solid #222; border-radius: 6px; padding: 14px 16px; }
.voucher + .voucher { margin-top: 18mm; }
.voucher-head { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 1px dashed #999; padding-bottom: 8px; margin-bottom: 10px; }
.voucher-title { font-size: 15pt; font-weight: 700; }
.voucher-no { font-size: 12pt; }
.voucher-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 18px; }
.voucher-row { display: flex; gap: 8px; border-bottom: 1px dotted #bbb; padding: 4px 0; }
.voucher-row.full { grid-column: 1 / -1; }
.voucher-label { color: #555; min-width: 96px; }
.voucher-value { font-weight: 600; }
.voucher-amount { font-size: 16pt; font-weight: 700; }
.voucher-words { background: #f5f5f5; border-radius: 4px; padding: 6px 10px; margin-top: 8px; }
.voucher-signs { display: flex; justify-content: space-between; margin-top: 26px; font-size: 10pt; }
.voucher-signs > div { text-align: center; min-width: 150px; border-top: 1px solid #333; padding-top: 4px; }
.sheet-table { width: 100%; border-collapse: collapse; font-size: 10pt; }
.sheet-table th, .sheet-table td { border: 1px solid #999; padding: 4px 6px; text-align: start; vertical-align: top; }
.sheet-table th { background: #eee; font-weight: 600; }
.sheet-table tfoot td { font-weight: 700; background: #f5f5f5; }
.sheet-group { background: #f0f0f0; font-weight: 700; }
@media print {
  body.print-page { background: #fff; }
  .print-sheet { width: auto; min-height: 0; margin: 0; padding: 0; box-shadow: none; }
}

/* ================================================================ polish v2
   Data-dense office screens: compact rows by default (the density toggle
   switches to "comfortable" and is remembered per browser), sticky headers,
   truncated long names with a tooltip, filter chips, and phone layouts.
   ========================================================================= */
.nowrap { white-space: nowrap; }
.truncate {
  display: inline-block; max-width: 100%; vertical-align: bottom;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.kbd, kbd.kbd {
  font-family: var(--font-num); font-size: 10.5px; line-height: 1;
  padding: 3px 5px; border-radius: 4px;
  border: 1px solid var(--border-strong); background: var(--surface-sunk); color: var(--text-faint);
}
.btn-primary .kbd { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.25); color: #fff; }

/* --- tables: compact by default ---------------------------------------- */
.table { font-size: 13px; }
.table tbody td { padding: 6px 12px; line-height: 1.5; }
.table thead th { padding: 8px 12px; font-size: 11.5px; }
.table .cell-title { font-weight: 600; white-space: nowrap; }
.table td .truncate { max-width: 240px; }
.table td.cell-wide .truncate { max-width: 340px; }
.table .row-actions { opacity: .55; gap: 0; }
.table .row-actions .btn-sm.btn-icon { width: 28px; height: 28px; }
.table tbody tr:focus-within .row-actions { opacity: 1; }
html[data-density="comfortable"] .table { font-size: 13.5px; }
html[data-density="comfortable"] .table tbody td { padding: 11px 14px; line-height: 1.6; }
html[data-density="comfortable"] .table thead th { padding: 10px 14px; }
html[data-density="comfortable"] .table td .truncate { max-width: 360px; }

/* Sticky header: the list scrolls inside its card so the header stays put. */
.table-wrap.scroll-y { max-height: calc(100vh - var(--topbar-h) - 190px); min-height: 240px; overflow: auto; }
.table-wrap.scroll-y thead th { position: sticky; top: 0; z-index: 2; box-shadow: inset 0 -1px 0 var(--border); }

/* A locked record: a small muted padlock by its reference, not a button. */
.lock-mark { display: inline-flex; vertical-align: -2px; margin-inline-start: 5px; color: var(--text-faint); opacity: .7; }
.lock-mark .icon { width: 12px; height: 12px; }

.money-zero { color: var(--text-faint); }

/* --- toolbar: search, filters, chips ------------------------------------ */
.table-toolbar { padding: 10px 12px; gap: 8px; }
.table-toolbar .field { min-width: 140px !important; }
.table-toolbar .select, .table-toolbar .input { min-height: 34px; padding-block: 5px; font-size: 13px; }
.table-toolbar .tools { margin-inline-start: auto; display: flex; gap: 6px; align-items: center; }
.density-toggle { height: 34px; width: 34px; }
.select.is-set { border-color: var(--brand-400); background-color: var(--brand-soft); color: var(--brand); font-weight: 500; }

.filter-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 0 12px 10px; }
.filter-chips:empty { display: none; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 4px 2px 10px; border-radius: 99px;
  background: var(--brand-soft); color: var(--brand);
  border: 1px solid color-mix(in srgb, var(--brand-500) 25%, transparent);
  font-size: 12px;
}
.filter-chip button {
  width: 18px; height: 18px; display: grid; place-items: center;
  border: 0; border-radius: 50%; background: none; color: inherit; cursor: pointer;
}
.filter-chip button:hover { background: color-mix(in srgb, var(--brand-500) 18%, transparent); }
.filter-chips .clear-all { border: 0; background: none; color: var(--text-soft); font-size: 12px; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* --- empty states -------------------------------------------------------- */
.empty { padding: 44px 24px; }
.empty .empty-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* --- page head ----------------------------------------------------------- */
.page-head { align-items: center; margin-bottom: 16px; }
.page-title { font-size: 20px; }
.quick-links .btn { gap: 6px; }

/* --- forms: check rows, switch grid, permission tree --------------------- */
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--brand-600); margin: 0; flex: none; }
.check-row { display: flex; flex-wrap: wrap; gap: 10px 22px; padding: 6px 0; }
.switch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px 18px; }
.input-group .addon-btn { cursor: pointer; gap: 6px; display: inline-flex; align-items: center; white-space: nowrap; }
.input-group .addon-btn:hover { color: var(--text); }

.perm-tree { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-muted); }
.perm-tree-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.perm-tree-bar .spacer { flex: 1; }
.perm-filter { max-width: 220px; min-height: 32px; padding-block: 4px; }
.perm-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; padding: 12px; align-items: start; }
.perm-group { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: 8px 12px 10px; margin: 0; min-width: 0; display: grid; gap: 6px; align-content: start; }
.perm-group[hidden] { display: none; }
.perm-group legend { display: flex; align-items: center; gap: 8px; width: 100%; padding: 4px 0 6px; border-bottom: 1px dashed var(--border); margin-bottom: 2px; float: left; }
.perm-group legend .check { font-weight: 600; color: var(--brand); }
.perm-group legend .icon { width: 15px; height: 15px; }
.perm-count { margin-inline-start: auto; font-size: 11px; color: var(--text-faint); }
.perm-group .check[hidden] { display: none; }
.perm-tree.all-on .perm-groups { opacity: .5; pointer-events: none; }

.logo-picker { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.logo-preview {
  width: 180px; height: 96px; flex: none; display: grid; place-items: center;
  border: 1px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-muted);
  background-image: linear-gradient(45deg, var(--surface-sunk) 25%, transparent 25%, transparent 75%, var(--surface-sunk) 75%);
  background-size: 14px 14px;
}
.logo-preview img { max-width: 160px; max-height: 80px; object-fit: contain; }
.backup-figure { font-size: 22px; font-weight: 650; margin-bottom: 6px; }
.backup-figure .muted { font-size: 13px; font-weight: 400; color: var(--text-faint); }

/* --- command palette with record results --------------------------------- */
.palette .modal-body { max-height: 70vh; }
.palette-group { padding: 8px 12px 4px; font-size: 11.5px; font-weight: 600; color: var(--text-faint); display: flex; align-items: center; gap: 6px; }
.palette-item .meta { display: block; font-size: 11.5px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.palette-item .body { min-width: 0; flex: 1; }
.palette-item .title { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.palette-hint { padding: 8px 14px; font-size: 11.5px; color: var(--text-faint); border-top: 1px solid var(--border); display: flex; gap: 14px; flex-wrap: wrap; }
.palette-loading { padding: 10px 14px; font-size: 12px; color: var(--text-faint); }

/* --- toasts --------------------------------------------------------------- */
.toast { gap: 9px; }
.toast .icon { width: 16px; height: 16px; flex: none; }

/* --- client portal --------------------------------------------------------- */
body.portal { background: var(--bg); }
.portal-bar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px; background: var(--brand-900); color: #fff;
}
.portal-logo { max-height: 38px; max-width: 110px; object-fit: contain; background: #fff; border-radius: 6px; padding: 2px 4px; }
.portal-office { font-weight: 600; font-size: 14px; line-height: 1.4; }
.portal-sub { font-size: 11.5px; color: rgba(255,255,255,.55); }
.portal-bar .btn-ghost { color: rgba(255,255,255,.8); }
.portal-bar .btn-ghost:hover { background: rgba(255,255,255,.1); color: #fff; }
.portal-main { max-width: 1040px; margin: 0 auto; padding: 22px 18px 48px; }
.auth.auth-single { grid-template-columns: 1fr; background: var(--bg); }
.auth-single .auth-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 28px 24px; box-shadow: var(--shadow-sm); }

/* --- dashboard ------------------------------------------------------------- */
.dash-grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }

/* --- phones ---------------------------------------------------------------- */
@media (max-width: 1100px) {
  .dash-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  html, body { overflow-x: hidden; }
  .page-head { gap: 10px; }
  .page-actions { margin-inline-start: 0; width: 100%; }
  .page-actions .btn { flex: 1 1 auto; }
  .grid-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 11px 12px; gap: 9px; }
  .stat-icon { width: 30px; height: 30px; }
  .stat-value { font-size: 18px; }
  .stat-meta { display: none; }
  .table-toolbar .table-search { max-width: none; min-width: 100%; }
  .table-toolbar .field { flex: 1 1 45%; min-width: 0 !important; }
  .table-toolbar .tools { margin-inline-start: 0; }
  .table-wrap.scroll-y { max-height: none; overflow-x: auto; }
  /* Wide lists scroll sideways with the first column pinned. */
  .table-wrap .table { min-width: 560px; }
  .table-wrap .table th:first-child,
  .table-wrap .table td:first-child {
    position: sticky; inset-inline-start: 0; z-index: 1;
    background: var(--surface); box-shadow: inset -1px 0 0 var(--border);
  }
  .table-wrap .table thead th:first-child { z-index: 3; background: var(--surface-muted); }
  .table td .truncate { max-width: 170px; }
  .table .row-actions { opacity: 1; }
  .quick-links .btn { flex: 1 1 40%; }
  .quick-links .kbd { display: none; }
  .toasts { inset-inline: 12px; inset-block-end: 12px; }
  .toast { min-width: 0; max-width: none; }
  .crumbs { overflow: hidden; }
  .crumbs > *:not(:first-child):not(:last-child) { display: none; }
  .portal-main { padding: 16px 12px 40px; }
}
@media print {
  .table-wrap.scroll-y { max-height: none; overflow: visible; }
  .filter-chips, .density-toggle { display: none !important; }
}

/* Compact lists keep every row on one line; a cell that overflows gets its
   full text as a tooltip (app.js), and "مريح" lets long cells wrap again. */
html:not([data-density="comfortable"]) .table-wrap.scroll-y .table td {
  white-space: nowrap; max-width: 250px; overflow: hidden; text-overflow: ellipsis;
}
/* The actions column stays in view when a wide list scrolls sideways. */
.table-wrap.scroll-y .table thead th:last-child,
.table-wrap.scroll-y .table tbody td:last-child {
  position: sticky; inset-inline-end: 0; z-index: 1;
  background: var(--surface); box-shadow: inset 1px 0 0 var(--border);
}
.table-wrap.scroll-y .table thead th:last-child { z-index: 3; background: var(--surface-muted); }
.table-wrap.scroll-y .table tbody tr:hover td:last-child { background: var(--surface-muted); }
html:not([data-density="comfortable"]) .table-wrap.scroll-y .table td br { display: none; }
html:not([data-density="comfortable"]) .table-wrap.scroll-y .table td.end { overflow: visible; }
/* Nested dashboard columns must shrink too, or a wide table pushes the page sideways. */
.dash-grid > .grid, .dash-grid > * { min-width: 0; grid-template-columns: minmax(0, 1fr); }
@media (max-width: 640px) {
  .table-wrap.scroll-y .table td { max-width: 210px; }
  .card .table-wrap { max-width: 100%; }
}

/* The actions column takes exactly the width of its icons — a fixed width let
   five or six icons spill over the column beside it. */
.table th.col-actions, .table tbody td:last-child { width: 1%; white-space: nowrap; }
.table .row-actions { flex-wrap: nowrap; }
/* On a phone a row keeps its first two actions (the record's own page first);
   the rest stay one tap away inside that page, and the name gets the room. */
@media (max-width: 640px) {
  .table .row-actions > :nth-child(n+3) { display: none; }
}
/* Long names are clipped (the full text is in the tooltip) so a ten-column list
   fits a laptop screen instead of hiding its last columns behind the scroll. */
html:not([data-density="comfortable"]) .table-wrap.scroll-y .table td { max-width: 180px; }
@media (max-width: 1500px) {
  html:not([data-density="comfortable"]) .table-wrap.scroll-y .table td { max-width: 150px; }
}
@media (max-width: 1500px) { .hide-lg { display: none !important; } }

/* Sidebar sections open one at a time and fold with a short slide, so the
   eye follows which section closed instead of the list jumping. */
.nav-items {
  display: block; overflow: hidden; max-height: 0; opacity: 0;
  padding-block: 0; transition: max-height .24s var(--ease), opacity .18s var(--ease), padding .24s var(--ease);
}
.nav-group.open .nav-items { max-height: 720px; opacity: 1; padding-block: 2px 6px; }
.chev { transition: transform .2s var(--ease); }
@media (prefers-reduced-motion: reduce) { .nav-items, .chev { transition: none; } }

/* The menu button opens the sidebar only where the sidebar folds away
   (the same 900px as above); on a desktop the sidebar is always there.
   It used to carry .hide-md, which hides under 860px — so phones, the only
   screens that need it, never saw it. */
.nav-toggle { display: none; }
@media (max-width: 900px) { .topbar .nav-toggle { display: grid; } }

/* ------------------------------------------------- dashboard date window */
.dfilter { position: relative; display: inline-flex; align-items: center; gap: 4px; }
.dfilter-step, .dfilter-main, .dfilter-today {
  height: 42px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  text-decoration: none; font: inherit; cursor: pointer; transition: background .13s var(--ease), border-color .13s var(--ease);
}
.dfilter-step { width: 38px; border-radius: var(--radius); color: var(--text-soft); }
.dfilter-step:hover { background: var(--surface-muted); color: var(--text); border-color: var(--border-strong); }
.dfilter-step:active { transform: translateY(1px); }
.dfilter-main { gap: 10px; padding: 0 14px; border-radius: var(--radius); min-width: 190px; }
.dfilter-main:hover { background: var(--surface-muted); border-color: var(--border-strong); }
.dfilter-main .icon:first-child { color: var(--accent); }
.dfilter-text { display: grid; text-align: start; line-height: 1.25; }
.dfilter-text b { font-size: 13.5px; font-weight: 600; }
.dfilter-text small { font-size: 11px; color: var(--text-faint); }
.dfilter-today { padding: 0 14px; border-radius: var(--radius); font-size: 13px; font-weight: 600; color: var(--brand); }
.dfilter-today:hover { background: var(--brand-soft); }
.dfilter.open .dfilter-main { border-color: var(--brand-500, #3b5998); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-500, #3b5998) 16%, transparent); }

.dfilter-pop {
  position: absolute; top: calc(100% + 8px); inset-inline-start: 0; z-index: 45; width: 340px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: 12px; animation: dfilterIn .14s var(--ease);
}
@keyframes dfilterIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.dfilter-presets { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.dfilter-preset {
  padding: 9px 10px; border-radius: 10px; font-size: 13px; text-align: center; text-decoration: none;
  color: var(--text); background: var(--surface-muted); border: 1px solid transparent;
}
.dfilter-preset:hover { background: var(--surface-sunk); }
.dfilter-preset.on { background: var(--brand); color: #fff; }
.dfilter-custom { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.dfilter-field label { display: block; font-size: 11.5px; color: var(--text-soft); margin-bottom: 4px; }
.dfilter-field input { width: 100%; height: 38px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 0 10px; font: inherit; font-size: 13px; }
.dfilter-field input:focus { outline: none; border-color: var(--brand-500, #3b5998); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-500, #3b5998) 16%, transparent); }
.dfilter-custom .btn { height: 38px; }
.dfilter-note { margin: 10px 2px 0; font-size: 11.5px; color: var(--text-faint); }

@media (max-width: 640px) {
  .dfilter { width: 100%; }
  .dfilter-main { flex: 1; min-width: 0; }
  .dfilter-pop { width: min(340px, calc(100vw - 28px)); inset-inline-start: auto; inset-inline-end: 0; }
  .dfilter-custom { grid-template-columns: 1fr 1fr; }
  .dfilter-custom .btn { grid-column: 1 / -1; }
}
