/*
 * Manhali Modern: components.
 * Class names mirror shadcn components; state uses Base UI data attributes
 * ([data-open] [data-checked] [data-selected] [data-highlighted] [data-disabled]
 * [data-pressed]) plus native aria-* where they are the source of truth.
 */

/* ── Icons ─────────────────────────────────────────────── */
.icon { inline-size: 18px; block-size: 18px; flex: none; }
.icon-sm { inline-size: 16px; block-size: 16px; flex: none; }
.icon-xs { inline-size: 14px; block-size: 14px; flex: none; }
.icon-lg { inline-size: 22px; block-size: 22px; flex: none; }

/* Icon tile: soft coloured square behind an icon (category, KPI, integration) */
.icon-tile {
  --tile-bg: var(--primary-soft); --tile-fg: var(--primary-soft-foreground);
  display: inline-grid; place-items: center; flex: none;
  inline-size: 36px; block-size: 36px; border-radius: var(--radius-md);
  background: var(--tile-bg); color: var(--tile-fg);
}
.icon-tile.sm { inline-size: 28px; block-size: 28px; border-radius: var(--radius-sm); }
.icon-tile.lg { inline-size: 48px; block-size: 48px; border-radius: 14px; }
.icon-tile.lg .icon { inline-size: 24px; block-size: 24px; }
.icon-tile.outline { background: var(--card); color: var(--foreground); box-shadow: var(--shadow-xs), 0 0 0 1px var(--border); }
[data-tone="orange"] { --tile-bg: var(--tag-orange-bg); --tile-fg: var(--tag-orange-fg); }
[data-tone="amber"]  { --tile-bg: var(--tag-amber-bg);  --tile-fg: var(--tag-amber-fg); }
[data-tone="green"]  { --tile-bg: var(--tag-green-bg);  --tile-fg: var(--tag-green-fg); }
[data-tone="teal"]   { --tile-bg: var(--tag-teal-bg);   --tile-fg: var(--tag-teal-fg); }
[data-tone="blue"]   { --tile-bg: var(--tag-blue-bg);   --tile-fg: var(--tag-blue-fg); }
[data-tone="violet"] { --tile-bg: var(--tag-violet-bg); --tile-fg: var(--tag-violet-fg); }
[data-tone="pink"]   { --tile-bg: var(--tag-pink-bg);   --tile-fg: var(--tag-pink-fg); }
[data-tone="red"]    { --tile-bg: var(--tag-red-bg);    --tile-fg: var(--tag-red-fg); }
[data-tone="neutral"]{ --tile-bg: var(--neutral-soft);  --tile-fg: var(--neutral-soft-foreground); }

/* ── Button ────────────────────────────────────────────── */
.btn {
  --btn-h: var(--control-h);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  block-size: var(--btn-h); padding-inline: 14px; border-radius: var(--radius-md);
  font-size: var(--text-sm); font-weight: var(--weight-medium); line-height: 1; white-space: nowrap;
  border: 1px solid transparent; user-select: none;
  transition: background-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out), color var(--dur-fast), transform var(--dur-fast) var(--ease-out);
}
.btn:active:not(:disabled, [data-disabled]) { transform: translateY(0.5px) scale(0.985); }
.btn:disabled, .btn[data-disabled] { opacity: 0.5; cursor: not-allowed; }
.btn .icon { inline-size: 16px; block-size: 16px; }
.btn-sm { --btn-h: var(--control-h-sm); padding-inline: 10px; gap: 6px; border-radius: var(--radius-sm); font-size: var(--text-sm); }
.btn-xs { --btn-h: var(--control-h-xs); padding-inline: 8px; gap: 4px; border-radius: var(--radius-sm); font-size: var(--text-xs); }
.btn-lg { --btn-h: var(--control-h-lg); padding-inline: 18px; font-size: var(--text-base); border-radius: 12px; }
.btn-icon { inline-size: var(--btn-h); padding: 0; }
.btn-block { inline-size: 100%; }

.btn-primary { background: var(--primary); color: var(--primary-foreground); box-shadow: var(--btn-primary-shadow); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-primary:active:not(:disabled) { background: var(--primary-active); }
.btn-outline { background: var(--card); color: var(--foreground); border-color: var(--border); box-shadow: var(--shadow-xs), var(--inset-highlight); }
.btn-outline:hover:not(:disabled), .btn-outline[data-open] { background: var(--hover); border-color: var(--border-strong); }
.btn-secondary { background: var(--secondary); color: var(--secondary-foreground); }
.btn-secondary:hover:not(:disabled) { background: var(--selected); }
.btn-soft { background: var(--primary-soft); color: var(--primary-soft-foreground); }
.btn-soft:hover:not(:disabled) { background: var(--primary-soft-hover); }
.btn-ghost { color: var(--muted-foreground); }
.btn-ghost:hover:not(:disabled), .btn-ghost[data-open], .btn-ghost[data-pressed] { background: var(--hover); color: var(--foreground); }
.btn-destructive { background: var(--destructive); color: var(--destructive-foreground); }
.btn-destructive:hover:not(:disabled) { background: color-mix(in oklch, var(--destructive), black 10%); }
.btn-destructive-soft { background: var(--destructive-soft); color: var(--destructive-soft-foreground); }
.btn-link { block-size: auto; padding: 0; color: var(--primary-soft-foreground); border-radius: var(--radius-xs); }
.btn-link:hover { text-decoration: underline; text-underline-offset: 3px; }
/* Links inside running text are underlined so they never rely on colour alone (WCAG 1.4.1) */
:where(p, .desc, .description, .card-description) :is(a:not([class]), .btn-link) {
  text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px;
  text-decoration-color: color-mix(in oklch, currentColor, transparent 55%);
}
:where(p, .desc, .description, .card-description) :is(a:not([class]), .btn-link):hover { text-decoration-color: currentColor; }

/* ── Kbd ───────────────────────────────────────────────── */
.kbd {
  display: inline-grid; place-items: center; min-inline-size: 20px; block-size: 20px; padding-inline: 5px;
  border-radius: var(--radius-xs); background: var(--card); color: var(--muted-foreground);
  border: 1px solid var(--border); box-shadow: 0 1px 0 var(--border);
  font-family: var(--font-num); font-size: 11px; font-weight: var(--weight-medium); line-height: 1;
}

/* ── Badge / pill / tag ────────────────────────────────── */
.badge {
  --badge-bg: var(--neutral-soft); --badge-fg: var(--neutral-soft-foreground);
  display: inline-flex; align-items: center; gap: 6px; block-size: 24px; padding-inline: 9px;
  border-radius: var(--radius-pill); background: var(--badge-bg); color: var(--badge-fg);
  font-size: var(--text-xs); font-weight: var(--weight-medium); line-height: 1; white-space: nowrap;
}
.badge .icon { inline-size: 13px; block-size: 13px; }
.badge-dot::before { content: ""; inline-size: 6px; block-size: 6px; border-radius: 50%; background: currentColor; }
.badge-success { --badge-bg: var(--success-soft); --badge-fg: var(--success-soft-foreground); }
.badge-warning { --badge-bg: var(--warning-soft); --badge-fg: var(--warning-soft-foreground); }
.badge-info    { --badge-bg: var(--info-soft);    --badge-fg: var(--info-soft-foreground); }
.badge-danger  { --badge-bg: var(--destructive-soft); --badge-fg: var(--destructive-soft-foreground); }
.badge-primary { --badge-bg: var(--primary-soft); --badge-fg: var(--primary-soft-foreground); }
.badge-outline { --badge-bg: var(--card); box-shadow: inset 0 0 0 1px var(--border); --badge-fg: var(--foreground); }
.badge-count { block-size: 20px; min-inline-size: 20px; padding-inline: 6px; justify-content: center; font-family: var(--font-num); font-size: 11px; }

.tag {
  display: inline-flex; align-items: center; gap: 5px; block-size: 24px; padding-inline: 8px;
  border-radius: var(--radius-sm); background: var(--tile-bg, var(--neutral-soft)); color: var(--tile-fg, var(--neutral-soft-foreground));
  font-size: var(--text-xs); font-weight: var(--weight-medium); white-space: nowrap; line-height: 1;
}
.tag .icon { inline-size: 13px; block-size: 13px; }

.dot { inline-size: 8px; block-size: 8px; border-radius: 50%; background: var(--subtle-foreground); flex: none; }
.dot.success { background: var(--success); } .dot.warning { background: var(--warning); } .dot.danger { background: var(--destructive); } .dot.info { background: var(--info); } .dot.brand { background: var(--brand); }
.dot.pulse { box-shadow: 0 0 0 0 color-mix(in oklch, var(--success), transparent 40%); animation: pulse 2s var(--ease-out) infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 6px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

.trend { display: inline-flex; align-items: center; gap: 2px; font-family: var(--font-num); font-size: var(--text-xs); font-weight: var(--weight-medium); direction: ltr; }
.trend.up { color: var(--success-soft-foreground); } .trend.down { color: var(--destructive-soft-foreground); }

/* ── Avatar ────────────────────────────────────────────── */
.avatar {
  --size: 32px;
  display: inline-grid; place-items: center; flex: none; inline-size: var(--size); block-size: var(--size);
  border-radius: 50%; overflow: hidden; background: var(--tile-bg, var(--muted)); color: var(--tile-fg, var(--muted-foreground));
  font-size: calc(var(--size) * 0.4); font-weight: var(--weight-medium); line-height: 1;
}
.avatar img { inline-size: 100%; block-size: 100%; object-fit: cover; }
.avatar.xs { --size: 22px; } .avatar.sm { --size: 26px; } .avatar.lg { --size: 44px; } .avatar.xl { --size: 64px; }
.avatar-group { display: inline-flex; }
.avatar-group .avatar { box-shadow: 0 0 0 2px var(--card); }
.avatar-group .avatar + .avatar { margin-inline-start: -8px; }

/* ── Field, input, textarea, select trigger ────────────── */
.field { display: flex; flex-direction: column; gap: 6px; min-inline-size: 0; }
.label { font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--foreground); }
.label .req { color: var(--destructive); margin-inline-start: 2px; }
.description { font-size: var(--text-xs); color: var(--muted-foreground); line-height: 1.5; }
.field-error { font-size: var(--text-xs); color: var(--destructive-soft-foreground); display: flex; gap: 6px; align-items: center; }

.input, .textarea, .select-trigger {
  inline-size: 100%; min-block-size: var(--control-h); padding-inline: 12px;
  background: var(--card); color: var(--foreground);
  border: 1px solid var(--input); border-radius: var(--radius-md);
  box-shadow: var(--shadow-xs);
  font-size: var(--text-base); line-height: 1.4;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.input::placeholder, .textarea::placeholder { color: var(--muted-foreground); }
.input:hover, .textarea:hover, .select-trigger:hover { border-color: var(--border-strong); }
.input:focus, .textarea:focus, .select-trigger:focus-visible, .select-trigger[data-open], .input-group:focus-within {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in oklch, var(--brand), transparent 82%);
}
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--destructive); box-shadow: 0 0 0 3px color-mix(in oklch, var(--destructive), transparent 85%); }
.input-group:has(> input[aria-invalid="true"]) { border-color: var(--destructive); box-shadow: 0 0 0 3px color-mix(in oklch, var(--destructive), transparent 85%); }
.input[readonly], .textarea[readonly] { background: var(--muted); color: var(--muted-foreground); box-shadow: none; }
.field-ok { font-size: var(--text-xs); color: var(--success-soft-foreground); display: flex; gap: 6px; align-items: center; }
.field-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.counter { font-family: var(--font-num); font-size: var(--text-xs); color: var(--muted-foreground); font-variant-numeric: tabular-nums; }
.counter[data-over] { color: var(--destructive-soft-foreground); }
.input:disabled, .textarea:disabled { background: var(--muted); color: var(--muted-foreground); cursor: not-allowed; }
.input-sm { min-block-size: var(--control-h-sm); font-size: var(--text-sm); border-radius: var(--radius-sm); }
.textarea { padding-block: 10px; min-block-size: 96px; resize: vertical; line-height: 1.6; }

