/* Control Mojes — mobile-first, sin dependencias externas (CSP: style-src 'self') */
:root {
  color-scheme: light;
  --bg: #faf6ef; --surface: #ffffff; --surface-2: #f3ece1; --border: #e4d9c8;
  --text: #221a12; --muted: #6d6052; --primary: #8a4209; --primary-2: #a8550f; --on-primary: #ffffff;
  --accent-bg: #fff3e0; --accent-bd: #f0b35b;
  --ok: #067647; --warn: #9a5b00; --danger: #b42318; --serious: #c4320a;
  --series-1: #257de0; --series-2: #f47230;
  --radius: 14px; --shadow: 0 1px 2px rgba(60, 40, 10, .08), 0 2px 8px rgba(60, 40, 10, .05);
  --tap: 46px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #16120e; --surface: #201a14; --surface-2: #2a221a; --border: #3a3026;
    --text: #f3ece3; --muted: #b3a593; --primary: #e08b3c; --primary-2: #f09a4a; --on-primary: #1a1006;
    --accent-bg: #33230f; --accent-bd: #8a5a1d;
    --ok: #3ccf8e; --warn: #f0b35b; --danger: #ff6b5e; --serious: #ff8a5c;
    --series-1: #338ced; --series-2: #e76624;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.45; }
a { color: var(--primary); }
h1 { font-size: 1.45rem; margin: .2rem 0 .8rem; }
h2 { font-size: 1.1rem; margin: 0 0 .7rem; }
h3 { font-size: 1rem; margin: 0; display: inline; }
small, .small { font-size: .85rem; }
.muted { color: var(--muted); }
.neg { color: var(--danger); } .pos { color: var(--ok); } .ok { color: var(--ok); font-weight: 600; }
.center { text-align: center; }
pre, code { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: .8rem; }
pre { white-space: pre-wrap; word-break: break-word; background: var(--surface-2); padding: .6rem; border-radius: 8px; }
.wrap { word-break: break-all; }

/* ---------- barra superior ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .6rem;
  padding: .5rem .8rem; padding-top: max(.5rem, env(safe-area-inset-top));
  background: var(--primary); color: var(--on-primary); }
.brand { display: flex; align-items: center; gap: .45rem; color: inherit; text-decoration: none; font-weight: 700; white-space: nowrap; }
.brand img { background: #fff; border-radius: 8px; }
.topsearch { flex: 1; display: none; }
.topsearch input { width: 100%; border: 0; border-radius: 999px; padding: .55rem 1rem; background: rgba(255,255,255,.95); color: #222; }
.usermenu { margin-left: auto; position: relative; }
.usermenu summary { list-style: none; cursor: pointer; }
.usermenu summary::-webkit-details-marker { display: none; }
.avatar { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; background: rgba(255,255,255,.25); font-weight: 700; }
.dropdown { position: absolute; right: 0; top: 46px; min-width: 220px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px; padding: .8rem; box-shadow: 0 8px 30px rgba(0,0,0,.2); display: grid; gap: .5rem; }

/* ---------- layout ---------- */
.layout { display: block; }
.sidenav { display: none; }
main { padding: 1rem .85rem 6.5rem; max-width: 1200px; margin: 0 auto; }
main.auth { min-height: 100vh; display: grid; place-content: center; padding: 1rem; }

.navlist { list-style: none; margin: 0; padding: 0; }
.navlist a { display: block; padding: .7rem .9rem; border-radius: 10px; text-decoration: none; color: var(--text); min-height: var(--tap); }
.navlist a.on, .navlist a:hover { background: var(--accent-bg); color: var(--primary); font-weight: 600; }
.navhead { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 1rem .9rem .3rem; }

.bottomnav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 30; display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
.bottomnav > a, .bottomnav summary { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; min-height: 60px; font-size: .75rem; color: var(--muted); text-decoration: none; cursor: pointer; list-style: none; }
.bottomnav summary::-webkit-details-marker { display: none; }
.bottomnav .ico { font-size: 1.35rem; line-height: 1; }
.bottomnav a.on { color: var(--primary); font-weight: 700; }
.moremenu { flex: 1; display: flex; }
.moremenu > summary { width: 100%; }
.moremenu[open] .sheet { position: fixed; left: 0; right: 0; bottom: calc(60px + env(safe-area-inset-bottom)); max-height: 72vh; overflow: auto;
  background: var(--surface); border-top: 1px solid var(--border); border-radius: 18px 18px 0 0; padding: .5rem .5rem 1rem;
  box-shadow: 0 -10px 40px rgba(0,0,0,.25); }

@media (min-width: 900px) {
  .topsearch { display: block; max-width: 520px; }
  .layout { display: grid; grid-template-columns: 240px 1fr; }
  .sidenav { display: block; position: sticky; top: 56px; height: calc(100vh - 56px); overflow: auto; padding: .8rem .5rem;
    border-right: 1px solid var(--border); background: var(--surface); }
  main { padding: 1.4rem 1.6rem 3rem; }
  .bottomnav { display: none; }
  h1 { font-size: 1.7rem; }
}

/* ---------- componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.card.narrow { max-width: 640px; }
.authcard { width: min(400px, 92vw); text-align: center; }
.authcard form { text-align: left; }
.grid2 { display: grid; gap: 1rem; }
.grid2.tight { gap: 0 1rem; }
@media (min-width: 760px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.pagehead { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .6rem; }
.pagehead h1 { margin: 0; }
.actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.actions form { margin: 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .3rem; min-height: var(--tap); padding: .55rem 1.1rem;
  border-radius: 12px; border: 1px solid var(--primary); background: var(--primary); color: var(--on-primary);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn:hover { background: var(--primary-2); }
.btn.ghost { background: transparent; color: var(--primary); }
.btn.small { min-height: 38px; padding: .35rem .8rem; font-size: .9rem; }
.btn.block { width: 100%; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger.ghost { background: transparent; color: var(--danger); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.linklike { background: none; border: 0; color: var(--primary); font: inherit; cursor: pointer; padding: .45rem 0; text-align: left; }
.linklike.danger { color: var(--danger); }
.iconbtn { border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); border-radius: 10px; width: 44px; height: 44px; cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent-bd); outline-offset: 2px; }

/* formularios — 16px evita el zoom automático en iOS */
form label { display: block; margin: 0 0 .9rem; font-weight: 600; font-size: .95rem; }
input, select, textarea { display: block; width: 100%; margin-top: .3rem; min-height: var(--tap); padding: .55rem .75rem; font: inherit; font-size: 16px;
  color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
input[type=checkbox], input[type=radio] { display: inline-block; width: 1.25rem; height: 1.25rem; min-height: 0; margin: 0 .4rem 0 0; vertical-align: -3px; accent-color: var(--primary); }
textarea { min-height: 70px; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px var(--accent-bg); }
.hint { display: block; font-weight: 400; color: var(--muted); margin-top: .25rem; }
fieldset { border: 0; padding: 0; margin: 0 0 .9rem; }
legend { font-weight: 600; font-size: .95rem; margin-bottom: .35rem; }
.radios { display: flex; flex-wrap: wrap; gap: .5rem; }
.radios legend { width: 100%; }
.radios label { margin: 0; font-weight: 500; padding: .55rem .8rem; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); cursor: pointer; min-height: var(--tap); display: flex; align-items: center; }
.radios.big label { flex: 1 1 140px; flex-direction: column; align-items: flex-start; }
.radios label:has(input:checked) { border-color: var(--primary); background: var(--accent-bg); }
.check { display: inline-flex !important; align-items: center; font-weight: 500 !important; margin: 0 !important; }
label.inline { display: grid; grid-template-columns: 1fr 160px; align-items: center; gap: .6rem; }
.withunit { display: flex; align-items: center; gap: .4rem; }
.withunit input { margin: 0; }
.otp { font-size: 1.6rem !important; letter-spacing: .4em; text-align: center; }
.secret { font-family: ui-monospace, monospace; font-size: 1.2rem; letter-spacing: .08em; background: var(--surface-2); padding: .7rem; border-radius: 10px; word-break: break-all; user-select: all; }
.steps li { margin-bottom: .6rem; }

.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; margin-bottom: .8rem; }
.filters input[type=search] { flex: 1 1 220px; margin: 0; }
.filters select { width: auto; flex: 0 1 180px; margin: 0; }
.filters label { margin: 0; font-weight: 500; }
.filters label input { width: auto; }

