/* ==========================================================================
   Maisha — design tokens and shared components
   Brand: the black-and-white Maisha mark, hand-lettered word, honey accent.
   ========================================================================== */

:root {
  --font-ui: "Bricolage Grotesque", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-hand: "Caveat Brush", "Bricolage Grotesque", cursive;

  /* Type scale (1.25 ratio) */
  --fs-xs: .75rem;
  --fs-sm: .875rem;
  --fs-md: 1rem;
  --fs-lg: 1.25rem;
  --fs-xl: 1.563rem;
  --fs-2xl: 1.953rem;
  --fs-3xl: 2.441rem;
  --fs-hand: clamp(2.4rem, 5vw, 3.4rem);

  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 24px; --space-6: 32px; --space-7: 48px; --space-8: 64px;

  /* Radii follow the logo: soft squares, round pills only for controls */
  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 22px;
  --r-pill: 999px;

  --ease: cubic-bezier(.2, .7, .2, 1);
  --dur: 180ms;
}

/* Light — paper white, ink black (the logo printed on a menu card) */
:root,
[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f4f0;
  --bg-sunk: #ecebe6;
  --surface: #ffffff;
  --surface-2: #f8f7f4;
  --ink: #1a1512;
  --ink-2: #463f39;
  --muted: #756d65;
  --line: #e2dfd8;
  --line-strong: #cdc8bf;
  --accent: #f2a900;          /* honey */
  --accent-ink: #8a5800;      /* honey, readable on paper */
  --accent-soft: #fdf1d3;
  --on-accent: #1a1512;
  --primary: #1a1512;         /* buttons use the logo's black */
  --on-primary: #ffffff;
  --success: #23764f;
  --success-soft: #e1f2e8;
  --danger: #c0352b;
  --danger-soft: #fbe5e2;
  --warning: #9a6400;
  --warning-soft: #fdf1d3;
  --info: #2c5d8a;
  --info-soft: #e3edf7;
  --shadow-1: 0 1px 2px rgba(40, 28, 16, .06), 0 1px 1px rgba(40, 28, 16, .04);
  --shadow-2: 0 12px 32px -12px rgba(40, 28, 16, .22), 0 2px 6px rgba(40, 28, 16, .06);
  --overlay: rgba(26, 21, 18, .45);
  --focus: 0 0 0 3px #ffffff, 0 0 0 5px var(--accent);
}

/* Dark — espresso, crema and honey */
[data-theme="dark"] {
  color-scheme: dark;
  --bg: #15110e;
  --bg-sunk: #100d0b;
  --surface: #1e1915;
  --surface-2: #262019;
  --ink: #f3ede5;
  --ink-2: #d5ccc1;
  --muted: #a59a8d;
  --line: #342c25;
  --line-strong: #4a4037;
  --accent: #f6b832;
  --accent-ink: #f6b832;
  --accent-soft: #3a2c12;
  --on-accent: #1a1512;
  --primary: #f3ede5;
  --on-primary: #15110e;
  --success: #5cc38d;
  --success-soft: #173326;
  --danger: #ff7b6e;
  --danger-soft: #3d1c18;
  --warning: #f6b832;
  --warning-soft: #3a2c12;
  --info: #7fb3e6;
  --info-soft: #182a3c;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-2: 0 16px 40px -12px rgba(0, 0, 0, .7), 0 2px 6px rgba(0, 0, 0, .35);
  --overlay: rgba(5, 4, 3, .66);
  --focus: 0 0 0 3px var(--bg), 0 0 0 5px var(--accent);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.app-splash {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  color: var(--ink);
  background: var(--bg);
  opacity: 1;
  visibility: visible;
  animation: splash-dismiss 220ms var(--ease) 3s forwards;
  transition: opacity 220ms var(--ease), visibility 220ms;
}
.app-splash.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.app-splash-content { display: grid; justify-items: center; gap: 20px; }
.app-splash-mark {
  display: block;
  width: min(165px, 48vw);
}
.app-splash-mark img {
  width: 100%;
  height: auto;
  max-height: 210px;
  object-fit: contain;
  animation: splash-pop 360ms var(--ease) both;
}
.app-splash-progress {
  display: block;
  width: min(190px, 52vw);
  height: 3px;
  overflow: hidden;
  border-radius: var(--r-pill);
  background: color-mix(in srgb, var(--ink) 16%, transparent);
}
.app-splash-progress span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left center;
  animation: splash-progress 3s linear forwards;
}
[data-theme="dark"] .app-splash-mark img { mix-blend-mode: screen; }
@keyframes splash-pop { from { opacity: 0; transform: scale(.8); } to { opacity: 1; transform: scale(1); } }
@keyframes splash-progress { to { transform: scaleX(1); } }
@keyframes splash-dismiss { to { opacity: 0; visibility: hidden; } }
@media (prefers-reduced-motion: reduce) {
  .app-splash { animation: splash-dismiss 0s linear 3s forwards; transition: none; }
  .app-splash-mark img, .app-splash-progress span { animation: none; transition: none; }
  .app-splash-progress span { transform: scaleX(1); }
}
img { max-width: 100%; display: block; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; line-height: 1.15; letter-spacing: -.01em; }
p { margin: 0; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.hand { font-family: var(--font-hand); font-weight: 400; letter-spacing: .01em; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.icon { width: 18px; height: 18px; stroke-width: 1.9; flex: none; }

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-sm); }

