/* =========================================================
   IMIMSA · Sistema Integral de Gestión (demo)
   Hoja de estilos principal
   Paleta tomada del logotipo corporativo:
   navy #181F78 · royal #1B4E9B · cobalt #2087C7 · cyan #23A0D6 · aqua #63C5D8
   ========================================================= */

:root {
  --ink: #0f1b2d;
  --ink-2: #26374f;
  --muted: #667a92;
  --line: #dde5ee;
  --line-soft: #eef3f8;
  --bg: #f4f7fa;
  --surface: #ffffff;

  --brand: #1b4e9b;
  --brand-600: #16357a;
  --brand-100: #e8f0fa;
  --accent: #2087c7;
  --accent-100: #e4f3fb;
  --navy: #181f78;
  --cyan: #23a0d6;
  --aqua: #63c5d8;

  --ok: #1b7f5a;
  --ok-100: #e2f4ec;
  --warn: #a9700a;
  --warn-100: #fdf1db;
  --danger: #ac3b32;
  --danger-100: #fbe9e7;
  --info: #1f5f96;
  --info-100: #e6eff8;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(15, 27, 45, .06), 0 8px 24px -16px rgba(15, 27, 45, .28);
  --shadow-lg: 0 24px 60px -24px rgba(15, 27, 45, .35);
  --sidebar-w: 250px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.012em; line-height: 1.25; }
