/* core.css — Shabani Mtowe unified interface system, v3 (v2: dashboard components from the owner's reference designs; v3: section views with a bottom dock, languages).
   Shared by every product. Holds structure, spacing, type, motion and components.
   Colors are NOT here: each product defines its --color-* tokens in styles.css. */

/* ---- Motion tokens (from advanced-motion-interface-engineering; values are starting points) ---- */
:root {
  --motion-duration-instant: 80ms;   /* press feedback */
  --motion-duration-fast: 150ms;     /* hover, focus, checkbox, exits of small elements */
  --motion-duration-base: 240ms;     /* toast, list item entrance, progress */
  --motion-ease-standard: cubic-bezier(0.2, 0, 0, 1);
  --motion-ease-enter: cubic-bezier(0, 0, 0, 1);
  --motion-ease-exit: cubic-bezier(0.3, 0, 1, 1);
  --motion-distance: 12px;
  --motion-scale-press: 0.97;

  /* ---- Spacing scale (4 px base) ---- */
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px; --space-5: 24px; --space-6: 32px;
  /* ---- Type scale ---- */
  --text-sm: 14px; --text-base: 16px; --text-lg: 18px; --text-xl: 30px; --text-display: 44px;
  /* ---- Shape and size ---- */
  --radius-sm: 12px; --radius-md: 16px; --radius-lg: 20px; --radius-xl: 28px; --radius-pill: 999px;
  --target-min: 44px;               /* Fitts: minimum touch target */
}
@media (prefers-reduced-motion: reduce) {
  :root { --motion-distance: 0px; --motion-scale-press: 1; }
}

/* ---- Base ---- */
html { color-scheme: light dark; box-sizing: border-box; -webkit-text-size-adjust: 100%;
  padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); scroll-padding-top: env(safe-area-inset-top, 0px); }
