/* Layout: app shell — top bar, collapsible sidebar (inline-start), content up to 1440px; drawer from inline-end. Tokens from UI_UX_DESIGN_SYSTEM.md */
:root {
  --brand-700: #163C7D; --brand-600: #1C4A98; --brand-100: #E6EDF8; --brand-50: #F3F6FC;
  --gray-brand: #727272;
  --bg: #F6F8FB; --surface: #FFFFFF; --surface-2: #F9FAFC; --border: #E3E8EF; --border-strong: #CBD3DF;
  --text: #1F2937; --text-muted: #5B6472; --on-brand: #FFFFFF;
  --success: #15803D; --success-bg: #E8F5EC; --warning: #B45309; --warning-bg: #FDF3E4;
  --danger: #B91C1C; --danger-bg: #FCEBEB; --info: #1D4ED8; --info-bg: #EAF0FD;
  --neutral: #4B5563; --neutral-bg: #F1F3F6;
  --c1: #1C4A98; --c2: #0F9D8A; --c3: #E0A100; --c4: #C2410C; --c5: #7C3AED; --c6: #64748B;
  --shadow: 0 8px 24px rgba(15, 23, 42, .10);
  --font: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, monospace;
  --r-sm: 6px; --r: 10px;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --brand-700: #9DBBF2; --brand-600: #7EA6EE; --brand-100: #1C2C4B; --brand-50: #172238;
  --bg: #0E1522; --surface: #151E2D; --surface-2: #192335; --border: #263349; --border-strong: #34445E;
  --text: #E6EBF2; --text-muted: #9EAABB; --on-brand: #0E1522;
  --success: #4ADE80; --success-bg: #12301F; --warning: #F5B454; --warning-bg: #352812;
  --danger: #F87171; --danger-bg: #3A1717; --info: #8FB0FF; --info-bg: #17254A;
  --neutral: #B4BECC; --neutral-bg: #222C3D;
  --c1: #7EA6EE; --c2: #2DD4BF; --c3: #FACC15; --c4: #FB923C; --c5: #A78BFA; --c6: #94A3B8;
  --shadow: 0 8px 24px rgba(0, 0, 0, .45); color-scheme: dark; } }
:root[data-theme="dark"] {
  --brand-700: #9DBBF2; --brand-600: #7EA6EE; --brand-100: #1C2C4B; --brand-50: #172238;
  --bg: #0E1522; --surface: #151E2D; --surface-2: #192335; --border: #263349; --border-strong: #34445E;
  --text: #E6EBF2; --text-muted: #9EAABB; --on-brand: #0E1522;
  --success: #4ADE80; --success-bg: #12301F; --warning: #F5B454; --warning-bg: #352812;
  --danger: #F87171; --danger-bg: #3A1717; --info: #8FB0FF; --info-bg: #17254A;
  --neutral: #B4BECC; --neutral-bg: #222C3D;
  --c1: #7EA6EE; --c2: #2DD4BF; --c3: #FACC15; --c4: #FB923C; --c5: #A78BFA; --c6: #94A3B8;
  --shadow: 0 8px 24px rgba(0, 0, 0, .45); color-scheme: dark; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body { background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px; line-height: 1.57; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand-600); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--brand-600); outline-offset: 2px; }
