/* =====================================================================
   Lo general: la estructura (menú y contenido), botones, casillas, tablas,
   listas, ventanas y avisos. Lo de cada pantalla está en pantallas.css.
   ===================================================================== */

*, *::before, *::after { box-sizing: inherit; }
html { height: 100%; scroll-padding-top: env(safe-area-inset-top, 0px); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100%;
  background: var(--paper); color: var(--ink);
  font-family: var(--ui); font-size: 16px; line-height: 1.45;
}
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
svg { width: 20px; height: 20px; flex: none; }
a { color: var(--brand); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- estructura ---------- */
.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
.rail {
  position: sticky; top: 0; align-self: start; height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
  background: var(--panel); border-right: 1px solid var(--line);
  padding: 18px 12px 14px; overflow-y: auto;
}
.brand { padding: 4px 10px 16px; }
.brand-name { font-family: var(--num); font-weight: 700; font-size: 29px; line-height: 1; letter-spacing: .2px; }
.brand-sub { color: var(--ink-3); font-size: 14px; margin-top: 4px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-sep { height: 1px; background: var(--line-2); margin: 8px 10px; }
.nav-btn {
  display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 44px; padding: 8px 12px; border: 0; border-radius: 8px;
  background: transparent; color: var(--ink-2); cursor: pointer; text-align: left; font-size: 16px;
}
.nav-btn svg { width: 21px; height: 21px; flex: none; }
.nav-btn:hover { background: var(--panel-2); color: var(--ink); }
.nav-btn[aria-current="page"] { background: var(--brand-soft); color: var(--brand); font-weight: 700; box-shadow: inset 3px 0 0 var(--brand); }
.rail-foot { margin-top: auto; padding: 12px 10px 0; display: flex; flex-direction: column; gap: 10px; font-size: 14px; color: var(--ink-3); }
.status { display: flex; align-items: center; gap: 8px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink-3); flex: none; }
.dot.on { background: var(--ok); }
.dot.off { background: var(--bad); }
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; color: var(--ink-2); }
.switch input { width: 18px; height: 18px; accent-color: var(--brand); }

.main { min-width: 0; padding: 26px 32px 60px; }
.view { max-width: 1280px; margin: 0 auto; }
.topbar, .tabbar { display: none; }

.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin-bottom: 18px; }
.page-title { font-family: var(--num); font-weight: 600; font-size: 36px; line-height: 1.05; margin: 0; letter-spacing: .2px; }
.page-head .grow { flex: 1; }
.lede { color: var(--ink-2); margin: -8px 0 18px; max-width: 70ch; }