.input-group {
  display: flex; align-items: center; gap: 8px; padding-inline: 12px; min-block-size: var(--control-h);
  background: var(--card); border: 1px solid var(--input); border-radius: var(--radius-md); box-shadow: var(--shadow-xs);
  color: var(--subtle-foreground); transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.input-group:hover { border-color: var(--border-strong); }
.input-group > input { flex: 1; min-inline-size: 0; border: 0; background: none; outline: none; block-size: 100%; color: var(--foreground); font-size: var(--text-base); }
.input-group > input::placeholder { color: var(--muted-foreground); }
.input-group .addon { color: var(--muted-foreground); font-size: var(--text-sm); white-space: nowrap; }
.input-group.sm { min-block-size: var(--control-h-sm); border-radius: var(--radius-sm); }
.input-group.sm > input { font-size: var(--text-sm); }

.select-trigger { display: inline-flex; align-items: center; gap: 8px; justify-content: space-between; text-align: start; cursor: pointer; }
.select-trigger .icon:last-child { color: var(--subtle-foreground); inline-size: 16px; block-size: 16px; }

/* ── Checkbox / radio / switch ─────────────────────────── */
.checkbox {
  display: inline-grid; place-items: center; flex: none; inline-size: 18px; block-size: 18px;
  border-radius: 5px; border: 1.5px solid var(--border-strong); background: var(--card); color: var(--primary-foreground);
  transition: background-color var(--dur-fast), border-color var(--dur-fast);
}
.checkbox .icon { inline-size: 12px; block-size: 12px; stroke-width: 3; opacity: 0; transform: scale(0.6); transition: opacity var(--dur-fast), transform var(--dur) var(--ease-out); }
.checkbox[data-checked], .checkbox[data-indeterminate] { background: var(--primary); border-color: var(--primary); }
.checkbox[data-checked] .icon, .checkbox[data-indeterminate] .icon { opacity: 1; transform: none; }
.checkbox[data-indeterminate] .icon { display: none; }
.checkbox[data-indeterminate]::after { content: ""; inline-size: 8px; block-size: 2px; border-radius: 1px; background: currentColor; }
.checkbox:hover:not([data-checked]) { border-color: var(--muted-foreground); }

.radio { display: inline-grid; place-items: center; inline-size: 18px; block-size: 18px; border-radius: 50%; border: 1.5px solid var(--border-strong); background: var(--card); flex: none; }
.radio[data-checked] { border-color: var(--primary); }
.radio[data-checked]::after { content: ""; inline-size: 8px; block-size: 8px; border-radius: 50%; background: var(--primary); }

.switch {
  position: relative; flex: none; inline-size: 36px; block-size: 21px; border-radius: 999px;
  background: var(--border-strong); transition: background-color var(--dur) var(--ease-out);
}
.switch::before {
  content: ""; position: absolute; inset-block-start: 2.5px; inset-inline-start: 2.5px; inline-size: 16px; block-size: 16px;
  border-radius: 50%; background: white; box-shadow: 0 1px 2px oklch(0 0 0 / 0.2);
  transition: transform var(--dur) var(--ease-out);
}
.switch[data-checked] { background: var(--primary); }
.switch[data-checked]::before { transform: translateX(15px); }
[dir="rtl"] .switch[data-checked]::before { transform: translateX(-15px); }
.switch[data-disabled], .switch:disabled { opacity: 0.45; cursor: not-allowed; }

.choice { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.choice .checkbox, .choice .radio { margin-block-start: 3px; }

/* Choice card (radio/checkbox as a card) */
.choice-card {
  display: flex; gap: 12px; align-items: flex-start; padding: 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--card); cursor: pointer; text-align: start;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast), background-color var(--dur-fast);
}
.choice-card:hover { border-color: var(--border-strong); }
.choice-card[data-checked] { border-color: var(--brand); background: color-mix(in oklch, var(--primary-soft), var(--card) 45%); box-shadow: 0 0 0 3px color-mix(in oklch, var(--brand), transparent 85%); }

/* Choice card carrying a checkbox indicator */
.choice-card[data-checked] .checkbox { background: var(--primary); border-color: var(--primary); }
.choice-card[data-checked] .checkbox .icon { opacity: 1; transform: none; }
.choice-card > .radio { margin-block-start: 2px; }
.choice-card[data-checked] .radio { border-color: var(--primary); }
.choice-card[data-checked] .radio::after { content: ""; inline-size: 8px; block-size: 8px; border-radius: 50%; background: var(--primary); }

/* Setting row: label + description at start, control at end */
.setting-row { display: flex; align-items: center; gap: 24px; padding: 16px var(--card-pad); border-block-start: 1px solid var(--border); }
.setting-row:first-child { border-block-start: 0; }
.setting-row .info { flex: 1 1 auto; min-inline-size: 0; display: flex; flex-direction: column; gap: 2px; }
.setting-row .info .label { display: inline-flex; align-items: center; gap: 8px; }
.setting-row .control { flex: 0 1 340px; min-inline-size: 0; }
.setting-row .control.fit { flex: none; }
.setting-row .control > .popover-anchor { display: block; }
.setting-row .control > .popover-anchor > .popup { inline-size: 100%; }
@media (max-width: 640px) { .setting-row:not(.inline) { flex-direction: column; align-items: stretch; gap: 10px; } .setting-row:not(.inline) .control { flex: none; } }

/* Upload tile / dropzone */
.upload-tile { display: flex; align-items: center; gap: 14px; padding: 14px; border-radius: 14px; border: 1.5px dashed var(--border-strong); background: var(--surface-2); transition: border-color var(--dur-fast), background-color var(--dur-fast); }
.upload-tile:hover, .upload-tile[data-dragging] { border-color: var(--brand); background: color-mix(in oklch, var(--primary-soft), var(--card) 50%); }
button.upload-tile { inline-size: 100%; text-align: start; }
/* The file input inside is .sr-only, so its keyboard focus shows on the tile */
:is(.upload-tile, .dropzone):has(input[type="file"]:focus-visible) { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in oklch, var(--brand), transparent 82%); }

/* "or" divider */
.or-divider { display: flex; align-items: center; gap: 12px; color: var(--muted-foreground); font-size: var(--text-xs); }
.or-divider::before, .or-divider::after { content: ""; flex: 1; block-size: 1px; background: var(--border); }

/* Standalone logo tile (bare pages) — same gradient as the workspace logo */
/* Brand mark: logo tile + name (auth pages, docs header) */
.brand-mark { display: inline-flex; align-items: center; gap: 10px; font-weight: var(--weight-bold); font-size: var(--text-md); }
.logo-tile { display: inline-grid; place-items: center; flex: none; inline-size: 36px; block-size: 36px; border-radius: 11px; background: linear-gradient(145deg, oklch(0.78 0.16 62), var(--brand) 55%, oklch(0.62 0.19 38)); color: white; box-shadow: 0 1px 2px oklch(0.5 0.15 40 / 0.35), inset 0 1px 0 oklch(1 0 0 / 0.35); font-family: var(--font-display); font-weight: var(--weight-bold); font-size: 18px; }

