/* =========================================================
   Kippo — Design System (CSS)
   Facturación electrónica SRI · Ecuador
   Fuentes: Plus Jakarta Sans (títulos/KPIs) + Inter (UI)
   ========================================================= */

/* ---------- 0. Fuentes (Google Fonts en index.html) ---------- */

/* ---------- 1. Tokens ---------- */
:root {
  /* Marca KIPPO */
  --brand-ink: #0F172A;
  --brand-ink-dark: #1E293B;
  --brand-success: #10B981;
  --brand-success-dark: #059669;
  --brand-accent: #F97316;
  --brand-accent-dark: #EA580C;

  /* Compatibilidad con estilos existentes */
  --primary: var(--brand-accent);
  --line: #E2E8F0;

  /* Superficies / neutros */
  --bg-app: #F8FAFC;
  --surface: #FFFFFF;
  --border: #E2E8F0;
  --border-strong: #CBD5E1;
  --text-primary: #0F172A;
  --text-secondary: #64748B;
  --text-muted: #94A3B8;

  /* Estados semánticos SRI */
  --ok-bg: #ECFDF5;    --ok-text: #047857;    --ok-line: #A7F3D0;
  --pend-bg: #FFF7ED;  --pend-text: #C2410C;  --pend-line: #FED7AA;
  --borr-bg: #FFFBEB;  --borr-text: #92400E;  --borr-line: #FCD34D;
  --err-bg: #FEF2F2;   --err-text: #B91C1C;   --err-line: #FECACA;

  /* Geometría */
  --r-card: 12px;
  --r-ctl: 8px;
  --r-full: 9999px;

  /* Elevación mínima */
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08);

  /* Layout */
  --sidebar-w: 240px;
  --topbar-h: 64px;

  /* Tipografía */
  --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
  --font-display: 'Plus Jakarta Sans', 'Inter', sans-serif;
}

/* ---------- 2. Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; padding: 0; }
a { color: var(--brand-accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 {
  font-family: var(--font-display);
  letter-spacing: -0.02em;
  color: var(--brand-ink);
  margin: 0;
}
h1 { font-size: 24px; font-weight: 800; }
h2 { font-size: 19px; font-weight: 700; }
h3 { font-size: 16px; font-weight: 700; }
p  { margin: 0; }

/* Regla obligatoria: números alineados */
.num, .money, .kpi, .tabular,
td.num, th.num, .clave, .ident, .sec {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}
.money, .kpi-value { font-variant-numeric: tabular-nums; }

.boot {
  display: grid; place-items: center; height: 100vh;
  color: var(--text-secondary); font-family: var(--font-display);
}

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

.sidebar {
  position: fixed; inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--brand-ink);
  color: #CBD5E1;
  display: flex; flex-direction: column;
  z-index: 40;
  overflow-y: auto;
}
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
  display: flex; flex-direction: column;
}
.content {
  padding: 24px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  flex: 1;
}

/* ---------- 4. Sidebar ---------- */
.brand {
  display: flex; align-items: center; gap: 10px;
  height: var(--topbar-h);
  padding: 0 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}
.brand-logo {
  width: 32px; height: 32px; flex-shrink: 0;
}
.brand-name {
  font-family: var(--font-display);
  font-weight: 800; font-size: 20px;
  color: #fff; letter-spacing: -0.03em;
}
.brand-tag {
  font-size: 10px; color: #64748B; line-height: 1.2;
}

.nav-cta { padding: 16px; }
.nav-section { padding: 8px 12px; }
.nav-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em;
  color: #64748B; padding: 8px 8px 4px; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; margin-bottom: 2px;
  border-radius: var(--r-ctl);
  color: #CBD5E1; font-size: 13.5px; font-weight: 500;
  width: 100%; text-align: left; cursor: pointer;
  transition: background .15s, color .15s;
}
.nav-item svg { width: 18px; height: 18px; stroke-width: 1.75; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; text-decoration: none; }
.nav-item.active {
  background: rgba(249, 115, 22, 0.22);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--brand-accent);
}
.nav-item .count {
  margin-left: auto; font-size: 11px;
  background: rgba(255,255,255,0.1); color: #E2E8F0;
  padding: 1px 7px; border-radius: var(--r-full);
  font-variant-numeric: tabular-nums;
}
.sidebar-footer {
  margin-top: auto; padding: 14px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 11px; color: #64748B;
}

/* ---------- 5. Topbar ---------- */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 30;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.user-chip {
  display: flex; align-items: center; gap: 9px;
  padding: 5px 9px; border-radius: var(--r-ctl);
  transition: background .15s;
}
.user-chip:hover { background: var(--bg-app); }
.avatar {
  width: 30px; height: 30px; border-radius: var(--r-full);
  background: linear-gradient(135deg, var(--brand-accent), var(--brand-success));
  color: #fff; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; font-family: var(--font-display);
}
.user-meta { line-height: 1.15; text-align: left; }
.user-meta .nm { font-size: 13px; font-weight: 600; }
.user-meta .rl { font-size: 11px; color: var(--text-secondary); }

/* ---------- 6. Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 14px;
  border-radius: var(--r-ctl);
  font-size: 13.5px; font-weight: 500;
  border: 1px solid transparent;
  transition: background .15s, border .15s, color .15s, transform .05s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn svg { width: 17px; height: 17px; stroke-width: 1.75; }

.btn-cta {                          /* Terracota — acción principal */
  background: var(--brand-accent);
  color: #fff; width: 100%;
  font-weight: 600; height: 42px;
}
.btn-cta:hover { background: var(--brand-accent-dark); }