.num, td.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
h1, h2, h3 { margin: 0; text-wrap: balance; }
h1 { font-size: 22px; line-height: 30px; font-weight: 600; }
h2 { font-size: 17px; line-height: 26px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* Shell */
.app { display: grid; grid-template-columns: 248px minmax(0, 1fr); grid-template-rows: 56px minmax(0, 1fr); height: 100%; }
.app.collapsed { grid-template-columns: 64px minmax(0, 1fr); }
.topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding-inline: 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: relative; z-index: 20; }
.topbar .logo { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar .logo img { height: 30px; width: auto; }
.logo-chip { background: #fff; border-radius: 6px; padding: 2px 4px; display: inline-flex; }
.facility-switch { border: 1px solid var(--border); background: var(--surface); border-radius: var(--r-sm); padding: 5px 10px; max-width: 220px; }
.search-btn { flex: 1; max-width: 420px; display: flex; align-items: center; gap: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-muted); border-radius: var(--r-sm); padding: 6px 10px; cursor: pointer; text-align: start; }
.search-btn kbd { margin-inline-start: auto; }
kbd { font-family: var(--mono); font-size: 11px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; background: var(--surface); color: var(--text-muted); }
.top-actions { display: flex; align-items: center; gap: 6px; margin-inline-start: auto; }
.icon-btn { position: relative; display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--r-sm); border: 1px solid transparent; background: transparent; cursor: pointer; color: var(--text-muted); }
.icon-btn:hover { background: var(--brand-50); color: var(--text); }
.icon-btn .dot { position: absolute; top: 5px; inset-inline-end: 5px; min-width: 16px; height: 16px; border-radius: 8px; background: var(--danger); color: #fff; font-size: 10px; display: grid; place-items: center; padding: 0 4px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-100); color: var(--brand-700); display: grid; place-items: center; font-weight: 600; font-size: 12px; flex: none; }
.user-btn { display: flex; align-items: center; gap: 8px; border: 0; background: transparent; cursor: pointer; padding: 4px 6px; border-radius: var(--r-sm); text-align: start; }
.user-btn:hover { background: var(--brand-50); }
.user-btn .who { line-height: 1.2; }
.user-btn .who b { display: block; font-size: 13px; }
.user-btn .who span { font-size: 11.5px; color: var(--text-muted); }

.sidebar { background: var(--surface); border-inline-end: 1px solid var(--border); overflow-y: auto; padding: 12px 8px 24px; }
.nav-group { margin-bottom: 10px; }
.nav-group > .nav-title { font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--text-muted); padding: 6px 10px; font-weight: 600; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: transparent; padding: 7px 10px; border-radius: var(--r-sm); cursor: pointer; color: var(--text); text-align: start; }
.nav-item:hover { background: var(--brand-50); }
.nav-item.active { background: var(--brand-100); color: var(--brand-700); font-weight: 600; }
.nav-item .count { margin-inline-start: auto; font-size: 11px; background: var(--neutral-bg); color: var(--neutral); border-radius: 10px; padding: 0 7px; }
.app.collapsed .nav-item span.lbl, .app.collapsed .nav-title, .app.collapsed .nav-item .count { display: none; }
.app.collapsed .nav-item { justify-content: center; }
.main { overflow-y: auto; min-width: 0; }
.page { max-width: 1440px; margin: 0 auto; padding: 20px 24px 64px; display: flex; flex-direction: column; gap: 16px; }