/* ── Tabs / segmented ──────────────────────────────────── */
.segmented {
  max-inline-size: 100%; overflow-x: auto; scrollbar-width: none; overscroll-behavior-inline: contain;
  display: inline-flex; gap: 2px; padding: 3px; border-radius: 12px; background: var(--muted);
  box-shadow: inset 0 0 0 1px color-mix(in oklch, var(--border), transparent 40%);
}
.segmented > button, .segmented > a {
  display: inline-flex; align-items: center; gap: 6px; block-size: 30px; padding-inline: 12px; border-radius: 9px;
  font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--muted-foreground); white-space: nowrap;
  transition: color var(--dur-fast), background-color var(--dur-fast), box-shadow var(--dur-fast);
}
.segmented > :hover { color: var(--foreground); }
.segmented > [data-selected], .segmented > [aria-selected="true"], .segmented > [aria-pressed="true"] {
  background: var(--card); color: var(--foreground); box-shadow: var(--shadow-sm), 0 0 0 1px color-mix(in oklch, var(--border), transparent 30%);
}
.segmented.icon-only > * { padding-inline: 8px; }
.segmented .count { font-family: var(--font-num); font-size: 11px; color: var(--muted-foreground); }

.tabs { display: flex; gap: 20px; border-block-end: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs > [role="tab"] {
  position: relative; display: inline-flex; gap: 6px; align-items: center; padding-block: 10px 12px;
  font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--muted-foreground); white-space: nowrap;
}
.tabs > [role="tab"]:hover { color: var(--foreground); }
.tabs > [aria-selected="true"] { color: var(--foreground); }
.tabs .count { font-family: var(--font-num); font-size: 11px; color: var(--muted-foreground); }
.tabs > [aria-selected="true"]::after { content: ""; position: absolute; inset-inline: 0; inset-block-end: -1px; block-size: 2px; border-radius: 2px; background: var(--brand); }

/* ── Card ──────────────────────────────────────────────── */
.card {
  background: var(--card); color: var(--card-foreground);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs), var(--inset-highlight);
  min-inline-size: 0;
}
.card-header { display: flex; align-items: center; gap: 12px; padding: 16px var(--card-pad) 0; min-block-size: 56px; }
.card-header.bordered { padding-block-end: 14px; border-block-end: 1px solid var(--border); }
.card-header .card-actions { margin-inline-start: auto; display: flex; gap: 6px; align-items: center; }
.card-description { font-size: var(--text-sm); color: var(--muted-foreground); }
.card-body { padding: var(--card-pad); }
.card-header + .card-body { padding-block-start: 14px; }
.card-footer { display: flex; align-items: center; gap: 8px; padding: 12px var(--card-pad); border-block-start: 1px solid var(--border); }
.card-flush { padding: 0; }
.card.interactive { transition: box-shadow var(--dur) var(--ease-out), border-color var(--dur) var(--ease-out), transform var(--dur) var(--ease-out); }
.card.interactive:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.card.danger { border-color: color-mix(in oklch, var(--destructive), transparent 62%); }
.card.danger .card-title { color: var(--destructive-soft-foreground); }
.card-header + .setting-row, .card-header + .list, .card-header + .table-wrap { margin-block-start: 14px; }
.card.note { border-color: color-mix(in oklch, var(--warning), transparent 50%); background: color-mix(in oklch, var(--warning-soft), var(--card) 30%); }
.card-inset { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; }

/* KPI card */
.kpi { display: flex; flex-direction: column; gap: 14px; padding: 18px var(--card-pad); }
.kpi-head { display: flex; align-items: center; gap: 10px; color: var(--muted-foreground); font-size: var(--text-sm); font-weight: var(--weight-medium); }
.kpi-head .icon-tile { inline-size: 30px; block-size: 30px; border-radius: 9px; }
.kpi-head .icon-tile .icon { inline-size: 16px; block-size: 16px; }
.kpi-head .link { margin-inline-start: auto; color: var(--subtle-foreground); }
.kpi-head .link:hover { color: var(--foreground); }
.kpi-body { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.kpi-value { font-family: var(--font-num); font-size: var(--text-2xl); font-weight: var(--weight-bold); line-height: 1.1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi-value .unit { font-size: var(--text-base); font-weight: var(--weight-medium); color: var(--muted-foreground); letter-spacing: 0; margin-inline-start: 4px; }
.kpi-meta { display: flex; align-items: center; gap: 6px; font-size: var(--text-xs); color: var(--muted-foreground); margin-block-start: 6px; white-space: nowrap; }

/* Stat strip (compact KPIs above tables) */
.stat-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--grid-gap); }
.stat { display: flex; flex-direction: column; gap: 8px; padding: 14px 16px; }
.stat-label { display: flex; align-items: center; gap: 8px; font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--muted-foreground); }
.stat-value { font-family: var(--font-num); font-size: var(--text-xl); font-weight: var(--weight-bold); line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-value .unit { font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--muted-foreground); margin-inline-start: 4px; }
.stat-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 6px; font-size: var(--text-xs); color: var(--muted-foreground); }
.stat.warning { background: color-mix(in oklch, var(--warning-soft), var(--card) 35%); border-color: color-mix(in oklch, var(--warning), transparent 55%); }
@media (max-width: 900px) { .stat-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ── Dot matrix (signature motif: learning progress as lessons) ── */
.dots { display: grid; grid-auto-flow: column; grid-template-rows: repeat(var(--rows, 7), 5px); gap: 3px; direction: ltr; }
.dots i { inline-size: 5px; block-size: 5px; border-radius: 50%; background: var(--chart-empty); }
.dots i[data-on] { background: var(--dot-color, var(--brand)); }

/* Chart host: svg fills, axis sits below */
[data-chart="area"], [data-chart="bars"], [data-chart="dotbars"] { display: flex; flex-direction: column; min-block-size: 0; }
[data-chart] > svg { flex: 1 1 auto; min-block-size: 0; }

/* ── Progress ──────────────────────────────────────────── */
.progress { position: relative; inline-size: 100%; block-size: 6px; border-radius: 99px; background: var(--muted); overflow: hidden; }
.progress > span { position: absolute; inset-block: 0; inset-inline-start: 0; inline-size: var(--value, 0%); border-radius: inherit; background: var(--bar, var(--brand)); transition: inline-size var(--dur-slow) var(--ease-out); }
.progress.sm { block-size: 4px; }
.progress.success > span { --bar: var(--success); }
.progress-row { display: flex; align-items: center; gap: 10px; }
.progress-row .progress { flex: 1; }
.progress-row .num { font-size: var(--text-xs); color: var(--muted-foreground); min-inline-size: 34px; text-align: end; }

.ring { --value: 0; --size: 44px; --stroke: 5px; position: relative; inline-size: var(--size); block-size: var(--size); border-radius: 50%;
  background: conic-gradient(var(--ring-color, var(--brand)) calc(var(--value) * 1%), var(--muted) 0); display: grid; place-items: center; flex: none; }
.ring::before { content: ""; position: absolute; inset: var(--stroke); border-radius: 50%; background: var(--card); }
.ring > span { position: relative; font-family: var(--font-num); font-size: 11px; font-weight: var(--weight-bold); }

/* ── Table ─────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.table-wrap > .table:not(.table-fluid, .table-bars) { min-inline-size: 600px; }
.table { inline-size: 100%; font-size: var(--text-sm); }
.table th {
  position: sticky; inset-block-start: 0; z-index: 1; block-size: 40px; padding-inline: 12px; text-align: start;
  background: var(--surface-2); color: var(--muted-foreground); font-size: var(--text-xs); font-weight: var(--weight-medium); white-space: nowrap;
  border-block-end: 1px solid var(--border);
}
.table th .sort { display: inline-flex; gap: 4px; align-items: center; }
.table td { block-size: 56px; padding: 8px 12px; border-block-end: 1px solid var(--border); vertical-align: middle; }
.table th:first-child, .table td:first-child { padding-inline-start: var(--card-pad); }
.table th:last-child, .table td:last-child { padding-inline-end: var(--card-pad); }
.table tbody tr { transition: background-color var(--dur-fast); }
.table tbody tr:hover { background-color: var(--hover); }
.table tbody tr[data-selected] { background-color: color-mix(in oklch, var(--primary-soft), transparent 35%); }
.table tbody tr:last-child td { border-block-end: 0; }
.table .num-col { text-align: end; font-family: var(--font-num); font-variant-numeric: tabular-nums; }
.table .check-col { inline-size: 44px; }
.table .actions-col { inline-size: 48px; text-align: end; }
.table .row-action { opacity: 0; transition: opacity var(--dur-fast); }
.table tr:hover .row-action, .table tr:focus-within .row-action { opacity: 1; }
@media (hover: none) { .table .row-action { opacity: 1; } }
.table .group-row td { block-size: 38px; background: var(--surface-2); font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--muted-foreground); }
.table-compact td { block-size: 46px; }
.cell-main { display: flex; align-items: center; gap: 10px; min-inline-size: 0; }
.cell-main .title { font-weight: var(--weight-medium); color: var(--foreground); }
.cell-main .sub { font-size: var(--text-xs); color: var(--muted-foreground); }
.table-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px var(--card-pad); border-block-start: 1px solid var(--border); font-size: var(--text-sm); color: var(--muted-foreground); }
.pager { display: flex; gap: 6px; }

/* Bar-backed rows: each row carries style="--share:NN%" and a soft bar fills that share.
   Fluid by default (never forced to 600px). data-tone on the table picks the bar tone. */
.table-bars tbody tr, .table-bars tbody tr:hover {
  --bar-bg: var(--primary-soft);
  background-image: linear-gradient(var(--bar-bg), var(--bar-bg)); background-repeat: no-repeat;
  background-size: var(--share, 0%) calc(100% - 8px); background-position: left center;
}
[dir="rtl"] .table-bars tbody tr { background-position: right center; }
.table-bars[data-tone] tbody tr { --bar-bg: color-mix(in oklch, var(--tile-bg), transparent 35%); }
.table-bars td { block-size: 44px; border-block-end-color: transparent; }
.table-bars .share { display: inline-block; min-inline-size: 44px; font-size: var(--text-xs); color: var(--muted-foreground); }

/* Toolbar + filter chip */
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px var(--card-pad); }
.toolbar .spacer { flex: 1; }
.toolbar.flush { padding: 0; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 6px; block-size: var(--control-h-sm); padding-inline: 10px; border-radius: var(--radius-sm);
  border: 1px dashed var(--border-strong); color: var(--muted-foreground); font-size: var(--text-sm); font-weight: var(--weight-medium);
}
.filter-chip:hover { background: var(--hover); color: var(--foreground); }
.filter-chip[data-active] { border-style: solid; border-color: color-mix(in oklch, var(--brand), transparent 55%); background: var(--primary-soft); color: var(--primary-soft-foreground); }
.filter-chip .icon { inline-size: 15px; block-size: 15px; }