.btn-primary { background: var(--brand-ink); color: #fff; }
.btn-primary:hover { background: var(--brand-ink-dark); }

.btn-success { background: var(--brand-success); color: #fff; }
.btn-success:hover { background: var(--brand-success-dark); }

.btn-secondary { background: #fff; color: var(--text-primary); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--bg-app); }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-app); color: var(--text-primary); }

.btn-danger { background: #fff; color: var(--err-text); border-color: var(--err-line); }
.btn-danger:hover { background: var(--err-bg); }

.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn-icon { width: 34px; height: 34px; padding: 0; }
.table .btn-icon { width: 30px; height: 30px; color: var(--text-secondary); }
.table .btn-icon:hover { background: var(--bg-app); color: var(--brand-accent); }
.table .btn-icon.danger:hover { background: var(--err-bg); color: var(--err-text); }

/* ---------- 7. Tarjetas ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-xs);
}
.card-pad { padding: 20px; }
.card-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.card-header h3 { font-family: var(--font-display); }
.card-body { padding: 20px; }

/* ---------- 8. KPIs ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: 18px;
  box-shadow: var(--shadow-xs);
}
.kpi-label {
  font-size: 12px; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: .04em; font-weight: 600;
}
.kpi-value {
  font-family: var(--font-display);
  font-size: 26px; font-weight: 800;
  color: var(--brand-ink);
  letter-spacing: -0.02em;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}
.kpi-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.kpi.up .kpi-value { color: var(--brand-success-dark); }
.kpi.electric .kpi-value { color: var(--brand-accent); }

/* ---------- 9. Tablas ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th {
  text-align: left; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-secondary);
  padding: 11px 16px;
  background: var(--bg-app);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.tbl td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.tbl tbody tr:hover { background: #F8FAFC; }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl .num, .tbl .money { text-align: right; font-variant-numeric: tabular-nums; }
.tbl .actions { text-align: right; white-space: nowrap; }
.tbl .mono {
  font-variant-numeric: tabular-nums;
  font-size: 12.5px; color: var(--text-secondary);
}
.tbl-empty { text-align: center; padding: 48px 20px; }
.tbl-empty .ico {
  width: 52px; height: 52px; margin: 0 auto 14px;
  background: var(--bg-app); border-radius: var(--r-full);
  display: grid; place-items: center; color: var(--text-muted);
}
.tbl-empty h4 { font-family: var(--font-display); margin-bottom: 6px; }
.tbl-empty p { color: var(--text-secondary); font-size: 13.5px; max-width: 380px; margin: 0 auto; }

/* ---------- 10. Badges (estados SRI) ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: var(--r-full);
  padding: 2.5px 10px;
  font-size: 11.5px; font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge .dot {
  width: 6px; height: 6px; border-radius: var(--r-full);
  background: currentColor; flex-shrink: 0;
}
.badge-autorizado  { background: var(--ok-bg);   color: var(--ok-text);   border-color: var(--ok-line); }
.badge-pendiente   { background: var(--pend-bg); color: var(--pend-text); border-color: var(--pend-line); }
.badge-borrador    { background: var(--borr-bg); color: var(--borr-text); border-color: var(--borr-line); }
.badge-rechazado   { background: var(--err-bg);  color: var(--err-text);  border-color: var(--err-line); }
.badge-anulada     { background: var(--err-bg);  color: var(--err-text);  border-color: var(--err-line); }
.badge-neutral     { background: var(--bg-app);  color: var(--text-secondary); border-color: var(--border); }

/* ---------- 11. Formularios ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 12.5px; font-weight: 600; color: var(--text-secondary);
}
.field .req { color: var(--err-line); }
.field input, .field select, .field textarea {
  height: 40px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-ctl);
  padding: 0 12px;
  font-size: 13.5px;
  transition: border .15s, box-shadow .15s;
  width: 100%;
}
.field textarea { height: auto; min-height: 76px; padding: 10px 12px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--brand-accent);
  box-shadow: 0 0 0 3px rgba(249,115,22,0.25);
}
.field input.num, .field .num { font-variant-numeric: tabular-nums; }
.field .hint { font-size: 11.5px; color: var(--text-muted); }
.cliente-duplicado-aviso,
.campo-error {
  display: none; margin-top: 6px; padding: 7px 9px;
  border: 1px solid var(--err-line); background: var(--err-bg);
  color: var(--err-text); border-radius: 6px; font-size: 12px; line-height: 1.4;
}
.input-error {
  border-color: var(--err-line) !important;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12) !important;
}
/* Validaciones de login y usuarios: mensaje visible + campo señalado */
.form-error {
  display: block; padding: 9px 11px; margin: 2px 0;
  border: 1px solid var(--err-line); background: var(--err-bg);
  color: var(--err-text); border-radius: 8px;
  font-size: 12.5px; line-height: 1.45;
}
.form-error[hidden] { display: none; }
.field.is-invalid > input,
.field.is-invalid > select,
.field.is-invalid > textarea {
  border-color: var(--err-line) !important;
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.12) !important;
}
.field.is-invalid > label { color: var(--err-text); }
.field.span-2 { grid-column: span 2; }
@media (max-width: 640px) { .field.span-2 { grid-column: span 1; } }

/* ---------- 12. Page header ---------- */
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.page-head .titles h1 { font-size: 22px; }
.page-head .titles p { color: var(--text-secondary); font-size: 13.5px; margin-top: 3px; }
.page-head .acts { display: flex; gap: 10px; flex-wrap: wrap; }
.page-head-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- 13. Filtros / tabs ---------- */
.tabs {
  display: inline-flex; gap: 4px;
  background: var(--bg-app); border: 1px solid var(--border);
  border-radius: var(--r-ctl); padding: 4px;
}
.tab {
  padding: 6px 14px; border-radius: 6px;
  font-size: 13px; font-weight: 500; color: var(--text-secondary);
  transition: background .15s, color .15s;
}
.tab:hover { color: var(--text-primary); }
.tab.active { background: #fff; color: var(--brand-accent); box-shadow: var(--shadow-xs); font-weight: 600; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.filters input, .filters select {
  height: 36px; border: 1px solid var(--border-strong);
  border-radius: var(--r-ctl); padding: 0 11px; font-size: 13px;
  background: #fff;
}
.filters input:focus, .filters select:focus {
  outline: none; border-color: var(--brand-accent);
  box-shadow: 0 0 0 3px rgba(249,115,22,0.25);
}

/* ---------- 14. Login ---------- */
/* La pantalla de acceso comparte el viewport con el pie legal: el pie queda
   fijo abajo y el contenido nunca lo empuja fuera de la pantalla. */
body:has(.login-screen) {
  height: 100vh; height: 100dvh;
  overflow: hidden;
  display: flex; flex-direction: column;
}
body:has(.login-screen) #root {
  flex: 1 1 auto; min-height: 0; overflow-y: auto;
}
body:has(.login-screen) .legal-footer { flex: 0 0 auto; }

.login-screen {
  min-height: 100%;
  display: grid; place-items: center;
  background:
    radial-gradient(1000px 500px at 15% -10%, rgba(249,115,22,0.16), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(16,185,129,0.14), transparent 60%),
    var(--bg-app);
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-sm);
  padding: 32px;
}
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.login-brand .nm {
  font-family: var(--font-display); font-weight: 800; font-size: 26px;
  color: var(--brand-ink); letter-spacing: -0.03em;
}
.login-tag { color: var(--text-secondary); font-size: 13.5px; margin-bottom: 24px; }
.login-card h2 { font-size: 18px; margin-bottom: 4px; }
.login-card .sub { color: var(--text-secondary); font-size: 13px; margin-bottom: 20px; }
.login-form { display: flex; flex-direction: column; gap: 14px; }

/* ============================================================
   LOGIN — DARK MODE GLASSMORPHISM
   Estilo exacto, aplicado solo a la vista de acceso.
   ============================================================ */
html:has(.login-dark),
body:has(.login-dark) {
  background:
    radial-gradient(600px 600px at 0% 0%, rgba(234, 88, 12, 0.08) 0%, transparent 70%),
    radial-gradient(600px 600px at 100% 100%, rgba(16, 185, 129, 0.10) 0%, transparent 70%),
    #070b14;
  background-attachment: fixed;
}
body:has(.login-dark) ::selection { background: #f97316; color: #fff; }

/* El pie legal deja de ser una banda aparte: se integra sobre el fondo del login */
body:has(.login-dark) {
  display: block;
  height: 100vh; height: 100dvh;
  overflow: hidden;
}
body:has(.login-dark) #root {
  height: 100vh; height: 100dvh;
  max-height: none;
  flex: 0 0 auto;
  overflow-y: auto;
}

/* 1. Fondo: azul marino casi negro, sin cuadrícula */
.login-screen.login-dark {
  width: 100%; min-height: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 16px 16px 56px; position: relative;
  overflow: hidden; isolation: isolate;

  background: transparent;

  font-family: Inter, Roboto, system-ui, -apple-system, sans-serif;
  color: #ffffff;
}
body:has(.login-dark) .login-screen.login-dark { padding: 16px 16px 56px; }

/* 1b. Glows gigantes difuminados, sin divs nuevos */
.login-screen.login-dark::before,
.login-screen.login-dark::after {
  content: ""; position: absolute;
  width: 600px; height: 600px;
  border-radius: 9999px;
  filter: blur(120px);
  pointer-events: none; z-index: 0;
}
.login-screen.login-dark::before {
  top: -300px; left: -300px;
  background: rgba(234, 88, 12, 0.20); /* #ea580c al 20% */
}
.login-screen.login-dark::after {
  bottom: -300px; right: -300px;
  background: rgba(16, 185, 129, 0.20); /* #10b981 al 20% */
}

/* 2. Soporte: botón secundario del mismo tamaño que "Ingresar", más sutil */
.login-screen.login-dark .login-support {
  position: relative; z-index: 2;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; box-sizing: border-box;
  margin-top: 8px; padding: 11px 16px;

  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;

  color: #cbd5e1; font-size: 0.875rem; font-weight: 600;
  text-decoration: none; white-space: nowrap;
  transition: background .2s ease, border-color .2s ease, color .2s ease;
}
.login-screen.login-dark .login-support svg {
  width: 14px; height: 14px; flex: 0 0 auto; color: #94a3b8;
}
.login-screen.login-dark .login-support span { color: #cbd5e1; }
.login-screen.login-dark .login-support-num {
  color: #94a3b8; font-variant-numeric: tabular-nums; font-weight: 600;
}
.login-screen.login-dark .login-support:hover {
  background: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.2);
  color: #ffffff;
}

/* 3. Tarjeta central: borde degradado naranja → verde + glassmorphism */
.login-screen.login-dark .login-card {
  position: relative; z-index: 2;
  width: 100%; max-width: 420px;
  margin-top: 0;
  padding: 32px;

  border: 1px solid transparent;
  border-radius: 16px;
  background:
    linear-gradient(rgba(17, 22, 37, 0.8), rgba(17, 22, 37, 0.8)) padding-box,
    linear-gradient(135deg, rgba(249, 115, 22, 0.7) 0%, rgba(16, 185, 129, 0.7) 100%) border-box;

  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  color: #ffffff;
  font-family: Inter, Roboto, system-ui, -apple-system, sans-serif;
}

/* 4. Tipografía */
.login-screen.login-dark .login-head {
  display: flex; flex-direction: column; align-items: center;
  text-align: center; margin-bottom: 32px;
}
.login-screen.login-dark .login-brand {
  display: flex; align-items: center; justify-content: center;
  gap: 10px; margin-bottom: 0;
}
.login-screen.login-dark .login-brand-nm {
  color: #ffffff; font-family: Inter, system-ui, sans-serif;
  font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1;
}
.login-screen.login-dark .login-logo { width: 46px; height: 46px; }
.login-screen.login-dark .login-tag {
  color: #9ca3af; margin: 8px 0 0; font-size: 13px; line-height: 1.35;
}
.login-screen.login-dark h2 {
  margin: 20px 0 8px; color: #ffffff;
  font-size: 1.5rem; font-weight: 700; line-height: 1.25;
  letter-spacing: -0.02em;
}
.login-screen.login-dark .sub { margin: 0; font-size: 14px; color: #9ca3af; }

/* 5. Inputs */
.login-screen.login-dark .field label {
  display: block; margin-bottom: 8px; text-align: left;
  font-size: 0.875rem; font-weight: 500; color: #9ca3af;
}
.login-screen.login-dark .field input {
  width: 100%; height: auto; min-height: 0; box-sizing: border-box;
  padding: 12px 16px;
  border: 1px solid rgba(75, 85, 99, 0.4);
  border-radius: 8px;
  background: rgba(30, 37, 57, 0.5);
  color: #ffffff; font-size: 0.875rem;
  transition: border-color .2s ease, box-shadow .2s ease, background .2s ease;
}
.login-screen.login-dark .field input::placeholder { color: #6b7280; }
.login-screen.login-dark .field input:focus {
  outline: none !important;
  border-color: rgba(249, 115, 22, 0.8) !important;
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.20) !important;
  background: rgba(30, 37, 57, 0.7);
}
.login-screen.login-dark .field.is-invalid > input {
  border-color: rgba(249, 115, 22, 0.9) !important;
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.20) !important;
}
.login-screen.login-dark .field.is-invalid > label { color: #fca5a5; }
.login-screen.login-dark .form-error {
  background: rgba(249, 115, 22, 0.12);
  border-color: rgba(249, 115, 22, 0.45);
  color: #fca5a5;
}

/* Recordarme: la sesión persistente es opt-in del usuario. */
.login-screen.login-dark .login-checkbox {
  display: flex; align-items: center; gap: 8px;
  margin-top: -2px;
  font-size: 0.8125rem; color: #9ca3af; cursor: pointer;
}
.login-screen.login-dark .login-checkbox input {
  width: 15px; height: 15px; margin: 0;
  accent-color: #f97316; cursor: pointer;
}

/* 6. Botón principal */
.login-screen.login-dark .btn-cta {
  width: 100%; height: auto; margin-top: 8px; box-sizing: border-box;
  padding: 12px 16px;
  border: 0; border-radius: 8px;
  background: #f97316; color: #ffffff;
  font-size: 0.875rem; font-weight: 700;
  box-shadow: 0 4px 20px rgba(249, 115, 22, 0.25);
  cursor: pointer;
  transition: background .25s ease, box-shadow .25s ease, transform .1s ease;
}
.login-screen.login-dark .btn-cta:hover {
  background: #ea580c !important; opacity: 1;
  box-shadow: 0 6px 22px rgba(234, 88, 12, 0.35);
}
.login-screen.login-dark .btn-cta:active { transform: translateY(1px); }

/* 7. Pie legal integrado, sin corte ni franja blanca */
body:has(.login-dark) .legal-footer {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  margin: 0; padding: 0 16px 14px;
  text-align: center; font-size: 12px;
  color: rgba(156, 163, 175, 0.75);
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  -webkit-backdrop-filter: none !important; backdrop-filter: none !important;
}
body:has(.login-dark) .legal-footer a {
  color: rgba(156, 163, 175, 0.75); transition: color .2s ease;
}
body:has(.login-dark) .legal-footer a:hover { color: #d1d5db; }

/* ---------- 15. Modal ---------- */
.modal-wrap {
  position: fixed; inset: 0; z-index: 100;
  display: none;
  background: rgba(15,23,42,0.62);
  backdrop-filter: blur(2px);
  padding: 24px; overflow-y: auto;
}
.modal-wrap.open { display: grid; place-items: center; }
.modal {
  background: var(--surface);
  border-radius: var(--r-card);
  border: 1px solid var(--border);
  box-shadow: 0 20px 50px rgba(15,23,42,0.25);
  width: 100%; max-width: 560px;
  max-height: calc(100vh - 48px);
  display: flex; flex-direction: column;
  animation: modalIn .16s ease-out;
}
.modal-lg { max-width: 860px; }
@keyframes modalIn {
  from { opacity: 0; transform: translateY(8px) scale(.985); }
  to   { opacity: 1; transform: none; }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-family: var(--font-display); }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--border);
}

/* ---------- 16. Toasts ---------- */
.toast-wrap {
  position: fixed; right: 20px; bottom: 20px; z-index: 200;
  display: flex; flex-direction: column; gap: 10px;
  pointer-events: none;
}
.toast {
  background: var(--brand-ink); color: #fff;
  border-radius: var(--r-ctl);
  padding: 11px 16px; font-size: 13.5px;
  box-shadow: 0 8px 24px rgba(15,23,42,0.3);
  display: flex; align-items: center; gap: 9px;
  animation: toastIn .18s ease-out;
  max-width: 380px;
}
.toast.ok  { background: var(--brand-success-dark); }
.toast.error{ background: #DC2626; }
.toast.info { background: var(--brand-accent); }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ---------- 17. Misc utilidades ---------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 780px) { .grid-2 { grid-template-columns: 1fr; } }
.mt-0{margin-top:0}.mt-2{margin-top:8px}.mt-3{margin-top:12px}.mt-4{margin-top:16px}.mt-6{margin-top:24px}
.mb-2{margin-bottom:8px}.mb-3{margin-bottom:12px}.mb-4{margin-bottom:16px}.mb-6{margin-bottom:24px}
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--text-secondary); }
.text-sm { font-size: 12.5px; }
.text-xs { font-size: 11.5px; }
.fw-600 { font-weight: 600; }
.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.flex-end { display: flex; justify-content: flex-end; gap: 10px; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; }
.divider { height: 1px; background: var(--border); margin: 18px 0; border: 0; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* Alertas */
.alert {
  border-radius: var(--r-ctl); padding: 12px 14px;
  font-size: 13.5px; border: 1px solid; display: flex; gap: 10px;
}
.alert-info { background: var(--pend-bg); color: var(--pend-text); border-color: #BFDBFE; }
.alert-warn { background: var(--borr-bg); color: var(--borr-text); border-color: #FDE68A; }
.alert-ok   { background: var(--ok-bg);   color: var(--ok-text);   border-color: #A7F3D0; }
.alert-err  { background: var(--err-bg);  color: var(--err-text);  border-color: #FECACA; }

/* Checklist de progreso de comprobante */
.flow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 12.5px; }
.flow .step {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--r-full);
  background: var(--bg-app); border: 1px solid var(--border);
  color: var(--text-secondary);
}
.flow .step.done { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok-text); }
.flow .step.active { background: var(--pend-bg); border-color: var(--pend-line); color: var(--pend-text); }
.flow .sep { color: var(--text-muted); }

/* ---------- 18. Responsive ---------- */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .content { padding: 16px; }
}
.menu-toggle { display: none; }
@media (max-width: 900px) {
  .menu-toggle {
    display: grid; place-items: center;
    width: 36px; height: 36px; border-radius: var(--r-ctl);
    border: 1px solid var(--border);
  }
}

/* Scrollbar sutil */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--r-full); border: 2px solid var(--bg-app); }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
::-webkit-scrollbar-track { background: transparent; }

