/* ─── styles.css - Estilos principales ──────────────────────────────────── */

/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--color-bg);
  color: var(--color-text);
  display: flex;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background .2s, color .2s;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */

.sidebar {
  width: 248px;
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: width .28s cubic-bezier(.4,0,.2,1), transform .28s cubic-bezier(.4,0,.2,1);
  overflow: hidden;
  border-right: 1px solid rgba(255,255,255,.04);
}

/* Colapsar sidebar */
.sidebar.collapsed { width: 68px; }
.sidebar.collapsed .logo-text,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-section,
.sidebar.collapsed .nav-divider + .nav-section,
.sidebar.collapsed .sidebar-version { display: none; }
.sidebar.collapsed .logo { justify-content: center; }
.sidebar.collapsed .logo-icon-wrap { margin: 0; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 12px; }
.sidebar.collapsed .nav-item::before { display: none; }
.sidebar.collapsed .theme-toggle { justify-content: center; }
.sidebar.collapsed .sidebar-toggle { margin: 0 auto; }

/* Header del sidebar */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,.05);
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  overflow: hidden;
}

.logo-icon-wrap {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(99,102,241,.4);
}

.logo-text {
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  letter-spacing: -.01em;
}

.sidebar-toggle {
  background: none;
  border: none;
  color: var(--sidebar-text);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-xs);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
  flex-shrink: 0;
}
.sidebar-toggle:hover { background: var(--sidebar-hover); color: #fff; }

/* Navegación */
.sidebar-nav {
  flex: 1;
  padding: 12px 10px;
  overflow-y: auto;
  overflow-x: hidden;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s;
  white-space: nowrap;
  margin-bottom: 2px;
  position: relative;
  border-left: 2px solid transparent;
}

.nav-item:hover {
  background: var(--sidebar-hover);
  color: var(--sidebar-text-2);
}

.nav-item.active {
  background: var(--sidebar-active);
  color: #fff;
  border-left-color: var(--sidebar-active-border);
  font-weight: 600;
}

.nav-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: .8;
}
.nav-item.active .nav-icon { opacity: 1; }

.nav-divider {
  height: 1px;
  background: rgba(255,255,255,.05);
  margin: 12px 4px;
}

.nav-section {
  display: block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--sidebar-text);
  padding: 4px 14px 8px;
  opacity: .5;
  white-space: nowrap;
}

/* Footer del sidebar */
.sidebar-footer {
  padding: 12px 10px 16px;
  border-top: 1px solid rgba(255,255,255,.05);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  color: var(--sidebar-text);
  cursor: pointer;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  transition: background .15s, color .15s;
  white-space: nowrap;
  flex: 1;
}
.theme-toggle:hover { background: var(--sidebar-hover); color: var(--sidebar-text-2); }

.sidebar-version {
  font-size: 10px;
  color: var(--sidebar-text);
  opacity: .4;
  white-space: nowrap;
  margin-left: 4px;
  flex-shrink: 0;
}

/* Overlay móvil */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  background: rgba(0,0,0,.6);
  z-index: 99;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.sidebar-overlay.active { display: block; }

/* ── Contenido principal ──────────────────────────────────────────────────── */

.main-content {
  flex: 1;
  margin-left: 248px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left .28s cubic-bezier(.4,0,.2,1);
}
.main-content.sidebar-collapsed { margin-left: 68px; }

/* ── Topbar ───────────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 28px;
  height: 64px;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--topbar-border);
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-xs);
}

.page-title {
  flex: 1;
  font-size: 18px;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -.02em;
}

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--color-text-2);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
.mobile-menu-btn:hover { background: var(--color-surface-2); }

.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* ── Área de página ─────────────────────────────────────────────────────── */

.page-container {
  flex: 1;
  padding: 28px;
  overflow-x: hidden;
}

/* ── Cards ────────────────────────────────────────────────────────────────── */

.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  padding: 24px;
  transition: box-shadow .2s;
}
.card:hover { box-shadow: var(--shadow); }

.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -.01em;
}

.card-subtitle {
  font-size: 12px;
  color: var(--color-text-3);
  margin-top: 3px;
}