*, *::before, *::after { box-sizing: inherit; }
input, select, button, textarea { box-sizing: border-box; font: inherit; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100dvh; background: var(--color-bg); color: var(--color-text);
  font: var(--text-base)/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.app { max-width: 600px; margin: 0 auto; padding: var(--space-5) var(--space-4) 112px; }
h1 { margin: 0; font-size: var(--text-xl); font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
h2 { margin: 0 0 var(--space-3); font-size: var(--text-lg); line-height: 1.3; }
.sub { margin: var(--space-1) 0 0; color: var(--color-text-2); }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
a { color: var(--color-text-2); }

/* ---- Card ---- */
.card { margin-top: var(--space-4); padding: var(--space-4); border: 1px solid var(--color-border);
  border-radius: var(--radius-lg); background: var(--color-surface); }

/* ---- Buttons: default = secondary; .primary, .tertiary, .danger ---- */
button { min-height: var(--target-min); padding: 0 var(--space-4); border: 1.5px solid var(--color-border-strong);
  border-radius: var(--radius-sm); background: transparent; color: var(--color-text); font-size: 15px; cursor: pointer;
  touch-action: manipulation;
  transition: transform var(--motion-duration-instant) var(--motion-ease-standard),
              background-color var(--motion-duration-fast) var(--motion-ease-standard),
              border-color var(--motion-duration-fast) var(--motion-ease-standard); }
button:active:not(:disabled) { transform: scale(var(--motion-scale-press)); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { border-color: var(--color-accent); background: var(--color-accent); color: var(--color-on-accent); font-weight: 600; }
button.primary:hover:not(:disabled) { border-color: var(--color-accent-hover); background: var(--color-accent-hover); }
button.tertiary { padding: 0 var(--space-2); border-color: transparent; color: var(--color-text); }
button.danger { color: var(--color-danger); font-weight: 600; }

/* ---- Fields ---- */
label.field { display: flex; flex-direction: column; min-width: 0; gap: 6px; font-size: var(--text-sm); font-weight: 600; color: var(--color-text-2); }
/* Fields inside a label keep 16px text (iOS zooms the page on smaller input text). */
label.field input, label.field select { font-size: var(--text-base); font-weight: 400; color: var(--color-text); }
input[type=text] { width: 100%; min-width: 0; min-height: var(--target-min); padding: 0 var(--space-3);
  border: 1.5px solid var(--color-border-strong); border-radius: var(--radius-sm); background: var(--color-surface); color: var(--color-text); }
input::placeholder { color: var(--color-text-2); opacity: 1; }
[aria-invalid="true"] { border-color: var(--color-danger) !important; border-width: 2.5px !important; }

/* ---- Messages ---- */
.msg { margin: var(--space-2) 0 0; font-size: var(--text-sm); color: var(--color-text-2); }
.msg:empty { margin: 0; }
.msg.err { font-weight: 600; color: var(--color-danger); }

/* ---- Focus (always visible for keyboard users) ---- */
:focus-visible { outline: 3px solid var(--color-focus); outline-offset: 2px; }

/* ---- Toast with optional action (Undo). Enter: rise + fade; exit: fade, shorter. Reduced motion: fade only. ---- */
.toast { position: fixed; left: 50%; bottom: calc(var(--space-4) + env(safe-area-inset-bottom, 0px)); z-index: 10;
  display: flex; align-items: center; gap: var(--space-3); max-width: calc(100% - 32px); padding: 6px 6px 6px var(--space-4);
  border-radius: var(--radius-md); background: var(--color-inverse-bg); color: var(--color-inverse-text);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25); transform: translateX(-50%);
  animation: core-toast-in var(--motion-duration-base) var(--motion-ease-enter); }
.toast.is-leaving { animation: core-toast-out var(--motion-duration-fast) var(--motion-ease-exit) forwards; }
.toast button { border-color: var(--color-inverse-text); color: var(--color-inverse-text); font-weight: 600; }
.toast :focus-visible { outline-color: var(--color-inverse-text); }
@keyframes core-toast-in { from { opacity: 0; transform: translate(-50%, var(--motion-distance)); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes core-toast-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes core-toast-fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .toast { animation-name: core-toast-fade; } } /* fade only: no transform runs at all */

/* ---- Footer and legal pages ---- */
footer { margin-top: var(--space-5); text-align: center; font-size: 13px; }
footer a { display: inline-flex; align-items: center; min-height: 48px; padding: 0 12px; }
.doc { max-width: 640px; margin: 0 auto; padding: var(--space-5); line-height: 1.6; }

/* ======================= v2: dashboard components (reference designs) ======================= */
/* Products that use these define the extra color tokens: --color-tile, --color-hero-bg, --color-hero-text,
   --color-hero-text-2, --color-positive. Every component is built from tokens only. */

/* Eyebrow: small label above a title or number. */
.eyebrow { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: 0.02em; color: var(--color-text-2); }

/* Hero: the one number that matters most, on a strong surface. */
.hero { position: relative; margin-top: var(--space-4); padding: var(--space-5); border: 1px solid var(--color-border);
  border-radius: var(--radius-xl); background: var(--color-hero-bg); color: var(--color-hero-text); }
.hero .eyebrow { color: var(--color-hero-text-2); }
.hero-value { margin: var(--space-1) 0 0; font-size: var(--text-display); font-weight: 700; line-height: 1.1; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

/* Stat tiles: label, number, optional chip. */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--space-3); }
.stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; padding: var(--space-3) var(--space-4); border-radius: var(--radius-md); background: var(--color-tile); }
.stat-value { font-size: 22px; font-weight: 700; line-height: 1.25; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.hero .stat { background: transparent; padding: 0; }
.hero .stats { margin-top: var(--space-4); padding-top: var(--space-4); border-top: 1px solid var(--color-hero-line, rgba(255,255,255,0.16)); }

/* Chip: short status or trend; meaning is always in the text. */
.chip { display: inline-flex; align-items: center; gap: 4px; width: max-content; padding: 2px 10px; border-radius: var(--radius-pill);
  font-size: 13px; font-weight: 600; background: var(--color-tile); color: var(--color-text); }

/* Segmented control: one choice from a few; selected = filled + aria-pressed. */
.segmented { display: flex; gap: 4px; padding: 4px; border-radius: var(--radius-pill); background: var(--color-tile); }
.segmented button { flex: 1; min-width: 0; padding: 0 var(--space-2); border-color: transparent; border-radius: var(--radius-pill); font-weight: 600; font-variant-numeric: tabular-nums; }
.segmented button[aria-pressed="true"] { border-color: var(--color-accent); background: var(--color-accent); color: var(--color-on-accent); }

/* Ring: SVG gauge. Use with <svg class="ring" viewBox="0 0 120 120"><circle class="ring-track" .../><circle class="ring-fill" .../></svg>. */
.ring { display: block; width: 132px; height: 132px; flex: none; transform: rotate(-90deg); }
.ring-track, .ring-fill { fill: none; stroke-width: 12; }
.ring-track { stroke: var(--color-track); }
.ring-fill { stroke: var(--color-accent); stroke-linecap: round; }

/* ======================= v3: section views + floating bottom dock ======================= */
/* Products set --color-nav-active-bg / --color-nav-active-text (contrast-checked) in their tokens.
   Below 900px one section shows at a time; at 900px and wider every section shows and the dock hides. */
.dock { display: none; }
@media (max-width: 899px) {
  .has-dock .app { padding-bottom: calc(120px + env(safe-area-inset-bottom, 0px)); }
  /* Focus Not Obscured (WCAG 2.4.11): focused items stay clear of the dock below and sticky bars above. */
  html.has-dock { scroll-padding-bottom: calc(104px + env(safe-area-inset-bottom, 0px)); scroll-padding-top: 112px; }
  .has-dock [data-view].is-off { display: none; }
  .dock { position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); z-index: 9;
    display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 8px; max-width: 480px; margin: 0 auto; padding: 6px;
    border: 1px solid var(--color-border); border-radius: var(--radius-xl); background: var(--color-surface); box-shadow: 0 10px 30px rgba(11, 19, 43, 0.16); }
  .dock a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-width: 0; min-height: 56px;
    padding: 0 2px; border-radius: 22px; color: var(--color-text-2); font-size: 12px; font-weight: 600; line-height: 1.2; text-align: center;
    text-decoration: none; overflow-wrap: normal; word-break: normal; hyphens: manual;
    transition: background-color var(--motion-duration-fast) var(--motion-ease-standard), color var(--motion-duration-fast) var(--motion-ease-standard); }
  .dock a[aria-current=page] { background: var(--color-nav-active-bg, var(--color-tile)); color: var(--color-nav-active-text, var(--color-accent)); font-weight: 700; }
  .dock svg { width: 24px; height: 24px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  .dock a[aria-current=page] svg { stroke-width: 2.4; }
  /* Small phones: a tighter dock and slightly smaller labels, so no label ever breaks inside a word. */
  @media (max-width: 374px) { .dock { left: 8px; right: 8px; gap: 2px; padding: 4px; } .dock a { font-size: 11px; letter-spacing: -0.1px; } }
  .has-dock .toast { bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
  .view-in { animation: core-view-in var(--motion-duration-base) var(--motion-ease-enter); }
}
@keyframes core-view-in { from { opacity: 0; transform: translateY(var(--motion-distance)); } to { opacity: 1; transform: none; } }
@keyframes core-view-fade { from { opacity: 0; } to { opacity: 1; } }
[tabindex="-1"]:focus { outline: none; }

/* ======================= v3: language button + searchable picker sheet ======================= */
.lang-btn, .theme-btn { display: inline-flex; align-items: center; gap: 6px; min-height: var(--target-min); max-width: 168px; padding: 0 var(--space-3);
  border: 1.5px solid var(--color-border-strong); border-radius: var(--radius-pill); background: var(--color-surface); color: var(--color-text); font-weight: 600; }
.lang-btn svg, .theme-btn svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.lang-name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
dialog.sheet { width: min(480px, calc(100% - 24px)); max-height: min(640px, calc(100dvh - 48px)); margin: auto; padding: 0;
  border: 1px solid var(--color-border); border-radius: var(--radius-xl); background: var(--color-surface); color: var(--color-text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3); }
dialog.sheet[open] { display: flex; flex-direction: column; animation: core-sheet-in var(--motion-duration-base) var(--motion-ease-enter); }
dialog.sheet::backdrop { background: rgba(6, 10, 22, 0.55); }
@keyframes core-sheet-in { from { opacity: 0; transform: translateY(var(--motion-distance)); } to { opacity: 1; transform: none; } }
@media (max-width: 599px) { dialog.sheet { width: 100%; max-width: none; margin: auto 0 0; border-radius: var(--radius-xl) var(--radius-xl) 0 0; max-height: 85dvh;
  padding-bottom: env(safe-area-inset-bottom, 0px); } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-4) var(--space-4) var(--space-2); }
.sheet-head h2 { margin: 0; }
.sheet-close { display: inline-grid; place-items: center; width: var(--target-min); height: var(--target-min); border: 0; border-radius: var(--radius-pill);
  background: var(--color-tile); color: var(--color-text); }
.sheet-close svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; }
.lang-search { padding: 0 var(--space-4); }
.lang-search input { width: 100%; min-height: var(--target-min); padding: 0 var(--space-3); border: 1.5px solid var(--color-border-strong);
  border-radius: var(--radius-pill); background: var(--color-surface); color: var(--color-text); font: inherit; font-size: var(--text-base); }