.tabs { display: flex; gap: .3rem; overflow-x: auto; margin-bottom: .8rem; }
.tabs a { padding: .5rem .9rem; border-radius: 999px; text-decoration: none; border: 1px solid var(--border); color: var(--text); white-space: nowrap; }
.tabs a.on { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }

/* mensajes */
.flashes { display: grid; gap: .5rem; margin-bottom: 1rem; }
.flash { padding: .75rem 1rem; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); }
.flash.success { border-color: var(--ok); color: var(--ok); }
.flash.error { border-color: var(--danger); color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, var(--surface)); }
.flash.warning { border-color: var(--accent-bd); background: var(--accent-bg); }
.flash.info { border-color: var(--series-1); }

/* indicadores */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; margin-bottom: 1rem; }
@media (min-width: 760px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } .tiles.small { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.tile { display: flex; flex-direction: column; gap: .15rem; padding: .85rem; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--border); color: var(--text); text-decoration: none; box-shadow: var(--shadow); min-width: 0; }
a.tile:hover { border-color: var(--primary); }
.tile .label { font-size: .8rem; color: var(--muted); }
.tile .value { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile .value.small { font-size: 1rem; }
.tile .value small { font-size: .8rem; font-weight: 500; color: var(--muted); }
.tile .sub { font-size: .78rem; color: var(--muted); }
.tile.accent { background: var(--accent-bg); border-color: var(--accent-bd); }

.summary { margin: .2rem 0 .8rem; }
.stockline { background: var(--surface-2); padding: .55rem .8rem; border-radius: 10px; }
.bigtotal { font-size: 1.3rem; margin: .4rem 0 1rem; }
.bigtotal strong { font-variant-numeric: tabular-nums; }
.totals { display: grid; gap: .5rem; margin: 1rem 0; }

.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: .12rem .5rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); vertical-align: middle; }
.badge.warn { background: var(--accent-bg); color: var(--warn); }
.st-anulada { background: color-mix(in srgb, var(--danger) 15%, var(--surface)); color: var(--danger); }
.st-abierta { background: var(--accent-bg); color: var(--warn); }
.st-cerrada, .st-activa { background: color-mix(in srgb, var(--ok) 15%, var(--surface)); color: var(--ok); }