/* ---------- Buttons ---------- */
.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--ink);
  --btn-bd: var(--line-strong);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 42px; padding: 0 var(--space-4);
  border: 1px solid var(--btn-bd); border-radius: var(--r-md);
  background: var(--btn-bg); color: var(--btn-fg);
  font-weight: 600; font-size: var(--fs-sm); text-decoration: none; white-space: nowrap;
  cursor: pointer;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease), transform 80ms;
}
.btn:hover { --btn-bd: var(--ink-2); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.is-loading { opacity: .6; pointer-events: none; }
.btn-primary { --btn-bg: var(--primary); --btn-fg: var(--on-primary); --btn-bd: var(--primary); }
.btn-primary:hover { --btn-bg: var(--ink-2); --btn-bd: var(--ink-2); }
.btn-accent { --btn-bg: var(--accent); --btn-fg: var(--on-accent); --btn-bd: var(--accent); }
.btn-accent:hover { filter: brightness(1.05); }
.btn-ghost { --btn-bg: transparent; --btn-bd: transparent; }
.btn-ghost:hover { --btn-bg: var(--surface-2); --btn-bd: var(--line); }
.btn-danger { --btn-bg: var(--danger); --btn-fg: #fff; --btn-bd: var(--danger); }
.btn-danger-ghost { --btn-bg: transparent; --btn-fg: var(--danger); --btn-bd: transparent; }
.btn-danger-ghost:hover { --btn-bg: var(--danger-soft); --btn-bd: var(--danger-soft); }
.btn-sm { min-height: 34px; padding: 0 var(--space-3); border-radius: var(--r-sm); }
.btn-lg { min-height: 52px; padding: 0 var(--space-5); font-size: var(--fs-md); }
.btn-block { width: 100%; }
.btn-icon { width: 42px; padding: 0; }
.btn-icon.btn-sm { width: 34px; }
.btn .spinner { display: none; }
.btn.is-loading .spinner { display: inline-block; }

.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Forms ---------- */
.field { display: grid; gap: 6px; align-content: start; }
.field + .field { margin-top: var(--space-4); }
.label { font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); }
.hint { font-size: var(--fs-xs); color: var(--muted); }
.field-error { font-size: var(--fs-xs); color: var(--danger); font-weight: 500; }
.input, .select, .textarea {
  width: 100%; min-height: 46px; padding: 10px 14px;
  border: 1px solid var(--line-strong); border-radius: var(--r-md);
  background: var(--surface); color: var(--ink);
  transition: border-color var(--dur), box-shadow var(--dur);
}
.textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
.input::placeholder, .textarea::placeholder { color: var(--muted); opacity: .8; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--ink-2); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px var(--accent-soft); }
.input.is-invalid { border-color: var(--danger); }
.select {
  appearance: none; padding-right: 40px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23756d65' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}
.input-group { position: relative; display: flex; align-items: center; }
.input-group > .icon { position: absolute; left: 14px; color: var(--muted); pointer-events: none; }
.input-group > .icon ~ .input { padding-left: 42px; }
.input-group > .input:has(~ .input-action) { padding-right: 48px; }
.input-group > .input:has(~ .input-addon) { padding-right: 56px; }
.input-group > .input-action { position: absolute; right: 6px; }
.input-addon { position: absolute; right: 14px; color: var(--muted); font-size: var(--fs-sm); font-weight: 600; pointer-events: none; }

.switch { position: relative; display: inline-flex; align-items: center; gap: var(--space-3); cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  width: 42px; height: 24px; border-radius: var(--r-pill); background: var(--line-strong);
  position: relative; transition: background-color var(--dur) var(--ease); flex: none;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform var(--dur) var(--ease);
}
.switch input:checked + .track { background: var(--success); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { box-shadow: var(--focus); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px;
  border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 600; white-space: nowrap;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line);
}
.badge-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
a.badge { text-decoration: none; }
.badge-accent { background: var(--accent-soft); color: var(--accent-ink); border-color: transparent; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ---------- Theme switcher ---------- */
.theme-switch {
  position: relative; display: inline-block; color: var(--ink);
}
.theme-switch > summary {
  display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 11px;
  border: 1px solid var(--line); border-radius: var(--r-pill); background: var(--surface-2);
  color: var(--ink); font-size: var(--fs-sm); font-weight: 650; cursor: pointer; list-style: none;
}
.theme-switch > summary::-webkit-details-marker { display: none; }
.theme-switch > summary:focus-visible { outline: none; box-shadow: var(--focus); }
.theme-switch > summary > .icon { width: 14px; height: 14px; color: var(--muted); }
.theme-current-icon { display: grid; place-items: center; }
.theme-current-icon > span { display: none; }
.theme-current-icon .icon { width: 16px; height: 16px; }
.theme-switch[data-current-mode="system"] [data-theme-icon="system"],
.theme-switch[data-current-mode="light"] [data-theme-icon="light"],
.theme-switch[data-current-mode="dark"] [data-theme-icon="dark"] { display: grid; }
.theme-options {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 120; display: grid; gap: 3px;
  min-width: 196px; padding: 6px; border: 1px solid var(--line); border-radius: 14px;
  background: var(--surface); box-shadow: var(--shadow-2);
}
.theme-switch:not([open]) .theme-options { display: none; }
.theme-options button {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 0 11px;
  border: 0; border-radius: 9px; background: transparent; color: var(--ink-2);
  font: inherit; font-size: var(--fs-sm); text-align: left; cursor: pointer;
}
.theme-options button .icon { width: 17px; height: 17px; color: var(--muted); }
.theme-options button:hover { background: var(--surface-2); color: var(--ink); }
.theme-options button[aria-pressed="true"] { background: var(--accent-soft); color: var(--ink); font-weight: 700; }

/* ---------- Toasts ---------- */
.toasts {
  position: fixed; z-index: 1000; right: var(--space-5); bottom: var(--space-5);
  display: flex; flex-direction: column-reverse; gap: var(--space-3);
  width: min(380px, calc(100vw - 32px)); pointer-events: none;
}
.toast {
  --tone: var(--info); --tone-soft: var(--info-soft);
  position: relative; overflow: hidden; pointer-events: auto;
  display: grid; grid-template-columns: auto 1fr auto; gap: var(--space-3); align-items: start;
  padding: 14px 14px 16px; border-radius: var(--r-md);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow-2);
  animation: toast-in 260ms var(--ease);
}
.toast.is-leaving { animation: toast-out 200ms var(--ease) forwards; }
.toast-success { --tone: var(--success); --tone-soft: var(--success-soft); }
.toast-error { --tone: var(--danger); --tone-soft: var(--danger-soft); }
.toast-warning { --tone: var(--warning); --tone-soft: var(--warning-soft); }
.toast-icon { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--tone-soft); color: var(--tone); }
.toast-icon .icon { width: 17px; height: 17px; }
.toast-title { font-weight: 700; font-size: var(--fs-sm); }
.toast-msg { font-size: var(--fs-sm); color: var(--ink-2); line-height: 1.4; margin-top: 1px; }
.toast-close { border: 0; background: transparent; color: var(--muted); cursor: pointer; padding: 4px; border-radius: 6px; }
.toast-close:hover { color: var(--ink); background: var(--surface-2); }
.toast-bar { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--tone); transform-origin: left; animation: toast-bar linear forwards; }
.toast:hover .toast-bar { animation-play-state: paused; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px) scale(.98); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(24px); } }
@keyframes toast-bar { from { transform: scaleX(1); } to { transform: scaleX(0); } }

