:root {
  --brand: #0d0d0d;
  --accent: #d4ff00;
  --ink: #0d0d0d;
  --muted: #6b6b66;
  --line: #e3e3de;
  --bg: #f4f4f0;
  --card: #ffffff;
  --danger: #c92a2a;
  --font: "Archivo", system-ui, -apple-system, sans-serif;
  --font-display: "Archivo Narrow", "Archivo", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 15px; line-height: 1.45; }
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--font-display); text-transform: uppercase; letter-spacing: .01em; margin: 0; }
a { color: inherit; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 2px solid transparent; border-radius: 999px; padding: 11px 22px; font: inherit; font-weight: 800; font-size: 14px; text-transform: uppercase; letter-spacing: .03em; cursor: pointer; }
.btn:disabled { opacity: .5; cursor: default; }
.btn--accent { background: var(--accent); color: var(--brand); }
.btn--dark { background: var(--brand); color: #fff; }
.btn--ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn--sm { padding: 6px 12px; font-size: 12px; }
.link { background: none; border: 0; padding: 0; font: inherit; color: inherit; text-decoration: underline; cursor: pointer; }

/* Entrada */
.login { min-height: 100vh; display: grid; place-items: center; background: var(--brand); color: #fff; padding: 24px; }
.login__card { text-align: center; max-width: 340px; }
.login__logo { height: 72px; margin-bottom: 20px; }
.login h1 { font-size: 44px; line-height: .95; margin-bottom: 14px; }
.login h1 span { color: var(--accent); }
.login p { color: rgba(255,255,255,.7); margin: 0 0 24px; }
.login__error { color: #ff8787 !important; margin-top: 16px !important; }

/* Estructura */
.app { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--brand); color: #fff; display: flex; flex-direction: column; padding: 22px 16px; position: sticky; top: 0; height: 100vh; }
.side__brand { display: grid; grid-template-columns: auto 1fr; column-gap: 10px; align-items: center; text-decoration: none; margin: 0 6px 28px; }
.side__brand img { height: 34px; grid-row: span 2; }
.side__brand span { font-family: var(--font-display); font-weight: 700; font-style: italic; font-size: 20px; letter-spacing: .02em; line-height: 1; }
.side__brand small { color: var(--accent); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; }
.side__nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side__nav a { text-decoration: none; padding: 10px 12px; border-radius: 10px; font-weight: 600; color: rgba(255,255,255,.75); display: flex; justify-content: space-between; align-items: center; }
.side__nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.side__nav a.is-current { background: var(--accent); color: var(--brand); }
.side__nav a em { font-style: normal; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; opacity: .55; }
.side__user { border-top: 1px solid rgba(255,255,255,.12); padding: 16px 6px 0; display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.side__user span { color: var(--accent); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.side__user .link { margin-top: 10px; align-self: flex-start; color: rgba(255,255,255,.7); font-size: 13px; }
.menu-btn { display: none; }

.main { padding: 32px clamp(16px, 4vw, 48px); max-width: 1200px; width: 100%; min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.page-head h1 { font-size: 36px; line-height: 1; }
.page-head p { margin: 6px 0 0; color: var(--muted); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 22px; }
.card + .card { margin-top: 16px; }
.card h2 { font-size: 20px; margin-bottom: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px; text-decoration: none; display: flex; flex-direction: column; gap: 6px; }
.tile:hover { border-color: var(--ink); }
.tile strong { font-size: 17px; }
.tile span { color: var(--muted); font-size: 14px; }
.tag { display: inline-block; font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; padding: 3px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); }
.tag--ok { background: #e8f7d0; color: #3b6d00; }
.tag--warn { background: #fff3d6; color: #8a5a00; }
.tag--off { background: #fde2e2; color: var(--danger); }

.soon { text-align: center; padding: 56px 22px; color: var(--muted); }
.soon strong { display: block; color: var(--ink); font-size: 18px; margin-bottom: 6px; }

/* Tablas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
tr:last-child td { border-bottom: 0; }
td small { display: block; color: var(--muted); }
td.actions { text-align: right; white-space: nowrap; }

/* Formularios */
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; align-items: end; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 700; }
.field input, .field select, td select { height: 44px; font: inherit; font-size: 15px; font-weight: 500; border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; color: var(--ink); min-width: 0; }
.field input:focus, .field select:focus, td select:focus { outline: none; border-color: var(--ink); }
.form-error { color: var(--danger); font-weight: 600; margin: 12px 0 0; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--brand); color: #fff; padding: 12px 20px; border-radius: 999px; font-weight: 600; z-index: 100; box-shadow: 0 8px 30px rgba(0,0,0,.2); }
.toast.is-error { background: var(--danger); }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 60; transform: translateX(-100%); transition: transform .2s; }
  .side.is-open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .menu-btn { display: block; position: fixed; top: 14px; right: 14px; z-index: 70; width: 44px; height: 44px; border-radius: 12px; border: 0; background: var(--brand); color: #fff; font-size: 20px; cursor: pointer; }
  .main { padding-top: 72px; }
}
.tile .tag { align-self: flex-start; margin-top: 4px; }

/* ---------- Productos ---------- */
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back { display: inline-block; text-decoration: none; color: var(--muted); font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.back:hover { color: var(--ink); }
.filters { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.filters input, .filters select, .inline-add input { font: inherit; font-size: 15px; height: 42px; border: 1.5px solid var(--line); border-radius: 10px; padding: 0 12px; background: #fff; min-width: 0; }
.filters input:focus, .filters select:focus, .inline-add input:focus { outline: none; border-color: var(--ink); }
.table-click tbody tr { cursor: pointer; }
.table-click tbody tr:hover { background: var(--bg); }
.thumb { width: 56px; }
.thumb img, .thumb span { display: block; width: 44px; height: 44px; border-radius: 10px; object-fit: cover; background: var(--bg); border: 1px solid var(--line); }
td.low { color: var(--danger); font-weight: 700; }

.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.card-head h2 { margin-bottom: 0; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 12px; }
.hint.empty { margin: 4px 0; }
.form--3 { grid-template-columns: 2fr 1fr 1fr; align-items: start; }
.field textarea { font: inherit; font-size: 15px; font-weight: 500; border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px; resize: vertical; }
.field textarea:focus { outline: none; border-color: var(--ink); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 2px; }
.chip { position: relative; cursor: pointer; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span, .chip--static { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px; border: 1.5px solid var(--line); font-weight: 600; font-size: 14px; background: #fff; }
.chip input:checked + span { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 2px; }
.chip--static button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0; font-size: 12px; }
.chip--static button:hover { color: var(--danger); }
.inline-add { display: flex; gap: 8px; margin-top: 14px; max-width: 420px; }
.inline-add input { flex: 1; }

/* Fotos */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.photos figure { margin: 0; position: relative; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--bg); }
.photos img { display: block; width: 100%; aspect-ratio: 1; object-fit: contain; background: #fff; }
.photos em { position: absolute; top: 8px; left: 8px; background: var(--accent); color: var(--brand); font-style: normal; font-size: 11px; font-weight: 800; text-transform: uppercase; padding: 3px 8px; border-radius: 999px; }
.photos figure div { display: flex; justify-content: center; gap: 4px; padding: 6px; border-top: 1px solid var(--line); background: #fff; }
.photos .is-loading { aspect-ratio: 1; display: grid; place-items: center; color: var(--muted); font-size: 13px; font-weight: 600; }

/* Tablas editables */
.table-edit th { white-space: nowrap; padding: 8px 6px; }
.table-edit td { padding: 6px; }
.table-edit input:not([type=checkbox]), .table-edit select { font: inherit; font-size: 14px; width: 100%; min-width: 90px; height: 38px; border: 1.5px solid var(--line); border-radius: 8px; padding: 0 10px; background: #fff; }
.table-edit input:focus, .table-edit select:focus { outline: none; border-color: var(--ink); }
.table-edit input.num { min-width: 90px; text-align: right; }
.table-edit input.num-sm { min-width: 64px; text-align: right; }
.table-edit input.sku { min-width: 110px; text-transform: uppercase; }
.table-edit input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--brand); }
.table-edit td.center { text-align: center; }
.table-edit td.margin { font-weight: 700; white-space: nowrap; min-width: 64px; }
.table-edit td.margin.low { color: var(--danger); }
.table-rows { max-width: 640px; }
.icon-btn { width: 32px; height: 32px; border-radius: 8px; border: 1.5px solid var(--line); background: #fff; cursor: pointer; font-size: 14px; color: var(--muted); }
.icon-btn:hover:not(:disabled) { border-color: var(--ink); color: var(--ink); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn + .icon-btn { margin-left: 4px; }

.savebar { position: sticky; bottom: 0; display: flex; justify-content: flex-end; align-items: center; gap: 10px; flex-wrap: wrap; padding: 14px 0; margin-top: 16px; background: linear-gradient(to top, var(--bg) 70%, transparent); }
.savebar .form-error { margin: 0 auto 0 0; }

/* Ajustes del catálogo */
.cat { border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-top: 12px; }
.cat__head { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.cat__head > input { font: inherit; font-size: 16px; font-weight: 700; height: 42px; border: 1.5px solid var(--line); border-radius: 10px; padding: 0 12px; flex: 1; min-width: 200px; }
.cat__head > input:focus { outline: none; border-color: var(--ink); }
.cat__fields { display: flex; gap: 12px; align-items: center; font-size: 13px; font-weight: 700; color: var(--muted); flex-wrap: wrap; }
.cat__fields label { color: var(--ink); font-weight: 600; display: flex; gap: 4px; align-items: center; }
.cat__tpls { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 12px; }
.tpl__head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; margin-bottom: 6px; }
.tpl__head .link { font-size: 13px; font-weight: 700; }
.tpl__row { display: grid; grid-template-columns: 1fr 90px 32px; gap: 6px; margin-bottom: 6px; }
.tpl__row input, .tpl__row select { font: inherit; font-size: 14px; height: 34px; border: 1.5px solid var(--line); border-radius: 8px; padding: 0 8px; background: #fff; min-width: 0; }
.tpl .hint { margin: 0; }

@media (max-width: 820px) {
  .filters, .form--3, .cat__tpls { grid-template-columns: 1fr; }
}

/* ---------- Compras ---------- */
.tag--info { background: #e0f0ff; color: #0b5cad; }
.r { text-align: right !important; }
.muted { color: var(--muted); }
fieldset.plain { border: 0; padding: 0; margin: 0; min-width: 0; }
fieldset.plain[disabled] input, fieldset.plain[disabled] select, fieldset.plain[disabled] textarea { background: var(--bg); color: var(--ink); }
fieldset.plain[disabled] .chip span { opacity: .7; }
.form--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); align-items: start; }
.picker { display: flex; gap: 8px; margin: 4px 0 14px; max-width: 640px; }
.picker input { flex: 1; font: inherit; font-size: 15px; height: 42px; border: 1.5px solid var(--line); border-radius: 10px; padding: 0 12px; min-width: 0; }
.picker input:focus { outline: none; border-color: var(--ink); }
.table-edit td.label { min-width: 220px; font-weight: 600; font-size: 14px; }
.table-edit td.stock { font-weight: 700; min-width: 50px; }
.table-edit td.low, .table-edit td .low { color: var(--danger); font-weight: 700; }
.table-edit .link { font-weight: 700; }
.summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 18px; }
.summary div { background: var(--bg); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 2px; }
.summary span { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.summary strong { font-size: 22px; }
.summary small { color: var(--muted); font-size: 12px; }
.summary .is-total { background: var(--brand); color: #fff; }
.summary .is-total span, .summary .is-total small { color: rgba(255,255,255,.7); }
@media (max-width: 820px) { .form--4, .summary { grid-template-columns: 1fr; } }
.table-compact th { white-space: normal; line-height: 1.2; }
.table-compact td.label { min-width: 170px; }
.table-compact input.num { min-width: 80px; }

/* ---------- Clientes, ventas y cuentas por cobrar ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; display: flex; flex-direction: column; gap: 2px; }
.kpi span { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.kpi strong { font-size: 24px; }
.kpi small { color: var(--muted); font-size: 13px; }
.kpi--debt { border-color: var(--ink); }
.kpi--alert { background: #fff1f1; border-color: #f5c2c2; }
.kpi--alert strong { color: var(--danger); }
.debt { color: var(--danger) !important; }
.favor { color: #3b6d00; }
.ok { color: #3b6d00; font-weight: 700; }
.link { font-weight: 600; }
.danger { color: var(--danger) !important; }
.notice { background: #fff8e6; border-color: #f2dca0; }
.static { height: 44px; display: flex; align-items: center; font-weight: 700; font-size: 15px; }
.sub { font-size: 16px; margin: 22px 0 8px; }
.summary .ghost { background: transparent; }

.credit-box { margin-top: 18px; border: 1px dashed var(--line); border-radius: 12px; padding: 14px; }
.credit-box > strong { display: inline-block; margin-right: 8px; margin-bottom: 10px; }
.credit-box.is-locked { opacity: .75; }
.check-field { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; height: 44px; align-self: end; }
.check-field input { width: 18px; height: 18px; accent-color: var(--brand); }

.cust-info { display: flex; flex-wrap: wrap; gap: 8px 22px; margin-top: 14px; padding: 12px 14px; background: var(--bg); border-radius: 12px; font-size: 14px; }

.pay { display: grid; grid-template-columns: 170px 1fr 110px 90px 1fr 32px; gap: 8px; align-items: center; margin-bottom: 8px; }
.pay select, .pay input { font: inherit; font-size: 14px; height: 40px; border: 1.5px solid var(--line); border-radius: 8px; padding: 0 10px; background: #fff; min-width: 0; }
.pay select:focus, .pay input:focus { outline: none; border-color: var(--ink); }
.pay__eq { font-weight: 700; font-size: 14px; white-space: nowrap; }
.paybox { display: flex; gap: 24px; flex-wrap: wrap; margin-top: 10px; padding: 12px 14px; background: var(--bg); border-radius: 12px; }
.pay-list { margin: 0 0 12px; padding-left: 18px; }
.pay-list li { margin-bottom: 4px; }

.aging { display: flex; flex-direction: column; gap: 10px; }
.aging__row { display: grid; grid-template-columns: 110px 1fr 110px; gap: 12px; align-items: center; font-size: 14px; }
.aging__row strong { text-align: right; }
.aging__bar { height: 12px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.aging__bar i { display: block; height: 100%; background: var(--ink); border-radius: 999px; min-width: 2px; }
.aging__bar i.late { background: var(--danger); }

.adjust { display: grid; grid-template-columns: 1.4fr 1fr 1.2fr 1fr 1.2fr auto; gap: 10px; align-items: end; }
.adjust .btn { height: 44px; }
@media (max-width: 1100px) { .adjust { grid-template-columns: 1fr 1fr; } }
@media (max-width: 820px) { .pay { grid-template-columns: 1fr 1fr; } .aging__row { grid-template-columns: 80px 1fr 90px; } }
