/*
 * Josoor design system — components. RTL-first (logical properties only, so the same
 * rules serve LTR). Reads tokens.css; no colour or size literals below except 0/1px.
 */
*, *::before, *::after { box-sizing: border-box; }
body.ds {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: var(--fs-base); line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
.ds :focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-sm); }
.ds .icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none;
  stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

/* ── Shell: sidebar (inline-start = right in RTL) + top bar + content ─────────── */
.ds-shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }
.ds-sidebar {
  background: var(--surface); border-inline-end: 1px solid var(--border);
  position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column;
}
.ds-brand { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5);
  height: var(--topbar-h); border-bottom: 1px solid var(--border); }
.ds-brand-mark { width: 36px; height: 36px; border-radius: var(--radius); background: var(--brand);
  color: var(--brand-ink); display: grid; place-items: center; font-weight: var(--fw-bold); }
.ds-brand-name { font-weight: var(--fw-bold); font-size: var(--fs-base); line-height: 1.2; }
.ds-brand-sub { font-size: var(--fs-xs); color: var(--text-3); }
.ds-nav { padding: var(--sp-3); display: flex; flex-direction: column; gap: 2px; }
.ds-nav-group { font-size: var(--fs-xs); color: var(--text-3); font-weight: var(--fw-semibold);
  padding: var(--sp-4) var(--sp-3) var(--sp-1); }
.ds-nav a { display: flex; align-items: center; gap: var(--sp-3); padding: 9px var(--sp-3);
  border-radius: var(--radius); color: var(--text-2); text-decoration: none;
  font-size: var(--fs-md); font-weight: var(--fw-medium); }
.ds-nav a:hover { background: var(--surface-2); color: var(--text); }
.ds-nav a[aria-current="page"] { background: var(--brand); color: var(--brand-ink); }
.ds-nav .ds-count { margin-inline-start: auto; font-size: var(--fs-xs); background: var(--warn-soft);
  color: var(--warn); border-radius: var(--radius-pill); padding: 0 8px; font-weight: var(--fw-semibold); }
.ds-nav a[aria-current="page"] .ds-count { background: rgba(255,255,255,.2); color: var(--brand-ink); }

.ds-main { min-width: 0; display: flex; flex-direction: column; }
.ds-topbar { height: var(--topbar-h); background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: var(--sp-3); padding: 0 var(--sp-6); position: sticky; top: 0; z-index: 5; }
.ds-topbar .spacer { flex: 1; }
.ds-context { display: inline-flex; align-items: center; gap: var(--sp-2); padding: 6px var(--sp-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface);
  font: inherit; font-size: var(--fs-sm); color: var(--text-2); cursor: pointer; }
.ds-context .ds-pill { margin: 0; }
.ds-iconbtn { width: 38px; height: 38px; display: grid; place-items: center; border-radius: var(--radius);
  border: 0; background: transparent; color: var(--text-2); cursor: pointer; position: relative; }
.ds-iconbtn:hover { background: var(--surface-2); color: var(--text); }
.ds-iconbtn .dot { position: absolute; top: 8px; inset-inline-end: 9px; width: 8px; height: 8px;
  border-radius: 50%; background: var(--bad); border: 2px solid var(--surface); }
.ds-user { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); color: var(--text-2); }
.ds-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; font-weight: var(--fw-semibold); font-size: var(--fs-sm); flex: none; }
.ds-menu-toggle { display: none; }

.ds-content { padding: var(--sp-8) var(--sp-8) var(--sp-8); max-width: 1320px; width: 100%; }
.ds-pagehead { display: flex; align-items: flex-end; gap: var(--sp-4); margin-bottom: var(--sp-6); flex-wrap: wrap; }
.ds-pagehead h1 { margin: 0; font-size: var(--fs-2xl); font-weight: var(--fw-bold); line-height: 1.3; }
.ds-pagehead p { margin: var(--sp-1) 0 0; color: var(--text-2); font-size: var(--fs-md); }
.ds-pagehead .actions { margin-inline-start: auto; display: flex; gap: var(--sp-2); flex-wrap: wrap; }

