/* Ferretería Beypaz — kit de marca y sistema de diseño
   Colores tomados del logo (public/img/logo.png):
     Verde bosque  #063c1e  contornos y "FERRETERÍA" → estructura (barra lateral, encabezado, acceso)
     Verde Beypaz  #0c843c  cerchas del techo        → acción principal, enlaces, gráficos
     Verde lima    #a6c83a  brillos de las cerchas   → detalles y realces sobre fondos oscuros
     Amarillo      #f8d810  letras "BEYPAZ"          → acento: sección activa, foco del escáner, destacados
     Oro           #e8b818  sombra de las letras     → acento sobre fondos claros (mejor contraste que el amarillo)
   El logo siempre va sobre una placa blanca (.brand-plate): sus contornos y "FERRETERÍA" son verde bosque
   y desaparecen sobre fondos oscuros. El rojo se reserva para alertas de stock.
   Sin fuentes externas: funciona sin conexión. */

:root {
  /* Paleta de marca (no cambia con el tema) */
  --brand-forest: #063c1e;
  --brand-green: #0c843c;
  --brand-lime: #a6c83a;
  --brand-yellow: #f8d810;
  --brand-gold: #e8b818;

  /* Roles */
  --bg: #eef2ec;
  --surface: #ffffff;
  --surface-2: #f4f7f2;
  --line: #d4ddd3;
  --text: #15241b;
  --muted: #56665b;
  --chrome: var(--brand-forest);
  --chrome-2: #0b4d28;
  --chrome-line: #1c5634;
  --chrome-text: #cfe1d4;
  --chrome-muted: #93b39c;
  --primary: var(--brand-green);
  --primary-hover: #0a7234;
  --primary-ink: #ffffff;
  --accent: var(--brand-yellow);
  --accent-ink: var(--brand-forest);
  --highlight: var(--brand-gold);
  --link: #0a7234;
  --chart: var(--brand-green);
  --red: #c62828;
  --red-bg: #fdeceb;
  --amber-bg: #fff6cc;
  --green: #0a7234;
  --green-bg: #e2f3e6;
  --radius: 10px;
  --nav-h: 62px;
  --focus: 0 0 0 3px color-mix(in srgb, var(--primary) 45%, transparent);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1510;
    --surface: #142019;
    --surface-2: #1b2a21;
    --line: #2a3d31;
    --text: #e5ede7;
    --muted: #93a69a;
    --chrome: #052e17;
    --chrome-2: #0a4022;
    --chrome-line: #17472b;
    --primary: #12994a;
    --primary-hover: #15a852;
    --highlight: var(--brand-yellow);
    --link: var(--brand-lime);
    --chart: #3fae63;
    --red: #ff6b6b;
    --red-bg: #3a1c1c;
    --amber-bg: #3a3410;
    --green: #7fd08a;
    --green-bg: #15301f;
    --focus: 0 0 0 3px color-mix(in srgb, var(--brand-lime) 60%, transparent);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  overscroll-behavior-y: none;
}
h1, h2, h3 { margin: 0; line-height: 1.15; letter-spacing: -0.01em; }
h1 { font-size: 1.55rem; font-weight: 780; }
h2 { font-size: 1.1rem; font-weight: 720; }
h3 { font-size: 0.95rem; font-weight: 700; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--link); }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.84rem; }
.num { font-variant-numeric: tabular-nums; text-align: right; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.stack { display: grid; gap: 14px; }
.spacer { height: 12px; }

/* ---------- Botones y campos ---------- */
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 9px 14px; border-radius: 8px; font-weight: 600; cursor: pointer; min-height: 40px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.dark { background: var(--chrome); border-color: var(--chrome); color: #fff; }
.btn.danger { color: var(--red); border-color: color-mix(in srgb, var(--red) 40%, var(--line)); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { min-height: 34px; padding: 5px 10px; font-size: 0.88rem; }
.btn.block { width: 100%; }
.btn.lg { min-height: 52px; font-size: 1.05rem; }

.field { display: grid; gap: 5px; }
.field > span { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; min-height: 42px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--text);
}
textarea.input { min-height: 74px; resize: vertical; }
.input:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.input-group { display: flex; gap: 6px; }
.input-group .input { flex: 1; }
.error-text { color: var(--red); font-weight: 600; font-size: 0.9rem; }

.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 2px; }
.segmented button {
  border: 0; background: transparent; padding: 7px 12px; border-radius: 7px; font-weight: 650; cursor: pointer; color: var(--muted); min-height: 34px;
}
.segmented button[aria-pressed="true"] { background: var(--chrome); color: #fff; }
@media (prefers-color-scheme: dark) { .segmented button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); } }

