/* HomeLibrary web. Paleta y tipografía tomadas de homelibrary/gui/theme.py (la app de escritorio).
   Computador: menú lateral fijo. Celular: barra de navegación abajo, como una app de Android. */
:root {
  --bg: #F3F5F9; --surface: #FFFFFF; --surface-alt: #EEF1F6; --border: #D9DEE7;
  --text: #1B2330; --muted: #5D6878; --primary: #1F6AA5; --primary-hover: #185786;
  --success: #2E8B57; --warning: #B7791F; --danger: #C53030; --danger-hover: #9B2C2C;
  --sidebar: #E6EAF1; --sidebar-active: #D3DCEA; --row-alt: #F4F6FA; --head: #E3E8F0;
  --on-accent: #FFFFFF; --shadow: 0 18px 50px rgba(20, 30, 50, .18); --overlay: rgba(15, 20, 30, .45);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: Consolas, "SFMono-Regular", Menlo, monospace;
  --r: 10px;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #16181D; --surface: #1F2229; --surface-alt: #272B33; --border: #323742;
  --text: #E6E9EF; --muted: #9AA3B2; --primary: #2F7FC1; --primary-hover: #2668A0;
  --success: #3FAE6E; --warning: #D69E2E; --danger: #E05252; --danger-hover: #B83E3E;
  --sidebar: #111318; --sidebar-active: #252A33; --row-alt: #252930; --head: #2A2F39;
  --shadow: 0 18px 50px rgba(0, 0, 0, .5); --overlay: rgba(0, 0, 0, .6); color-scheme: dark; } }
:root[data-theme="dark"] {
  --bg: #16181D; --surface: #1F2229; --surface-alt: #272B33; --border: #323742;
  --text: #E6E9EF; --muted: #9AA3B2; --primary: #2F7FC1; --primary-hover: #2668A0;
  --success: #3FAE6E; --warning: #D69E2E; --danger: #E05252; --danger-hover: #B83E3E;
  --sidebar: #111318; --sidebar-active: #252A33; --row-alt: #252930; --head: #2A2F39;
  --shadow: 0 18px 50px rgba(0, 0, 0, .5); --overlay: rgba(0, 0, 0, .6); color-scheme: dark; }

html, body, #app { height: 100%; }
#app { height: 100dvh; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); -webkit-tap-highlight-color: transparent; }
* { box-sizing: border-box; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; text-wrap: balance; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- Botones y campos ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px;
  border-radius: 8px; border: 1px solid transparent; background: var(--primary); color: var(--on-accent);
  font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--primary-hover); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.ghost:hover { background: var(--surface-alt); }