/* ── Cards, stats ──────────────────────────────────────────────────────────── */
.ds-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm); }
.ds-card-pad { padding: var(--sp-5); }
/* بطاقة برأس (.ds-tablehead) ثم محتوى حرّ — فقرات ونماذج وأشرطة أدوات ونتائج يرسمها السكربت. كل ما ليس رأسًا ولا جدولًا
   يأخذ هامش البطاقة، والجداول تبقى بعرض البطاقة. حاوية النتائج (.ds-flow-out) لا تأخذ الهامش بنفسها بل أبناؤها، فيبقى
   الجدول داخلها بعرضه والفقرة بجانبه بهامشها. */
.ds-card-flow > :not(.ds-tablehead, .ds-table-wrap, .ds-pager, .ds-flow-out, table, dialog),
.ds-card-flow > .ds-flow-out > :not(.ds-table-wrap, table, dialog) { margin-inline: var(--sp-5); }
.ds-card-flow > .ds-tablehead + :not(.ds-table-wrap, .ds-flow-out, table) { margin-block-start: var(--sp-4); }
.ds-card-flow > .ds-tablehead + .ds-flow-out > :first-child:not(.ds-table-wrap, table) { margin-block-start: var(--sp-4); }
.ds-card-flow > :is(p, .ds-note) + :is(form, div):not(.ds-flow-out, .ds-table-wrap),
.ds-card-flow > :not(.ds-tablehead) + .ds-flow-out > :is(.ds-table-wrap, table):first-child { margin-block-start: var(--sp-3); }
.ds-card-flow + .ds-card, .ds-card + .ds-card-flow { margin-block-start: var(--sp-4); }
.ds-card-flow:not(:has(> .ds-tablehead)) { padding-block-start: var(--sp-5); }
.ds-card-flow { padding-block-end: var(--sp-5); }
.ds-card-flow:has(> .ds-table-wrap:last-child, > table:last-child, > .ds-pager:last-child,
  > .ds-flow-out:last-child > .ds-table-wrap:last-child, > .ds-flow-out:last-child > table:last-child) { padding-block-end: 0; }
.ds-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-4); margin-bottom: var(--sp-6); }
@media (max-width: 1100px) { .ds-stats { grid-template-columns: repeat(2, 1fr); } }
.ds-stat { padding: var(--sp-4) var(--sp-5); display: flex; flex-direction: column; gap: 2px; }
.ds-stat .label { font-size: var(--fs-sm); color: var(--text-2); display: flex; align-items: center; gap: var(--sp-2); }
.ds-stat .value { font-size: var(--fs-xl); font-weight: var(--fw-bold); font-variant-numeric: tabular-nums; }
.ds-stat .hint { font-size: var(--fs-xs); color: var(--text-3); }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.ds-btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: 40px; padding: 0 var(--sp-4); border-radius: var(--radius); border: 1px solid transparent;
  font: inherit; font-size: var(--fs-md); font-weight: var(--fw-semibold); cursor: pointer; white-space: nowrap; }
.ds-btn-primary { background: var(--brand); color: var(--brand-ink); }
.ds-btn-primary:hover { background: var(--brand-hover); }
.ds-btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.ds-btn-secondary:hover { background: var(--surface-2); }
.ds-btn-ghost { background: transparent; color: var(--text-2); }
.ds-btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.ds-btn-danger { background: var(--surface); color: var(--bad); border-color: var(--border-strong); }
.ds-btn-sm { height: 32px; padding: 0 var(--sp-3); font-size: var(--fs-sm); }

/* ── Form fields ───────────────────────────────────────────────────────────── */
.ds-filters { display: grid; grid-template-columns: 2fr repeat(3, 1fr) auto; gap: var(--sp-4); align-items: end; }
.ds-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.ds-field label { font-size: var(--fs-sm); font-weight: var(--fw-semibold); color: var(--text); }
.ds-field .help { font-size: var(--fs-xs); color: var(--text-2); }
.ds-input, .ds-select { height: 40px; width: 100%; padding: 0 var(--sp-3); border-radius: var(--radius);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-size: var(--fs-md); }
.ds-input::placeholder { color: var(--text-3); }
.ds-input:focus, .ds-select:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus); }
.ds-input-icon { position: relative; }
.ds-input-icon .icon { position: absolute; inset-inline-start: 12px; top: 11px; color: var(--text-3); }
.ds-input-icon .ds-input { padding-inline-start: 38px; }
.ds-check { width: 16px; height: 16px; accent-color: var(--brand); cursor: pointer; }