/* List rows (inside cards) */
.list { display: flex; flex-direction: column; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px var(--card-pad); border-block-start: 1px solid var(--border); min-inline-size: 0; }
.list-row:first-child { border-block-start: 0; }
a.list-row:hover, button.list-row:hover { background: var(--hover); }
.list-row .meta { margin-inline-start: auto; display: flex; align-items: center; gap: 10px; color: var(--muted-foreground); font-size: var(--text-sm); flex: none; }
/* Provider / integration row: .icon-tile + text + .meta (status and actions). On phones the meta drops under the text. */
@media (max-width: 640px) {
  .list-row.provider { flex-wrap: wrap; }
  .list-row.provider .meta { inline-size: 100%; justify-content: space-between; padding-inline-start: 48px; }
}

/* Description list (key/value) */
.kv { display: grid; grid-template-columns: minmax(96px, auto) 1fr; gap: 10px 16px; font-size: var(--text-sm); }
.kv dt { color: var(--muted-foreground); }
.kv dd { color: var(--foreground); font-weight: var(--weight-medium); min-inline-size: 0; }

/* ── Popup: menu, popover, select list ─────────────────── */
.popup {
  position: absolute; z-index: 60; min-inline-size: 200px; padding: 5px;
  background: var(--popover); color: var(--popover-foreground);
  border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg);
  transform-origin: var(--transform-origin, top); opacity: 0; transform: translateY(-4px) scale(0.98); pointer-events: none; visibility: hidden;
  transition: opacity var(--dur-fast) var(--ease-out), transform var(--dur) var(--ease-out), visibility 0s linear var(--dur), display var(--dur) allow-discrete;
}
/* Closed popups leave layout entirely (no phantom scroll); allow-discrete keeps the exit fade */
.popup:not([data-open]) { display: none; }
.popup[data-open] { opacity: 1; transform: none; pointer-events: auto; visibility: visible; transition-delay: 0s; }
@starting-style { .popup[data-open] { opacity: 0; transform: translateY(-4px) scale(0.98); } }
.popup[data-side="top"] { inset-block-end: calc(100% + 6px); }
.popup:not([data-side="top"]) { inset-block-start: calc(100% + 6px); }
.popup[data-align="end"] { inset-inline-end: 0; } .popup:not([data-align="end"]) { inset-inline-start: 0; }
.popover-anchor { position: relative; display: inline-block; }

/* Date picker (core.js): .select-trigger.date-trigger + its .popup.date-pop calendar */
.date-trigger .date-value { display: inline-flex; align-items: center; gap: 8px; min-inline-size: 0; }
.date-trigger .date-value .icon { color: var(--muted-foreground); flex: none; }
.date-trigger[data-empty] .select-value { color: var(--muted-foreground); }
.popover-anchor > .popup.date-pop, .setting-row .control > .popover-anchor > .popup.date-pop { inline-size: 300px; max-inline-size: calc(100vw - 32px); padding: 0; }
.date-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-block-end: 1px solid var(--border); }
.cal { padding: 8px 10px 2px; }
.cal-nav { display: flex; align-items: center; justify-content: space-between; margin-block-end: 4px; }
.cal-title { font-size: var(--text-sm); font-weight: var(--weight-bold); }
.cal-grid { inline-size: 100%; border-collapse: collapse; table-layout: fixed; }
.cal-grid th { padding-block: 4px; font-size: 11px; font-weight: var(--weight-medium); color: var(--muted-foreground); text-align: center; }
.cal-grid td { padding: 1px; text-align: center; }
.cal-day { inline-size: 100%; max-inline-size: 38px; aspect-ratio: 1; border-radius: 10px; font-family: var(--font-num); font-size: var(--text-sm); font-variant-numeric: tabular-nums; color: var(--foreground); transition: background-color var(--dur-fast), color var(--dur-fast); }
.cal-day:hover:not(:disabled) { background: var(--hover); }
.cal-day[data-outside] { color: var(--subtle-foreground); }
.cal-day[data-today] { box-shadow: inset 0 0 0 1.5px var(--border-strong); font-weight: var(--weight-bold); }
.cal-day[aria-pressed="true"] { background: var(--primary); color: var(--primary-foreground); box-shadow: none; font-weight: var(--weight-bold); }
.cal-day:disabled { color: var(--subtle-foreground); opacity: 0.45; cursor: not-allowed; }
.date-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 12px 12px; }
.menu-item {
  display: flex; align-items: center; gap: 10px; inline-size: 100%; min-block-size: 34px; padding-inline: 10px; border-radius: 8px;
  font-size: var(--text-sm); color: var(--foreground); text-align: start; cursor: pointer; outline: none;
}
.menu-item .icon { inline-size: 16px; block-size: 16px; color: var(--muted-foreground); }
.menu-item:hover, .menu-item[data-highlighted], .menu-item:focus-visible { background: var(--hover); }
.menu-item.danger { color: var(--destructive-soft-foreground); } .menu-item.danger .icon { color: currentColor; }
.menu-item .shortcut { margin-inline-start: auto; color: var(--muted-foreground); font-size: var(--text-xs); }
.menu-item[data-selected]::after { content: ""; margin-inline-start: auto; inline-size: 6px; block-size: 6px; border-radius: 50%; background: var(--brand); }
.menu-label { padding: 8px 10px 4px; font-size: var(--text-xs); color: var(--muted-foreground); font-weight: var(--weight-medium); }
.menu-sep { block-size: 1px; background: var(--border); margin: 5px -5px; }
/* Menu whose items stack a title over a wrapping muted description (saved replies, templates) */
.reply-menu { inline-size: min(320px, calc(100vw - 48px)); }
.reply-menu .menu-item { flex-direction: column; align-items: flex-start; gap: 2px; padding-block: 8px; }
.reply-menu .menu-item .text-xs { color: var(--muted-foreground); white-space: normal; line-height: 1.5; }

/* Tooltip (CSS-only, keyboard-visible) */
[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip); position: absolute; inset-block-end: calc(100% + 8px); inset-inline-start: 50%; translate: -50% 0;
  padding: 5px 9px; border-radius: 8px; background: var(--foreground); color: var(--background);
  font-size: var(--text-xs); font-weight: var(--weight-medium); white-space: nowrap; line-height: 1.3;
  opacity: 0; pointer-events: none; transition: opacity var(--dur-fast) var(--ease-out); z-index: 80;
}
[dir="rtl"] [data-tip]::after { translate: 50% 0; }
[data-tip]:hover::after, [data-tip]:focus-visible::after { opacity: 1; transition-delay: 350ms; }

/* ── Dialog / sheet ────────────────────────────────────── */
.backdrop {
  position: fixed; inset: 0; z-index: 90; background: var(--overlay); backdrop-filter: blur(2px);
  opacity: 0; visibility: hidden; transition: opacity var(--dur) var(--ease-out), visibility 0s linear var(--dur);
}
.backdrop[data-open] { opacity: 1; visibility: visible; transition-delay: 0s; }
.dialog {
  position: fixed; z-index: 100; inset-block-start: 50%; inset-inline-start: 50%; translate: -50% -50%;
  inline-size: min(520px, calc(100vw - 32px)); max-block-size: calc(100dvh - 48px); overflow: auto;
  background: var(--popover); border: 1px solid var(--border); border-radius: var(--radius-xl); box-shadow: var(--shadow-lg);
  opacity: 0; scale: 0.97; visibility: hidden;
  transition: opacity var(--dur) var(--ease-out), scale var(--dur-slow) var(--ease-out), visibility 0s linear var(--dur-slow);
}
[dir="rtl"] .dialog { translate: 50% -50%; }
.dialog[data-open] { opacity: 1; scale: 1; visibility: visible; transition-delay: 0s; }
.dialog-header { display: flex; gap: 14px; align-items: flex-start; padding: 22px 22px 0; }
.dialog-title { font-size: var(--text-md); font-weight: var(--weight-bold); }
.dialog-body { padding: 16px 22px; }
.dialog-footer { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 22px; border-block-start: 1px solid var(--border); background: var(--surface-2); border-end-start-radius: var(--radius-xl); border-end-end-radius: var(--radius-xl); }
.dialog-close { margin-inline-start: auto; }
.dialog-header + .dialog-footer { margin-block-start: 18px; }

