/* ════════════════════════════════════════════
   LAMKARGA S.A.S — Design tokens
════════════════════════════════════════════ */

/* ── Light (default) ── */
:root,
html[data-theme='light'] {
  --tb-bg:         #f0f4f9;
  --tb-surface:    #ffffff;
  --tb-surface2:   #f7f9fc;
  --tb-border:     #e2e8f0;
  --tb-text:       #1a202c;
  --tb-muted:      #64748b;
  --tb-primary:    #2563eb;
  --tb-primary-h:  #1d4ed8;
  --tb-success:    #059669;
  --tb-danger:     #dc2626;
  --tb-warning:    #d97706;
  --tb-info:       #0891b2;
  --tb-sidebar:    #1e2d4e;
  --tb-shadow:     0 1px 4px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --tb-shadow-md:  0 4px 16px rgba(0,0,0,0.09);
  --tb-radius:     14px;
  --tb-radius-sm:  8px;
  /* Bootstrap bridge */
  --bs-body-bg:       var(--tb-bg);
  --bs-body-color:    var(--tb-text);
  --bs-card-bg:       var(--tb-surface);
  --bs-border-color:  var(--tb-border);
  --bs-secondary-bg:  var(--tb-surface2);
}

/* ── Dark ── */
html[data-theme='dark'] {
  --tb-bg:         #0d1117;
  --tb-surface:    #161c2a;
  --tb-surface2:   #1e2638;
  --tb-border:     #2a3348;
  --tb-text:       #dde3ee;
  --tb-muted:      #8896b0;
  --tb-primary:    #60a5fa;
  --tb-primary-h:  #93c5fd;
  --tb-success:    #34d399;
  --tb-danger:     #f87171;
  --tb-warning:    #fbbf24;
  --tb-info:       #22d3ee;
  --tb-sidebar:    #0f1623;
  --tb-shadow:     0 1px 4px rgba(0,0,0,0.4);
  --tb-shadow-md:  0 4px 16px rgba(0,0,0,0.5);
  /* Bootstrap bridge */
  --bs-body-bg:          var(--tb-bg);
  --bs-body-color:       var(--tb-text);
  --bs-card-bg:          var(--tb-surface);
  --bs-border-color:     var(--tb-border);
  --bs-secondary-bg:     var(--tb-surface2);
  --bs-tertiary-bg:      var(--tb-surface);
  --bs-secondary-color:  var(--tb-muted);
  --bs-emphasis-color:   var(--tb-text);
  --bs-link-color:       var(--tb-primary);
}

/* ════════════════════════════════════════════
   Base
════════════════════════════════════════════ */
body {
  background: var(--tb-bg);
  color: var(--tb-text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 0.9rem;
  transition: background 0.22s, color 0.22s;
}

/* ════════════════════════════════════════════
   Sidebar
════════════════════════════════════════════ */
.sidebar {
  width: 232px;
  min-width: 232px;
  background: var(--tb-sidebar);
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-right: 1px solid rgba(255,255,255,0.06);
  transition: width 0.25s ease, min-width 0.25s ease, background 0.22s;
}

/* Header fijo: no se desplaza */
.sidebar-header { flex-shrink: 0; background: inherit; }

/* Nav scrollable */
.sidebar-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
}
.sidebar-nav > ul { flex: 1 0 auto; }

.sidebar-brand {
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-user {
  background: rgba(255,255,255,0.04);
  padding: 0.6rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

/* ════════════════════════════════════════════
   Clientes — sticky header + scroll body
════════════════════════════════════════════ */
#page-clientes { display: flex; flex-direction: column; }
.cli-wrap { display: flex; flex-direction: column; flex: 1 1 auto; }
.cli-header {
  position: sticky; top: -1.5rem; z-index: 20;
  background: var(--tb-bg); padding-top: 1.5rem; margin-top: -1.5rem;
  padding-bottom: 0.6rem; border-bottom: 1px solid var(--tb-border);
  transition: background 0.22s;
}
.cli-body { overflow-y: auto; overflow-x: auto; max-height: calc(100vh - 270px); }
.cli-body .table thead th {
  position: sticky; top: 0; z-index: 5;
  background: var(--tb-surface2) !important;
  box-shadow: 0 1px 0 var(--tb-border);
}
.cli-pagination-bar {
  flex-shrink: 0; border-top: 1px solid var(--tb-border);
  padding: 0.4rem 0; background: var(--tb-bg); transition: background 0.22s;
}

/* ════════════════════════════════════════════
   Manifiestos — sticky header + scroll body
════════════════════════════════════════════ */
#page-manifiestos {
  display: flex;
  flex-direction: column;
}
.mf-wrap {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
}

/* Filtros pegados al tope (mismo patrón que #rep-filters) */
.mf-header {
  position: sticky;
  top: -1.5rem;
  z-index: 20;
  background: var(--tb-bg);
  padding-top: 1.5rem;
  margin-top: -1.5rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--tb-border);
  transition: background 0.22s;
}