/* ── Pills / badges ────────────────────────────────────────────────────────── */
.ds-pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: var(--radius-pill);
  font-size: var(--fs-xs); font-weight: var(--fw-semibold); white-space: nowrap; background: var(--muted-soft); color: var(--text-2); }
.ds-pill.ok { background: var(--ok-soft); color: var(--ok); }
.ds-pill.warn { background: var(--warn-soft); color: var(--warn); }
.ds-pill.bad { background: var(--bad-soft); color: var(--bad); }
.ds-pill.info { background: var(--info-soft); color: var(--info); }
.ds-pill.brand { background: var(--brand); color: var(--brand-ink); }
.ds-pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ── Table ─────────────────────────────────────────────────────────────────── */
/* position: the containing block of absolutely positioned children (screen-reader-only labels in a header cell):
   without it they are placed against the page, escape this scroll box, and widen the whole page sideways on a phone. */
.ds-table-wrap { overflow-x: auto; position: relative; }
.ds-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-md); }
.ds-table th { background: var(--surface-2); color: var(--text-2); font-size: var(--fs-sm); font-weight: var(--fw-semibold);
  text-align: start; padding: 12px var(--sp-4); border-bottom: 1px solid var(--border); white-space: nowrap; }
.ds-table td { padding: 14px var(--sp-4); border-bottom: 1px solid var(--border); vertical-align: middle; }
.ds-table tbody tr:hover td { background: var(--surface-2); }
.ds-table tbody tr[aria-selected="true"] td { background: var(--brand-soft); }
.ds-table tr:last-child td { border-bottom: 0; }
.ds-table .w-check { width: 44px; }
.ds-table .num { font-variant-numeric: tabular-nums; }
.ds-cell-user { display: flex; align-items: center; gap: var(--sp-3); }
.ds-cell-user .name { font-weight: var(--fw-semibold); color: var(--text); }
.ds-cell-sub { font-size: var(--fs-xs); color: var(--text-2); direction: ltr; text-align: end; }
.ds-cell-user .ds-cell-sub { text-align: start; }
.ds-health { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--text-2); }
.ds-health::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.ds-health.bad::before { background: var(--bad); }
.ds-health.none::before { background: var(--border-strong); }

.ds-bulkbar { display: none; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4);
  background: var(--brand-soft); border-bottom: 1px solid var(--border); font-size: var(--fs-sm); }
.ds-bulkbar.on { display: flex; }
.ds-bulkbar strong { color: var(--brand); }
.ds-tablehead { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border); }
.ds-tablehead h2 { margin: 0; font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.ds-tablehead .meta { color: var(--text-2); font-size: var(--fs-sm); }
.ds-pager { display: flex; align-items: center; gap: var(--sp-2); padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--border); font-size: var(--fs-sm); color: var(--text-2); }
.ds-pager .spacer { flex: 1; }
.ds-pager button[aria-current="page"] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

/* ── Courses (Phase 4): course cards, the «المزيد» action menu, roster picker ── */
.crs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--sp-4); padding: var(--sp-4); }
.crs-card { display: flex; flex-direction: column; gap: var(--sp-2); padding: var(--sp-4); box-shadow: var(--shadow-sm);
  transition: border-color .15s ease, box-shadow .15s ease; }
.crs-card:hover { border-color: var(--border-strong); }
/* Course grids inside a panel (2026-11-01): the grid is a tray in the page tone, so the white
   cards part by their gaps — no added lines. The panel header already draws the top edge. */