/* ── Metric Cards ─────────────────────────────────────────────────────────── */

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.metric-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow-sm);
  transition: transform .2s, box-shadow .2s;
  cursor: default;
}
.metric-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.metric-label {
  font-size: 11px;
  color: var(--color-text-3);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.metric-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--color-text);
  letter-spacing: -.03em;
  line-height: 1.1;
}
.metric-value.positive { color: var(--color-success); }
.metric-value.negative { color: var(--color-danger); }

.metric-icon {
  font-size: 26px;
  margin-bottom: 4px;
  line-height: 1;
}

.metric-trend {
  font-size: 12px;
  color: var(--color-text-3);
  margin-top: 2px;
}

/* ── Charts grid ──────────────────────────────────────────────────────────── */

.charts-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.chart-wrapper {
  position: relative;
  height: 260px;
}

/* ── Tablas ───────────────────────────────────────────────────────────────── */

.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
  margin: 0 -4px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead th {
  background: var(--color-surface-2);
  color: var(--color-text-3);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .07em;
  padding: 10px 16px;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  border-bottom: 1px solid var(--color-border);
}
thead th:first-child { border-radius: var(--radius-sm) 0 0 0; }
thead th:last-child  { border-radius: 0 var(--radius-sm) 0 0; }
thead th:hover { color: var(--color-primary); }

tbody tr {
  border-bottom: 1px solid var(--color-border);
  transition: background .1s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--color-surface-2); }

tbody td {
  padding: 12px 16px;
  color: var(--color-text);
  vertical-align: middle;
}

/* ── Badges ───────────────────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
  white-space: nowrap;
}
.badge-success { background: var(--color-success-lt); color: var(--color-success); }
.badge-danger  { background: var(--color-danger-lt);  color: var(--color-danger); }
.badge-warning { background: var(--color-warning-lt); color: var(--color-warning); }
.badge-info    { background: var(--color-info-lt);    color: var(--color-info); }
.badge-neutral { background: var(--color-surface-2);  color: var(--color-text-2); }

/* ── Botones ──────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: all .18s;
  text-decoration: none;
  white-space: nowrap;
  letter-spacing: -.01em;
  line-height: 1.2;
}
.btn:active { transform: scale(.97); }
.btn svg { flex-shrink: 0; }

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
  box-shadow: 0 2px 8px rgba(99,102,241,.3);
}
.btn-primary:hover {
  background: var(--color-primary-dk);
  border-color: var(--color-primary-dk);
  box-shadow: var(--shadow-primary);
  transform: translateY(-1px);
}

.btn-success { background: var(--color-success); color: #fff; border-color: var(--color-success); }
.btn-danger  { background: var(--color-danger);  color: #fff; border-color: var(--color-danger);  box-shadow: 0 2px 8px rgba(239,68,68,.3); }
.btn-warning { background: var(--color-warning); color: #fff; border-color: var(--color-warning); }

.btn-outline {
  background: transparent;
  border-color: var(--color-border);
  color: var(--color-text-2);
}
.btn-outline:hover {
  background: var(--color-surface-2);
  border-color: var(--color-border-2);
  color: var(--color-text);
}

.btn-ghost { background: transparent; border-color: transparent; color: var(--color-text-2); }
.btn-ghost:hover { background: var(--color-surface-2); color: var(--color-text); }

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }

/* ── Formularios ──────────────────────────────────────────────────────────── */

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-2);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.form-label .required { color: var(--color-danger); margin-left: 2px; }

.form-control {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
}
.form-control:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-lt);
}
.form-control::placeholder { color: var(--color-text-3); }
.form-control.error { border-color: var(--color-danger); }

select.form-control {
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
}
.form-grid .form-full { grid-column: 1 / -1; }

/* ── Filtros ──────────────────────────────────────────────────────────────── */

.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin-bottom: 20px;
  padding: 16px 20px;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-xs);
}
.filters-bar .form-group { margin-bottom: 0; min-width: 110px; }
.filters-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-left: auto;
}

/* Separador visual entre grupos de filtros */
.filters-bar .filters-sep {
  width: 1px;
  height: 32px;
  background: var(--color-border);
  align-self: flex-end;
  margin: 0 4px;
}

