/* HIS prototypes — shared design system (RTL, Arabic-first) */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Arabic:wght@400;500;600;700&display=swap');

:root {
  --bg: #F4F6FA;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --ink: #0F172A;
  --ink-2: #334155;
  --muted: #64748B;
  --line: #E3E8EF;
  --line-2: #EEF2F6;

  --primary: #3B5BDB;
  --primary-600: #2F4AC0;
  --primary-soft: #EDF1FF;
  --primary-ink: #23359A;

  --success: #15803D;
  --success-soft: #E7F6EC;
  --warning: #B45309;
  --warning-soft: #FEF3E2;
  --danger: #DC2626;
  --danger-soft: #FDECEC;
  --info: #0369A1;
  --info-soft: #E6F3FA;
  --violet: #6D28D9;
  --violet-soft: #F1EBFE;
  --neutral-soft: #EEF1F5;

  --sidebar: #0B1433;
  --sidebar-2: #16214A;
  --sidebar-ink: #C9D2EE;
  --sidebar-muted: #7E8BB6;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .05);
  --shadow-lg: 0 24px 60px rgba(15, 23, 42, .22);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0A0F1E;
    --surface: #111A2E;
    --surface-2: #0E1628;
    --ink: #E6EAF5;
    --ink-2: #C3CBE0;
    --muted: #8A96B3;
    --line: #223050;
    --line-2: #1A253F;
    --primary: #6E8BFF;
    --primary-600: #5A78F5;
    --primary-soft: rgba(110, 139, 255, .15);
    --primary-ink: #B4C3FF;
    --success: #4ADE80;
    --success-soft: rgba(74, 222, 128, .12);
    --warning: #FBBF24;
    --warning-soft: rgba(251, 191, 36, .12);
    --danger: #F87171;
    --danger-soft: rgba(248, 113, 113, .13);
    --info: #38BDF8;
    --info-soft: rgba(56, 189, 248, .12);
    --violet: #A78BFA;
    --violet-soft: rgba(167, 139, 250, .14);
    --neutral-soft: #1A2440;
    --sidebar: #070C1F;
    --sidebar-2: #131C3D;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0A0F1E;
  --surface: #111A2E;
  --surface-2: #0E1628;
  --ink: #E6EAF5;
  --ink-2: #C3CBE0;
  --muted: #8A96B3;
  --line: #223050;
  --line-2: #1A253F;
  --primary: #6E8BFF;
  --primary-600: #5A78F5;
  --primary-soft: rgba(110, 139, 255, .15);
  --primary-ink: #B4C3FF;
  --success: #4ADE80;
  --success-soft: rgba(74, 222, 128, .12);
  --warning: #FBBF24;
  --warning-soft: rgba(251, 191, 36, .12);
  --danger: #F87171;
  --danger-soft: rgba(248, 113, 113, .13);
  --info: #38BDF8;
  --info-soft: rgba(56, 189, 248, .12);
  --violet: #A78BFA;
  --violet-soft: rgba(167, 139, 250, .14);
  --neutral-soft: #1A2440;
  --sidebar: #070C1F;
  --sidebar-2: #131C3D;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: 'IBM Plex Sans Arabic', system-ui, 'Segoe UI', Tahoma, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.3; }
.ic { width: 18px; height: 18px; flex: 0 0 auto; }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 264px; flex: 0 0 264px;
  background: var(--sidebar); color: var(--sidebar-ink);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column;
  scrollbar-width: thin; scrollbar-color: #26315c transparent;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 20px 20px 14px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 11px;
  background: linear-gradient(135deg, #5B7CFF, #8B5CF6);
  display: grid; place-items: center; color: #fff;
  box-shadow: 0 6px 18px rgba(91, 124, 255, .35);
}
.brand-mark .ic { width: 20px; height: 20px; }
.brand-name { font-weight: 700; color: #fff; font-size: 15px; }
.brand-sub { font-size: 11.5px; color: var(--sidebar-muted); }
.nav-group { padding: 6px 12px; }
.nav-label { font-size: 11.5px; color: var(--sidebar-muted); padding: 10px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 10px;
  color: var(--sidebar-ink); font-size: 13.5px; text-decoration: none;
}
.nav-item:hover { background: var(--sidebar-2); color: #fff; text-decoration: none; }
.nav-item .ic { opacity: .8; }
.nav-item.active {
  background: linear-gradient(270deg, rgba(110, 139, 255, .30), rgba(110, 139, 255, .08));
  color: #fff; box-shadow: inset -3px 0 0 #8FA5FF;
}
.nav-item.active .ic { opacity: 1; }
.nav-item .nav-badge {
  margin-inline-start: auto; font-size: 11px; padding: 0 7px; border-radius: 999px;
  background: rgba(255, 255, 255, .12); color: #fff;
}
.nav-search { padding: 0 14px 10px; }
.nav-search .input { height: 34px; background: rgba(255, 255, 255, .06); border-color: rgba(255, 255, 255, .08); color: #fff; font-size: 13px; }
.nav-search .input::placeholder { color: var(--sidebar-muted); }
.nav-search .input:focus { border-color: #8FA5FF; box-shadow: none; }
.nav-search .ic { color: var(--sidebar-muted); }
.nav-section { padding: 1px 12px; }
.nav-sec-btn {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; background: transparent;
  color: var(--sidebar-ink); font: inherit; font-size: 13.5px; font-weight: 500; border-radius: 10px; cursor: pointer; text-align: start;
}
.nav-sec-btn:hover { background: var(--sidebar-2); color: #fff; }
.nav-sec-btn .ic { opacity: .8; }
.nav-sec-btn .chev { margin-inline-start: auto; width: 15px; height: 15px; opacity: .5; transition: transform .2s; }
.nav-section.open > .nav-sec-btn .chev { transform: rotate(180deg); }
.nav-section.has-active > .nav-sec-btn { color: #fff; font-weight: 600; }
.nav-sec-items { display: none; padding: 2px 0 6px; padding-inline-start: 18px; }
.nav-section.open .nav-sec-items, .nav-section.filtering .nav-sec-items { display: block; }
.nav-sec-items .nav-item { font-size: 13px; padding: 7px 10px; }
.nav-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--sidebar-muted); flex: 0 0 auto; }
.nav-item.active .nav-dot { background: #8FA5FF; box-shadow: 0 0 0 3px rgba(143, 165, 255, .25); }
.nav-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot {
  margin-top: auto; padding: 14px 18px; border-top: 1px solid rgba(255, 255, 255, .06);
  font-size: 12px; color: var(--sidebar-muted);
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; height: 64px;
  display: flex; align-items: center; gap: 12px; padding: 0 24px;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.crumbs { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; }
.crumbs b { color: var(--ink); font-weight: 600; }
.crumbs .ic { width: 14px; height: 14px; }
.top-search { margin-inline-start: auto; width: 320px; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); display: grid; place-items: center; color: var(--ink-2);
  cursor: pointer; position: relative; padding: 0;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn .dot {
  position: absolute; top: 8px; inset-inline-end: 9px; width: 7px; height: 7px;
  border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 2px var(--surface);
}
.menu-btn { display: none; }
.user-chip {
  display: flex; align-items: center; gap: 10px; padding: 4px 12px 4px 4px;
  padding-inline: 4px 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface);
}
.user-chip .who { line-height: 1.2; }
.user-chip .who b { display: block; font-size: 12.5px; }
.user-chip .who span { font-size: 11px; color: var(--muted); }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary-ink);
  display: grid; place-items: center; font-weight: 600; font-size: 12px; flex: 0 0 auto;
}
.avatar.lg { width: 44px; height: 44px; font-size: 15px; }
.avatar.violet { background: var(--violet-soft); color: var(--violet); }
.avatar.success { background: var(--success-soft); color: var(--success); }
.avatar.warning { background: var(--warning-soft); color: var(--warning); }

.content { padding: 24px; width: 100%; max-width: 1440px; margin: 0 auto; }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 22px; font-weight: 700; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.back-link { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.back-link .ic { width: 16px; height: 16px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn .ic { width: 16px; height: 16px; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:focus-visible, .chip:focus-visible, .tab:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); }
.btn-soft { background: var(--primary-soft); border-color: transparent; color: var(--primary-ink); }
.btn-soft:hover { background: var(--primary-soft); filter: brightness(.97); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); filter: brightness(.95); }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-success:hover { background: var(--success); filter: brightness(.95); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--neutral-soft); }
.btn-sm { height: 32px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.btn-icon { width: 32px; padding: 0; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- Cards & grids ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line-2); flex-wrap: wrap; }
.card-head h3 { margin: 0; font-size: 15px; font-weight: 600; }
.card-head p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.card-body { padding: 18px; }
.card-body.tight { padding: 0; }
.stack-lg > * + * { margin-top: 16px; }
.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)); }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.split.wide-side { grid-template-columns: minmax(0, 1fr) 420px; }
.mb-16 { margin-bottom: 16px; }
.mt-16 { margin-top: 16px; }

