@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@600;800;900&display=swap');

:root {
  --bg: #f4efe6;
  --panel: #ffffff;
  --ink: #1c1f26;
  --muted: #6b6f7a;
  --line: #e4ddd0;
  --green: #1a8a3f;
  --green-dark: #146c31;
  --red: #c8322b;
  --red-dark: #a32620;
  --amber: #e5990b;
  --blue: #1d5fd4;
  --radius: 18px;
  --shadow: 0 6px 20px rgba(28, 31, 38, .08);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Nunito', 'Segoe UI', system-ui, sans-serif;
  font-weight: 700;
  background: var(--bg);
  color: var(--ink);
  font-size: 18px;
  touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
}
input, textarea, select { -webkit-user-select: text; user-select: text; font-family: inherit; font-weight: 700; }
button { font-family: inherit; font-weight: 800; cursor: pointer; border: 0; }
.hidden { display: none !important; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 56px; padding: 0 22px; border-radius: 14px;
  font-size: 18px; background: #fff; color: var(--ink); border: 2px solid var(--line);
  transition: transform .08s ease, background .15s ease;
}
.btn:active { transform: scale(.96); }
.btn.primary { background: var(--green); color: #fff; border-color: var(--green); }
.btn.primary:active { background: var(--green-dark); }
.btn.danger { background: #fff; color: var(--red); border-color: var(--red); }
.btn.danger.solid { background: var(--red); color: #fff; }
.btn.ghost { background: transparent; border-color: rgba(255,255,255,.35); color: #fff; }
.btn.big { min-height: 84px; font-size: 26px; border-radius: 18px; }
.btn.sm { min-height: 44px; padding: 0 14px; font-size: 15px; border-radius: 10px; }
.btn.blue { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn.amber { background: var(--amber); color: #fff; border-color: var(--amber); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 20px; background: var(--ink); color: #fff;
}
.brand { font-size: 24px; font-weight: 900; letter-spacing: .5px; display: flex; align-items: center; gap: 12px; }
.brand .dot { width: 14px; height: 14px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(26,138,63,.25); }
.clock { font-size: 20px; font-weight: 800; opacity: .9; }
.userbox { display: flex; align-items: center; gap: 10px; font-size: 17px; }
.userbox .btn { min-height: 46px; }

/* ---------- alert bar ---------- */
.alert-bar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 12px 20px; background: var(--red); color: #fff; font-size: 19px; font-weight: 800;
  animation: pulse 1.6s ease-in-out infinite;
}
.alert-bar .chip { background: rgba(255,255,255,.18); padding: 6px 12px; border-radius: 10px; }
@keyframes pulse { 0%,100% { background: var(--red);} 50% { background: var(--red-dark);} }

/* ---------- POS layout ---------- */
.pos { display: grid; grid-template-columns: 1fr 400px; gap: 12px; padding: 12px; height: calc(100vh - 66px); min-height: 0; }
.pos.with-alert { height: calc(100vh - 66px - 58px); }
.grid-wrap { position: relative; display: flex; gap: 8px; min-height: 0; }
.grid {
  flex: 1; display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: 10px;
  align-content: start; overflow-y: auto; padding-right: 2px; scroll-behavior: smooth; scrollbar-width: none;
}
.grid::-webkit-scrollbar, .lines::-webkit-scrollbar { display: none; }
.scrollbtns { display: flex; flex-direction: column; gap: 8px; width: 58px; flex-shrink: 0; }
.scrollbtns button {
  flex: 1; min-height: 64px; border-radius: 14px; background: var(--ink); color: #fff; font-size: 24px;
  box-shadow: var(--shadow); transition: opacity .15s ease, transform .08s ease;
}
.scrollbtns button:active { transform: scale(.94); }
.scrollbtns button:disabled { opacity: .18; }
.scrollbtns.hidden-overflow { display: none; }
.scrollbtns.inline { flex-direction: row; width: auto; gap: 6px; }
.scrollbtns.inline button { flex: none; width: 54px; min-height: 44px; font-size: 18px; border-radius: 10px; }
.card {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 12px 8px 10px; min-height: 176px; background: var(--panel); border-radius: 16px;
  box-shadow: var(--shadow); border: 3px solid transparent; text-align: center;
  transition: transform .1s ease, border-color .15s ease;
}
.card:active { transform: scale(.96); border-color: var(--c, var(--green)); }
.card img { height: 88px; width: auto; max-width: 100%; object-fit: contain; pointer-events: none; }
.card .name { font-size: 17px; font-weight: 900; line-height: 1.1; }
.card .price { font-size: 20px; font-weight: 900; color: var(--c, var(--green)); }
.card .stock { position: absolute; top: 10px; right: 10px; font-size: 13px; font-weight: 800; padding: 4px 9px; border-radius: 999px; background: #eef0f3; color: var(--muted); }
.card .stock.low { background: var(--red); color: #fff; }
.card .inq { position: absolute; top: 10px; left: 10px; width: 36px; height: 36px; border-radius: 50%; background: var(--c, var(--green)); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 17px; font-weight: 900; }

.ticket { display: flex; flex-direction: column; background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; min-height: 0; }
.ticket h2 { margin: 0; padding: 8px 12px; font-size: 18px; background: #faf7f1; border-bottom: 2px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.ticket h2 .muted { font-size: 14px; }
.lines { flex: 1; overflow-y: auto; padding: 4px 8px; scroll-behavior: smooth; scrollbar-width: none; min-height: 60px; }
.lines .empty { color: var(--muted); text-align: center; padding: 24px 10px; font-size: 17px; }
.line { display: grid; grid-template-columns: 1fr auto auto auto; gap: 6px; align-items: center; padding: 5px 0; border-bottom: 1px solid var(--line); }
.line .nm { font-size: 15px; font-weight: 900; line-height: 1.05; min-width: 0; }
.line .nm small { display: block; font-size: 12px; color: var(--muted); font-weight: 700; }
.line .sub { font-size: 16px; font-weight: 900; text-align: right; min-width: 74px; }
.line .qty { display: flex; align-items: center; gap: 2px; }
.line .qty button { width: 44px; height: 44px; border-radius: 10px; font-size: 24px; background: #eef0f3; color: var(--ink); }
.line .qty .n { min-width: 34px; text-align: center; font-size: 20px; font-weight: 900; }
.line .rm { width: 40px; height: 44px; border-radius: 10px; background: #fde8e6; color: var(--red); font-size: 18px; }
.total-row { display: flex; justify-content: space-between; align-items: center; padding: 8px 14px; background: var(--ink); color: #fff; font-size: 18px; }
.total-row strong { font-size: 30px; font-weight: 900; }
.pay { padding: 6px 10px; border-top: 2px solid var(--line); }
.pay-row { display: flex; justify-content: space-between; align-items: center; font-size: 15px; color: var(--muted); }
.pay-row input { width: 150px; font-size: 22px; text-align: right; padding: 5px 10px; border: 2px solid var(--line); border-radius: 10px; }
.quick { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; margin: 6px 0 2px; }
.quick button { height: 42px; border-radius: 10px; background: #eef0f3; font-size: 14px; padding: 0 2px; }
.quick button.clear { background: #fde8e6; color: var(--red); }
.change-row { display: flex; justify-content: space-between; align-items: center; font-size: 16px; padding: 2px 4px 0; }
.change-row strong { font-size: 24px; color: var(--green); }
.change-row.neg strong { color: var(--red); }
.actions { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; padding: 6px 10px 10px; }
.actions .btn.big { min-height: 68px; font-size: 24px; }

/* pantallas bajas (1024x768 con barra de Windows y navegador) */
@media (max-height: 720px) {
  .top { padding: 8px 16px; }
  .brand { font-size: 20px; }
  .clock { font-size: 17px; }
  .userbox .btn { min-height: 40px; font-size: 15px; }
  .pos { height: calc(100vh - 56px); padding: 8px; gap: 8px; }
  .pos.with-alert { height: calc(100vh - 56px - 50px); }
  .alert-bar { padding: 8px 16px; font-size: 16px; }
  .card { min-height: 150px; padding: 8px 6px; }
  .card img { height: 70px; }
  .actions .btn.big { min-height: 58px; font-size: 22px; }
  .total-row strong { font-size: 26px; }
}

/* ---------- overlay ---------- */
.overlay { position: fixed; inset: 0; background: rgba(28,31,38,.6); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; animation: fadeIn .18s ease; }
.overlay.closing { animation: fadeOut .18s ease forwards; }
.overlay.closing .modal { animation: popOut .18s ease forwards; }
.modal { background: #fff; border-radius: 24px; padding: 28px; width: min(560px, 100%); max-height: 95vh; overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); animation: popIn .22s cubic-bezier(.2,.9,.3,1.2); }
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes fadeOut { from { opacity: 1 } to { opacity: 0 } }
@keyframes popIn { from { opacity: 0; transform: translateY(24px) scale(.92) } to { opacity: 1; transform: none } }
@keyframes popOut { from { opacity: 1; transform: none } to { opacity: 0; transform: translateY(12px) scale(.96) } }
.overlay.dlg { z-index: 70; }
.dlg-box { text-align: center; width: min(480px, 100%); }
.dlg-icon { width: 72px; height: 72px; border-radius: 50%; margin: 0 auto 10px; display: flex; align-items: center; justify-content: center; font-size: 40px; font-weight: 900; color: #fff; background: var(--green); }
.dlg-icon.danger { background: var(--red); }
.dlg-box h3 { font-size: 26px; margin: 4px 0 8px; }
.dlg-text { color: var(--muted); font-size: 18px; margin: 0 0 6px; }
.dlg-body { margin: 4px 0 8px; }
.dlg-sum { display: flex; justify-content: space-between; font-size: 18px; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.dlg-sum.total { font-size: 24px; font-weight: 900; border: 0; }
.dlg-sum.total strong { color: var(--green); font-size: 32px; }
.dlg-sum.change strong { color: var(--green); }
.dlg-box .row .btn.big { min-height: 72px; font-size: 22px; }
.toast.out { animation: fadeOut .4s ease forwards; }
.modal.done { text-align: center; }
.modal.done .check { width: 96px; height: 96px; border-radius: 50%; background: var(--green); color: #fff; font-size: 56px; display: flex; align-items: center; justify-content: center; margin: 0 auto 12px; }
.modal.done h3 { font-size: 30px; margin: 6px 0; }
.modal.done .big-money { font-size: 56px; font-weight: 900; color: var(--green); margin: 4px 0 18px; }
.modal h3 { margin: 0 0 14px; font-size: 24px; }
.modal label { display: block; font-size: 15px; color: var(--muted); margin: 10px 0 4px; }
.modal input, .modal select { width: 100%; font-size: 20px; padding: 12px; border: 2px solid var(--line); border-radius: 12px; }
.modal .row { display: flex; gap: 10px; margin-top: 18px; }
.modal .row .btn { flex: 1; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 14px 22px; border-radius: 14px; font-size: 18px; z-index: 60; box-shadow: var(--shadow); }
.toast.err { background: var(--red); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: radial-gradient(1200px 600px at 20% -10%, #d8ead9 0%, var(--bg) 55%); }
.login { width: min(420px, 100%); background: #fff; border-radius: 26px; padding: 34px; box-shadow: 0 20px 60px rgba(28,31,38,.15); }
.login h1 { margin: 0 0 4px; font-size: 32px; font-weight: 900; }
.login p { margin: 0 0 22px; color: var(--muted); }
.login label { display: block; font-size: 15px; color: var(--muted); margin: 14px 0 6px; }
.login input { width: 100%; font-size: 22px; padding: 14px; border: 2px solid var(--line); border-radius: 14px; }
.login .btn { width: 100%; margin-top: 22px; }
.login .err { color: var(--red); margin-top: 12px; min-height: 24px; }

/* ---------- admin ---------- */
.admin { padding: 18px 20px 60px; max-width: 1400px; margin: 0 auto; }
.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.tabs button { min-height: 52px; padding: 0 20px; border-radius: 14px; background: #fff; border: 2px solid var(--line); font-size: 17px; }
.tabs button.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; background: #fff; padding: 12px; border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; }
.filters .preset { min-height: 46px; padding: 0 16px; border-radius: 10px; background: #eef0f3; font-size: 15px; }
.filters .preset.on { background: var(--green); color: #fff; }
.filters input[type=date] { font-size: 16px; padding: 8px 10px; border: 2px solid var(--line); border-radius: 10px; }
.filters .sep { width: 1px; height: 32px; background: var(--line); margin: 0 6px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 16px; }
.kpi { background: #fff; border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.kpi .l { color: var(--muted); font-size: 14px; text-transform: uppercase; letter-spacing: .6px; }
.kpi .v { font-size: 34px; font-weight: 900; margin-top: 4px; }
.kpi.green .v { color: var(--green); }
.panel { background: #fff; border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.panel h3 { margin: 0 0 14px; font-size: 19px; display: flex; justify-content: space-between; align-items: center; }
.panel.alert { border: 3px solid var(--red); background: #fff4f3; }
.panel.alert h3 { color: var(--red); }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.alert-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; }
.alert-item { display: flex; align-items: center; gap: 12px; background: #fff; border: 2px solid #f3c9c6; border-radius: 14px; padding: 10px 12px; }
.alert-item img { height: 52px; }
.alert-item .n { font-weight: 900; }
.alert-item .s { color: var(--red); font-weight: 900; font-size: 20px; }
.alert-item .m { color: var(--muted); font-size: 13px; }
.bars .bar-row { display: grid; grid-template-columns: 170px 1fr 110px; gap: 10px; align-items: center; margin: 8px 0; font-size: 16px; }
.bars .bar-row .lbl { display: flex; align-items: center; gap: 8px; font-weight: 800; }
.bars .bar-row .lbl img { height: 32px; }
.bars .track { height: 26px; background: #f0ece4; border-radius: 8px; overflow: hidden; }
.bars .fill { height: 100%; border-radius: 8px; background: var(--c, var(--green)); min-width: 3px; transition: width .4s ease; }
.bars .val { text-align: right; font-weight: 900; }
.bars .val small { color: var(--muted); font-weight: 700; }
.chart { display: flex; align-items: flex-end; gap: 4px; height: 190px; padding-top: 24px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.chart .col .b { width: 100%; max-width: 46px; background: var(--green); border-radius: 6px 6px 0 0; position: relative; }
.chart .col .b span { position: absolute; top: -20px; left: 50%; transform: translateX(-50%); font-size: 11px; white-space: nowrap; color: var(--muted); }
.chart .col .x { font-size: 11px; color: var(--muted); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 16px; }
table.tbl th { text-align: left; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .5px; padding: 8px 10px; border-bottom: 2px solid var(--line); }
table.tbl td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.tbl tr.void td { opacity: .45; text-decoration: line-through; }
table.tbl .r { text-align: right; }
table.tbl img { height: 44px; vertical-align: middle; }
table.tbl input[type=text], table.tbl input[type=number] { font-size: 16px; padding: 8px; border: 2px solid var(--line); border-radius: 8px; width: 100%; }
table.tbl input[type=number] { width: 90px; }
.pill { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 800; }
.pill.ok { background: #e3f4e8; color: var(--green); }
.pill.low { background: var(--red); color: #fff; }
.pill.warn { background: #fdf0d2; color: #9a6400; }
.pill.off { background: #eee; color: var(--muted); }
.items-mini { color: var(--muted); font-size: 14px; font-weight: 700; }
.stock-big { font-size: 26px; font-weight: 900; }
.stock-big.low { color: var(--red); }
.muted { color: var(--muted); }
.empty-msg { color: var(--muted); padding: 20px; text-align: center; }

@media (max-width: 900px) {
  .pos { grid-template-columns: 1fr; height: auto; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); overflow: visible; }
  .card { min-height: 190px; }
  .card img { height: 90px; }
  .cols { grid-template-columns: 1fr; }
  .bars .bar-row { grid-template-columns: 120px 1fr 90px; }
  .top { flex-wrap: wrap; }
}
