:root {
  --bg: #f4f5f7; --card: #ffffff; --text: #1b1f24; --muted: #667080; --border: #dde1e6;
  --accent: #1f6feb; --accent-soft: #e3edfd; --ok: #1a7f37; --ok-soft: #dcf3e3;
  --warn: #9a6700; --warn-soft: #fff4d6; --bad: #c62828; --bad-soft: #fde4e4;
  --pcb: #1d6b3c; --grid: #eef0f3;
  --radius: 10px; --shadow: 0 1px 2px rgb(0 0 0 / .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --card: #181c22; --text: #e6e9ee; --muted: #98a1ae; --border: #2a3039;
    --accent: #5b9bff; --accent-soft: #1b2a44; --ok: #4ac26b; --ok-soft: #15301f;
    --warn: #e0b341; --warn-soft: #362b10; --bad: #ff6b6b; --bad-soft: #3a1818;
    --pcb: #4ac26b; --grid: #1d2229; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
a { color: var(--accent); }
header.top {
  position: sticky; top: 0; z-index: 1000; background: var(--card); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px; padding: 10px 16px;
}
header.top h1 { font-size: 16px; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header.top select { max-width: 45vw; }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
nav.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 1000; display: flex;
  background: var(--card); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs a {
  flex: 1; text-align: center; padding: 8px 2px 10px; font-size: 12px; color: var(--muted); text-decoration: none;
}
nav.tabs a .ico { display: block; font-size: 20px; line-height: 1.2; }
nav.tabs a.active { color: var(--accent); font-weight: 600; }
@media (min-width: 800px) {
  body { padding-bottom: 0; }
  nav.tabs { position: sticky; top: 49px; bottom: auto; border-top: 0; border-bottom: 1px solid var(--border); justify-content: center; }
  nav.tabs a { flex: 0 0 auto; padding: 10px 18px; font-size: 14px; }
  nav.tabs a .ico { display: inline; font-size: 15px; margin-right: 6px; }
}
section.view { display: none; }
section.view.active { display: block; }
h2 { font-size: 18px; margin: 4px 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); min-width: 0;
}
.card.wide { grid-column: 1 / -1; }
.card .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.card .value { font-size: 24px; font-weight: 650; margin: 2px 0; font-variant-numeric: tabular-nums; }
.card .sub { font-size: 13px; color: var(--muted); }
.card.bad { border-color: var(--bad); background: var(--bad-soft); }
.card.warn { border-color: var(--warn); background: var(--warn-soft); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent); vertical-align: middle;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.grey { background: var(--border); color: var(--muted); }
.bar { height: 8px; background: var(--border); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar > span { display: block; height: 100%; background: var(--ok); }
.banner { border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; border: 1px solid; }
.banner.warn { background: var(--warn-soft); border-color: var(--warn); }
.banner.bad { background: var(--bad-soft); border-color: var(--bad); }
.banner.ok { background: var(--ok-soft); border-color: var(--ok); }
.banner.info { background: var(--accent-soft); border-color: var(--accent); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
button, select, input, textarea {
  font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; min-height: 36px;
}
button { cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.seg { border-radius: 99px; padding: 5px 12px; }
button.seg.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
button:disabled { opacity: .5; cursor: default; }
input[type=checkbox] { min-height: 0; width: 20px; height: 20px; accent-color: var(--accent); }
.legend-note { font-size: 12px; color: var(--muted); margin-top: 6px; }
form.cfg { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.field label { display: block; font-weight: 600; font-size: 14px; }
.field .hint { font-size: 12px; color: var(--muted); }
.field input[type=number] { width: 100%; margin-top: 4px; }
.field.err input { border-color: var(--bad); }
.field .errmsg { color: var(--bad); font-size: 12px; }
.check { display: flex; gap: 10px; align-items: center; padding: 6px 0; }
.changed { background: var(--warn-soft); }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.err td { background: var(--bad-soft); }
tr.warnrow td { background: var(--warn-soft); }
.scroll { overflow-x: auto; }
@media (max-width: 640px) {
  table.stack thead { display: none; }
  table.stack tr { display: block; border-bottom: 1px solid var(--border); padding: 6px 0; }
  table.stack td { display: flex; justify-content: space-between; gap: 10px; border: 0; padding: 3px 4px; text-align: right; }
  table.stack td::before { content: attr(data-l); color: var(--muted); font-size: 12px; text-align: left; }
}
pre.raw { white-space: pre-wrap; word-break: break-all; font-size: 12px; max-height: 300px; overflow: auto; background: var(--bg); padding: 8px; border-radius: 6px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-wrap form { width: 100%; max-width: 340px; display: grid; gap: 12px; }
.login-wrap input { width: 100%; }
.error { color: var(--bad); font-size: 14px; }

/* ---------------------------------------------------------------- inventario */
.search { width: 100%; font-size: 17px; padding: 10px 12px; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; scrollbar-width: none; }
.chips button { flex: 0 0 auto; }
.items { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.item {
  display: grid; grid-template-columns: 76px 1fr; gap: 10px; align-items: center; cursor: pointer;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px;
  color: inherit; text-decoration: none; min-width: 0;
}
.item:hover { border-color: var(--accent); }
.item .thumb { width: 76px; height: 56px; }
.item .name { font-weight: 650; line-height: 1.25; overflow-wrap: anywhere; }
.item .meta { font-size: 13px; color: var(--muted); margin-top: 2px; }
.item .locs { font-size: 12px; margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px; }
.thumb { object-fit: contain; background: var(--grid); border-radius: 6px; padding: 3px; display: block; }
.code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12px; font-weight: 600;
  background: var(--bg); border: 1px solid var(--border); border-radius: 5px; padding: 0 5px; white-space: nowrap; }
.qty { font-variant-numeric: tabular-nums; font-weight: 700; }
.empty { text-align: center; padding: 30px 10px; color: var(--muted); }
.summary { font-size: 13px; color: var(--muted); margin: -4px 0 10px; }

/* ---------------------------------------------------------------- ficha */
.hero { display: grid; gap: 14px; grid-template-columns: 1fr; margin-bottom: 12px; }
@media (min-width: 720px) { .hero { grid-template-columns: 340px 1fr; } }
.hero .pic { width: 100%; aspect-ratio: 4 / 3; }
.hero h2 { font-size: 21px; margin: 0 0 4px; }
.big-qty { font-size: 34px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stepper { display: inline-flex; align-items: center; gap: 6px; }
.stepper button { min-width: 36px; padding: 4px 8px; font-weight: 700; }
.stepper .qty { min-width: 2.2em; text-align: center; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.attrib { font-size: 12px; color: var(--muted); margin-top: 6px; }
.back { display: inline-block; margin-bottom: 10px; text-decoration: none; }
.section { margin-top: 16px; }
.kv dd { overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- formularios */
form.grid-form { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.field input, .field select, .field textarea { width: 100%; margin-top: 4px; }
.field input[type=checkbox] { width: 20px; margin: 0; }
.field label.check { font-weight: 400; display: flex; }
.field.full { grid-column: 1 / -1; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline input[type=number] { width: 90px; }
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); color: var(--text);
  padding: 16px; width: min(460px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto; }
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog h3 { margin-top: 0; }
dialog .toolbar:last-child { margin: 14px 0 0; justify-content: flex-end; }
button.danger { color: var(--bad); border-color: var(--bad); }
#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(76px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 99px; z-index: 2000;
  font-size: 14px; box-shadow: 0 4px 16px rgb(0 0 0 / .25); max-width: calc(100vw - 32px); display: none;
}
#toast.show { display: block; }
#toast.bad { background: var(--bad); color: #fff; }
@media (min-width: 800px) { #toast { bottom: 24px; } }

/* ---------------------------------------------------------------- añadir */
.pick { display: grid; grid-template-columns: 96px 1fr; gap: 12px; align-items: center; }
.pick .thumb { width: 96px; height: 72px; }
.steps { display: grid; gap: 12px; }

/* ---------------------------------------------------------------- cajones (Gridfinity) */
.drawers { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); margin-top: 8px; }
.drawer-btn { text-align: left; padding: 10px; }
.drawer-btn b { display: block; }
.gf-wrap { overflow-x: auto; }
.gf {
  --cell: clamp(30px, calc((100vw - 64px) / var(--cols) - 3px), 64px); display: grid; gap: 3px; padding: 6px; background: var(--grid); border: 2px solid var(--border);
  border-radius: 8px; width: max-content; margin: 0 auto; position: relative;
  grid-template-columns: repeat(var(--cols), var(--cell)); grid-auto-rows: var(--cell);
}
.gf .cell { border: 1px dashed var(--border); border-radius: 5px; cursor: default; }
.gf.editing .cell { cursor: pointer; border-color: var(--muted); }
.gf .cell.sel { background: var(--accent-soft); border: 2px solid var(--accent); }
.gf .bin {
  background: var(--card); border: 1px solid var(--border); border-radius: 6px; box-shadow: var(--shadow);
  position: relative; overflow: hidden; cursor: pointer; padding: 2px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; min-width: 0; min-height: 0; color: inherit; font: inherit;
}
.gf.dense .bin .nm { display: none; }
.gf.dense .bin img { max-height: 70%; }
.gf.dense .bin .lbl, .gf.dense .bin .n, .gf.dense .bin .more { font-size: 9px; }
.gf .bin:hover, .gf .bin.on { border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: -1px; }
.gf .bin.empty-bin { background: transparent; }
.gf .bin .lbl { position: absolute; top: 1px; left: 3px; font-size: 10px; font-weight: 700; color: var(--muted); }
.gf .bin .more { position: absolute; top: 1px; right: 3px; font-size: 10px; font-weight: 700; color: var(--accent); }
.gf .bin .n { position: absolute; bottom: 1px; right: 3px; font-size: 10px; font-weight: 700; }
.gf .bin img { max-width: 92%; max-height: 62%; object-fit: contain; }
.gf .bin .nm { font-size: 9px; line-height: 1.1; text-align: center; max-width: 100%; overflow: hidden;
  white-space: nowrap; text-overflow: ellipsis; padding: 0 2px; }
.gf-front { text-align: center; font-size: 12px; color: var(--muted); margin: 4px 0; letter-spacing: .1em; text-transform: uppercase; }

/* ---------------------------------------------------------------- tarjetas (vista previa) */
.preview-box { background: var(--grid); border-radius: var(--radius); padding: 16px; overflow: auto; display: flex; justify-content: center; }
.preview-box .ccard { box-shadow: 0 2px 10px rgb(0 0 0 / .18); }
