:root {
  --ink: #111;
  --muted: #6b6b6b;
  --line: #e6e6e6;
  --bg: #fff;
  --soft: #f3f3f3;
  --ok: #0a7d33;
  --bad: #b3261e;
  --warn: #9a6700;
  --radius: 14px;
  --nav-h: 76px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { min-height: 100vh; }
body.no-scroll { overflow: hidden; }
h1 { font-size: 34px; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 20px; margin: 0; }
h3 { font-size: 17px; margin: 0; }
p { margin: 0 0 12px; }
a { color: inherit; }
button { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Estructura ---------- */
.shell { min-height: 100vh; }
.main { padding: 16px 16px calc(var(--nav-h) + var(--safe-b) + 24px); max-width: 720px; margin: 0 auto; }
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; background: var(--bg);
  border-top: 1px solid var(--line); padding: 6px 6px calc(6px + var(--safe-b)); gap: 4px;
}
.nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; text-decoration: none;
  padding: 10px 2px 8px; border-radius: 12px; font-size: 13px; font-weight: 500;
}
.nav a svg { width: 26px; height: 26px; }
.nav a.active { background: var(--soft); }
.nav .brand, .nav .nav-desktop { display: none; }

@media (min-width: 900px) {
  .nav {
    top: 0; right: auto; width: 240px; flex-direction: column; border-top: 0; border-right: 1px solid var(--line);
    padding: 20px 14px; gap: 2px; overflow-y: auto;
  }
  .nav .brand { display: block; font-weight: 800; font-size: 18px; padding: 4px 12px 18px; line-height: 1.2; }
  .nav a { flex: none; flex-direction: row; gap: 14px; padding: 12px; font-size: 16px; }
  .nav a svg { width: 22px; height: 22px; }
  .nav .nav-desktop { display: flex; }
  .nav .nav-mobile-only { display: none; }
  .nav .spacer { flex: 1; }
  .main { margin-left: 240px; max-width: none; padding: 32px 40px 48px; }
  .main > .page { max-width: 820px; margin: 0 auto; }
  .main > .page.narrow { max-width: 480px; }
}

