/* ============================================================
   DASHBOARD-V2.CSS — One UI 8 Redesign 2026
   Clean, minimal, rounded, Outfit typography
   ============================================================ */

/* ============================================================
   1. VARIABLES CSS — One UI 8 Palette
   ============================================================ */
:root {
  /* Backgrounds */
  --clr-bg: #f6f6f9;
  --clr-card: #ffffff;
  --clr-bg-secondary: #f0f1f5;
  --clr-border: #e5e7eb;

  /* Text */
  --clr-text: #1a1a2e;
  --clr-muted: #6b7280;
  --clr-hints: #9ca3af;

  /* Primary — Indigo (One UI 8 inspired) */
  --clr-primary: #6366f1;
  --clr-primary-dim: rgba(99,102,241,0.08);
  --clr-primary-light: #eef2ff;

  /* Semantic */
  --clr-verde: #10b981;
  --clr-azul: #3b82f6;
  --clr-amarillo: #f59e0b;
  --clr-rojo: #ef4444;

  /* Typography scale */
  --text-xs:  11px;
  --text-sm:  13px;
  --text-md:  14px;
  --text-kpi: 26px;

  /* Radii — One UI 8 consistent rounding */
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 20px;
  --radius-pill: 999px;

  /* Shadows — soft, layered */
  --shadow-card: 0 1px 3px rgba(0,0,0,0.04), 0 4px 16px rgba(99,102,241,0.04);
  --shadow-hover: 0 2px 8px rgba(0,0,0,0.06), 0 8px 24px rgba(99,102,241,0.06);

  /* Easing curves */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
}

/* ============================================================
   1b. DARK THEME
   ============================================================ */
[data-theme="dark"] {
  --clr-bg: #0a0a0f;
  --clr-card: #13131c;
  --clr-bg-secondary: #0f0f17;
  --clr-border: #1e1e2e;
  --clr-text: #e8e8ec;
  --clr-muted: #9ca3af;
  --clr-hints: #6b7280;
  --clr-primary-dim: rgba(99,102,241,0.15);
  --clr-primary-light: rgba(99,102,241,0.12);
  --shadow-card: 0 1px 3px rgba(0,0,0,0.4), 0 4px 20px rgba(0,0,0,0.3);
  --shadow-hover: 0 2px 8px rgba(0,0,0,0.5), 0 8px 24px rgba(0,0,0,0.4);
  color-scheme: dark;
}

[data-theme="dark"] body { background-color: var(--clr-bg); color: var(--clr-text); }
[data-theme="dark"] .sticky-header { background: rgba(10,10,15,0.95); box-shadow: 0 1px 12px rgba(99,102,241,0.06); border-bottom: none; }
[data-theme="dark"] .date-group input[type="date"] { color-scheme: dark; }
[data-theme="dark"] .table tbody tr:hover { background: rgba(255,255,255,0.03) !important; }
[data-theme="dark"] .table thead th { background: var(--clr-bg-secondary) !important; }
[data-theme="dark"] .kpi-card.ventas   { box-shadow: 0 0 24px rgba(16,185,129,0.08) !important; }
[data-theme="dark"] .kpi-card.compras  { box-shadow: 0 0 24px rgba(59,130,246,0.08) !important; }
[data-theme="dark"] .kpi-card.gastos   { box-shadow: 0 0 24px rgba(245,158,11,0.08) !important; }
[data-theme="dark"] .kpi-card.deuda    { box-shadow: 0 0 24px rgba(239,68,68,0.08) !important; }
[data-theme="dark"] .kpi-card.utilidad { box-shadow: 0 0 24px rgba(99,102,241,0.10) !important; }

/* ============================================================
   2. BASE
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

body {
  background-color: var(--clr-bg);
  color: var(--clr-text);
  font-family: 'Outfit', system-ui, -apple-system, sans-serif;
  font-size: var(--text-md);
  font-weight: 400;
  overflow-x: hidden;
  margin: 0;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
  color: var(--clr-text) !important;
  font-weight: 500 !important;
  font-family: 'Outfit', system-ui, sans-serif;
  margin: 0;
}

.fw-bold { font-weight: 500 !important; }
.fw-bolder { font-weight: 600 !important; }
.small { font-size: var(--text-sm); }

/* ============================================================
   3. COLORES SEMÁNTICOS
   ============================================================ */
