:root {
  color-scheme: light dark;
  --bg: #f3f5f6; --panel: #ffffff; --panel2: #f8f9fa; --text: #15202b; --muted: #5b6875; --line: #dfe4e8;
  --primary: #0f6b5f; --primary-hover: #0b574d; --on-primary: #ffffff; --tint: #e3f2ef;
  --danger: #b3261e; --danger-bg: #fbe6e4; --warn: #875700; --warn-bg: #fdf1d7; --ok: #116a4e; --ok-bg: #dcf3e8; --off-bg: #e9ecef;
  --side: #10292a; --side-text: #cfdedc; --side-active: #1d4543;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 41, 42, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101518; --panel: #192126; --panel2: #1f282e; --text: #e8edf0; --muted: #9dabb6; --line: #2d3840;
    --primary: #45bfa9; --primary-hover: #63d0bc; --on-primary: #06231f; --tint: #173a36;
    --danger: #ff9389; --danger-bg: #47211e; --warn: #f1c566; --warn-bg: #3e3113; --ok: #6fdcb4; --ok-bg: #143a2e; --off-bg: #2a343b;
    --side: #0c1214; --side-text: #bccbd0; --side-active: #1f2e30; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14.5px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
h1 { font-size: 21px; line-height: 1.25; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15.5px; margin: 0; }
h3 { font-size: 14px; margin: 0; }
p { margin: 0; }
a { color: var(--primary); }
.layout { display: grid; grid-template-columns: 216px minmax(0, 1fr); min-height: 100%; }
.side { position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; background: var(--side); color: var(--side-text); padding: 14px 10px; }
.brand { display: flex; align-items: center; gap: 8px; padding: 4px 8px 14px; color: #fff; font-size: 17px; font-weight: 700; }
.brand img { display: block; height: 30px; width: auto; max-width: 100%; }
.brand-bar img { display: block; height: 24px; width: auto; }
.login-brand { margin: 0; line-height: 0; }
.login-logo img { display: block; height: 44px; width: auto; max-width: 100%; }
.side a { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 10px; color: inherit; text-decoration: none; border-radius: 7px; font-size: 14px; }
.side a:hover { background: var(--side-active); }
.side a.on { background: var(--side-active); color: #fff; font-weight: 600; }
.side .group { margin: 12px 10px 4px; font-size: 11.5px; letter-spacing: .05em; text-transform: uppercase; opacity: .65; }
.side .count { min-width: 20px; padding: 0 6px; text-align: center; font-size: 12px; font-weight: 700; color: #10292a; background: #f3c969; border-radius: 99px; }
.side .foot { margin-top: auto; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, .12); }
.side .who { padding: 4px 10px 6px; font-size: 13px; }
.main { min-width: 0; padding: 20px 22px 60px; }
.mobile-bar { display: none; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 10px 16px; margin-bottom: 14px; }
.sub { color: var(--muted); font-size: 13px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.between { justify-content: space-between; }
.stack { display: grid; gap: 14px; }
.panel { min-width: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.panel > h2 { margin-bottom: 10px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 10px; }
.kpi { min-width: 0; padding: 11px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.kpi span { display: block; color: var(--muted); font-size: 12.5px; }
.kpi b { display: block; margin-top: 2px; font-size: 19px; font-weight: 650; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi small { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
.kpi.strong { background: var(--tint); border-color: transparent; }
.neg { color: var(--danger); }
.pos { color: var(--ok); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
button, .btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 6px 12px; color: var(--on-primary); background: var(--primary); border: 1px solid var(--primary); border-radius: 7px; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
button:hover, .btn:hover { background: var(--primary-hover); }
button.ghost, .btn.ghost { color: var(--text); background: var(--panel); border-color: var(--line); font-weight: 500; }
button.ghost:hover, .btn.ghost:hover { background: var(--panel2); }
button.danger { color: var(--danger); background: var(--panel); border-color: var(--danger); }
button.danger:hover { background: var(--danger-bg); }
button.link { min-height: 0; padding: 0; color: var(--primary); background: none; border: 0; font-weight: 600; text-align: left; }
button.link:hover { background: none; text-decoration: underline; }
button:disabled { opacity: .55; cursor: default; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.f { display: grid; gap: 3px; min-width: 0; font-size: 12.5px; color: var(--muted); align-content: start; }
.f small { font-size: 12px; }
input, select, textarea { width: 100%; min-height: 37px; padding: 7px 9px; font: inherit; font-size: 14.5px; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 7px; }
textarea { min-height: 90px; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
input[type=checkbox] { width: 17px; height: 17px; min-height: 0; accent-color: var(--primary); flex: none; }
.check { display: flex; align-items: flex-start; gap: 8px; padding: 6px 0; font-size: 14px; }
/* Formularios en rejilla. Cada campo ocupa tres filas compartidas (texto, casilla, ayuda), así que en un
   mismo renglón todos los textos quedan a la misma altura y todas las casillas también, tengan ayuda o no. */
.form, .filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); row-gap: 3px; column-gap: 11px; align-items: start; margin-top: -8px; }
.filters { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); column-gap: 9px; margin-bottom: 12px; }
.form > *, .filters > * { padding-top: 8px; }
.form > .f, .filters > .f { display: grid; grid-template-rows: subgrid; grid-row: span 3; padding-top: 0; }
.form > .f > span:first-child, .filters > .f > span:first-child { padding-top: 8px; }
.form > .f > *, .filters > .f > * { align-self: start; }
.form > .check, .filters > .check { grid-row: span 3; align-self: start; }
.form > .actions { padding-top: 0; }
.form .wide { grid-column: 1 / -1; }
.table { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 8px 9px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { position: sticky; top: 0; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--panel); white-space: nowrap; }
th.num { text-align: right; }
tbody tr:hover { background: var(--panel2); }
tr:last-child td { border-bottom: 0; }
tr.voided td { color: var(--muted); text-decoration: line-through; }
tr.clickable { cursor: pointer; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-ok { color: var(--ok); background: var(--ok-bg); } .b-warn { color: var(--warn); background: var(--warn-bg); }
.b-danger { color: var(--danger); background: var(--danger-bg); } .b-off { color: var(--muted); background: var(--off-bg); }
.tabs { display: flex; gap: 2px; margin: 0 0 14px; overflow-x: auto; border-bottom: 1px solid var(--line); scrollbar-width: thin; }
.tabs a { flex: none; padding: 8px 11px; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; font-size: 14px; }
.tabs a:hover { color: var(--text); }
.tabs a.on { color: var(--primary); border-color: var(--primary); font-weight: 650; }
.segment { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; }
.segment button { min-height: 32px; padding: 3px 10px; color: var(--muted); background: transparent; border-color: transparent; font-weight: 500; }
.segment button:hover { background: var(--panel2); }
.segment button.on { color: var(--primary); background: var(--tint); font-weight: 650; }
.notice { padding: 9px 12px; color: var(--warn); background: var(--warn-bg); border-radius: 7px; font-size: 14px; }
.notice.danger { color: var(--danger); background: var(--danger-bg); }
.bar { height: 7px; min-width: 60px; overflow: hidden; background: var(--off-bg); border-radius: 99px; }
.bar i { display: block; height: 100%; background: var(--primary); }
.cards { display: grid; gap: 7px; }
.card { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; }
.empty { padding: 26px 10px; color: var(--muted); text-align: center; }
.skeleton { height: 120px; border-radius: var(--radius); background: linear-gradient(90deg, var(--off-bg), var(--panel2), var(--off-bg)); background-size: 300% 100%; animation: wave 1.2s linear infinite; }
@keyframes wave { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }
.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login form { display: grid; gap: 12px; width: min(360px, 100%); padding: 22px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
#toast { position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 50; width: fit-content; max-width: min(560px, calc(100vw - 32px)); margin: auto; padding: 10px 14px; color: #fff; background: #1f2d33; border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, .25); }
#toast.error { background: #a4231b; }
dialog { width: min(640px, calc(100vw - 24px)); max-height: calc(100vh - 32px); padding: 0; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
dialog.wide { width: min(920px, calc(100vw - 24px)); }
dialog::backdrop { background: rgba(10, 20, 22, .5); }
.d-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 13px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 1; }
.d-body { padding: 14px 16px 16px; }
.actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 14px; grid-column: 1 / -1; }
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; margin-right: 5px; border-radius: 2px; }
.dl { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: 4px 14px; font-size: 14px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; font-variant-numeric: tabular-nums; }
.receipt-logo { display: block; max-width: 160px; max-height: 80px; margin: 0 auto 8px; }
.logo-preview { max-width: 160px; max-height: 80px; border-radius: 6px; background: #fff; padding: 4px; }
.receipt { padding: 12px; font-family: ui-monospace, Consolas, monospace; font-size: 13px; white-space: pre-wrap; background: var(--panel2); border-radius: 7px; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.thumbs img { width: 120px; height: 120px; object-fit: cover; border-radius: 7px; border: 1px solid var(--line); }
[hidden] { display: none !important; }
@media (max-width: 820px) {
  .layout { display: block; }
  .side { position: fixed; z-index: 30; left: 0; top: 0; width: 240px; transform: translateX(-100%); transition: transform .16s ease; }
  .layout.open .side { transform: none; box-shadow: 0 0 30px rgba(0, 0, 0, .4); }
  .mobile-bar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; padding: 8px 14px; color: #fff; background: var(--side); }
  .mobile-bar button { color: #fff; background: transparent; border-color: rgba(255, 255, 255, .35); }
  .main { padding: 14px 14px 50px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi b { font-size: 16.5px; }
  .hide-sm { display: none; }
}
@media print {
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area { position: fixed; inset: 0; color: #000; background: #fff; }
}

.billing-banner { padding: 9px 22px; color: var(--warn); background: var(--warn-bg); font-weight: 600; }
.billing-banner.danger { color: var(--danger); background: var(--danger-bg); }

/* Avisos */
.side .notice-link { margin-bottom: 6px; background: rgba(255, 255, 255, .06); }
.mobile-bar .bell { margin-left: auto; }
.bell.has { border-color: #f3c969; font-weight: 700; }
.notices { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-height: 60vh; overflow-y: auto; }
.notices a { display: grid; gap: 2px; padding: 10px 12px; border-radius: 8px; color: inherit; text-decoration: none; background: var(--panel2); }
.notices li.new a { border-left: 4px solid #f3c969; }
.notices span { font-size: 13.5px; }
.notices small { font-size: 12px; opacity: .7; }
.notices-head { margin: 10px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; opacity: .75; }
.notices.old a { opacity: .72; }
.notices { max-height: 38vh; }
.danger-text { color: var(--danger) !important; }
.danger-zone { border-color: rgba(217, 83, 79, .45); }

/* Documentos legales */
.legal-wrap { max-width: 860px; margin: 0 auto; padding: 24px 16px 48px; }
.legal h1 { margin: 12px 0 4px; }
.legal h2 { margin: 22px 0 6px; font-size: 16px; }
.legal p { margin: 0 0 8px; line-height: 1.6; }
.legal-nav { display: flex; flex-wrap: wrap; gap: 6px 14px; padding-bottom: 10px; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.legal-nav a[aria-current="page"] { font-weight: 700; text-decoration: none; }
.legal-back { margin-top: 24px; }
mark.pending { background: #fff3b0; color: #15202b; padding: 0 3px; border-radius: 3px; }
.legal-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px; margin-top: 14px; font-size: 13px; }
.legal-list { margin: 4px 0 6px 18px; }
.legal-list li { margin: 4px 0; }
/* Teclado: enlace para saltar al contenido y foco siempre visible */
.skip { position: absolute; left: -9999px; top: 8px; z-index: 100; background: var(--panel); color: var(--text); padding: 8px 12px; border-radius: 8px; }
.skip:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

/* Mensajes (chat interno y soporte) */
.chat-list { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow-y: auto; padding: 4px 0 10px; }
.bubble { align-self: flex-start; max-width: min(560px, 90%); background: var(--off-bg, #eef2f1); border-radius: 12px; padding: 8px 12px; }
.bubble.me { align-self: flex-end; background: color-mix(in srgb, var(--primary, #0f6b5f) 14%, transparent); }
.chat-form { display: flex; gap: 8px; align-items: flex-end; margin-top: 8px; }
.chat-form textarea { flex: 1; min-width: 0; }
.card.on { outline: 2px solid var(--primary, #0f6b5f); }
.readonly-bar { position: sticky; top: 0; z-index: 50; margin: 0; border-radius: 0; text-align: center; }
a.card { color: inherit; text-decoration: none; }

/* Mensajes: lista compacta al lado y conversación a la mano */
.chat-layout { display: grid; grid-template-columns: minmax(200px, 280px) 1fr; gap: 16px; align-items: start; }
.chat-side { display: grid; gap: 8px; position: sticky; top: 8px; }
.chat-people { display: grid; gap: 2px; max-height: 62vh; overflow-y: auto; }
.chat-person { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 8px; color: inherit; text-decoration: none; }
.chat-person:hover { background: var(--off-bg); }
.chat-person.on { background: var(--ok-bg); font-weight: 600; }
.chat-person-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-picker { display: none; width: 100%; margin-bottom: 8px; }
.chat-thread .chat-list { max-height: 55vh; }
@media (max-width: 760px) {
  .chat-layout { display: block; }
  .chat-side { display: none; }
  .chat-picker { display: block; }
}
.big-code { font-size: 34px; font-weight: 700; letter-spacing: .18em; text-align: center; margin: 10px 0; }
/* Aceptación de términos: el recuadro va centrado (antes quedaba a la izquierda). */
.login > div { display: grid; justify-items: center; width: 100%; }
.login .legal-list { margin: 0; padding-left: 20px; }
