:root {
  --bg: #faf7f2; --card: #fff; --text: #2b2420; --muted: #6f655d; --line: #ebe4da;
  --field-line: #958879; --disabled: #b3a89d;
  --brand: #b5501f; --brand-dark: #8f3d15; --brand-soft: #f6e3d6; --on-brand: #fff;
  --ok: #2f7d4a; --ok-soft: #e3f3e8; --ok-ink: #1f5a33;
  --bad: #c0392b; --bad-soft: #fbe1de; --bad-ink: #8a2419; --bad-line: #e7b9b3;
  --warn: #8a5a12; --warn-soft: #fdf0d5;
  --radius: 10px; --tap: 44px;
}
* { box-sizing: border-box; }
button, .btn, .tile { -webkit-tap-highlight-color: transparent; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--brand); }
:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.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; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }

.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .75rem; height: 52px; padding: 0 16px; background: var(--brand); color: var(--on-brand); }
.top a { color: var(--on-brand); }
.top :focus-visible { outline-color: var(--on-brand); }
.brand { display: inline-flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-weight: 700; text-decoration: none; font-size: 1.05rem; }
.who { margin-left: auto; font-size: .9rem; opacity: .95; }
.menu-btn { display: none; min-width: var(--tap); min-height: var(--tap); margin-left: -10px; background: none; border: 0; color: var(--on-brand); font-size: 1.4rem; cursor: pointer; }
.nav-backdrop { display: none; }
.side { position: fixed; top: 52px; left: 0; bottom: 0; width: 200px; padding: 12px 8px; background: var(--card); border-right: 1px solid var(--line); overflow-y: auto; z-index: 10; }
.side a { display: block; padding: 9px 12px; border-radius: 8px; color: var(--text); text-decoration: none; }
.side a:hover { background: var(--bg); }
.side a.active { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }
main { padding: 20px 16px 60px; max-width: 1200px; }
main.with-nav { margin-left: 200px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; overflow-x: auto; }
.card.narrow { max-width: 380px; margin: 40px auto; }
.card.narrow.left { margin: 0 0 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.stats4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 16px; }
.stat, .stats3 > div { display: flex; flex-direction: column; gap: 2px; }
.stat span, .stats3 span { color: var(--muted); font-size: .85rem; }
.stat strong, .stats3 strong { font-size: 1.45rem; }
.stat small { color: var(--muted); }
.stats3 > div { background: var(--bg); padding: 10px 12px; border-radius: 8px; }