.ds-card .crs-grid { background: var(--bg); border-radius: 0 0 calc(var(--radius-lg) - 1px) calc(var(--radius-lg) - 1px); }
.ds-card .crs-grid:has(~ .ds-pager:not(:empty)) { border-radius: 0; }
.crs-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-2); }
.crs-pills { display: flex; flex-wrap: wrap; gap: 4px; }
.crs-title { margin: 0; font-size: var(--fs-md); font-weight: var(--fw-semibold); line-height: 1.4; }
.crs-facts { display: flex; flex-wrap: wrap; gap: var(--sp-3); font-size: var(--fs-sm); color: var(--text-2); }
.crs-teachers { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.crs-teachers .icon { width: 15px; height: 15px; color: var(--text-3); flex: none; }
.crs-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-2); }
.crs-stat { background: var(--surface-2); border-radius: var(--radius); padding: var(--sp-2) var(--sp-3); }
.crs-stat .k { display: block; font-size: var(--fs-xs); color: var(--text-3); }
.crs-stat .v { display: block; font-size: var(--fs-md); font-weight: var(--fw-bold); }
.crs-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: auto; }
.crs-more { position: relative; }
.crs-more > summary { list-style: none; cursor: pointer; }
.crs-more > summary::-webkit-details-marker { display: none; }
.crs-menu { position: absolute; inset-inline-end: 0; top: calc(100% + 4px); z-index: 30; min-width: 190px;
  display: flex; flex-direction: column; align-items: stretch; gap: 2px; padding: var(--sp-2);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.crs-menu .ds-btn { justify-content: flex-start; width: 100%; }
.roster-picks { display: flex; flex-direction: column; align-items: stretch; gap: 2px; margin-top: 4px; max-height: 180px; overflow: auto; }
.roster-picks .ds-btn { justify-content: flex-start; }

/* ── Users (Phase 5): detail tabs, key/value grid, import panel, bulk extras ── */
.ds-tabs { display: flex; flex-wrap: wrap; gap: 2px; margin-bottom: var(--sp-4); border-bottom: 1px solid var(--border); }
.ds-tab { appearance: none; background: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px;
  padding: var(--sp-2) var(--sp-4); font: inherit; font-size: var(--fs-md); color: var(--text-2); cursor: pointer; }
.ds-tab:hover { color: var(--text); }
.ds-tab[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); font-weight: var(--fw-semibold); }
.ds-tab:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.ds-kv { display: grid; grid-template-columns: minmax(130px, max-content) 1fr; gap: var(--sp-2) var(--sp-5); margin: 0; font-size: var(--fs-md); }
.ds-kv dt { color: var(--text-3); }
.ds-kv dd { margin: 0; color: var(--text); overflow-wrap: anywhere; }
.ds-ud-sub { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 4px 0 0; color: var(--text-2); }
.ds-section-title { margin: var(--sp-5) 0 var(--sp-3); font-size: var(--fs-md); font-weight: var(--fw-semibold); }
.ds-row-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; margin: var(--sp-3) 0; }
.ds-checkline { display: inline-flex; gap: 8px; align-items: center; margin-top: var(--sp-3); font-size: var(--fs-sm); color: var(--text-2); }
.ds-import .meta, .ds-row-actions .meta { color: var(--text-3); font-size: var(--fs-sm); }
.ds-bulk-extra { display: inline-flex; gap: 6px; align-items: center; }
.ds-bulk-extra .ds-select, .ds-bulk-extra .ds-input { min-width: 200px; height: 32px; }
.ds-pre { margin: 6px 0 0; padding: var(--sp-2) var(--sp-3); background: var(--surface-2); border-radius: var(--radius-sm);
  font-size: var(--fs-xs); white-space: pre-wrap; overflow-wrap: anywhere; direction: ltr; text-align: left; color: var(--text-2); }
.ds-code { font-family: ui-monospace, monospace; font-size: var(--fs-lg); letter-spacing: 2px; direction: ltr; }
.ds-progress { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; min-width: 80px; }
.ds-progress > span { display: block; height: 100%; background: var(--brand); }
/* a wide table scrolls inside its wrapper instead of widening the whole page on phones */
#section-users .ds-table-wrap, #section-user-detail .ds-table-wrap, .admin-section .ds-table-wrap { contain: inline-size; }

/* ── Admin sections (generic, shared by the remaining dashboard sections) ────── */
/* status banner (JS toggles .ok/.bad/.warn/.info; display is toggled inline by the section JS) */
.ds-msg { padding: var(--sp-3) var(--sp-4); border-radius: var(--radius); font-size: var(--fs-md); font-weight: var(--fw-semibold);
  margin-bottom: var(--sp-4); background: var(--muted-soft); color: var(--text-2); }