/* ── Multiselect dropdown ─────────────────────────────────────────────────── */

.ms-wrap {
  position: relative;
  min-width: 130px;
}
.ms-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  text-align: left;
  cursor: pointer;
  background: var(--color-surface);
  border: 1px solid var(--color-border-2);
  border-radius: var(--radius-sm);
  padding: 7px 10px;
  font-size: 13px;
  color: var(--color-text);
  font-family: inherit;
  transition: border-color .15s;
  white-space: nowrap;
  overflow: hidden;
}
.ms-btn:hover              { border-color: var(--color-primary); }
.ms-wrap.ms-open .ms-btn  { border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-lt,rgba(99,102,241,.15)); }
.ms-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.ms-arrow { font-size: 10px; color: var(--color-text-3); flex-shrink: 0; transition: transform .15s; }
.ms-wrap.ms-open .ms-arrow { transform: rotate(180deg); }
.ms-badge {
  background: var(--color-primary);
  color: #fff;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  flex-shrink: 0;
}

.ms-panel {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 100%;
  max-height: 240px;
  overflow-y: auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  z-index: 200;
  padding: 4px 0;
}
.ms-wrap.ms-open .ms-panel { display: block; }
.ms-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  font-size: 13px;
  color: var(--color-text);
  cursor: pointer;
  user-select: none;
  transition: background .1s;
  white-space: nowrap;
}
.ms-option:hover { background: var(--color-surface-2); }
.ms-option input[type="checkbox"] { width: 14px; height: 14px; accent-color: var(--color-primary); cursor: pointer; flex-shrink: 0; }
.ms-divider { height: 1px; background: var(--color-border); margin: 4px 0; }

/* ── Date range ───────────────────────────────────────────────────────────── */

.date-range-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.date-range-group .form-control { min-width: 130px; }
.date-range-group .form-control:disabled { opacity: .45; }
.date-all-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--color-text-2);
  cursor: pointer;
  white-space: nowrap;
}
.date-all-label input { accent-color: var(--color-primary); cursor: pointer; }

/* ── Monto range ──────────────────────────────────────────────────────────── */

.monto-range-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.monto-range-group .form-control { min-width: 90px; max-width: 120px; }
.monto-sep,
.date-sep {
  padding-bottom: 9px;
  color: var(--color-text-3);
  font-size: 12px;
  flex-shrink: 0;
}

/* ── Paginación ───────────────────────────────────────────────────────────── */

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 20px;
  padding: 0 4px;
}
.pagination button {
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-2);
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  transition: all .15s;
  min-width: 32px;
}
.pagination button:hover { background: var(--color-surface-2); color: var(--color-text); }
.pagination button.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
  box-shadow: 0 2px 6px rgba(99,102,241,.35);
}
.pagination button:disabled { opacity: .35; cursor: not-allowed; }

/* ── Modal ────────────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  background: rgba(0,0,0,.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 580px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  animation: modalIn .22s cubic-bezier(.34,1.56,.64,1);
  border: 1px solid var(--color-border);
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(.93) translateY(-12px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 26px 18px;
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.modal-title { font-size: 16px; font-weight: 700; letter-spacing: -.02em; }

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text-3);
  padding: 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
}
.modal-close:hover { background: var(--color-danger-lt); color: var(--color-danger); }

.modal-body {
  padding: 22px 26px;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 16px 26px;
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

/* ── Modal wide ───────────────────────────────────────────────────────────── */

.modal.modal-wide { max-width: 860px; }

/* ── Pago de corte ────────────────────────────────────────────────────────── */