.page-head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.page-head .titles { min-width: 0; flex: 1 1 320px; }
.crumbs { font-size: 12px; color: var(--text-muted); margin-bottom: 2px; }
.crumbs a { color: var(--text-muted); }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: var(--r-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap; font-weight: 500; }
.btn:hover { background: var(--surface-2); border-color: var(--brand-600); }
.btn.primary { background: var(--brand-600); border-color: var(--brand-600); color: var(--on-brand); }
.btn.primary:hover { background: var(--brand-700); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.danger.solid { background: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
:where(svg:not([width]):not(.chart)) { width: 18px; height: 18px; flex: none; }
.btn svg, .icon-btn svg, .nav-item svg { width: 18px; height: 18px; flex: none; }
.link-btn { border: 0; background: transparent; color: var(--brand-600); cursor: pointer; padding: 0; }
.link-btn:hover { text-decoration: underline; }

/* Cards & grids */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 16px 18px; min-width: 0; }
.card > header { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.card > header h2 { font-size: 15px; }
.card > header .more { margin-inline-start: auto; font-size: 13px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 14px 16px; cursor: pointer; text-align: start; display: flex; flex-direction: column; gap: 2px; }
.tile:hover { border-color: var(--brand-600); }
.tile .lbl { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.tile .val { font-size: 26px; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; }
.tile .sub { font-size: 12px; color: var(--text-muted); }
.tile.bad .val { color: var(--danger); }
.tile.warn .val { color: var(--warning); }
.tile.good .val { color: var(--success); }

/* Chips */
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 500; line-height: 20px; padding: 0 8px; border-radius: 999px; white-space: nowrap; }
.chip.success { color: var(--success); background: var(--success-bg); }
.chip.warning { color: var(--warning); background: var(--warning-bg); }
.chip.danger { color: var(--danger); background: var(--danger-bg); }
.chip.info { color: var(--info); background: var(--info-bg); }
.chip.neutral { color: var(--neutral); background: var(--neutral-bg); }
.chip.brand { color: var(--brand-700); background: var(--brand-100); }
.chip svg { width: 13px; height: 13px; }
.flags { display: inline-flex; gap: 4px; }
.flag { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; background: var(--neutral-bg); color: var(--neutral); }
.flag.danger { background: var(--danger-bg); color: var(--danger); }
.flag svg { width: 13px; height: 13px; }

/* Filter bar & table */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar .search { flex: 1 1 240px; display: flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface); padding: 0 10px; height: 36px; max-width: 360px; }
.toolbar .search input { border: 0; outline: 0; background: transparent; width: 100%; }
.toolbar select { height: 36px; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface); padding: 0 8px; }
.views { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.views button, .views a { border: 0; background: transparent; padding: 8px 12px; cursor: pointer; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.views button.on, .views a.on { color: var(--brand-700); border-bottom-color: var(--brand-600); font-weight: 600; }
.views button .n, .views a .n { font-size: 11px; background: var(--neutral-bg); border-radius: 9px; padding: 0 6px; margin-inline-start: 4px; color: var(--neutral); }
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); overflow-x: auto; }
table.dt { width: 100%; border-collapse: collapse; min-width: 640px; }
table.dt th { position: sticky; top: 0; background: var(--surface-2); text-align: start; font-size: 12px; font-weight: 600; color: var(--text-muted); padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.dt td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.dt tbody tr { cursor: pointer; }
table.dt tbody tr:hover { background: var(--brand-50); }
table.dt tbody tr.sel { background: var(--brand-100); }
table.dt tr:last-child td { border-bottom: 0; }
table.dt td.wrap { white-space: normal; max-width: 320px; }
table.dt td.cb, table.dt th.cb { width: 36px; }
.table-foot { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--text-muted); flex-wrap: wrap; }
.table-foot .pager { margin-inline-start: auto; display: flex; gap: 4px; }
.bulkbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--brand-100); border-radius: var(--r-sm); flex-wrap: wrap; }
.empty { text-align: center; padding: 40px 16px; color: var(--text-muted); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.empty svg { width: 36px; height: 36px; }

/* Forms */
.form { display: flex; flex-direction: column; gap: 18px; }
.fsec { border: 1px solid var(--border); border-radius: var(--r); padding: 14px 16px; background: var(--surface); }
.fsec > h3 { margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.fgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text); }
.field label .req { color: var(--danger); }
.field .hint { font-size: 11.5px; color: var(--text-muted); }
.field input, .field select, .field textarea { border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface); padding: 7px 10px; min-height: 36px; width: 100%; }
.field textarea { min-height: 84px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--brand-100); border-color: var(--brand-600); }
.field.err input, .field.err select, .field.err textarea { border-color: var(--danger); }
.field .errmsg { font-size: 11.5px; color: var(--danger); }
.field input[readonly] { background: var(--surface-2); color: var(--text-muted); }
.check { display: flex; gap: 8px; align-items: center; }
.err-summary { border: 1px solid var(--danger); background: var(--danger-bg); color: var(--danger); border-radius: var(--r-sm); padding: 10px 12px; font-size: 13px; }
.form-foot { position: sticky; bottom: 0; display: flex; gap: 8px; justify-content: flex-end; padding: 12px 0 0; background: linear-gradient(transparent, var(--bg) 30%); }
.radio-row { display: flex; gap: 8px; flex-wrap: wrap; }
.radio-row label { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border-strong); border-radius: var(--r-sm); padding: 6px 10px; cursor: pointer; font-weight: 500; font-size: 13px; }
.radio-row input { width: auto; min-height: 0; }
.radio-row label:has(input:checked) { border-color: var(--brand-600); background: var(--brand-100); color: var(--brand-700); }