/* Tabla scrollable */
.mf-body {
  overflow-y: auto;
  overflow-x: auto;
  max-height: calc(100vh - 270px);
}

/* Encabezados de tabla pegados al tope del scroll */
.mf-body .table thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--tb-surface2) !important;
  box-shadow: 0 1px 0 var(--tb-border);
}

/* Barra de paginación siempre visible debajo */
.mf-pagination-bar {
  flex-shrink: 0;
  border-top: 1px solid var(--tb-border);
  padding: 0.4rem 0;
  background: var(--tb-bg);
  transition: background 0.22s;
}

/* ── Botón toggle ── */
.sidebar-toggle {
  background: none;
  border: 1px solid rgba(255,255,255,0.18);
  color: rgba(255,255,255,0.55);
  padding: 4px 7px;
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
  font-size: 0.85rem;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
}
.sidebar-toggle:hover {
  color: #fff;
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.35);
}
.sidebar-toggle:focus-visible {
  outline: 2px solid var(--tb-primary);
  outline-offset: 2px;
}

/* ── Estado colapsado ── */
.sidebar-collapsed .sidebar { width: 72px; min-width: 72px; }

.sidebar-collapsed .sidebar .menu-text     { display: none !important; }
.sidebar-collapsed .sidebar .brand-text    { display: none; }
.sidebar-collapsed .sidebar .sidebar-user  { display: none; }

.sidebar-collapsed .sidebar .sidebar-brand {
  justify-content: center;
  padding-left: .5rem;
  padding-right: .5rem;
}

.sidebar-collapsed .sidebar .nav-section-label {
  height: 6px;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden;
  font-size: 0;
}
.sidebar-collapsed .sidebar .nav-item {
  justify-content: center;
  padding: .5rem 0 !important;
  margin: 2px 6px;
}
.sidebar-collapsed .sidebar .nav-item .bi { margin-right: 0 !important; font-size: 1.1rem; }
.sidebar-collapsed .sidebar .logout-btn   { justify-content: center; padding-left: .25rem !important; padding-right: .25rem !important; }
.sidebar-collapsed .sidebar .logout-btn .bi { margin-right: 0 !important; }

.nav-section-label {
  font-size: 0.67rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: rgba(255,255,255,0.28);
  padding: 0.3rem 1rem;
  margin-top: 0.5rem;
}

.nav-item {
  color: rgba(255,255,255,0.65) !important;
  border-radius: var(--tb-radius-sm);
  padding: 0.5rem 0.85rem !important;
  font-size: 0.86rem;
  display: flex;
  align-items: center;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
  border-left: 3px solid transparent;
  margin: 1px 6px;
}

.nav-item:hover {
  background: rgba(255,255,255,0.09) !important;
  color: #fff !important;
}

.nav-item.active {
  background: rgba(96,165,250,0.16) !important;
  color: #93c5fd !important;
  border-left-color: #60a5fa;
}

/* ════════════════════════════════════════════
   Topbar
════════════════════════════════════════════ */
.topbar {
  background: var(--tb-surface);
  height: 54px;
  border-bottom: 1px solid var(--tb-border);
  transition: background 0.22s, border-color 0.22s;
}

/* Theme toggle */
#theme-toggle {
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--tb-radius-sm);
  border: 1px solid var(--tb-border);
  background: var(--tb-surface2);
  color: var(--tb-text);
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, color 0.18s, transform 0.15s;
  font-size: 0.92rem;
}
#theme-toggle:hover {
  background: var(--tb-primary);
  border-color: var(--tb-primary);
  color: #fff;
  transform: rotate(15deg);
}
#theme-toggle:focus-visible {
  outline: 2px solid var(--tb-primary);
  outline-offset: 2px;
}

/* ════════════════════════════════════════════
   Cards
════════════════════════════════════════════ */
.card {
  border-radius: var(--tb-radius) !important;
  border: 1px solid var(--tb-border) !important;
  background: var(--tb-surface) !important;
  box-shadow: var(--tb-shadow) !important;
  transition: box-shadow 0.2s, transform 0.15s, background 0.22s, border-color 0.22s;
}
.card:hover {
  box-shadow: var(--tb-shadow-md) !important;
}
.card-header {
  background: var(--tb-surface) !important;
  border-bottom: 1px solid var(--tb-border) !important;
  border-radius: var(--tb-radius) var(--tb-radius) 0 0 !important;
  color: var(--tb-text) !important;
}