.pago-corte-wrap {
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.pago-corte-controls {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}
.pago-corte-resultados {
  max-height: 380px;
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
.pago-corte-table-wrap { overflow-x: auto; }
.pago-corte-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.pago-corte-table thead th {
  position: sticky;
  top: 0;
  background: var(--color-surface-2);
  padding: 9px 12px;
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--color-text-2);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}
.pago-corte-table tbody tr {
  border-bottom: 1px solid var(--color-border-2);
  transition: background .1s;
}
.pago-corte-table tbody tr:last-child { border-bottom: none; }
.pago-corte-table tbody tr:hover { background: var(--color-surface-2); }
.pago-corte-table tbody td { padding: 8px 12px; vertical-align: middle; }
.pago-corte-table input[type="checkbox"] {
  width: 15px; height: 15px;
  accent-color: var(--color-primary);
  cursor: pointer;
}
.pc-plazo-old   { color: var(--color-text-3); }
.pc-plazo-arrow { color: var(--color-text-3); margin: 0 4px; font-size: 11px; }
.pc-plazo-new   { font-weight: 600; color: var(--color-primary); }
.pc-pagado-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 700;
  background: var(--color-success-lt, #d1fae5);
  color: var(--color-success, #059669);
}
.pago-corte-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 4px;
  flex-wrap: wrap;
}
.pago-corte-resumen {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
}

/* Botón pagar corte en barchart */
.tdc-bar-pay-btn {
  margin-left: auto;
  font-size: 11px;
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border-2);
  background: transparent;
  color: var(--color-primary);
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.tdc-bar-pay-btn:hover {
  background: var(--color-primary-lt, rgba(99,102,241,.1));
  border-color: var(--color-primary);
}

/* ── Toasts ───────────────────────────────────────────────────────────────── */

.toast-container {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-radius: var(--radius);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  font-weight: 500;
  min-width: 280px;
  max-width: 380px;
  animation: toastIn .28s cubic-bezier(.34,1.56,.64,1);
  color: var(--color-text);
  pointer-events: all;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(24px) scale(.95); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}
.toast.removing { animation: toastOut .2s ease forwards; }
@keyframes toastOut {
  to { opacity: 0; transform: translateX(24px); }
}

.toast-success { border-left: 4px solid var(--color-success); }
.toast-error   { border-left: 4px solid var(--color-danger);  }
.toast-warning { border-left: 4px solid var(--color-warning); }
.toast-info    { border-left: 4px solid var(--color-info);    }

/* ── Estados vacíos y carga ─────────────────────────────────────────────── */

.empty-state, .loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 20px;
  color: var(--color-text-3);
  gap: 14px;
  text-align: center;
}
.empty-state-icon { font-size: 52px; opacity: .7; }
.empty-state-text { font-size: 15px; font-weight: 600; color: var(--color-text-2); }
.empty-state-sub  { font-size: 13px; }