.sheet {
  position: fixed; z-index: 100; inset-block: 8px; inset-inline-end: 8px; inline-size: min(460px, calc(100vw - 16px));
  display: flex; flex-direction: column; background: var(--popover); border: 1px solid var(--border);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-lg);
  transform: translateX(calc(100% + 16px)); visibility: hidden;
  transition: transform var(--dur-slow) var(--ease-out), visibility 0s linear var(--dur-slow);
}
[dir="rtl"] .sheet { transform: translateX(calc(-100% - 16px)); }
.sheet.from-start { inset-inline-end: auto; inset-inline-start: 8px; transform: translateX(calc(-100% - 16px)); }
[dir="rtl"] .sheet.from-start { transform: translateX(calc(100% + 16px)); }
.sheet-section { display: flex; flex-direction: column; gap: 10px; }
.sheet-section > h3 { font-size: var(--text-sm); font-weight: var(--weight-bold); }
/* Bottom sheet (phones): .sheet.from-bottom */
.sheet.from-bottom, [dir="rtl"] .sheet.from-bottom {
  inset-block: auto 8px; inset-inline: 8px; inline-size: auto; max-block-size: calc(100dvh - 48px); transform: translateY(calc(100% + 16px));
}
.sheet[data-open] { transform: none !important; visibility: visible; transition-delay: 0s; }
.sheet-header { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-block-end: 1px solid var(--border); }
.sheet-body { flex: 1; overflow: auto; padding: 20px; display: flex; flex-direction: column; gap: 20px; }
.sheet-footer { display: flex; gap: 8px; padding: 14px 20px; border-block-start: 1px solid var(--border); }

/* ── Toast ─────────────────────────────────────────────── */
.toaster { position: fixed; z-index: 120; inset-block-end: 20px; inset-inline-end: 20px; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 10px; min-inline-size: 280px; max-inline-size: 380px; padding: 12px 14px;
  background: var(--popover); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg);
  font-size: var(--text-sm); pointer-events: auto; animation: toast-in var(--dur-slow) var(--ease-out);
}
.toast .icon { color: var(--success); }
.toast.error .icon { color: var(--destructive); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }

/* ── Alert / banner ────────────────────────────────────── */
.alert { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: 14px; background: var(--alert-bg, var(--info-soft)); color: var(--alert-fg, var(--info-soft-foreground)); font-size: var(--text-sm); }
.alert .alert-title { font-weight: var(--weight-bold); color: inherit; }
.alert p { color: var(--foreground); opacity: 0.85; }
.alert.warning { --alert-bg: var(--warning-soft); --alert-fg: var(--warning-soft-foreground); }
.alert.danger { --alert-bg: var(--destructive-soft); --alert-fg: var(--destructive-soft-foreground); }
.alert.success { --alert-bg: var(--success-soft); --alert-fg: var(--success-soft-foreground); }
.alert.brand { --alert-bg: var(--primary-soft); --alert-fg: var(--primary-soft-foreground); }

/* ── Empty / error states ──────────────────────────────── */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; padding: 48px 24px; }
.empty .art { position: relative; display: grid; place-items: center; inline-size: 72px; block-size: 72px; border-radius: 22px; background: var(--tile-bg, var(--primary-soft)); color: var(--tile-fg, var(--primary-soft-foreground)); margin-block-end: 6px; rotate: -4deg; box-shadow: var(--shadow-sm); }
.empty .art .icon { inline-size: 30px; block-size: 30px; rotate: 4deg; }
.empty .art::before { content: ""; position: absolute; inset: -10px; border-radius: 28px; border: 1.5px dashed color-mix(in oklch, var(--tile-fg, var(--brand)), transparent 65%); rotate: 8deg; }
.empty h3 { font-size: var(--text-md); }
.empty p { max-inline-size: 42ch; color: var(--muted-foreground); font-size: var(--text-sm); }
.empty .actions { display: flex; gap: 8px; margin-block-start: 8px; flex-wrap: wrap; justify-content: center; }
/* First-time empty state: starting-point cards under the one primary action */
.starter-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; inline-size: min(760px, 100%); margin-block-start: 20px; text-align: start; }
.starter-grid > .starter { display: flex; gap: 12px; align-items: flex-start; padding: 14px; }
@media (max-width: 720px) { .starter-grid { grid-template-columns: minmax(0, 1fr); } }

/* ── Skeleton ──────────────────────────────────────────── */
.skeleton { --sk: var(--muted); --sk-hi: color-mix(in oklch, var(--muted), var(--foreground) 7%); border-radius: 8px; background: linear-gradient(90deg, var(--sk) 0%, var(--sk-hi) 50%, var(--sk) 100%) 0 0 / 200% 100%; animation: shimmer 1.6s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── Stepper (for real sequences only) ─────────────────── */
.steps { display: flex; flex-direction: column; gap: 2px; }
.step { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; font-size: var(--text-sm); color: var(--muted-foreground); }
.step .marker { display: grid; place-items: center; inline-size: 22px; block-size: 22px; border-radius: 50%; border: 1.5px solid var(--border-strong); font-family: var(--font-num); font-size: 11px; font-weight: var(--weight-bold); flex: none; background: var(--card); }
.step[data-state="done"] { color: var(--foreground); }
.step[data-state="done"] .marker { background: var(--success); border-color: var(--success); color: var(--success-foreground); }
.step[data-state="current"] { background: var(--card); color: var(--foreground); font-weight: var(--weight-medium); box-shadow: var(--shadow-sm), 0 0 0 1px var(--border); }
.steps.horizontal { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 6px; }
.steps.flush .step[data-state="current"] { background: none; box-shadow: none; }
.step[data-state="current"] .marker { border-color: var(--brand); color: var(--primary-soft-foreground); background: var(--primary-soft); }
.step .marker .icon { inline-size: 12px; block-size: 12px; stroke-width: 3; }
/* Marker with <span class="n">1</span> + check icon: the number until done, then the check */
.step:not([data-state="done"]) .marker:has(.n) .icon, .step[data-state="done"] .marker .n { display: none; }

/* ── Contextual bars ───────────────────────────────────── */
.floating-bar {
  position: fixed; z-index: 70; inset-block-end: 20px; inset-inline-start: 50%; translate: -50% 0;
  display: flex; align-items: center; gap: 6px; padding-block: 6px; padding-inline: 14px 6px; border-radius: 14px;
  background: oklch(0.24 0.012 55); color: oklch(0.96 0.005 75); box-shadow: var(--shadow-lg); font-size: var(--text-sm);
}
[dir="rtl"] .floating-bar { translate: 50% 0; }
.floating-bar .btn-ghost { color: oklch(0.85 0.01 70); } .floating-bar .btn-ghost:hover { background: oklch(1 0 0 / 0.1); color: white; }
.floating-bar .sep { inline-size: 1px; block-size: 20px; background: oklch(1 0 0 / 0.15); margin-inline: 4px; }
.dark .floating-bar { background: oklch(0.32 0.01 60); border: 1px solid var(--border-strong); }

.save-bar {
  position: sticky; inset-block-end: 12px; z-index: 30; display: flex; align-items: center; gap: 10px;
  margin-block-start: var(--section-gap); padding-block: 10px; padding-inline: 16px 10px; border-radius: 14px;
  background: oklch(0.24 0.012 55); color: oklch(0.96 0.005 75); box-shadow: var(--shadow-lg); font-size: var(--text-sm);
}
.save-bar .grow { color: oklch(0.85 0.01 70); }
@media (max-width: 600px) { .save-bar .grow { font-size: var(--text-xs); line-height: 1.35; } }
.save-bar .btn-ghost { color: oklch(0.85 0.01 70); } .save-bar .btn-ghost:hover { background: oklch(1 0 0 / 0.1); color: white; }
.dark .save-bar { background: oklch(0.32 0.01 60); border: 1px solid var(--border-strong); }
.save-bar:not([hidden]) { animation: save-in var(--dur-slow) var(--ease-out); }
@keyframes save-in { from { opacity: 0; transform: translateY(12px); } }

.separator { block-size: 1px; background: var(--border); border: 0; }
.separator.vertical { inline-size: 1px; block-size: 20px; }

/* ── Promoted patterns (first built page-locally, now shared) ──────────── */

/* Course / product cover: soft tone + dot pattern + floating icon tile. Set data-tone on .cover. */
.cover {
  position: relative; block-size: 132px; display: grid; place-items: center; overflow: hidden;
  border-start-start-radius: calc(var(--radius-lg) - 1px); border-start-end-radius: calc(var(--radius-lg) - 1px);
  background: radial-gradient(circle, color-mix(in oklch, var(--tile-fg, var(--brand)), transparent 78%) 1.2px, transparent 1.8px) 0 0 / 14px 14px, var(--tile-bg, var(--primary-soft));
  color: var(--tile-fg, var(--primary-soft-foreground));
}
.cover::after { content: ""; position: absolute; inline-size: 150px; block-size: 150px; border-radius: 50%; background: radial-gradient(circle, color-mix(in oklch, var(--card), transparent 30%), transparent 70%); }
.cover .cover-icon { position: relative; z-index: 1; display: grid; place-items: center; inline-size: 64px; block-size: 64px; border-radius: 20px; background: var(--card); color: var(--tile-fg, var(--brand)); box-shadow: var(--shadow-md); rotate: -4deg; }
.cover .cover-icon .icon { inline-size: 30px; block-size: 30px; rotate: 4deg; }
/* Status badge pinned on a cover (course, product, path cards) */
.cover .status { position: absolute; z-index: 1; inset-block-start: 12px; inset-inline-start: 12px; background: var(--card); box-shadow: var(--shadow-xs); }
.cover.sm { block-size: 96px; } .cover.sm .cover-icon { inline-size: 48px; block-size: 48px; border-radius: 15px; } .cover.sm .cover-icon .icon { inline-size: 22px; block-size: 22px; }

/* Course card: .card.course-card > .cover + .course-body(.card-title, .course-meta, .course-foot) */
.course-card { position: relative; display: flex; flex-direction: column; }
.course-card:has(.popup[data-open]) { z-index: 5; }
.course-card .card-menu { position: absolute; z-index: 2; inset-block-start: 10px; inset-inline-end: 10px; }
.course-card .card-menu > .btn { background: var(--card); box-shadow: var(--shadow-xs); }
.course-card[data-status="archived"] .cover { filter: saturate(0.2); }
.course-body { display: flex; flex-direction: column; gap: 10px; padding: 14px 16px 16px; flex: 1; }
.course-body .card-title a:hover { color: var(--primary-soft-foreground); }
.course-meta { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; font-size: var(--text-xs); color: var(--muted-foreground); }
.course-meta > span { display: inline-flex; align-items: center; gap: 5px; }
.course-foot { display: flex; align-items: center; gap: 8px; margin-block-start: auto; padding-block-start: 12px; border-block-start: 1px solid var(--border); }
.course-foot .price { margin-inline-start: auto; font-weight: var(--weight-bold); font-size: var(--text-base); white-space: nowrap; }
.course-foot .price .unit { font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--muted-foreground); margin-inline-start: 3px; }
.course-foot .was { font-size: var(--text-xs); color: var(--muted-foreground); text-decoration: line-through; font-family: var(--font-num); }