/* ---------- controles ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  font-weight: 700; font-size: 16px; cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--panel-2); }
.btn svg { width: 19px; height: 19px; flex: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { background: var(--brand); filter: brightness(1.08); }
.btn-tag { background: var(--tag); border-color: var(--tag-edge); color: var(--tag-ink); }
.btn-tag:hover { background: var(--tag); filter: brightness(1.04); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--panel-2); color: var(--ink); }
.btn-danger { color: var(--bad); }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 15px; }
.btn-xs { min-height: 30px; padding: 0 10px; font-size: 14px; border-radius: 6px; }
.btn-icon { width: 40px; padding: 0; min-height: 40px; }
.btn-block { width: 100%; }
.btn:disabled, .btn.is-disabled { opacity: .45; cursor: not-allowed; filter: none; }
.ro .needs-write { display: none !important; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span, .field > label { font-size: 14px; font-weight: 700; color: var(--ink-2); }
.field small { color: var(--ink-3); font-size: 13px; }
.input, .select, .textarea {
  width: 100%; min-height: 44px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--ink); font-size: 16px;
}
.textarea { padding: 10px 12px; min-height: 76px; resize: vertical; line-height: 1.4; }
.select { padding-right: 8px; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 28%, transparent); }
.input.num { text-align: right; font-variant-numeric: tabular-nums; }
.input.is-missing { border-color: var(--warn); background: var(--warn-soft); }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.span2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); padding: 3px; gap: 3px; flex-wrap: wrap; }
.seg button { display: inline-flex; align-items: center; gap: 6px; border: 0; background: transparent; min-height: 38px; padding: 0 14px; border-radius: 7px; cursor: pointer; font-weight: 700; color: var(--ink-2); }
.seg button svg { width: 18px; height: 18px; }
.seg-grid { display: grid; }
.seg-grid.seg-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.seg-grid.seg-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.seg-grid button { justify-content: center; }
.seg button[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.panel-pad { padding: 18px 20px; }
.panel-head { display: flex; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--line-2); }
.panel-head h2, .h2 { font-size: 19px; margin: 0; }
.panel-head .grow { flex: 1; }
.muted { color: var(--ink-3); }
.small { font-size: 14px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.numtxt { font-variant-numeric: tabular-nums; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.hr { height: 1px; background: var(--line-2); margin: 14px 0; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 28px; padding: 2px 11px; border-radius: 999px;
  background: var(--panel-2); color: var(--ink-2); border: 1px solid var(--line-2);
  font-size: 14px; font-weight: 700; white-space: nowrap;
}
.chip b { color: var(--ink); }
.chip-ok b, .chip-warn b, .chip-bad b, .chip-brand b, .chip-unk b { color: inherit; }
.chip-unk { background: transparent; border: 1px dashed var(--line); color: var(--ink-3); }
.stock.unk { color: var(--ink-3); font-weight: 400; }
.loc-box { display: flex; flex-direction: column; gap: 6px; color: var(--ink-3); }
.loc-box:empty { display: none; }
.loc-btn { justify-content: space-between; width: 100%; color: var(--ink); }
.loc-chip { cursor: pointer; font: inherit; font-size: 14px; font-weight: 700; }
.loc-option { min-height: 56px; font-size: 18px; }
.banner .grow { flex: 1; }
.chip-ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip-bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.chip-brand { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.stock { font-weight: 700; font-variant-numeric: tabular-nums; }
.stock.ok { color: var(--ok); }
.stock.warn { color: var(--warn); }
.stock.bad { color: var(--bad); }
.stock.zero { color: var(--ink-3); }

/* ---------- tablas ---------- */
.tbl-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 15.5px; }
.tbl th {
  text-align: left; font-size: 14px; color: var(--ink-2); font-weight: 700;
  padding: 10px 12px; border-bottom: 2px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 1; white-space: nowrap;
}
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl .c { text-align: center; }
.tbl tbody tr.click { cursor: pointer; }
.tbl tbody tr.click:hover td { background: var(--panel-2); }
.tbl tbody tr.sel td { background: var(--brand-soft); }
.tbl tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: 0; }
.tbl .desc { min-width: 220px; }
.tbl .code { color: var(--ink-3); font-size: 14px; }
.tbl tr.anul td { color: var(--ink-3); text-decoration: line-through; }
.tbl tr.anul td.keep { text-decoration: none; }

.empty { padding: 36px 20px; text-align: center; color: var(--ink-3); }
.empty strong { display: block; color: var(--ink-2); font-size: 18px; margin-bottom: 4px; }