label { display: block; margin-bottom: 10px; font-size: .88rem; color: var(--muted); }
label.check { display: flex; align-items: center; gap: 6px; color: var(--text); }
/* 16px como mínimo: con menos, Safari de iPhone hace zoom al tocar el campo */
input, select, textarea { display: block; width: 100%; margin-top: 3px; padding: 9px 10px; font: inherit; font-size: 16px; color: var(--text); background: var(--card); border: 1px solid var(--field-line); border-radius: 8px; }
input[type=checkbox] { width: auto; display: inline; margin: 0; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > label { flex: 1 1 140px; }
form.inline { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
form.inline label { margin: 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; justify-content: space-between; margin-bottom: 16px; }
.filter { margin-bottom: 10px; max-width: 320px; }

.btn { display: inline-block; padding: 9px 14px; font: inherit; font-weight: 500; color: var(--text); background: var(--card); border: 1px solid var(--field-line); border-radius: 8px; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.primary:hover { background: var(--brand-dark); }
.btn.primary:disabled { opacity: .45; cursor: not-allowed; }
.btn.danger { color: var(--bad); border-color: var(--bad-line); }
.btn.small { padding: 4px 9px; font-size: .85rem; }
.btn.big { padding: 13px 18px; font-size: 1.05rem; }
.quick { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: .82rem; color: var(--muted); font-weight: 600; }
tfoot th { color: var(--text); font-size: .95rem; border-bottom: 0; }
td.r, th.r { text-align: right; white-space: nowrap; }
td.actions a { margin-left: 8px; white-space: nowrap; }
td form { margin: 0; }
table.lines td { padding: 4px; }
table.lines input, table.lines select { margin: 0; }
tr.inactive td { opacity: .5; }
.neg { color: var(--bad); }
.pos { color: var(--ok); }
.strong { font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 99px; font-size: .75rem; font-weight: 600; }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.danger { background: var(--bad-soft); color: var(--bad); }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; background: var(--ok-soft); color: var(--ok-ink); }
.flash.error { background: var(--bad-soft); color: var(--bad-ink); }

/* Punto de venta */
.pos-layout { display: grid; grid-template-columns: 1fr 340px; gap: 16px; align-items: start; }
.pos-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 8px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tile { display: flex; flex-direction: column; gap: 4px; min-height: 104px; padding: 14px; text-align: left; font: inherit; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; transition: transform .06s; }
.tile:hover { border-color: var(--field-line); }
.tile:active { transform: scale(.97); background: var(--brand-soft); }
.tile.agotado { border-style: dashed; }
.tile .tag { align-self: flex-start; }
.tile strong { font-size: 1rem; }
.tile span { font-size: 1.15rem; color: var(--brand-dark); font-weight: 600; }
.pos-cart { position: sticky; top: 68px; }
.cart td { padding: 6px 2px; }
.cart .qty { display: inline-flex; align-items: center; gap: 4px; }
.cart .qty button { width: 34px; height: 34px; border: 1px solid var(--field-line); background: var(--card); color: var(--text); border-radius: 6px; font-size: 1rem; cursor: pointer; }
.total-line { display: flex; justify-content: space-between; align-items: baseline; margin: 10px 0; font-size: 1.1rem; }
.total-line strong { font-size: 1.5rem; }
.quick-cash { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
#cobrar { width: 100%; margin-bottom: 8px; }
#limpiar { width: 100%; }
.cart .aviso td { padding-top: 0; color: var(--warn); font-size: .85rem; }
.pos-bar { display: none; }

.calc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0 16px; }
.ticket { max-width: 360px; }
.print-only { display: none; }

@media (max-width: 900px) {
  .menu-btn { display: block; }
  .side { transform: translateX(-100%); visibility: hidden; transition: transform .2s, visibility 0s .2s; box-shadow: 2px 0 12px rgba(0,0,0,.08); }
  body.nav-open .side { transform: none; visibility: visible; transition: transform .2s; }
  body.nav-open .nav-backdrop { display: block; position: fixed; inset: 52px 0 0; z-index: 9; width: 100%; border: 0; background: rgba(43,36,32,.35); }
  main.with-nav { margin-left: 0; }
  .grid2, .grid3, .pos-layout { grid-template-columns: 1fr; }
  .stats4 { grid-template-columns: 1fr 1fr; }
  .pos-cart { position: static; scroll-margin-top: 64px; }
  /* Barra fija con el total para no tener que bajar hasta el ticket */
  .pos-bar:not([hidden]) { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 15; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -4px 14px rgba(43,36,32,.08); }
  .pos-bar strong { font-size: 1.35rem; }
  body.has-pos-bar main { padding-bottom: 96px; }
  body.nav-open .pos-bar { display: none; }
  .who { font-size: .8rem; }
}
@media (max-width: 520px) {
  .stats3 { grid-template-columns: 1fr; }
  .stat strong { font-size: 1.2rem; }
  .tiles { grid-template-columns: 1fr 1fr; }
}
@media (pointer: coarse) {
  .btn, .btn.small { min-height: var(--tap); }
  .btn.small { padding: 8px 12px; }
  .cart .qty button { width: var(--tap); height: var(--tap); }
  .side a { padding: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .side, body.nav-open .side { transition: none; }
  .tile { transition: none; }
  .tile:active { transform: none; }
}
@media print {
  .top, .side, .no-print, .btn, .flash, .pos-bar, .nav-backdrop { display: none !important; }
  main.with-nav { margin: 0; padding: 0; }
  .card { border: 0; padding: 0; }
  .print-only { display: block; }
  body { background: var(--card); }
}

/* Logo, configuración y caja */
.brand img { height: 34px; width: auto; max-width: 120px; object-fit: contain; background: var(--card); border-radius: 6px; padding: 2px; }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 8px; margin: 32px auto 0; text-align: center; font-size: 1.3rem; }
.login-brand img { max-height: 90px; max-width: 220px; object-fit: contain; }
.login-brand + h1 { text-align: center; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs a { padding: 9px 14px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--brand-dark); border-color: var(--brand); font-weight: 600; }
.logo-preview { display: flex; align-items: center; gap: 16px; margin-bottom: 12px; }
.logo-preview img { max-height: 80px; max-width: 200px; object-fit: contain; border: 1px solid var(--line); border-radius: 8px; padding: 6px; background: var(--card); }
.ticket .logo { display: block; max-height: 70px; max-width: 180px; margin: 0 auto 6px; }
.ticket h2, .ticket .head { text-align: center; }
.caja-banner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; background: var(--ok-soft); color: var(--ok-ink); }
.caja-banner.cerrada { background: var(--bad-soft); color: var(--bad-ink); }
.caja-banner a { color: inherit; font-weight: 600; }
.kv { width: 100%; }
.kv td:last-child { text-align: right; white-space: nowrap; }
.kv tr.big td { font-size: 1.15rem; font-weight: 700; }
.delete-form { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.card > .delete-form:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.inline-del { display: inline; margin-left: 8px; }
.link-danger { background: none; border: 0; padding: 0; font: inherit; color: var(--bad); text-decoration: underline; cursor: pointer; }
.link-disabled { margin-left: 8px; color: var(--disabled); cursor: help; text-decoration: underline dotted; }

/* Escanear ticket (Gastos) */
.scan { margin: 4px 0 14px; padding: 12px; background: var(--bg); border: 1px dashed var(--field-line); border-radius: var(--radius); }
.scan .scan-btn { display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); margin: 0 10px 6px 0; color: var(--text); font-size: 1rem; }
.scan .scan-btn.busy { opacity: .6; pointer-events: none; }
.scan-btn:focus-within { outline: 3px solid var(--brand); outline-offset: 2px; }
.scan-result { display: flex; gap: 12px; align-items: flex-start; margin-top: 8px; }
.scan-result[hidden] { display: none; }
.scan-result img { width: 84px; max-height: 120px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); background: var(--card); }
.scan-result p { margin: 0 0 6px; }
.warn-text { color: var(--warn); }
input.filled, select.filled { background: var(--ok-soft); border-color: var(--ok); }
.ticket-link { white-space: nowrap; }
.scan [data-scan-help] { display: block; }
.renglones { margin: 4px 0 14px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); }
.renglones[hidden] { display: none; }
.renglones legend { padding: 0 4px; font-weight: 600; }
.renglones > p { margin: 0 0 8px; }
.renglon { padding: 8px 0; border-top: 1px solid var(--line); }
.renglon.off .renglon-campos { display: none; }
.renglon:not(.off) [data-imp-lbl] { display: none; }
.renglon.off { padding: 4px 0; }
.renglon-check { margin-bottom: 6px; font-weight: 500; }
.renglon-check input { width: 20px; height: 20px; flex: none; margin: 0; }
.renglon-campos { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 8px; }
.renglon-campos label { margin: 0; }
.renglon-campos .unidad { font-size: .8rem; }
.renglones-resumen { margin: 8px 0 0; font-weight: 600; }
@media (max-width: 480px) { .renglon-campos { grid-template-columns: 1fr 1fr; } .renglon-campos label:first-child { grid-column: 1 / -1; } }