/* Prototype-only control strip (switch between filled and empty states); never ships */
.proto-note { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; border: 1px dashed var(--border-strong); border-radius: 12px; color: var(--muted-foreground); font-size: var(--text-xs); }
.proto-note .btn { margin-inline-start: auto; }

/* Dropzone for uploads (video, files, images) */
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 26px 16px; text-align: center;
  border: 1.5px dashed var(--border-strong); border-radius: 14px; background: var(--surface-2);
  transition: border-color var(--dur-fast), background-color var(--dur-fast);
}
.dropzone:hover, .dropzone[data-dragging] { border-color: var(--brand); background: color-mix(in oklch, var(--primary-soft), transparent 50%); }

/* Dashed "add" affordance (add section, add question, add block) */
.add-dashed {
  display: flex; align-items: center; justify-content: center; gap: 8px; inline-size: 100%; min-block-size: 52px;
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius-lg); color: var(--muted-foreground); font-size: var(--text-sm); font-weight: var(--weight-medium);
  transition: border-color var(--dur-fast), color var(--dur-fast), background-color var(--dur-fast);
}
.add-dashed:hover { border-color: var(--brand); color: var(--primary-soft-foreground); background: color-mix(in oklch, var(--primary-soft), transparent 50%); }

/* Browser frame for storefront / template / page previews */
.browser { border-radius: 14px; border: 1px solid var(--border); background: var(--surface-2); overflow: hidden; box-shadow: var(--shadow-md); }
.browser-bar { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-block-end: 1px solid var(--border); }
.browser-bar .lights { display: flex; gap: 6px; direction: ltr; }
.browser-bar .lights i { inline-size: 10px; block-size: 10px; border-radius: 50%; background: var(--border-strong); }
.browser-bar .lights i:nth-child(1) { background: oklch(0.7 0.17 25); }
.browser-bar .lights i:nth-child(2) { background: oklch(0.8 0.14 80); }
.browser-bar .lights i:nth-child(3) { background: oklch(0.72 0.15 150); }
.browser-bar .address { flex: 1; display: flex; justify-content: center; }
.browser-bar .address span { display: inline-flex; align-items: center; gap: 6px; block-size: 24px; padding-inline: 12px; border-radius: 999px; background: var(--card); border: 1px solid var(--border); font-size: var(--text-xs); color: var(--muted-foreground); direction: ltr; }

/* Person: name over an LTR email/phone that still aligns to the start in RTL */
.person { display: flex; flex-direction: column; align-items: flex-start; min-inline-size: 0; }
.person .name { font-weight: var(--weight-medium); color: var(--foreground); }
.person .ltr { font-size: var(--text-xs); color: var(--muted-foreground); }

/* Totals list (orders, invoices, checkout summaries) */
.totals { display: flex; flex-direction: column; gap: 8px; font-size: var(--text-sm); }
.totals > div { display: flex; justify-content: space-between; gap: 12px; }
.totals dt, .totals .k { color: var(--muted-foreground); }
.totals .grand { padding-block-start: 10px; border-block-start: 1px dashed var(--border-strong); font-weight: var(--weight-bold); font-size: var(--text-md); }

