/* ==========================================================================
   A.M Foods POS — base + shared components. Every view builds from these.
   ========================================================================== */
@import url('./tokens.css');

/* --- reset -------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.45;
  color: var(--text);
  background: var(--surface-sunken);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
h1, h2, h3, h4, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--info); text-decoration: none; }
:focus-visible { outline: 3px solid var(--gold-400); outline-offset: 2px; border-radius: var(--r-sm); }
::selection { background: var(--gold-300); color: var(--ink-900); }

/* Numbers must never jitter as they change — POS totals are read at a glance. */
.num, .table td, .table th, input[type=number], .money { font-variant-numeric: tabular-nums; }

/* --- scrollbars --------------------------------------------------------- */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: var(--r-pill); border: 3px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background-color: var(--text-faint); background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* --- app shell ---------------------------------------------------------- */
.app { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }

.topbar {
  display: flex; align-items: center; gap: var(--s4);
  height: var(--topbar-h); flex: 0 0 var(--topbar-h);
  padding: 0 var(--s4);
  background: linear-gradient(180deg, var(--ink-800), var(--ink-900));
  color: var(--text-on-dark);
  border-bottom: 2px solid var(--gold-500);
  box-shadow: var(--sh-2);
  z-index: var(--z-sticky);
}
.brand { display: flex; align-items: center; gap: var(--s3); min-width: 0; }
.brand-mark {
  width: 38px; height: 38px; flex: none; display: grid; place-items: center;
  border-radius: var(--r-md);
  background: linear-gradient(145deg, var(--gold-400), var(--gold-600));
  color: var(--ink-900); font-weight: 800; font-size: var(--fs-lg); letter-spacing: -.5px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.45);
}
.brand-text { min-width: 0; }
.brand-name {
  font-size: var(--fs-md); font-weight: 700; letter-spacing: .3px; color: var(--gold-300);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-tag { font-size: var(--fs-xs); color: var(--text-on-dark-muted); white-space: nowrap; }

.nav { display: flex; gap: var(--s1); margin-left: var(--s4); }
.nav-link {
  display: flex; align-items: center; gap: var(--s2);
  height: 40px; padding: 0 var(--s4);
  border-radius: var(--r-pill); border: 0; background: transparent;
  color: var(--text-on-dark-muted); font-size: var(--fs-md); font-weight: 600;
  transition: background var(--t-fast), color var(--t-fast);
}
.nav-link:hover { background: rgba(255,255,255,.08); color: var(--text-on-dark); }
.nav-link.active { background: var(--gold-400); color: var(--ink-900); }
.nav-ico { font-size: var(--fs-lg); line-height: 1; }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: var(--s3); }
.clock { font-size: var(--fs-sm); color: var(--text-on-dark-muted); font-variant-numeric: tabular-nums; }
.role-chip {
  padding: 3px 10px; border-radius: var(--r-pill); font-size: var(--fs-xs);
  font-weight: 700; text-transform: uppercase; letter-spacing: .6px;
  background: rgba(233,185,73,.16); color: var(--gold-300);
  border: 1px solid rgba(233,185,73,.35);
}