.spinner {
  width: 38px;
  height: 38px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  -webkit-animation: spin .75s linear infinite;
  animation: spin .75s linear infinite;
}
@-webkit-keyframes spin { to { -webkit-transform: rotate(360deg); transform: rotate(360deg); } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Progress bar ─────────────────────────────────────────────────────────── */

.progress-bar {
  height: 6px;
  background: var(--color-surface-2);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 99px;
  transition: width .45s ease;
  background: linear-gradient(90deg, var(--color-primary), #8b5cf6);
}
.progress-fill.over { background: linear-gradient(90deg, #ef4444, #f97316); }
.progress-fill.warn { background: linear-gradient(90deg, var(--color-warning), #f97316); }

/* ── TDC Bar Chart ────────────────────────────────────────────────────────── */

.tdc-barchart-card {
  margin-bottom: 24px;
}

/* ── Tabs del card resumen TDC ───────────────────────────────────────────── */

.tdc-tab-nav {
  display: flex;
  gap: 2px;
  background: var(--color-surface-2);
  border-radius: var(--radius);
  padding: 3px;
  margin-left: auto;
}
.tdc-tab-btn {
  padding: 5px 14px;
  border-radius: calc(var(--radius) - 2px);
  border: none;
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-2);
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.tdc-tab-btn.active {
  background: var(--color-surface);
  color: var(--color-primary);
  box-shadow: 0 1px 3px rgba(0,0,0,.1);
}
.tdc-tab-panel { display: none; }
.tdc-tab-panel.active { display: block; }

/* ── Panel Pagos del mes ─────────────────────────────────────────────────── */

.pagos-mes-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px 6px;
  border-bottom: 1px solid var(--color-border-2);
}
.pagos-mes-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-2);
  white-space: nowrap;
}
.pagos-mes-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.pagos-mes-table thead th {
  padding: 9px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--color-text-2);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface-2);
}
.pagos-mes-table tbody tr {
  border-bottom: 1px solid var(--color-border-2);
  transition: background .1s;
}
.pagos-mes-table tbody tr:last-child { border-bottom: none; }
.pagos-mes-table tbody tr:hover { background: var(--color-surface-2); }
.pagos-mes-table tbody td { padding: 10px 16px; vertical-align: middle; }
.pagos-mes-table tfoot td {
  padding: 10px 16px;
  border-top: 2px solid var(--color-border);
  font-weight: 700;
}
.pagos-dias-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  margin-left: 6px;
}
.pagos-dias-ok   { background: #d1fae5; color: #065f46; }
.pagos-dias-warn { background: #fef3c7; color: #92400e; }
.pagos-dias-late { background: #fee2e2; color: #991b1b; }

/* ── Totales y ponderación ────────────────────────────────────────────────── */
.tdc-totales {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.tdc-total-item {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
}
.tdc-total-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--color-text-3);
  font-weight: 600;
}
.tdc-total-val {
  font-size: 14px;
  font-weight: 700;
  color: var(--color-text);
}
.tdc-total-sep {
  width: 1px;
  height: 28px;
  background: var(--color-border);
  margin: 0 6px;
}
.tdc-ponderacion {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  padding: 5px 14px;
  border-radius: var(--radius);
  border: 2px solid;
  background: transparent;
  transition: border-color .3s, color .3s;
}
.tdc-pond-pct {
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.02em;
}
.tdc-pond-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}
.tdc-barchart {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 4px 0 8px;
}
.tdc-bar-row {
  display: flex;
  align-items: center;
  gap: 14px;
}
.tdc-bar-label {
  width: 170px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text);
}
.tdc-bar-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}
.tdc-bar-track {
  flex: 1 1 0;
  min-width: 0;
  height: 26px;
  background: var(--color-surface-2);
  border-radius: 6px;
  overflow: hidden;
  position: relative;
}
.tdc-bar-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 10px;
  min-width: 4px;
  transition: width .45s ease;
}
.tdc-bar-pct {
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
}
.tdc-bar-limit {
  flex-shrink: 0;
  white-space: nowrap;
  text-align: right;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
}
.tdc-bar-sub {
  font-size: 11.5px;
  color: var(--color-text-3);
  padding-left: 192px;
  padding-bottom: 10px;
  margin-top: 3px;
}

/* ── Account chips ────────────────────────────────────────────────────────── */

.account-chip {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  margin-bottom: 10px;
  transition: border-color .15s, background .15s;
}
.account-chip:last-child { margin-bottom: 0; }
.account-chip:hover { border-color: var(--color-primary-mid); background: var(--color-primary-lt); }

.account-chip-icon {
  font-size: 20px;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--color-primary), #8b5cf6);
  flex-shrink: 0;
}

.account-chip-info { flex: 1; min-width: 0; }
.account-chip-name { font-weight: 600; font-size: 13px; }
.account-chip-sub  { font-size: 11px; color: var(--color-text-3); margin-top: 1px; }
.account-chip-amount { font-weight: 800; font-size: 16px; text-align: right; }
.account-chip-amount.positive { color: var(--color-success); }
.account-chip-amount.negative { color: var(--color-danger); }

/* ── Tarjeta TDC visual ───────────────────────────────────────────────────── */

.credit-card-visual {
  border-radius: var(--radius-lg);
  padding: 20px;
  color: #fff;
  position: relative;
  overflow: hidden;
  min-height: 120px;
}
.credit-card-visual::before {
  content: '';
  position: absolute;
  top: -40px; right: -40px;
  width: 140px; height: 140px;
  border-radius: 50%;
  background: rgba(255,255,255,.1);
}
.credit-card-visual::after {
  content: '';
  position: absolute;
  bottom: -30px; right: 40px;
  width: 100px; height: 100px;
  border-radius: 50%;
  background: rgba(255,255,255,.06);
}

/* ── Tarjeta row dashboard ────────────────────────────────────────────────── */