/* ---------- Encabezados ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0 20px; }
.page-head h1 { font-size: 32px; }
.back { display: inline-flex; align-items: center; gap: 6px; text-decoration: none; color: var(--muted); font-size: 15px; margin-bottom: 4px; background: none; border: 0; padding: 4px 0; cursor: pointer; }
.fab {
  width: 56px; height: 56px; border-radius: 50%; background: var(--ink); color: #fff; border: 0; font-size: 30px;
  line-height: 1; display: grid; place-items: center; cursor: pointer; text-decoration: none; flex: none;
}
.icon-btn { background: var(--soft); border: 0; width: 36px; height: 36px; border-radius: 50%; cursor: pointer; font-size: 15px; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 999px;
  padding: 14px 24px; font-weight: 600; font-size: 16px; cursor: pointer; text-decoration: none; min-height: 48px;
  background: var(--soft); color: var(--ink);
}
.btn.primary { background: var(--ink); color: #fff; }
.btn.danger { background: var(--bad); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.block { width: 100%; }
.btn.small { padding: 8px 16px; min-height: 38px; font-size: 14px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible, .fab:focus-visible, .nav a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 3px solid #2f6fed; outline-offset: 2px;
}
.row-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.row-actions .btn { flex: 1 1 140px; }

/* ---------- Filtros y pestañas ---------- */
.seg { display: flex; background: var(--soft); border-radius: 12px; padding: 4px; margin-bottom: 20px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 12px 8px; border-radius: 9px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.filters { display: flex; gap: 8px; margin-bottom: 20px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 14px; padding: 0 14px;
  height: 48px; background: #fff; white-space: nowrap; color: var(--muted); flex: none; position: relative;
}
.pill b { color: var(--ink); font-weight: 600; }
.pill select { position: absolute; inset: 0; opacity: 0; width: 100%; cursor: pointer; font-size: 16px; }
.pill.round { width: 48px; padding: 0; justify-content: center; border-radius: 50%; cursor: pointer; }
.pill.round svg { width: 22px; height: 22px; }
.searchbar { margin-bottom: 16px; }

/* ---------- Listas ---------- */
.overview { margin-bottom: 20px; }
.overview .label { font-size: 14px; font-weight: 600; color: var(--muted); letter-spacing: .02em; text-transform: uppercase; margin-bottom: 8px; }
.overview .grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.overview .grid small { display: block; color: var(--muted); font-size: 14px; }
.overview .grid strong { font-size: 21px; }
.group-title { font-weight: 700; font-size: 16px; margin: 24px 0 0; padding-bottom: 10px; border-bottom: 1.5px solid #999; }
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 0; border-bottom: 1px solid var(--line);
  text-decoration: none; cursor: pointer; background: none; border-left: 0; border-right: 0; border-top: 0; width: 100%; text-align: left;
}
.row .l { min-width: 0; }
.row .l strong { font-size: 19px; font-weight: 500; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .l span { color: var(--muted); font-size: 16px; }
.row .r { text-align: right; display: flex; align-items: center; gap: 10px; flex: none; }
.row .r .amt { font-size: 19px; display: block; }
.row .chev { color: #999; font-size: 22px; }
.status { color: var(--muted); font-size: 16px; display: block; }
.status.ok { color: var(--ok); }
.status.bad { color: var(--bad); }
.status.warn { color: var(--warn); }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
.empty h3 { color: var(--ink); margin-bottom: 6px; }

/* ---------- Tarjetas y formularios ---------- */
.card { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; background: #fff; }
.card h3 { margin-bottom: 10px; }
.card.soft { background: var(--soft); border-color: transparent; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; }
.kv.total { font-size: 20px; font-weight: 700; border-top: 2px solid var(--ink); margin-top: 8px; padding-top: 12px; }
.field { margin-bottom: 14px; }
.field > label, .label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; color: #333; }
input[type=text], input[type=email], input[type=tel], input[type=number], input[type=date], input[type=password], input[type=search], select, textarea {
  width: 100%; font: inherit; padding: 12px 14px; border: 1px solid #cfcfcf; border-radius: 10px; background: #fff; color: var(--ink); min-height: 48px;
}
textarea { min-height: 84px; resize: vertical; }
.two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.two > * { min-width: 0; }
input[type=date] { min-width: 0; max-width: 100%; }
.check { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.check input { width: 22px; height: 22px; }
.err { color: var(--bad); font-size: 14px; margin: 8px 0; }
.banner { background: #fff4d6; border: 1px solid #f0d58a; padding: 12px 14px; border-radius: 12px; margin-bottom: 16px; font-size: 14px; }
.banner.info { background: var(--soft); border-color: var(--line); }

.line-item { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 10px; background: #fff; }
.line-item .top { display: flex; gap: 8px; margin-bottom: 8px; }
.line-item .top input { flex: 1; }
.line-item .grid { display: grid; grid-template-columns: 80px 1fr auto; gap: 8px; align-items: end; }
.line-item .amount { text-align: right; font-weight: 600; padding-bottom: 12px; }
.menu-list a, .menu-list button.item {
  display: flex; align-items: center; gap: 16px; padding: 18px 4px; border-bottom: 1px solid var(--line); text-decoration: none; font-size: 19px; font-weight: 600;
  background: none; border-left: 0; border-right: 0; border-top: 0; width: 100%; text-align: left; cursor: pointer;
}
.menu-list svg { width: 26px; height: 26px; flex: none; }
.menu-list small { display: block; font-weight: 400; color: var(--muted); font-size: 14px; }

/* ---------- Checkout / teclado ---------- */
.amount-display { font-size: 72px; font-weight: 700; letter-spacing: -.03em; margin: 36px 0 32px; min-height: 90px; overflow-wrap: anywhere; line-height: 1; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin: 16px 0 20px; }
.keypad button { background: #fff; border: 0; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); font-size: 34px; font-weight: 500; height: 84px; cursor: pointer; }
.keypad button:nth-child(3n) { border-right: 0; }
.keypad button:nth-last-child(-n+3) { border-bottom: 0; }
.keypad button:active { background: var(--soft); }
.keypad button.dim { color: #999; }
.note-btn { width: 100%; background: #fff; border: 1px solid var(--line); border-radius: 12px; height: 56px; font-size: 19px; font-weight: 500; cursor: pointer; }
.cart-badge { display: inline-block; background: #fff; color: var(--ink); border-radius: 999px; padding: 2px 10px; font-size: 14px; margin-left: 4px; }
.tile-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tile { border: 1px solid var(--line); border-radius: 12px; padding: 14px; text-align: left; background: #fff; cursor: pointer; min-height: 84px; }
.tile strong { display: block; font-size: 16px; }
.tile span { color: var(--muted); }

/* ---------- Gráficas simples ---------- */
.bars { display: flex; gap: 10px; align-items: flex-end; height: 160px; padding-top: 8px; }
.bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 6px; min-width: 0; }
.bar i { display: block; width: 100%; background: var(--ink); border-radius: 6px 6px 0 0; min-height: 2px; }
.bar small { font-size: 12px; color: var(--muted); }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.stat { border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.stat small { color: var(--muted); display: block; margin-bottom: 4px; }
.stat strong { font-size: 22px; }

/* ---------- Hojas modales ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: #fff; width: 100%; max-height: 92vh; border-radius: 20px 20px 0 0; display: flex; flex-direction: column; animation: up .18s ease-out; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 8px; }
.sheet-body { padding: 8px 20px calc(20px + var(--safe-b)); overflow-y: auto; }
.preview-frame { display: block; width: 100%; height: min(50vh, 640px); border: 1px solid var(--line); border-radius: 12px; background: #f3f3f3; }
@keyframes up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (min-width: 700px) {
  .backdrop { align-items: center; }
  .sheet { width: 520px; border-radius: 20px; max-height: 88vh; }
  .sheet.wide { width: 720px; }
}

#toast { position: fixed; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 16px); transform: translate(-50%, -20px); background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 999px; opacity: 0; pointer-events: none; transition: .2s; z-index: 100; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--bad); }

/* ---------- Login ---------- */
.login { max-width: 380px; margin: 14vh auto 0; padding: 0 20px; }
.login h1 { margin-bottom: 8px; text-align: center; }
.login-logo { display: block; width: 150px; max-width: 60%; height: auto; margin: 0 auto 20px; }
.nav .brand img { display: block; height: 40px; width: auto; max-width: 100%; }

@media print { .nav, .fab, .row-actions, .back { display: none !important; } .main { margin: 0; padding: 0; } }