/* ---------- KPI tiles ---------- */
.kpi { padding: 16px 18px; }
.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kpi-label { color: var(--muted); font-size: 12.5px; }
.kpi-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.kpi-icon.success { background: var(--success-soft); color: var(--success); }
.kpi-icon.warning { background: var(--warning-soft); color: var(--warning); }
.kpi-icon.danger { background: var(--danger-soft); color: var(--danger); }
.kpi-icon.violet { background: var(--violet-soft); color: var(--violet); }
.kpi-icon.info { background: var(--info-soft); color: var(--info); }
.kpi-value { font-size: 24px; font-weight: 700; margin-top: 8px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi-value small { font-size: 13px; font-weight: 500; color: var(--muted); }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 2px; display: flex; align-items: center; gap: 6px; }
.trend-up { color: var(--success); font-weight: 600; }
.trend-down { color: var(--danger); font-weight: 600; }

/* ---------- Forms ---------- */
.input, .select, .textarea {
  height: 38px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink); padding: 0 12px;
  font: inherit; min-width: 0; width: 100%;
}
.textarea { height: auto; min-height: 90px; padding: 10px 12px; resize: vertical; line-height: 1.6; }
.select { appearance: none; padding-inline-end: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748B' 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 12px center; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input[readonly] { background: var(--surface-2); color: var(--ink-2); }
.input-icon { position: relative; min-width: 0; }
.input-icon .ic { position: absolute; inset-inline-start: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.input-icon .input { padding-inline-start: 36px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field-label { font-size: 12.5px; color: var(--ink-2); font-weight: 500; }
.field .hint { font-size: 11.5px; color: var(--muted); }
.req::after { content: ' *'; color: var(--danger); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-all { grid-column: 1 / -1; }
.form-section { font-size: 13px; font-weight: 600; color: var(--ink); margin: 6px 0 -4px; grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; }
.form-section::after { content: ''; flex: 1; height: 1px; background: var(--line-2); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13.5px; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); width: 16px; height: 16px; margin: 0; }
.radio-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.radio-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; cursor: pointer; display: flex; gap: 10px; align-items: flex-start; background: var(--surface); }
.radio-card:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.radio-card b { display: block; font-size: 13.5px; }
.radio-card span { font-size: 12px; color: var(--muted); }

.switch { position: relative; width: 38px; height: 22px; display: inline-block; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--line); border-radius: 999px; transition: .2s; cursor: pointer; }
.switch span::after { content: ''; position: absolute; top: 3px; right: 3px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 2px rgba(0, 0, 0, .25); }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(-16px); }

