/* ============================================================
   DASHBOARD-V2.CSS — Rediseño 2026
   Flat, minimal, sin gradientes, sin sombras
   ============================================================ */

/* ============================================================
   1. VARIABLES CSS
   ============================================================ */
:root {
  /* Backgrounds */
  --clr-bg: #f4f6fb;
  --clr-card: #ffffff;
  --clr-bg-secondary: #f0f2f8;
  --clr-border: #e2e8f0;

  /* Text */
  --clr-text: #1e1b4b;
  --clr-muted: #64748b;
  --clr-hints: #94a3b8;

  /* Purple palette */
  --clr-primary: #7c3aed;
  --clr-primary-dim: rgba(124,58,237,0.10);
  --clr-primary-light: #ede9fe;

  /* Semantic (mantener significado) */
  --clr-verde: #059669;
  --clr-azul: #3b82f6;
  --clr-amarillo: #d97706;
  --clr-rojo: #dc2626;
  --clr-morado: #7c3aed;
}

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

body {
  background-color: var(--clr-bg);
  color: var(--clr-text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  font-size: 14px;
  font-weight: 400;
  overflow-x: hidden;
  margin: 0;
}

h1, h2, h3, h4, h5, h6 {
  color: var(--clr-text) !important;
  font-weight: 500 !important;
  margin: 0;
}

/* Reducir pesos de Bootstrap */
.fw-bold { font-weight: 500 !important; }
.fw-bolder { font-weight: 500 !important; }
.small { font-size: 13px; }

/* ============================================================
   3. COLORES SEMÁNTICOS (override de clases existentes)
   ============================================================ */
.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-morado)   !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; }

/* ============================================================
   4. CARDS
   ============================================================ */
.card {
  background-color: var(--clr-card) !important;
  border: 0.5px solid var(--clr-border) !important;
  border-radius: 1rem !important;
  color: var(--clr-text) !important;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 16px rgba(124,58,237,0.06) !important;
}

.card-header {
  background: transparent !important;
  border-bottom: 0.5px solid var(--clr-border) !important;
  color: var(--clr-muted) !important;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 10px 14px;
}

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

/* ============================================================
   5. KPI CARDS
   ============================================================ */
.kpi-card {
  padding: 12px 14px !important;
  border-left-width: 3px !important;
}

.kpi-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--clr-muted);
}

.kpi-value {
  font-size: 22px;
  font-weight: 500;
  line-height: 1.15;
  margin: 5px 0 3px;
}

.kpi-sub {
  font-size: 11px;
  font-weight: 400;
  color: var(--clr-muted);
  font-style: normal;
}

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

/* Ocultar accent bar — reemplazada por border-left */
.kpi-accent-bar { display: none !important; }

