/* ==========================================================
   Sistema Ferretería MyM — estilos (sin dependencias)
   Paleta tomada del logo: azul marino, dorado, rojo y crema
   ========================================================== */
:root {
  --navy: #1b2a4a;
  --navy-2: #24365e;
  --navy-3: #0f1a33;
  --gold: #e3a92b;
  --gold-2: #f4c95d;
  --red: #c23a2b;
  --cream: #f7f2e7;
  --bg: #f3f0e9;
  --card: #ffffff;
  --text: #1d2433;
  --muted: #677086;
  --line: #e4dfd3;
  --ok: #1f8a4c;
  --ok-bg: #e5f4ea;
  --warn: #b26b00;
  --warn-bg: #fdf1d9;
  --err-bg: #fbe6e3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 4px 14px rgba(20, 30, 50, .05);
  --side: 236px;
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); line-height: 1.45;
}
a { color: var(--navy-2); }
h1, h2, h3 { margin: 0 0 .6rem; line-height: 1.2; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
small, .muted { color: var(--muted); }
.ico { width: 18px; height: 18px; flex: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.text-ok { color: var(--ok); } .text-err { color: var(--red); } .text-warn { color: var(--warn); }
.hidden { display: none !important; }

/* ---------- Layout ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--side); background: var(--navy);
  color: #dfe5f2; display: flex; flex-direction: column; z-index: 40; transition: transform .2s;
}
.brand { display: flex; align-items: center; gap: .6rem; padding: 1rem .9rem; color: #fff; text-decoration: none; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand img { width: 46px; height: 46px; object-fit: contain; border-radius: 50%; background: var(--cream); padding: 2px; }
.brand span { font-weight: 700; font-size: 1rem; color: var(--gold-2); letter-spacing: .3px; }
.sidebar nav { flex: 1; overflow-y: auto; padding: .6rem .5rem; }
.sidebar nav a {
  display: flex; align-items: center; gap: .7rem; padding: .62rem .8rem; border-radius: 8px;
  color: #cfd7e8; text-decoration: none; font-size: .95rem; margin-bottom: 2px;
}
.sidebar nav a:hover { background: var(--navy-2); color: #fff; }
.sidebar nav a.active { background: var(--gold); color: var(--navy-3); font-weight: 600; }
.side-foot { padding: .6rem 1rem; font-size: .75rem; color: #8b97b3; }
.main { margin-left: var(--side); min-height: 100vh; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: .8rem;
  background: #fff; border-bottom: 3px solid var(--gold); padding: .55rem 1.2rem;
}
.content { padding: 1.2rem; flex: 1; width: 100%; max-width: 1500px; }
.user-box { display: flex; align-items: center; gap: .4rem; margin-left: auto; font-size: .9rem; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; border: 0; background: transparent; border-radius: 8px; color: var(--navy); cursor: pointer; }
.icon-btn:hover { background: var(--cream); }
.only-mobile { display: none; }
.backdrop { display: none; }

/* Buscador global */
.gsearch { position: relative; flex: 1; max-width: 520px; display: flex; align-items: center; }
.gsearch .ico { position: absolute; left: 10px; color: var(--muted); }
.gsearch input { width: 100%; padding: .55rem .8rem .55rem 2.1rem; border: 1px solid var(--line); border-radius: 999px; background: var(--bg); font: inherit; }
.gsearch input:focus { outline: 2px solid var(--gold); background: #fff; }
.gs-results { position: absolute; top: 110%; left: 0; right: 0; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); max-height: 420px; overflow-y: auto; display: none; z-index: 50; }
.gs-results.open { display: block; }
.gs-item { display: flex; justify-content: space-between; gap: .6rem; padding: .55rem .8rem; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--text); }
.gs-item:hover, .gs-item.sel { background: var(--cream); }
.gs-item small { display: block; }

/* ---------- Componentes ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: .8rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head h1 { margin: 0; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem; border: 1px solid #ece7dc; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .6rem; gap: .5rem; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 1rem; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stat { background: #fff; border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); border-left: 5px solid var(--navy); }
.stat .lbl { font-size: .8rem; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.stat .val { font-size: 1.5rem; font-weight: 700; margin-top: .2rem; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: .82rem; color: var(--muted); }
.stat.gold { border-left-color: var(--gold); }
.stat.green { border-left-color: var(--ok); }
.stat.red { border-left-color: var(--red); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .55rem .95rem;
  border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--text); font: inherit;
  font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; line-height: 1.2;
}
.btn:hover { filter: brightness(.96); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn-gold { background: var(--gold); border-color: var(--gold); color: var(--navy-3); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-sm { padding: .3rem .55rem; font-size: .85rem; }
.btn-block { width: 100%; }
.btn-lg { padding: .85rem 1.2rem; font-size: 1.05rem; }

input, select, textarea {
  font: inherit; padding: .5rem .65rem; border: 1px solid #d6d0c2; border-radius: 8px; background: #fff; color: var(--text); width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); border-color: var(--gold); }
label { display: flex; flex-direction: column; gap: .25rem; font-size: .88rem; font-weight: 600; color: #3a4258; }
label.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: 500; }
label.check input { width: auto; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem; }
.form-grid.g3f { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: 1 / -1; }
.filters { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: .8rem; }
.filters label { min-width: 140px; flex: 1; max-width: 260px; }
.filters .grow { max-width: none; flex: 2; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); background: #faf8f3; padding: .55rem .6rem; border-bottom: 2px solid var(--line); white-space: nowrap; }
td { padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:hover { background: #fcfaf5; }
tr.anulada td { color: #9aa0ad; text-decoration: line-through; }
.thumb { width: 38px; height: 38px; border-radius: 6px; object-fit: cover; background: var(--cream); }

.badge { display: inline-block; padding: .2rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 700; text-decoration: none; white-space: nowrap; background: #eceff5; color: var(--navy); }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-err { background: var(--err-bg); color: var(--red); }
.alert { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: .93rem; }
.alert-ok { background: var(--ok-bg); color: #145c33; border: 1px solid #bfe3cc; }
.alert-err { background: var(--err-bg); color: #8f2418; border: 1px solid #f1c3bc; }
.alert-warn { background: var(--warn-bg); color: #7a4a00; border: 1px solid #f1d9a6; }
.empty { text-align: center; color: var(--muted); padding: 1.5rem; }
.pager { display: flex; gap: .3rem; align-items: center; justify-content: flex-end; margin-top: .8rem; flex-wrap: wrap; }
.pager a { padding: .3rem .65rem; border: 1px solid var(--line); border-radius: 6px; text-decoration: none; background: #fff; }
.pager a.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.tabs { display: flex; gap: .3rem; border-bottom: 2px solid var(--line); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a { padding: .55rem .9rem; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -2px; }
.tabs a.active { color: var(--navy); border-color: var(--gold); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .3rem 1rem; font-size: .93rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }

/* ---------- Modales (dialog nativo) ---------- */
dialog { border: 0; border-radius: 12px; padding: 0; width: min(640px, calc(100vw - 24px)); box-shadow: 0 20px 60px rgba(0,0,0,.3); color: var(--text); }
dialog.wide { width: min(980px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(15, 26, 51, .55); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: .9rem 1.1rem; background: var(--navy); color: #fff; }
.modal-head h2 { margin: 0; color: #fff; }
.modal-head .icon-btn { color: #fff; }
.modal-head .icon-btn:hover { background: var(--navy-2); }
.modal-body { padding: 1.1rem; max-height: calc(100vh - 170px); overflow-y: auto; }
.modal-foot { padding: .8rem 1.1rem; display: flex; justify-content: flex-end; gap: .5rem; border-top: 1px solid var(--line); background: #faf8f3; }

.toast { position: fixed; bottom: 18px; right: 18px; background: var(--navy); color: #fff; padding: .75rem 1.1rem; border-radius: 10px; box-shadow: var(--shadow); opacity: 0; transform: translateY(10px); transition: .2s; z-index: 100; max-width: 360px; pointer-events: none; }
.toast.show { opacity: 1; transform: none; }
.toast.err { background: var(--red); }

/* ---------- Login ---------- */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: radial-gradient(circle at 20% 10%, var(--navy-2), var(--navy-3)); }
.auth-card { background: #fff; border-radius: 16px; padding: 1.8rem; width: 100%; max-width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,.35); border-top: 6px solid var(--gold); }
.auth-card h1 { text-align: center; font-size: 1.3rem; }
.auth-card form { display: flex; flex-direction: column; gap: .8rem; }
.auth-card .form-grid { display: grid; }
.auth-logo { display: block; width: 120px; height: 120px; object-fit: contain; margin: -.5rem auto .6rem; }

/* ---------- POS ---------- */
.pos-page .content { max-width: none; }
.pos { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 1rem; align-items: start; }
.pos-search { position: relative; }
.pos-search input { font-size: 1.1rem; padding: .8rem 1rem .8rem 2.6rem; border: 2px solid var(--navy); border-radius: 10px; }
.pos-search > .ico { position: absolute; left: 12px; top: 15px; color: var(--navy); width: 20px; height: 20px; }
.pos-results { position: absolute; top: 100%; left: 0; right: 0; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 30px rgba(0,0,0,.15); z-index: 20; max-height: 360px; overflow-y: auto; display: none; }
.pos-results.open { display: block; }
.pr-item { display: grid; grid-template-columns: 42px 1fr auto; gap: .6rem; align-items: center; padding: .5rem .7rem; cursor: pointer; border-bottom: 1px solid var(--line); }
.pr-item:hover, .pr-item.sel { background: var(--cream); }
.pr-item .thumb { width: 42px; height: 42px; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin: .7rem 0; }
.chip { padding: .35rem .75rem; border-radius: 999px; border: 1px solid var(--line); background: #fff; font-size: .85rem; cursor: pointer; font-weight: 600; color: var(--navy); }
.chip:hover, .chip.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.chip.fav { border-color: var(--gold); background: #fff8e6; color: var(--navy-3); }
.chip.fav:hover { background: var(--gold); }
.cart td { padding: .4rem .45rem; }
.cart input { padding: .35rem .4rem; text-align: right; width: 82px; }
.cart input.pct { width: 70px; }
.cart .pname { font-weight: 600; line-height: 1.25; min-width: 170px; }
.cart .pname small { display: block; font-weight: 400; }
.cart tr.nostock { background: #fff2f0; }
.cart tr.sel { outline: 2px solid var(--gold); outline-offset: -2px; }
.pos-side { position: sticky; top: 76px; }
.totals { font-size: 1rem; }
.totals .row { display: flex; justify-content: space-between; padding: .3rem 0; }
.totals .grand { font-size: 1.7rem; font-weight: 800; color: var(--navy); border-top: 2px solid var(--navy); margin-top: .4rem; padding-top: .5rem; }
.totals .gain { color: var(--ok); font-weight: 700; }
.pay-row { display: grid; grid-template-columns: 1fr 120px 34px; gap: .4rem; margin-bottom: .4rem; }
.kbd { display: inline-block; font-size: .72rem; padding: 0 .35rem; border: 1px solid #c9c2b2; border-bottom-width: 2px; border-radius: 4px; background: #faf8f3; font-family: ui-monospace, monospace; color: var(--navy); }
.shortcuts { font-size: .8rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: .3rem .8rem; }

/* ---------- Importación de listas ---------- */
.drop { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .3rem; text-align: center;
  border: 2px dashed #c9c1ad; border-radius: 12px; padding: 2rem 1rem; background: #fcfaf5; cursor: pointer; font-weight: 500; transition: .15s; }
.drop:hover, .drop.over { border-color: var(--gold); background: #fff8e6; }
.drop b { font-size: 1.05rem; color: var(--navy); }
#vista td, #vista th { font-size: .82rem; white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
#vista tr.ign td { color: #b0b5c0; }
#vista th.map-cod { background: #e8eefb; } #vista th.map-desc { background: #fff3d6; } #vista th.map-precio { background: #e3f3e8; }
#resBody tr.off td { opacity: .45; }
#resBody .vinc { position: relative; }
#resBody .vinc input { padding: .25rem .4rem; font-size: .85rem; }

/* ---------- Gráficos SVG ---------- */
.chart { width: 100%; height: 260px; }
.chart text { font-size: 11px; fill: var(--muted); }
.legend { display: flex; gap: 1rem; font-size: .85rem; flex-wrap: wrap; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: .3rem; vertical-align: -1px; }
.bar-list .bl { display: grid; grid-template-columns: minmax(0, 1fr) 90px; gap: .5rem; align-items: center; margin-bottom: .45rem; font-size: .88rem; }
.bar-list .track { height: 8px; background: var(--cream); border-radius: 99px; overflow: hidden; margin-top: 3px; }
.bar-list .fill { height: 100%; background: var(--gold); border-radius: 99px; }

/* ---------- Comprobante ---------- */
.ticket { max-width: 760px; margin: 1rem auto; background: #fff; padding: 1.5rem; box-shadow: var(--shadow); border-radius: 8px; }
.ticket-head { display: flex; gap: 1rem; align-items: center; border-bottom: 2px solid var(--navy); padding-bottom: .8rem; margin-bottom: .8rem; }
.ticket-head img { width: 80px; height: 80px; object-fit: contain; }
.ticket table td, .ticket table th { padding: .35rem .4rem; }
.ticket.t80 { max-width: 320px; font-size: 12px; padding: .6rem; }
.ticket.t80 .ticket-head { flex-direction: column; text-align: center; gap: .3rem; }
.ticket.t80 .ticket-head img { width: 60px; height: 60px; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .pos { grid-template-columns: minmax(0, 1fr); }
  .pos-side { position: static; }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  body.menu-open .sidebar { transform: none; }
  body.menu-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 35; }
  .main { margin-left: 0; }
  .only-mobile { display: inline-flex; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .form-grid.g3f { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
  :root { font-size: 14px; }
  .content { padding: .8rem; }
  .topbar { padding: .5rem .7rem; gap: .4rem; }
  .hide-sm { display: none !important; }
  .form-grid, .form-grid.g3f { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
  .stat .val { font-size: 1.15rem; }
  .filters label { max-width: none; min-width: 45%; }
  .pay-row { grid-template-columns: 1fr 100px 34px; }
}

@media print {
  .sidebar, .topbar, .no-print, .toast { display: none !important; }
  .main { margin: 0; }
  body, .content { background: #fff; padding: 0; }
  .ticket { box-shadow: none; margin: 0; max-width: none; }
  .ticket.t80 { max-width: 80mm; }
  .card { box-shadow: none; border: 0; }
}
