/* ===========================================================================
   Gestión Empresa — sistema visual (v3)
   Dirección: SaaS claro y de alto contraste. Sidebar y contenido comparten
   la misma base clara (nada de chrome oscuro) — evita cualquier ajuste fino
   de contraste "texto claro sobre oscuro" y sus riesgos de legibilidad.
   Un acento violeta usado con decisión, tipografía sans única.
   =========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:ital,wght@0,400;0,500;0,600;0,700;0,800;1,500&display=swap');

:root {
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Superficies — todo claro, un solo mundo tonal */
  --bg-page: #f7f7f9;
  --bg-surface: #ffffff;
  --bg-surface-sunken: #f2f2f6;
  --bg-sidebar: #ffffff;

  /* Texto — alto contraste en todos lados, sin variantes "on-dark" */
  --text-primary: #101014;
  --text-secondary: #43434d;
  --text-tertiary: #6c6c76;
  --text-muted: #8f8f99;

  /* Bordes */
  --border: rgba(16, 16, 20, 0.10);
  --border-strong: rgba(16, 16, 20, 0.16);

  /* Acento — violeta, un solo hue, uso decidido */
  --primary-50: #f4f1fe;
  --primary-100: #e7e0fd;
  --primary-200: #cabdfa;
  --primary-500: #7c3aed;
  --primary-600: #6d28d9;
  --primary-700: #5b21b6;

  /* Semántico — vívido y legible */
  --success-500: #16a34a;
  --success-bg: #dcfce7;
  --success-text: #15803d;
  --danger-500: #e11d2f;
  --danger-bg: #fde2e2;
  --danger-text: #c31427;
  --warning-500: #d97706;
  --warning-bg: #fef1d3;
  --warning-text: #a35c07;
  --info-500: #0284c7;
  --info-bg: #e0f2fe;
  --info-text: #0369a1;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;

  --shadow-xs: 0 1px 2px rgba(16, 16, 20, 0.04);
  --shadow-sm: 0 1px 3px rgba(16, 16, 20, 0.05), 0 1px 2px rgba(16, 16, 20, 0.04);
  --shadow-md: 0 10px 24px rgba(16, 16, 20, 0.08), 0 2px 6px rgba(16, 16, 20, 0.04);
  --shadow-lg: 0 24px 56px rgba(16, 16, 20, 0.14), 0 4px 14px rgba(16, 16, 20, 0.06);

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);

  --sidebar-w: 264px;

  /* Retema Bootstrap */
  --bs-body-font-family: var(--font-sans);
  --bs-body-bg: var(--bg-page);
  --bs-body-color: var(--text-primary);
  --bs-border-color: var(--border);
  --bs-primary: var(--primary-600);
  --bs-primary-rgb: 109, 40, 217;
  --bs-link-color: var(--primary-600);
  --bs-link-hover-color: var(--primary-700);
  --bs-secondary-color: var(--text-secondary);
  --bs-success: var(--success-500);
  --bs-danger: var(--danger-500);
  --bs-warning: var(--warning-500);
  --bs-info: var(--info-500);
}

* { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; box-sizing: border-box; }

html, body { background: var(--bg-page); color: var(--text-primary); }

body { font-family: var(--font-sans); font-size: 14.5px; line-height: 1.55; letter-spacing: -0.001em; }

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-sans);
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.015em;
  text-wrap: balance;
}

a { color: var(--primary-600); text-decoration: none; transition: color .15s var(--ease-out); }
a:hover { color: var(--primary-700); }

::selection { background: var(--primary-100); color: var(--text-primary); }

:focus-visible { outline: 2px solid var(--primary-500); outline-offset: 2px; border-radius: var(--radius-sm); }

.num, td.num, .stat-value, .money { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

/* ===== Layout: sidebar + contenido ======================================= */

.app-shell { display: flex; min-height: 100vh; }

.ledger-spine {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  color: var(--text-primary);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  z-index: 40;
}

.ledger-brand { display: flex; align-items: center; gap: 11px; padding: 24px 22px 20px; }

.ledger-brand-mark {
  width: 32px; height: 32px; border-radius: 9px;
  background: var(--primary-600);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 800; font-size: 14px; flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(109, 40, 217, 0.28);
}

.ledger-brand-name { font-weight: 800; font-size: 15px; color: var(--text-primary); line-height: 1.2; letter-spacing: -0.01em; }
.ledger-brand-sub { font-size: 10.5px; color: var(--text-tertiary); letter-spacing: .04em; text-transform: uppercase; font-weight: 600; margin-top: 1px; }

.empresa-switcher {
  margin: 4px 16px 10px;
  padding: 14px 15px;
  border-radius: var(--radius-md);
  background: var(--bg-surface-sunken);
  border: 1px solid var(--border);
}

.empresa-switcher-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--text-tertiary); margin-bottom: 5px; }
.empresa-switcher-name { font-size: 14px; font-weight: 700; color: var(--text-primary); line-height: 1.35; display: block; letter-spacing: -0.01em; }
.empresa-switcher-name:hover { color: var(--primary-600); }
.empresa-switcher-meta { margin-top: 10px; display: flex; gap: 6px; flex-wrap: wrap; }