/* listas táctiles */
.rowlist { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.card .rowlist { border: 0; border-radius: 0; }
.rowlist li { border-top: 1px solid var(--border); }
.rowlist li:first-child { border-top: 0; }
.rowlist li.muted { padding: .9rem; }
.rowlist a { display: flex; justify-content: space-between; align-items: center; gap: .8rem; padding: .8rem .9rem; color: var(--text); text-decoration: none; min-height: 56px; }
.rowlist a:hover { background: var(--surface-2); }
.rowlist strong { white-space: nowrap; font-variant-numeric: tabular-nums; }
.voided { opacity: .6; }
.voided a span:first-child { text-decoration: line-through; }

/* tablas → tarjetas en móvil */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .55rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: .8rem; color: var(--muted); font-weight: 600; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.low td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
tr.inactive { opacity: .55; }
@media (max-width: 759px) {
  table.cards thead { display: none; }
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards tr { border: 1px solid var(--border); border-radius: 12px; margin-bottom: .6rem; padding: .4rem .2rem; background: var(--surface); }
  table.cards td { border: 0; display: flex; justify-content: space-between; gap: 1rem; padding: .3rem .7rem; text-align: right; }
  table.cards td::before { content: attr(data-l); color: var(--muted); font-size: .82rem; text-align: left; }
  table.cards td[colspan] { display: block; text-align: left; }
  table.cards td[colspan]::before { content: none; }
}
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; margin: 0 0 1rem; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

/* líneas de compra */
.lines { display: grid; gap: .6rem; margin-bottom: .6rem; }
.line { display: grid; grid-template-columns: 1fr 1fr 44px; gap: 0 .6rem; padding: .7rem; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.line label:first-child { grid-column: 1 / -1; }
.line label { margin-bottom: .4rem; }
.line .iconbtn { align-self: center; grid-row: 2; grid-column: 3; }
@media (min-width: 760px) { .line { grid-template-columns: 2fr 1fr 1fr 44px; } .line label:first-child { grid-column: auto; } .line .iconbtn { grid-row: auto; grid-column: auto; } }

/* timeline */
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { border-left: 3px solid var(--border); padding: .4rem 0 .8rem .8rem; margin-left: .3rem; }
.timeline time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .85rem; }
.audit .act-login_fallido, .audit .act-acceso_denegado, .audit .act-mfa_fallido { border-left-color: var(--danger); }
.audit .act-anular { border-left-color: var(--warn); }
details > summary { cursor: pointer; }
.history > summary { list-style: none; }
.raw summary { color: var(--muted); }
.voidbox { display: inline-block; }
.voidbox[open] form { margin-top: .5rem; padding: .8rem; border: 1px solid var(--danger); border-radius: 12px; background: var(--surface); min-width: min(320px, 85vw); }
.voidbox > summary, .inlinemenu > summary { list-style: none; }
.voidbox > summary::-webkit-details-marker, .inlinemenu > summary::-webkit-details-marker { display: none; }
.inlinemenu { display: inline-block; position: relative; }
.inlinemenu[open] form { position: absolute; right: 0; z-index: 5; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: .4rem .9rem; display: grid; min-width: 220px; box-shadow: 0 8px 30px rgba(0,0,0,.18); }

.alerts { list-style: none; padding: 0; margin: 0; display: grid; gap: .4rem; }
.alert { display: flex; gap: .6rem; align-items: flex-start; padding: .6rem .7rem; border-radius: 10px; border: 1px solid var(--border); }
.alert.warning { border-color: var(--accent-bd); background: var(--accent-bg); }
.alert.serious { border-color: var(--serious); }
.alert a { color: var(--text); }

.pager { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .8rem 0; font-size: .9rem; color: var(--muted); }

/* gráfico */
.chart { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--border); stroke-width: 1; }
.chart .bar.s1 { fill: var(--series-1); }
.chart .bar.s2 { fill: var(--series-2); }
.chart .bar:hover { opacity: .8; }
.chart .tick { fill: var(--muted); font-size: 15px; }
.legend { display: flex; gap: 1rem; font-size: .85rem; color: var(--muted); margin-bottom: .3rem; }
.legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: .3rem; vertical-align: -1px; }
.sw.s1 { background: var(--series-1); } .sw.s2 { background: var(--series-2); }