/* Form extras */
.chips-input { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-block-size: var(--control-h); padding: 6px 8px; background: var(--card); border: 1px solid var(--input); border-radius: var(--radius-md); box-shadow: var(--shadow-xs); }
.chips-input:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in oklch, var(--brand), transparent 82%); }
.chips-input > input { flex: 1 1 120px; min-inline-size: 80px; border: 0; background: none; outline: none; font-size: var(--text-sm); color: var(--foreground); }
.chips-input .tag button { display: inline-grid; place-items: center; margin-inline-start: 2px; border-radius: 4px; opacity: 0.7; }
.chips-input .tag button:hover { opacity: 1; }
.otp { display: flex; align-items: center; gap: 8px; direction: ltr; }
.otp .input { flex: 1 1 0; min-inline-size: 0; block-size: 56px; padding: 0; text-align: center; font-family: var(--font-num); font-size: var(--text-xl); font-weight: var(--weight-medium); caret-color: var(--brand); }
.otp .sep { flex: none; inline-size: 8px; block-size: 2px; border-radius: 1px; background: var(--border-strong); }
.otp[data-state="success"] .input { border-color: var(--success); }
.otp[data-state="error"] { animation: shake 360ms var(--ease-out); }
.otp[data-state="error"] .input { border-color: var(--destructive); }
@keyframes shake { 20%, 60% { translate: -5px 0; } 40%, 80% { translate: 5px 0; } }
@media (max-width: 380px) { .otp { gap: 6px; } .otp .input { block-size: 48px; } }
.strength { display: flex; flex-direction: column; gap: 6px; }
.strength .s-label { color: var(--foreground); font-weight: var(--weight-medium); }
.strength .bars { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
.strength .bars i { block-size: 4px; border-radius: 99px; background: var(--muted); transition: background-color var(--dur) var(--ease-out); }
.strength[data-score="1"] .bars i:nth-child(-n+1) { background: var(--destructive); }
.strength[data-score="2"] .bars i:nth-child(-n+2) { background: var(--warning); }
.strength[data-score="3"] .bars i:nth-child(-n+3) { background: var(--brand); }
.strength[data-score="4"] .bars i { background: var(--success); }

/* Content helpers */
.stars { display: inline-flex; gap: 1px; color: var(--warning); direction: ltr; flex: none; }
.stars .icon { inline-size: 15px; block-size: 15px; fill: currentColor; }
.stars .icon.off { color: var(--border-strong); }
.code { display: inline-flex; align-items: center; gap: 6px; block-size: 26px; padding-inline: 8px; border-radius: var(--radius-sm); border: 1px dashed var(--border-strong); background: var(--surface-2); font-family: var(--font-num); font-size: var(--text-sm); font-weight: var(--weight-medium); direction: ltr; }
.course-thumb { display: grid; place-items: center; flex: none; inline-size: 40px; block-size: 40px; border-radius: 12px; background: var(--tile-bg, var(--primary-soft)); color: var(--tile-fg, var(--primary-soft-foreground)); }
.course-thumb.lg { inline-size: 44px; block-size: 44px; }
.file-chip { display: inline-flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; border: 1px solid var(--border); background: var(--card); font-size: var(--text-sm); max-inline-size: 100%; text-align: start; }
a.file-chip, button.file-chip { transition: border-color var(--dur-fast); }
a.file-chip:hover, button.file-chip:hover { border-color: var(--border-strong); }
.file-chip.block { display: flex; inline-size: 100%; }
.file-chip[data-uploading] { background: var(--surface-2); }
.day-sep { display: flex; align-items: center; gap: 12px; color: var(--muted-foreground); font-size: var(--text-xs); font-weight: var(--weight-medium); }
.day-sep::before, .day-sep::after { content: ""; flex: 1; block-size: 1px; background: var(--border); }
.presence { position: relative; display: inline-flex; }
.presence[data-online]::after { content: ""; position: absolute; inset-block-end: 0; inset-inline-end: 0; inline-size: 10px; block-size: 10px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 2px var(--card); }
.avatar.unassigned { background: transparent; border: 1.5px dashed var(--border-strong); color: var(--muted-foreground); }
.split { display: inline-flex; align-items: stretch; }
.split > .btn:first-child { border-start-end-radius: 0; border-end-end-radius: 0; }
.split > .popover-anchor > .btn, .split > .btn:last-child:not(:first-child) { border-start-start-radius: 0; border-end-start-radius: 0; margin-inline-start: 1px; }
.serp { display: flex; flex-direction: column; gap: 2px; padding: 14px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.serp .serp-url { font-size: var(--text-xs); color: var(--muted-foreground); direction: ltr; text-align: start; }
.serp .serp-title { font-size: var(--text-base); color: var(--info-soft-foreground); font-weight: var(--weight-medium); }
.serp .serp-desc { font-size: var(--text-sm); color: var(--muted-foreground); }
.serp .site { display: flex; align-items: center; gap: 8px; font-size: var(--text-xs); color: var(--foreground); }
.serp .site .favicon { display: grid; place-items: center; flex: none; inline-size: 22px; block-size: 22px; border-radius: 50%; background: var(--card); border: 1px solid var(--border); font-size: 11px; font-weight: var(--weight-bold); color: var(--primary-soft-foreground); }
.serp .site + .serp-title { margin-block-start: 6px; }
.flag { font-family: "Noto Color Emoji", "Apple Color Emoji", "Segoe UI Emoji", sans-serif; font-size: 18px; line-height: 1; }
/* Overlapping colour dots (theme or template palette preview) */
.swatch-dots { display: inline-flex; }
.swatch-dots i { inline-size: 16px; block-size: 16px; border-radius: 50%; background: var(--tile-fg, var(--brand)); box-shadow: 0 0 0 2px var(--card); }
.swatch-dots i + i { margin-inline-start: -4px; }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { rotate: 360deg; } }

/* Long-form writing (blog, text pages, lesson articles) */
.prose { display: flex; flex-direction: column; gap: 14px; font-size: 1.0625rem; line-height: 1.95; max-inline-size: 72ch; }
html[lang="en"] .prose { line-height: 1.75; }
.prose h2 { font-size: var(--text-lg); margin-block-start: 10px; }
.prose h3 { font-size: var(--text-md); }
.prose ul, .prose ol { padding-inline-start: 1.4em; display: flex; flex-direction: column; gap: 6px; }
.prose li::marker { color: var(--brand); }
.prose blockquote { padding-block: 6px; padding-inline-start: 16px; border-inline-start: 3px solid var(--brand); color: var(--muted-foreground); }
.format-bar { position: sticky; inset-block-start: var(--topbar-h); z-index: 20; display: flex; align-items: center; gap: 2px; flex-wrap: wrap; padding: 6px 10px; border-radius: 12px; background: color-mix(in oklch, var(--background), transparent 6%); backdrop-filter: blur(10px); border: 1px solid var(--border); box-shadow: var(--shadow-xs); }
.format-bar .separator.vertical { margin-inline: 4px; }
.format-bar .btn[aria-pressed="true"] { background: var(--selected); color: var(--foreground); }
.format-bar .end { margin-inline-start: auto; display: flex; gap: 2px; }
/* Writing surface: .sheet-paper holds .title-input (+ .subtitle-input) and .prose; .writer-foot shows counts and autosave */
.sheet-paper { inline-size: 100%; max-inline-size: 700px; margin-inline: auto; padding: 32px 28px 20px; display: flex; flex-direction: column; gap: 10px; }
.title-input, .subtitle-input { inline-size: 100%; padding: 0; border: 0; background: none; outline: none; color: var(--foreground); resize: none; overflow: hidden; field-sizing: content; font: inherit; }
.title-input { font-size: var(--text-2xl); font-weight: var(--weight-bold); line-height: 1.35; }
.subtitle-input { font-size: var(--text-md); color: var(--muted-foreground); line-height: 1.6; }
.title-input::placeholder, .subtitle-input::placeholder { color: var(--muted-foreground); }
.title-input:focus-visible, .subtitle-input:focus-visible { outline: none; }
.writer-foot { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 12px var(--card-pad); border-block-start: 1px solid var(--border); font-size: var(--text-xs); color: var(--muted-foreground); }
.writer-foot > span { display: inline-flex; align-items: center; gap: 6px; }
.writer-foot .end { margin-inline-start: auto; }
@media (max-width: 720px) {
  .sheet-paper { padding: 24px 16px 16px; }
  .title-input { font-size: var(--text-xl); }
  .writer-foot .end { margin-inline-start: 0; }
}

/* ── Unification layer (audit round 2) ────────────────────────────────── */

/* Editor family: every editor (course, path, quiz, product, blog, text page) shares
   head → ".desc.autosave" saved line, actions "معاينة" (outline) + "نشر <entity>" (primary, rocket),
   unsaved edits → .save-bar, and an aside whose first card is "الحالة". */
.desc.autosave, .autosave { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.autosave > .icon, .autosave > svg { flex: none; color: var(--success); inline-size: 15px; block-size: 15px; }
.tabs [role="tab"]:disabled, .tabs [role="tab"][aria-disabled="true"], .segmented > [aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

/* Readiness card (publish checklist with ring) — course, path, product, quiz editors */
.readiness-head { display: flex; align-items: center; gap: 12px; }
.readiness-head .ring { --size: 46px; }

/* Long-form writing scaffold (blog + text pages); title/subtitle/foot rules live with .sheet-paper above */
.writer { display: flex; flex-direction: column; }
.writer-col { display: flex; flex-direction: column; gap: 10px; min-inline-size: 0; }

/* Composer (messages, ticket replies, review replies) */
.composer { display: flex; flex-direction: column; border: 1px solid var(--input); border-radius: 14px; background: var(--card); box-shadow: var(--shadow-xs); transition: border-color var(--dur-fast), box-shadow var(--dur-fast), background-color var(--dur-fast); }
.composer:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in oklch, var(--brand), transparent 82%); }
.composer textarea { display: block; inline-size: 100%; min-block-size: 44px; padding: 11px 14px 4px; border: 0; background: none; resize: vertical; outline: none; font-size: var(--text-base); line-height: 1.65; }
.composer textarea::placeholder { color: var(--muted-foreground); }
.composer-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 12px 0; }
.composer-tools { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; padding: 4px 6px 6px; }
.composer-tools .spacer { flex: 1; }
.composer-tools .hint { font-size: var(--text-xs); color: var(--muted-foreground); display: inline-flex; align-items: center; gap: 4px; margin-inline-end: 8px; }
.composer[data-mode="note"] { border-color: color-mix(in oklch, var(--warning), transparent 45%); background: color-mix(in oklch, var(--warning-soft), var(--card) 40%); }
.composer[data-mode="note"]:focus-within { box-shadow: 0 0 0 3px color-mix(in oklch, var(--warning), transparent 80%); }

/* Timeline marker: one size, round, for event rows (tickets, audit log, order history) */
.icon-tile.round { inline-size: 28px; block-size: 28px; border-radius: 50%; }
.icon-tile.round .icon { inline-size: 14px; block-size: 14px; }

/* Grid-list footer, the card-less sibling of .table-footer */
.results-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; color: var(--muted-foreground); font-size: var(--text-sm); }

/* Two-column form rows */
.field-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 640px) { .field-row { grid-template-columns: minmax(0, 1fr); } }

/* Secondary table columns step aside on phones so the name + status always fit */
@media (max-width: 600px) { .hide-sm { display: none !important; } }

/* Menu item trailing count */
.menu-item .count { margin-inline-start: auto; font-family: var(--font-num); font-size: var(--text-xs); color: var(--muted-foreground); }