.ledger-nav { flex: 1; padding: 6px 14px; display: flex; flex-direction: column; gap: 2px; }

.ledger-nav-section { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted); padding: 18px 10px 7px; }

.ledger-nav-group { display: flex; flex-direction: column; }

.ledger-nav-group > summary.ledger-nav-section {
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color .13s var(--ease-out);
  list-style: none;
}
.ledger-nav-group > summary.ledger-nav-section::-webkit-details-marker { display: none; }
.ledger-nav-group > summary.ledger-nav-section::marker { content: ""; }
.ledger-nav-group > summary.ledger-nav-section:hover { color: var(--text-primary); }

.ledger-nav-caret { font-size: 12px; opacity: .6; transition: transform .15s var(--ease-out); }
.ledger-nav-group[open] > summary .ledger-nav-caret { transform: rotate(180deg); }

.ledger-nav-group-body { display: flex; flex-direction: column; gap: 2px; }

.ledger-nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 600;
  transition: background .13s var(--ease-out), color .13s var(--ease-out);
}

.ledger-nav-link i { font-size: 16px; width: 18px; text-align: center; opacity: .8; }

.ledger-nav-link:hover { background: var(--bg-surface-sunken); color: var(--text-primary); }

.ledger-nav-link.active { background: var(--primary-50); color: var(--primary-700); }
.ledger-nav-link.active i { opacity: 1; color: var(--primary-600); }

.ledger-foot { padding: 14px; border-top: 1px solid var(--border); }

.ledger-user { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius-sm); }

.ledger-user-avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--primary-50);
  border: 1px solid var(--primary-100);
  color: var(--primary-700);
  display: flex; align-items: center; justify-content: center;
  font-size: 12.5px; font-weight: 800; flex-shrink: 0;
}

.ledger-user-name { font-size: 13px; color: var(--text-primary); font-weight: 700; line-height: 1.2; }
.ledger-user-link { font-size: 11.5px; color: var(--text-tertiary); text-decoration: none; font-weight: 500; }
.ledger-user-link:hover { color: var(--primary-600); }

.app-main { margin-left: var(--sidebar-w); flex: 1; min-width: 0; display: flex; flex-direction: column; }

.app-content { padding: 4px 36px 48px; flex: 1; animation: page-in .28s var(--ease-out); }

.simple-topbar { padding: 16px 32px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--border); background: var(--bg-surface); }

@keyframes page-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .app-content { animation: none; } }

/* ===== Cabeceras de página ================================================ */

.page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 24px; padding-top: 24px; }
.page-eyebrow { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--primary-600); font-weight: 700; margin-bottom: 6px; }
.page-title { font-size: 27px; margin: 0; color: var(--text-primary); letter-spacing: -0.02em; }
.page-subtitle { font-size: 13.5px; color: var(--text-secondary); margin-top: 5px; font-weight: 500; }

/* ===== Tarjetas ============================================================ */

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  transition: box-shadow .18s var(--ease-out), transform .18s var(--ease-out), border-color .18s var(--ease-out);
}

a.text-decoration-none .card:hover,
.card.card-hover:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); transform: translateY(-2px); }

.card-body { padding: 22px 24px; }

/* Nota: .stat-card comparte el mismo elemento que .card-body en los templates
   (class="card-body stat-card") — nunca darle padding propio, pisaría el de
   .card-body y deja el texto pegado al borde. Solo controla el espaciado
   interno entre label/valor. */
.stat-card { display: flex; flex-direction: column; gap: 8px; }
.stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-tertiary); font-weight: 700; }
.stat-value { font-size: 25px; font-weight: 800; color: var(--text-primary); line-height: 1.1; letter-spacing: -0.02em; }
.stat-value.positivo { color: var(--success-text); }
.stat-value.negativo { color: var(--danger-text); }
.stat-hint { font-size: 12px; color: var(--text-tertiary); font-weight: 600; margin-left: 2px; }

/* ===== Tablas ============================================================== */

.table-responsive { background: var(--bg-surface); border-radius: var(--radius-lg); border: 1px solid var(--border); box-shadow: var(--shadow-xs); }

.table { margin-bottom: 0; --bs-table-bg: transparent; color: var(--text-primary); }

