:root {
  /* Paleta corporativa sobria (Enterprise Dark) */
  --bg-app: #0f141c;
  --bg-surface: #151b26;
  --bg-surface-elevated: #1c2433;
  --bg-input: #121824;
  --bg-hover: #222c3d;
  
  --border-color: #273142;
  --border-subtle: #1e2638;
  
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  
  --accent-primary: #1f6feb;
  --accent-primary-hover: #388bfd;
  --badge-debt-bg: rgba(248, 81, 73, 0.15);
  --badge-debt-text: #ff7b72;
  --badge-ok-bg: rgba(46, 160, 67, 0.15);
  --badge-ok-text: #3fb950;
  --badge-warning-bg: rgba(210, 153, 34, 0.15);
  --badge-warning-text: #d29922;
  --badge-neutral-bg: rgba(110, 118, 129, 0.15);
  --badge-neutral-text: #8b949e;
  
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  background-color: var(--bg-app);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 13px;
  line-height: 1.4;
  overflow: hidden; /* El scroll lo maneja la tabla */
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   AUTH OVERLAY
   ========================================================================== */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-app);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.4);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.auth-brand h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.auth-brand p {
  font-size: 12px;
  color: var(--text-muted);
}

.auth-instruction {
  margin-bottom: 18px;
  font-size: 12px;
  color: var(--text-secondary);
}

.input-group {
  margin-bottom: 16px;
}

.input-group label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.password-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.password-wrapper input {
  width: 100%;
  padding: 8px 38px 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-mono);
  outline: none;
  transition: border-color 0.2s ease;
}

.password-wrapper input:focus {
  border-color: var(--accent-primary);
}

.btn-toggle-pwd {
  position: absolute;
  right: 8px;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 4px;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.btn-toggle-pwd:hover {
  color: var(--text-primary);
  background-color: var(--bg-hover);
}

.input-group input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-mono);
  outline: none;
}

.input-group input:focus {
  border-color: var(--accent-primary);
}

.auth-error-msg {
  color: var(--badge-debt-text);
  font-size: 12px;
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ==========================================================================
   APP LAYOUT & HEADER FIJO
   ========================================================================== */
.app-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* CABECERA PRINCIPAL SUPERIOR (FIJA) */
.top-nav {
  height: 52px;
  padding: 0 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  z-index: 50;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-box {
  width: 28px;
  height: 28px;
  background: var(--accent-primary);
  color: #fff;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
}

.title-meta h1 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-environment {
  font-size: 11px;
  color: var(--badge-ok-text);
  font-weight: 500;
  background: var(--badge-ok-bg);
  padding: 2px 6px;
  border-radius: 4px;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.search-box-header {
  position: relative;
  display: flex;
  align-items: center;
}

.search-box-header svg {
  position: absolute;
  left: 10px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-box-header input {
  width: 320px;
  height: 32px;
  padding: 0 10px 0 32px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 12px;
  outline: none;
  transition: border-color 0.15s ease;
}

.search-box-header input:focus {
  border-color: var(--accent-primary);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid var(--border-color);
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  transition: all 0.15s ease;
}

.btn:hover {
  background: var(--bg-hover);
}

.btn-primary {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #fff;
  width: 100%;
  justify-content: center;
  height: 36px;
}

.btn-primary:hover {
  background: var(--accent-primary-hover);
}

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

.btn-ghost:hover {
  color: var(--badge-debt-text);
}

/* ==========================================================================
   BARRA DE ESTADO / FILTROS RESUMEN
   ========================================================================== */
.table-meta-bar {
  height: 40px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  font-size: 12px;
  color: var(--text-secondary);
}

.meta-stats-inline {
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-inline-item strong {
  color: var(--text-primary);
  font-weight: 600;
}

.btn-reset-small {
  background: transparent;
  border: none;
  color: var(--accent-primary);
  font-size: 12px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}

.btn-reset-small:hover {
  text-decoration: underline;
}

/* ==========================================================================
   AREA DE TABLA CON CABECERA TOTALMENTE FIJA (STICKY)
   ========================================================================== */
.table-container-fixed {
  flex: 1;
  overflow: auto; /* Permite scroll horizontal y vertical */
  position: relative;
  background: var(--bg-app);
}

.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12px;
  text-align: left;
}

/* FILA 1 DE CABECERA: TITULOS CON ORDENAMIENTO (FIJA) */
.data-table thead tr.header-titles th {
  position: sticky;
  top: 0;
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  font-weight: 600;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-color);
  z-index: 20;
  white-space: nowrap;
  user-select: none;
}

.data-table thead tr.header-titles th.sortable {
  cursor: pointer;
}

.data-table thead tr.header-titles th.sortable:hover {
  background: var(--bg-hover);
}

.th-sort-wrapper {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.sort-icon {
  color: var(--text-muted);
  width: 12px;
  height: 12px;
}

/* FILA 2 DE CABECERA: INPUTS / SELECTS DE FILTRO INTEGRADOS (FIJA) */
.data-table thead tr.header-filters th {
  position: sticky;
  top: 37px; /* Justo debajo de los títulos */
  background: var(--bg-surface);
  padding: 6px 12px;
  border-bottom: 2px solid var(--border-color);
  z-index: 19;
}

.col-filter-input, .col-filter-select {
  width: 100%;
  height: 26px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 11px;
  padding: 0 6px;
  outline: none;
}

.col-filter-input:focus, .col-filter-select:focus {
  border-color: var(--accent-primary);
}

/* CUERPO DE LA TABLA */
.data-table tbody tr {
  transition: background-color 0.1s ease;
}

.data-table tbody tr:hover {
  background-color: var(--bg-hover);
}

.data-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  white-space: nowrap;
}

.td-mono {
  font-family: var(--font-mono);
  color: #58a6ff;
  font-weight: 500;
}

.td-debt-amount {
  font-family: var(--font-mono);
  font-weight: 600;
}

.td-debt-amount.has-debt {
  color: var(--badge-debt-text);
}

/* BADGES SOBRIOS */
.badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}

.badge-danger {
  background: var(--badge-debt-bg);
  color: var(--badge-debt-text);
}

.badge-success {
  background: var(--badge-ok-bg);
  color: var(--badge-ok-text);
}

.badge-warning {
  background: var(--badge-warning-bg);
  color: var(--badge-warning-text);
}

.badge-neutral {
  background: var(--badge-neutral-bg);
  color: var(--badge-neutral-text);
}

.loading-state {
  text-align: center;
  padding: 40px !important;
  color: var(--text-secondary);
}

/* ==========================================================================
   FOOTER CON PAGINACIÓN Y TOTALES
   ========================================================================== */
.pagination-footer {
  height: 44px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  padding: 0 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  z-index: 30;
  font-size: 12px;
  color: var(--text-secondary);
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-page {
  height: 28px;
  padding: 0 10px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-page:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* ==========================================================================
   MODAL DE DETALLE
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 14px;
  font-family: var(--font-mono);
  color: var(--text-primary);
}

.modal-sub {
  font-size: 12px;
  color: var(--text-secondary);
  display: block;
}

.btn-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 4px;
}

.btn-close:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.modal-section h4 {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 4px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  font-size: 12px;
}

.detail-label {
  color: var(--text-secondary);
  font-size: 11px;
  display: block;
}

.tickets-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ticket-row {
  background: var(--bg-app);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  padding: 8px 12px;
  display: flex;
  justify-content: space-between;
  font-size: 12px;
}

/* ==========================================================================
   SOLAPAS DE NAVEGACION
   ========================================================================== */
.nav-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-app);
  padding: 3px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn.active {
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  font-weight: 600;
}

.tab-view {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
}

.tab-view.active {
  display: flex;
}

/* ==========================================================================
   HOJA DE TABLA DINÁMICA (GOOGLE SHEETS STYLE)
   ========================================================================== */
.pivot-workspace {
  display: flex;
  flex: 1;
  height: 100%;
  overflow: hidden;
}

/* PANEL LATERAL DE CONFIGURACION */
.pivot-sidebar {
  width: 320px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  padding: 16px;
  gap: 16px;
  overflow-y: auto;
}

.pivot-sidebar-header h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.pivot-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.pivot-zone-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: block;
  margin-bottom: 8px;
}