/* Delta badge */
.kpi-delta {
  font-size: 10px;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 4px;
  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: #dc2626;             }
.kpi-delta.neutral { background: rgba(100,116,139,0.10); color: var(--clr-muted);    }
.kpi-delta.warn    { background: rgba(217,119,6,0.12);   color: var(--clr-amarillo); }

/* ============================================================
   6. HEADER STICKY
   ============================================================ */
.sticky-header {
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 0.5px solid var(--clr-border);
  padding: 8px 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: 26px;
  height: 26px;
  background: var(--clr-primary);
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
  font-size: 13px;
  color: #fff;
  flex-shrink: 0;
}

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

/* ============================================================
   7. NAV PILLS (TABS)
   ============================================================ */
.nav-pills {
  background: var(--clr-card) !important;
  border: 0.5px solid var(--clr-border) !important;
  border-radius: 8px !important;
  padding: 3px !important;
  gap: 2px !important;
  display: flex;
}

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

.nav-pills .nav-link:hover {
  color: var(--clr-text) !important;
  background: rgba(0,0,0,0.05) !important;
}

.nav-pills .nav-link.active {
  background-color: var(--clr-primary) !important;
  color: #fff !important;
}

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

.date-group input[type="date"] {
  background: transparent;
  border: none;
  color: var(--clr-text);
  font-size: 11px;
  font-family: 'Inter', 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: 11px;
  padding: 0 2px;
}

.btn-ver {
  background: var(--clr-primary);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 500;
  font-family: 'Inter', system-ui, sans-serif;
  padding: 0 14px;
  height: 30px;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: background 0.15s;
  text-transform: uppercase;
}
.btn-ver:hover { background: #6d28d9; }

.quick-pills {
  display: flex;
  background: var(--clr-card);
  border: 0.5px solid var(--clr-border);
  border-radius: 6px;
  overflow: hidden;
  height: 30px;
}

.quick-pill {
  background: transparent;
  border: none;
  border-right: 0.5px solid var(--clr-border);
  color: var(--clr-muted);
  font-size: 11px;
  font-weight: 500;
  font-family: 'Inter', system-ui, sans-serif;
  padding: 0 11px;
  height: 100%;
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.03em;
}
.quick-pill:last-child { border-right: none; }
.quick-pill:hover      { color: var(--clr-text); background: rgba(0,0,0,0.05); }
.quick-pill.active     { background: var(--clr-primary); color: #fff; }

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

.btn-logout {
  background: none !important;
  border: 0.5px solid var(--clr-border) !important;
  color: var(--clr-muted) !important;
  font-size: 11px !important;
  padding: 4px 10px !important;
  border-radius: 6px !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;
}
.btn-primary:hover { background-color: #6d28d9 !important; }

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

.macro-btn {
  border: none !important;
  background: transparent !important;
  color: var(--clr-muted) !important;
  font-size: 11px !important;
  font-weight: 500 !important;
  padding: 5px 12px !important;
  border-radius: 6px !important;
  transition: all 0.15s !important;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
}
.macro-btn:hover { color: var(--clr-text) !important; background: rgba(0,0,0,0.05) !important; }
.macro-btn.active { background: var(--clr-primary) !important; color: #fff !important; }
.sort-btn.active  { background: var(--clr-primary) !important; color: #fff !important; }

/* ============================================================
   11. CONTENT AREA Y SECTION LABELS
   ============================================================ */
.content-area { padding: 12px; }

.tab-section-title {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--clr-hints);
  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: 8px; --bs-gutter-y: 8px; }

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

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

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

/* Bootstrap table-dark override */
.table-dark {
  --bs-table-bg: transparent !important;
  --bs-table-hover-bg: rgba(0,0,0,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(0,0,0,0.03) !important; }

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

.tree-item {
  padding: 7px 10px;
  border-radius: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--clr-muted);
  margin-bottom: 1px;
  cursor: pointer;
  transition: all 0.12s;
}
.tree-item:hover  { background-color: rgba(0,0,0,0.04); 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(0,0,0,0.03);
  border-left: 2px solid var(--clr-border);
  font-weight: 500;
  color: var(--clr-text);
  font-size: 13px;
}
.dep-item:hover { border-left-color: var(--clr-primary); }

.cat-item {
  padding-left: 20px;
  color: var(--clr-muted);
  font-size: 12px;
  border-left: 0.5px 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 7px;
  border-radius: 4px;
  background: rgba(0,0,0,0.08);
  color: var(--clr-text);
  font-size: 11px;
  margin-left: 8px;
  border: none;
  transition: background 0.15s;
}
.btn-tree-toggle:hover { background: rgba(0,0,0,0.14); }

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

.debt-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 3px;
  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
   ============================================================ */
.badge-abc-a { background-color: rgba(29,158,117,0.15);  color: var(--clr-verde);    font-weight: 500; border: 0.5px solid rgba(29,158,117,0.3); }
.badge-abc-b { background-color: rgba(55,138,221,0.15);  color: var(--clr-azul);     font-weight: 500; border: 0.5px solid rgba(55,138,221,0.3); }
.badge-abc-c { background-color: rgba(100,100,100,0.12); color: var(--clr-muted);    font-weight: 500; border: 0.5px solid var(--clr-border);       }

/* ============================================================
   16. STATUS BADGES / PILLS
   ============================================================ */
.badge-status-red    { background: #FCEBEB; color: #791F1F; padding: 2px 7px; border-radius: 9px; font-size: 11px; font-weight: 400; }
.badge-status-yellow { background: #FAEEDA; color: #854F0B; padding: 2px 7px; border-radius: 9px; font-size: 11px; font-weight: 400; }
.badge-status-green  { background: #EAF3DE; color: #3B6D11; padding: 2px 7px; border-radius: 9px; font-size: 11px; font-weight: 400; }

/* light is now default — dark overrides removed */

/* ============================================================
   17. URGENCY (reorder)
   ============================================================ */
.urgency-red    { background-color: rgba(226,75,74,0.10)  !important; }
.urgency-yellow { background-color: rgba(239,159,39,0.08) !important; }
.urgency-green  { background-color: rgba(29,158,117,0.05) !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
   ============================================================ */
#loginScreen {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 16px;
}
#dashboardScreen { display: none; }

.login-card {
  background: var(--clr-card);
  border: 0.5px solid var(--clr-border);
  border-radius: 8px;
  padding: 32px;
  max-width: 340px;
  width: 100%;
}
.login-card h3 { text-align: center; margin-bottom: 20px; font-size: 18px; font-weight: 500 !important; }
.pin-input      { font-size: 22px !important; letter-spacing: 10px; text-align: center; }
.login-error    { color: var(--clr-rojo); font-size: 13px; text-align: center; margin-top: 8px; display: none; }

/* ============================================================
   20. FORM CONTROLS
   ============================================================ */
.form-control {
  background-color: var(--clr-card) !important;
  border: 0.5px solid var(--clr-border) !important;
  color: var(--clr-text) !important;
  border-radius: 6px !important;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  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: none !important;
}

/* ============================================================
   21. P&L / NEGOCIO
   ============================================================ */
.pl-row   { display: flex; justify-content: space-between; padding: 3px 12px; font-size: 13px; }
.pl-row:hover { background: rgba(0,0,0,0.02); }

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

.negocio-selector .btn        { font-size: 11px; border-radius: 20px; padding: 4px 12px; font-weight: 400; }
.negocio-selector .btn.active { background: var(--clr-morado) !important; color: #fff !important; border-color: var(--clr-morado) !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: 13px; padding: 4px 8px; line-height: 1; transition: color 0.15s;
}
.items-clear-btn:hover { color: var(--clr-text); }

.item-margin-bar  { height: 4px; background: rgba(0,0,0,0.06); border-radius: 2px; overflow: hidden; margin-bottom: 10px; }
.item-margin-fill { height: 100%; border-radius: 2px; transition: width 0.4s ease; }

.item-details { padding: 10px 12px; border-radius: 6px; border: 0.5px solid var(--clr-border); background: var(--clr-bg); font-size: 13px; }

@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: 0.5px solid var(--clr-border) !important;
  border-radius: 8px !important;
}
.modal-header { border-color: var(--clr-border) !important; padding: 10px 16px; }
.modal-title  { font-size: 13px !important; font-weight: 500 !important; color: var(--clr-text) !important; letter-spacing: 0.06em; text-transform: uppercase; }


/* ============================================================
   24. ERROR BANNER
   ============================================================ */
#apiError {
  background-color: rgba(226,75,74,0.12) !important;
  color: var(--clr-rojo) !important;
  border: 0.5px solid rgba(226,75,74,0.3) !important;
  border-left: 3px solid var(--clr-rojo) !important;
  border-radius: 8px !important;
  font-size: 13px !important;
}

/* ============================================================
   25. MOBILE RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  /* Header row 1 */
  .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; }

  /* Tabs — row 2, scroll horizontal */
  .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: 10px !important; padding: 5px 9px !important; white-space: nowrap; }

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

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

  /* Macro pills */
  .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: 10px !important; padding: 4px 8px !important; white-space: nowrap; }

  /* Charts full width */
  .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; }

  /* Explorer sidebar */
  #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: 0.5px solid var(--clr-border);
  }
  #tab-exp .flex-grow-1 { padding-left: 0 !important; padding-top: 10px; }
  .tree-item            { min-height: 44px; }

  /* Purchases */
  #buyBars { padding: 8px; }

  /* Content */
  .content-area { padding: 8px; }
}

/* ============================================================
   26. ANIMACIONES Y HOVER
   ============================================================ */

/* KPI card hover sutil */
.kpi-card {
  transition: transform 0.15s ease, border-color 0.15s ease;
}
.kpi-card:hover {
  transform: translateY(-1px);
}

/* Tab content fade-in */
.tab-pane.show { animation: fadeIn 0.2s ease; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Transiciones en filas de tabla */
.table tbody tr { transition: background 0.12s ease; }

/* Transición en botones de filtro */
.macro-btn, .quick-pill, .nav-pills .nav-link {
  transition: all 0.15s ease !important;
}

/* ============================================================
   27. MEJORAS VISUALES PLOTLY
   ============================================================ */

/* Fondo del área de gráfica — ya es transparente, pero aseguramos */
.js-plotly-plot { border-radius: 4px; }

/* Tooltips de Plotly — refuerzo via CSS donde sea posible */
.hoverlayer .hovertext rect { rx: 4px !important; }

/* Chart containers: padding consistente */
.card.p-3 { padding: 14px !important; }

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