p { margin: 0 0 .8em; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: linear-gradient(180deg, #101750 0%, #181f78 55%, #0c1240 100%);
  color: #c3cfe4;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 60;
}

.brand {
  padding: 14px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-logo {
  width: 100%;
  background: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
  overflow: hidden;
}
.brand-logo img { width: 100%; height: auto; max-height: 64px; object-fit: contain; display: block; }
.brand-tag {
  font-size: 9px; color: #8fa0c6; text-transform: uppercase;
  letter-spacing: .1em; text-align: center; margin-top: 8px; font-weight: 600;
}
.brand-name { font-size: 15px; font-weight: 700; color: #fff; letter-spacing: -.01em; line-height: 1.15; }
.brand-sub { font-size: 9.5px; color: #8fa0c6; text-transform: uppercase; letter-spacing: .09em; margin-top: 2px; }

.nav { padding: 14px 12px; overflow-y: auto; flex: 1; }
.nav-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: .12em;
  color: #7a89b4; padding: 14px 10px 7px; font-weight: 600;
}
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: 8px;
  color: #b4c1d8; font-size: 13.5px; font-weight: 500;
  margin-bottom: 2px; text-decoration: none;
  transition: background .14s, color .14s;
  position: relative;
}
.nav a:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.nav a.active { background: rgba(35,160,214,.26); color: #fff; font-weight: 600; }
.nav a.active::before {
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px;
  width: 3px; border-radius: 0 3px 3px 0; background: #2bb0e2;
}
.nav a .ico { width: 17px; text-align: center; opacity: .9; font-size: 14px; }
.nav a .tag {
  margin-left: auto; font-size: 9.5px; font-weight: 700;
  padding: 1px 6px; border-radius: 20px;
  background: rgba(35,160,214,.22); color: #8cd9f0; letter-spacing: .04em;
}
.sidebar-foot {
  padding: 13px 16px; border-top: 1px solid rgba(255,255,255,.08);
  font-size: 11px; color: #8090b6; line-height: 1.5;
}
.sidebar-foot strong { color: #cfe0e6; font-weight: 600; }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 60px;
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 14px;
  padding: 0 22px;
  position: sticky; top: 0; z-index: 40;
}
.topbar h1 { font-size: 16px; font-weight: 650; }
.topbar .crumb { font-size: 12px; color: var(--muted); }
.menu-btn {
  display: none; background: none; border: 1px solid var(--line);
  border-radius: 8px; width: 34px; height: 34px; cursor: pointer;
  font-size: 16px; color: var(--ink-2); line-height: 1;
}
.topbar-spacer { flex: 1; }
.period-chip {
  display: none; align-items: center; gap: 7px;
  border: 1px solid var(--line); border-radius: 20px;
  padding: 5px 13px; font-size: 12px; color: var(--ink-2); background: #fff;
}
.period-chip b { color: var(--brand); font-weight: 650; }
.user-chip {
  display: flex; align-items: center; gap: 9px;
  padding-left: 14px; border-left: 1px solid var(--line);
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--brand-100); color: var(--brand-600);
  display: grid; place-items: center; font-weight: 700; font-size: 12px;
  border: 1px solid #cbdcf2;
}
.user-meta { line-height: 1.25; }
.user-meta b { display: block; font-size: 12.5px; font-weight: 600; }
.user-meta span { font-size: 10.5px; color: var(--muted); }

.content { padding: 22px; max-width: 1420px; width: 100%; }

/* ---------- Page head ---------- */
.page-head { margin-bottom: 18px; display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.page-head h2 { font-size: 21px; }
.page-head p { color: var(--muted); font-size: 13px; margin: 3px 0 0; max-width: 74ch; }
.page-head .spacer { flex: 1; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Cards / grid ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-head {
  padding: 14px 17px;
  border-bottom: 1px solid var(--line-soft);
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.card-head h3 { font-size: 13.5px; font-weight: 650; }
.card-head .sub { font-size: 11.5px; color: var(--muted); }
.card-head .spacer { flex: 1; }
.card-body { padding: 17px; }
.card-body.tight { padding: 12px 14px; }
.card-body.flush { padding: 0; }

.grid { display: grid; gap: 15px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid-5 { grid-template-columns: repeat(5, minmax(0,1fr)); }
.grid-side { grid-template-columns: minmax(0, 1.62fr) minmax(0, 1fr); align-items: start; }
.grid-side-l { grid-template-columns: minmax(0, 1fr) minmax(0, 1.62fr); align-items: start; }
.stack > * + * { margin-top: 15px; }

/* ---------- KPI ---------- */
.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 15px 16px;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.kpi::after {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 3px;
  background: var(--brand); opacity: .8;
}
.kpi.k-ok::after { background: var(--ok); }
.kpi.k-warn::after { background: var(--warn); }
.kpi.k-danger::after { background: var(--danger); }
.kpi.k-info::after { background: var(--info); }
.kpi-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em;
  color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 6px;
}
.kpi-value {
  font-size: 24px; font-weight: 700; letter-spacing: -.03em;
  margin-top: 7px; font-variant-numeric: tabular-nums; line-height: 1.1;
}
.kpi-value small { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.kpi-foot { font-size: 11.5px; color: var(--muted); margin-top: 7px; display: flex; align-items: center; gap: 6px; }
.delta { font-weight: 650; font-size: 11.5px; }
.delta.up { color: var(--ok); }
.delta.down { color: var(--danger); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl thead th {
  text-align: left; padding: 9px 14px;
  background: #f8fafc; border-bottom: 1px solid var(--line);
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); font-weight: 650; white-space: nowrap;
}
table.tbl tbody td { padding: 10px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.tbl tbody tr:last-child td { border-bottom: 0; }
table.tbl tbody tr:hover { background: #fbfdfe; }
table.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.tbl .mono { font-variant-numeric: tabular-nums; }
table.tbl tfoot td {
  padding: 10px 14px; font-weight: 700;
  background: #f8fafc; border-top: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.t-main { font-weight: 600; }
.t-sub { font-size: 11.5px; color: var(--muted); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 10.5px; font-weight: 650; padding: 2.5px 8px;
  border-radius: 20px; letter-spacing: .02em; white-space: nowrap;
  border: 1px solid transparent;
}
.badge-ok { background: var(--ok-100); color: var(--ok); border-color: #c6e7d9; }
.badge-warn { background: var(--warn-100); color: var(--warn); border-color: #f2dfb8; }
.badge-danger { background: var(--danger-100); color: var(--danger); border-color: #f5cfca; }
.badge-info { background: var(--info-100); color: var(--info); border-color: #cfe1f2; }
.badge-neutral { background: #eef2f6; color: var(--ink-2); border-color: #e0e7ee; }
.badge-brand { background: var(--brand-100); color: var(--brand-600); border-color: #cbdff5; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font-family: inherit; font-size: 13px; font-weight: 600;
  padding: 8px 15px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: #fff; color: var(--ink-2);
  transition: background .13s, border-color .13s, transform .06s;
  white-space: nowrap;
}
.btn:hover { background: #f7fafc; border-color: #cbd8e4; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); border-color: var(--brand-600); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--brand); }
.btn-ghost:hover { background: var(--brand-100); }
.btn-sm { font-size: 12px; padding: 5px 11px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label {
  font-size: 11px; font-weight: 650; color: var(--ink-2);
  text-transform: uppercase; letter-spacing: .05em;
}
.field input, .field select, .field textarea {
  font-family: inherit; font-size: 13.5px; color: var(--ink);
  padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; width: 100%; transition: border-color .13s, box-shadow .13s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(27,78,155,.13);
}
.field .hint { font-size: 11px; color: var(--muted); }
.form-grid { display: grid; gap: 13px; }
.form-grid.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.form-grid.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.form-grid.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-all { grid-column: 1 / -1; }

.search {
  position: relative; display: flex; align-items: center;
}
.search input { padding-left: 32px; }
.search .mag { position: absolute; left: 11px; color: var(--muted); font-size: 12px; pointer-events: none; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; gap: 3px; border-bottom: 1px solid var(--line);
  margin-bottom: 16px; overflow-x: auto;
}
.tabs button {
  font-family: inherit; font-size: 13px; font-weight: 600;
  background: none; border: 0; border-bottom: 2px solid transparent;
  color: var(--muted); padding: 9px 13px; cursor: pointer; white-space: nowrap;
}
.tabs button:hover { color: var(--ink); }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ---------- Charts ---------- */
.chart-box { position: relative; height: 260px; }
.chart-box.sm { height: 200px; }
.chart-box.lg { height: 300px; }

/* ---------- Module cards (home) ---------- */
.mod-card {
  display: block; background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius); padding: 17px; text-decoration: none;
  color: inherit; box-shadow: var(--shadow);
  transition: transform .15s, box-shadow .15s, border-color .15s;
  position: relative; overflow: hidden;
}
.mod-card:hover {
  transform: translateY(-2px); border-color: #b6cbe8;
  box-shadow: 0 3px 6px rgba(15,27,45,.06), 0 18px 40px -22px rgba(15,27,45,.4);
  text-decoration: none;
}
.mod-ico {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  font-size: 17px; margin-bottom: 11px; background: var(--brand-100); color: var(--brand-600);
}
.mod-card h4 { font-size: 14px; margin-bottom: 3px; }
.mod-card p { font-size: 12px; color: var(--muted); margin: 0 0 11px; line-height: 1.5; }
.mod-stat { display: flex; justify-content: space-between; align-items: baseline; border-top: 1px solid var(--line-soft); padding-top: 9px; }
.mod-stat .v { font-weight: 700; font-size: 15px; font-variant-numeric: tabular-nums; }
.mod-stat .l { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.mod-card .arrow { position: absolute; top: 16px; right: 16px; color: #c3d2dd; font-size: 15px; }

/* ---------- Flow diagram ---------- */
.flow { display: grid; gap: 10px; grid-template-columns: repeat(5, minmax(0,1fr)); align-items: stretch; }
.flow-step {
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px; position: relative; text-align: center;
}
.flow-step .n {
  width: 22px; height: 22px; border-radius: 50%; background: var(--brand);
  color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center;
  margin: 0 auto 7px;
}
.flow-step b { display: block; font-size: 12px; margin-bottom: 2px; }
.flow-step span { font-size: 10.5px; color: var(--muted); line-height: 1.4; display: block; }

/* ---------- POS ---------- */
.pos-grid { display: grid; grid-template-columns: minmax(0,1.5fr) minmax(0,1fr); gap: 15px; align-items: start; }
.prod-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 9px; max-height: 430px; overflow-y: auto; padding: 2px; }
.prod-item {
  border: 1px solid var(--line); border-radius: 9px; padding: 10px;
  cursor: pointer; background: #fff; text-align: left; font-family: inherit;
  transition: border-color .12s, box-shadow .12s, transform .06s;
}
.prod-item:hover { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(27,78,155,.08); }
.prod-item:active { transform: scale(.985); }
.prod-item .n { font-size: 12.5px; font-weight: 600; line-height: 1.3; margin-bottom: 5px; display: block; }
.prod-item .p { font-size: 13px; font-weight: 700; color: var(--brand); font-variant-numeric: tabular-nums; }
.prod-item .s { font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.prod-item.tax { border-left: 3px solid var(--accent); }

.cart-list { max-height: 300px; overflow-y: auto; }
.cart-row {
  display: grid; grid-template-columns: 1fr auto auto; gap: 9px;
  align-items: center; padding: 9px 0; border-bottom: 1px dashed var(--line-soft);
}
.cart-row:last-child { border-bottom: 0; }
.cart-row .name { font-size: 12.5px; font-weight: 600; line-height: 1.3; }
.cart-row .meta { font-size: 10.5px; color: var(--muted); }
.qty { display: flex; align-items: center; gap: 0; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.qty button {
  width: 25px; height: 27px; border: 0; background: #f7fafc; cursor: pointer;
  font-size: 14px; color: var(--ink-2); line-height: 1; font-family: inherit;
}
.qty button:hover { background: var(--brand-100); color: var(--brand-600); }
.qty input {
  width: 38px; height: 27px; border: 0; text-align: center; font-family: inherit;
  font-size: 12.5px; font-weight: 650; font-variant-numeric: tabular-nums;
}
.qty input:focus { outline: none; background: #f4f8fd; }

.totals { border-top: 2px solid var(--line); margin-top: 10px; padding-top: 10px; }
.tot-row { display: flex; justify-content: space-between; font-size: 12.5px; padding: 3px 0; }
.tot-row .k { color: var(--muted); }
.tot-row .v { font-variant-numeric: tabular-nums; font-weight: 600; }
.tot-row.grand { font-size: 17px; font-weight: 750; padding-top: 8px; margin-top: 5px; border-top: 1px solid var(--line); letter-spacing: -.02em; }
.tot-row.grand .k { color: var(--ink); font-weight: 700; font-size: 13px; letter-spacing: 0; }

/* ---------- Ticket preview ---------- */
.ticket {
  background: #fff; border: 1px dashed #c3d1dd; border-radius: 6px;
  padding: 14px; font-family: "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;
  font-size: 11px; line-height: 1.55; color: #1c2b3a; max-width: 320px;
}
.ticket .c { text-align: center; }
.ticket .b { font-weight: 700; }
.ticket hr { border: 0; border-top: 1px dashed #c3d1dd; margin: 7px 0; }
.ticket .r { display: flex; justify-content: space-between; gap: 6px; }
.ticket .tot { font-weight: 700; font-size: 12.5px; }
.qr-box { width: 64px; height: 64px; margin: 8px auto 4px; display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; }
.qr-box i { background: #1c2b3a; }
.qr-box i.o { background: transparent; }

/* ---------- Misc ---------- */
.notice {
  display: flex; gap: 10px; padding: 11px 14px; border-radius: 9px;
  font-size: 12.5px; line-height: 1.55; border: 1px solid;
}
.notice b { font-weight: 650; }
.notice-warn { background: var(--warn-100); border-color: #f0dcb4; color: #7a5207; }
.notice-info { background: var(--info-100); border-color: #cddff0; color: #17496f; }
.notice-ok { background: var(--ok-100); border-color: #c3e6d5; color: #12603f; }
.notice .ni { font-size: 15px; line-height: 1.2; flex: 0 0 auto; }

.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 11.5px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

.empty {
  text-align: center; padding: 34px 18px; color: var(--muted); font-size: 13px;
}
.empty .ei { font-size: 26px; opacity: .35; display: block; margin-bottom: 8px; }

.loading { padding: 28px; text-align: center; color: var(--muted); font-size: 13px; }
.spinner {
  width: 20px; height: 20px; border: 2px solid var(--line);
  border-top-color: var(--brand); border-radius: 50%;
  display: inline-block; animation: spin .7s linear infinite; vertical-align: middle;
  margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: 22px; right: 22px; z-index: 200;
  background: var(--ink); color: #fff; padding: 11px 17px;
  border-radius: 9px; font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 9px;
  transform: translateY(70px); opacity: 0; transition: all .25s cubic-bezier(.2,.8,.3,1);
  max-width: 90vw;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast .ti { color: #6ee7b7; font-weight: 700; }

.cell-note { font-size: 11px; color: var(--muted); }
.tag-list { display: flex; flex-wrap: wrap; gap: 5px; }

.mini-tbl { width: 100%; font-size: 12px; border-collapse: collapse; }
.mini-tbl td { padding: 5px 0; border-bottom: 1px solid var(--line-soft); }
.mini-tbl td:last-child { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.mini-tbl tr:last-child td { border-bottom: 0; }

.progress { height: 6px; background: var(--line-soft); border-radius: 4px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--brand); border-radius: 4px; }
.progress.warn > i { background: var(--warn); }
.progress.danger > i { background: var(--danger); }

.avatar-sm {
  width: 26px; height: 26px; border-radius: 50%; background: #eef3f8;
  color: var(--ink-2); display: inline-grid; place-items: center;
  font-size: 10.5px; font-weight: 700; flex: 0 0 auto;
}
.person { display: flex; align-items: center; gap: 9px; }

.legal { font-size: 11.5px; color: var(--muted); line-height: 1.6; }
.legal b { color: var(--ink-2); }

.overlay {
  display: none; position: fixed; inset: 0; background: rgba(9,20,30,.5);
  z-index: 55; backdrop-filter: blur(2px);
}
.overlay.show { display: block; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .grid-5 { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .flow { grid-template-columns: repeat(3, minmax(0,1fr)); }
}

@media (max-width: 980px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%); transition: transform .25s cubic-bezier(.2,.8,.3,1);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: grid; place-items: center; }
  .grid-side, .grid-side-l { grid-template-columns: minmax(0,1fr); }
  .pos-grid { grid-template-columns: minmax(0,1fr); }
  .content { padding: 16px; }
  .topbar { padding: 0 14px; gap: 10px; }
  .topbar .crumb { display: none; }
  .period-chip { display: flex; }
  .user-meta { display: none; }
}

@media (max-width: 760px) {
  .grid-3, .grid-5 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .form-grid.g3, .form-grid.g4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .flow { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .page-head h2 { font-size: 18.5px; }
  .kpi-value { font-size: 21px; }
}

@media (max-width: 540px) {
  .grid-2, .grid-3, .grid-4, .grid-5 { grid-template-columns: minmax(0,1fr); }
  .form-grid.g2, .form-grid.g3, .form-grid.g4 { grid-template-columns: minmax(0,1fr); }
  .form-grid .span-2 { grid-column: auto; }
  .flow { grid-template-columns: minmax(0,1fr); }
  .content { padding: 13px; }
  .card-body { padding: 14px; }
  .period-chip { display: none; }
  .toast { left: 13px; right: 13px; bottom: 13px; }
  .prod-list { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

/* ---------- Informes (motor js/reportes.js) ---------- */

.rep-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(9, 20, 30, .62);
  display: flex; flex-direction: column; align-items: center;
  padding: 18px; overflow: auto; -webkit-overflow-scrolling: touch;
  backdrop-filter: blur(3px);
}

.rep-sheet {
  background: #fff; width: 100%; max-width: 900px;
  border-radius: 12px; overflow: hidden;
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, .65);
  margin: auto 0; display: flex; flex-direction: column;
  max-height: calc(100vh - 36px);
}

.rep-toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 11px 16px; background: #fff;
  border-bottom: 1px solid var(--line); flex: 0 0 auto;
}
.rep-toolbar-title {
  font-size: 12.5px; font-weight: 700; color: var(--ink);
  letter-spacing: -.01em; flex: 1; min-width: 120px;
}
.rep-toolbar-btns { display: flex; gap: 6px; flex-wrap: wrap; }

.rep-doc { padding: 30px 34px 34px; overflow-y: auto; flex: 1 1 auto; }

/* Encabezado */
.rep-head {
  display: flex; align-items: center; gap: 20px;
  padding-bottom: 15px; border-bottom: 3px solid var(--brand);
}
.rep-brand {
  flex: 0 0 auto; width: 150px; display: flex;
  align-items: center; justify-content: center;
}
.rep-brand img { width: 100%; height: auto; max-height: 62px; object-fit: contain; display: block; }
.rep-firm-data { font-size: 10.5px; color: var(--muted); line-height: 1.5; }
.rep-firm-name {
  font-size: 13px; font-weight: 750; color: var(--ink);
  letter-spacing: -.01em; line-height: 1.25; margin-bottom: 2px;
}

.rep-titlebar {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; flex-wrap: wrap; padding: 15px 0 13px;
  border-bottom: 1px solid var(--line);
}
.rep-title { font-size: 19px; letter-spacing: -.025em; color: var(--ink); margin: 0; }
.rep-sub { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.rep-stamp {
  font-size: 10px; color: var(--muted); text-align: right;
  line-height: 1.65; flex: 0 0 auto;
}
.rep-stamp b { color: var(--ink-2); font-weight: 700; }

/* Tabla del informe */
.rep-tbl-wrap { margin-top: 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.rep-tbl { width: 100%; border-collapse: collapse; font-size: 11.5px; }
table.rep-tbl thead th {
  background: var(--brand); color: #fff;
  font-size: 9px; text-transform: uppercase; letter-spacing: .07em;
  font-weight: 700; padding: 7px 8px; text-align: left;
  border: 1px solid var(--brand-600);
}
table.rep-tbl thead th.r { text-align: right; }
table.rep-tbl tbody td {
  padding: 6px 8px; border: 1px solid var(--line);
  vertical-align: top; color: var(--ink);
}
table.rep-tbl tbody tr:nth-child(even) td { background: #f7fafd; }
table.rep-tbl td.r, table.rep-tbl th.r { text-align: right; }
table.rep-tbl td.num {
  font-variant-numeric: tabular-nums; white-space: nowrap;
  font-weight: 550;
}
table.rep-tbl tfoot td {
  padding: 7px 8px; font-weight: 750; font-size: 11.5px;
  background: var(--brand-100) !important; color: var(--brand-600);
  border: 1px solid #cbdff5; font-variant-numeric: tabular-nums;
}
table.rep-tbl .rep-empty {
  text-align: center; color: var(--muted); padding: 26px 10px; font-style: italic;
}
.rep-count {
  font-size: 10px; color: var(--muted);
  margin-top: 7px; text-align: right;
}

/* Pie del informe */
.rep-foot { margin-top: 26px; }
.rep-nota {
  font-size: 10.5px; color: var(--ink-2); line-height: 1.6;
  background: #fbfdff; border: 1px solid var(--line);
  border-left: 3px solid var(--brand);
  border-radius: 0 6px 6px 0; padding: 9px 12px; margin-bottom: 26px;
}
.rep-nota b { font-weight: 700; }
.rep-sign {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 22px; margin-bottom: 20px; padding-top: 16px;
}
.rep-sign > div {
  font-size: 9px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 650; text-align: center;
}
.rep-sign > div span {
  display: block; border-top: 1px solid #9fb0c2;
  height: 34px; margin-bottom: 5px;
}
.rep-legal {
  font-size: 8.5px; color: var(--muted); line-height: 1.6;
  border-top: 1px solid var(--line-soft); padding-top: 9px; text-align: center;
}

/* ---------- Impresión ---------- */

@media print {
  .sidebar, .topbar, .head-actions, .no-print { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  .content { padding: 0; max-width: none; }

  /* Informe abierto: se imprime solo el documento */
  body.rep-printing > *:not(#repOverlay) { display: none !important; }
  body.rep-printing .rep-overlay {
    position: static; display: block; background: none;
    padding: 0; overflow: visible; backdrop-filter: none;
  }
  body.rep-printing .rep-sheet {
    box-shadow: none; border-radius: 0; max-width: none;
    max-height: none; width: 100%; margin: 0;
  }
  body.rep-printing .rep-doc {
    padding: 0; overflow: visible; max-height: none;
  }
  body.rep-printing .rep-toolbar { display: none !important; }

  table.rep-tbl thead { display: table-header-group; }
  table.rep-tbl tr { break-inside: avoid; }
  .rep-foot { break-inside: avoid; }
  .rep-sign { break-inside: avoid; }

  @page { size: A4 portrait; margin: 14mm 12mm; }
}

/* ---------- Factura imprimible ---------- */

.fac-top {
  display: flex; gap: 18px; align-items: stretch;
  justify-content: space-between; flex-wrap: wrap;
  margin-top: 16px; padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.fac-box {
  border: 2px solid var(--brand); border-radius: 8px;
  padding: 10px 18px; text-align: center; min-width: 190px;
  background: var(--brand-100);
}
.fac-box-t {
  font-size: 9px; text-transform: uppercase; letter-spacing: .14em;
  font-weight: 800; color: var(--brand-600);
}
.fac-numero {
  font-size: 19px; font-weight: 800; color: var(--brand-600);
  letter-spacing: -.02em; font-variant-numeric: tabular-nums;
  margin: 2px 0 1px; line-height: 1.2;
}
.fac-mini { font-size: 9.5px; color: var(--muted); }

.fac-meta {
  display: grid; grid-template-columns: repeat(2, auto);
  gap: 5px 24px; font-size: 10px; align-content: center;
}
.fac-meta > div { display: flex; gap: 6px; align-items: baseline; }
.fac-meta b {
  font-weight: 700; color: var(--muted);
  text-transform: uppercase; font-size: 8.5px; letter-spacing: .06em;
}
.fac-meta span { color: var(--ink); font-weight: 600; }

.fac-cli {
  margin-top: 13px; border: 1px solid var(--line);
  border-radius: 8px; overflow: hidden;
}
.fac-cli-h {
  background: #f4f8fd; padding: 5px 11px;
  font-size: 8.5px; text-transform: uppercase; letter-spacing: .09em;
  font-weight: 800; color: var(--brand-600);
  border-bottom: 1px solid var(--line);
}
.fac-cli-g {
  display: grid; grid-template-columns: 1.6fr 1fr 1fr 1fr;
  gap: 8px 14px; padding: 9px 11px;
}
.fac-cli-g > div { min-width: 0; }
.fac-cli-g b {
  display: block; font-size: 8px; text-transform: uppercase;
  letter-spacing: .07em; color: var(--muted); font-weight: 700;
  margin-bottom: 1px;
}
.fac-cli-g span {
  display: block; font-size: 11px; font-weight: 600; color: var(--ink);
  overflow-wrap: break-word;
}

.fac-totales { display: flex; justify-content: flex-end; margin-top: 14px; }
.fac-tot-tbl { width: 300px; border-collapse: collapse; font-size: 11.5px; }
.fac-tot-tbl td { padding: 4px 9px; border-bottom: 1px solid var(--line-soft); }
.fac-tot-tbl td:first-child { color: var(--muted); }
.fac-tot-tbl td.num {
  text-align: right; font-variant-numeric: tabular-nums;
  font-weight: 600; white-space: nowrap;
}
.fac-tot-tbl tr.fac-grand td {
  background: var(--brand); color: #fff;
  font-size: 14px; font-weight: 800; padding: 7px 9px;
  border-bottom: 0;
}
.fac-tot-tbl tr.fac-grand td:first-child { color: #fff; }

.fac-pie {
  display: flex; gap: 18px; align-items: flex-start;
  margin-top: 22px; padding-top: 13px;
  border-top: 1px solid var(--line);
}
.fac-qr { flex: 0 0 auto; text-align: center; }
.fac-qr .qr-box { width: 68px; height: 68px; margin: 0 auto 4px; }
.fac-qr-t { font-size: 7.5px; color: var(--muted); line-height: 1.35; }
.fac-legales { font-size: 9.5px; color: var(--muted); line-height: 1.6; flex: 1; }
.fac-legales b { color: var(--ink-2); font-weight: 700; }
.fac-nota {
  margin-top: 6px; padding-top: 6px;
  border-top: 1px dashed var(--line); font-style: italic;
}

@media (max-width: 720px) {
  .fac-top { flex-direction: column; gap: 12px; }
  .fac-box { min-width: 0; width: 100%; }
  .fac-cli-g { grid-template-columns: 1fr 1fr; }
  .fac-tot-tbl { width: 100%; }
  .fac-pie { flex-direction: column; }
  .fac-qr { display: flex; align-items: center; gap: 10px; }
  .fac-qr .qr-box { margin: 0; }
}

/* Responsive del informe en pantalla */
@media (max-width: 720px) {
  .rep-overlay { padding: 0; }
  .rep-sheet { border-radius: 0; max-height: none; min-height: 100vh; }
  .rep-doc { padding: 18px 15px 26px; }
  .rep-head { flex-direction: column; align-items: flex-start; gap: 12px; }
  .rep-brand { width: 130px; }
  .rep-titlebar { flex-direction: column; }
  .rep-stamp { text-align: left; }
  .rep-title { font-size: 16px; }
  .rep-sign { grid-template-columns: 1fr; gap: 26px; }
  table.rep-tbl { font-size: 10px; min-width: 560px; }
  table.rep-tbl thead th, table.rep-tbl tbody td { padding: 5px 6px; }
  .fac-tbl-hold { overflow-x: auto; }
  .rep-toolbar { position: sticky; top: 0; z-index: 2; }
  .rep-toolbar-btns { width: 100%; }
  .rep-toolbar-btns .btn { flex: 1; }
}

/* ---------- Tiquet: solo existe para imprimir ----------
   La hoja #printTicket se crea al pulsar «Tiquet», se manda al
   diálogo de impresión y se retira al cerrar. Nunca queda en
   pantalla, así el POS no arrastra una vista previa permanente. */
.ticket-print { display: none; }

body.printing-ticket > *:not(#printTicket) { display: none !important; }

body.printing-ticket #printTicket {
  display: block !important;
  position: static;
  background: #fff;
  padding: 0;
}

body.printing-ticket #printTicket .ticket {
  max-width: none;
  width: 100%;
  border: 0;
  border-radius: 0;
  padding: 0;
  font-size: 11px;
  line-height: 1.5;
  color: #000;
}

body.printing-ticket #printTicket .ticket hr {
  border-top: 1px dashed #666;
}

body.printing-ticket #printTicket .qr-box i { background: #000; }
body.printing-ticket #printTicket .qr-box i.o { background: transparent; }