.field-tags-container {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: var(--bg-app);
  padding: 10px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  min-height: 90px;
}

.field-tag {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: grab;
  user-select: none;
  transition: all 0.15s ease;
}

.field-tag:hover {
  border-color: var(--accent-primary);
  background: var(--bg-hover);
}

.pivot-drop-zones {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pivot-zone {
  background: var(--bg-app);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 10px;
}

.pivot-zone-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.zone-drop-target {
  min-height: 38px;
  background: var(--bg-input);
  border: 1px dashed var(--border-color);
  border-radius: 4px;
  padding: 4px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.zone-drop-target.drag-over {
  border-color: var(--accent-primary);
  background: rgba(31, 111, 235, 0.08);
}

.placeholder-text {
  font-size: 11px;
  color: var(--text-muted);
  padding-left: 6px;
}

.pivot-val-config {
  display: flex;
  gap: 6px;
}

.pivot-actions {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
}

/* AREA DE HOJA DE CALCULO DERECHA */
.pivot-sheet-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-app);
  overflow: hidden;
}

.sheet-toolbar {
  height: 36px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 0 16px;
  display: flex;
  align-items: center;
  font-size: 12px;
  color: var(--text-secondary);
}

.sheet-scroll-container {
  flex: 1;
  overflow: auto;
}

.sheet-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  background: var(--bg-app);
}

.sheet-table th {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  padding: 8px 12px;
  font-weight: 600;
  color: var(--text-primary);
  text-align: right;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 10;
}

.sheet-table th:first-child {
  text-align: left;
  position: sticky;
  left: 0;
  z-index: 12;
}

.sheet-table th.sheet-corner-cell {
  background: var(--bg-surface);
  text-align: center;
  color: var(--text-muted);
  width: 40px;
}

.sheet-table td {
  border: 1px solid var(--border-color);
  padding: 6px 12px;
  color: var(--text-primary);
  text-align: right;
  font-family: var(--font-mono);
  white-space: nowrap;
}

.sheet-table td:first-child {
  text-align: left;
  font-family: var(--font-family);
  font-weight: 600;
  background: var(--bg-surface);
  position: sticky;
  left: 0;
  z-index: 5;
}

.sheet-table td.sheet-row-idx {
  text-align: center;
  background: var(--bg-surface);
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 400;
  width: 40px;
}

.sheet-table tr:hover td {
  background-color: var(--bg-hover);
}

.sheet-table tr.sheet-total-row td {
  background: var(--bg-surface-elevated);
  font-weight: 700;
  border-top: 2px solid var(--accent-primary);
}