.text-info-bright   { color: var(--clr-azul)     !important; }
.text-success-bright{ color: var(--clr-verde)    !important; }
.text-danger-bright { color: var(--clr-rojo)     !important; }
.text-warning-bright{ color: var(--clr-amarillo) !important; }
.text-accent        { color: var(--clr-primary)   !important; }
.text-white         { color: var(--clr-text)      !important; }
.text-muted         { color: var(--clr-muted)     !important; }
.text-warning       { color: var(--clr-amarillo) !important; }
.text-success       { color: var(--clr-verde)    !important; }
.text-danger        { color: var(--clr-rojo)     !important; }
.text-info          { color: var(--clr-azul)     !important; }
.text-white-50      { color: var(--clr-muted) !important; }

/* ============================================================
   4. CARDS — One UI 8 rounded surfaces
   ============================================================ */
.card {
  background-color: var(--clr-card) !important;
  border: 1px solid var(--clr-border) !important;
  border-radius: var(--radius-md) !important;
  color: var(--clr-text) !important;
  box-shadow: var(--shadow-card) !important;
  transition: box-shadow 0.2s ease, transform 0.2s ease;
}

/* Override Bootstrap flex on chart cards — Plotly needs block display with explicit width */
.card.p-3 {
  display: block !important;
}
.card.p-3 > [id^="chart"] {
  width: 100%;
}

/* Ensure all chart containers have dimensions for Plotly */
[id^="chart"] {
    width: 100%;
    min-height: 1px;
}

.card-header {
  background: transparent !important;
  border-bottom: 1px solid var(--clr-border) !important;
  color: var(--clr-muted) !important;
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 12px 16px;
  border-radius: var(--radius-md) var(--radius-md) 0 0 !important;
}

.card-body { color: var(--clr-text); }

/* ============================================================
   5. KPI CARDS — One UI 8 style
   ============================================================ */
.kpi-card {
  padding: 18px 20px !important;
  box-shadow: var(--shadow-card) !important;
  border: 1px solid var(--clr-border) !important;
  border-radius: var(--radius-md) !important;
  position: relative;
  overflow: hidden;
}

.kpi-card.ventas   { border-left: 4px solid var(--clr-verde)   !important; background: linear-gradient(135deg, rgba(16,185,129,0.06) 0%, transparent 60%) !important; }
.kpi-card.compras  { border-left: 4px solid var(--clr-azul)    !important; background: linear-gradient(135deg, rgba(59,130,246,0.06) 0%, transparent 60%) !important; }
.kpi-card.gastos   { border-left: 4px solid var(--clr-amarillo) !important; background: linear-gradient(135deg, rgba(245,158,11,0.06) 0%, transparent 60%) !important; }
.kpi-card.deuda    { border-left: 4px solid var(--clr-rojo)    !important; background: linear-gradient(135deg, rgba(239,68,68,0.06) 0%, transparent 60%) !important; }
.kpi-card.utilidad { border-left: 4px solid var(--clr-primary)  !important; background: linear-gradient(135deg, rgba(99,102,241,0.08) 0%, transparent 60%) !important; }

.kpi-icon {
  position: absolute; top: 12px; right: 16px;
  font-size: 34px; opacity: 0.06; color: var(--clr-text);
  pointer-events: none; line-height: 1;
}

.kpi-label {
  font-size: var(--text-xs) !important;
  font-weight: 500 !important;
  letter-spacing: 0.07em !important;
  text-transform: uppercase !important;
  color: var(--clr-muted) !important;
  margin-bottom: 4px !important;
}

.kpi-value {
  font-size: var(--text-kpi) !important;
  font-weight: 500 !important;
  line-height: 1.1 !important;
  margin: 5px 0 3px;
  font-family: 'Outfit', system-ui, sans-serif;
}

.kpi-sub {
  font-size: var(--text-xs) !important;
  color: var(--clr-muted) !important;
  margin-top: 3px !important;
}

.kpi-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