@media (max-width: 640px) {
  .toasts { left: 16px; right: 16px; top: 12px; bottom: auto; flex-direction: column; width: auto; }
  @keyframes toast-in { from { opacity: 0; transform: translateY(-12px); } }
}

/* ---------- Dialog (confirm + modal) ---------- */
.dialog {
  width: min(460px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line);
  border-radius: var(--r-lg); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-2);
}
.dialog-wide { width: min(560px, calc(100vw - 32px)); }
.dialog::backdrop { background: var(--overlay); backdrop-filter: blur(2px); }
.dialog[open] { animation: dialog-in 220ms var(--ease); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(10px) scale(.98); } }
.dialog-body { padding: var(--space-5); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-5) var(--space-5) 0; }
.dialog-head h2 { font-size: var(--fs-lg); }
.dialog-foot { display: flex; justify-content: flex-end; gap: var(--space-2); padding: 0 var(--space-5) var(--space-5); }
.confirm-icon { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; background: var(--danger-soft); color: var(--danger); margin-bottom: var(--space-4); }
.confirm-title { font-size: var(--fs-lg); font-weight: 700; margin-bottom: 6px; }
.confirm-text { color: var(--ink-2); font-size: var(--fs-sm); }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: var(--space-8) var(--space-5); color: var(--muted); }
.empty .icon { width: 36px; height: 36px; margin: 0 auto var(--space-3); color: var(--line-strong); }
.empty h3 { color: var(--ink); font-size: var(--fs-lg); margin-bottom: 6px; }
.empty p { max-width: 42ch; margin: 0 auto var(--space-4); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
}
.icon-xs { width: 12px; height: 12px; }

@media (max-width: 700px) {
  .input, .select, .textarea { font-size: 16px; }
}
.dialog[open] { animation: dialog-in 280ms cubic-bezier(.2, .9, .25, 1.05); }
.dialog::backdrop { animation: fade-in-bd 250ms ease; }
@keyframes fade-in-bd { from { opacity: 0; } }
