:root {
  --navy: #0f2742; --navy-2: #173556; --navy-ink: #c9d6e6;
  --bg: #eef1f5; --card: #fff; --ink: #1b2533; --muted: #64708a; --line: #dfe4ec; --zebra: #f8f9fb;
  --brand: #1d6fb8; --brand-dark: #165a99; --ok: #0f7a4a; --bad: #b3261e;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif; }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 240px; flex-shrink: 0; background: var(--navy); color: var(--navy-ink);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.content { flex: 1; min-width: 0; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 20px; color: #fff;
  font-size: 18px; font-weight: 700; letter-spacing: .02em; border-bottom: 1px solid var(--navy-2); }
.logo { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 7px;
  background: var(--brand); color: #fff; font-weight: 800; }
nav { flex: 1; overflow-y: auto; padding: 8px 0; scrollbar-width: thin; scrollbar-color: var(--navy-2) transparent; }
.nav-sec { margin: 2px 8px; }
.nav-head { display: flex; align-items: center; gap: 9px; width: 100%; text-align: left; background: none; border: 0;
  padding: 10px 10px; border-radius: 6px; cursor: pointer; color: #dbe6f3; font-size: 12px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em; transition: background .15s, color .15s; }
.nav-head:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-head span { flex: 1; }
.nav-ico { width: 17px; height: 17px; flex-shrink: 0; fill: none; stroke: #4ea1ea; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-chev { width: 16px; height: 16px; fill: none; stroke: #7f93ad; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform .25s; }
.nav-sec.cerrada .nav-chev { transform: rotate(-90deg); }
.nav-sec.tiene-activa > .nav-head { color: #fff; }
.nav-sec.tiene-activa > .nav-head .nav-ico { stroke: #8fc7ff; }
.nav-items { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .25s ease; }
.nav-items > div { overflow: hidden; margin-left: 18px; border-left: 1px solid var(--navy-2); }
.nav-sec.cerrada .nav-items { grid-template-rows: 0fr; }
nav .nav-items button { display: block; width: 100%; text-align: left; background: none; border: 0; border-left: 3px solid transparent;
  margin-left: -1px; color: #aebfd4; padding: 7px 12px; border-radius: 0 6px 6px 0; font-size: 13.5px;
  transition: background .15s, color .15s, padding-left .15s; }
nav .nav-items button:hover { background: rgba(255,255,255,.07); color: #fff; padding-left: 16px; }
nav .nav-items button.active { background: linear-gradient(90deg, rgba(78,161,234,.28), rgba(78,161,234,.06));
  border-left-color: #4ea1ea; color: #fff; font-weight: 600; }
nav .nav-head:focus-visible, nav .nav-items button:focus-visible { outline: 2px solid #4ea1ea; outline-offset: -2px; }
@media (prefers-reduced-motion: reduce) { .nav-items, .nav-chev, nav button { transition: none !important; } }
.side-foot { margin-top: auto; padding: 14px 16px; border-top: 1px solid var(--navy-2); display: grid; gap: 6px; }
.modo { font-size: 12px; color: #9fb2cb; word-break: break-all; margin-bottom: 4px; }
.side-btn { display: block; text-align: left; background: none; border: 1px solid var(--navy-2); color: var(--navy-ink);
  padding: 7px 10px; border-radius: 5px; font-size: 13px; cursor: pointer; }
.side-btn:hover { background: var(--navy-2); }

.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 16px 28px; background: var(--card); border-bottom: 1px solid var(--line); }
.page-head h1 { margin: 0; font-size: 20px; }
main { padding: 22px 28px 40px; max-width: 1080px; }

/* Tarjetas y formularios */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  padding: 18px 20px; margin-bottom: 18px; box-shadow: 0 1px 2px rgba(15, 39, 66, .04); }
h2 { margin: 0 0 14px; font-size: 15px; }
h3 { margin: 20px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--brand-dark); }
.row { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; margin-bottom: 14px; }
.row.end { justify-content: flex-end; align-items: center; margin: 14px 0 0; }
.row.between { justify-content: space-between; align-items: center; }
.grow { flex: 1; min-width: 200px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
input, select { font: inherit; font-weight: 400; color: var(--ink); background: #fff;
  border: 1px solid #c8d0dc; border-radius: 5px; padding: 7px 9px; }
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: var(--brand); }
button { font: inherit; cursor: pointer; background: var(--brand); color: #fff; border: 0; border-radius: 5px; padding: 8px 16px; }
button:hover { background: var(--brand-dark); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost { background: #fff; color: var(--brand-dark); border: 1px solid #c8d0dc; }
button.ghost:hover { background: var(--bg); }
.btn-file { display: inline-block; flex-direction: row; background: var(--brand); color: #fff; padding: 8px 14px; border-radius: 6px;
  font-size: 14px; font-weight: 600; cursor: pointer; }
.btn-file:hover { background: var(--brand-dark); }
textarea { width: 100%; font: 13px/1.4 Consolas, monospace; padding: 8px; border: 1px solid #c8d0dc; border-radius: 6px; resize: vertical; }
.pc-lista { max-height: 260px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; }
.pc-err { color: var(--bad); margin: 2px 0; }
button.small { padding: 4px 10px; font-size: 13px; }
button.link { background: none; color: var(--bad); padding: 2px 6px; }
button.link:hover { background: #fdecea; }

/* Tablas contables */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
thead th { background: #f1f4f8; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  border-bottom: 2px solid #cfd7e3; }
tbody tr:nth-child(even) td { background: var(--zebra); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; font-family: "Cascadia Mono", Consolas, monospace; }
tfoot td, tr.total td { font-weight: 700; background: #f1f4f8 !important; border-top: 2px solid var(--navy); border-bottom: 0; }
table.lines select, table.lines input { width: 100%; }
table.lines tbody tr:nth-child(even) td { background: none; }
.indent { padding-left: 28px; }
.neg { color: var(--bad); }

/* Asientos */
.asiento { border: 1px solid var(--line); border-radius: 6px; margin-bottom: 12px; overflow: hidden; }
.asiento header { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 7px 12px;
  background: #f1f4f8; border-bottom: 1px solid var(--line); font-weight: 600; }
.asiento .muted { font-weight: 400; }
.asiento table tr:last-child td { border-bottom: 0; }

.muted { color: var(--muted); }
.empty { color: var(--muted); padding: 14px 0; }
.status { font-size: 13px; font-weight: 600; }
.status.ok, td.ok { color: var(--ok); } .status.bad, td.bad { color: var(--bad); }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 10px; background: #e6ecf4; color: var(--muted); }
.tag.estado-borrador { background: #fff3d6; color: #8a5a00; }
.tag.estado-contabilizado { background: #e0f3e6; color: var(--ok); }
.tag.estado-anulado { background: #fdecea; color: var(--bad); }
.asiento.anulado table { opacity: .55; text-decoration: line-through; }
.asiento.borrador { border-style: dashed; }

/* Cuenta y panel del propietario */
.banner { padding: 10px 28px; background: #fff3d6; color: #8a5a00; border-bottom: 1px solid #f0dca8; font-weight: 600; }
.banner.bad { background: #fdecea; color: var(--bad); border-bottom-color: #f5c6c2; }
.plan-info { margin: -4px 0 4px; color: #7cc0ff; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; }
.kpi-n { font-size: 26px; font-weight: 700; color: var(--navy); font-variant-numeric: tabular-nums; }
.kpi-t { font-size: 12px; color: var(--muted); }
.scroll-x { overflow-x: auto; }
table.admin td { vertical-align: middle; }
table.admin input[type=text], table.admin input[type=date], table.admin input[type=number], table.admin select { width: 100%; min-width: 90px; padding: 5px 7px; }
table.admin .f-estado { margin-top: 4px; }
.small-t { font-size: 11px; }
.banner { margin: 0; }

/* Facturas y libros de IVA */
.libro-head { margin: 0 0 12px; line-height: 1.5; }
table.libro { font-size: 11.5px; white-space: nowrap; }
table.libro th, table.libro td { padding: 4px 7px; }
.anulada-fila td { color: var(--muted); text-decoration: line-through; }
.anulada-fila td:last-child, .anulada-fila td .tag { text-decoration: none; }
main:has(#view-libro-ventas:not([hidden])), main:has(#view-libro-compras:not([hidden])), main:has(#view-facturas:not([hidden])) { max-width: none; }

/* Seguimiento, comprobantes e informe */
ul.pendientes { margin: 4px 0 12px; padding-left: 22px; }
ul.pendientes li { margin: 2px 0; }
.comprobante table.comp-datos td { border: 1px solid var(--line); padding: 6px 8px; }
.firmas { display: flex; justify-content: space-around; margin-top: 56px; text-align: center; }
.informe-sec { margin-bottom: 26px; }
.informe-h { font-size: 18px; border-bottom: 2px solid var(--navy); padding-bottom: 6px; margin-bottom: 14px; color: var(--navy); }
.informe-portada { text-align: center; padding: 60px 0; }
.informe-portada h1 { font-size: 34px; margin: 6px 0; color: var(--navy); }
.informe-mes { font-size: 22px; }
main:has(#view-informe:not([hidden])), main:has(#view-cxc:not([hidden])), main:has(#view-cxp:not([hidden])), main:has(#view-retenciones:not([hidden])) { max-width: none; }

/* Conciliación bancaria */
.scroll-y { max-height: 340px; overflow-y: auto; border: 1px solid var(--line); border-radius: 6px; margin: 6px 0; }
.scroll-y table { margin: 0; }
main:has(#view-conciliacion:not([hidden])) { max-width: none; }
details summary { cursor: pointer; margin: 8px 0; }

/* Empresa activa */
.empresa-sel { padding: 12px 16px; border-bottom: 1px solid var(--navy-2); display: grid; gap: 4px; }
.empresa-sel label { color: #7f93ad; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.empresa-sel select { background: var(--navy-2); color: #fff; border: 1px solid #2a4a70; font-weight: 600; width: 100%; }
.empresa-chip { font-size: 13px; font-weight: 600; color: var(--brand-dark); background: #e6f0fa; border: 1px solid #c6dcf2;
  padding: 4px 12px; border-radius: 14px; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Acceso */
.logo-svg { flex-shrink: 0; border-radius: 10px; }
.brand-name { font-weight: 700; letter-spacing: .02em; }
.login { position: fixed; inset: 0; display: grid; grid-template-columns: minmax(420px, 1.15fr) minmax(380px, 1fr); background: #fff; z-index: 10; overflow: auto; }
.login-hero { position: relative; overflow: hidden; isolation: isolate; display: flex; flex-direction: column; justify-content: space-between; gap: 28px;
  padding: 40px 56px; color: #fff; background: linear-gradient(155deg, #12304f 0%, #0c2038 55%, #091a2e 100%); }
.login-hero::before { content: ""; position: absolute; inset: 0; z-index: -1; opacity: .55;
  background-image: linear-gradient(rgba(255,255,255,.05) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.05) 1px, transparent 1px);
  background-size: 44px 44px; -webkit-mask-image: radial-gradient(ellipse at 30% 35%, #000 0, transparent 75%); mask-image: radial-gradient(ellipse at 30% 35%, #000 0, transparent 75%); }
.hero-glow { position: absolute; border-radius: 50%; filter: blur(70px); z-index: -1; }
.hero-glow.g1 { width: 380px; height: 380px; background: #1d6fb8; opacity: .45; top: -120px; left: -80px; }
.hero-glow.g2 { width: 320px; height: 320px; background: #4ea1ea; opacity: .22; bottom: -100px; right: -60px; }
.hero-brand { display: flex; align-items: center; gap: 12px; font-size: 24px; }
.hero-main { display: grid; gap: 20px; max-width: 560px; }
.hero-pill { justify-self: start; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: #9fd0ff;
  background: rgba(78, 161, 234, .14); border: 1px solid rgba(78, 161, 234, .35); padding: 5px 12px; border-radius: 999px; }
.hero-main h2 { margin: 0; font-size: 38px; line-height: 1.12; font-weight: 750; letter-spacing: -.01em; }
.hero-sub { margin: 0; color: #b9c9de; font-size: 16px; line-height: 1.55; }
.hero-card { background: rgba(255,255,255,.07); border: 1px solid rgba(255,255,255,.14); backdrop-filter: blur(8px); border-radius: 14px;
  padding: 16px 20px 14px; box-shadow: 0 20px 50px rgba(0,0,0,.35); max-width: 440px; transform: rotate(-1.2deg); }
.hc-head { display: flex; justify-content: space-between; align-items: center; font-size: 12.5px; color: #c9d6e6; margin-bottom: 12px; }
.hc-tag { font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; padding: 2px 8px; border-radius: 999px; background: rgba(255,255,255,.12); color: #d5e1f0; }
.hc-kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.hc-kpis small { display: block; color: #9fb2cb; font-size: 11px; margin-bottom: 2px; }
.hc-kpis b { font-size: 14.5px; font-variant-numeric: tabular-nums; }
.hc-pay b { color: #7ee0a9; }
.hc-bars { display: flex; align-items: flex-end; gap: 8px; height: 54px; margin-top: 14px; }
.hc-bars i { flex: 1; border-radius: 4px 4px 2px 2px; background: linear-gradient(180deg, #4ea1ea, #1d6fb8); opacity: .9; }
.hero-feats { list-style: none; margin: 4px 0 0; padding: 0; display: grid; gap: 14px; }
.hero-feats li { display: flex; gap: 12px; align-items: center; color: #d5e1f0; font-size: 15px; }
.hero-feats .fi { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0;
  background: rgba(78, 161, 234, .16); border: 1px solid rgba(78, 161, 234, .3); color: #7cc0ff; }
.hero-foot { color: #7f93ad; font-size: 12.5px; }

.login-pane { max-width: none; display: grid; place-items: center; padding: 32px 24px; background: radial-gradient(circle at 85% 8%, #e3eefb 0, transparent 45%), #f4f7fb; }
.login-box { width: min(430px, 100%); display: grid; gap: 16px; background: #fff; padding: 30px 32px 24px; border-radius: 16px;
  border: 1px solid #e3e9f2; box-shadow: 0 24px 60px rgba(15, 39, 66, .12); animation: subir .45s ease both; }
@keyframes subir { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.login-box h1 { margin: 0 0 4px; font-size: 24px; color: var(--navy); }
.login-box p { margin: 0; }
.login-mobile-brand { display: none; align-items: center; gap: 10px; font-size: 20px; color: var(--navy); }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; background: #eef2f8; border-radius: 10px; }
.seg button { background: none; color: var(--muted); padding: 9px 12px; border-radius: 8px; font-weight: 600; }
.seg button:hover { background: rgba(255,255,255,.6); }
.seg button.on { background: #fff; color: var(--navy); box-shadow: 0 1px 3px rgba(15, 39, 66, .16); }
.fld .in { position: relative; display: block; }
.fld .in svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: #8a97ad; pointer-events: none; }
.fld .in input { width: 100%; padding: 11px 12px 11px 40px; font-size: 15px; border-radius: 9px; }
.fld .in input[type=password] { padding-right: 76px; }
button.eye { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); background: none; color: var(--brand-dark);
  padding: 4px 8px; font-size: 12px; font-weight: 600; }
button.eye:hover { background: var(--bg); }
.fuerza { display: flex; align-items: center; gap: 10px; margin-top: -6px; }
.fuerza span { flex: 1; height: 6px; background: #e6ecf4; border-radius: 4px; overflow: hidden; }
.fuerza i { display: block; height: 100%; width: 0; background: var(--bad); transition: width .25s, background .25s; }
.fuerza small { color: var(--muted); font-size: 12px; min-width: 70px; }
.info { background: #eef5fd; border: 1px solid #cfe2f6; color: #1d4f85; padding: 10px 12px; border-radius: 9px; font-size: 13px; line-height: 1.45; }
.login-box .status:empty { display: none; }
button.cta { padding: 12px 16px; font-size: 15px; font-weight: 650; border-radius: 9px; background: linear-gradient(180deg, #2a82d0, #1d6fb8);
  box-shadow: 0 6px 16px rgba(29, 111, 184, .35); }
button.cta:hover { filter: brightness(1.06); background: linear-gradient(180deg, #2a82d0, #1d6fb8); }
.spin { display: none; width: 15px; height: 15px; margin-right: 8px; vertical-align: -2px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
  border-radius: 50%; animation: giro .7s linear infinite; }
button.cta.cargando .spin { display: inline-block; }
@keyframes giro { to { transform: rotate(360deg); } }
.login-foot { text-align: center; color: var(--muted); font-size: 12.5px; }

/* Cuenta pendiente de aprobación */
.pend { position: fixed; inset: 0; z-index: 11; display: grid; place-items: center; padding: 24px; overflow: auto;
  background: radial-gradient(circle at 20% 10%, #1f4a78 0, transparent 50%), linear-gradient(155deg, #12304f, #091a2e); }
.pend-card { width: 100%; max-width: 460px; display: grid; gap: 14px; justify-items: center; text-align: center; padding: 36px 32px;
  background: #fff; border-radius: 16px; box-shadow: 0 30px 70px rgba(0,0,0,.4); animation: subir .45s ease both; }
.pend-ico { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; background: #fff3d6; color: #b7791f; }
.pend-ico.bad { background: #fdecea; color: var(--bad); }
.pend-card h1 { margin: 0; font-size: 22px; color: var(--navy); }
.pend-card p { margin: 0; color: var(--muted); line-height: 1.55; }
.pend-acciones { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 6px; }

@media (max-width: 900px) {
  .login { grid-template-columns: 1fr; }
  .login-hero { display: none; }
  .login-mobile-brand { display: flex; }
}

.toast { position: fixed; bottom: 22px; right: 22px; background: var(--navy); color: #fff; padding: 11px 18px;
  border-radius: 6px; box-shadow: 0 4px 14px rgba(0,0,0,.25); z-index: 20; max-width: 420px; }
.toast.bad { background: var(--bad); }

@media (max-width: 800px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  nav { display: block; overflow: visible; }
  nav button { width: auto; border-left: 0; }
  main, .page-head { padding-left: 14px; padding-right: 14px; }
}
@media print {
  @page { size: landscape; margin: 10mm; }
  .sidebar, form, .row, button, .toast { display: none !important; }
  .page-head .row { display: flex !important; }
  .informe-sec { page-break-after: always; }
  .informe-sec:last-child { page-break-after: auto; }
  .banner { display: none !important; }
  body.solo-doc .page-head, body.solo-doc .card:not(.print-doc) { display: none !important; }
  body.solo-doc .print-doc { display: block !important; }
  .page-head { border: 0; } .card { border: 0; box-shadow: none; padding: 0; }
  body { background: #fff; }
}