/* Round-3 shared fixes */
/* Phones: tables that hide secondary columns drop the 600px minimum and tighten cells */
@media (max-width: 600px) {
  .table-wrap > .table:has(.hide-sm) { min-inline-size: 0; }
  .table.fit-sm th, .table.fit-sm td { padding-inline: 6px; }
  .table.fit-sm th:first-child, .table.fit-sm td:first-child { padding-inline-start: 12px; }
  .table.fit-sm th:last-child, .table.fit-sm td:last-child { padding-inline-end: 8px; }
  .table.fit-sm .cell-main > :first-child:is(.avatar, .icon-tile, .course-thumb) { display: none; }
  .table .person { max-inline-size: 132px; }
  .table .person > * { max-inline-size: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
.show-sm { display: none; }
@media (max-width: 600px) { .show-sm { display: revert; } }
.composer .hint { font-size: var(--text-xs); color: var(--muted-foreground); display: inline-flex; align-items: center; gap: 6px; }
.dialog-header + .dialog-body[hidden] + .dialog-footer, .dialog-header + .dialog-footer { margin-block-start: 18px; }

/* Overflowing tab strips fade at the inline end, so it is clear more tabs scroll into view */
@media (max-width: 720px) {
  .segmented { mask-image: linear-gradient(to var(--fade-to, left), #000 calc(100% - 28px), transparent); }
  [dir="ltr"] .segmented { --fade-to: right; }
  .segmented:has(> :last-child[data-selected], > :last-child[aria-selected="true"]) { mask-image: none; }
}

/* Attention stat tiles: the action link ("Message them", "Grade now") sits at the end of the meta line */
.stat-meta > .btn-link { margin-inline-start: auto; }

/* ── Page layout (shared by every area shell) ─────────────
   .page > .page-head (.titles, .desc, .actions, .title-row), .detail-layout, .settings-layout,
   .desktop-only / .mobile-only, skip link, touch-target sizes. Area shells own the chrome around .page. */
.mobile-only { display: none !important; }
.page { inline-size: 100%; max-inline-size: var(--content-max); margin-inline: auto; padding: 8px var(--page-pad) 40px; display: flex; flex-direction: column; gap: var(--section-gap); }
.page.narrow { max-inline-size: 880px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; padding-block-start: 12px; }
.page-head .titles { display: flex; flex-direction: column; gap: 4px; min-inline-size: 0; flex: 1 1 320px; }
.page-head .desc { color: var(--muted-foreground); font-size: var(--text-sm); }
.page-head .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
/* Detail / editor pages: h1 entity name with its status badge beside it */
.page-head .title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* Two-column detail layout */
.detail-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--section-gap); align-items: start; }
.detail-layout > aside { position: sticky; inset-block-start: calc(var(--topbar-h) + 12px); display: flex; flex-direction: column; gap: var(--grid-gap); max-block-size: calc(100dvh - var(--topbar-h) - 28px); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; margin: -4px; padding: 4px; }
/* Tall asides fade at the bottom while more cards sit below the fold (scroll-driven, no JS) */
@supports (animation-timeline: scroll()) {
  .detail-layout > aside:not(.static) { animation: aside-fade linear both; animation-timeline: scroll(self); }
  @keyframes aside-fade { from { mask-image: linear-gradient(#000 calc(100% - 40px), transparent); } to { mask-image: none; } }
}
.detail-layout > aside.static { position: static; max-block-size: none; overflow: visible; }

/* Settings layout: shared sub-nav (injected from SETTINGS_NAV) + content column */
.settings-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 32px; align-items: start; }
.settings-nav { position: sticky; inset-block-start: calc(var(--topbar-h) + 12px); display: flex; flex-direction: column; gap: 2px; }
.settings-nav .nav-item[aria-current="page"] { background: var(--card); box-shadow: var(--shadow-sm), 0 0 0 1px var(--border); }
.settings-nav .nav-item[aria-current="page"] .icon { color: var(--brand); }
.settings-nav-group { display: flex; flex-direction: column; gap: 2px; }
.settings-nav-group + .settings-nav-group { margin-block-start: 14px; }
.settings-nav .nav-label { padding: 0 10px 4px; font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--muted-foreground); }
.settings-content { display: flex; flex-direction: column; gap: var(--section-gap); min-inline-size: 0; }
.settings-content > .card { scroll-margin-block-start: calc(var(--topbar-h) + 16px); }
@media (max-width: 1023px) {
  .settings-layout { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .settings-nav { position: static; flex-direction: row; overflow-x: auto; scrollbar-width: none; margin-inline: calc(var(--page-pad) * -1); padding-inline: var(--page-pad); padding-block: 2px 4px; }
  .settings-nav .nav-item { flex: none; }
  /* Sideways strip: groups flow inline, divided by a hairline instead of a label */
  .settings-nav-group { display: contents; }
  .settings-nav .nav-label { display: none; }
  .settings-nav-group + .settings-nav-group::before { content: ""; flex: none; align-self: center; inline-size: 1px; block-size: 18px; margin-inline: 4px; background: var(--border); }
}

/* ── Skip link: hidden until focused ───────────────────── */
.skip-link {
  position: fixed; z-index: 200; inset-block-start: 10px; inset-inline-start: 10px; padding: 10px 16px;
  border-radius: var(--radius-md); background: var(--primary); color: var(--primary-foreground);
  font-weight: var(--weight-medium); box-shadow: var(--shadow-lg); translate: 0 -160%; transition: translate var(--dur) var(--ease-out);
}
.skip-link:not(:focus-visible) { box-shadow: none; }
.skip-link:focus-visible { translate: 0 0; outline: 2px solid var(--ring); outline-offset: 2px; }
.page:focus { outline: none; }

/* Touch screens: controls grow to a comfortable 40px+ target */
@media (pointer: coarse) {
  :root { --control-h-xs: 34px; --control-h-sm: 40px; --control-h: 44px; --control-h-lg: 48px; }
}
@media (max-width: 1023px) {
  :root { --page-pad: 16px; }
  .desktop-only { display: none !important; }
  .mobile-only { display: inline-flex !important; }
  .detail-layout { grid-template-columns: minmax(0, 1fr); }
  .detail-layout > aside { position: static; max-block-size: none; overflow: visible; }
  .page-head .actions { inline-size: 100%; }
}

/* Mobile bottom bar (up to 5 destinations). Area shells inject it and reserve its height. */
.bottom-bar { display: none; }
@media (max-width: 1023px) {
  .bottom-bar {
    position: fixed; z-index: 50; inset-inline: 0; inset-block-end: 0; display: grid; grid-template-columns: repeat(5, 1fr);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); background: color-mix(in oklch, var(--background), transparent 8%);
    backdrop-filter: blur(12px); border-block-start: 1px solid var(--border);
  }
  .bottom-bar a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding-block: 6px; border-radius: 10px; font-size: 11px; font-weight: var(--weight-medium); color: var(--muted-foreground); }
  .bottom-bar a[aria-current="page"] { color: var(--foreground); }
  .bottom-bar a[aria-current="page"] .icon { color: var(--brand); }
}

/* Brand switcher swatch (academy colour presets, css/brands.css) */
.brand-swatch { flex: none; inline-size: 14px; block-size: 14px; border-radius: 50%; background: var(--swatch); box-shadow: inset 0 0 0 1px oklch(0 0 0 / 0.12); }
.brand-menu { inline-size: 220px; }
.brand-menu .menu-item[aria-checked="true"]::after { content: "✓"; margin-inline-start: auto; color: var(--primary-soft-foreground); font-weight: var(--weight-bold); }

/* ── Lesson trail ─────────────────────────────────────────
   One dot per lesson (or question): filled when done, ringed where the learner is, hollow ahead,
   dashed when locked, red when wrong. <b> between dots is a section break. Sizes: .sm, default, .lg.
   Write the dots by hand, or let core.js build them: <div class="trail" data-trail="13/24" data-breaks="5,11"
   data-locked-from="21" data-wrong="3,7"></div> (1-based positions; the current dot follows the last done one). */
.trail { --d: 9px; --g: 5px; display: flex; flex-wrap: wrap; align-items: center; gap: var(--g); }
.trail i { flex: none; inline-size: var(--d); block-size: var(--d); border-radius: 50%; box-shadow: inset 0 0 0 1.5px var(--border-strong); }
.trail i[data-done] { background: var(--brand); box-shadow: none; }
.trail i[data-current] { background: var(--card); box-shadow: inset 0 0 0 2.5px var(--brand), 0 0 0 3px color-mix(in oklch, var(--brand), transparent 78%); }
.trail i[data-locked] { box-shadow: none; outline: 1.5px dashed var(--border-strong); outline-offset: -1.5px; }
.trail i[data-wrong] { background: var(--destructive); box-shadow: none; }
.trail b { flex: none; inline-size: 10px; block-size: 1.5px; margin-inline: 2px; background: var(--border-strong); border-radius: 2px; }
.trail.sm { --d: 7px; --g: 4px; }
.trail.lg { --d: 12px; --g: 6px; }
@media (prefers-reduced-motion: no-preference) {
  .trail i[data-current] { animation: trail-here 2.4s var(--ease-out) infinite; }
  @keyframes trail-here { 0%, 100% { box-shadow: inset 0 0 0 2.5px var(--brand), 0 0 0 3px color-mix(in oklch, var(--brand), transparent 78%); }
    50% { box-shadow: inset 0 0 0 2.5px var(--brand), 0 0 0 6px color-mix(in oklch, var(--brand), transparent 90%); } }
}
.trail-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: var(--text-xs); color: var(--muted-foreground); }
.trail-legend > span { display: inline-flex; align-items: center; gap: 6px; }

/* ── Affiliate ────────────────────────────────────────────
   Shared by platform/affiliates, platform/referrals and student/affiliate.
   .link-box: a referral link or code with its copy button (.url is always LTR).
   .bal-panes: the three Affara balances side by side (on hold, available, paid or reserved), over the dot motif. */
.link-box { display: flex; align-items: center; gap: 8px; min-inline-size: 0; min-block-size: var(--control-h-lg); padding: 4px; padding-inline-start: 14px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-2); }
.link-box .url { flex: 1; min-inline-size: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; unicode-bidi: isolate; text-align: start; font-family: var(--font-num); font-size: var(--text-sm); font-weight: var(--weight-medium); }
.link-box .url .dim { color: var(--muted-foreground); font-weight: var(--weight-regular); }
.bal-panes { position: relative; overflow: hidden; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.bal-panes::before {
  content: ""; position: absolute; inset-block: 0; inset-inline-end: 0; inline-size: 35%; pointer-events: none;
  background: radial-gradient(circle, color-mix(in oklch, var(--brand), transparent 80%) 1.2px, transparent 1.8px) 0 0 / 14px 14px;
  mask-image: linear-gradient(to right, black, transparent);
}
[dir="ltr"] .bal-panes::before { mask-image: linear-gradient(to left, black, transparent); }
.bal-pane { position: relative; display: flex; flex-direction: column; gap: 8px; padding: 20px var(--card-pad); min-inline-size: 0; }
.bal-pane + .bal-pane { border-inline-start: 1px solid var(--border); }
.bal-amount { font-family: var(--font-num); font-size: var(--text-2xl); font-weight: var(--weight-bold); line-height: 1.1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bal-amount .unit { font-size: var(--text-base); font-weight: var(--weight-medium); color: var(--muted-foreground); letter-spacing: 0; margin-inline-start: 6px; }
@media (max-width: 800px) {
  .bal-panes { grid-template-columns: minmax(0, 1fr); }
  .bal-pane + .bal-pane { border-inline-start: 0; border-block-start: 1px solid var(--border); }
}