/* Delta badge — pill shape */
.kpi-delta {
  font-size: 10px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
  letter-spacing: 0.02em;
  flex-shrink: 0;
  margin-top: 1px;
}
.kpi-delta.up      { background: #dcfce7; color: #059669; }
.kpi-delta.down    { background: #fee2e2; color: #ef4444; }
.kpi-delta.neutral { background: rgba(107,114,128,0.10); color: var(--clr-muted); }
.kpi-delta.warn    { background: rgba(245,158,11,0.12); color: var(--clr-amarillo); }

/* ============================================================
   6. HEADER STICKY
   ============================================================ */
.sticky-header {
  background: rgba(246,246,249,0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--clr-border);
  padding: 10px 16px;
  position: sticky;
  top: 0;
  z-index: 1000;
}

.header-row-top {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.header-row-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.logo-badge {
  width: 28px;
  height: 28px;
  background: var(--clr-primary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: var(--text-sm);
  color: #fff;
  flex-shrink: 0;
}

.header-row-top h5 {
  font-size: var(--text-sm) !important;
  font-weight: 600 !important;
  color: var(--clr-text) !important;
  letter-spacing: -0.01em;
}

/* ============================================================
   7. NAV PILLS (TABS) — One UI 8 rounded
   ============================================================ */
.nav-pills {
  background: var(--clr-card) !important;
  border: 1px solid var(--clr-border) !important;
  border-radius: var(--radius-md) !important;
  padding: 4px !important;
  gap: 2px !important;
  display: flex;
}

.nav-pills .nav-link {
  color: var(--clr-muted) !important;
  background: transparent !important;
  font-weight: 500 !important;
  font-size: var(--text-xs) !important;
  letter-spacing: 0.04em;
  border-radius: 12px !important;
  padding: 6px 14px !important;
  transition: all 0.2s ease !important;
  text-transform: uppercase;
}

.nav-pills .nav-link:not(.active):hover {
  color: var(--clr-text) !important;
  background: var(--clr-bg-secondary) !important;
}

.nav-pills .nav-link.active {
  background: var(--clr-primary) !important;
  color: #ffffff !important;
  border-radius: 12px !important;
}

/* ============================================================
   8. DATE CONTROLS
   ============================================================ */
.date-group {
  display: flex;
  align-items: center;
  background: var(--clr-card);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  height: 32px;
}

.date-group input[type="date"] {
  background: transparent;
  border: none;
  color: var(--clr-text);
  font-size: var(--text-xs);
  font-family: 'Outfit', system-ui, sans-serif;
  font-weight: 400;
  padding: 0 8px;
  height: 100%;
  outline: none;
  width: 116px;
  color-scheme: light;
}

.date-group .date-sep {
  color: var(--clr-hints);
  font-size: var(--text-xs);
  padding: 0 2px;
}

.btn-ver {
  background: var(--clr-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-weight: 500;
  font-family: 'Outfit', system-ui, sans-serif;
  padding: 0 16px;
  height: 32px;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  text-transform: uppercase;
}
.btn-ver:hover { background: #4f46e5; }
.btn-ver:active { transform: scale(0.97); }

.quick-pills {
  display: flex;
  background: var(--clr-card);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  height: 32px;
}

.quick-pill {
  background: transparent;
  border: none;
  border-right: 1px solid var(--clr-border);
  color: var(--clr-muted);
  font-size: var(--text-xs);
  font-weight: 500;
  font-family: 'Outfit', system-ui, sans-serif;
  padding: 0 12px;
  height: 100%;
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.03em;
}
.quick-pill:last-child { border-right: none; }
.quick-pill:not(.active):hover { color: var(--clr-text); background: var(--clr-bg-secondary); }
.quick-pill.active { background: var(--clr-primary); color: #fff; }

/* ============================================================
   9. BOTONES
   ============================================================ */
.btn-theme {
  background: none;
  border: 1px solid var(--clr-border);
  color: var(--clr-muted);
  border-radius: var(--radius-sm);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  font-size: var(--text-md);
  flex-shrink: 0;
}
.btn-theme:hover { color: var(--clr-text); border-color: var(--clr-muted); }

.btn-logout {
  background: none !important;
  border: 1px solid var(--clr-border) !important;
  color: var(--clr-muted) !important;
  font-size: var(--text-xs) !important;
  padding: 4px 12px !important;
  border-radius: var(--radius-sm) !important;
  transition: all 0.2s !important;
}
.btn-logout:hover {
  border-color: var(--clr-rojo) !important;
  color: var(--clr-rojo) !important;
}

.btn-primary {
  background-color: var(--clr-primary) !important;
  border: none !important;
  font-weight: 500 !important;
  border-radius: var(--radius-sm) !important;
}
.btn-primary:hover { background-color: #4f46e5 !important; }

/* ============================================================
   10. MACRO FILTER PILLS
   ============================================================ */
.macro-pills {
  display: flex;
  background: var(--clr-card);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-md);
  padding: 4px;
  gap: 2px;
  width: fit-content;
  margin: 0 auto 14px;
}

.macro-btn {
  border: 1px solid var(--clr-border) !important;
  background: transparent !important;
  color: var(--clr-muted) !important;
  font-size: var(--text-xs) !important;
  font-weight: 500 !important;
  padding: 5px 14px !important;
  border-radius: 12px !important;
  transition: all 0.2s !important;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
}
.macro-btn:not(.active):hover { color: var(--clr-text) !important; background: var(--clr-bg-secondary) !important; }
.macro-btn.active { background: var(--clr-primary) !important; color: #ffffff !important; border-color: var(--clr-primary) !important; }
.sort-btn.active  { background: var(--clr-primary) !important; color: #fff !important; }

.btn:active, .macro-btn:active, .quick-pill:active {
  transform: scale(0.97);
}

/* ============================================================
   11. CONTENT AREA Y SECTION LABELS
   ============================================================ */
.content-area { padding: 20px; }
@media (min-width: 769px) { .content-area { padding: 24px 28px; } }

.tab-section-title {
  font-size: var(--text-xs);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--clr-muted);
  margin-bottom: 10px;
  margin-top: 4px;
}

.tab-section-divider {
  border-color: var(--clr-border);
  margin: 20px 0 8px;
  opacity: 0.5;
}

.row.g-3 { --bs-gutter-x: 16px; --bs-gutter-y: 16px; }

/* ============================================================
   12. TABLAS
   ============================================================ */
.table {
  color: var(--clr-text) !important;
  font-size: var(--text-sm);
  border-color: transparent;
}

.table thead th {
  font-size: var(--text-xs) !important;
  font-weight: 500 !important;
  color: var(--clr-muted) !important;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--clr-border) !important;
  background: var(--clr-bg) !important;
  padding: 8px 12px;
  white-space: nowrap;
}

.table tbody tr { border-bottom: 1px solid var(--clr-border); transition: background 0.15s; }
.table tbody tr:hover { background: rgba(99,102,241,0.03) !important; }
.table tbody td {
  padding: 8px 12px;
  vertical-align: middle;
  border-bottom: 1px solid var(--clr-border);
  color: var(--clr-text);
}

/* Bootstrap table-dark override — map to theme vars */
.table-dark {
  --bs-table-bg: transparent !important;
  --bs-table-hover-bg: rgba(99,102,241,0.03) !important;
  --bs-table-color: var(--clr-text) !important;
  --bs-table-border-color: var(--clr-border) !important;
  --bs-table-striped-bg: transparent !important;
}

.text-end             { font-variant-numeric: tabular-nums; }
.clickable-row        { cursor: pointer; }
.clickable-row:hover  { background: rgba(99,102,241,0.03) !important; }

/* ============================================================
   13. TREE SIDEBAR
   ============================================================ */
.tree-sidebar {
  width: 320px;
  background-color: var(--clr-bg-secondary);
  border-right: 1px solid var(--clr-border);
  padding: 10px;
  flex-shrink: 0;
  min-height: 80vh;
  border-radius: var(--radius-md) 0 0 var(--radius-md);
}

.tree-item {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: var(--text-sm);
  color: var(--clr-muted);
  margin-bottom: 2px;
  cursor: pointer;
  transition: all 0.15s;
}
.tree-item:hover  { background-color: var(--clr-primary-dim); color: var(--clr-text); }
.tree-item.active { background-color: var(--clr-primary-dim); color: var(--clr-text); border-left: 2px solid var(--clr-primary); }

.dep-item {
  background-color: rgba(99,102,241,0.04);
  border-left: 2px solid var(--clr-border);
  font-weight: 500;
  color: var(--clr-text);
  font-size: var(--text-sm);
}
.dep-item:hover { border-left-color: var(--clr-primary); }

.cat-item {
  padding-left: 20px;
  color: var(--clr-muted);
  font-size: var(--text-sm);
  border-left: 1px solid var(--clr-border);
  margin-left: 12px;
}
.cat-item:hover { color: var(--clr-text); }

.btn-tree-filter { flex-grow: 1; cursor: pointer; text-align: left; }
.btn-tree-toggle {
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 8px;
  background: var(--clr-primary-dim);
  color: var(--clr-primary);
  font-size: var(--text-xs);
  margin-left: 8px;
  border: none;
  transition: background 0.2s;
}
.btn-tree-toggle:hover { background: rgba(99,102,241,0.15); }

/* ============================================================
   14. DEBT BAR
   ============================================================ */
.debt-bar {
  height: 10px;
  background: var(--clr-primary-light);
  border-radius: var(--radius-pill);
  overflow: hidden;
}

#deudaPctLabel {
  font-size: 24px !important;
  font-weight: 500 !important;
  line-height: 1.1 !important;
}
#deudaRefLabel {
  font-size: var(--text-xs) !important;
  color: var(--clr-muted) !important;
}
#deudaAbonosLabel {
  font-size: var(--text-xs) !important;
}

.debt-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: var(--radius-pill);
  background: var(--clr-primary);
  transition: width 0.8s cubic-bezier(0.4,0,0.2,1);
}
.debt-bar-fill.warn { background: var(--clr-amarillo); }
.debt-bar-fill.good { background: var(--clr-verde); }

/* ============================================================
   15. ABC BADGES — pill shape
   ============================================================ */
.badge-abc-a { background-color: rgba(16,185,129,0.12); color: var(--clr-verde); font-weight: 500; border: 1px solid rgba(16,185,129,0.25); border-radius: var(--radius-pill); }
.badge-abc-b { background-color: rgba(59,130,246,0.12); color: var(--clr-azul);  font-weight: 500; border: 1px solid rgba(59,130,246,0.25); border-radius: var(--radius-pill); }
.badge-abc-c { background-color: rgba(107,114,128,0.10); color: var(--clr-muted); font-weight: 500; border: 1px solid var(--clr-border); border-radius: var(--radius-pill); }

/* ============================================================
   16. STATUS BADGES / PILLS
   ============================================================ */
.badge-status-red    { background: #fef2f2; color: #991b1b; padding: 3px 10px; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: 500; }
.badge-status-yellow { background: #fffbeb; color: #92400e; padding: 3px 10px; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: 500; }
.badge-status-green  { background: #ecfdf5; color: #065f46; padding: 3px 10px; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: 500; }

/* ============================================================
   17. URGENCY (reorder)
   ============================================================ */
.urgency-red    { background-color: rgba(239,68,68,0.06)  !important; }
.urgency-yellow { background-color: rgba(245,158,11,0.06) !important; }
.urgency-green  { background-color: rgba(16,185,129,0.04) !important; }

/* ============================================================
   18. LOADER
   ============================================================ */
.loader {
  display: none;
  position: fixed;
  top: 0; left: 0;
  width: 100%;
  height: 3px;
  background: var(--clr-primary);
  z-index: 2000;
  animation: loading 1.5s infinite;
}
@keyframes loading {
  0%   { left: -100%; width: 100%; }
  100% { left: 100%;  width: 100%; }
}

/* ============================================================
   19. LOGIN — One UI 8 centered card
   ============================================================ */
#loginScreen {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 16px;
  background: var(--clr-bg);
}
#dashboardScreen { display: none; }

.login-card {
  background: var(--clr-card);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  max-width: 360px;
  width: 100%;
  box-shadow: var(--shadow-card);
}
.login-card h3 { text-align: center; margin-bottom: 20px; font-size: 20px; font-weight: 600 !important; }
.pin-input      { font-size: 24px !important; letter-spacing: 10px; text-align: center; border-radius: var(--radius-sm) !important; }
.login-error    { color: var(--clr-rojo); font-size: var(--text-sm); text-align: center; margin-top: 8px; display: none; }

/* ============================================================
   20. FORM CONTROLS
   ============================================================ */
.form-control {
  background-color: var(--clr-card) !important;
  border: 1px solid var(--clr-border) !important;
  color: var(--clr-text) !important;
  border-radius: var(--radius-sm) !important;
  font-family: 'Outfit', system-ui, sans-serif;
  font-size: var(--text-md);
  font-weight: 400;
}
.form-control:focus {
  background-color: var(--clr-card) !important;
  color: var(--clr-text) !important;
  border-color: var(--clr-primary) !important;
  box-shadow: 0 0 0 3px var(--clr-primary-dim) !important;
}

/* ============================================================
   21. P&L / NEGOCIO — override hardcoded dark styles
   ============================================================ */
.pl-row   { display: flex; justify-content: space-between; padding: 4px 14px; font-size: var(--text-sm); }
.pl-row:hover { background: var(--clr-primary-dim); border-radius: 6px; }

.pl-header    { color: var(--clr-primary); font-weight: 500; font-size: var(--text-xs); letter-spacing: 0.08em; text-transform: uppercase; padding: 8px 14px 2px; }
.pl-total     { border-top: 1px solid var(--clr-border); font-weight: 500; padding: 4px 14px; display: flex; justify-content: space-between; font-size: var(--text-sm); }
.pl-grand     { border-top: 2px solid var(--clr-primary); font-weight: 500; font-size: 15px; padding: 6px 14px; display: flex; justify-content: space-between; }
.pl-separator { border-top: 1px dashed var(--clr-border); margin: 4px 0; }

.negocio-selector .btn { font-size: var(--text-xs); border-radius: var(--radius-pill); padding: 5px 14px; font-weight: 400; }
.negocio-selector .btn.active { background: var(--clr-primary) !important; color: #fff !important; border-color: var(--clr-primary) !important; }

/* Override Bootstrap bg-dark used in negocioTab.js */
.bg-dark {
  background-color: var(--clr-card) !important;
  color: var(--clr-text) !important;
}
.border-secondary {
  border-color: var(--clr-border) !important;
}

/* ============================================================
   22. ITEMS SEARCH
   ============================================================ */
.items-search-wrap { position: relative; }

.items-clear-btn {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  background: none; border: none; color: var(--clr-muted); cursor: pointer;
  font-size: var(--text-sm); padding: 4px 8px; line-height: 1; transition: color 0.15s;
}
.items-clear-btn:hover { color: var(--clr-text); }

.item-margin-bar  { height: 4px; background: var(--clr-border); border-radius: var(--radius-pill); overflow: hidden; margin-bottom: 10px; }
.item-margin-fill { height: 100%; border-radius: var(--radius-pill); transition: width 0.4s ease; }

.item-details { padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--clr-border); background: var(--clr-bg); font-size: var(--text-sm); }

@media (max-width: 768px) {
  .items-search-section { position: sticky; top: 0; z-index: 100; background: var(--clr-bg); padding-bottom: 8px; }
}

/* ============================================================
   23. MODAL
   ============================================================ */
.modal-content {
  background: var(--clr-card) !important;
  color: var(--clr-text) !important;
  border: 1px solid var(--clr-border) !important;
  border-radius: var(--radius-md) !important;
}
.modal-header { border-color: var(--clr-border) !important; padding: 12px 16px; }
.modal-title  { font-size: var(--text-sm) !important; font-weight: 500 !important; color: var(--clr-text) !important; letter-spacing: 0.06em; text-transform: uppercase; }

/* ============================================================
   24. ERROR BANNER
   ============================================================ */
#apiError {
  background-color: rgba(239,68,68,0.08) !important;
  color: var(--clr-rojo) !important;
  border: 1px solid rgba(239,68,68,0.2) !important;
  border-left: 3px solid var(--clr-rojo) !important;
  border-radius: var(--radius-sm) !important;
  font-size: var(--text-sm) !important;
}

/* ============================================================
   25. MOBILE RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  .header-row-top                  { flex-wrap: wrap; gap: 6px; }
  .header-row-top h5               { font-size: 12px !important; white-space: nowrap; }
  .header-row-top > .d-flex        { order: 1; }
  .header-row-top #btnTheme        { order: 1; margin-left: auto; }
  .header-row-top .btn-logout      { order: 1; }
  #lblUpdated                      { display: none !important; }

  .header-row-top .nav-pills {
    order: 2;
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 2px;
    scrollbar-width: none;
  }
  .header-row-top .nav-pills::-webkit-scrollbar { display: none; }
  .header-row-top .nav-pills .nav-link { font-size: 12px !important; padding: 5px 10px !important; white-space: nowrap; }

  .header-row-controls                   { justify-content: center; gap: 4px; }
  .date-group input[type="date"]          { width: 94px; font-size: 12px; }
  .btn-ver                                { font-size: 12px; padding: 0 10px; }
  .quick-pill                             { font-size: 12px; padding: 0 8px; }

  .kpi-card               { padding: 10px 12px !important; }
  .kpi-value              { font-size: 18px !important; }
  #kpiNeta                { font-size: 20px !important; }

  .macro-pills {
    padding: 3px;
    overflow-x: auto;
    scrollbar-width: none;
    width: 100%;
    justify-content: flex-start;
  }
  .macro-pills::-webkit-scrollbar { display: none; }
  .macro-btn { font-size: 12px !important; padding: 4px 8px !important; white-space: nowrap; }

  .col-md-6, .col-md-7, .col-md-5 { flex: 0 0 100%; max-width: 100%; }
  .card [id^="chart"]             { height: 200px !important; }
  #chartProfit, #chartMarginPct   { height: 200px !important; }

  #tab-exp > .d-flex { flex-direction: column; }
  .tree-sidebar {
    width: 100%;
    min-height: auto;
    max-height: 35vh;
    overflow-y: auto;
    border-right: none;
    border-bottom: 1px solid var(--clr-border);
    border-radius: var(--radius-md);
  }
  #tab-exp .flex-grow-1 { padding-left: 0 !important; padding-top: 10px; }
  .tree-item            { min-height: 44px; }

  #buyBars { padding: 8px; }
  .content-area { padding: 8px; }
}

/* ============================================================
   26. ANIMACIONES Y HOVER
   ============================================================ */
.kpi-card {
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  opacity: 0;
  transform: translateY(16px);
  animation: cardEnter 0.5s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}
@keyframes cardEnter {
  to { opacity: 1; transform: translateY(0); }
}
.row.g-3 > *:nth-child(1) .kpi-card { animation-delay: 0ms; }
.row.g-3 > *:nth-child(2) .kpi-card { animation-delay: 50ms; }
.row.g-3 > *:nth-child(3) .kpi-card { animation-delay: 100ms; }
.row.g-3 > *:nth-child(4) .kpi-card { animation-delay: 150ms; }
.row.g-3 > *:nth-child(5) .kpi-card { animation-delay: 200ms; }
.row.g-3 > *:nth-child(6) .kpi-card { animation-delay: 250ms; }

@media (hover: hover) and (pointer: fine) {
  .kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-hover) !important;
    transition: transform 160ms var(--ease-out), box-shadow 160ms ease-out;
  }
}

/* Chart cards: never apply opacity animation (breaks Plotly rendering) */
.card.p-3 { opacity: 1 !important; animation: none !important; }

.tab-pane.show { animation: tabFadeIn 150ms ease-out both; }
@keyframes tabFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.table tbody tr { transition: background 0.15s ease; }

.macro-btn, .quick-pill, .nav-pills .nav-link {
  transition: transform 160ms cubic-bezier(0.23, 1, 0.32, 1),
              background-color 160ms ease-out,
              color 160ms ease-out,
              box-shadow 160ms ease-out;
}

/* Mini-cards ingreso por tipo */
.pays-mini-card {
  flex: 1;
  padding: 10px 14px;
  background: var(--clr-card);
  border: 1px solid var(--clr-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card);
}
.pays-mini-label {
  font-size: var(--text-xs);
  color: var(--clr-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}
.pays-mini-value {
  font-size: 18px;
  font-weight: 500;
  line-height: 1.1;
}

/* ============================================================
   27. PLOTLY CHART OVERRIDES
   ============================================================ */
.js-plotly-plot { border-radius: var(--radius-sm); }
.hoverlayer .hovertext rect { rx: 8px !important; }
.card.p-3 { padding: 20px !important; }
.js-plotly-plot .plot-container { border-radius: var(--radius-sm); overflow: visible; }

/* ============================================================
   28. SCROLLBAR — minimal
   ============================================================ */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--clr-border); border-radius: var(--radius-pill); }
::-webkit-scrollbar-thumb:hover { background: var(--clr-muted); }

/* ============================================================
   29. FOCUS VISIBLE — Accessibility
   ============================================================ */
:focus-visible {
  outline: 2px solid var(--clr-primary);
  outline-offset: 2px;
  border-radius: 4px;
}

button:focus-visible, .btn:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--clr-primary);
  outline-offset: 2px;
}

/* ============================================================
   30. REDUCED MOTION — Accessibility
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