.view { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.view-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: var(--s5); }
.view-head {
  display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap;
  padding: var(--s4) var(--s5); background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.view-title { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -.2px; }
.view-sub { font-size: var(--fs-sm); color: var(--text-muted); }

/* --- buttons ------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--tap); padding: 0 var(--s5);
  border: 1px solid transparent; border-radius: var(--r-md);
  font-size: var(--fs-md); font-weight: 650; white-space: nowrap;
  transition: transform var(--t-fast), box-shadow var(--t-fast),
              background var(--t-fast), border-color var(--t-fast);
  user-select: none;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn.primary { background: var(--ink-800); color: var(--text-on-dark); box-shadow: var(--sh-1); }
.btn.primary:hover:not(:disabled) { background: var(--ink-700); box-shadow: var(--sh-2); }

.btn.gold { background: linear-gradient(180deg, var(--gold-400), var(--gold-500)); color: var(--ink-900); box-shadow: var(--sh-1); }
.btn.gold:hover:not(:disabled) { filter: brightness(1.05); box-shadow: var(--sh-2); }

.btn.success { background: var(--success); color: #fff; box-shadow: var(--sh-1); }
.btn.success:hover:not(:disabled) { filter: brightness(1.07); box-shadow: var(--sh-2); }

.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover:not(:disabled) { filter: brightness(1.07); }

.btn.ghost { background: var(--surface); border-color: var(--line-strong); color: var(--text); }
.btn.ghost:hover:not(:disabled) { background: var(--cream-100); border-color: var(--text-faint); }

.btn.quiet { background: transparent; color: var(--text-muted); }
.btn.quiet:hover:not(:disabled) { background: var(--cream-100); color: var(--text); }

.btn.sm { min-height: 36px; padding: 0 var(--s3); font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn.lg { min-height: var(--tap-lg); padding: 0 var(--s6); font-size: var(--fs-lg); border-radius: var(--r-lg); }
.btn.block { width: 100%; }

.icon-btn {
  display: inline-grid; place-items: center;
  width: 38px; height: 38px; flex: none;
  border: 0; border-radius: var(--r-md); background: transparent;
  color: var(--text-muted); font-size: var(--fs-lg); line-height: 1;
  transition: background var(--t-fast), color var(--t-fast);
}
.icon-btn:hover { background: var(--cream-100); color: var(--text); }
.icon-btn.danger:hover { background: var(--danger-bg); color: var(--danger); }

/* --- form controls ------------------------------------------------------ */
.input, .select, textarea.input {
  width: 100%; min-height: var(--tap);
  padding: 0 var(--s4);
  border: 1.5px solid var(--line-strong); border-radius: var(--r-md);
  background: var(--surface); color: var(--text);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
textarea.input { padding: var(--s3) var(--s4); min-height: 84px; resize: vertical; line-height: 1.5; }
.input:focus, .select:focus, textarea.input:focus {
  outline: none; border-color: var(--gold-500);
  box-shadow: 0 0 0 3px rgba(212,160,50,.2);
}
.input::placeholder { color: var(--text-faint); }
.input:disabled, .select:disabled { background: var(--cream-100); color: var(--text-muted); }
.input-lg { min-height: var(--tap-lg); font-size: var(--fs-lg); }
.select { appearance: none; padding-right: var(--s8); cursor: pointer;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236E645A' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right var(--s4) center;
}
.field { display: flex; flex-direction: column; gap: var(--s2); }
.field-label { font-size: var(--fs-sm); font-weight: 650; color: var(--text-muted); }
.hint { font-size: var(--fs-xs); color: var(--text-faint); }
.stack { display: flex; flex-direction: column; gap: var(--s4); }
.stack.tight { gap: var(--s2); }
.row { display: flex; align-items: center; gap: var(--s3); }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.between { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
.spacer { flex: 1; }

/* segmented control — payment mode, date presets, paper width */
.segment { display: inline-flex; padding: 3px; gap: 3px; background: var(--cream-100);
  border: 1px solid var(--line); border-radius: var(--r-md); }
.segment > button {
  flex: 1; min-height: 40px; padding: 0 var(--s4); border: 0; border-radius: var(--r-sm);
  background: transparent; color: var(--text-muted); font-size: var(--fs-md); font-weight: 650;
  transition: background var(--t-fast), color var(--t-fast), box-shadow var(--t-fast);
}
.segment > button:hover { color: var(--text); }
.segment > button.on { background: var(--surface); color: var(--text); box-shadow: var(--sh-1); }
.segment.block { display: flex; width: 100%; }

.switch { display: flex; align-items: center; gap: var(--s3); cursor: pointer; min-height: var(--tap); }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
  width: 48px; height: 28px; flex: none; border-radius: var(--r-pill);
  background: var(--line-strong); position: relative; transition: background var(--t-fast);
}
.switch-track::after {
  content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 50%; background: #fff; box-shadow: var(--sh-1);
  transition: transform var(--t-fast);
}
.switch input:checked + .switch-track { background: var(--success); }
.switch input:checked + .switch-track::after { transform: translateX(20px); }
.switch input:focus-visible + .switch-track { outline: 3px solid var(--gold-400); outline-offset: 2px; }

/* --- surfaces ----------------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--sh-1);
}
.card-head { padding: var(--s4) var(--s5); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: var(--s3); }
.card-title { font-size: var(--fs-md); font-weight: 700; }
.card-body { padding: var(--s5); }
.grid { display: grid; gap: var(--s4); }

/* --- badges / chips ----------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: .3px;
  background: var(--cream-100); color: var(--text-muted);
}
.badge.ok { background: var(--success-bg); color: var(--success); }
.badge.err { background: var(--danger-bg); color: var(--danger); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.info { background: var(--info-bg); color: var(--info); }

/* veg / non-veg mark — the Indian square-with-dot convention */
.vmark { width: 13px; height: 13px; flex: none; border: 1.6px solid var(--nonveg); border-radius: 2.5px; position: relative; }
.vmark.veg { border-color: var(--veg); }
.vmark::after { content: ''; position: absolute; inset: 2.4px; border-radius: 50%; background: var(--nonveg); }
.vmark.veg::after { background: var(--veg); }

/* --- table -------------------------------------------------------------- */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; padding: var(--s3) var(--s4);
  font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .7px;
  color: var(--text-muted); background: var(--cream-50);
  border-bottom: 1px solid var(--line); white-space: nowrap;
  position: sticky; top: 0; z-index: 1;
}
.table td { padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: var(--cream-50); }
.table .r { text-align: right; }
.table .c { text-align: center; }
.table tr.is-void td { color: var(--text-faint); text-decoration: line-through; }
.table tr.is-void td .badge { text-decoration: none; }
.table-wrap { overflow: auto; max-height: 100%; }

/* --- overlay / modal ---------------------------------------------------- */
.overlay {
  position: fixed; inset: 0; z-index: var(--z-modal);
  display: grid; place-items: center; padding: var(--s4);
  background: rgba(20,17,15,.5); backdrop-filter: blur(2px);
  opacity: 0; transition: opacity var(--t-med);
}
.overlay.in { opacity: 1; }
.modal {
  width: 100%; max-height: 90dvh; display: flex; flex-direction: column;
  background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--sh-pop);
  transform: translateY(10px) scale(.98); transition: transform var(--t-med);
}
.overlay.in .modal { transform: none; }
.modal-head { display: flex; align-items: center; gap: var(--s3); padding: var(--s5) var(--s5) var(--s3); }
.modal-title { font-size: var(--fs-lg); font-weight: 700; flex: 1; }
.modal-body { padding: var(--s3) var(--s5) var(--s5); overflow-y: auto; }
.modal-text { color: var(--text-muted); line-height: 1.55; }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--s3); padding: var(--s4) var(--s5); border-top: 1px solid var(--line); }
.modal-foot .btn { min-width: 104px; }