.ds-msg.ok { background: var(--ok-soft); color: var(--ok); }
.ds-msg.bad { background: var(--bad-soft); color: var(--bad); }
.ds-msg.warn { background: var(--warn-soft); color: var(--warn); }
.ds-msg.info { background: var(--info-soft); color: var(--info); }
.ds-note { font-size: var(--fs-sm); color: var(--text-2); }
.ds-note.ok { color: var(--ok); } .ds-note.bad { color: var(--bad); } .ds-note.warn { color: var(--warn); } .ds-note.muted { color: var(--text-2); }
/* callout box with a side accent */
.ds-callout { padding: var(--sp-3) var(--sp-4); border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--border);
  border-inline-start: 4px solid var(--border-strong); font-size: var(--fs-sm); color: var(--text-2); line-height: 1.7; }
.ds-callout.ok { border-inline-start-color: var(--ok); background: var(--ok-soft); }
.ds-callout.warn { border-inline-start-color: var(--warn); background: var(--warn-soft); }
.ds-callout.info { border-inline-start-color: var(--info); background: var(--info-soft); }
.ds-callout.brand { border-inline-start-color: var(--brand); }
.ds-callout b, .ds-callout strong { color: var(--text); }
.ds-callout.ok b, .ds-callout.ok strong { color: var(--ok); }
.ds-callout.warn b, .ds-callout.warn strong { color: var(--warn); }
.ds-callout.info b, .ds-callout.info strong { color: var(--info); }
/* empty / loading state */
.ds-empty { padding: var(--sp-8) var(--sp-4); text-align: center; color: var(--text-2); font-size: var(--fs-md); }
.ds-empty.bad { color: var(--bad); }
.ds-empty.sm { padding: var(--sp-4); }
/* toolbars: a row of filters/actions */
.ds-toolbar { display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: center; }
.ds-toolbar.end { align-items: flex-end; }
.ds-pager:empty { display: none; }
.ds-toolbar .grow { flex: 1 1 200px; min-width: 0; }
.ds-toolbar .ds-input, .ds-toolbar .ds-select { width: auto; min-width: 140px; }
.ds-toolbar .ds-input.grow { width: auto; }
.ds-tablehead { flex-wrap: wrap; }
.ds-tablehead .tools { margin-inline-start: auto; display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; }
.ds-sm.ds-input, .ds-sm.ds-select { height: 32px; font-size: var(--fs-sm); }
.ds-input.search { width: 220px; }
.ds-input-icon.sm .icon { top: 7px; }
.ds-progress.tone > span.ok { background: var(--ok); } .ds-progress.tone > span.warn { background: var(--warn); } .ds-progress.tone > span.bad { background: var(--bad); }
.ds-textarea { width: 100%; padding: var(--sp-2) var(--sp-3); border-radius: var(--radius); border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: inherit; font-size: var(--fs-md); resize: vertical; }
.ds-textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus); }
.ds-input[type="color"] { width: 54px; padding: 2px; cursor: pointer; }
.ds-formgrid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4); }
.ds-formgrid .full { grid-column: 1 / -1; }
.ds-stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.ds-stack.sm { gap: var(--sp-3); }
.ds-actions-end { display: flex; gap: var(--sp-3); justify-content: flex-end; align-items: center; flex-wrap: wrap; }
.ds-actions-between { display: flex; gap: var(--sp-3); justify-content: space-between; align-items: center; flex-wrap: wrap; }
/* layouts */
.ds-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-5); align-items: start; margin-bottom: var(--sp-5); }
.ds-grid-fit { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: var(--sp-5); align-items: start; }
.ds-card-gap { margin-bottom: var(--sp-5); }
.ds-narrow { max-width: 680px; margin-inline: auto; }
/* KPI tiles: auto-fit variant of .ds-stats, tones, icon, clickable */
.ds-stats.fit { grid-template-columns: repeat(auto-fit, minmax(min(170px, 100%), 1fr)); }
.ds-stat .value.ok { color: var(--ok); } .ds-stat .value.warn { color: var(--warn); } .ds-stat .value.bad { color: var(--bad); }
.ds-stat .value.sm { font-size: var(--fs-lg); }
/* a money value in a tile may hold two currencies: it wraps inside the tile instead of widening the page */
.ds-stat { min-width: 0; }
.ds-stat .value.ds-money { white-space: normal; overflow-wrap: anywhere; }
.ds-stat.has-icon { flex-direction: row; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.ds-stat.has-icon > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.ds-stat .ico { width: 38px; height: 38px; border-radius: var(--radius); display: grid; place-items: center; flex: none;
  background: var(--brand-soft); color: var(--brand); }
.ds-stat .ico.ok { background: var(--ok-soft); color: var(--ok); } .ds-stat .ico.warn { background: var(--warn-soft); color: var(--warn); }
.ds-stat .ico.bad { background: var(--bad-soft); color: var(--bad); } .ds-stat .ico.info { background: var(--info-soft); color: var(--info); }
.ds-stat.click { cursor: pointer; text-align: start; font: inherit; color: inherit; width: 100%; }
.ds-stat.click:hover { border-color: var(--border-strong); background: var(--surface-2); }
.ds-stat.click.is-active { border-color: var(--brand); box-shadow: var(--focus); }
/* segmented control (tabs-as-buttons) */
.ds-seg { display: inline-flex; gap: 2px; padding: 3px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); flex-wrap: wrap; }
.ds-seg > button { appearance: none; border: 0; background: transparent; color: var(--text-2); font: inherit; font-size: var(--fs-sm);
  font-weight: var(--fw-semibold); padding: 6px var(--sp-3); border-radius: var(--radius-sm); cursor: pointer; white-space: nowrap; }