/* =========================================================
   19. Bloques de layout (usados por app.js / views)
   ========================================================= */

/* --- Sidebar (estructura app.js) --- */
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  height: var(--topbar-h); padding: 0 18px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}
.sidebar .brand-logo { border-radius: 8px; flex-shrink: 0; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, var(--brand-accent), var(--brand-success));
  color: #fff; display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 800; font-size: 18px;
}
.brand-text { min-width: 0; line-height: 1.15; }
.brand-text .brand-name { display: block; font-size: 18px; color: #fff; }
.brand-text .brand-tag {
  display: block; font-size: 10.5px; color: #64748B;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px;
}

.nav { padding: 6px 12px; }
.nav-grupo { margin-bottom: 4px; }
.nav-titulo {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.09em;
  color: #64748B; font-weight: 600; padding: 14px 10px 6px;
}
.nav-item .nav-icon { display: grid; place-items: center; }
.nav-icon svg { width: 18px; height: 18px; }

.sidebar-foot {
  margin-top: auto; padding: 14px;
  border-top: 1px solid rgba(255,255,255,0.08);
}
.ambiente-tag {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 10.5px; font-weight: 600; letter-spacing: .05em;
  padding: 4px 10px; border-radius: var(--r-full);
  margin-bottom: 12px;
}
.ambiente-tag .dot { width: 6px; height: 6px; border-radius: var(--r-full); background: currentColor; }
.ambiente-tag.test { background: rgba(245,158,11,.15); color: #FCD34D; }
.ambiente-tag.prod { background: rgba(16,185,129,.15); color: #6EE7B7; }

.user-box { display: flex; align-items: center; gap: 10px; }
.user-avatar {
  width: 34px; height: 34px; border-radius: var(--r-full); flex-shrink: 0;
  background: linear-gradient(135deg, var(--brand-accent), var(--brand-success));
  color: #fff; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; font-family: var(--font-display);
}
.user-info { min-width: 0; line-height: 1.2; flex: 1; }
.user-info strong {
  display: block; font-size: 12.5px; color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-info small { font-size: 10.5px; color: #64748B; text-transform: uppercase; letter-spacing: .04em; }
.sidebar-foot .btn-icon {
  width: 32px; height: 32px; display: grid; place-items: center;
  border-radius: var(--r-ctl); color: #94A3B8;
}
.sidebar-foot .btn-icon:hover { background: rgba(255,255,255,.08); color: #fff; }

/* --- Topbar extras --- */
.menu-toggle {
  width: 36px; height: 36px; display: none;
  place-items: center; border-radius: var(--r-ctl);
  border: 1px solid var(--border); color: var(--text-secondary);
}
.clock { white-space: nowrap; font-variant-numeric: tabular-nums; }

/* --- Login extras --- */
.login-brand { align-items: center; margin-bottom: 18px; }
.login-logo { border-radius: 10px; }
.login-brand-nm {
  font-family: var(--font-display); font-weight: 800; font-size: 30px;
  color: var(--brand-ink); letter-spacing: -0.03em; line-height: 1;
}
.login-card .login-tag { margin: 4px 0 0; font-size: 13px; }
.login-form .btn-cta { margin-top: 4px; }
.btn-block { width: 100%; }

/* =========================================================
   20. Dashboard
   ========================================================= */
.dash { display: flex; flex-direction: column; gap: 20px; }
.dash .alert { align-items: center; }
.dash .alert .btn { margin-left: auto; flex-shrink: 0; }

.cards-4 {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-card); padding: 18px;
  box-shadow: var(--shadow-xs);
  position: relative; overflow: hidden;
}
.stat-card::before {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 3px;
  background: var(--brand-accent);
}
.stat-card.blue::before   { background: var(--brand-accent); }
.stat-card.purple::before { background: var(--brand-ink); }
.stat-card.orange::before { background: var(--brand-accent); }
.stat-card.red::before    { background: var(--err-text); }
.stat-card.green::before  { background: var(--brand-success); }
.stat-label {
  font-size: 11.5px; font-weight: 600; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: .04em;
}
.stat-value {
  font-family: var(--font-display); font-size: 25px; font-weight: 800;
  color: var(--brand-ink); letter-spacing: -0.02em;
  margin-top: 7px; font-variant-numeric: tabular-nums;
}
.stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ---------- Tarjeta destacada del plan ---------- */
.plan-hero {
  position: relative; isolation: isolate; overflow: hidden;
  display: grid; grid-template-columns: minmax(240px, 1.05fr) minmax(420px, 1.6fr);
  gap: 18px 28px; padding: 22px 24px 18px;
  border-radius: 18px; color: #fff;
  background: linear-gradient(120deg, #0F172A 0%, #1E293B 55%, #0F172A 100%);
  box-shadow: 0 18px 40px rgba(15, 23, 42, .22);
}
.plan-hero-glow {
  position: absolute; z-index: -1; top: -45%; right: -8%;
  width: 440px; height: 440px; pointer-events: none;
  background: radial-gradient(circle, rgba(16,185,129,.30), transparent 66%);
}
.plan-hero.is-alert .plan-hero-glow {
  background: radial-gradient(circle, rgba(249,115,22,.32), transparent 66%);
}
.plan-hero-main { display: flex; align-items: flex-start; gap: 14px; min-width: 0; }
.plan-hero-icon {
  width: 52px; height: 52px; flex-shrink: 0; border-radius: 14px;
  display: grid; place-items: center; color: #F97316;
  background: rgba(249,115,22,.16); border: 1px solid rgba(249,115,22,.35);
}
.plan-hero-icon svg { width: 24px; height: 24px; }
.plan-hero-id { min-width: 0; }
.plan-eyebrow {
  font-size: 10.5px; font-weight: 700; letter-spacing: .12em;
  text-transform: uppercase; color: #94A3B8;
}
.plan-hero-name {
  font-family: var(--font-display); font-size: 23px; font-weight: 800;
  letter-spacing: -.02em; line-height: 1.15; color: #fff;
  margin: 5px 0 9px; overflow-wrap: anywhere;
}
.plan-hero-tags {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  font-size: 11.5px; color: #94A3B8; text-transform: capitalize;
}
.plan-code {
  padding: 3px 9px; border-radius: 999px; font-weight: 700; letter-spacing: .04em;
  color: #6EE7B7; background: rgba(16,185,129,.16);
  border: 1px solid rgba(16,185,129,.35);
}
.plan-modalidad::before { content: "·"; margin-right: 8px; color: #64748B; }
.plan-status {
  display: inline-flex; align-items: center; gap: 7px;
  margin-top: 14px; padding: 5px 11px; border-radius: 999px;
  font-size: 12px; font-weight: 700; border: 1px solid;
}
.plan-status i {
  width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
}
.plan-status.ok {
  color: #6EE7B7; background: rgba(16,185,129,.12);
  border-color: rgba(16,185,129,.35);
}
.plan-status.ok i { background: #10B981; box-shadow: 0 0 0 3px rgba(16,185,129,.20); }
.plan-status.err {
  color: #FDBA74; background: rgba(249,115,22,.12);
  border-color: rgba(249,115,22,.35);
}
.plan-status.err i { background: #F97316; box-shadow: 0 0 0 3px rgba(249,115,22,.20); }
.plan-hero-metrics {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px; align-self: center;
}
.plan-metric {
  min-width: 0; padding: 14px 15px; border-radius: 12px;
  background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.10);
}
.plan-metric > span {
  display: block; font-size: 10.5px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: #94A3B8;
}
.plan-metric strong {
  display: block; margin-top: 7px; font-family: var(--font-display);
  font-size: 24px; font-weight: 800; letter-spacing: -.02em;
  color: #fff; line-height: 1.1; font-variant-numeric: tabular-nums;
}
.plan-metric strong small { font-size: 14px; font-weight: 600; color: #94A3B8; }
.plan-metric strong.plan-date { font-size: 17px; }
.plan-metric em {
  display: block; margin-top: 6px; font-size: 11px; font-style: normal; color: #94A3B8;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.plan-hero-foot {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 14px;
  padding-top: 14px; border-top: 1px solid rgba(255,255,255,.09);
  font-size: 12px; color: #CBD5E1;
}
.plan-progress {
  flex: 1; height: 7px; border-radius: 99px; overflow: hidden;
  background: rgba(255,255,255,.10);
}
.plan-progress i {
  display: block; height: 100%; border-radius: 99px; transition: width .4s ease;
}
.plan-progress.ok i { background: linear-gradient(90deg, #10B981, #34D399); }
.plan-progress.warn i { background: linear-gradient(90deg, #F97316, #FB923C); }
.plan-progress.err i { background: linear-gradient(90deg, #EF4444, #F97316); }
.plan-hero-foot b { color: #fff; font-variant-numeric: tabular-nums; }
.plan-hero-alert {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; border-radius: 11px; font-size: 12.5px; color: #FED7AA;
  background: rgba(249,115,22,.12); border: 1px solid rgba(249,115,22,.30);
}
.plan-hero-alert svg { flex-shrink: 0; color: #F97316; }
.plan-hero-alert span { flex: 1; line-height: 1.4; }
.plan-hero-alert .btn {
  flex-shrink: 0; color: #fff;
  background: var(--brand-accent); border-color: var(--brand-accent);
}
.plan-hero-alert .btn:hover { background: var(--brand-accent-dark); }

/* Variante compacta para la pantalla de acceso bloqueado */
.login-screen .plan-hero {
  grid-template-columns: 1fr; gap: 14px; padding: 18px;
  margin: 16px 0; border-radius: 14px; text-align: left;
}
.login-screen .plan-hero-icon { width: 42px; height: 42px; border-radius: 12px; }
.login-screen .plan-hero-icon svg { width: 20px; height: 20px; }
.login-screen .plan-hero-name { font-size: 19px; }
.login-screen .plan-hero-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.login-screen .plan-hero.is-min .plan-metric:first-child { display: none; }
.login-screen .plan-metric { padding: 11px 12px; }
.login-screen .plan-metric strong { font-size: 19px; }
.login-screen .plan-metric strong.plan-date { font-size: 14px; }
.login-screen .plan-hero-alert { flex-wrap: wrap; }

@media (max-width: 900px) {
  .plan-hero { grid-template-columns: 1fr; padding: 20px; }
  .plan-hero-metrics { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
}

/* Paneles */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-card); box-shadow: var(--shadow-xs);
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 15px 18px; border-bottom: 1px solid var(--border);
}
.panel-head h3 { font-family: var(--font-display); font-size: 15px; }
.panel-sub { font-size: 12px; color: var(--text-secondary); text-transform: capitalize; }
.panel-body { padding: 18px; }
.panel-body.flush { padding: 0; }

/* Top clientes con barra */
.top-cliente {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 0; border-bottom: 1px dashed var(--border);
}
.top-cliente:last-child { border-bottom: none; }
.tc-info { flex: 1; min-width: 0; }
.tc-info strong {
  display: block; font-size: 13px; margin-bottom: 7px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tc-bar { height: 6px; background: var(--bg-app); border-radius: var(--r-full); overflow: hidden; }
.tc-bar i {
  display: block; height: 100%; border-radius: var(--r-full);
  background: linear-gradient(90deg, var(--brand-accent), var(--brand-success));
}
.top-cliente > span {
  font-weight: 600; font-size: 13.5px;
  font-variant-numeric: tabular-nums; color: var(--brand-ink);
}

/* Actividad */
.actividad { list-style: none; margin: 0; padding: 0; }
.actividad li {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px dashed var(--border);
  font-size: 13.5px;
}
.actividad li:last-child { border-bottom: none; }
.actividad .dot {
  width: 8px; height: 8px; border-radius: var(--r-full);
  background: var(--brand-accent); flex-shrink: 0;
}
.actividad li small { margin-left: auto; color: var(--text-muted); font-size: 11.5px; white-space: nowrap; }

/* Estados vacíos (voz Kippo) */
.empty {
  text-align: center; padding: 34px 18px;
  color: var(--text-secondary); font-size: 13.5px;
}
.empty strong { display: block; color: var(--text-primary); margin-bottom: 4px; }

/* =========================================================
   21. Modal (clases usadas por ui.js)
   ========================================================= */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15,23,42,0.62); backdrop-filter: blur(2px);
}
.modal-wrap .modal { position: relative; z-index: 2; }
.modal-wrap.open .modal { position: relative; z-index: 2; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { font-family: var(--font-display); font-size: 16px; }
.modal-x {
  width: 32px; height: 32px; border-radius: var(--r-ctl);
  display: grid; place-items: center; font-size: 20px; color: var(--text-secondary);
}
.modal-x:hover { background: var(--bg-app); color: var(--text-primary); }
.confirm-msg { font-size: 14px; color: var(--text-primary); }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* Tablas (clases usadas por views) */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-secondary); padding: 10px 14px;
  background: var(--bg-app); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.table tbody tr:hover { background: #F8FAFC; }
.table tbody tr:last-child td { border-bottom: none; }
.table .money, .table .r { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions {
  text-align: right; white-space: nowrap; width: 1%; font-size: 0;
}
.table .actions .btn-icon { display: inline-grid; vertical-align: middle; margin-left: 2px; }

/* Tabla compacta (paneles del dashboard) */
.dash-panels { grid-template-columns: 1fr 1.4fr; }
@media (max-width: 1100px) { .dash-panels { grid-template-columns: 1fr; } }
.table-compact { font-size: 12.5px; }
.table-compact th { padding: 8px 7px; font-size: 10.5px; }
.table-compact td { padding: 9px 7px; }
.table-compact .truncate {
  max-width: 120px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.table-compact .badge { font-size: 10.5px; padding: 2px 7px; gap: 4px; }
.table-compact .badge .dot { width: 5px; height: 5px; }
.mono { font-variant-numeric: tabular-nums; font-size: 12.5px; }

/* Badges extra (nombres usados por ui.js) */
.badge-ok    { background: var(--ok-bg);   color: var(--ok-text);   border-color: var(--ok-line); }
.badge-pend  { background: var(--pend-bg); color: var(--pend-text); border-color: var(--pend-line); }
.badge-borr  { background: var(--borr-bg); color: var(--borr-text); border-color: var(--borr-line); }
.badge-err   { background: var(--err-bg);  color: var(--err-text);  border-color: var(--err-line); }
.badge-info  { background: var(--pend-bg); color: var(--pend-text); border-color: var(--pend-line); }
.badge-warn  { background: var(--pend-bg); color: var(--pend-text); border-color: var(--pend-line); }
.badge-error { background: var(--err-bg);  color: var(--err-text);  border-color: var(--err-line); }
.badge-mute  { background: var(--bg-app);  color: var(--text-secondary); border-color: var(--border); }

/* Botón bloque (login/acciones) */
.btn-block { width: 100%; }

/* =========================================================
   23. Detalle de líneas (formularios de comprobantes)
   ========================================================= */
.detalle-head,
.detalle-row {
  display: grid;
  grid-template-columns: 110px minmax(180px, 1fr) 78px 108px 86px 92px 34px;
  gap: 8px;
  align-items: center;
}
.detalle-head {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-secondary);
  padding-bottom: 8px; margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.detalle-row { margin-bottom: 8px; }
.detalle-row input,
.detalle-row select {
  height: 36px; width: 100%; min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-ctl);
  padding: 0 9px; font-size: 13px;
  font-variant-numeric: tabular-nums;
  transition: border .15s, box-shadow .15s;
}
.detalle-row input:focus,
.detalle-row select:focus {
  outline: none; border-color: var(--brand-accent);
  box-shadow: 0 0 0 3px rgba(249,115,22,0.25);
}
.detalle-row input[type="number"] { text-align: right; }
.detalle-row .btn-icon { width: 34px; height: 34px; justify-self: end; color: var(--text-muted); }
.detalle-row .btn-icon:hover { background: var(--err-bg); color: var(--err-text); }

/* Nota de débito: solo descripción + valor */
.detalle-head.nd-head,
.detalle-row.nd-row { grid-template-columns: minmax(200px, 1fr) 140px 34px; }

/* Detalle exclusivo de ventas: 8 columnas */
.detalle-head.detalle-venta-head,
.detalle-row.detalle-venta {
  grid-template-columns: minmax(200px, 1.6fr) 110px 100px 80px 90px 120px 34px;
}
.detalle-row.detalle-venta input[readonly] {
  background: var(--bg-app); color: var(--text-secondary); cursor: default;
}
.detalle-row.detalle-venta input[data-k="subtotal"] {
  font-weight: 700; color: var(--brand-success-dark); text-align: right;
}

/* Buscadores instantáneos */
.live-search { position: relative; width: 100%; }
.live-search > input {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--border-strong); border-radius: var(--r-ctl);
  background: var(--surface); font-size: 13px;
}
.live-search > input:focus {
  outline: none; border-color: var(--brand-accent);
  box-shadow: 0 0 0 3px rgba(249,115,22,0.25);
}
.product-search { max-width: 420px; }
.product-search > input { height: 34px; }
.live-results {
  display: none; position: absolute; z-index: 50; top: calc(100% + 4px); left: 0; right: 0;
  max-height: 300px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--r-ctl); box-shadow: var(--shadow-md);
}
.live-results.is-open { display: block; }
.live-item {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  width: 100%; padding: 9px 12px; border: 0; border-bottom: 1px solid var(--border);
  background: transparent; text-align: left; cursor: pointer; font: inherit;
}
.live-item:last-child { border-bottom: 0; }
.live-item:hover, .live-item.is-active { background: var(--pend-bg, #FFF7ED); }
.live-item-main { font-size: 13px; font-weight: 600; color: var(--brand-ink); }
.live-item-meta { font-size: 11.5px; color: var(--text-secondary); }
.live-empty { padding: 12px; font-size: 12.5px; color: var(--text-secondary); }

/* Desplegables de notas de crédito/débito */
.panel.panel-overflow { overflow: visible; }
.factura-search .live-results { max-height: 280px; }
.extra-menu-anchor { position: relative; }
.extra-menu {
  position: absolute; z-index: 60; top: calc(100% + 8px); right: 0;
  width: 280px; padding: 8px;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--r-ctl); box-shadow: var(--shadow-md);
}
.extra-menu[hidden] { display: none; }
.extra-menu .live-results {
  position: static; max-height: 220px;
  border: 0; box-shadow: none;
}
#form-nc input[readonly], #form-nc select[disabled],
#form-nd input[readonly], #form-nd select[disabled] {
  background: var(--bg-app); color: var(--text-secondary); cursor: default;
}

/* Logo en configuración y RIDE */
.logo-preview-box {
  display: flex; align-items: center; gap: 16px;
  padding: 14px; border: 1px dashed var(--border-strong);
  border-radius: var(--r-ctl); background: var(--bg-app);
}
.logo-preview-box img { max-width: 220px; max-height: 80px; object-fit: contain; }
.ride-emisor { position: relative; }
.ride-logo { max-width: 110px; max-height: 55px; object-fit: contain; display: block; margin-bottom: 6px; }

@media (max-width: 900px) {
  .detalle-head { display: none; }
  .detalle-row,
  .detalle-row.nd-row {
    grid-template-columns: 1fr 1fr;
    padding: 12px; border: 1px solid var(--border);
    border-radius: var(--r-ctl); background: var(--bg-app);
  }
  .detalle-row input[data-k="descripcion"],
  .detalle-row select[data-k="descripcion"] { grid-column: span 2; }
}

/* Barra de totales */
.totals-bar {
  display: flex; align-items: center; justify-content: flex-end; gap: 34px;
  background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-card);
  box-shadow: var(--shadow-xs);
  padding: 14px 22px; margin: 18px 0;
  font-variant-numeric: tabular-nums;
}
.totals-bar > div { text-align: right; }
.totals-bar span {
  display: block; font-size: 11.5px; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: .04em; font-weight: 600;
}
.totals-bar strong {
  font-family: var(--font-display); font-size: 17px; font-weight: 700;
  color: var(--brand-ink);
}
.totals-bar .grand strong { font-size: 24px; color: var(--brand-success-dark); }
.totals-bar .grand span { color: var(--brand-success-dark); }

/* Acciones pegadas al final del formulario */
.sticky-actions {
  position: sticky; bottom: 0; z-index: 5;
  display: flex; justify-content: flex-end; gap: 10px;
  background: var(--bg-app);
  padding: 14px 0 4px; margin-top: 8px;
  border-top: 1px solid var(--border);
}

/* Documentos retenidos (retenciones) */
.doc-ret {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-ctl); margin-bottom: 12px;
}
.doc-ret .form-actions { margin-top: 12px; }

/* Panel de pestañas (configuración) */
.tab-panel { animation: fadeIn .14s ease-out; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* RIDE */
/* El QR lleva la URL de validez del SRI + clave (≈158 bytes → QR versión 9,
   53 módulos), así que necesita 144px para escanearse bien desde pantalla. */
.ride { font-size: 13px; position: relative; padding-right: 158px; }
.ride-qr {
  position: absolute; top: 0; right: 0;
  width: 144px;
  text-align: center;
}
.ride-qr svg { width: 144px !important; height: 144px !important; display: block; }
.ride-qr::after {
  content: "Validez en el SRI";
  display: block; margin-top: 4px;
  font-size: 9.5px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: var(--text-muted);
}
.ride-head {
  display: flex; justify-content: space-between; gap: 18px;
  padding-bottom: 12px; border-bottom: 2px solid var(--brand-ink);
  margin-bottom: 10px;
}
.ride-emisor strong { font-family: var(--font-display); font-size: 15px; color: var(--brand-ink); }
.ride-emisor, .ride-doc-info { line-height: 1.55; }
.ride-doc-info { text-align: right; white-space: nowrap; }
.ride-doc-info strong {
  font-family: var(--font-display); font-size: 14px;
  text-transform: uppercase; letter-spacing: .02em;
}
.ride-clave {
  background: var(--bg-app); border: 1px solid var(--border);
  border-radius: var(--r-ctl); padding: 8px 12px; margin-bottom: 12px;
}
.ride-clave small {
  display: block; font-size: 10px; font-weight: 700; letter-spacing: .08em;
  color: var(--text-secondary); text-transform: uppercase; margin-bottom: 3px;
}
.ride-clave .mono {
  font-size: 13.5px; font-weight: 600; color: var(--brand-ink);
  word-spacing: 2px; word-break: break-all;
}
.ride-cliente {
  padding-bottom: 12px; border-bottom: 1px solid var(--border);
  margin-bottom: 12px; line-height: 1.7;
}
.ride-cliente strong { color: var(--text-secondary); font-weight: 600; }

table.ride-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.ride-table th {
  text-align: left; font-size: 10.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-secondary);
  padding: 8px 9px; background: var(--bg-app);
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.ride-table td { padding: 8px 9px; border-bottom: 1px solid var(--border); }
.ride-table .num, .ride-table .money {
  text-align: right; font-variant-numeric: tabular-nums;
}
.ride-table tfoot td {
  font-weight: 600; background: var(--bg-app);
  border-top: 2px solid var(--brand-ink); border-bottom: none;
}
.ride-pie,
.ride-foot {
  margin-top: 14px; padding-top: 10px; border-top: 1px dashed var(--border);
  font-size: 11.5px; color: var(--text-secondary); text-align: center; line-height: 1.6;
}
.ride-foot strong, .ride-foot { color: var(--text-secondary); }

/* Totales (RIDE y reportes) */
.ride-totales {
  display: grid; gap: 6px; margin-top: 14px; padding-top: 12px;
  border-top: 1px dashed var(--border);
  font-variant-numeric: tabular-nums;
}
.ride-totales > div {
  display: flex; justify-content: space-between; gap: 16px; font-size: 13px;
}
.ride-totales .small-line { font-size: 11.5px; color: var(--text-muted); }
.ride-totales .grand {
  border-top: 1px solid var(--brand-ink); padding-top: 8px; margin-top: 4px;
  font-size: 16px; font-weight: 700; font-family: var(--font-display);
}

/* =========================================================
   24. Responsive real
   ========================================================= */
@media (max-width: 900px) {
  .menu-toggle { display: grid; }
}

/* =========================================================
   25. Retenciones — tabla de impuestos y modal de códigos
   ========================================================= */
.tabla-impuestos tbody td,
.tabla-codigos tbody td { vertical-align: middle; }

/* Encabezados con color de marca */
.tabla-impuestos thead th,
.tabla-codigos thead th,
.tabla-codigos-catalogo thead th {
  background: var(--pend-bg);
  color: var(--pend-text);
  border-bottom-color: var(--pend-line);
}
.tabla-codigos-catalogo tbody tr:hover { background: var(--bg-app); }
.tabla-codigos-catalogo td { vertical-align: middle; }
.tabla-retenciones thead th {
  background: var(--pend-bg);
  color: var(--pend-text);
  border-bottom-color: var(--pend-line);
}

/* Switch "Activo" del catálogo de códigos */
.switch-line {
  display: inline-flex; align-items: center; gap: 10px;
  margin-top: 8px; cursor: pointer;
  font-size: 13px; font-weight: 500; color: var(--text-secondary);
  user-select: none;
}
.switch-line input {
  position: absolute; opacity: 0; width: 1px; height: 1px;
}
.switch-track {
  position: relative;
  width: 40px; height: 22px;
  border-radius: var(--r-full);
  background: var(--border-strong);
  box-shadow: var(--shadow-xs);
  transition: background .18s ease;
}
.switch-dot {
  position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(15, 23, 42, .25);
  transition: transform .18s ease;
}
.switch-line input:checked + .switch-track { background: var(--brand-accent); }
.switch-line input:checked + .switch-track .switch-dot { transform: translateX(18px); }
.switch-line input:focus-visible + .switch-track { box-shadow: 0 0 0 3px rgba(249, 115, 22, .25); }
.switch-line:hover .switch-label { color: var(--text-primary); }

/* Variante verde/gris usada en Planes (activo / inactivo). */
.switch-green input:checked + .switch-track { background: #16a34a; }
.switch-green input:focus-visible + .switch-track { box-shadow: 0 0 0 3px rgba(22, 163, 74, .25); }

/* Paginador del catálogo */
.catalog-pager {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-top: 1px solid var(--border);
  background: var(--surface); font-size: 12.5px; color: var(--text-secondary);
}
.catalog-pager .pager-info { font-variant-numeric: tabular-nums; }
.catalog-pager .btn:disabled { opacity: .45; cursor: not-allowed; }
.tabla-impuestos tbody tr,
.tabla-codigos tbody tr { transition: background .15s ease; }
.tabla-impuestos tbody tr:hover,
.tabla-codigos tbody tr:hover { background: var(--bg-app); }
.tabla-impuestos tbody td { padding: 10px 12px; }

/* Controles dentro de la tabla de impuestos */
.tabla-impuestos input,
.tabla-impuestos select {
  width: 100%; height: 36px;
  padding: 0 10px;
  font: inherit; font-size: 13px;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-ctl);
  box-shadow: var(--shadow-xs);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.tabla-impuestos input:focus,
.tabla-impuestos select:focus {
  outline: none;
  border-color: var(--brand-accent);
  box-shadow: 0 0 0 3px rgba(249, 115, 22, .25);
}
.tabla-impuestos input[readonly] {
  background: var(--bg-app);
  color: var(--text-primary);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.tabla-impuestos .base-imp,
.tabla-impuestos .pct-imp { text-align: right; font-variant-numeric: tabular-nums; }
.tabla-impuestos .btn-quitar {
  width: 32px; height: 32px;
  display: inline-grid; place-items: center;
  color: var(--text-secondary);
  border-radius: var(--r-ctl);
}
.tabla-impuestos .btn-quitar:hover {
  background: var(--err-bg);
  color: var(--err-text);
}

/* Campo de código + lupa (ref. imagen 1) */
.input-group,
.ret-input-group { display: flex; align-items: center; gap: 6px; }
.input-group .cod-ret,
.ret-input-group .cod-ret { flex: 1; min-width: 0; }
.btn-lupa,
.ret-btn-lupa {
  width: 36px; height: 36px; min-width: 36px;
  display: inline-grid; place-items: center;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-ctl);
  color: var(--text-secondary); cursor: pointer;
  box-shadow: var(--shadow-xs);
  transition: border-color .15s ease, color .15s ease, background .15s ease;
}
.btn-lupa:hover,
.ret-btn-lupa:hover {
  border-color: var(--brand-accent);
  color: var(--brand-accent);
  background: var(--pend-bg);
}

/* Chip de tipo de impuesto en el modal (ref. imagen 2) */
.ret-chip {
  display: inline-block; font-size: 11.5px; font-weight: 700;
  padding: 2px 8px; border-radius: 10px;
  background: var(--pend-bg); color: var(--pend-text);
}

/* Alineación numérica */
.tabla-impuestos .ret-num,
.tabla-codigos .ret-num { text-align: right; font-variant-numeric: tabular-nums; }
.tabla-codigos td:nth-child(2) { font-variant-numeric: tabular-nums; }

/* Catálogo de códigos de retención */
.chip {
  display: inline-block; font-size: 11.5px; font-weight: 700;
  padding: 2px 8px; border-radius: 10px;
  background: var(--pend-bg); color: var(--pend-text);
}
.chip-muted { background: var(--bg-app); color: var(--text-muted); }
.chip-si {
  background: var(--ok-bg); color: var(--ok-text);
  border: 1px solid var(--ok-line);
}
.chip-no {
  background: var(--err-bg); color: var(--err-text);
  border: 1px solid var(--err-line);
}
.imp-chip {
  display: inline-block; font-size: 11.5px; font-weight: 700;
  padding: 3px 10px; border-radius: 8px;
  background: var(--pend-bg); color: var(--pend-text);
  border: 1px solid var(--pend-line);
}
.tabla-codigos-catalogo thead th.col-impuesto {
  background: #FFF7ED; color: #C2410C; border-bottom-color: #FED7AA;
}
.codigos-notice { margin-bottom: 14px; line-height: 1.5; }
.empty-cell { text-align: center; color: var(--text-muted); padding: 18px 10px; }

/* ---- Suscripción, pagos y enlaces legales ---- */
.plan-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px;
}
.plan-card {
  display: block; cursor: pointer; border: 1px solid var(--line, #E5E7EB);
  border-radius: 12px; padding: 14px; background: #fff; transition: border-color .15s, box-shadow .15s;
}
.plan-card:hover { border-color: var(--primary, var(--brand-accent)); box-shadow: 0 4px 14px rgba(249,115,22,.08); }
.plan-card:has(input:checked) {
  border-color: var(--brand-accent);
  background: var(--pend-bg);
  box-shadow: 0 0 0 3px rgba(249,115,22,.18);
}
.plan-card input { margin-right: 8px; accent-color: var(--brand-accent); }
.plan-nombre { font-weight: 700; margin: 6px 0 2px; }
.plan-precio { font-size: 20px; font-weight: 800; color: var(--primary, var(--brand-accent)); }
.plan-detalle { font-size: 12px; color: var(--text-muted, #6B7280); margin-top: 4px; }
.nota-pago { max-width: 140px; margin-right: 6px; }
.legal-footer {
  display: flex; gap: 18px; justify-content: center; align-items: center;
  padding: 14px 20px; font-size: 12px; color: var(--text-muted, #6B7280);
  border-top: 1px solid var(--line, #E5E7EB); background: #fff;
}
.legal-footer a { color: inherit; text-decoration: underline; cursor: pointer; }

/* Acceso compacto en pantallas bajas/estrechas: el pie legal no se pierde */
@media (max-height: 760px) {
  body:has(.login-screen) .login-screen { padding: 12px; }
  .login-card { padding: 20px; }
  .login-brand { margin-bottom: 12px; }
  .login-brand-nm { font-size: 26px; }
  .login-logo { width: 38px; height: 38px; }
  .login-card .login-tag { margin-bottom: 12px; }
  .login-card .sub { margin-bottom: 12px; }
  .login-form { gap: 10px; }
}
@media (max-width: 640px), (max-height: 620px) {
  .legal-footer { gap: 10px; padding: 8px 10px; font-size: 11px; flex-wrap: wrap; }
}
@media (max-height: 560px) {
  .login-card { padding: 14px; }
  .login-card h2 { font-size: 16px; }
  .login-card .sub { display: none; }
  .login-brand { margin-bottom: 8px; }
  .login-brand-nm { font-size: 22px; }
  .login-logo { width: 32px; height: 32px; }
  .login-form { gap: 8px; }
  body:has(.login-screen) .field input { height: 36px; }
  .legal-footer { padding: 6px 8px; font-size: 10px; }
}
/* Variante oscura: mantiene el pie sin scroll en pantallas bajas */
@media (max-height: 700px) {
  .login-screen.login-dark .login-card { padding: 24px; }
  .login-screen.login-dark .login-head { margin-bottom: 20px; }
  .login-screen.login-dark h2 { margin-top: 12px; font-size: 24px; }
  .login-screen.login-dark .sub { margin-top: 4px; }
  .login-screen.login-dark .login-form { gap: 8px; }
}
@media (max-height: 680px) {
  .login-screen.login-dark .login-card { padding: 12px; }
  .login-screen.login-dark .login-head { margin-bottom: 16px; }
  .login-screen.login-dark h2 { margin-top: 10px; font-size: 18px; }
  .login-screen.login-dark .login-form { gap: 6px; }
  .login-screen.login-dark .field input { padding: 8px 14px; }
  .login-screen.login-dark .btn-cta { padding: 10px 14px; }
  .login-screen.login-dark .login-support { margin-top: 6px; padding: 9px 14px; }
}
@media (max-height: 520px) {
  .login-screen.login-dark .login-card { padding: 10px; }
  .login-screen.login-dark .login-head { margin-bottom: 6px; }
  .login-screen.login-dark h2 { margin-top: 6px; font-size: 19px; }
  .login-screen.login-dark .login-tag { margin-top: 4px; font-size: 12px; }
  .login-screen.login-dark .login-brand-nm { font-size: 22px; }
  .login-screen.login-dark .login-logo { width: 32px; height: 32px; }
  .login-screen.login-dark .login-form { gap: 6px; }
  .login-screen.login-dark .field input { padding: 7px 14px; }
  .login-screen.login-dark .btn-cta { padding: 9px 14px; }
  .login-screen.login-dark .login-support { margin-top: 6px; padding: 8px 14px; font-size: 14px; }
}
.btn-ok { background: #16A34A; color: #fff; border-color: #16A34A; }
