/* Shared components. They read only theme variables from tokens.css, so the same button,
   chip or sheet works on the dark POS, the light back office and the group CRM. */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
a { color: var(--accent); text-underline-offset: 3px; }
img, svg { display: block; max-width: 100%; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- type ---------- */
.title { font-family: var(--font-title); font-weight: 500; font-size: var(--fs-title); line-height: 1.1; letter-spacing: -.01em; }
[data-theme^="drown"] .title { font-weight: 400; }
.label { font-size: var(--fs-label); font-weight: 500; letter-spacing: .14em; text-transform: uppercase; color: var(--text-soft); }
.small { font-size: var(--fs-small); }
.muted { color: var(--text-soft); }
.num { font-variant-numeric: tabular-nums; }
.strong { font-weight: 500; }
.order-number { font-family: var(--font-display); font-size: var(--fs-number); line-height: 1; }

/* ---------- layout helpers (spacing scale only: 4 8 12 16 24 32 48) ---------- */
.row { display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap; }
.row.tight { gap: var(--s2); }
.row.spread { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: var(--s4); }
.stack.tight { gap: var(--s2); }
.stack.loose { gap: var(--s5); }
.grid { display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.grow { flex: 1; min-width: 0; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--touch); padding: 0 var(--s4); border-radius: var(--r-btn);
  font-weight: 500; font-size: var(--fs-small); border: 1px solid var(--line); background: var(--surface);
  transition: background var(--t-fast) ease-out, border-color var(--t-fast) ease-out; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.btn.primary:hover { filter: brightness(1.12); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.pill { border-radius: var(--r-chip); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- inputs ---------- */
.input, input:not([type]), input[type="text"], input[type="email"], input[type="password"], input[type="tel"], input[type="search"],
input[type="number"], input[type="date"], select, textarea {
  width: 100%; min-height: var(--touch); padding: 0 var(--s3); border-radius: var(--r-btn);
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
}
textarea { padding: var(--s3); min-height: 120px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--primary); }
input[type="color"] { width: 64px; height: var(--touch); padding: var(--s1); border-radius: var(--r-btn); border: 1px solid var(--line); background: var(--surface); }
.field { display: flex; flex-direction: column; gap: var(--s2); }
.field .hint { font-size: var(--fs-small); color: var(--text-soft); }
.field .error { font-size: var(--fs-small); color: var(--danger); }
.check { display: flex; align-items: center; gap: var(--s3); min-height: var(--touch); cursor: pointer; }
.form-error { padding: var(--s3) var(--s4); border-radius: var(--r-btn); border: 1px solid var(--danger); color: var(--danger); font-size: var(--fs-small); }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); padding: var(--s5); }
.card.flat { padding: 0; overflow: hidden; }
.card h3 { font-size: var(--fs-body); font-weight: 500; }

/* ---------- chips and status ---------- */
.chip { display: inline-flex; align-items: center; gap: var(--s1); padding: var(--s1) var(--s3); border-radius: var(--r-chip);
  border: 1px solid var(--line); font-size: var(--fs-label); font-weight: 500; line-height: 1.5; white-space: nowrap; }
.brand-chip { display: inline-flex; align-items: center; padding: var(--s1) var(--s3); border-radius: var(--r-chip);
  background: var(--chip-bg, var(--surface-2)); color: var(--chip-fg, var(--text));
  font-size: var(--fs-label); font-weight: 500; line-height: 1.5; white-space: nowrap; }
.status { display: inline-flex; align-items: center; gap: var(--s2); font-size: var(--fs-label); font-weight: 500;
  letter-spacing: .08em; text-transform: uppercase; }
.status::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status.ok { color: var(--ok); } .status.warn { color: var(--warn); } .status.danger { color: var(--danger); } .status.info { color: var(--info); }
.status.neutral { color: var(--text-soft); }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-small); }
.table th { text-align: left; padding: var(--s3) var(--s4); font-size: var(--fs-label); font-weight: 500; letter-spacing: .14em;
  text-transform: uppercase; color: var(--text-soft); border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table td.num { white-space: nowrap; }
.table tr.link { cursor: pointer; }
.table tr.link:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: var(--s2); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { min-height: var(--touch); padding: 0 var(--s4); font-size: var(--fs-small); font-weight: 500; color: var(--text-soft);
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--primary); }

/* ---------- key / value ---------- */
.kv { display: grid; grid-template-columns: minmax(120px, max-content) 1fr; gap: var(--s2) var(--s4); font-size: var(--fs-small); }
.kv dt { color: var(--text-soft); }
.kv dd { min-width: 0; overflow-wrap: anywhere; }

/* ---------- sheets (dialogs) ---------- */
.sheet-overlay { position: fixed; inset: 0; background: var(--overlay); display: grid; place-items: center; padding: var(--s4); z-index: 50;
  animation: fade var(--t-fast) ease-out; }
.sheet { width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); color: var(--text);
  border-radius: var(--r-sheet); padding: var(--s6); display: flex; flex-direction: column; gap: var(--s5);
  animation: rise var(--t-med) var(--ease); }
.sheet.wide { width: min(760px, 100%); }
.sheet .actions { display: flex; gap: var(--s3); justify-content: flex-end; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } }

/* ---------- toasts ---------- */
.toast-host { position: fixed; left: 50%; bottom: var(--s5); transform: translateX(-50%); display: flex; flex-direction: column;
  gap: var(--s2); z-index: 60; width: min(480px, calc(100vw - 32px)); }
.toast { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); border-radius: var(--r-btn);
  background: var(--text); color: var(--bg); font-size: var(--fs-small); animation: rise var(--t-med) var(--ease); }
.toast .grow { min-width: 0; }
.toast .btn { min-height: 36px; background: transparent; color: inherit; border-color: currentColor; }
.toast.danger { background: var(--danger); color: var(--on-primary); }

/* ---------- states ---------- */
.empty { padding: var(--s7) var(--s5); text-align: center; color: var(--text-soft); }
.unavailable { padding: var(--s3) var(--s4); border: 1px dashed var(--line); border-radius: var(--r-btn); color: var(--text-soft); font-size: var(--fs-small); }
.loading { color: var(--text-soft); font-size: var(--fs-small); padding: var(--s4) 0; }
.secret { font-family: ui-monospace, Menlo, monospace; font-size: var(--fs-small); padding: var(--s3); border-radius: var(--r-btn);
  background: var(--surface-2); border: 1px solid var(--line); overflow-wrap: anywhere; user-select: all; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; transition-duration: 1ms !important; }
}

/* ---------- touch-first controls (shared by every app) ---------- */
@media (pointer: coarse) { [data-density="desk"] { --touch: 48px; } }

/* segmented control: a few mutually exclusive choices */
.seg { display: inline-flex; padding: var(--s1); gap: var(--s1); border-radius: var(--r-chip); background: var(--surface-2); border: 1px solid var(--line); max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button { min-height: calc(var(--touch) - 8px); padding: 0 var(--s4); border-radius: var(--r-chip); font-size: var(--fs-small); font-weight: 500; color: var(--text-soft); white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); }

/* selectable chips (services, artists, time slots) */
.chip-btn { display: inline-flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 2px; min-height: var(--touch); padding: var(--s2) var(--s4);
  border-radius: var(--r-btn); border: 1px solid var(--line); background: var(--surface); font-size: var(--fs-small); text-align: left; }
.chip-btn small { font-size: var(--fs-label); color: var(--text-soft); }
.chip-btn[aria-pressed="true"] { border-color: var(--primary); background: var(--primary); color: var(--on-primary); }
.chip-btn[aria-pressed="true"] small { color: inherit; opacity: .8; }
.chip-btn.full { border-style: dashed; color: var(--text-soft); }
.chip-btn.full[aria-pressed="true"] { color: var(--on-primary); }
.chip-row { display: flex; flex-wrap: wrap; gap: var(--s2); }
.scroll-row { display: flex; gap: var(--s2); overflow-x: auto; padding-bottom: var(--s1); scrollbar-width: thin; }
.scroll-row > * { flex: none; }

/* on/off switch built on a checkbox */
.switch { display: inline-flex; align-items: center; gap: var(--s3); min-height: var(--touch); cursor: pointer; }
.switch input { appearance: none; -webkit-appearance: none; width: 44px; height: 26px; border-radius: var(--r-chip); background: var(--line); position: relative; transition: background var(--t-fast) ease-out; flex: none; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--surface); transition: transform var(--t-fast) ease-out; }
.switch input:checked { background: var(--primary); }
.switch input:checked::after { transform: translateX(18px); }

/* − 2 + */
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: var(--r-btn); background: var(--surface); }
.stepper button { width: var(--touch); height: var(--touch); font-size: 22px; }
.stepper output { min-width: 40px; text-align: center; font-weight: 500; font-variant-numeric: tabular-nums; }

/* stat tiles (label · value · note) */
.tiles { display: grid; gap: var(--s3); grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); padding: var(--s4); display: flex; flex-direction: column; gap: var(--s1); min-width: 0; }
.tile .tile-label { font-size: var(--fs-small); color: var(--text-soft); }
.tile .tile-value { font-size: 28px; font-weight: 500; line-height: 1.15; overflow-wrap: anywhere; }
.tile .tile-note { font-size: var(--fs-label); color: var(--text-soft); }

/* floating "new" button on phones */
.fab { position: fixed; right: var(--s4); bottom: calc(var(--s4) + env(safe-area-inset-bottom)); z-index: 40; min-height: 56px; padding: 0 var(--s5);
  border-radius: var(--r-chip); background: var(--primary); color: var(--on-primary); font-weight: 500; box-shadow: 0 8px 24px var(--overlay); }

/* actions that stay at the bottom of long forms */
.sticky-actions { position: sticky; bottom: 0; z-index: 20; margin: 0 calc(-1 * var(--s4)); padding: var(--s3) var(--s4) calc(var(--s3) + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--line); display: flex; gap: var(--s3); align-items: center; flex-wrap: wrap; }

/* sheets become bottom sheets on phones */
@media (max-width: 640px) {
  .sheet-overlay { place-items: end stretch; padding: 0; }
  .sheet { width: 100%; max-height: 92vh; border-radius: var(--r-sheet) var(--r-sheet) 0 0; padding: var(--s5) var(--s4) calc(var(--s5) + env(safe-area-inset-bottom)); }
  .sheet.wide { width: 100%; }
  .sheet .actions { flex-direction: column-reverse; }
  .sheet .actions .btn { width: 100%; }
}