.ds-seg > button:hover { background: var(--surface-2); color: var(--text); }
.ds-seg > button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }
.ds-seg .cnt { opacity: .7; font-weight: var(--fw-regular); margin-inline-start: 4px; }
/* list rows (feeds, messages) */
.ds-list > * { padding: var(--sp-3) var(--sp-5); border-bottom: 1px solid var(--border); }
.ds-list > *:last-child { border-bottom: 0; }
.ds-list-row { display: flex; align-items: center; gap: var(--sp-3); }
.ds-list-row .grow { flex: 1; min-width: 0; }
.ds-list-row .title { font-weight: var(--fw-semibold); font-size: var(--fs-md); }
.ds-list-row .sub { font-size: var(--fs-xs); color: var(--text-2); }
.ds-list .unread { background: var(--brand-soft); }
.ds-list .clickable { cursor: pointer; }
.ds-list .clickable:hover { background: var(--surface-2); }
.ds-chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.ds-sep { border: 0; border-top: 1px dashed var(--border-strong); margin: var(--sp-4) 0; }
.ds-dropdown { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); max-height: 240px; overflow-y: auto; margin-top: var(--sp-1); }
.ds-dropdown:empty { display: none; }
.ds-dropdown .opt { padding: var(--sp-2) var(--sp-3); cursor: pointer; font-size: var(--fs-md); border-bottom: 1px solid var(--border); }
.ds-dropdown .opt:last-child { border-bottom: 0; }
.ds-dropdown .opt:hover { background: var(--surface-2); }
.ds-sub { font-size: var(--fs-xs); color: var(--text-2); }
.ds-money { font-variant-numeric: tabular-nums; white-space: nowrap; }
/* profile */
.ds-profile { display: grid; grid-template-columns: 1fr 2fr; gap: var(--sp-5); align-items: start; }
.ds-profile-card { text-align: center; }
.ds-profile-avatar { width: 96px; height: 96px; border-radius: 50%; border: 3px solid var(--brand); object-fit: cover; margin-bottom: var(--sp-4); background: var(--surface-2); }
.ds-profile-name { font-size: var(--fs-lg); font-weight: var(--fw-bold); margin-bottom: 2px; }
.ds-profile-foot { margin-top: var(--sp-5); padding-top: var(--sp-4); border-top: 1px solid var(--border); }
.ds-card.has-fail { border-color: var(--bad); }
.ds-card code, .ds-callout code, .ds-msg code, .ds-table code { font-family: ui-monospace, Consolas, monospace; font-size: .85em; background: var(--muted-soft); color: var(--text);
  padding: 1px 6px; border-radius: var(--radius-sm); direction: ltr; unicode-bidi: embed; }
