:root {
  --bg: #f3f5f9; --card: #fff; --text: #15202b; --muted: #6b7785; --line: #e3e8ef;
  --primary: #2563eb; --go: #16a34a; --danger: #dc2626; --busy: #fde8e8; --busy-text: #b91c1c;
  --free: #dcfce7; --free-text: #166534; --shadow: 0 1px 3px rgba(16, 24, 40, .08);
  --safe-top: env(safe-area-inset-top, 0px); --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b; --card: #19212b; --text: #e6ebf1; --muted: #93a1b1; --line: #28323e;
    --busy: #3b1d1d; --busy-text: #fca5a5; --free: #14301f; --free-text: #86efac; --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); line-height: 1.4;
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding: calc(56px + var(--safe-top)) 0 calc(64px + var(--safe-bottom));
}
h2 { margin: 4px 0 12px; font-size: 1.35rem; }
h3 { margin: 18px 0 8px; font-size: 1.05rem; }
a { color: var(--primary); }
hr { border: 0; border-top: 1px dashed var(--line); margin: 8px 0; }
.muted { color: var(--muted); font-size: .88rem; }
.pos { color: var(--go); } .neg { color: var(--danger); }
.grow { flex: 1; min-width: 0; }

#top {
  position: fixed; inset: 0 0 auto 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: var(--safe-top) 12px 0; height: calc(56px + var(--safe-top));
  background: var(--primary); color: #fff;
}
#top small { display: block; opacity: .8; font-size: .75rem; }
#top .icon { color: #fff; font-size: 1.4rem; }
.clock { font-variant-numeric: tabular-nums; opacity: .9; }

#view { max-width: 980px; margin: 0 auto; padding: 14px 16px; }

#tabs {
  position: fixed; inset: auto 0 0 0; z-index: 20; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: var(--safe-bottom);
}
#tabs a {
  flex: 1; text-align: center; padding: 7px 2px 6px; font-size: .72rem; text-decoration: none;
  color: var(--muted); border-top: 3px solid transparent;
}
#tabs a span { display: block; font-size: 1.25rem; }
#tabs a.on { color: var(--primary); border-top-color: var(--primary); font-weight: 600; }

