/* =========================
   Design Tokens (CSS Variables)
   ========================= */
:root {
  /* Colores primarios */
  --color-primary: #4f46e5;
  --color-primary-hover: #4338ca;
  --color-primary-light: #e0e7ff;

  /* Colores de estado */
  --color-success: #16a34a;
  --color-success-light: #dcfce7;
  --color-success-border: #86efac;

  --color-warning: #f59e0b;
  --color-warning-light: #fef9c3;
  --color-warning-border: #fde047;

  --color-danger: #dc2626;
  --color-danger-light: #fee2e2;
  --color-danger-border: #fecaca;

  --color-info-light: #dbeafe;

  /* Grises */
  --color-text: #111;
  --color-text-secondary: #475569;
  --color-text-muted: #64748b;
  --color-text-light: #94a3b8;

  --color-bg: #f6f7fb;
  --color-bg-white: #fff;
  --color-bg-subtle: #f8fafc;
  --color-bg-hover: #f1f5f9;

  --color-border: #e2e8f0;
  --color-border-light: #f1f5f9;
  --color-border-dark: #d1d5db;

  /* Bordes redondeados */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 999px;

  /* Sombras */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -2px rgba(0,0,0,.1);

  /* Transiciones */
  --transition-fast: 0.15s ease;

  /* Tipografía */
  --font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif;
  --font-size-xs: 11px;
  --font-size-sm: 12px;
  --font-size-md: 13px;
  --font-size-xl: 16px;

  /* Espaciado */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 12px;
  --spacing-lg: 16px;
}

/* =========================
   Base
   ========================= */
* { box-sizing: border-box; }
.hidden { display: none !important; }

body {
  margin: 0;
  font-family: var(--font-family);
  color: var(--color-text);
  background: var(--color-bg);
}

/* =========================
   Header
   ========================= */
header {
  padding: var(--spacing-lg) var(--spacing-lg) var(--spacing-md);
  background: var(--color-bg-white);
  border-bottom: 1px solid var(--color-border);
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  align-items: center;
  gap: var(--spacing-md);
  width: 100%;
  box-sizing: border-box;
}

header .title { grid-column: 1; grid-row: 1; }
header .headerRight { grid-column: 2; grid-row: 1; justify-self: end; }
header .controls { grid-column: 1 / -1; grid-row: 2; }

.title {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  flex-wrap: wrap;
}

/* Botón volver al selector de módulos */
.backToSelector {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  text-decoration: none;
  transition: var(--transition-fast);
}
.backToSelector:hover {
  background: var(--color-primary-light);
  border-color: var(--color-primary);
  color: var(--color-primary);
}
.backToSelector svg { width: 18px; height: 18px; }

h1 { margin: 0; font-size: 22px; }
h3 { margin: 0 0 12px; font-size: 15px; font-weight: 700; }
h4 { margin: 0; font-size: 13px; font-weight: 700; color: var(--color-text-secondary); }
p { margin: 0; color: var(--color-text-secondary); }

/* Header con usuario y logout */
.headerRight {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-left: auto;
}
.userInfo {
  display: flex;
  align-items: center;
  gap: 12px;
}
.userDisplay {
  font-size: 13px;
  font-weight: 600;
  color: #1e40af;
  background: linear-gradient(135deg, #dbeafe 0%, #e0e7ff 100%);
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid #bfdbfe;
}
.logoutBtn {
  padding: 8px 16px;
  background: #fff;
  border: 1px solid #e5e7ef;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  color: #666;
  cursor: pointer;
  transition: var(--transition-fast);
}
.logoutBtn:hover {
  background: #fff5f5;
  border-color: #fecaca;
  color: #b91c1c;
}
.btnAjustes {
  font-size: 18px;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition-fast);
  padding: 0;
  color: var(--color-text-muted);
}
.btnAjustes:hover {
  background: var(--color-bg-subtle);
  color: var(--color-text);
}

/* =========================
   Controles superiores
   ========================= */
.controls {
  margin-top: 4px;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 10px;
  width: 100%;
  box-sizing: border-box;
}

@media (min-width: 769px) {
  header {
    position: sticky;
    top: 0;
    z-index: 100;
  }
}
.control label {
  display: block;
  font-size: 12px;
  color: #555;
  margin-bottom: 4px;
}
.control input,
.control select {
  width: 100%;
  padding: 10px;
  border: 1px solid #d7d9e5;
  border-radius: 10px;
  background: #fff;
  font-size: 13px;
}
.control input:focus,
.control select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}
.controlBtn {
  display: flex;
  align-items: flex-end;
}
.controls button {
  width: 100% !important;
  padding: 10px;
  border: 1px solid #d7d9e5;
  border-radius: 10px;
  background: #fff;
  font-size: 13px;
  cursor: pointer;
  font-weight: 600;
  color: var(--color-text-secondary);
  transition: var(--transition-fast);
  white-space: nowrap;
}
.controls button:hover {
  background: var(--color-bg-hover);
  border-color: var(--color-primary);
}

/* =========================
   Main
   ========================= */
main {
  margin: 0 auto;
  padding: var(--spacing-lg);
  width: 85%;
  max-width: 2000px;
}

/* =========================
   Botones generales
   ========================= */
button {
  cursor: pointer;
  font-weight: 700;
  padding: var(--spacing-md);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-white);
  transition: var(--transition-fast);
}
button:hover { filter: brightness(.98); }

.btnPrimary {
  padding: 10px 18px;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 13px;
}
.btnPrimary:hover { background: var(--color-primary-hover); }

.btnSecondary {
  padding: 10px 18px;
  background: var(--color-bg-white);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 13px;
}
.btnSecondary:hover { background: var(--color-bg-hover); }

.btnDanger {
  padding: 10px 18px;
  background: var(--color-danger-light);
  border: 1px solid var(--color-danger-border);
  color: var(--color-danger);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
}
.btnDanger:hover { background: #fee2e2; border-color: #fca5a5; }

.btnSmall { padding: 6px 12px !important; font-size: 12px !important; }
.btnIcon {
  background: none;
  border: none;
  font-size: 16px;
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
}
.btnIcon:hover { background: var(--color-bg-hover); }
.btnIcon.danger:hover { background: var(--color-danger-light); }

/* =========================
   Tarjetas / KPIs / Paneles
   ========================= */
.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}

.card,
.panel {
  background: var(--color-bg-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--spacing-md);
  box-shadow: var(--shadow-sm);
}