.btn.danger { background: var(--danger); } .btn.danger:hover { background: var(--danger-hover); }
.btn.success { background: var(--success); } .btn.success:hover { filter: brightness(.92); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.block { width: 100%; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-weight: 600; font-size: 13px; }
.input { height: 38px; padding: 0 10px; border-radius: 8px; border: 1.5px solid var(--border); background: var(--surface-alt); width: 100%; }
.input:focus { border-color: var(--primary); outline: none; }
.input:disabled { opacity: .6; }
.field.err .input { border-color: var(--danger); }
.field .msg { color: var(--danger); font-size: 12px; min-height: 16px; }
textarea.input { height: auto; padding: 8px 10px; font: 12px/1.5 var(--mono); resize: vertical; }
.general { font-size: 13px; min-height: 18px; }
.general.bad { color: var(--danger); } .general.ok { color: var(--success); }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--primary); }
.seg { display: inline-flex; background: var(--surface-alt); border-radius: 8px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 5px 12px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.seg button.on { background: var(--primary); color: var(--on-accent); }

/* ---------- Acceso ---------- */
.auth { display: grid; grid-template-columns: 5fr 6fr; min-height: 100%; }
.brand { --b-fondo: #0B0E13; --b-sup: #161C26; --b-azul: #2F7FC1; --b-azul2: #5AA7E6; --b-texto: #A9B4C4;
  background: radial-gradient(120% 70% at 85% 10%, rgba(47,127,193,.22), transparent 60%), radial-gradient(90% 60% at 0% 100%, rgba(47,127,193,.12), transparent 60%), var(--b-fondo);
  color: #FFFFFF; display: flex; flex-direction: column; padding: 40px 48px 28px; position: relative; border-right: 3px solid var(--b-azul); min-width: 0; }
.brand .marca { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 19px; letter-spacing: -.2px; }
.brand-centro { margin: auto 0; max-width: 460px; padding-block: 32px; }
.brand .logo-grande { display: block; margin-bottom: 18px; filter: drop-shadow(0 14px 30px rgba(47,127,193,.35)); }
.brand .eyebrow { color: var(--b-azul2); font-size: 12px; font-weight: 700; letter-spacing: 1.6px; text-transform: uppercase; }
.brand h1 { font-size: 34px; line-height: 1.15; letter-spacing: -.6px; margin: 8px 0 12px; }
.brand .lema { color: var(--b-texto); font-size: 15px; margin: 0 0 26px; opacity: 1; }
.brand ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 14px; }
.brand li { display: flex; align-items: center; gap: 14px; }
.brand li b { display: block; font-size: 14.5px; } .brand li small { display: block; color: var(--b-texto); font-size: 12.5px; }
.rasgo-ic { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; flex: none; font-size: 17px;
  background: var(--b-sup); border: 1px solid rgba(90,167,230,.25); }
.brand .ver { color: #6B7686; font-size: 12px; }
.auth-side { display: grid; place-items: center; padding-block: 32px; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.panel { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px 30px; display: grid; gap: 10px; }
.panel h2 { font-size: 26px; letter-spacing: -.3px; }
.panel h2::before { content: ""; display: block; width: 48px; height: 4px; border-radius: 2px; background: var(--primary); margin-bottom: 14px; }
.hint { background: var(--surface-alt); border-radius: 8px; padding: 8px 12px; font-size: 12.5px; }

/* ---------- Estructura ---------- */
.shell { display: grid; grid-template-columns: 230px 1fr; height: 100%; }
.side { background: var(--sidebar); display: flex; flex-direction: column; padding: 22px 12px 16px; gap: 2px; overflow-y: auto; }
.side .logo { font-size: 20px; font-weight: 700; padding: 0 6px; display: flex; align-items: center; gap: 8px; }
.side .who { color: var(--muted); font-size: 12px; padding: 0 6px 12px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.nav { display: flex; align-items: center; gap: 12px; height: 40px; padding: 0 12px; border-radius: 8px; border: 0; background: transparent;
  text-align: left; cursor: pointer; font-size: 14px; width: 100%; }
.nav:hover { background: var(--sidebar-active); }
.nav.on { background: var(--sidebar-active); font-weight: 700; }
.nav .ic { width: 20px; text-align: center; }
.nav .badge { margin-left: auto; background: var(--danger); color: var(--on-accent); font-size: 11px; font-weight: 700; border-radius: 99px; padding: 1px 7px; }
.side .bottom { margin-top: auto; display: grid; gap: 2px; padding-top: 12px; }
.side .bottom .nav { color: var(--muted); font-size: 13px; height: 34px; }
.demo-chip { font-size: 11px; color: var(--muted); text-align: center; padding-top: 8px; }
main { overflow-y: auto; padding-block: 22px; padding-left: 28px; padding-right: max(28px, env(safe-area-inset-right, 0px)); min-width: 0; }
.head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.head h1 { font-size: 26px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.card-pad { padding: 16px; }
.sec-title { font-size: 15px; font-weight: 700; }
.stack { display: grid; gap: 12px; }

/* ---------- Tarjetas de estadística ---------- */
.stats { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; }
.stat { padding: 14px 16px; }
.stat .lbl { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }
.stat .val { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats.three { grid-template-columns: repeat(3, 1fr); }

/* ---------- Tablas ---------- */
.table-wrap { overflow: auto; border-radius: var(--r); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { background: var(--head); text-align: left; padding: 8px 10px; font-weight: 700; position: sticky; top: 0; white-space: nowrap; }
td { padding: 7px 10px; border-top: 1px solid transparent; }
tbody tr:nth-child(even) td { background: var(--row-alt); }
tbody tr.sel td { background: var(--primary); color: var(--on-accent); }
tbody tr[data-id] { cursor: pointer; }
tbody tr:not(.sel)[data-id]:hover td { background: var(--surface-alt); }
td.c, th.c { text-align: center; }
tr.danger:not(.sel) td { color: var(--danger); } tr.warn:not(.sel) td { color: var(--warning); } tr.ok:not(.sel) td { color: var(--success); }
.empty { padding: 36px 12px; text-align: center; color: var(--muted); }
.tbl-card { padding: 6px; }

/* ---------- Vistas ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; padding: 12px; margin-bottom: 12px; }
.toolbar .grow { flex: 1 1 240px; min-width: 0; }
.toolbar .mini label { font-size: 11px; color: var(--muted); font-weight: 400; }
.toolbar select.input { height: 34px; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 270px; gap: 12px; align-items: start; }
.detail { padding: 16px; display: flex; flex-direction: column; gap: 8px; min-height: 320px; }
.detail h3 { font-size: 16px; }
.detail .actions { margin-top: auto; display: grid; gap: 6px; padding-top: 10px; }
.foot { color: var(--muted); font-size: 12px; margin-top: 8px; }
.dash { display: grid; grid-template-columns: 3fr 2fr; gap: 12px; margin-top: 16px; }
.list-row { display: flex; justify-content: space-between; gap: 10px; padding: 4px 0; }
.list-row b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.cols2 { display: grid; grid-template-columns: 2fr 3fr; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
.code { font: 11.5px var(--mono); color: var(--muted); overflow-wrap: anywhere; }

/* Vista previa del informe (como el PDF) */
.paper { background: #FFFFFF; color: #1B2330; border-radius: 6px; padding: 28px 30px; box-shadow: var(--shadow); max-height: 560px; overflow: auto; }
.paper h2 { color: #1F538D; font-size: 15px; margin: 18px 0 6px; }
.paper .ttl { color: #1F538D; font-size: 26px; font-weight: 800; text-align: center; border-top: 2px solid #1F538D; padding-top: 14px; }
.paper .sub { text-align: center; color: #5B6573; margin-bottom: 12px; }
.paper table { font-size: 11.5px; }
.paper th { background: #1F538D; color: #FFFFFF; position: static; }
.paper td { border: 1px solid #C9D3E0; background: #FFFFFF; }
.paper tbody tr:nth-child(even) td { background: #EAF1FB; }
.paper .note { color: #5B6573; font-style: italic; }

/* ---------- Modal y aviso ---------- */
.overlay { position: fixed; inset: 0; background: var(--overlay); display: grid; place-items: center; z-index: 50;
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); padding-block: 16px; }
.modal { background: var(--bg); border-radius: 14px; box-shadow: var(--shadow); width: min(var(--w, 560px), 100%); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; border: 1px solid var(--border); }
.modal header { padding: 20px 22px 6px; } .modal header h2 { font-size: 20px; }
.modal .body { padding: 8px 22px; overflow: auto; min-height: 0; overscroll-behavior: contain; display: grid; gap: 6px; }
.modal footer { padding: 12px 22px 18px; display: grid; gap: 8px; }
.modal footer .row { justify-content: flex-end; }
.fgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 16px; }
.fgrid .full { grid-column: 1 / -1; }
.toast { position: fixed; right: max(18px, calc(env(safe-area-inset-right, 0px) + 18px)); bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
  background: var(--success); color: var(--on-accent); padding: 10px 18px; border-radius: 10px; font-weight: 600; z-index: 60; box-shadow: var(--shadow); max-width: min(520px, calc(100% - 36px)); }
.toast.error { background: var(--danger); } .toast.info { background: var(--primary); } .toast.warn { background: var(--warning); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) { .stats { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 860px) {
  .auth { grid-template-columns: 1fr; } .brand { padding: calc(env(safe-area-inset-top, 0px) + 22px) 16px 20px; }
  .brand { border-right: 0; border-bottom: 3px solid var(--b-azul); padding-inline: 20px; } .brand-centro { padding-block: 18px 4px; } .brand .logo-grande { width: 84px; height: 84px; margin-bottom: 12px; } .brand h1 { font-size: 24px; } .brand .lema { margin-bottom: 8px; font-size: 14px; } .brand ul, .brand .ver { display: none; } .brand .marca { display: none; }
  .auth-side { place-items: start center; padding-top: 16px; padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 24px); }
  .panel { padding: 22px 18px; }
  .shell { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  main { grid-row: 1; padding-top: calc(env(safe-area-inset-top, 0px) + 16px); padding-bottom: 20px;
    padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
  /* Menú como barra inferior (se desliza si no caben todas las opciones) */
  .side { grid-row: 2; flex-direction: row; align-items: stretch; overflow-x: auto; gap: 0; border-top: 1px solid var(--border);
    padding: 4px max(6px, env(safe-area-inset-left, 0px)) calc(env(safe-area-inset-bottom, 0px) + 4px); scrollbar-width: none; }
  .side::-webkit-scrollbar { display: none; }
  .side .logo, .side .who, .demo-chip { display: none; }
  .nav { flex-direction: column; justify-content: center; gap: 1px; width: auto; min-width: 68px; height: 54px; padding: 0 6px; font-size: 11px; position: relative; }
  .nav .ic { font-size: 19px; width: auto; }
  .nav .badge { position: absolute; top: 3px; right: 10px; margin: 0; }
  .side .bottom { margin: 0; padding: 0; display: flex; }
  .side .bottom .nav { height: 54px; font-size: 11px; }
  .split, .dash, .cols2, .grid2 { grid-template-columns: minmax(0, 1fr); }
  .shell { height: 100%; overflow: hidden; } main { overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .detail { min-height: 0; }
  .toast { left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom, 0px) + 74px); max-width: none; }
  .input, .btn { min-height: 42px; } .input { font-size: 16px; }   /* 16px: el teclado de iPhone no hace zoom */
  .modal { max-height: calc(100dvh - 32px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)); }
}
@media (max-width: 520px) { .stats, .stats.three { grid-template-columns: repeat(2, 1fr); } .fgrid { grid-template-columns: 1fr; } .head h1 { font-size: 22px; } }
@media (prefers-reduced-motion: no-preference) { .modal { animation: pop .14s ease-out; } @keyframes pop { from { transform: translateY(8px); opacity: .6; } } }

/* ---------- Agregados: cuentas, seguridad, instalación ---------- */
.small { font-size: 12.5px; }
.panel p { margin: 0 0 4px; }
.btn.big { height: 44px; font-size: 15px; }
.btn.light { background: #FFFFFF; color: #1F6AA5; } .btn.light:hover { background: #E8F1FA; }
.btn.cargando { opacity: .7; cursor: progress; }
.btn.grow1 { flex: 1 1 140px; }
.row.end { justify-content: flex-end; }
label.btn { cursor: pointer; }
.link { background: none; border: 0; padding: 0; color: var(--primary); font-weight: 700; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.links { text-align: center; font-size: 13.5px; }
.check.small { font-size: 13px; }
.check span { min-width: 0; }
.field .check { font-weight: 400; font-size: 13.5px; }
.codigo { font: 700 26px/1.2 var(--mono); letter-spacing: 2px; text-align: center; background: var(--surface-alt); border: 1px dashed var(--border);
  border-radius: 12px; padding: 18px 8px; user-select: all; overflow-wrap: anywhere; }
.lema { opacity: .85; font-size: 16px; }
.instalar-auth { margin-top: 18px; }
.oculto { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.peligro { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.legal-t { font-size: 14px; margin: 12px 0 2px; } .legal-p { margin: 0; color: var(--muted); }
.modal ol { margin: 4px 0; padding-left: 20px; display: grid; gap: 6px; }
.informe-wrap { margin-top: 16px; }
.cargando-app, .noscript { padding: 40px; text-align: center; color: var(--muted); }
.side .logo img { border-radius: 6px; }

/* ---------- Guardar como PDF (imprimir solo el informe) ---------- */
@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #FFFFFF; }
  body * { visibility: hidden; }
  .paper, .paper * { visibility: visible; }
  .paper { position: absolute; left: 0; top: 0; width: 100%; max-height: none; overflow: visible; box-shadow: none; padding: 0; }
  .paper th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .paper tbody tr:nth-child(even) td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .toast, #modal-root { display: none !important; }
}