/* ---------- resúmenes ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0; margin-bottom: 18px; }
.kpi { padding: 14px 20px; border-right: 1px solid var(--line-2); }
.kpi:last-child { border-right: 0; }
.kpi span { display: block; color: var(--ink-2); font-size: 14px; font-weight: 700; }
.kpi b { display: block; font-family: var(--num); font-weight: 700; font-size: clamp(26px, 2.3vw, 34px); line-height: 1.1; font-variant-numeric: tabular-nums; white-space: nowrap; }
.kpi small { display: block; color: var(--ink-3); font-size: 13px; line-height: 1.3; margin-top: 2px; }
.kpi b.neg { color: var(--bad); }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar .input, .toolbar .select { width: auto; }
.toolbar .search { flex: 1 1 280px; min-width: 220px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--line-2); flex-wrap: wrap; }

.list { display: flex; flex-direction: column; }
.li { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line-2); }
.li:last-child { border-bottom: 0; }
.li .grow { flex: 1; min-width: 0; }
.li .t { font-weight: 700; }
.li .s { color: var(--ink-3); font-size: 14px; }
.li.done .t { text-decoration: line-through; color: var(--ink-3); }
.check { width: 22px; height: 22px; accent-color: var(--ok); flex: none; cursor: pointer; }

.cols2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.cols-form { display: grid; grid-template-columns: 400px minmax(0, 1fr); gap: 18px; align-items: start; }

.picked { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); }
.picked .grow { flex: 1; min-width: 0; }
.picked .t { font-weight: 700; }

.month-nav { display: inline-flex; align-items: center; gap: 6px; }
.month-nav b { min-width: 150px; text-align: center; font-size: 17px; }

.banner svg { width: 20px; height: 20px; }
.banner { display: flex; gap: 12px; align-items: center; padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-weight: 700; }
.banner-warn { background: var(--warn-soft); color: var(--warn); }
.banner-bad { background: var(--bad-soft); color: var(--bad); }
.banner-info { background: var(--brand-soft); color: var(--brand); }

/* ---------- modal y avisos ---------- */
.overlay { position: fixed; inset: 0; z-index: 100; background: var(--overlay); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 16px; overflow-y: auto; }
.dialog { width: 100%; max-width: 880px; background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.dialog.narrow { max-width: 480px; }
.dialog.mid { max-width: 640px; }
.dialog-head { display: flex; align-items: flex-start; gap: 12px; padding: 18px 22px 12px; }
.dialog-head h2 { margin: 0; font-size: 22px; line-height: 1.25; flex: 1; }
.dialog-body { padding: 4px 22px 18px; }
.dialog-foot { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; padding: 14px 22px; border-top: 1px solid var(--line-2); }
.dialog-foot .grow { flex: 1; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 0 22px; }
.tabs button { border: 0; background: transparent; padding: 10px 14px; font-weight: 700; color: var(--ink-3); cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs button[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); }

.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--ink); color: var(--panel); padding: 12px 18px; border-radius: 10px; font-weight: 700; box-shadow: var(--shadow); animation: toast .2s ease-out; }
.toast.err { background: var(--bad); color: #fff; }
@keyframes toast { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.skeleton { padding: 60px 20px; text-align: center; color: var(--ink-3); }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--brand); animation: spin 1s linear infinite; margin: 0 auto 14px; }
@keyframes spin { to { transform: rotate(360deg); } }

html.big .app, html.big .overlay { zoom: 1.12; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- entrada, cuenta y permisos ---------- */
[hidden] { display: none !important; }
#gate { display: none; }
html.gated #gate { display: flex; position: fixed; inset: 0; z-index: 90; background: var(--paper); align-items: flex-start; justify-content: center; padding: max(6vh, 24px) 16px 32px; overflow-y: auto; }
html.gated .app { visibility: hidden; }
.gate-card { width: 100%; max-width: 460px; padding: 26px 24px 22px; display: flex; flex-direction: column; gap: 12px; }
.gate-card p { margin: 0; }
.gate-brand { margin-bottom: 4px; }
.gate-title { font-size: 24px; line-height: 1.25; margin: 4px 0 0; }
.gate-err, .gate-ok { border-radius: 8px; padding: 10px 12px; font-weight: 700; font-size: 15px; }
.gate-err { background: var(--bad-soft); color: var(--bad); }
.gate-ok { background: var(--ok-soft); color: var(--ok); }
.user-box:empty { display: none; }
.user-line { display: flex; align-items: center; gap: 10px; color: var(--ink-2); }
.user-line .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.user-line b { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-line .grow span { font-size: 13px; }
.dot.half { background: var(--warn); }
html:not(.owner) .needs-owner { display: none !important; }
.progress { height: 12px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); overflow: hidden; }
.progress > div { height: 100%; width: 0; background: var(--brand); transition: width .2s; }
.input:disabled, .select:disabled { background: var(--panel-2); color: var(--ink-2); }