.kpiCard {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  overflow: hidden;
}
.kpiCard::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--color-primary) 0%, #818cf8 100%);
}
.kpiCard.kpiPendiente::before {
  background: linear-gradient(90deg, var(--color-warning) 0%, #fbbf24 100%);
}

.kpiLabel { font-size: var(--font-size-sm); color: var(--color-text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
.kpiValue { font-size: 22px; font-weight: 900; margin-top: var(--spacing-sm); }
.kpiSub { font-size: var(--font-size-sm); color: var(--color-text-muted); margin-top: var(--spacing-xs); }
.kpiPendiente .kpiValue { color: var(--color-warning); }

/* =========================
   Dashboard
   ========================= */
.dashboardGrid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--spacing-md); margin-bottom: var(--spacing-md); align-items: stretch; }

.panel h2 { font-size: 18px; }
.panelHeader {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 12px;
}

.chartPanel { padding: 20px; display: flex; flex-direction: column; }
.chartContainer { position: relative; width: 100%; flex: 1; min-height: 280px; }

/* Rankings */
.rankPanel { padding: 20px; display: flex; flex-direction: column; align-self: start; position: relative; }
.rankPanel h3 { margin-bottom: 12px; }
.rankPanel .rankList { overflow-y: auto; max-height: 340px; scrollbar-width: thin; scrollbar-color: #cbd5e1 transparent; padding-bottom: 8px; }
.rankPanel .rankList::-webkit-scrollbar { width: 6px; }
.rankPanel .rankList::-webkit-scrollbar-track { background: transparent; }
.rankPanel .rankList::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
.rankPanel .rankList::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
.rankPanel::after {
  content: '';
  position: absolute;
  bottom: 20px;
  left: 20px;
  right: 20px;
  height: 40px;
  background: linear-gradient(to bottom, transparent, rgba(255,255,255,0.95));
  pointer-events: none;
  border-radius: 0 0 10px 10px;
  transition: opacity 0.2s;
}
.rankPanel.scrolledEnd::after { opacity: 0; }
.rankList { display: flex; flex-direction: column; gap: 6px; }
.rankRow {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin: 3px 0;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--color-border-light);
  transition: all 0.2s ease;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  position: relative;
  overflow: hidden;
  flex-shrink: 0;
}
.rankRow::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: linear-gradient(180deg, var(--color-primary) 0%, #818cf8 100%);
  opacity: 0;
  transition: opacity 0.2s ease;
}
.rankRow:hover {
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  border-color: var(--color-border);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}
.rankRow:hover::before { opacity: 1; }
.rankRow:last-child { margin-bottom: 0; }

.rankLeft {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.rankName {
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text);
}
.rankName > span:last-child {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.rankPos, .rankIdx {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
  font-size: 12px;
  font-weight: 800;
  color: #64748b;
  flex-shrink: 0;
}
.rankPos.gold, .rankRow:nth-child(1) .rankIdx {
  background: linear-gradient(135deg, #fef08a 0%, #fde047 100%);
  color: #854d0e;
  box-shadow: 0 2px 6px rgba(253, 224, 71, 0.4);
}
.rankPos.silver, .rankRow:nth-child(2) .rankIdx {
  background: linear-gradient(135deg, #e5e7eb 0%, #d1d5db 100%);
  color: #4b5563;
}
.rankPos.bronze, .rankRow:nth-child(3) .rankIdx {
  background: linear-gradient(135deg, #fed7aa 0%, #fdba74 100%);
  color: #9a3412;
}

.rankBar {
  height: 5px;
  background: var(--color-bg-hover);
  border-radius: 999px;
  overflow: hidden;
}
.rankBar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary) 0%, #818cf8 100%);
  border-radius: 999px;
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}
.rankRow:nth-child(1) .rankBar span { background: linear-gradient(90deg, #eab308 0%, #facc15 100%); }
.rankRow:nth-child(2) .rankBar span { background: linear-gradient(90deg, #6b7280 0%, #9ca3af 100%); }
.rankRow:nth-child(3) .rankBar span { background: linear-gradient(90deg, #ea580c 0%, #fb923c 100%); }

.rankInfo { flex: 1; min-width: 0; }
.rankMeta { font-size: 11px; color: var(--color-text-muted); }
.rankAmount, .rankAmt {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: var(--color-primary);
  white-space: nowrap;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 8px;
}

/* =========================
   Departments
   ========================= */
.deptSection { margin-bottom: 16px; }
.deptPanel { padding: 20px; }
.deptCards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.deptCard { padding: 16px; border-radius: var(--radius-md); text-align: center; transition: var(--transition-fast); }
.deptCard:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.deptCard .deptName { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px; margin-bottom: 8px; }
.deptCard .deptAmount { font-size: 22px; font-weight: 800; }
.deptCard .deptCount { font-size: 11px; color: var(--color-text-muted); margin-top: 4px; }
.deptCard:nth-child(1) { background: #ede9fe; } .deptCard:nth-child(1) .deptName { color: #6d28d9; } .deptCard:nth-child(1) .deptAmount { color: #5b21b6; }
.deptCard:nth-child(2) { background: #dbeafe; } .deptCard:nth-child(2) .deptName { color: #1d4ed8; } .deptCard:nth-child(2) .deptAmount { color: #1e40af; }
.deptCard:nth-child(3) { background: #dcfce7; } .deptCard:nth-child(3) .deptName { color: #15803d; } .deptCard:nth-child(3) .deptAmount { color: #166534; }
.deptCard:nth-child(4) { background: #fef3c7; } .deptCard:nth-child(4) .deptName { color: #a16207; } .deptCard:nth-child(4) .deptAmount { color: #92400e; }
.deptCard:nth-child(n+5) { background: #f1f5f9; } .deptCard:nth-child(n+5) .deptName { color: #475569; } .deptCard:nth-child(n+5) .deptAmount { color: #334155; }

/* =========================
   Estimación anual
   ========================= */
.estimacionPanel { padding: 20px; display: flex; flex-direction: column; }
.estimacionPanel.hidden { display: none !important; }
.estimacionGrid { display: grid; grid-template-columns: repeat(2, 1fr); grid-template-rows: 1fr 1fr; gap: 10px; flex: 1; }
.estimCard { padding: 16px; border-radius: var(--radius-md); background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%); border: 1px solid #bfdbfe; text-align: center; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.estimCard .estimLabel { display: block; font-size: 11px; font-weight: 700; color: #1e40af; text-transform: uppercase; letter-spacing: .3px; margin-bottom: 6px; }
.estimCard .estimValue { font-size: 20px; font-weight: 800; color: #1d4ed8; }
.estimCardTotal { background: linear-gradient(135deg, #1e40af 0%, #2563eb 100%); border-color: #1e3a8a; }
.estimCardTotal .estimLabel { color: #bfdbfe; }
.estimCardTotal .estimValue { color: #fff; font-size: 24px; }

/* =========================
   Tabla detalle (estilo Impagos)
   ========================= */

/* topBar within the Detalle panel */
.topBar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 10px 0 12px;
  width: 100%;
  position: relative;
}

.actionsLeft {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.actionsInline {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

/* smallBtn base */
.smallBtn {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
  font-weight: 600;
  width: auto !important;
  transition: var(--transition-fast);
  cursor: pointer;
}

/* Primario (azul) — Nuevo trabajo */
.primaryBtn {
  width: auto !important;
  background: var(--color-primary) !important;
  color: #fff !important;
  border: 1px solid var(--color-primary) !important;
}
.primaryBtn:hover {
  background: var(--color-primary-hover) !important;
  border-color: var(--color-primary-hover) !important;
}

/* Ghost neutro (blanco) */
.ghostBtn {
  background: var(--color-bg-white) !important;
  color: var(--color-text-secondary) !important;
  border: 1px solid var(--color-border-dark) !important;
  font-weight: 600 !important;
  border-radius: var(--radius-sm);
  padding: var(--spacing-sm) var(--spacing-md);
  box-shadow: none !important;
  transition: var(--transition-fast);
}
.ghostBtn:hover {
  background: var(--color-bg-subtle) !important;
  border-color: #9ca3af !important;
  color: var(--color-text) !important;
}
.ghostBtn:active { background: var(--color-bg-hover) !important; }

/* Peligro (rojo) — Borrar */
.dangerBtn {
  background: var(--color-danger-light) !important;
  border-color: var(--color-danger-border) !important;
  color: var(--color-danger) !important;
  font-weight: 600 !important;
}
.dangerBtn:hover {
  background: #fee2e2 !important;
  border-color: #fca5a5 !important;
}

/* tableWrap (Impagos-style scrollable wrapper) */
.tableWrap {
  width: 100%;
  max-height: 70vh;
  overflow: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  background: var(--color-bg-white);
  box-shadow: var(--shadow-sm);
}

/* tableHeader inside panel */
.tableHeader {
  margin-bottom: 0;
}

.tableSection {
  background: #fff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.tableActions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
/* Search bar inside table section */
.tableToolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--color-bg-subtle);
  border-bottom: 1px solid var(--color-border);
  position: relative;
}
.tableToolbar .tableSearchBar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}
.tableSearchBar input {
  flex: 1;
  padding: 9px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 13px;
  background: #fff;
  transition: var(--transition-fast);
}
.tableSearchBar input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}
.tableSearchBar input::placeholder { color: var(--color-text-light); }
.tableSearchIcon { font-size: 15px; color: var(--color-text-muted); }
.tableActionsLeft, .tableActionsRight { display: flex; gap: 8px; flex-wrap: wrap; }
.tableScroll {
  width: 100%;
  overflow-x: auto;
  overflow-y: auto;
  max-height: calc(100vh - 160px);
}

.dataTable {
  width: 100%;
  min-width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-md);
  background: var(--color-bg-white);
}

/* Cabecera sticky */
.dataTable th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: #f8fafc;
  padding: 10px 12px;
  font-weight: 700;
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  border-bottom: 2px solid var(--color-border);
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
  user-select: none;
}

/* Celdas */
.dataTable td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border-light);
  vertical-align: middle;
  text-align: center;
  white-space: nowrap;
  font-size: var(--font-size-md);
}

/* Filas de datos */
.dataTable tbody tr {
  transition: background-color 0.15s ease;
  cursor: default;
}

/* Zebra striping */
.dataTable tbody tr:nth-child(even):not(.groupHeaderRow):not(.selected):not(.groupChildRow) {
  background-color: var(--color-bg-subtle);
}

/* Hover en filas */
.dataTable tbody tr:hover:not(.groupHeaderRow) td {
  background-color: var(--color-primary-light) !important;
}

/* Fila seleccionada */
.dataTable tbody tr.selected td {
  background-color: #dbeafe !important;
}

/* Sorting */
.sortable {
  cursor: pointer;
  position: relative;
  padding-right: 20px !important;
}
.sortable::after {
  content: "⇅";
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 10px;
  opacity: .4;
}
.sortActive::after { opacity: 1; content: "↑"; }
.sortActive.sortDesc::after { content: "↓"; }

.tdActions { display: flex; gap: 4px; justify-content: center; }
.clienteLink { color: var(--color-text); cursor: pointer; font-weight: 600; text-decoration: none; }
.clienteLink:hover { text-decoration: underline; color: var(--color-primary); }
.distribText { font-size: 12px; line-height: 1.4; text-align: center; }
.tableEmpty { text-align: center; padding: 40px; color: var(--color-text-muted); }
.emptyIcon { font-size: 48px; display: block; margin-bottom: 8px; }

.tableFooter {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: #fbfcff;
  border-top: 1px solid #eef0f7;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary);
}

/* Grouped table: client group header row */
.groupHeaderRow td {
  background: #f5f6f9 !important;
  border-top: 2px solid var(--color-border);
  border-bottom: 1px solid var(--color-border);
  padding: 8px 14px;
  font-weight: 800;
  font-size: 13px;
  color: var(--color-text);
  cursor: pointer;
  position: relative;
}
.groupHeaderRow:hover td {
  background: #eceef3 !important;
}
.groupHeaderRow .groupClienteName {
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
}
.groupHeaderRow .groupClienteCount {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-muted);
  background: #fff;
  padding: 2px 8px;
  border-radius: var(--radius-full);
}
.groupHeaderRow .groupTotal { font-weight: 800; color: var(--color-text); }
.groupHeaderRow .groupNif { font-size: 11px; font-weight: 500; color: var(--color-text-muted); margin-left: 8px; }

/* =========================
   Pagination
   ========================= */
.paginationControls { display: flex; align-items: center; gap: 4px; }
.btnPagination {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: #fff;
  cursor: pointer;
  font-size: 16px;
  font-weight: 700;
  color: var(--color-text-secondary);
  transition: var(--transition-fast);
}
.btnPagination:hover:not(:disabled) { background: var(--color-primary-light); color: var(--color-primary); border-color: var(--color-primary); }
.btnPagination:disabled { opacity: .35; cursor: default; }
.pagInfo { font-size: 13px; font-weight: 700; color: var(--color-text); padding: 0 8px; white-space: nowrap; }
.pagSizeSelect { padding: 5px 8px; border: 1px solid var(--color-border); border-radius: var(--radius-sm); font-size: 12px; font-weight: 600; color: var(--color-text); background: #fff; margin-left: 8px; cursor: pointer; }

/* =========================
   Selection bar
   ========================= */
.selectionBar { display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: #dbeafe; border-bottom: 1px solid #93c5fd; font-size: 13px; color: var(--color-text-secondary); border-radius: var(--radius-sm); margin: 8px 0; }
.selectionBar strong { font-weight: 800; color: var(--color-primary); }
.selectionBar .btnSelAction { padding: 5px 12px; border-radius: var(--radius-sm); font-size: 12px; font-weight: 600; border: 1px solid var(--color-border-dark); cursor: pointer; transition: var(--transition-fast); background: var(--color-bg-white); color: var(--color-text-secondary); }
.btnSelAction.deselect:hover { background: var(--color-bg-subtle); }

/* Table buttons compact inside table */
.tableWrap .smallBtn {
  padding: 4px 10px;
  font-size: var(--font-size-xs);
}

/* Column settings button (compact mode) */
.actionsInline .btnColSettings {
  display: inline-flex !important;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

/* Column settings dropdown (inside topBar) */
.colSettingsDropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  padding: 12px 0;
  z-index: 100;
  min-width: 220px;
  max-height: 400px;
  overflow-y: auto;
}

.tdSel input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--color-primary); }
.thSel { width: 44px !important; text-align: center; }
.thSel input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--color-primary); }
.tdCheck input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; accent-color: var(--color-primary); }

/* Checkbox scaling (like Impagos) */
.tableWrap input[type="checkbox"] { transform: scale(1.1); }
.tableScroll input[type="checkbox"] { transform: scale(1.1); }

/* Sel (checkbox) column */
.dataTable.newLayout thead th.thSel,
.dataTable.newLayout tbody td.tdSel {
  text-align: center;
  width: 44px;
}

/* Selected row highlight */
.dataTable.newLayout tbody tr.rowSelected td {
  background-color: #dbeafe !important;
}

/* =========================
   Badges
   ========================= */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid #e5e7ef;
  background: #fff;
  font-size: 12px;
  font-weight: 700;
}
.badge.iguala { background: #dbeafe; color: #1d4ed8; border-color: #93c5fd; }
.rowIguala { background: #f0f9ff !important; }
.rowIguala:hover { background: #e0f2fe !important; }
.badge.extraordinario { background: #dbeafe; color: #1d4ed8; border-color: #93c5fd; }
.badge.facturado { background: var(--color-success-light); color: var(--color-success); border-color: var(--color-success-border); }
.badge.pendiente { background: var(--color-warning-light); color: #92400e; border-color: var(--color-warning-border); }
.badge.suplido { background: #dbeafe; color: #1e40af; border-color: #93c5fd; }
.badge.gasto { background: #fef3c7; color: #92400e; border-color: #fde047; }

/* =========================
   Adjuntos / Suplidos
   ========================= */
.suplidoNum { font-weight: 700; color: #1d4ed8; cursor: pointer; padding: 4px 10px; border-radius: var(--radius-full); background: var(--color-info-light); font-size: 12px; transition: var(--transition-fast); display: inline-block; }
.suplidoNum:hover { background: #bfdbfe; }
.adjBadge { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border: 1px solid var(--color-border); border-radius: var(--radius-full); background: var(--color-info-light); color: #1d4ed8; font-size: 12px; font-weight: 700; cursor: pointer; transition: var(--transition-fast); }
.adjBadge:hover { background: #bfdbfe; border-color: #3b82f6; }
.adjNone { color: var(--color-text-light); font-size: 12px; }

/* Adjuntos popup */
.adjuntosPopup { position: absolute; z-index: 1500; width: 320px; max-height: 400px; overflow-y: auto; background: var(--color-bg-white); border: 1px solid var(--color-border); border-radius: var(--radius-lg); box-shadow: 0 12px 28px rgba(0,0,0,.15); padding: 0; }
.adjPopupHeader { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--color-border); background: var(--color-bg-subtle); }
.adjPopupHeader strong { font-size: 13px; }
.adjPopupList { padding: 8px; }
.adjPopupItem { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: var(--radius-sm); transition: var(--transition-fast); font-size: 12px; }
.adjPopupItem:hover { background: var(--color-bg-subtle); }
.adjPopupConcepto { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.adjPopupImporte { font-weight: 700; white-space: nowrap; color: var(--color-text-secondary); }
.adjDownload { text-decoration: none; font-size: 14px; transition: var(--transition-fast); }
.adjDownload:hover { transform: scale(1.2); }
.adjPopupTotal { padding: 6px 10px; font-size: 12px; color: var(--color-text-secondary); border-top: 1px solid var(--color-border-light); margin-top: 4px; }

/* =========================
   Modals
   ========================= */
.modalOverlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}
/* Ensure modalCliente sits above other modals (e.g. igualas) */
#modalCliente { z-index: 1100; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideIn { from { opacity: 0; transform: translateY(-20px) scale(0.95); } to { opacity: 1; transform: translateY(0) scale(1); } }

.modalBox {
  width: min(760px, 100%);
  background: #fff;
  border: none;
  border-radius: 16px;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,.25), 0 0 0 1px rgba(0,0,0,.05);
  overflow: hidden;
  animation: slideIn 0.25s ease;
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}
.modalLarge { width: min(850px, 95%); }
.modalSmall { width: min(480px, 95%); }

.modalHeader {
  padding: 18px 20px;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: linear-gradient(180deg, #fafbfc 0%, #fff 100%);
}
.modalHeader h2 { margin: 0; font-size: 18px; font-weight: 800; }
.modalTitle { font-size: 16px; font-weight: 700; color: #1e293b; }

.modalClose {
  border: 1px solid #e5e7eb;
  background: #fff;
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 600;
  font-size: 13px;
  color: #64748b;
  transition: all 0.15s ease;
}
.modalClose:hover { background: #f8fafc; border-color: #cbd5e1; color: #334155; }

.modalBody {
  padding: 20px;
  max-height: calc(80vh - 150px);
  overflow-y: auto;
  flex: 1;
}
.modalFooter {
  padding: 16px 20px;
  border-top: 1px solid #e5e7eb;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  background: #f8fafc;
}

/* Mini panels inside modals (Impagos style) */
.modalOverlay .miniBody {
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 12px;
}
.miniTitle { font-size: 13px; font-weight: 700; color: #374151; margin-bottom: 8px; }
.miniBody { font-size: 12px; color: #333; padding: 4px; }

/* =========================
   Forms
   ========================= */
.formRow { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.formGroup { display: flex; flex-direction: column; gap: 4px; }
.formGroup label { font-size: 12px; font-weight: 600; color: var(--color-text-secondary); }
.formGroup input, .formGroup select, .formGroup textarea { padding: 10px 12px; border: 1px solid var(--color-border); border-radius: var(--radius-md); font-size: 13px; font-family: inherit; background: var(--color-bg-white); transition: var(--transition-fast); }

input[type="number"] { -moz-appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.formGroup input:focus, .formGroup select:focus, .formGroup textarea:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-light); }
.formGroup input.invalid { border-color: var(--color-danger); box-shadow: 0 0 0 3px var(--color-danger-light); }
.formGroup select:disabled { background: #f1f5f9; color: var(--color-text-muted); cursor: not-allowed; opacity: .7; }

.fg1 { flex: 1; min-width: 140px; }
.fg2 { flex: 2; min-width: 200px; }
.fg3 { flex: 3; min-width: 250px; }
.fg6 { flex: 6; min-width: 100%; }

.formSection { margin-bottom: 20px; padding: 16px; background: var(--color-bg-subtle); border-radius: var(--radius-md); border: 1px solid var(--color-border-light); }
.formSectionHeader { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.mesAnioRow { display: flex; gap: 8px; }
.mesAnioRow select, .mesAnioRow input { padding: 10px 12px; border: 1px solid var(--color-border); border-radius: var(--radius-md); font-size: 13px; }

/* Dynamic rows */
.dynamicRows { display: flex; flex-direction: column; gap: 8px; }
.dynRow { display: flex; gap: 8px; align-items: center; }
.dynRow input, .dynRow select { padding: 8px 10px; border: 1px solid var(--color-border); border-radius: var(--radius-sm); font-size: 13px; }
.dynRow input:focus, .dynRow select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-light); }
.cptTareaTag { font-size: 10px; font-weight: 700; color: var(--color-primary); background: var(--color-primary-light); padding: 2px 6px; border-radius: 4px; white-space: nowrap; cursor: default; }

.totalRow { display: flex; justify-content: space-between; padding: 10px 0 0; margin-top: 8px; border-top: 1px solid var(--color-border); font-size: 14px; }
.distribDiff { font-size: 12px; font-weight: 700; }
.distribDiff.ok { color: var(--color-success); }
.distribDiff.error { color: var(--color-danger); }
.distribAssignAll { font-size: 11px; color: var(--color-primary); cursor: pointer; font-weight: 600; border: none; background: none; padding: 2px 6px; border-radius: 4px; transition: var(--transition-fast); }
.distribAssignAll:hover { background: var(--color-primary-light); }

.adjuntoRow { display: flex; gap: 8px; align-items: center; padding: 8px; background: var(--color-bg-white); border: 1px solid var(--color-border-light); border-radius: var(--radius-sm); }
.adjuntoRow .adjName { font-size: 12px; color: var(--color-primary); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Client link in trabajo modal */
.clienteLink {
  display: inline-block;
  margin-top: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-primary);
  text-decoration: none;
  transition: var(--transition-fast);
}
.clienteLink:hover {
  color: var(--color-primary-hover);
  text-decoration: underline;
}

.checkboxGroup { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.checkboxGroup label { display: flex; align-items: center; gap: 6px; padding: 8px 14px; border: 1px solid var(--color-border); border-radius: var(--radius-full); cursor: pointer; font-size: 13px; transition: var(--transition-fast); }
.checkboxGroup label:hover { background: var(--color-bg-hover); }
.checkboxGroup label:has(input:checked) { border-color: var(--color-primary); background: var(--color-primary-light); }
.checkboxGroup input:checked+span { color: var(--color-primary); font-weight: 700; }

/* =========================
   Cliente list / detalle
   ========================= */
.clienteSearchRow { display: flex; gap: 8px; margin-bottom: 16px; }
.clienteSearchRow input { flex: 1; padding: 10px 12px; border: 1px solid var(--color-border); border-radius: var(--radius-md); font-size: 13px; }
.clienteSearchRow input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-light); }
.listaClientes { display: flex; flex-direction: column; gap: 6px; max-height: 60vh; overflow-y: auto; }
.clienteItem { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border: 1px solid var(--color-border-light); border-radius: var(--radius-md); background: var(--color-bg-white); cursor: pointer; transition: var(--transition-fast); }
.clienteItem:hover { border-color: var(--color-primary); background: var(--color-primary-light); }
.clienteItemLeft { flex: 1; min-width: 0; }
.clienteItemName { font-weight: 700; font-size: 14px; }
.clienteItemMeta { font-size: 12px; color: var(--color-text-muted); margin-top: 2px; }
.clienteItemRight { display: flex; gap: 8px; align-items: center; }
.clienteItemStat { text-align: center; }
.clienteItemStat .val { font-size: 16px; font-weight: 800; color: var(--color-primary); }
.clienteItemStat .lbl { font-size: 10px; color: var(--color-text-muted); text-transform: uppercase; }
.clienteDetalleInfo { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; padding: 16px; background: var(--color-bg-subtle); border-radius: var(--radius-md); }
.detailField { display: flex; flex-direction: column; gap: 2px; }
.detailLabel { font-size: 11px; font-weight: 600; color: var(--color-text-muted); text-transform: uppercase; }
.detailValue { font-size: 14px; font-weight: 600; }
.clienteDetalleTrabajos { max-height: 50vh; overflow-y: auto; padding: 4px; }

/* Detalle trabajo cards */
.dtEmpty { text-align: center; padding: 32px 16px; color: var(--color-text-muted); }
.dtEmptyIcon { font-size: 40px; display: block; margin-bottom: 8px; }
.dtSummaryBar { display: flex; gap: 16px; align-items: center; padding: 12px 16px; margin-bottom: 12px; background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%); border-radius: var(--radius-md); border: 1px solid var(--color-border-light); font-size: 13px; }
.dtSummaryItem { color: var(--color-text-muted); }
.dtSummaryItem strong { color: var(--color-text); }
.dtFact strong { color: var(--color-success); }
.dtPend strong { color: var(--color-warning); }
.dtCard { border: 1px solid var(--color-border-light); border-radius: var(--radius-md); padding: 0; margin-bottom: 8px; cursor: pointer; transition: all .2s ease; overflow: hidden; background: var(--color-bg-white); position: relative; }
.dtCard::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; border-radius: 4px 0 0 4px; }
.dtCard--facturado::before { background: var(--color-success); }
.dtCard--pendiente::before { background: var(--color-warning); }
.dtCard:hover { border-color: var(--color-primary); box-shadow: 0 4px 12px rgba(79,70,229,.1); transform: translateY(-1px); }
.dtCardTop { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px 6px 20px; }
.dtCardBadges { display: flex; gap: 6px; }
.dtCardDate { font-size: 11px; color: var(--color-text-muted); font-weight: 600; }
.dtCardBody { display: flex; justify-content: space-between; align-items: center; padding: 2px 16px 8px 20px; gap: 12px; }
.dtCardConcepto { font-size: 13px; color: var(--color-text-secondary); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dtCardImporte { font-size: 16px; font-weight: 800; color: var(--color-text); white-space: nowrap; }
.dtCardAction { padding: 6px 16px 8px 20px; opacity: 0; transition: opacity .2s; }
.dtCard:hover .dtCardAction { opacity: 1; }
.dtCardOpen { font-size: 11px; font-weight: 700; color: var(--color-primary); text-transform: uppercase; letter-spacing: .3px; }

/* =========================
   Ajustes
   ========================= */
.ajustesTabs { display: flex; gap: 0; margin-bottom: 20px; background: var(--color-bg-subtle); border-radius: var(--radius-md); padding: 4px; border: 1px solid var(--color-border-light); }
.ajustesTab { padding: 10px 20px; border: none; background: transparent; font-size: 13px; font-weight: 600; color: var(--color-text-muted); cursor: pointer; border-radius: calc(var(--radius-md) - 2px); transition: all .2s ease; margin: 0; }
.ajustesTab.active { color: var(--color-primary); background: var(--color-bg-white); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.ajustesTab:hover:not(.active) { color: var(--color-text); background: rgba(255,255,255,.5); }
.ajustesAddRow { display: flex; gap: 8px; margin-bottom: 16px; padding: 12px 16px; background: linear-gradient(135deg, #f8fafc 0%, #eef2ff 100%); border-radius: var(--radius-md); border: 1px dashed var(--color-border); }
.ajustesAddRow input { flex: 1; padding: 10px 14px; border: 1px solid var(--color-border); border-radius: var(--radius-md); font-size: 13px; background: #fff; }
.ajustesAddRow input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-light); }
.ajustesList { display: flex; flex-direction: column; gap: 6px; }
.ajustesItem { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border: 1px solid var(--color-border-light); border-radius: var(--radius-md); background: var(--color-bg-white); transition: all .15s ease; }
.ajustesItem:hover { border-color: var(--color-primary-light); box-shadow: 0 2px 8px rgba(79,70,229,.06); }
.ajustesItem .itemName { flex: 1; font-size: 14px; font-weight: 700; color: var(--color-text); }

/* =========================
   Variables (inside Ajustes)
   ========================= */
.varGenList { display: flex; flex-direction: column; gap: 8px; }
.varGenItem { border: 1px solid var(--color-border); border-radius: var(--radius-md); overflow: hidden; }
.varGenHeader { display: flex; align-items: center; gap: 12px; padding: 14px 16px; background: var(--color-bg-subtle); cursor: pointer; transition: var(--transition-fast); }
.varGenHeader:hover { background: var(--color-bg-hover); }
.varGenName { flex: 1; font-size: 14px; font-weight: 700; }
.varPctBadge { padding: 3px 10px; border-radius: var(--radius-full); font-size: 12px; font-weight: 800; background: var(--color-primary-light); color: var(--color-primary); }
.varGenTotals { display: flex; gap: 16px; font-size: 12px; }
.varFact { color: var(--color-text-muted); }
.varAmount { color: var(--color-primary); font-weight: 700; }
.varToggleArrow { font-size: 12px; color: var(--color-text-muted); width: 20px; text-align: center; }
.varGenDetail { padding: 12px 16px; }
.varTable { width: 100%; border-collapse: collapse; font-size: 13px; }
.varTable th { text-align: left; padding: 8px 10px; background: var(--color-bg-subtle); border-bottom: 2px solid var(--color-border); font-size: 11px; font-weight: 700; color: var(--color-text-muted); text-transform: uppercase; }
.varTable td { padding: 8px 10px; border-bottom: 1px solid var(--color-border-light); }
.varTable tfoot td { border-top: 2px solid var(--color-border); background: var(--color-bg-subtle); font-weight: 700; }
.varEmpty td { color: var(--color-text-light); }
.varGrandTotal { display: flex; justify-content: space-between; align-items: center; padding: 16px; margin-top: 12px; background: linear-gradient(135deg, #ede9fe, #e0e7ff); border-radius: var(--radius-md); font-size: 14px; font-weight: 700; }
.pctInput { width: 80px; padding: 8px 12px; border: 2px solid var(--color-border); border-radius: var(--radius-md); font-size: 14px; text-align: center; font-weight: 800; color: var(--color-primary); background: var(--color-bg-white); transition: all .2s ease; appearance: textfield; -moz-appearance: textfield; }
.pctInput::-webkit-inner-spin-button, .pctInput::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.pctInput:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-light); background: #fff; }
.pctInput:hover { border-color: #a5b4fc; }

/* =========================
   Comparar igualas
   ========================= */
.compControls { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; padding-bottom: 16px; border-bottom: 1px solid var(--color-border); }
.compSelectors { display: flex; gap: 8px; align-items: flex-end; flex-wrap: wrap; }
.compVs { font-size: 13px; font-weight: 800; color: var(--color-text-muted); padding-bottom: 10px; }
.compMonth { margin-bottom: 12px; border: 1px solid var(--color-border-light); border-radius: var(--radius-md); overflow: hidden; }
.compMonthHeader { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--color-bg-subtle); font-size: 13px; }
.compMonthHeader.hasCambios { background: #fef3c7; }
.compMonthName { font-weight: 700; min-width: 80px; }
.compMonthStats { flex: 1; color: var(--color-text-muted); font-size: 12px; }
.compCambiosBadge { padding: 2px 10px; background: var(--color-warning); color: #fff; border-radius: var(--radius-full); font-size: 11px; font-weight: 700; }
.compChanges { padding: 8px 12px; }
.compChange { display: flex; align-items: center; gap: 10px; padding: 6px 8px; font-size: 12px; border-radius: var(--radius-sm); margin-bottom: 4px; }
.compChange.nueva { background: #dcfce7; }
.compChange.baja { background: #fee2e2; }
.compChange.modificada { background: #fef3c7; }
.compChangeTag { font-weight: 800; font-size: 11px; min-width: 70px; }
.compChange.nueva .compChangeTag { color: var(--color-success); }
.compChange.baja .compChangeTag { color: var(--color-danger); }
.compChange.modificada .compChangeTag { color: #92400e; }
.compChange span:nth-child(2) { flex: 1; }
.compNoCambios { padding: 20px; text-align: center; color: var(--color-text-muted); font-size: 13px; }

/* =========================
   Igualas result
   ========================= */
.igResultSummary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 20px; }
.igResultCard { padding: 16px; border-radius: var(--radius-md); text-align: center; }
.igResultCard.creadas { background: var(--color-success-light); color: var(--color-success); }
.igResultCard.modificadas { background: var(--color-warning-light); color: #92400e; }
.igResultCard.sinCambios { background: var(--color-bg-subtle); color: var(--color-text-muted); }
.igResultCard .igNum { font-size: 28px; font-weight: 800; display: block; }
.igResultCard .igLbl { font-size: 12px; font-weight: 600; }
.igResultSection { margin-bottom: 16px; }
.igResultSection h4 { margin-bottom: 8px; }
.igResultItem { display: flex; justify-content: space-between; padding: 6px 10px; font-size: 13px; border-bottom: 1px solid var(--color-border-light); }
.igResultItem:last-child { border-bottom: none; }

/* =========================
   Toast — Impagos style (dark solid bg)
   ========================= */
.toastContainer {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.toast {
  background: #1e293b;
  color: #f1f5f9;
  padding: 12px 20px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  font-size: 14px;
  font-weight: 600;
  max-width: 400px;
  pointer-events: auto;
  animation: toastIn 0.3s ease;
}
.toast.success { background: #059669; color: #fff; }
.toast.error { background: #dc2626; color: #fff; }
.toast.warning { background: #d97706; color: #fff; }
.toast.info { background: #2563eb; color: #fff; }

@keyframes toastIn { from { opacity: 0; transform: translateX(100%); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { from { opacity: 1; transform: translateX(0); } to { opacity: 0; transform: translateX(100%); } }
.toast.removing { animation: toastOut 0.3s ease forwards; }

/* =========================
   Custom Alerts / Confirms — Impagos style
   ========================= */
.alertOverlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10001;
  padding: 20px;
  animation: fadeIn 0.15s ease;
}
.alertBox {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
  padding: 28px 32px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  animation: slideIn 0.2s ease;
}
.alertIcon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  font-size: 28px;
  font-weight: bold;
}
.alertBox--warning .alertIcon { background: #fef3c7; color: #d97706; }
.alertBox--error .alertIcon, .alertBox--danger .alertIcon { background: #fee2e2; color: #dc2626; }
.alertBox--info .alertIcon { background: #dbeafe; color: #2563eb; }
.alertBox--success .alertIcon { background: #d1fae5; color: #059669; }
.alertMessage { font-size: 15px; color: #374151; line-height: 1.5; margin-bottom: 20px; word-break: break-word; }
.alertActions { display: flex; gap: 10px; justify-content: center; }
.alertBtn { padding: 10px 24px; border-radius: 10px; font-size: 14px; font-weight: 600; cursor: pointer; transition: all 0.15s ease; border: none; }
.alertBtn--cancel { background: #f3f4f6; color: #374151; border: 1px solid #e5e7eb; }
.alertBtn--cancel:hover { background: #e5e7eb; }
.alertBtn--confirm { background: var(--color-primary); color: #fff; }
.alertBtn--confirm:hover { background: var(--color-primary-hover); }
.alertBtn--confirm.alertBtn--danger { background: #dc2626; }
.alertBtn--confirm.alertBtn--danger:hover { background: #b91c1c; }

/* =========================
   Programación mensual igualas
   ========================= */
.progActions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 12px 16px; background: var(--color-bg-subtle); border-radius: var(--radius-md); border: 1px solid var(--color-border-light); }
.progActions label { font-size: 13px; font-weight: 600; color: var(--color-text-muted); }
.progActions input[type="number"] { padding: 6px 10px; border: 1px solid #d7d9e5; border-radius: 10px; font-size: 13px; background: #fff; }
.progGrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.progRow { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border: 1px solid #eef0f7; border-radius: 10px; background: #fff; transition: all .15s; }
.progRow.active { background: #dcfce7; border-color: #86efac; }
.progRow input[type="checkbox"] { margin: 0; cursor: pointer; width: 16px; height: 16px; accent-color: var(--color-primary); }
.progRow .progMesName { font-size: 13px; font-weight: 700; min-width: 55px; color: var(--color-text); }
.progRow .progImporte { flex: 1; padding: 6px 10px; border: 1px solid #d7d9e5; border-radius: 8px; text-align: right; font-size: 13px; font-family: inherit; width: 90px; background: #fff; }
.progRow .progImporte:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-light); }
.progRow .progImporte:disabled { background: #f8fafc; color: var(--color-text-muted); opacity: .5; }
.progRow .progCurrency { font-size: 12px; color: var(--color-text-muted); font-weight: 600; }
.progRow.locked { opacity: .5; cursor: not-allowed; position: relative; }
.progRow.locked::after { content: "🔒"; position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font-size: 11px; }

/* ===== PROG EDITOR — REDESIGNED ===== */
.igProgHeader { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; padding: 16px 20px; background: linear-gradient(135deg, #f8fafc 0%, #eef2ff 100%); border-radius: var(--radius-md); border: 1px solid #e0e7ff; }
.igProgHeader h3 { margin: 0; font-size: 16px; font-weight: 700; flex: 1; color: var(--color-text); }
.igProgAnioInput { width: 78px; padding: 6px 10px; border: 1px solid #c7d2fe; border-radius: 8px; font-size: 14px; font-weight: 700; text-align: center; background: #fff; color: var(--color-primary); }
.igProgAnioInput:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-light); }
.btnLink { background: none; border: none; color: var(--color-text-muted); font-size: 13px; cursor: pointer; padding: 4px 0; font-weight: 600; }
.btnLink:hover { color: var(--color-primary); }

/* Section cards */
.igProgSection { background: #fff; border-radius: var(--radius-lg); padding: 20px; border: 1px solid var(--color-border-light); box-shadow: var(--shadow-sm); margin-bottom: 16px; }
.igProgSectionTitle { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; color: var(--color-text-secondary); text-transform: uppercase; letter-spacing: .3px; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid #eef0f7; }
.igProgSectionTitle svg { color: var(--color-primary); flex-shrink: 0; }
.igProgSectionTitle .igDistribStatus { margin-left: auto; text-transform: none; letter-spacing: 0; }

/* Toolbar */
.igProgToolbar { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.igProgPeriodBtns { display: flex; gap: 4px; flex-wrap: wrap; }
.btnPeriod { padding: 6px 12px; font-size: 11px; font-weight: 700; border: 1.5px solid #d7d9e5; border-radius: 8px; background: #fff; cursor: pointer; color: var(--color-text-muted); transition: all .15s; text-transform: uppercase; letter-spacing: .3px; }
.btnPeriod:hover { background: #eef2ff; border-color: #a5b4fc; color: var(--color-primary); }
.btnPeriod.active { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.btnPeriodSmall { padding: 5px 9px; font-size: 10px; }
.igProgPeriodSep { width: 1px; height: 22px; background: #d7d9e5; flex-shrink: 0; }
.igProgApplyRow { display: flex; align-items: center; gap: 8px; }
.igProgQuickInput { width: 90px; padding: 7px 10px; border: 1.5px solid #d7d9e5; border-radius: 8px; font-size: 13px; text-align: right; font-family: inherit; font-weight: 600; }
.igProgQuickInput:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-light); }
.igProgQuickInput::placeholder { font-weight: 400; color: var(--color-text-light); }
.btnApplyImporte { padding: 7px 14px; font-size: 12px; }
.igProgTotalInline { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--color-text-secondary); font-weight: 600; padding: 8px 14px; background: linear-gradient(135deg, #f0fdf4 0%, #ecfdf5 100%); border-radius: 8px; border: 1px solid #bbf7d0; }
.igProgTotalInline strong { color: #15803d; font-size: 15px; font-weight: 800; }

/* 6x2 Month Grid */
.igProgGrid6x2 { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.igProgMonth { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 6px; border: 1.5px solid #e5e7eb; border-radius: 10px; background: #fafbfc; transition: all .2s; position: relative; }
.igProgMonth.active { background: #f0fdf4; border-color: #86efac; box-shadow: 0 0 0 1px rgba(134,239,172,.3); }
.igProgMonth.locked { opacity: .4; pointer-events: none; }
.igProgMonth.locked::after { content: "🔒"; position: absolute; top: 4px; right: 4px; font-size: 9px; }
.igProgMonth input[type="checkbox"] { margin: 0; cursor: pointer; width: 16px; height: 16px; accent-color: #22c55e; }
.igProgMonth .progMes { font-size: 11px; font-weight: 800; text-transform: uppercase; color: var(--color-text-muted); letter-spacing: .5px; }
.igProgMonth.active .progMes { color: #15803d; }
.igProgMonth .progImporte { width: 100%; padding: 5px 4px; border: 1.5px solid #e5e7eb; border-radius: 6px; text-align: center; font-size: 12px; font-family: inherit; background: #fff; font-weight: 600; font-variant-numeric: tabular-nums; }
.igProgMonth .progImporte:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-light); }
.igProgMonth .progImporte:disabled { background: transparent; border-color: transparent; color: #d1d5db; }

/* Distribution section */
.igProgDistribSection { background: #fafbff; }
.igDistribInlineGrid { display: flex; gap: 8px; flex-wrap: wrap; }
.igDistribItem { display: flex; align-items: center; gap: 0; }
.igDistribBtn { padding: 7px 12px; font-size: 12px; font-weight: 700; border: 1.5px solid #d7d9e5; border-radius: 8px 0 0 8px; background: #fff; cursor: pointer; color: var(--color-text-secondary); transition: var(--transition-fast); white-space: nowrap; }
.igDistribBtn:hover { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.igDistribItem .igDistribImporte { width: 75px; padding: 7px 8px; border: 1.5px solid #d7d9e5; border-left: none; border-radius: 0 8px 8px 0; text-align: right; font-size: 12px; font-family: inherit; font-weight: 600; font-variant-numeric: tabular-nums; }
.igDistribItem .igDistribImporte:focus { outline: none; border-color: var(--color-primary); position: relative; z-index: 1; box-shadow: 0 0 0 2px var(--color-primary-light); }
.igDistribStatus { font-size: 12px; font-weight: 700; }
.igDistribStatus.muted { color: var(--color-text-muted); }
.igDistribStatus.ok { color: #16a34a; }
.igDistribStatus.error { color: #dc2626; }
.igProgFooter { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; padding-top: 16px; }

.btnMini { padding: 6px 12px; font-size: 11px; font-weight: 700; border: 1.5px solid #d7d9e5; border-radius: 8px; background: #fff; cursor: pointer; color: var(--color-text-secondary); transition: var(--transition-fast); }
.btnMini:hover { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }

@media (max-width: 600px) {
  .igProgGrid6x2 { grid-template-columns: repeat(4, 1fr); }
  .igProgPeriodBtns { gap: 3px; }
  .btnPeriod { padding: 5px 8px; font-size: 10px; }
  .igDistribInlineGrid { flex-direction: column; }
}

/* Legacy styles (keep for compatibility) */
.igProgDistribGrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.igDistribRow { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid #eef0f7; border-radius: 8px; background: #fff; }
.igDistribName { font-size: 13px; font-weight: 600; min-width: 90px; color: var(--color-text); }
.igDistribImporte { flex: 1; padding: 6px 10px; border: 1px solid #d7d9e5; border-radius: 8px; text-align: right; font-size: 13px; font-family: inherit; width: 90px; }
.igDistribImporte:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-light); }
.igDistribCur { font-size: 12px; color: var(--color-text-muted); font-weight: 600; }

/* Distribution header and validation */
.igDistribHeader { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.igDistribValidation { margin-top: 10px; padding: 8px 12px; border-radius: var(--radius-sm); font-size: 12px; font-weight: 600; }
.igDistribValidation.info { background: #f0f9ff; color: #0369a1; }
.igDistribValidation.ok { background: #f0fdf4; color: #15803d; }
.igDistribValidation.error { background: #fef2f2; color: #dc2626; }

/* =========================
   Autocomplete dropdown
   ========================= */
.autocompleteWrap { position: relative; }
.autocompleteWrap input { width: 100%; padding: 10px 12px; border: 1px solid var(--color-border); border-radius: var(--radius-md); font-size: 13px; background: #fff; transition: var(--transition-fast); }
.autocompleteWrap input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-light); }
.autocompleteWrap input.hasSelection { border-color: var(--color-success); background: #f0fdf4; font-weight: 600; color: var(--color-success); }
.autocompleteDropdown { position: absolute; top: 100%; left: 0; right: 0; z-index: 50; background: #fff; border: 1px solid var(--color-border); border-top: none; border-radius: 0 0 var(--radius-md) var(--radius-md); max-height: 220px; overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.autocompleteDropdown .acItem { padding: 10px 14px; cursor: pointer; font-size: 13px; transition: background .1s; border-bottom: 1px solid var(--color-border-light); display: flex; justify-content: space-between; align-items: center; }
.autocompleteDropdown .acItem:hover, .autocompleteDropdown .acItem.acActive { background: var(--color-primary-light); }
.autocompleteDropdown .acItem:last-child { border-bottom: none; }
.autocompleteDropdown .acItem .acNif { font-size: 11px; color: var(--color-text-muted); }
.autocompleteDropdown .acNoResults { padding: 12px 14px; font-size: 13px; color: var(--color-text-muted); text-align: center; }

/* =========================
   Nueva iguala form
   ========================= */
.igNuevaForm .niFormContent { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.igNuevaForm .niFormActions { display: flex; gap: 8px; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--color-border-light); }
.niSelectedInfo { padding: 10px 16px; border-radius: var(--radius-md); font-size: 13px; font-weight: 600; flex: 1; min-width: 200px; }
.niSelectedInfo.exists { background: #fef3c7; border: 1px solid #fde047; color: #92400e; }
.niSelectedInfo.newClient { background: #dcfce7; border: 1px solid #86efac; color: #15803d; }
.niSelectedInfo.hasIguala { background: #fee2e2; border: 1px solid #fecaca; color: #dc2626; }
.niDistribSection { padding: 16px; margin-top: 12px; background: var(--color-bg-subtle); border-radius: var(--radius-md); border: 1px solid var(--color-border-light); }
.niDistribSection .dynRow { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.niDistribSection .dynRow span { flex: 2; font-size: 13px; font-weight: 600; }
.niDistribSection .dynRow input { flex: 1; padding: 6px 10px; border: 1px solid var(--color-border); border-radius: var(--radius-sm); font-size: 13px; text-align: right; }

/* Igualas delete button bigger */
.igDeleteBtn { padding: 6px 14px !important; font-size: 13px !important; min-width: auto; }

/* =========================
   Panel Igualas
   ========================= */
.igualasTopBar { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; padding: 16px 20px; background: linear-gradient(135deg, #f8fafc 0%, #eef2ff 100%); border-radius: var(--radius-md); border: 1px solid #e0e7ff; }
.igNuevaForm { padding: 20px; margin-bottom: 16px; background: #fff; border-radius: var(--radius-md); border: 1px solid #e0e7ff; box-shadow: 0 2px 8px rgba(79,70,229,.08); }
.igNuevaForm .formGroup { margin: 0; }
.igToggle { cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.igToggle input { cursor: pointer; }

/* Igualas table inside panel */
.igualasTableWrap { border-radius: var(--radius-lg); border: 1px solid var(--color-border); overflow: hidden; background: #fff; max-height: 50vh; overflow-y: auto; box-shadow: var(--shadow-sm); }
.igualasTableWrap .dataTable th { background: #f8fafc; font-size: 11px; padding: 10px 16px; position: sticky; top: 0; z-index: 5; border-bottom: 2px solid var(--color-border); }
.igualasTableWrap .dataTable td { padding: 10px 16px; border-bottom: 1px solid var(--color-border-light); }
.igualasTableWrap .dataTable tbody tr:hover td { background: var(--color-primary-light) !important; }
.igualasTableWrap .dataTable tbody tr { cursor: pointer; }
/* Zebra striping for igualas table */
.igualasTableWrap .dataTable tbody tr:nth-child(even) { background-color: var(--color-bg-subtle); }
.igualasTableCount { padding: 10px 16px; font-size: 12px; font-weight: 600; color: var(--color-text-muted); background: #fbfcff; border-top: 1px solid #eef0f7; text-align: right; }

/* Igualas search */
.igSearchRow { display: flex; gap: 10px; margin-bottom: 16px; }
.igSearchRow input { flex: 1; padding: 10px 14px; border: 1px solid #d7d9e5; border-radius: 10px; font-size: 13px; background: #fff; transition: var(--transition-fast); }
.igSearchRow input:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-light); }
.igSearchRow input::placeholder { color: var(--color-text-light); }

/* Igualas stats bar */
.igStatsBar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 16px; }
.igStat { padding: 12px 16px; border-radius: var(--radius-md); text-align: center; border: 1px solid var(--color-border-light); }
.igStat .igStatValue { font-size: 20px; font-weight: 800; display: block; }
.igStat .igStatLabel { font-size: 10px; font-weight: 700; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: .3px; }
.igStat.igStatTotal { background: linear-gradient(135deg, #ede9fe 0%, #e0e7ff 100%); border-color: #c7d2fe; }
.igStat.igStatTotal .igStatValue { color: var(--color-primary); }
.igStat.igStatActivas { background: #dcfce7; border-color: #86efac; }
.igStat.igStatActivas .igStatValue { color: #15803d; }
.igStat.igStatInactivas { background: #fee2e2; border-color: #fecaca; }
.igStat.igStatInactivas .igStatValue { color: #dc2626; }
.igStat.igStatImporte { background: #fff7ed; border-color: #fed7aa; }
.igStat.igStatImporte .igStatValue { color: #c2410c; }

/* =========================
   Footer
   ========================= */
.appFooter {
  text-align: center;
  padding: 20px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border);
  background: var(--color-bg-white);
  margin-top: 16px;
  letter-spacing: .3px;
}
footer { text-align: center; }
.small { font-size: 12px; color: #666; }

/* Evitar desbordes */
.panel, .panel * { min-width: 0; }

/* Panels stretch equally (like Impagos) */
section.panel { margin-top: 12px; margin-bottom: 12px; }
.dashboardGrid .panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.hintInline { font-size: var(--font-size-sm); color: #666; }

/* =========================
   AUTENTICACIÓN / LOGIN
   ========================= */
.loginScreen {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 20px;
}
.loginBox {
  background: #fff;
  border-radius: 24px;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.3);
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
}
.loginLogo { text-align: center; margin-bottom: 32px; }
.loginLogo h1 { font-size: 32px; color: #111; margin: 0 0 8px 0; }
.loginSubtitle { font-size: 14px; color: #666; margin: 0; }
.loginForm { display: flex; flex-direction: column; gap: 20px; }
.loginField { display: flex; flex-direction: column; gap: 8px; }
.loginField label { font-size: 13px; font-weight: 600; color: #333; }
.loginField input { padding: 14px 16px; border: 2px solid #e5e7ef; border-radius: 12px; font-size: 15px; transition: border-color 0.2s ease, box-shadow 0.2s ease; background: #fafbfc; }
.loginField input:focus { outline: none; border-color: #667eea; box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.15); background: #fff; }
.loginField input::placeholder { color: #aaa; }
.loginError { background: #fff5f5; border: 1px solid #fecaca; color: #b91c1c; padding: 12px 16px; border-radius: 10px; font-size: 13px; font-weight: 500; text-align: center; }
.loginBtn { padding: 14px 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: #fff; border: none; border-radius: 12px; font-size: 15px; font-weight: 700; cursor: pointer; transition: transform 0.15s ease, box-shadow 0.15s ease; margin-top: 8px; }
.loginBtn:hover { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(102, 126, 234, 0.4); }
.loginBtn:active { transform: translateY(0); }
.loginBtn:disabled { opacity: 0.7; cursor: not-allowed; transform: none; box-shadow: none; }

/* =========================
   Responsive
   ========================= */
@media (max-width: 1100px) {
  .dashboardGrid { grid-template-columns: 1fr; }
  .chartContainer { min-height: 220px; }
}

@media (max-width: 900px) {
  main { width: 95%; }
  .controls { grid-template-columns: repeat(4, 1fr); }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .deptCards { grid-template-columns: repeat(2, 1fr); }
  .estimacionGrid { grid-template-columns: repeat(2, 1fr); }
  .formRow { flex-direction: column; }
  .fg1, .fg2, .fg3, .fg6 { min-width: 100%; }
  .varGenTotals { flex-direction: column; gap: 2px; }
}

@media (max-width: 768px) {
  main { width: 100%; max-width: none; padding: 12px; }
  .controls { grid-template-columns: repeat(2, 1fr); }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .headerRight { width: 100%; justify-content: flex-end; margin-top: 12px; }
  .userDisplay { display: none; }
  .tableActionsLeft { flex-wrap: wrap; }
  .compSelectors { flex-direction: column; }
  .compVs { display: none; }
  .loginBox { padding: 32px 24px; }

  /* En móviles, header no sticky */
  header { position: static !important; }
}

@media (max-width: 600px) {
  .kpis { grid-template-columns: 1fr; }
  .deptCards { grid-template-columns: 1fr; }
  .estimacionGrid { grid-template-columns: 1fr; }
  .tableActions { flex-direction: column; }
  .tableFooter { flex-direction: column; gap: 8px; text-align: center; }
  .varGrandTotal { flex-direction: column; gap: 4px; text-align: center; }
  .igResultSummary { grid-template-columns: 1fr; }
  .igStatsBar { grid-template-columns: repeat(2, 1fr); }
}

/* =========================
   NEW TABLE LAYOUT: Grouped by client with monthly columns
   ========================= */

/* Column settings button */
.btnColSettings {
  display: flex !important;
  align-items: center;
  gap: 5px;
  padding: 7px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #fff;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: var(--transition-fast);
  white-space: nowrap;
  width: auto !important;
  height: auto !important;
}
.btnColSettings:hover { background: var(--color-bg-hover); border-color: var(--color-primary); color: var(--color-primary); }

/* Column settings dropdown */
.colSettingsDropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 16px;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  padding: 12px 0;
  z-index: 100;
  min-width: 220px;
  max-height: 400px;
  overflow-y: auto;
}
.colSettingsDropdown .colSettingTitle {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--color-text-muted);
  padding: 4px 16px 8px;
  border-bottom: 1px solid var(--color-border-light);
  margin-bottom: 4px;
}
.colSettingsDropdown label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  font-size: 13px;
  cursor: pointer;
  transition: background .1s;
}
.colSettingsDropdown label:hover { background: var(--color-bg-hover); }
.colSettingsDropdown label input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--color-primary); }

/* New table layout */
.dataTable.newLayout { min-width: 1200px; }
.dataTable.newLayout th { padding: 8px 6px; font-size: 11px; }
.dataTable.newLayout td { padding: 7px 6px; font-size: 12px; }

/* Month columns compact */
.dataTable.newLayout th.thMonth { width: 70px; min-width: 60px; }
.dataTable.newLayout td.tdMonth { font-variant-numeric: tabular-nums; }
.dataTable.newLayout td.tdMonth.hasValue { font-weight: 700; color: var(--color-text); }
.dataTable.newLayout td.tdMonth:not(.hasValue) { color: var(--color-text-light); }

/* Total column */
.dataTable.newLayout td.tdTotal { font-weight: 800; color: var(--color-text); font-variant-numeric: tabular-nums; }

/* In-column filter dropdowns */
.thFilterWrap { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.thFilterWrap .thLabel { display: block; }
.thFilterInput {
  width: 100%;
  max-width: 120px;
  padding: 3px 6px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-size: 10px;
  background: #fff;
  text-transform: none;
  font-weight: 500;
  letter-spacing: normal;
}
.thFilterInput:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px var(--color-primary-light); }
select.thFilterInput { cursor: pointer; }

/* Cabecera detalle: filtros dentro (estilo Impagos) */
.thFlex {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: var(--spacing-sm);
}

.thLabel {
  font-weight: 700;
  white-space: nowrap;
  font-size: var(--font-size-xs);
}

/* Controles in-header (estilo Impagos) */
.thSelect, .thInput {
  min-width: 0;
  padding: 5px 8px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-bg-white);
  font-size: var(--font-size-xs);
  height: 28px;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: var(--transition-fast);
}

.thSelect:hover, .thInput:hover {
  border-color: var(--color-text-light);
}

.thSelect:focus, .thInput:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px var(--color-primary-light);
}

/* Cliente: input filtro siempre visible (estilo Impagos) */
#fltClientCol {
  position: static;
  width: 100px;
  flex: 0 0 auto;
  opacity: 1;
  transform: none;
  pointer-events: auto;
  box-shadow: none;
}

/* Client column header flex layout (like Impagos) */
.dataTable.newLayout thead th[data-colid="cliente"] .thFlex {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  flex-wrap: nowrap;
}
/* Other columns centered */
.dataTable.newLayout thead th:not([data-colid="cliente"]) .thFilterWrap {
  align-items: center;
}

/* Group header row (client summary) */
.dataTable.newLayout .groupHeaderRow td {
  background: #f5f6f9 !important;
  border-top: 2px solid var(--color-border-dark);
  border-bottom: 1px solid var(--color-border);
  padding: 6px 6px;
  font-weight: 700;
  font-size: 12px;
  color: var(--color-text);
  cursor: pointer;
  user-select: none;
}
.dataTable.newLayout .groupHeaderRow:hover td {
  background: #eceef3 !important;
}
.dataTable.newLayout .groupHeaderRow td.tdMonth { font-weight: 800; }
.dataTable.newLayout .groupHeaderRow td.tdMonth.hasValue { color: var(--color-primary); }

/* Expand/collapse arrow */
.expandArrow {
  display: inline-block;
  width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  font-size: 11px;
  color: var(--color-text-muted);
  transition: transform .2s ease;
  margin-right: 4px;
  flex-shrink: 0;
}
.groupHeaderRow.expanded .expandArrow { transform: rotate(90deg); }

.grpClienteCell {
  display: flex;
  align-items: center;
  gap: 4px;
  text-align: left;
  overflow: hidden;
}
.grpClienteName { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.grpClienteCount {
  font-size: 10px;
  font-weight: 600;
  color: var(--color-text-muted);
  background: #fff;
  padding: 1px 7px;
  border-radius: var(--radius-full);
  margin-left: 4px;
}
.grpFacturadoBtn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 2px;
  border-radius: 4px;
  transition: background .15s;
}
.grpFacturadoBtn:hover { background: var(--color-bg-hover); }

/* Child rows (individual works) - hidden by default */
.groupChildRow { display: none; }
.groupChildRow.visible { display: table-row; }
.groupChildRow td { font-size: 12px; padding-left: 10px !important; overflow: hidden; text-overflow: ellipsis; }
.groupChildRow td:first-child { padding-left: 28px !important; }
.groupChildRow td.tdSel { width: 44px; min-width: 44px; padding: 7px 10px !important; }

/* Zebra for child rows within a group */
.groupChildRow:nth-child(odd of .groupChildRow.visible) { background-color: #fff; }
.groupChildRow:nth-child(even of .groupChildRow.visible) { background-color: #f8f9fc; }

/* Facturado checkbox in child rows */
.tdCheckSmall input[type="checkbox"] { transform: scale(1.05); cursor: pointer; accent-color: var(--color-success); }

/* Child row click hint */
.groupChildRow { cursor: pointer; }
.groupChildRow:hover td { background-color: #eef2ff !important; }
.childOpenHint {
  font-size: 10px;
  color: var(--color-primary);
  opacity: 0;
  transition: opacity .15s;
  margin-left: 4px;
}
.groupChildRow:hover .childOpenHint { opacity: 1; }

/* Suplidos column */
.tdAdj { text-align: center; }
.adjIndicator { display: inline-flex; align-items: center; gap: 3px; padding: 3px 8px; border: 1px solid #d1d5db; border-radius: var(--radius-full); background: #f9fafb; color: #6b7280; font-size: 11px; font-weight: 600; cursor: pointer; transition: var(--transition-fast); }
.adjIndicator:hover { background: #e0e7ff; border-color: #818cf8; color: #4f46e5; }
.tdProvision { text-align: center; }
.provisionIndicator { display: inline-flex; align-items: center; gap: 3px; padding: 3px 8px; border: 1px solid #d1d5db; border-radius: var(--radius-full); background: #fefce8; color: #92400e; font-size: 11px; font-weight: 600; }

/* Sort arrow on headers */
.thSortable { cursor: pointer; }
.thSortable .sortIcon { font-size: 9px; opacity: .4; margin-left: 2px; }
.thSortable.sortActive .sortIcon { opacity: 1; }
.thSortable.sortActive.sortDesc .sortIcon::after { content: "↓"; }
.thSortable.sortActive:not(.sortDesc) .sortIcon::after { content: "↑"; }

/* Client/concept column: truncate long text instead of expanding the table */
.dataTable.newLayout td[style*="text-align:left"] {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 320px;
}