.tarjeta-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--color-border);
}
.tarjeta-row:last-child { border-bottom: none; }
.tarjeta-color-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 0 6px currentColor;
}
.tarjeta-info { flex: 1; min-width: 0; }
.tarjeta-name { font-weight: 600; font-size: 13px; }
.tarjeta-sub  { font-size: 11px; color: var(--color-text-3); margin-top: 3px; }
.tarjeta-amounts { text-align: right; flex-shrink: 0; }
.tarjeta-used  { font-weight: 700; font-size: 14px; }
.tarjeta-limit { font-size: 11px; color: var(--color-text-3); }

/* ── Sección / cabecera ───────────────────────────────────────────────────── */

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.section-title { font-size: 16px; font-weight: 700; letter-spacing: -.02em; }

/* ── Acciones en tabla ────────────────────────────────────────────────────── */

.actions-cell { display: flex; gap: 6px; justify-content: flex-end; }
.btn-table {
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text-2);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn-table:hover { background: var(--color-surface-2); color: var(--color-text); }
.btn-table.danger:hover {
  background: var(--color-danger-lt);
  color: var(--color-danger);
  border-color: var(--color-danger);
}

/* ── Utilidades ───────────────────────────────────────────────────────────── */

.flex          { display: flex; }
.flex-1        { flex: 1; }
.items-center  { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2         { gap: 8px; }
.gap-3         { gap: 12px; }
.gap-4         { gap: 16px; }
.mt-4          { margin-top: 16px; }
.mb-4          { margin-bottom: 16px; }
.text-right    { text-align: right; }
.text-center   { text-align: center; }
.text-sm       { font-size: 12px; }
.text-muted    { color: var(--color-text-2); }
.text-danger   { color: var(--color-danger) !important; }
.font-bold     { font-weight: 700; }
.w-full        { width: 100%; }
.hidden        { display: none !important; }

/* ── Responsive ───────────────────────────────────────────────────────────── */

/* ── 1024px: tablet landscape / laptop pequeño ─────────────────────────── */
@media (max-width: 1024px) {
  .charts-grid { grid-template-columns: 1fr; }
  .chart-wrapper { height: 220px; }
  .metric-value { font-size: 24px; }
}

/* ── 900px: iPad landscape ──────────────────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar { width: 200px; }
  .main-content { margin-left: 200px; }
  .main-content.sidebar-collapsed { margin-left: 68px; }
  .metric-value { font-size: 22px; }
  .tdc-bar-label { width: 140px; font-size: 12px; }
  .tdc-bar-limit  { width: 90px;  font-size: 12px; }
  .tdc-bar-sub  { padding-left: 162px; font-size: 11px; }
}

/* ── 768px: tablet portrait / móvil grande ──────────────────────────────── */
@media (max-width: 768px) {
  /* Sidebar */
  .sidebar {
    transform: translateX(-100%);
    width: 248px !important;
    box-shadow: none;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  .main-content { margin-left: 0 !important; }
  .mobile-menu-btn { display: flex; }

  /* Topbar */
  .topbar { padding: 0 16px; height: 56px; }
  .page-title { font-size: 16px; }

  /* Layout */
  .page-container { padding: 16px; }
  .card { padding: 16px; }
  .card-header { flex-wrap: wrap; gap: 10px; }

  /* Métricas */
  .metrics-grid { grid-template-columns: 1fr 1fr; }
  .metric-value { font-size: 20px; }
  .metric-label { font-size: 10px; }

  /* Charts */
  .chart-wrapper { height: 200px; }
  .charts-grid { gap: 12px; }

  /* Formularios */
  .form-grid { grid-template-columns: 1fr; }
  .filters-bar { padding: 14px 16px; gap: 10px; }
  .filters-bar .form-group { min-width: calc(50% - 10px); flex: 1 1 calc(50% - 10px); }

  /* Tablas */
  table { font-size: 12px; }
  thead th { padding: 8px 12px; font-size: 10px; }
  tbody td { padding: 10px 12px; }

  /* Modales */
  .modal { max-width: 100%; width: calc(100% - 32px); }
  .modal-footer { flex-wrap: wrap; gap: 8px; }
  .modal-footer .btn { flex: 1 1 auto; text-align: center; }

  /* Paginación */
  .pagination { justify-content: center; flex-wrap: wrap; }

  /* TDC bar chart */
  .tdc-bar-label { width: 130px; font-size: 12px; }
  .tdc-bar-limit  { width: 85px;  font-size: 12px; }
  .tdc-bar-sub  { padding-left: 152px; font-size: 11px; }
  .tdc-bar-track { height: 22px; }
  .tdc-bar-pct { font-size: 11px; }

  /* Vacío */
  .empty-state { padding: 40px 16px; }
  .empty-state-icon { font-size: 36px; }
}

/* ── 480px: móvil ────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  /* Layout */
  .page-container { padding: 12px; }
  .card { padding: 14px; }

  /* Topbar */
  .topbar { height: 52px; }
  .page-title { font-size: 15px; }

  /* Métricas */
  .metrics-grid { grid-template-columns: 1fr; }
  .metric-value { font-size: 20px; }

  /* Filtros */
  .filters-bar { padding: 12px; gap: 8px; }
  .filters-bar .form-group { min-width: 100%; flex: 1 1 100%; }
  .filters-bar .btn { width: 100%; }

  /* Modales */
  .modal {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    align-self: flex-end;
    max-height: 95vh;
    width: 100%;
  }
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal-footer { flex-direction: column-reverse; }
  .modal-footer .btn { width: 100%; justify-content: center; }
  .modal-footer > div { width: 100%; display: flex; flex-direction: column; gap: 8px; }

  /* TDC bar chart: apila label sobre la barra */
  .tdc-bar-row { flex-wrap: wrap; gap: 6px; }
  .tdc-bar-label { width: 100%; justify-content: flex-start; font-size: 12px; }
  .tdc-bar-track { flex: 1 1 calc(100% - 90px); min-width: 0; height: 22px; }
  .tdc-bar-limit  { width: 80px; font-size: 12px; }
  .tdc-bar-sub  { padding-left: 0; font-size: 11px; margin-top: 0; padding-bottom: 12px; }

  /* Tablas */
  table { font-size: 12px; }
  tbody td { padding: 8px 10px; }
  thead th { padding: 7px 10px; }

  /* Botón tabla (···) */
  .btn-table { padding: 4px 6px; font-size: 15px; }

  /* Empty state */
  .empty-state { padding: 32px 12px; }
}

/* ── 375px: iPhone SE / pantallas pequeñas ──────────────────────────────── */
@media (max-width: 375px) {
  .page-container { padding: 10px; }
  .card { padding: 12px; }
  .topbar { height: 48px; }
  .page-title { font-size: 14px; }
  .metric-value { font-size: 18px; }
  .metric-label { font-size: 9px; }
  .filters-bar { padding: 10px; }
  table { font-size: 11px; }
  tbody td { padding: 7px 8px; }
  thead th { padding: 6px 8px; font-size: 9px; }
}

/* ── Fixes específicos de Safari ──────────────────────────────────────────── */

/* Safari: body con 100vh en iOS usa la altura visible (sin toolbar) */
@supports (-webkit-touch-callout: none) {
  body { min-height: -webkit-fill-available; }
  .sidebar { min-height: -webkit-fill-available; }
}

/* Safari: inputs de tipo date/number/color pueden ignorar estilos */
input[type="date"].form-control,
input[type="number"].form-control,
input[type="color"].form-control {
  -webkit-appearance: none;
  appearance: none;
}

/* Safari: animation de modal necesita translate3d para GPU acceleration */
@keyframes modalIn {
  from { opacity: 0; -webkit-transform: scale(.93) translateY(-12px); transform: scale(.93) translateY(-12px); }
  to   { opacity: 1; -webkit-transform: scale(1) translateY(0); transform: scale(1) translateY(0); }
}

/* Safari: scrollbars en sidebar */
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 99px; }

/* Safari: gap en flex con versiones antiguas – fallback con margins */
@supports not (gap: 8px) {
  .sidebar-nav .nav-item + .nav-item { margin-top: 2px; }
  .topbar-actions > * + * { margin-left: 8px; }
  .filters-bar > * + * { margin-left: 12px; }
  .actions-cell > * + * { margin-left: 6px; }
  .metrics-grid > * + * { margin-top: 16px; }
}