@media print { .topbar, .sidenav, .bottomnav, .actions, .filters { display: none !important; } main { padding: 0; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

fieldset.card.inset { background: var(--surface-2); box-shadow: none; padding: .8rem 1rem .2rem; }
fieldset.card.inset legend { padding: 0 .3rem; }
.costline { grid-template-columns: 1fr 1fr 44px; }
@media (min-width: 760px) { .costline { grid-template-columns: 1.2fr 2fr 1fr 44px; } }
.profit { font-size: 1.1rem; }

.pay-pagada { background: color-mix(in srgb, var(--ok) 15%, var(--surface)); color: var(--ok); }
.pay-parcial { background: var(--accent-bg); color: var(--warn); }
.pay-pendiente { background: var(--surface-2); color: var(--muted); }
.pay-vencida { background: color-mix(in srgb, var(--danger) 15%, var(--surface)); color: var(--danger); }
.pay-anulada { background: var(--surface-2); color: var(--muted); }
.payform[open] form { margin-top: .7rem; }
.payform > summary { list-style: none; }
.payform > summary::-webkit-details-marker { display: none; }
.chart .threshold { stroke: var(--danger); stroke-width: 1.5; stroke-dasharray: 6 4; }
.wastebox { font-size: 1.1rem; background: var(--surface-2); padding: .7rem .9rem; border-radius: 12px; }
.lotbox { background: var(--accent-bg); border: 1px solid var(--accent-bd); padding: .7rem .9rem; border-radius: 12px; }
.lotbox strong { font-variant-numeric: tabular-nums; }
