:root {
  --navy: #0F1C30;
  --navy-2: #304A6E;
  --light: #F3F5F9;
  --tint: #E3EAF6;
  --accent: #668DC0;
  --accent-ink: #304A6E;
  --accent-2: #C0D0EF;
  --accent-2-ink: #1F6B57;
  --ink: #0F1C30;
  --muted: #4F5B6E;
  --line: #D5DAE3;
  --card: #FFFFFF;
  --red: #C0392B;
  --red-bg: #FDECEA;
  --green-bg: #E2F1EB;
  --radius: 14px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--light); font-size: 15px; }
a { color: var(--accent-ink); }
h1, h2, h3 { margin: 0 0 12px; line-height: 1.2; }
h1 { font-size: 26px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }

/* Estructura */
.shell { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
.side { background: var(--navy); color: var(--light); padding: 20px 14px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; overflow: auto; }
.brand { font-weight: 800; font-size: 20px; padding: 4px 10px 18px; }
.brand span { color: var(--accent); }
.side a { color: #C2C6CE; text-decoration: none; padding: 9px 12px; border-radius: 10px; display: flex; gap: 10px; align-items: center; }
.side a:hover { background: var(--navy-2); }
.side a.active { background: var(--accent); color: var(--navy); font-weight: 700; }
.side .spacer { flex: 1; }
.side .portal-link { margin: 8px 4px 2px; padding: 10px; background: var(--navy-2); border-radius: 10px; color: var(--light); }
.side .portal-link .link-text { font-size: 13px; font-weight: 700; word-break: break-all; margin: 4px 0 8px; user-select: all; }
.side .portal-link button { width: 100%; justify-content: center; padding: 6px 10px; font-size: 13px; background: var(--accent); border-color: var(--accent); color: var(--navy); font-weight: 700; }
.side .who { font-size: 13px; color: #8C96A8; padding: 8px 12px; }
.main { padding: 26px 30px 60px; max-width: 1280px; width: 100%; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.topbar > * { min-width: 0; flex-shrink: 1; }
.menu-btn { display: none; }

/* Componentes */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat b { display: block; font-size: 28px; }
.stat span { color: var(--muted); font-size: 13px; }
.stat.warn b { color: var(--red); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.right { text-align: right; }
.hidden { display: none !important; }

button, .btn { font: inherit; border: 1px solid var(--navy); background: var(--card); color: var(--navy); padding: 8px 14px; border-radius: 10px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { background: var(--tint); }
button.primary, .btn.primary { background: var(--navy); color: var(--light); }
button.primary:hover, .btn.primary:hover { background: var(--navy-2); }
button.accent { background: var(--accent); border-color: var(--accent); color: var(--navy); font-weight: 700; }
button.danger { border-color: var(--red); color: var(--red); }
button.danger:hover { background: var(--red-bg); }
button.link { border: none; background: none; padding: 0; color: var(--accent-ink); text-decoration: underline; }
button:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid #C2C6CE; border-radius: 10px; background: #fff; color: var(--ink); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: var(--accent); }
input[type=checkbox], input[type=radio] { width: auto; }
label { display: block; font-size: 13px; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 4px; }
.form { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.form .full { grid-column: 1 / -1; }
.check { display: flex; gap: 8px; align-items: center; color: var(--ink); font-size: 14px; }

.scan { font-size: 24px; padding: 14px 16px; font-family: Consolas, monospace; letter-spacing: 1px; border-width: 2px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; }
tr.late td { background: var(--red-bg); }
tr.res-group td { background: var(--tint); border-top: 2px solid var(--accent); }
.table-wrap { overflow-x: auto; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--tint); color: var(--accent-ink); white-space: nowrap; }
.badge.ok { background: var(--green-bg); color: var(--accent-2-ink); }
.badge.bad { background: var(--red-bg); color: var(--red); }
.badge.dark { background: var(--navy); color: var(--light); }
.code { font-family: Consolas, monospace; }

.big-balance { font-size: 44px; font-weight: 800; line-height: 1; }
.notice { padding: 12px 14px; border-radius: 10px; background: var(--tint); margin-bottom: 14px; }
.notice.bad { background: var(--red-bg); color: var(--red); }
.notice.ok { background: var(--green-bg); color: var(--accent-2-ink); }

.picker { position: relative; }
.picker .results { position: absolute; z-index: 20; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(15,28,48,.15); max-height: 300px; overflow: auto; }
.picker .results button { display: block; width: 100%; text-align: left; border: none; border-radius: 0; border-bottom: 1px solid var(--line); padding: 9px 12px; }
.portal-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; cursor: pointer; }
.portal-toggle.on { background: var(--green-bg); border-color: var(--accent-2); }
.portal-toggle.locked { color: var(--muted); cursor: default; }
.portal-toggle input { margin: 0; }
.side a .pdot { margin-left: auto; font-size: 12px; }
.no-cover { display: flex; align-items: center; justify-content: center; text-align: center; background: var(--tint); color: var(--muted); border: 1px dashed var(--line); border-radius: 6px; font-size: 10px; line-height: 1.2; padding: 4px; }
.chip { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--tint); border-radius: 10px; padding: 10px 12px; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs a { padding: 7px 14px; border-radius: 999px; text-decoration: none; color: var(--navy); border: 1px solid var(--line); background: #fff; }
.tabs a.active { background: var(--navy); color: var(--light); border-color: var(--navy); }

.result-card { border-radius: var(--radius); padding: 16px; margin-top: 14px; border: 2px solid var(--line); }
.result-card.out { border-color: var(--accent); background: #EEF3FB; }
.result-card.in { border-color: var(--accent-2); background: var(--green-bg); }

#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--navy); color: var(--light); padding: 12px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 380px; }
.toast.error { background: var(--red); }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; }

/* Recibo */
.receipt { max-width: 380px; margin: 0 auto; background: #fff; padding: 22px; border: 1px dashed #bbb; font-size: 14px; }
.receipt h2 { text-align: center; margin-bottom: 2px; }
.receipt .center { text-align: center; }
.receipt hr { border: none; border-top: 1px dashed #999; margin: 12px 0; }
.receipt table td, .receipt table th { padding: 4px 2px; border: none; }

/* Etiquetas */
.labels { display: grid; gap: 0; background: #fff; }
.labels.a4-3x8 { grid-template-columns: repeat(3, 70mm); grid-auto-rows: 37mm; width: 210mm; }
.labels.a4-2x7 { grid-template-columns: repeat(2, 99mm); grid-auto-rows: 38mm; width: 210mm; }
.labels.roll { grid-template-columns: 50mm; grid-auto-rows: 25mm; }
.label { border: 1px dashed #ccc; padding: 2mm 3mm; overflow: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.label .num { font-size: 16px; font-weight: 800; line-height: 1.1; }
.labels.roll .label .num { font-size: 12px; }
.label .t { font-size: 10px; font-weight: 700; line-height: 1.15; max-height: 2.4em; overflow: hidden; }
.label .n { font-size: 9px; color: #444; }
.label svg { max-width: 100%; height: auto; }
.labels.roll .label .t { font-size: 8px; }

@media print {
  .no-print, .side, .topbar, #toasts { display: none !important; }
  body { background: #fff; }
  .shell { display: block; }
  .main { padding: 0; max-width: none; }
  .card { border: none; padding: 0; }
  .receipt { border: none; }
  .label { border-color: transparent; }
  @page { margin: 8mm; }
}

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 30% 0 0; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .main { padding: 16px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
}