.lang-status { margin: var(--space-2) var(--space-4) 0; font-size: 13px; color: var(--color-text-2); }
.lang-list { flex: 1 1 auto; overflow-y: auto; overscroll-behavior: contain; margin: var(--space-2) 0 0; padding: 0 var(--space-3) var(--space-4); list-style: none; }
.lang-opt { display: flex; width: 100%; align-items: baseline; justify-content: space-between; gap: var(--space-3); min-height: 52px;
  padding: var(--space-2) var(--space-3); border: 0; border-radius: var(--radius-md); background: transparent; color: var(--color-text); text-align: start; }
.lang-opt:hover { background: var(--color-tile); }
.lang-opt[aria-current=true] { background: var(--color-nav-active-bg, var(--color-tile)); color: var(--color-nav-active-text, var(--color-accent)); }
.lang-native { font-size: 17px; font-weight: 700; }
.lang-sub { font-size: 14px; color: var(--color-text-2); }
.lang-opt[aria-current=true] .lang-sub { color: inherit; }
.lang-opt[aria-current=true] .lang-native::after { content: " ✓"; }
.lang-none { margin: var(--space-3) var(--space-4) var(--space-4); color: var(--color-text-2); }
@media (prefers-reduced-motion: reduce) {
  .view-in { animation-name: core-view-fade; }
  .dock a { transition: none; }
  dialog.sheet[open] { animation-name: core-view-fade; }
}
/* Right-to-left languages (Arabic): progress grows from the right. */
[dir=rtl] .bar-fill { transform-origin: right center; }

/* v3.1: forced dark theme also darkens native controls (scrollbars, date pickers). */
:root[data-theme=dark] { color-scheme: dark; }
:root[data-theme=light] { color-scheme: light; }