/* sticky save bar (settings) */
.ds-savebar { position: sticky; bottom: var(--sp-4); z-index: 5; display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap;
  margin-top: var(--sp-5); padding: var(--sp-3) var(--sp-4); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow); }
/* code blocks (deployment guide) */
.ds-codeblock { position: relative; margin: var(--sp-2) 0; contain: inline-size; }
.ds-codeblock pre { margin: 0; padding: var(--sp-3) var(--sp-4); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: auto; direction: ltr; text-align: left; font-family: ui-monospace, Consolas, monospace; font-size: var(--fs-sm); line-height: 1.7; color: var(--text); }
/* The command is always LTR and starts at the physical left, so the copy button sits at the physical right with room
   reserved for it — on an RTL page inset-inline-end is the LEFT edge, where the button covered the command's first letters. */
.ds-codeblock pre { padding-right: 84px; }
.ds-codeblock .ds-btn { position: absolute; top: var(--sp-2); right: var(--sp-2); left: auto; }
.ds-card-title { margin: 0 0 var(--sp-2); font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
/* bar chart (sales) */
.ds-bars { min-height: 220px; display: flex; align-items: flex-end; gap: var(--sp-2); padding-bottom: 24px; position: relative; }
.ds-bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 200px; position: relative; min-width: 0; }
.ds-bars .bar > .fill { display: block; width: 100%; max-width: 44px; background: var(--brand); border-radius: var(--radius-sm) var(--radius-sm) 0 0; min-height: 2px; }
.ds-bars .bar > .lbl { position: absolute; bottom: -22px; font-size: var(--fs-xs); color: var(--text-2); white-space: nowrap; }
.ds-bars .bar > .val { font-size: var(--fs-xs); color: var(--text-2); margin-bottom: 2px; font-variant-numeric: tabular-nums; }

/* ── Modal dialogs (<dialog> opened with showModal) ─────────────────────────── */
/* The theme's global reset (style.css: * { margin: 0 }) removes the browser's own margin: auto, which is what centres
   a modal dialog — without it a dialog sits in the top corner. Restored here once for every modal dialog; the
   browser's max-width / max-height (the viewport less a small gap) and overflow: auto stay as they are, so a long
   dialog scrolls inside itself. A side sheet would set its own margin with a class (none exists today). */
dialog:modal { margin: auto; }

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  .ds-filters { grid-template-columns: 1fr 1fr; }
  .ds-filters .ds-field:first-child { grid-column: 1 / -1; }
}
@media (max-width: 860px) {
  .ds-shell { grid-template-columns: 1fr; }
  .ds-sidebar { position: fixed; inset-block: 0; inset-inline-start: 0; width: var(--sidebar-w); z-index: 20;
    transform: translateX(100%); transition: transform .2s ease; box-shadow: var(--shadow); }
  [dir="ltr"] .ds-sidebar { transform: translateX(-100%); }
  .ds-shell.nav-open .ds-sidebar { transform: none; }
  .ds-menu-toggle { display: grid; }
  .ds-topbar { padding: 0 var(--sp-4); }
  .ds-content { padding: var(--sp-5) var(--sp-4); }
  .ds-user .who, .ds-context .scope { display: none; }
  .ds-hide-sm { display: none; }
  .ds-filters { grid-template-columns: 1fr; }
  .ds-grid-2, .ds-formgrid, .ds-profile { grid-template-columns: 1fr; }
  /* a nowrap/ellipsis row inside a 1fr track used to set the track's min-content and widen the whole page */
  .ds-grid-2 { grid-template-columns: minmax(0, 1fr); }
  .ds-input.search { width: 100%; }
  .ds-toolbar .ds-input, .ds-toolbar .ds-select { width: 100%; }
  .ds-grid-fit { grid-template-columns: 1fr; }
  .ds-tablehead .tools { margin-inline-start: 0; width: 100%; }
  .ds-tablehead .tools .ds-input-icon { flex: 1 1 180px; }
}