.table > thead > tr > th {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-tertiary); font-weight: 700;
  border-bottom: 1px solid var(--border-strong);
  background: var(--bg-surface-sunken);
  padding: 13px 18px;
}
.table > thead > tr > th:first-child { border-top-left-radius: var(--radius-lg); }
.table > thead > tr > th:last-child { border-top-right-radius: var(--radius-lg); }

.table > tbody > tr > td { padding: 14px 18px; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--text-secondary); font-weight: 500; }
.table > tbody > tr:last-child > td { border-bottom: none; }
.table > tbody > tr { transition: background .12s var(--ease-out); }
.table-hover > tbody > tr:hover > td { background: var(--bg-surface-sunken); }

/* ===== Badges =============================================================== */

.badge { font-weight: 700; font-size: 11px; letter-spacing: .01em; padding: 5px 10px; border-radius: 999px; border: 1px solid transparent; }
.badge.bg-success { background: var(--success-bg) !important; color: var(--success-text) !important; }
.badge.bg-danger  { background: var(--danger-bg)  !important; color: var(--danger-text)  !important; }
.badge.bg-warning { background: var(--warning-bg) !important; color: var(--warning-text) !important; }
.badge.bg-info    { background: var(--info-bg)    !important; color: var(--info-text)    !important; }
.badge.bg-secondary { background: var(--primary-50) !important; color: var(--primary-700) !important; }

/* ===== Botones ============================================================== */

.btn { font-weight: 700; font-size: 13.5px; border-radius: var(--radius-sm); padding: 9px 16px; transition: background .13s var(--ease-out), border-color .13s var(--ease-out), transform .08s var(--ease-out), box-shadow .13s var(--ease-out); }
.btn:active { transform: scale(.97); }

.btn-primary { background: var(--primary-600); border-color: var(--primary-600); box-shadow: 0 2px 8px rgba(109, 40, 217, 0.25); color: #fff; }
.btn-primary:hover { background: var(--primary-700); border-color: var(--primary-700); }
.btn-primary:focus, .btn-primary:active { background: var(--primary-700) !important; border-color: var(--primary-700) !important; }
.btn-primary:disabled { background: var(--primary-500); border-color: var(--primary-500); opacity: .5; box-shadow: none; }

.btn-outline-primary { color: var(--primary-600); border-color: var(--primary-200); }
.btn-outline-primary:hover { background: var(--primary-600); border-color: var(--primary-600); color: #fff; }

.btn-outline-secondary { color: var(--text-secondary); border-color: var(--border-strong); }
.btn-outline-secondary:hover { background: var(--bg-surface-sunken); color: var(--text-primary); border-color: var(--border-strong); }

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

.btn-sm { padding: 6px 12px; font-size: 12.5px; }

/* ===== Formularios ========================================================= */

.form-label { font-size: 12.5px; font-weight: 700; color: var(--text-secondary); margin-bottom: 6px; }

.form-control, .form-select {
  background: var(--bg-surface); border: 1.5px solid var(--border-strong); border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 500; padding: 9px 13px; color: var(--text-primary);
  transition: border-color .13s var(--ease-out), box-shadow .13s var(--ease-out);
}
.form-control:focus, .form-select:focus { border-color: var(--primary-500); box-shadow: 0 0 0 3.5px var(--primary-100); }
.form-control::placeholder { color: var(--text-muted); }
.form-control:disabled { background: var(--bg-surface-sunken); color: var(--text-tertiary); }

.form-check-input { border-color: var(--border-strong); }
.form-check-input:checked { background-color: var(--primary-600); border-color: var(--primary-600); }
.form-check-input:focus { box-shadow: 0 0 0 3px var(--primary-100); }

/* Quita las flechas de los inputs numéricos — en columnas angostas (tablas
   de ítems) se comían espacio y el número quedaba visualmente cortado. */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

.form-control-sm { padding: 7px 9px; font-size: 12.5px; }

/* ===== Alertas ============================================================= */

.alert { border: 1px solid transparent; border-radius: var(--radius-md); font-size: 13.5px; font-weight: 500; padding: 13px 17px; animation: alert-in .22s var(--ease-out); }
@keyframes alert-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.alert-success { background: var(--success-bg); color: var(--success-text); }
.alert-danger  { background: var(--danger-bg);  color: var(--danger-text); }
.alert-warning { background: var(--warning-bg); color: var(--warning-text); }
.alert-info    { background: var(--info-bg);    color: var(--info-text); }

/* ===== Dropdowns ============================================================ */

.dropdown-menu { border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-lg); padding: 6px; animation: pop-in .16s var(--ease-out); }
@keyframes pop-in { from { opacity: 0; transform: scale(.96) translateY(-4px); } to { opacity: 1; transform: scale(1) translateY(0); } }
.dropdown-item { border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 500; padding: 8px 11px; color: var(--text-primary); }
.dropdown-item:hover, .dropdown-item:focus { background: var(--primary-50); color: var(--primary-700); }
.dropdown-header { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-tertiary); font-weight: 700; }