/* ---------- Toolbar, chips, segmented ---------- */
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 14px; border-bottom: 1px solid var(--line-2); }
.toolbar .input-icon { flex: 1 1 240px; max-width: 340px; }
.toolbar .select, .toolbar .input { width: auto; }
.toolbar .input-icon .input { width: 100%; }
.toolbar .spacer { flex: 1; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  height: 32px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); font: inherit; font-size: 13px; cursor: pointer; color: var(--ink-2);
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.chip:hover { background: var(--surface-2); }
.chip.active { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.chip .count { font-size: 11px; background: var(--neutral-soft); padding: 0 7px; border-radius: 999px; color: var(--ink-2); line-height: 18px; }
.chip.active .count { background: rgba(255, 255, 255, .2); color: inherit; }
.seg { display: inline-flex; background: var(--neutral-soft); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font: inherit; font-size: 13px; color: var(--ink-2); cursor: pointer; }
.seg button.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); font-weight: 600; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  font-weight: 600; color: var(--muted); font-size: 12px; text-align: start;
  padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--line-2); vertical-align: middle; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table tr.clickable { cursor: pointer; }
.table tfoot td { font-weight: 700; background: var(--surface-2); border-top: 1px solid var(--line); }
.table .num { text-align: end; font-variant-numeric: tabular-nums; }
.table .center { text-align: center; }
.table.compact td { padding: 8px 12px; }
.table .wrap { white-space: normal; }
.cell-main { font-weight: 600; color: var(--ink); }
.cell-sub { font-size: 12px; color: var(--muted); }
.cell-person { display: flex; align-items: center; gap: 10px; }
.table-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 14px; color: var(--muted); font-size: 12.5px; border-top: 1px solid var(--line-2); flex-wrap: wrap; }
.pager { display: flex; gap: 4px; }
.pager button { min-width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); font: inherit; font-size: 13px; cursor: pointer; }
.pager button.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.empty { padding: 44px 16px; text-align: center; color: var(--muted); }
.empty .ic { width: 36px; height: 36px; opacity: .5; margin-bottom: 8px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px;
  border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--neutral-soft); color: var(--ink-2);
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge.plain::before { display: none; }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.primary { background: var(--primary-soft); color: var(--primary-ink); }
.badge.violet { background: var(--violet-soft); color: var(--violet); }
.tag { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px; font-size: 11.5px; font-weight: 600; background: var(--neutral-soft); color: var(--ink-2); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); padding: 0 12px; overflow-x: auto; }
.tab {
  background: none; border: 0; font: inherit; padding: 12px 12px; color: var(--muted); cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab .count { font-size: 11px; background: var(--neutral-soft); padding: 0 7px; border-radius: 999px; line-height: 18px; color: var(--ink-2); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- Overlays: modal & drawer ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(8, 12, 28, .5); display: none;
  align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.overlay.open { display: flex; }
.modal {
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg);
  width: min(640px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column;
  animation: pop .18s ease-out; border: 1px solid var(--line);
}
.modal.lg { width: min(920px, 100%); }
.modal.sm { width: min(460px, 100%); }
.modal-head, .drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line-2); }
.modal-head h3, .drawer-head h3 { margin: 0; font-size: 16px; }
.modal-head p, .drawer-head p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.modal-body, .drawer-body { padding: 20px; overflow-y: auto; }
.modal-foot, .drawer-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line-2); flex-wrap: wrap; }
.modal-foot .left, .drawer-foot .left { margin-inline-end: auto; }
.overlay[data-kind="drawer"] { padding: 0; align-items: stretch; justify-content: flex-end; }
.drawer {
  width: min(560px, 100%); height: 100%; background: var(--surface); display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg); animation: slide .22s ease-out;
}
.drawer-body { flex: 1; }
@keyframes pop { from { transform: translateY(8px) scale(.98); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes slide { from { transform: translateX(-40px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Toast ---------- */
.toast-wrap { position: fixed; bottom: 20px; left: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: var(--ink); color: var(--surface); padding: 12px 16px; border-radius: 12px;
  box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 10px; font-size: 13.5px;
  animation: pop .2s ease-out; max-width: 380px;
}
.toast .ic { color: #4ADE80; }
.toast.danger .ic { color: #F87171; }
.toast.warning .ic { color: #FBBF24; }

/* ---------- Misc components ---------- */
.dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 20px; margin: 0; }
.dl.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.dl dt { font-size: 12px; color: var(--muted); }
.dl dd { margin: 2px 0 0; font-weight: 600; }
.divider { height: 1px; background: var(--line-2); margin: 16px 0; border: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12.5px; }
.tnum { font-variant-numeric: tabular-nums; }
.strong { font-weight: 700; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-primary { color: var(--primary); }
.row { display: flex; align-items: center; gap: 8px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }

.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; background: var(--info-soft); color: var(--ink-2); font-size: 13px; }
.alert .ic { color: var(--info); margin-top: 1px; }
.alert.warning { background: var(--warning-soft); }
.alert.warning .ic { color: var(--warning); }
.alert.danger { background: var(--danger-soft); }
.alert.danger .ic { color: var(--danger); }
.alert.success { background: var(--success-soft); }
.alert.success .ic { color: var(--success); }
.alert b { color: var(--ink); }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding-inline-start: 24px; padding-bottom: 16px; }
.timeline li::before { content: ''; position: absolute; inset-inline-start: 4px; top: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.timeline li::after { content: ''; position: absolute; inset-inline-start: 8px; top: 20px; bottom: 0; width: 1px; background: var(--line); }
.timeline li:last-child { padding-bottom: 0; }
.timeline li:last-child::after { display: none; }
.timeline li.success::before { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.timeline li.warning::before { background: var(--warning); box-shadow: 0 0 0 3px var(--warning-soft); }
.timeline li.danger::before { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.tl-title { font-weight: 600; font-size: 13.5px; }
.tl-meta { font-size: 12px; color: var(--muted); }

.progress { height: 8px; background: var(--neutral-soft); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: inherit; }
.progress.success > span { background: var(--success); }
.progress.warning > span { background: var(--warning); }
.progress.danger > span { background: var(--danger); }
.stackbar { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: var(--neutral-soft); gap: 2px; }
.stackbar span { display: block; height: 100%; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-inline-end: 6px; vertical-align: -1px; }

.bars { display: flex; align-items: flex-end; gap: 14px; height: 200px; padding-top: 12px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; height: 100%; justify-content: flex-end; min-width: 0; }
.bar-val { font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.bar { width: 100%; max-width: 64px; border-radius: 8px 8px 4px 4px; background: var(--primary); min-height: 4px; }
.bar-label { font-size: 12px; color: var(--muted); text-align: center; }

.steps { display: flex; align-items: center; gap: 8px; }
.step { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.step .num { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; font-size: 12px; font-weight: 700; background: var(--surface); }
.step.done { color: var(--ink-2); }
.step.done .num { background: var(--success); border-color: var(--success); color: #fff; }
.step.current { color: var(--ink); font-weight: 600; }
.step.current .num { border-color: var(--primary); color: var(--primary); }
.step-line { flex: 1; height: 2px; background: var(--line); min-width: 16px; }
.step-line.done { background: var(--success); }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line-2); }
.list > li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }

.sigpad { display: block; width: 100%; height: 170px; border: 1.5px dashed var(--line); border-radius: 12px; background: var(--surface-2); touch-action: none; cursor: crosshair; }
.doc-paper { background: #fff; color: #111827; border: 1px solid var(--line); border-radius: 12px; padding: 32px 36px; line-height: 1.9; font-size: 14px; }
.doc-paper h2 { text-align: center; margin: 0 0 4px; font-size: 18px; }
.doc-paper .sub { text-align: center; color: #6B7280; font-size: 12.5px; margin-bottom: 18px; }
.doc-paper .ph { background: #EEF2FF; color: #3730A3; padding: 0 6px; border-radius: 4px; font-weight: 600; }

.matrix th, .matrix td { text-align: center; }
.matrix th:first-child, .matrix td:first-child { text-align: start; }
.matrix tr.group td { background: var(--surface-2); font-weight: 700; font-size: 12.5px; color: var(--ink-2); }

/* Engine extras: report rows, tiles, board, week grid */
.table tr.group-row td { background: var(--surface-2); font-weight: 700; color: var(--ink-2); font-size: 12.5px; }
.table tr.total-row td { font-weight: 700; border-top: 1px solid var(--line); background: var(--surface-2); }
.table tr.row-danger td:first-child { box-shadow: inset -3px 0 0 var(--danger); }
.table tr.row-warning td:first-child { box-shadow: inset -3px 0 0 var(--warning); }
.table tr.row-success td:first-child { box-shadow: inset -3px 0 0 var(--success); }
.tile-grid { display: grid; gap: 10px; }
.tile { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--surface); box-shadow: inset -4px 0 0 var(--line); display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.tile.clickable, .board-card.clickable, .event.clickable { cursor: pointer; }
.tile.clickable:hover, .board-card.clickable:hover { border-color: var(--primary); }
.tile.success { box-shadow: inset -4px 0 0 var(--success); }
.tile.warning { box-shadow: inset -4px 0 0 var(--warning); background: var(--warning-soft); }
.tile.danger { box-shadow: inset -4px 0 0 var(--danger); background: var(--danger-soft); }
.tile.info { box-shadow: inset -4px 0 0 var(--info); }
.tile.primary { box-shadow: inset -4px 0 0 var(--primary); background: var(--primary-soft); }
.tile.violet { box-shadow: inset -4px 0 0 var(--violet); background: var(--violet-soft); }
.tile.muted { opacity: .65; }
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(240px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 4px; }
.board-col { background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px; padding: 10px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.board-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px 4px; }
.board-card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow); }
.table.week td { vertical-align: top; min-width: 120px; white-space: normal; }
.event { display: flex; flex-direction: column; gap: 2px; padding: 6px 8px; border-radius: 8px; background: var(--primary-soft); color: var(--primary-ink); font-size: 12px; margin-bottom: 4px; border-inline-start: 3px solid var(--primary); }
.event b { font-size: 12.5px; }
.event span { color: var(--ink-2); }
.event.success { background: var(--success-soft); color: var(--success); border-color: var(--success); }
.event.warning { background: var(--warning-soft); color: var(--warning); border-color: var(--warning); }
.event.danger { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.event.violet { background: var(--violet-soft); color: var(--violet); border-color: var(--violet); }
.event.info { background: var(--info-soft); color: var(--info); border-color: var(--info); }
.event.muted { background: var(--neutral-soft); color: var(--muted); border-color: var(--line); }

.kbd { font-family: ui-monospace, Consolas, monospace; font-size: 11px; padding: 1px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; color: var(--muted); background: var(--surface); }

.proto-note { font-size: 12px; color: var(--muted); text-align: center; padding: 24px 0 8px; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split, .split.wide-side { grid-template-columns: 1fr; }
  .top-search { width: 240px; }
}
@media (max-width: 900px) {
  .sidebar { position: fixed; top: 0; bottom: 0; right: 0; transform: translateX(100%); transition: transform .25s; z-index: 60; }
  body.nav-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  body.nav-open::after { content: ''; position: fixed; inset: 0; background: rgba(8, 12, 28, .45); z-index: 55; }
  .menu-btn { display: grid; }
  .top-search, .user-chip .who { display: none; }
  .topbar { padding: 0 16px; }
  .content { padding: 16px; }
  .grid-2, .grid-3, .grid-4, .form-grid, .form-grid.cols-3, .dl.cols-3 { grid-template-columns: 1fr; }
  .page-head h1 { font-size: 19px; }
  .toolbar .input-icon { max-width: none; }
  .doc-paper { padding: 20px; }
}
@media (max-width: 520px) {
  .grid-4 { grid-template-columns: 1fr; }
  .dl { grid-template-columns: 1fr; }
}

@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .content { padding: 0; max-width: none; }
  .card { box-shadow: none; }
  body { background: #fff; }
}
