/* Maxi Sabor — estilos de la aplicación */
:root {
  --red: #b3261e;
  --red-600: #9a1f18;
  --red-50: #fdecea;
  --amber: #f2a541;
  --amber-50: #fff4e3;
  --green: #1e7a46;
  --green-50: #e6f4ec;
  --ink: #1f1b16;
  --ink-2: #4b443c;
  --muted: #7b7268;
  --line: #e9e1d7;
  --bg: #fbf7f2;
  --card: #ffffff;
  --shadow: 0 1px 2px rgba(31, 27, 22, .06), 0 4px 16px rgba(31, 27, 22, .06);
  --radius: 14px;
  --nav-h: 64px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--red); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.5rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.right { text-align: right; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.hidden { display: none !important; }

.boot { min-height: 100vh; display: grid; place-content: center; text-align: center; color: var(--muted); }

/* ---------- Estructura ---------- */
.shell { min-height: 100vh; display: flex; }
.sidebar {
  width: 240px; flex: 0 0 240px; background: var(--ink); color: #f4ede4;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; padding: 18px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand img { width: 40px; height: 40px; border-radius: 10px; }
.brand b { display: block; font-size: 1.05rem; }
.brand span { font-size: .75rem; color: #bdb2a5; }
.nav-list { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav-list a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
  color: #e8dfd4; text-decoration: none; font-size: .95rem;
}
.nav-list a:hover { background: rgba(255, 255, 255, .06); }
.nav-list a.active { background: var(--red); color: #fff; }
.nav-list .sep { height: 1px; background: rgba(255, 255, 255, .08); margin: 8px 4px; }
.nav-list svg, .tabbar svg, .btn svg { width: 20px; height: 20px; flex: 0 0 auto; }
.sidebar .who { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid rgba(255, 255, 255, .08); font-size: .85rem; }
.sidebar .who button { background: none; border: 0; color: var(--amber); padding: 4px 0; cursor: pointer; }

.main { flex: 1; min-width: 0; padding: 24px 28px 40px; max-width: 1280px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.tabbar { display: none; }
.mobile-head { display: none; }

/* ---------- Componentes ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stack > * + * { margin-top: 16px; }

.kpi { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; position: relative; overflow: hidden; }
.kpi .label { font-size: .85rem; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 1.7rem; font-weight: 700; margin-top: 4px; letter-spacing: -.02em; }
.kpi .sub { font-size: .8rem; color: var(--muted); margin-top: 2px; }
.kpi.hero { background: var(--ink); color: #fff; }
.kpi.hero .label, .kpi.hero .sub { color: #cfc5b8; }
.kpi.hero.win { background: linear-gradient(135deg, #17603a, #1e7a46); }
.kpi.hero.loss { background: linear-gradient(135deg, #8a1c16, #b3261e); }
.kpi .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); cursor: pointer; font-weight: 600; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #d6cabb; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-600); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.danger { color: var(--red); }
.btn.small { min-height: 34px; padding: 0 10px; font-size: .85rem; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: #fff; display: inline-grid; place-items: center; cursor: pointer; }

label.field { display: block; }
label.field > span { display: block; font-size: .85rem; color: var(--ink-2); margin-bottom: 4px; font-weight: 600; }
.input, select.input, textarea.input {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
}
.input:focus { outline: 2px solid rgba(179, 38, 30, .25); border-color: var(--red); }
textarea.input { min-height: 70px; resize: vertical; }
.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.hint { font-size: .8rem; color: var(--muted); margin-top: 4px; }

.seg { display: inline-flex; background: #f1ebe3; border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 8px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--ink-2); min-height: 38px; }
.seg button.on { background: #fff; color: var(--red); box-shadow: var(--shadow); }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: .75rem; font-weight: 700; }
.chip.green { background: var(--green-50); color: var(--green); }
.chip.red { background: var(--red-50); color: var(--red); }
.chip.amber { background: var(--amber-50); color: #9a5b00; }
.chip.gray { background: #f1ebe3; color: var(--ink-2); }

table.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.table td { padding: 10px; border-bottom: 1px solid #f3ede6; vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
.table .voided td { opacity: .5; text-decoration: line-through; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 2px; border-bottom: 1px solid #f3ede6; }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; }
.list-item .meta { font-size: .82rem; color: var(--muted); }

.empty { text-align: center; padding: 28px 12px; color: var(--muted); }
.empty b { display: block; color: var(--ink); margin-bottom: 4px; }

.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) 2fr auto; align-items: center; gap: 10px; padding: 6px 0; font-size: .9rem; }
.bar { height: 10px; background: #f1ebe3; border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--red); border-radius: 99px; }
.bar.amber > i { background: var(--amber); }

.chart { width: 100%; height: auto; display: block; }
.chart text { font-size: 11px; fill: var(--muted); font-family: var(--font); }
.legend { display: flex; gap: 14px; font-size: .8rem; color: var(--muted); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

.alert { padding: 12px 14px; border-radius: 10px; background: var(--amber-50); color: #7a4800; font-size: .9rem; }
.alert.red { background: var(--red-50); color: var(--red-600); }
.alert.green { background: var(--green-50); color: var(--green); }

/* ---------- Login ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-art { background: var(--ink); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-art::after { content: ""; position: absolute; right: -120px; bottom: -120px; width: 380px; height: 380px; border-radius: 50%; background: var(--red); opacity: .9; }
.auth-art h1 { font-size: 2.4rem; position: relative; z-index: 1; max-width: 420px; }
.auth-art p { color: #cfc5b8; position: relative; z-index: 1; max-width: 420px; }
.auth-art .brand { padding: 0; position: relative; z-index: 1; }
.auth-form { display: grid; place-items: center; padding: 32px 20px; }
.auth-form form { width: 100%; max-width: 380px; }
.auth-form form > * + * { margin-top: 14px; }

/* ---------- Punto de venta ---------- */
.pos-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.pos-tools { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.pos-tools .input { flex: 1; min-width: 180px; }
.cats { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 8px; scrollbar-width: none; }
.cats button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 14px; white-space: nowrap; cursor: pointer; font-weight: 600; min-height: 36px; }
.cats button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.dish-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.dish-tile {
  background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px; text-align: left; cursor: pointer;
  min-height: 92px; display: flex; flex-direction: column; justify-content: space-between; position: relative; transition: transform .06s;
}
.dish-tile:active { transform: scale(.97); }
.dish-tile b { font-size: .95rem; line-height: 1.25; }
.dish-tile .price { color: var(--red); font-weight: 700; }
.dish-tile .qty-badge { position: absolute; top: -6px; right: -6px; background: var(--red); color: #fff; border-radius: 999px; min-width: 24px; height: 24px; display: grid; place-items: center; font-size: .8rem; font-weight: 700; padding: 0 6px; }
.cart { position: sticky; top: 16px; }
.cart-lines { max-height: 46vh; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.cart-line { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid #f3ede6; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.stepper button { width: 34px; height: 34px; border: 0; background: #fff; cursor: pointer; font-size: 1.1rem; font-weight: 700; }
.stepper span { min-width: 30px; text-align: center; font-weight: 700; }
.cart-total { display: flex; justify-content: space-between; align-items: baseline; font-size: 1.1rem; padding: 12px 0; }
.cart-total b { font-size: 1.6rem; }
.cart-bar { display: none; }

/* ---------- Ventanas (diálogos) ---------- */
dialog.modal { border: 0; border-radius: 16px; padding: 0; width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 32px); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
dialog.modal::backdrop { background: rgba(31, 27, 22, .45); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; z-index: 2; }
.modal-body { padding: 18px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: #fff; flex-wrap: wrap; }

.recipe-line { display: grid; grid-template-columns: minmax(0, 2fr) 1fr 90px auto auto; gap: 8px; align-items: center; margin-bottom: 8px; }
.recipe-line .cost { font-size: .85rem; color: var(--muted); min-width: 64px; text-align: right; }
.cost-box { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; background: #faf6f0; border-radius: 12px; padding: 12px; margin-top: 12px; }
.cost-box div span { display: block; font-size: .75rem; color: var(--muted); }
.cost-box div b { font-size: 1.05rem; }

#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 24px; z-index: 1000; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow); font-weight: 600; max-width: calc(100vw - 32px); animation: pop .2s ease-out; }
.toast.error { background: var(--red); }
.toast.ok { background: var(--green); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.more-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.more-grid a { display: flex; flex-direction: column; gap: 8px; background: #fff; border-radius: 14px; padding: 16px; text-decoration: none; color: var(--ink); box-shadow: var(--shadow); font-weight: 600; }
.more-grid a svg { width: 26px; height: 26px; color: var(--red); }

.print-head { display: none; }

/* ---------- Tableta y celular ---------- */
@media (max-width: 1100px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pos-layout { grid-template-columns: minmax(0, 1fr) 320px; }
}

@media (max-width: 860px) {
  .sidebar { display: none; }
  .main { padding: 12px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); }
  .mobile-head {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    position: sticky; top: 0; z-index: 20; background: var(--red); color: #fff;
    padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  }
  .mobile-head .brand { padding: 0; }
  .mobile-head .brand img { width: 32px; height: 32px; border: 2px solid rgba(255, 255, 255, .5); }
  .mobile-head .brand span { color: #ffd9d4; }
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: #fff; border-top: 1px solid var(--line); height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: .7rem; font-weight: 600; }
  .tabbar a.active { color: var(--red); }
  .tabbar a.sell { color: #fff; }
  .tabbar a.sell .bubble { background: var(--red); width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center; margin-top: -22px; box-shadow: 0 6px 16px rgba(179, 38, 30, .4); }
  .tabbar a.sell span { color: var(--red); }
  .tabbar a.sell svg { width: 26px; height: 26px; }
  .topbar h1 { font-size: 1.3rem; }
  .g2, .g3 { grid-template-columns: minmax(0, 1fr); }
  .kpi .value { font-size: 1.45rem; }
  .pos-layout { grid-template-columns: minmax(0, 1fr); }
  .cart { display: none; }
  .cart.open { display: block; position: fixed; inset: auto 0 0 0; top: auto; z-index: 40; border-radius: 18px 18px 0 0; max-height: 85vh; overflow-y: auto; padding-bottom: calc(18px + env(safe-area-inset-bottom)); }
  .cart-backdrop.open { position: fixed; inset: 0; background: rgba(31, 27, 22, .45); z-index: 39; }
  .cart-bar {
    display: flex; position: fixed; left: 12px; right: 12px; bottom: calc(var(--nav-h) + 10px + env(safe-area-inset-bottom)); z-index: 25;
    background: var(--ink); color: #fff; border-radius: 14px; padding: 12px 16px; align-items: center; justify-content: space-between; border: 0; font-weight: 700; cursor: pointer;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
  }
  .dish-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .auth { grid-template-columns: 1fr; }
  .auth-art { padding: 28px 20px; min-height: 0; }
  .auth-art h1 { font-size: 1.6rem; margin-top: 24px; }
  .auth-art::after { width: 220px; height: 220px; right: -80px; bottom: -80px; }
  .recipe-line { grid-template-columns: minmax(0, 1fr) 80px 76px auto; }
  .recipe-line .cost { grid-column: 1 / -2; text-align: left; }
  .cost-box { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  dialog.modal { width: 100vw; max-width: 100vw; max-height: 92vh; margin: auto 0 0 0; border-radius: 18px 18px 0 0; }
  .hide-m { display: none; }
}

@media (max-width: 520px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px 14px; }
  .kpi .value { font-size: 1.25rem; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .table { font-size: .85rem; }
  .table td, .table th { padding: 8px 6px; }
}

/* ---------- Impresión / PDF ---------- */
@media print {
  .sidebar, .tabbar, .mobile-head, .no-print, #toasts, .cart-bar { display: none !important; }
  body { background: #fff; }
  .main { padding: 0; max-width: none; }
  .card, .kpi { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
  .kpi.hero { background: #fff !important; color: #000; }
  .kpi.hero .label, .kpi.hero .sub { color: #555; }
  .print-head { display: block; margin-bottom: 12px; }
  .g4 { grid-template-columns: repeat(4, 1fr); }
  .g2 { grid-template-columns: repeat(2, 1fr); }
}