/* Stat cards — acento izquierdo */
.card-stat {
  border-left: 4px solid var(--tb-primary) !important;
}
.card-stat .stat-label {
  font-size: 0.71rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--tb-muted);
}
.card-stat .stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin-top: 4px;
}

/* ════════════════════════════════════════════
   Tables
════════════════════════════════════════════ */
.table {
  color: var(--tb-text) !important;
  --bs-table-color:        var(--tb-text);
  --bs-table-bg:           transparent;
  --bs-table-border-color: var(--tb-border);
  --bs-table-hover-bg:     rgba(96,165,250,0.06);
  --bs-table-striped-bg:   var(--tb-surface2);
}
.table th {
  font-size: 0.71rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--tb-muted) !important;
  border-bottom: 2px solid var(--tb-border) !important;
  padding: 0.65rem 0.75rem;
  background: var(--tb-surface2) !important;
}
.table td {
  font-size: 0.87rem;
  color: var(--tb-text);
  border-color: var(--tb-border) !important;
  padding: 0.6rem 0.75rem;
  vertical-align: middle;
}
.table-light, thead.table-light th {
  background-color: var(--tb-surface2) !important;
  color: var(--tb-muted) !important;
}
.table-secondary {
  --bs-table-bg: var(--tb-surface2);
  opacity: 0.65;
}
.table-hover > tbody > tr:hover > * {
  background-color: rgba(96,165,250,0.06) !important;
  color: var(--tb-text) !important;
}