/* ---------- Estructura ---------- */
.shell { min-height: 100vh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 236px; background: var(--chrome); color: var(--chrome-text);
  display: flex; flex-direction: column; padding: 18px 12px; gap: 4px; z-index: 5;
}
/* Logo sobre placa blanca, con el filo amarillo de la marca */
.brand-plate {
  display: block; background: #fff; border-radius: 12px; padding: 10px 14px; border-bottom: 4px solid var(--brand-yellow);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08);
}
.brand-plate img { display: block; width: 100%; height: auto; }
.sidebar .brand-plate { margin: 0 2px 16px; }
.nav-link {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 8px; color: var(--chrome-text);
  text-decoration: none; font-weight: 600; border: 0; background: transparent; cursor: pointer; text-align: left; width: 100%;
}
.nav-link svg { width: 20px; height: 20px; flex: none; }
.nav-link:hover { background: var(--chrome-2); color: #fff; }
.nav-link[aria-current="page"] { background: var(--accent); color: var(--accent-ink); }
.sidebar .sep { height: 1px; background: var(--chrome-line); margin: 8px 6px; }
.sidebar .user { margin-top: auto; padding: 10px 12px; border-top: 1px solid var(--chrome-line); font-size: 0.85rem; color: var(--chrome-muted); }
.sidebar .user strong { display: block; color: #fff; font-size: 0.92rem; }

.main { margin-left: 236px; padding: 26px 30px 60px; max-width: 1280px; }
.topbar { display: none; }
.bottom-nav { display: none; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.card > h2, .card > .card-head { margin-bottom: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

@media (max-width: 899px) {
  .sidebar { display: none; }
  .main { margin-left: 0; padding: 14px 14px calc(var(--nav-h) + 28px + env(safe-area-inset-bottom)); }
  .topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 10px; position: sticky; top: 0; z-index: 4;
    background: var(--chrome); color: #fff; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; font-weight: 800;
  }
  .topbar { border-bottom: 3px solid var(--brand-yellow); }
  .topbar .brand-plate { padding: 4px 8px; border-radius: 8px; border-bottom-width: 0; }
  .topbar .brand-plate img { width: auto; height: 34px; }
  .bottom-nav {
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; position: fixed; inset: auto 0 0 0; z-index: 6;
    background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
  }
  .bottom-nav a, .bottom-nav button {
    display: grid; justify-items: center; gap: 2px; padding: 8px 2px 7px; min-height: var(--nav-h); border: 0; background: transparent;
    color: var(--muted); text-decoration: none; font-size: 0.72rem; font-weight: 650; cursor: pointer;
  }
  .bottom-nav svg { width: 24px; height: 24px; }
  .bottom-nav [aria-current="page"] { color: var(--link); box-shadow: inset 0 3px 0 var(--accent); }
  .form-grid { grid-template-columns: 1fr; }
  h1 { font-size: 1.35rem; }
}

/* ---------- Etiqueta de góndola (KPI) ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 18px; }
.tag {
  position: relative; background: var(--surface); border: 1px solid var(--line); border-top: 7px solid var(--highlight);
  border-radius: 4px 4px 12px 12px; padding: 18px 16px 14px;
}
.tag::before {
  content: ""; position: absolute; top: -1px; left: 50%; width: 14px; height: 14px; margin-left: -7px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 50%; transform: translateY(-50%);
}
.tag .label { color: var(--muted); font-weight: 650; font-size: 0.86rem; }
.tag .value { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.02em; margin: 2px 0; }
.tag .hint { color: var(--muted); font-size: 0.82rem; }
.tag.alert { border-top-color: var(--red); }
.tag.alert .value { color: var(--red); }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 14px; margin-bottom: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 14px; }
@media (max-width: 1100px) { .grid-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 899px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ---------- Gráficos ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart .bar { fill: var(--chart); }
.chart .bar.peak { fill: var(--highlight); }
.chart .axis { stroke: var(--line); }
.chart text { fill: var(--muted); font-size: 11px; }
.hbars { display: grid; gap: 10px; }
.hbar .meta { display: flex; justify-content: space-between; gap: 10px; font-size: 0.9rem; margin-bottom: 3px; }
.hbar .meta span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .track { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--chart); border-radius: 4px; }
.hbar .fill.accent { background: var(--highlight); }

/* ---------- Listas ---------- */
.list { display: grid; }
.list-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 14px; align-items: center; padding: 12px 4px;
  border-bottom: 1px solid var(--line); width: 100%; text-align: left; background: transparent; border-left: 0; border-right: 0; border-top: 0;
  cursor: pointer; color: inherit;
}
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: var(--surface-2); }
.list-row .title { font-weight: 650; overflow: hidden; text-overflow: ellipsis; }
.list-row .sub { color: var(--muted); font-size: 0.84rem; }
.list-row .end { text-align: right; }
.list-row.static { cursor: default; }
.list-row.static:hover { background: transparent; }

@media (min-width: 900px) {
  .products-list .list-row { grid-template-columns: minmax(0, 2.4fr) 1fr 0.9fr 0.9fr 0.9fr; }
  .products-list .head { font-size: 0.8rem; color: var(--muted); font-weight: 650; cursor: default; padding-bottom: 8px; }
  .products-list .head:hover { background: transparent; }
  .products-list .cell-cat, .products-list .cell-price, .products-list .cell-loc { display: block; }
}
@media (max-width: 899px) {
  .products-list .head, .products-list .cell-cat, .products-list .cell-loc { display: none; }
  .products-list .cell-price { display: none; }
}
.products-list .cell-name { min-width: 0; }

.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 0.8rem; font-weight: 700;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--line); white-space: nowrap;
}
.badge.ok { background: var(--green-bg); color: var(--green); border-color: transparent; }
.badge.low { background: var(--amber-bg); color: var(--text); border-color: var(--highlight); }
.badge.out { background: var(--red-bg); color: var(--red); border-color: transparent; }
.badge.void { text-decoration: line-through; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.toolbar .input { width: auto; flex: 1 1 200px; }
.toolbar select.input { flex: 0 1 190px; }

.empty { text-align: center; color: var(--muted); padding: 34px 12px; }
.empty strong { display: block; color: var(--text); font-size: 1.02rem; margin-bottom: 4px; }

.dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 0.92rem; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; text-align: right; font-weight: 600; }