/* Detail */
.detail-head { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 16px 18px; }
.detail-head .ph { width: 72px; height: 72px; border-radius: var(--r); background: var(--brand-50); display: grid; place-items: center; color: var(--brand-600); flex: none; }
.detail-head .ph svg { width: 34px; height: 34px; }
.detail-head .meta { flex: 1 1 300px; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.detail-head .facts { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; color: var(--text-muted); }
.detail-head .facts b { color: var(--text); font-weight: 600; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs button, .tabs a { border: 0; background: transparent; padding: 9px 14px; cursor: pointer; white-space: nowrap; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on, .tabs a.on { color: var(--brand-700); border-bottom-color: var(--brand-600); font-weight: 600; }
.kv { display: grid; grid-template-columns: minmax(120px, 38%) minmax(0, 1fr); gap: 8px 14px; font-size: 13.5px; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.timeline li { display: grid; grid-template-columns: 26px minmax(0, 1fr); gap: 8px; font-size: 13px; }
.timeline .ti { width: 26px; height: 26px; border-radius: 50%; background: var(--brand-50); color: var(--brand-600); display: grid; place-items: center; }
.timeline .ti svg { width: 14px; height: 14px; }
.timeline time { display: block; font-size: 11.5px; color: var(--text-muted); }

/* Progress / stepper */
.stepper { display: flex; gap: 0; flex-wrap: wrap; }
.stepper .st { flex: 1 1 110px; display: flex; flex-direction: column; gap: 4px; padding: 8px 10px; border-top: 3px solid var(--border); font-size: 12.5px; color: var(--text-muted); }
.stepper .st.done { border-top-color: var(--success); color: var(--text); }
.stepper .st.cur { border-top-color: var(--brand-600); color: var(--brand-700); font-weight: 600; }
.stepper .st b { font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.bar { height: 8px; border-radius: 4px; background: var(--neutral-bg); overflow: hidden; min-width: 60px; }
.bar > span { display: block; height: 100%; background: var(--brand-600); border-radius: 4px; }
.bar.danger > span { background: var(--danger); }
.bar.warning > span { background: var(--warning); }
.bar.success > span { background: var(--success); }
.conf { display: flex; align-items: center; gap: 8px; }
.conf .bar { width: 90px; }

/* Kanban */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(230px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 6px; }
.kcol { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); padding: 10px; display: flex; flex-direction: column; gap: 8px; min-height: 200px; }
.kcol h3 { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.kcard { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 10px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.kcard:hover { border-color: var(--brand-600); }
.kcard .row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* Calendar */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal .dow { font-size: 11.5px; color: var(--text-muted); text-align: center; font-weight: 600; }
.cal .day { min-height: 84px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 6px; font-size: 12px; display: flex; flex-direction: column; gap: 3px; cursor: pointer; }
.cal .day.out { opacity: .4; }
.cal .day.today { border-color: var(--brand-600); }
.cal .day .d { font-weight: 600; font-variant-numeric: tabular-nums; }
.cal .pill { border-radius: 4px; padding: 1px 5px; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Drawer, modal, toast, palette */
.scrim { position: fixed; inset: 0; background: rgba(15, 23, 42, .38); z-index: 40; }
.drawer { position: fixed; top: 0; bottom: 0; inset-inline-end: 0; width: min(480px, 100vw); background: var(--surface); border-inline-start: 1px solid var(--border); box-shadow: var(--shadow); z-index: 41; display: flex; flex-direction: column; animation: slidein .15s ease-out; }
[dir="rtl"] .drawer { animation-name: slideinr; }
@keyframes slidein { from { transform: translateX(24px); opacity: .5; } }
@keyframes slideinr { from { transform: translateX(-24px); opacity: .5; } }
.drawer header { display: flex; align-items: center; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.drawer header h2 { flex: 1; min-width: 0; }
.drawer .body { padding: 16px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.drawer footer { margin-top: auto; padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; flex-wrap: wrap; }
.modal { position: fixed; z-index: 42; inset: 0; display: grid; place-items: center; padding: 16px; pointer-events: none; }
.modal .box { pointer-events: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow); width: min(560px, 100%); max-height: 90vh; overflow-y: auto; }
.modal .box.wide { width: min(860px, 100%); }
.modal .box header { display: flex; align-items: center; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal .box header h2 { flex: 1; }
.modal .box .body { padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; }
.modal .box footer { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.toasts { position: fixed; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); inset-inline-end: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--text); color: var(--surface); padding: 10px 14px; border-radius: var(--r-sm); box-shadow: var(--shadow); font-size: 13px; max-width: 360px; display: flex; gap: 10px; align-items: center; }
.toast.err { background: var(--danger); color: #fff; }
.palette { position: fixed; z-index: 50; top: 10vh; inset-inline: 0; margin: 0 auto; width: min(620px, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.palette input { width: 100%; border: 0; border-bottom: 1px solid var(--border); padding: 14px 16px; font-size: 15px; background: transparent; outline: 0; }
.palette .res { max-height: 50vh; overflow-y: auto; padding: 6px; }
.palette .grp { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); padding: 8px 10px 4px; font-weight: 600; }
.palette .it { display: flex; gap: 10px; align-items: center; width: 100%; border: 0; background: transparent; text-align: start; padding: 8px 10px; border-radius: var(--r-sm); cursor: pointer; }
.palette .it:hover, .palette .it.on { background: var(--brand-100); }
.menu { position: absolute; z-index: 30; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm); box-shadow: var(--shadow); min-width: 220px; padding: 6px; }
.menu button { display: flex; width: 100%; gap: 8px; align-items: center; border: 0; background: transparent; padding: 8px 10px; border-radius: 6px; cursor: pointer; text-align: start; }
.menu button:hover { background: var(--brand-50); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.notif-panel { position: absolute; top: 52px; inset-inline-end: 60px; width: min(380px, calc(100vw - 32px)); z-index: 30; }

/* Banners & AI */
.banner { display: flex; gap: 10px; align-items: center; padding: 10px 14px; border-radius: var(--r-sm); border: 1px solid; font-size: 13.5px; flex-wrap: wrap; }
.banner.danger { border-color: var(--danger); background: var(--danger-bg); color: var(--danger); }
.banner.warning { border-color: var(--warning); background: var(--warning-bg); color: var(--warning); }
.banner.info { border-color: var(--info); background: var(--info-bg); color: var(--info); }
.banner .grow { flex: 1; min-width: 200px; }
.banner svg { width: 18px; height: 18px; flex: none; }
.ai { border: 1.5px dashed var(--brand-600); border-radius: var(--r); padding: 12px 14px; background: var(--brand-50); }
.ai .ai-tag { font-size: 12px; font-weight: 600; color: var(--brand-700); display: flex; gap: 6px; align-items: center; margin-bottom: 8px; }
.sim { font-size: 11px; border: 1px dashed var(--warning); color: var(--warning); border-radius: 4px; padding: 0 6px; }

/* Login */
.login { min-height: 100%; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); }
.login .side { background: var(--brand-600); color: #fff; padding: 40px; display: flex; flex-direction: column; gap: 20px; justify-content: space-between; }
.login .side h1 { font-size: 30px; line-height: 1.3; max-width: 16ch; }
.login .side p { opacity: .9; max-width: 42ch; }
.login .side ul { margin: 0; padding-inline-start: 18px; opacity: .92; display: grid; gap: 6px; }
.login .pane { padding: 32px; display: flex; flex-direction: column; gap: 18px; overflow-y: auto; }
.role-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.role-card { text-align: start; border: 1px solid var(--border); background: var(--surface); border-radius: var(--r); padding: 12px 14px; cursor: pointer; display: flex; gap: 10px; align-items: flex-start; }
.role-card:hover { border-color: var(--brand-600); background: var(--brand-50); }
.role-card .ws { font-size: 11px; font-weight: 600; color: var(--brand-700); background: var(--brand-100); border-radius: 4px; padding: 0 6px; }
.role-card b { display: block; }
.role-card span.d { font-size: 12px; color: var(--text-muted); }

/* Signature & OTP */
.sigpad { border: 1px dashed var(--border-strong); border-radius: var(--r-sm); background: var(--surface-2); width: 100%; height: 150px; touch-action: none; cursor: crosshair; display: block; }
.sig-slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.sig-slot { border: 1px solid var(--border); border-radius: var(--r-sm); padding: 10px; display: flex; flex-direction: column; gap: 4px; min-height: 96px; }
.sig-slot.done { border-color: var(--success); }
.sig-slot .sigimg { height: 40px; }
.otp { display: flex; gap: 6px; direction: ltr; }
.otp input { width: 44px; height: 48px; text-align: center; font-size: 20px; border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface); }

/* Charts */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--text-muted); font-size: 11px; font-family: var(--font); }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--text-muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-inline-end: 4px; vertical-align: -1px; }
.hbars { display: flex; flex-direction: column; gap: 8px; }
.hbar { display: grid; grid-template-columns: minmax(90px, 34%) minmax(0, 1fr) 44px; gap: 8px; align-items: center; font-size: 12.5px; }
.hbar .bar { height: 10px; }
.hbar .v { text-align: end; font-variant-numeric: tabular-nums; }

/* Mobile phone frame + public */
.phone { width: 390px; max-width: 100%; margin: 0 auto; border: 10px solid var(--text); border-radius: 36px; overflow: hidden; background: var(--bg); box-shadow: var(--shadow); }
.phone .scr { height: 720px; overflow-y: auto; display: flex; flex-direction: column; }
.phone .ptop { background: var(--brand-600); color: #fff; padding: 14px 16px; display: flex; gap: 10px; align-items: center; }
.phone .pbody { padding: 14px; display: flex; flex-direction: column; gap: 12px; flex: 1; }
.phone .pnav { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--border); background: var(--surface); }
.phone .pnav button { border: 0; background: transparent; padding: 8px 0 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; color: var(--text-muted); cursor: pointer; }
.phone .pnav button.on { color: var(--brand-600); font-weight: 600; }
.phone .pnav svg { width: 20px; height: 20px; }
.jobcard { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.big-btn { height: 48px; font-size: 15px; justify-content: center; width: 100%; }

/* Misc */
.split { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.list-plain { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; }
.list-plain li { padding: 9px 0; border-bottom: 1px solid var(--border); display: flex; gap: 10px; align-items: center; font-size: 13.5px; }
.list-plain li:last-child { border-bottom: 0; }
.qr { width: 96px; height: 96px; }
.label-sheet { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.label { border: 1px dashed var(--border-strong); border-radius: 6px; padding: 8px; display: flex; gap: 8px; align-items: center; background: #fff; color: #111; font-size: 11px; }
.label b { font-size: 12px; }
.code-strip { font-family: var(--mono); font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; overflow-x: auto; }
.help { font-size: 12.5px; color: var(--text-muted); }
.demo-ribbon { font-size: 11px; background: var(--warning-bg); color: var(--warning); border: 1px solid var(--warning); border-radius: 4px; padding: 0 6px; white-space: nowrap; }

@media (max-width: 1100px) { .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g-main { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .app.collapsed { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; top: 56px; bottom: 0; inset-inline-start: 0; width: 260px; z-index: 35; display: none; box-shadow: var(--shadow); }
  .app.navopen .sidebar { display: block; }
  .g2, .g3 { grid-template-columns: minmax(0, 1fr); }
  .fgrid { grid-template-columns: minmax(0, 1fr); }
  .login { grid-template-columns: minmax(0, 1fr); }
  .login .side { padding: 24px 16px; }
  .login .pane { padding: 20px 16px; }
  .page { padding: 16px 16px 64px; }
  .search-btn span.t, .search-btn kbd, .facility-switch, .user-btn .who { display: none; }
  .label-sheet { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .topbar { gap: 6px; padding-inline: 10px; }
  .demo-ribbon, .user-btn > svg, .top-actions [data-act="theme"] { display: none; }
  .top-actions { gap: 2px; }
  .top-actions .btn.primary.sm { font-size: 0; padding: 6px 8px; gap: 0; }
  .search-btn { flex: 0 0 auto; }
  .page-head { flex-direction: column; align-items: stretch; }
  .page-head .titles, .page-head .actions { flex: none; }
  .page-head .actions { flex-wrap: wrap; }
}
.phone .ptop { color: var(--on-brand); }

/* ---------- Server-rendered app additions ---------- */
a.nav-item, a.tile, a.btn, a.it { text-decoration: none; color: inherit; }
a.btn.primary { color: var(--on-brand); }
a.nav-item.active { color: var(--brand-700); }
.pre { white-space: pre-line; }
.fgrid.tight { gap: 8px; }
.req { color: var(--danger); }
.hidden { display: none !important; }
.flashes { display: flex; flex-direction: column; gap: 8px; }
.inline-form { display: inline; }
.actions form { display: inline-flex; }
.right { margin-inline-start: auto; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
dialog.dlg { border: 1px solid var(--border); border-radius: var(--r); padding: 0; width: min(560px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
dialog.dlg.wide { width: min(860px, calc(100vw - 32px)); }
dialog.dlg::backdrop { background: rgba(15, 23, 42, .38); }
dialog.dlg > form > header, dialog.dlg > header { display: flex; align-items: center; gap: 8px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
dialog.dlg header h2 { flex: 1; font-size: 16px; }
dialog.dlg .body { padding: 16px 18px; display: flex; flex-direction: column; gap: 14px; max-height: 70vh; overflow-y: auto; }
dialog.dlg footer { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
details.menu-wrap { position: relative; }
details.menu-wrap > summary { list-style: none; cursor: pointer; }
details.menu-wrap > summary::-webkit-details-marker { display: none; }
details.menu-wrap > .menu { position: absolute; top: calc(100% + 6px); inset-inline-end: 0; z-index: 30; }
.menu { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow); min-width: 220px; padding: 6px; display: flex; flex-direction: column; }
.menu a, .menu button { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: var(--r-sm); border: 0; background: transparent; color: var(--text); text-align: start; cursor: pointer; width: 100%; }
.menu a:hover, .menu button:hover { background: var(--brand-50); text-decoration: none; }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 0; }
.typeahead { position: relative; }
.ta-list { position: absolute; inset-inline: 0; top: 100%; z-index: 20; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm); box-shadow: var(--shadow); max-height: 260px; overflow-y: auto; display: none; }
.ta-list.open { display: block; }
.ta-list button { display: block; width: 100%; text-align: start; padding: 8px 10px; border: 0; background: transparent; cursor: pointer; }
.ta-list button:hover, .ta-list button.on { background: var(--brand-50); }
.palette-dlg { width: min(640px, calc(100vw - 32px)); }
.palette-dlg input { width: 100%; border: 0; border-bottom: 1px solid var(--border); padding: 14px 16px; font-size: 15px; background: var(--surface); outline: none; }
.palette-dlg .res { max-height: 60vh; overflow-y: auto; padding: 6px; }
.palette-dlg .grp { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; padding: 8px 10px 4px; }
.palette-dlg .it { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: var(--r-sm); }
.palette-dlg .it:hover, .palette-dlg .it.on { background: var(--brand-50); }
.sim { white-space: nowrap; }
.sigpad-wrap { display: flex; flex-direction: column; gap: 6px; }
.tabs a { text-decoration: none; }
.checklist td input[type=text] { max-width: 120px; }
.qr-box svg { background: #fff; border-radius: 6px; }
.board-col-drop { outline: 2px dashed var(--brand-600); outline-offset: -4px; }
.public-wrap { max-width: 520px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.public-head { background: var(--brand-600); color: var(--on-brand); padding: 14px 16px; display: flex; gap: 10px; align-items: center; border-radius: var(--r); }
.public-head img { height: 28px; background: #fff; border-radius: 6px; padding: 2px 6px; }
.scan-video { width: 100%; max-height: 50vh; background: #000; border-radius: var(--r); }
.styleguide-swatch { width: 100%; height: 48px; border-radius: var(--r-sm); border: 1px solid var(--border); }
@media (max-width: 860px) {
  .app .sidebar { position: fixed; top: 56px; bottom: 0; inset-inline-start: 0; width: 260px; z-index: 35; display: none; box-shadow: var(--shadow); }
  .app.navopen .sidebar { display: block; }
}
/* Print (A4) */
@media print {
  .topbar, .sidebar, .page-head .actions, .no-print, .toasts, .flashes { display: none !important; }
  .app { display: block; }
  body { background: #fff; color: #000; }
  .card, .table-wrap { border-color: #999; break-inside: avoid; }
  @page { size: A4; margin: 14mm; }
}
.print-doc { max-width: 800px; margin: 0 auto; background: #fff; color: #111; padding: 24px; font-size: 12.5px; }
.print-doc table { width: 100%; border-collapse: collapse; }
.print-doc td, .print-doc th { border-bottom: 1px solid #ddd; padding: 5px 6px; text-align: start; vertical-align: top; }
.print-doc th { background: #f3f5f8; font-weight: 600; }
.print-doc .ph { display: flex; justify-content: space-between; align-items: center; border-bottom: 2px solid #1C4A98; padding-bottom: 8px; margin-bottom: 12px; }
.print-doc .ph img { height: 34px; }
.print-doc h2 { font-size: 15px; margin: 14px 0 6px; }
.print-doc .sigs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 18px; }
.print-doc .sigs div { border-top: 1px solid #333; padding-top: 4px; min-height: 70px; }
.print-doc .sigs img { max-height: 40px; }
.print-bar { max-width: 800px; margin: 12px auto; display: flex; gap: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.sr-only:focus { position: fixed; top: 8px; inset-inline-start: 8px; width: auto; height: auto; clip: auto; background: var(--surface); padding: 8px 12px; z-index: 99; border-radius: var(--r-sm); }
.main > .page:first-child { padding-bottom: 0; }
.main > .page:first-child:empty { display: none; }
.views a, .tabs a { text-decoration: none !important; display: inline-block; }
.dt td, .kv dd, .kcard, .timeline li div, .jobcard, .banner .grow, .detail-head .facts span { unicode-bidi: plaintext; }
@media (max-width: 600px) {
  .topbar { gap: 6px; padding-inline: 10px; }
  .topbar .tenant-name, .topbar .demo-ribbon, .topbar [data-theme-toggle], .topbar .lang-btn { display: none; }
  .topbar .top-actions { gap: 4px; margin-inline-start: auto; }
  .topbar .user-btn .who { display: none; }
}
@media (max-width: 600px) { .phone { border: 0; border-radius: 0; width: 100%; box-shadow: none; } .phone .scr { height: auto; min-height: 70vh; } }
/* Workflow designer */
.wf-chain { display: flex; flex-wrap: wrap; align-items: stretch; gap: 8px; }
.wf-node { flex: 1 1 170px; max-width: 240px; min-width: 0; display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); }
.wf-node.fixed { background: var(--surface-2); border-style: dashed; justify-content: center; }
.wf-node.off { opacity: .45; border-style: dotted; }
.wf-node .ic { width: 14px; height: 14px; vertical-align: -2px; margin-inline-end: 3px; }
.wf-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.wf-arrow { display: flex; align-items: center; color: var(--text-muted); }
[dir="rtl"] .wf-arrow .ic { transform: scaleX(-1); }
.wf-step { border: 1px solid var(--border); }
.wf-step legend { width: 100%; display: flex; gap: 8px; align-items: center; padding: 0; }
.wf-step h4 { font-size: 12.5px; margin: 14px 0 6px; color: var(--text-muted); }
.wf-num { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--brand-600); color: var(--on-brand); font-size: 12px; font-weight: 600; }
.wf-checks { display: flex; flex-wrap: wrap; gap: 4px 14px; }
.wf-cond { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.wf-cond select[multiple] { width: 100%; }
[hidden] { display: none !important; }
.wf-opts { align-self: end; padding-bottom: 8px; display: flex; flex-wrap: wrap; gap: 6px 16px; }
.wf-step .check { font-weight: 400; }
.wf-step .check input[type=checkbox] { width: auto; height: auto; margin: 0; }