/* ════════════════════════════════════════════
   Forms
════════════════════════════════════════════ */
.form-control,
.form-select {
  background-color: var(--tb-surface) !important;
  border-color: var(--tb-border) !important;
  color: var(--tb-text) !important;
  border-radius: var(--tb-radius-sm) !important;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus,
.form-select:focus {
  background-color: var(--tb-surface) !important;
  color: var(--tb-text) !important;
  border-color: var(--tb-primary) !important;
  box-shadow: 0 0 0 3px rgba(96,165,250,0.18) !important;
}
.form-control::placeholder { color: var(--tb-muted); opacity: 0.7; }
.form-label { color: var(--tb-text); font-size: 0.87rem; }
.input-group-text {
  background: var(--tb-surface2) !important;
  border-color: var(--tb-border) !important;
  color: var(--tb-muted) !important;
}

/* ════════════════════════════════════════════
   Buttons
════════════════════════════════════════════ */
.btn {
  border-radius: var(--tb-radius-sm) !important;
  font-weight: 500;
  transition: all 0.18s;
}
.btn:focus-visible {
  outline: 2px solid var(--tb-primary);
  outline-offset: 2px;
  box-shadow: none !important;
}
.btn-primary {
  background: var(--tb-primary) !important;
  border-color: var(--tb-primary) !important;
  color: #fff !important;
}
.btn-primary:hover {
  background: var(--tb-primary-h) !important;
  border-color: var(--tb-primary-h) !important;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37,99,235,0.28) !important;
}
.btn-success {
  background: var(--tb-success) !important;
  border-color: var(--tb-success) !important;
  color: #fff !important;
}
.btn-danger  { background: var(--tb-danger)  !important; border-color: var(--tb-danger)  !important; color:#fff !important; }
.btn-warning { background: var(--tb-warning) !important; border-color: var(--tb-warning) !important; }
.btn-outline-secondary {
  color: var(--tb-text) !important;
  border-color: var(--tb-border) !important;
  background: var(--tb-surface) !important;
}
.btn-outline-secondary:hover {
  background: var(--tb-surface2) !important;
  border-color: var(--tb-muted) !important;
  color: var(--tb-text) !important;
}
.btn-outline-primary  { color: var(--tb-primary) !important; border-color: var(--tb-primary) !important; background: transparent !important; }
.btn-outline-primary:hover { background: var(--tb-primary) !important; color: #fff !important; }
.btn-outline-danger   { color: var(--tb-danger)  !important; border-color: var(--tb-danger)  !important; background: transparent !important; }
.btn-outline-danger:hover  { background: var(--tb-danger)  !important; color: #fff !important; }
.btn-outline-success  { color: var(--tb-success) !important; border-color: var(--tb-success) !important; background: transparent !important; }
.btn-outline-success:hover { background: var(--tb-success) !important; color: #fff !important; }
.btn-outline-light { border-color: rgba(255,255,255,0.2) !important; color: rgba(255,255,255,0.75) !important; }
.btn-outline-light:hover { background: rgba(255,255,255,0.1) !important; color: #fff !important; }
.btn-xs { padding: .16rem .45rem; font-size: .75rem; line-height: 1.2; border-radius: 5px !important; }

/* ════════════════════════════════════════════
   Modals
════════════════════════════════════════════ */
.modal-content {
  background: var(--tb-surface) !important;
  border: 1px solid var(--tb-border) !important;
  border-radius: var(--tb-radius) !important;
  box-shadow: 0 24px 64px rgba(0,0,0,0.2) !important;
  color: var(--tb-text) !important;
}
.modal-header,
.modal-footer { border-color: var(--tb-border) !important; }
.modal-title { color: var(--tb-text) !important; }
.modal-backdrop { background: rgba(0,0,0,0.55) !important; }

/* ════════════════════════════════════════════
   Alerts
════════════════════════════════════════════ */
.alert { border-radius: var(--tb-radius-sm) !important; }

/* ════════════════════════════════════════════
   Badges
════════════════════════════════════════════ */
.badge {
  border-radius: 6px !important;
  font-weight: 600 !important;
  letter-spacing: 0.02em;
  font-size: 0.73rem;
}

/* ════════════════════════════════════════════
   Dropdown results (búsqueda de clientes)
════════════════════════════════════════════ */
.dropdown-results {
  position: absolute;
  z-index: 1000;
  max-height: 220px;
  overflow-y: auto;
  min-width: 320px;
  background: var(--tb-surface) !important;
  border: 1px solid var(--tb-border) !important;
  border-radius: var(--tb-radius-sm) !important;
  box-shadow: var(--tb-shadow-md) !important;
}
.dropdown-results .dropdown-item {
  padding: 0.45rem 0.9rem;
  cursor: pointer;
  font-size: 0.87rem;
  color: var(--tb-text);
  background: transparent;
  transition: background 0.1s;
}
.dropdown-results .dropdown-item:hover {
  background: rgba(96,165,250,0.1) !important;
  color: var(--tb-primary) !important;
}

/* ════════════════════════════════════════════
   Balance colors
════════════════════════════════════════════ */
.text-deuda     { color: var(--tb-danger)   !important; font-weight: 600; }
.text-saldo-fav { color: var(--tb-primary)  !important; font-weight: 600; }
.text-paz-salvo { color: var(--tb-success)  !important; font-weight: 600; }

/* ════════════════════════════════════════════
   Misc
════════════════════════════════════════════ */
.page       { display: block; }
.page.d-none { display: none !important; }
.expand-row  { background: var(--tb-surface2); }

code {
  background: var(--tb-surface2);
  color: var(--tb-primary);
  padding: 0.1em 0.4em;
  border-radius: 4px;
  font-size: 0.85em;
}

/* ════════════════════════════════════════════
   Reports sticky + scroll
════════════════════════════════════════════ */
#rep-filters {
  position: sticky;
  top: -1.5rem;
  z-index: 100;
  background: var(--tb-bg);
  padding-top: 1.5rem;
  margin-top: -1.5rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--tb-border);
  margin-bottom: 0.75rem;
  transition: background 0.22s, border-color 0.22s;
}
#rep-resultado {
  overflow-y: auto;
  max-height: calc(100vh - 260px);
  border-radius: 6px;
}
#rep-resultado .table thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--tb-surface2) !important;
  box-shadow: 0 1px 0 var(--tb-border);
}

/* ════════════════════════════════════════════
   Charts section
════════════════════════════════════════════ */
#charts-section { transition: opacity 0.3s; }

/* ════════════════════════════════════════════
   Rol Consulta — ocultar acciones de escritura
════════════════════════════════════════════ */
body.consulta-mode .hide-for-consulta { display: none !important; }

/* ════════════════════════════════════════════
   Print
════════════════════════════════════════════ */
@media print { .no-print { display: none !important; } }

/* ════════════════════════════════════════════
   Responsive sidebar
════════════════════════════════════════════ */
@media (max-width: 768px) {
  /* En mobile, colapsar automáticamente si no hay preferencia guardada */
  body:not(.sidebar-expanded-mobile) .sidebar { width: 72px; min-width: 72px; }
  body:not(.sidebar-expanded-mobile) .sidebar .menu-text  { display: none !important; }
  body:not(.sidebar-expanded-mobile) .sidebar .brand-text { display: none; }
  body:not(.sidebar-expanded-mobile) .sidebar .sidebar-user { display: none; }
  body:not(.sidebar-expanded-mobile) .sidebar .nav-section-label { height: 6px; margin: 0 !important; padding: 0 !important; overflow: hidden; font-size: 0; }
  body:not(.sidebar-expanded-mobile) .sidebar .nav-item { justify-content: center; padding: .5rem 0 !important; }
  body:not(.sidebar-expanded-mobile) .sidebar .nav-item .bi { margin-right: 0 !important; }
  body:not(.sidebar-expanded-mobile) .sidebar .sidebar-brand { justify-content: center; padding-left: .5rem; padding-right: .5rem; }
}