#drawer {
  position: fixed; top: 0; bottom: 0; left: 0; width: 270px; z-index: 40; background: var(--card);
  transform: translateX(-100%); transition: transform .2s; padding-top: var(--safe-top); overflow-y: auto;
}
.drawer-head { display: flex; gap: 10px; align-items: center; padding: 16px; border-bottom: 1px solid var(--line); }
#drawer nav a { display: block; padding: 13px 18px; color: var(--text); text-decoration: none; }
#drawer nav a.on { background: rgba(37, 99, 235, .12); color: var(--primary); font-weight: 600; }
.scrim { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .4); display: none; }
.drawer-open #drawer { transform: none; }
.drawer-open .scrim { display: block; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px;
  margin-bottom: 10px; box-shadow: var(--shadow);
}
.card.hint { border-style: dashed; }
.card.clickable { cursor: pointer; }
.card.busy { border-color: #f87171; }
.row { display: flex; align-items: center; gap: 10px; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.head h2 { margin: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid .card { margin: 0; }
.stat { display: flex; flex-direction: column; gap: 2px; margin: 0; }
.stat b { font-size: 1.2rem; }
.grid2 + .card, .grid2 + h3 { margin-top: 12px; }
.ico { font-size: 1.6rem; }
.timer { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; margin: 8px 0 2px; }
.items { list-style: none; padding: 0; margin: 8px 0; font-size: .92rem; }
.items li { display: flex; justify-content: space-between; align-items: center; padding: 2px 0; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.btns .btn { flex: 1; }
.badge { font-size: .72rem; font-weight: 700; padding: 3px 9px; border-radius: 99px; }
.badge.busy { background: var(--busy); color: var(--busy-text); }
.badge.free { background: var(--free); color: var(--free-text); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px;
  padding: 8px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--card);
  color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.go { background: var(--go); border-color: var(--go); color: #fff; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; }
.btn.block { display: flex; width: 100%; margin-top: 10px; }
.btn:active { transform: scale(.98); }
.icon { background: none; border: 0; font-size: 1.3rem; padding: 6px 8px; cursor: pointer; color: var(--muted); }
.x { background: none; border: 0; color: var(--danger); cursor: pointer; padding: 0 4px; font-size: .95rem; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 8px; }
.chip { flex: none; padding: 7px 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--card);
  color: var(--text); font: inherit; cursor: pointer; }
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.search, .field input, .field select, input[type=date] {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card);
  color: var(--text); font: inherit;
}
input[type=date] { width: auto; }
.search { margin-bottom: 10px; }
.empty { text-align: center; padding: 34px 12px; color: var(--muted); font-size: 2.2rem; }
.empty p { font-size: 1rem; margin: 6px 0 0; }

.overlay { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .5); display: flex;
  align-items: flex-end; justify-content: center; }
.modal { background: var(--card); width: 100%; max-width: 480px; max-height: 92vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(16px + var(--safe-bottom)); }
@media (min-width: 600px) { .overlay { align-items: center; } .modal { border-radius: 18px; } }
.modal h3 { margin-top: 0; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.field { display: block; margin-bottom: 10px; }
.field span { display: block; font-size: .82rem; color: var(--muted); margin-bottom: 4px; }
.err { background: var(--busy); color: var(--busy-text); padding: 8px 10px; border-radius: 8px; margin: 8px 0 0; }
.sum { margin-bottom: 12px; }
.r-row { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; }
.r-total { font-size: 1.1rem; font-weight: 700; }
.sale-list { max-height: 40vh; overflow-y: auto; margin-bottom: 10px; }
.sale-row { padding: 6px 0; border-bottom: 1px solid var(--line); }
.qty { width: 78px !important; text-align: center; }
.receipt { font-family: ui-monospace, Consolas, monospace; font-size: .9rem; }
.r-head, .r-foot { text-align: center; }
.help ol, .help ul { padding-left: 20px; }

#toast {
  position: fixed; left: 50%; bottom: calc(76px + var(--safe-bottom)); transform: translate(-50%, 20px);
  background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0;
  pointer-events: none; transition: .25s; z-index: 80; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
.locked #top, .locked #tabs, .locked #drawer, .locked .scrim { display: none !important; }
.locked { padding: var(--safe-top) 0 var(--safe-bottom); }
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 12px; }
.auth-card { width: 100%; max-width: 420px; padding: 20px 18px; }
.auth-logo { text-align: center; margin-bottom: 10px; }
.auth-logo h2 { margin: 6px 0 2px; }
.auth .chips { justify-content: center; }
.center { text-align: center; }
.pw, .field span.pw { position: relative; display: block; font-size: inherit; color: inherit; margin: 0; }
.pw input { padding-right: 46px; }
.eye { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); border: 0; background: none;
  font-size: 1.25rem; padding: 8px 10px; cursor: pointer; color: var(--muted); }
.link-btn { display: block; width: 100%; background: none; border: 0; color: var(--primary); cursor: pointer;
  padding: 12px 0 4px; font: inherit; text-align: center; }
.forgot { background: var(--bg); border-radius: 10px; padding: 10px 12px; margin-top: 8px; font-size: .92rem; }
.forgot p { margin: 0 0 6px; }
.contact { background: var(--bg); border-radius: 10px; padding: 10px 12px; margin: 10px 0; text-align: left; }
.banner { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; border-radius: 12px;
  padding: 10px 14px; margin-bottom: 12px; font-weight: 600; }
@media (prefers-color-scheme: dark) { .banner { background: #3a2c0a; color: #fcd34d; border-color: #78560f; } }
.banner.info { background: #dbeafe; color: #1e40af; border-color: #93c5fd; display: flex; align-items: center;
  justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.banner.info .btn { min-height: 36px; padding: 4px 12px; }
@media (prefers-color-scheme: dark) { .banner.info { background: #12284d; color: #93c5fd; border-color: #2b4c86; } }
#print-area { display: none; }
@media print {
  body { background: #fff; padding: 0; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; color: #000; max-width: 80mm; margin: 0 auto; }
}
@media (min-width: 900px) { #tabs { display: none; } body { padding-bottom: 0; } }