/* ---------- Modal / hoja inferior ---------- */
dialog {
  border: 0; padding: 0; border-radius: 14px; background: var(--surface); color: var(--text);
  width: min(620px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}
dialog::backdrop { background: rgba(10, 12, 14, 0.55); }
dialog[open] { display: flex; flex-direction: column; }
dialog.wide { width: min(760px, calc(100vw - 24px)); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 18px 10px; }
.dlg-body { padding: 4px 18px 18px; overflow-y: auto; display: grid; gap: 14px; }
.dlg-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); flex-wrap: wrap; }
@media (max-width: 899px) {
  dialog { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: 16px 16px 0 0; max-height: 92dvh; }
  .dlg-foot .btn { flex: 1 1 auto; }
}

/* ---------- Avisos ---------- */
#toasts { position: fixed; z-index: 100; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom)); display: grid; gap: 8px; width: min(440px, calc(100vw - 24px)); pointer-events: none; }
@media (min-width: 900px) { #toasts { bottom: 24px; } }
.toast { background: var(--chrome); color: #fff; padding: 12px 14px; border-radius: 10px; font-weight: 600; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3); border-left: 5px solid var(--accent); animation: toast-in 0.18s ease-out; }
.toast.error { border-left-color: #ff6b6b; }
.toast.ok { border-left-color: var(--brand-lime); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

.pill-offline { background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 3px 10px; font-size: 0.78rem; font-weight: 800; }

/* ---------- Escáner ---------- */
.scanner { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 4 / 3; max-height: 52dvh; width: 100%; }
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner .frame { position: absolute; inset: 18% 14%; border: 3px solid var(--accent); border-radius: 14px; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.38); pointer-events: none; }
.scanner .frame::after { content: ""; position: absolute; left: 8px; right: 8px; top: 50%; height: 2px; background: var(--accent); opacity: 0.85; animation: scan-line 1.8s ease-in-out infinite alternate; }
@keyframes scan-line { from { top: 12%; } to { top: 88%; } }
@media (prefers-reduced-motion: reduce) { .scanner .frame::after { animation: none; } }
.scanner .overlay-msg { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; color: #fff; padding: 20px; gap: 6px; background: #08140d; }
.scanner .controls { position: absolute; right: 8px; bottom: 8px; display: flex; gap: 6px; }
.scanner .controls .btn { background: rgba(0, 0, 0, 0.6); color: #fff; border-color: transparent; }

.result-card { border-left: 6px solid var(--accent); }
.result-card.missing { border-left-color: var(--red); }
.qty-input { display: flex; gap: 6px; align-items: stretch; }
.qty-input .input { text-align: center; font-weight: 750; font-size: 1.2rem; min-height: 50px; }
.qty-input .btn { min-width: 50px; font-size: 1.3rem; }
.big-stock { font-size: 2.1rem; font-weight: 800; line-height: 1; }

/* ---------- Punto de venta ---------- */
.pos { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 14px; align-items: start; }
@media (max-width: 899px) { .pos { grid-template-columns: 1fr; } }
.cart-line { display: grid; grid-template-columns: minmax(0, 1fr) 92px auto; gap: 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.cart-line .input { min-height: 38px; text-align: center; }
.total-box { display: flex; justify-content: space-between; align-items: baseline; font-size: 1.6rem; font-weight: 800; padding: 12px 0 4px; }
.suggest { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-top: 6px; background: var(--surface); }

/* ---------- Login ---------- */
.login {
  min-height: 100dvh; display: grid; place-items: center; padding: 20px; background-color: var(--chrome);
  /* cercha diagonal tenue, como la viga del logo */
  background-image: repeating-linear-gradient(45deg, transparent 0 46px, rgba(166, 200, 58, 0.07) 46px 50px),
    repeating-linear-gradient(-45deg, transparent 0 46px, rgba(166, 200, 58, 0.05) 46px 50px);
}
.login-card { width: min(400px, 100%); background: var(--surface); border-radius: 14px; padding: 26px 22px; display: grid; gap: 16px; border-top: 8px solid var(--accent); }
.login-card .brand-plate { padding: 14px 28px 12px; margin: -6px -2px 4px; }

/* ---------- Etiquetas imprimibles ---------- */
#print-area { display: none; }
.label-sheet { display: grid; grid-template-columns: repeat(3, 62mm); gap: 3mm; justify-content: center; }
.label-sheet .label { width: 62mm; height: 34mm; border: 0.3mm dashed #888; border-radius: 1.5mm; padding: 2mm; display: grid; grid-template-columns: 26mm 1fr; gap: 2.5mm; align-items: center; color: #000; background: #fff; break-inside: avoid; font-family: system-ui, Arial, sans-serif; }
.label-sheet .label svg { width: 26mm; height: 26mm; display: block; }
.label-sheet .label .l-name { font-size: 8.5pt; font-weight: 700; line-height: 1.15; max-height: 3.5em; overflow: hidden; }
.label-sheet .label .l-sku { font-size: 7.5pt; font-family: ui-monospace, Menlo, Consolas, monospace; margin-top: 1mm; }
.label-sheet .label .l-price { font-size: 13pt; font-weight: 800; margin-top: 1mm; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; }
  body { background: #fff; }
  @page { size: A4; margin: 9mm; }
}

/* ---------- Varios ---------- */
.skeleton { height: 14px; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2), var(--line), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }
.qr-box { width: 140px; height: 140px; background: #fff; padding: 6px; border-radius: 8px; border: 1px solid var(--line); flex: none; }
.qr-box svg { width: 100%; height: 100%; display: block; }
.check-col { width: 22px; height: 22px; accent-color: var(--primary); }