/* --- toast -------------------------------------------------------------- */
.toast-host {
  position: fixed; left: 50%; bottom: var(--s6); transform: translateX(-50%);
  z-index: var(--z-toast); display: flex; flex-direction: column; gap: var(--s2);
  align-items: center; pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s5); border-radius: var(--r-pill);
  background: var(--ink-800); color: var(--text-on-dark);
  font-size: var(--fs-md); font-weight: 600; box-shadow: var(--sh-3);
  opacity: 0; transform: translateY(14px); transition: opacity var(--t-med), transform var(--t-med);
  pointer-events: auto; cursor: pointer; max-width: min(92vw, 480px);
}
.toast.in { opacity: 1; transform: none; }
.toast-icon { display: grid; place-items: center; width: 20px; height: 20px; flex: none;
  border-radius: 50%; font-size: var(--fs-xs); font-weight: 800; }
.toast-ok .toast-icon { background: var(--success); color: #fff; }
.toast-err .toast-icon { background: var(--danger); color: #fff; }
.toast-info .toast-icon { background: var(--info); color: #fff; }

/* --- empty / loading ---------------------------------------------------- */
.empty { display: grid; place-items: center; gap: var(--s3); padding: var(--s12) var(--s5); text-align: center; color: var(--text-muted); }
.empty-ico { font-size: 44px; opacity: .4; line-height: 1; }
.empty-title { font-size: var(--fs-lg); font-weight: 700; color: var(--text); }
.empty-text { font-size: var(--fs-sm); max-width: 40ch; }

.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid var(--line-strong); border-top-color: var(--gold-500);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: grid; place-items: center; padding: var(--s12); }

/* --- login -------------------------------------------------------------- */
.login-wrap {
  min-height: 100dvh; display: grid; place-items: center; padding: var(--s5);
  background: radial-gradient(120% 100% at 50% 0%, var(--ink-700), var(--ink-900));
}
.login-card { width: 100%; max-width: 380px; background: var(--surface);
  border-radius: var(--r-xl); box-shadow: var(--sh-pop); padding: var(--s8) var(--s6); text-align: center; }
.login-mark {
  width: 66px; height: 66px; margin: 0 auto var(--s4); display: grid; place-items: center;
  border-radius: var(--r-lg); font-size: var(--fs-2xl); font-weight: 800; letter-spacing: -1px;
  background: linear-gradient(145deg, var(--gold-400), var(--gold-600)); color: var(--ink-900);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.5);
}
.login-name { font-size: var(--fs-xl); font-weight: 800; letter-spacing: .3px; }
.login-tag { font-size: var(--fs-sm); color: var(--text-muted); margin-bottom: var(--s6); }
.pin-input { text-align: center; letter-spacing: 14px; font-size: var(--fs-2xl);
  font-weight: 700; padding-left: 14px; min-height: 62px; }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s2); margin-top: var(--s4); }
.pin-key { min-height: 56px; border: 1.5px solid var(--line); border-radius: var(--r-md);
  background: var(--surface); font-size: var(--fs-xl); font-weight: 650;
  transition: background var(--t-fast), transform var(--t-fast); }
.pin-key:hover { background: var(--cream-100); }
.pin-key:active { transform: scale(.96); }

/* --- helpers ------------------------------------------------------------ */
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.mono { font-family: var(--font-mono); }
.strong { font-weight: 700; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.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; }
.hidden { display: none !important; }

/* --- top bar on small screens -------------------------------------------
   At stall-phone widths the stall name, four tabs and the clock cannot all
   fit. The tabs are what the cashier actually presses, so they win the room. */
@media (max-width: 780px) {
  .topbar { gap: var(--s2); padding: 0 var(--s3); }
  .brand-text { display: none; }
  .nav { margin-left: var(--s2); overflow-x: auto; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav-link { padding: 0 var(--s3); font-size: var(--fs-sm); }
  .clock, .role-chip { display: none; }
}

/* Narrower still: only the tab you are on keeps its label. */
@media (max-width: 470px) {
  .nav-link .nav-label { display: none; }
  .nav-link.active .nav-label { display: inline; }
  .nav-link { padding: 0 var(--s3); }
}