/* ===== Módulos (accesos rápidos) ============================================ */

.module-card { display: block; text-decoration: none; padding: 20px; height: 100%; }
.module-icon { width: 40px; height: 40px; border-radius: 11px; display: flex; align-items: center; justify-content: center; background: var(--primary-50); color: var(--primary-600); font-size: 18px; margin-bottom: 14px; }
.module-title { font-size: 15.5px; font-weight: 700; color: var(--text-primary); margin: 0; letter-spacing: -0.01em; }
.module-hint { font-size: 12px; color: var(--text-tertiary); margin-top: 3px; font-weight: 500; }

/* ===== Empresas — grid ====================================================== */

.empresa-card { display: block; text-decoration: none; padding: 22px; height: 100%; }
.empresa-card-top { display: flex; align-items: flex-start; gap: 13px; }
.empresa-avatar {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--primary-600); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 17px; flex-shrink: 0;
}
.empresa-card-name { font-weight: 700; font-size: 15.5px; color: var(--text-primary); line-height: 1.35; letter-spacing: -0.01em; }
.empresa-card-ruc { font-size: 12px; color: var(--text-tertiary); font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; }
.empresa-card-foot { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); display: flex; gap: 6px; flex-wrap: wrap; }

/* ===== Estado vacío ========================================================= */

.empty-state { text-align: center; padding: 56px 24px; color: var(--text-tertiary); }
.empty-state i { font-size: 26px; color: var(--text-muted); margin-bottom: 10px; display: block; }
.empty-state p { font-size: 13.5px; margin: 0; font-weight: 500; }

/* ===== Login ================================================================ */

.auth-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--bg-page);
  background-image: radial-gradient(circle at 15% 15%, var(--primary-50) 0%, transparent 45%);
  padding: 24px;
}
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 38px 34px;
  animation: page-in .35s var(--ease-out);
}
.auth-mark {
  width: 46px; height: 46px; border-radius: 13px;
  background: var(--primary-600); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 20px;
  margin: 0 auto 20px;
  box-shadow: 0 4px 14px rgba(109, 40, 217, 0.28);
}
.auth-title { text-align: center; font-size: 21px; margin-bottom: 4px; letter-spacing: -0.02em; }
.auth-subtitle { text-align: center; font-size: 12.5px; color: var(--text-tertiary); margin-bottom: 28px; font-weight: 500; }

/* ===== Zona de arrastrar / pegar archivos ================================== */

.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-surface-sunken);
  padding: 40px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s var(--ease-out), background .15s var(--ease-out), transform .1s var(--ease-out);
}
.dropzone:hover { border-color: var(--primary-500); background: var(--primary-50); }
.dropzone i { font-size: 30px; color: var(--primary-500); margin-bottom: 10px; display: block; }
.dropzone-title { font-size: 14px; font-weight: 700; color: var(--text-primary); margin: 0 0 3px; }
.dropzone-hint { font-size: 12px; color: var(--text-tertiary); margin: 0; }
.dropzone.dropzone-active { border-color: var(--primary-500); background: var(--primary-50); transform: scale(1.005); }
.dropzone.disabled { pointer-events: none; opacity: .55; }

.preview-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}
.preview-chip {
  position: relative;
  width: 110px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
  animation: page-in .18s var(--ease-out);
}
.preview-chip img { width: 100%; height: 80px; object-fit: cover; display: block; }
.preview-icon { width: 100%; height: 80px; display: flex; align-items: center; justify-content: center; background: var(--bg-surface-sunken); color: var(--danger-500); font-size: 26px; }
.preview-name { font-size: 10.5px; color: var(--text-tertiary); padding: 5px 7px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.preview-remove {
  position: absolute; top: 4px; right: 4px;
  width: 20px; height: 20px; border-radius: 50%;
  background: rgba(16, 16, 20, 0.65); color: #fff; border: none;
  font-size: 14px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.preview-remove:hover { background: var(--danger-500); }

/* ===== Utilidades ============================================================ */

.text-tertiary { color: var(--text-tertiary) !important; }
.saldo-positivo { color: var(--success-text); font-weight: 700; }
.saldo-negativo { color: var(--danger-text); font-weight: 700; }

@media (max-width: 900px) {
  .ledger-spine { transform: translateX(-100%); transition: transform .2s var(--ease-out); box-shadow: var(--shadow-lg); }
  .ledger-spine.open { transform: translateX(0); }
  .app-main { margin-left: 0; }
  .app-topbar, .app-content, .simple-topbar { padding-left: 18px; padding-right: 18px; }
}
