/* ==========================================================================
   SISTEMA DE ANÁLISIS DE PRECIOS UNITARIOS - ESTILOS PROFESIONALES
   ========================================================================== */

:root {
  /* Paleta de Diseño Premium */
  --bg-app: #0f172a;
  --bg-panel: #1e293b;
  --bg-card: #273549;
  --bg-input: #0f172a;
  --border-color: #334155;
  --border-focus: #6366f1;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-light: #64748b;

  --color-primary: #4f46e5;
  --color-primary-hover: #4338ca;
  --color-primary-light: rgba(79, 70, 229, 0.15);
  
  --color-success: #10b981;
  --color-success-light: rgba(16, 185, 129, 0.15);
  
  --color-warning: #f59e0b;
  --color-warning-light: rgba(245, 158, 11, 0.15);

  --color-info: #06b6d4;
  --color-info-light: rgba(6, 182, 212, 0.15);

  --color-danger: #ef4444;
  --color-danger-hover: #dc2626;

  /* Hoja de Papel Físico / Vista Previa */
  --paper-bg: #ffffff;
  --paper-text: #1e293b;
  --paper-border: #cbd5e1;
  --paper-header-bg: #f1f5f9;
  --paper-subtotal-bg: #f8fafc;
  --paper-highlight: #0284c7;

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --shadow-panel: 0 4px 20px rgba(0, 0, 0, 0.25);
  --shadow-sheet: 0 15px 35px rgba(0, 0, 0, 0.4);
}

/* Reset y Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   Barra de Navegación Superior
   ========================================================================== */
.top-nav {
  min-height: 60px;
  background-color: var(--bg-panel);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  z-index: 10;
  gap: 16px;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  white-space: nowrap;
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--color-primary), #818cf8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  color: #fff;
  box-shadow: 0 2px 10px rgba(79, 70, 229, 0.4);
  flex-shrink: 0;
}

.brand-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #fff;
  white-space: nowrap;
  line-height: 1.2;
}

.brand-subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  line-height: 1.2;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: 4px 0;
  flex-wrap: nowrap;
}
.nav-actions::-webkit-scrollbar {
  display: none;
}

.user-nav-group {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: 6px;
  padding-left: 10px;
  border-left: 1px solid var(--border-color);
  flex-shrink: 0;
}

/* Botones */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-primary {
  background-color: var(--color-primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}
.btn-primary:hover {
  background-color: var(--color-primary-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background-color: var(--bg-card);
  color: var(--text-main);
  border-color: var(--border-color);
}
.btn-secondary:hover {
  background-color: #334155;
  border-color: #475569;
}

.btn-accent {
  background: linear-gradient(135deg, #0284c7, #06b6d4);
  color: #fff;
  box-shadow: 0 2px 8px rgba(6, 182, 212, 0.3);
}
.btn-accent:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-excel {
  background: linear-gradient(135deg, #107c41, #15803d);
  color: #fff;
  box-shadow: 0 2px 8px rgba(16, 124, 65, 0.35);
}
.btn-excel:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
}

.btn-outline {
  background: transparent;
  border-color: var(--border-color);
  color: var(--text-muted);
}
.btn-outline:hover {
  border-color: var(--text-muted);
  color: #fff;
}

.btn-sm {
  font-size: 0.75rem;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
}

.btn-xs {
  font-size: 0.7rem;
  padding: 3px 8px;
}

.btn-primary-light {
  background-color: var(--color-primary-light);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.3);
}
.btn-primary-light:hover {
  background-color: rgba(79, 70, 229, 0.3);
  color: #fff;
}

.btn-success-light {
  background-color: var(--color-success-light);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.3);
}
.btn-success-light:hover {
  background-color: rgba(16, 185, 129, 0.3);
  color: #fff;
}

.btn-warning-light {
  background-color: var(--color-warning-light);
  color: #fcd34d;
  border: 1px solid rgba(245, 158, 11, 0.3);
}
.btn-warning-light:hover {
  background-color: rgba(245, 158, 11, 0.3);
  color: #fff;
}

.btn-info-light {
  background-color: var(--color-info-light);
  color: #67e8f9;
  border: 1px solid rgba(6, 182, 212, 0.3);
}
.btn-info-light:hover {
  background-color: rgba(6, 182, 212, 0.3);
  color: #fff;
}

.btn-danger-icon {
  background: transparent;
  color: #f87171;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}
.btn-danger-icon:hover {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
}

/* ==========================================================================
   Layout Principal de Dos Columnas
   ========================================================================== */
.app-layout {
  display: grid;
  grid-template-columns: 520px 1fr;
  flex: 1;
  overflow: hidden;
}

@media (min-width: 1440px) {
  .app-layout {
    grid-template-columns: 580px 1fr;
  }
}

/* ==========================================================================
   Panel de Edición (Izquierdo)
   ========================================================================== */
.editor-panel {
  background-color: var(--bg-panel);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: rgba(30, 41, 59, 0.8);
}

.panel-header h2 {
  font-size: 0.95rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #e2e8f0;
}

.badge-status {
  font-size: 0.72rem;
  padding: 3px 8px;
  background-color: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border-radius: 20px;
  border: 1px solid rgba(16, 185, 129, 0.25);
}

.editor-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Scrollbar personalizada */
.editor-scroll::-webkit-scrollbar,
.preview-viewport::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}
.editor-scroll::-webkit-scrollbar-thumb,
.preview-viewport::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 4px;
}
.editor-scroll::-webkit-scrollbar-thumb:hover,
.preview-viewport::-webkit-scrollbar-thumb:hover {
  background: #475569;
}

/* Secciones del Formulario */
.form-section {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 18px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  color: #f1f5f9;
  font-size: 0.92rem;
  font-weight: 600;
}

.section-title-with-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.title-left {
  display: flex;
  align-items: center;
  gap: 8px;
}
.title-left h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: #f1f5f9;
}

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

.section-hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* Formularios y Grids */
.form-grid {
  display: grid;
  gap: 12px;
}
.grid-2 {
  grid-template-columns: 1fr 1fr;
}
.grid-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group label {
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--text-muted);
}

.form-group input,
.form-group textarea,
.data-input-table input,
.data-input-table select {
  font-family: inherit;
  font-size: 0.82rem;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  padding: 7px 10px;
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

.form-group input:focus,
.form-group textarea:focus,
.data-input-table input:focus,
.data-input-table select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.25);
}

.input-with-suffix {
  position: relative;
  display: flex;
  align-items: center;
}
.input-with-suffix input {
  width: 100%;
  padding-right: 28px;
}
.input-with-suffix span {
  position: absolute;
  right: 10px;
  font-size: 0.8rem;
  color: var(--text-muted);
  pointer-events: none;
}

.file-upload-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}
.file-input {
  font-size: 0.72rem !important;
  padding: 5px !important;
}

.mt-3 {
  margin-top: 12px;
}

/* Tablas de Captura de Insumos */
.table-responsive-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  margin-bottom: 10px;
}

.data-input-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.data-input-table th {
  background-color: #1e293b;
  color: var(--text-muted);
  font-weight: 600;
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border-color);
}

.data-input-table td {
  padding: 5px 6px;
  border-bottom: 1px solid #2d3b4e;
}

.data-input-table input {
  width: 100%;
  padding: 4px 6px;
  font-size: 0.78rem;
}

.data-input-table tr:hover {
  background-color: rgba(255, 255, 255, 0.02);
}

.subtotal-indicator {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  font-size: 0.82rem;
  color: var(--text-muted);
  padding-top: 4px;
}
.subtotal-indicator strong {
  font-size: 0.95rem;
  color: #38bdf8;
  font-family: var(--font-mono);
}

.toggle-checkbox-custom {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background-color: rgba(99, 102, 241, 0.14);
  border: 1px solid rgba(99, 102, 241, 0.4);
  padding: 4px 10px;
  border-radius: 20px;
  cursor: pointer;
  user-select: none;
  transition: all 0.2s ease;
}
.toggle-checkbox-custom:hover {
  background-color: rgba(99, 102, 241, 0.25);
  border-color: #818cf8;
}
.toggle-checkbox-custom input[type="checkbox"] {
  accent-color: #6366f1;
  width: 15px;
  height: 15px;
  cursor: pointer;
  margin: 0;
}
.custom-check-text {
  font-size: 0.74rem;
  font-weight: 600;
  color: #c7d2fe;
}

/* ==========================================================================
   CABECERA Y REORDENAMIENTO DE SECCIONES DINÁMICAS
   ========================================================================== */
.sections-global-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  margin-bottom: 12px;
  padding: 9px 14px;
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.8), rgba(15, 23, 42, 0.9));
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.sections-header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.sections-header-title i {
  color: #38bdf8;
  font-size: 0.95rem;
}

.concept-sections-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 16px;
}

.section-reorder-group {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 2px;
  margin-right: 4px;
}
.btn-reorder {
  background: transparent;
  border: none;
  color: #94a3b8;
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: 3px;
  font-size: 0.7rem;
  transition: all 0.15s ease;
}
.btn-reorder:hover:not(:disabled) {
  background-color: rgba(56, 189, 248, 0.2);
  color: #38bdf8;
}
.btn-reorder:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}

.btn-delete-section {
  background: transparent;
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #f87171;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  transition: all 0.2s ease;
}
.btn-delete-section:hover {
  background-color: rgba(239, 68, 68, 0.25);
  border-color: #ef4444;
  color: #fff;
}

.btn-outline-primary {
  background: transparent;
  border: 1px solid rgba(99, 102, 241, 0.4);
  color: #a5b4fc;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-outline-primary:hover {
  background-color: rgba(99, 102, 241, 0.2);
  border-color: #818cf8;
  color: #fff;
}

.sobrecostos-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  transition: opacity 0.25s ease, filter 0.25s ease;
}
.sobrecostos-grid.disabled-grid,
.table-responsive-wrapper.disabled-grid,
.signatures-vertical-grid.disabled-grid {
  opacity: 0.38;
  filter: grayscale(0.6);
  pointer-events: none;
}

.sobrecosto-card {
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.sobrecosto-card label {
  font-size: 0.76rem;
  font-weight: 600;
  color: #94a3b8;
}

.signatures-vertical-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ==========================================================================
   Panel de Previsualización (Derecho)
   ========================================================================== */
.preview-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  background-color: #0b1120;
  overflow: hidden;
}

.preview-toolbar {
  height: 48px;
  background-color: #131d31;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  color: var(--text-muted);
  font-size: 0.82rem;
  flex-shrink: 0;
}

.toolbar-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-icon {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.78rem;
}
.btn-icon:hover {
  background: #334155;
}

.preview-viewport {
  flex: 1;
  overflow: auto;
  padding: 30px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background: radial-gradient(circle at top center, #1e293b 0%, #0b1120 70%);
}

/* ==========================================================================
   DOCUMENTO OFICIAL TIPO HOJA CARTA
   ========================================================================== */
.document-sheet {
  width: 820px;
  min-height: 1050px;
  background-color: var(--paper-bg);
  color: var(--paper-text);
  padding: 32px 36px;
  box-shadow: var(--shadow-sheet);
  border-radius: 2px;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: transform 0.2s ease;
  transform-origin: top center;
  font-family: Arial, Helvetica, sans-serif;
}

/* Encabezado del Documento */
.doc-header {
  display: grid;
  grid-template-columns: 90px 1fr 130px;
  align-items: center;
  gap: 15px;
  border-bottom: 2px solid #0f172a;
  padding-bottom: 12px;
  margin-bottom: 12px;
}

.doc-logo-container {
  width: 85px;
  height: 65px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.doc-logo-container img {
  max-width: 100%;
  max-height: 65px;
  object-fit: contain;
}

.doc-logo-placeholder {
  width: 100%;
  height: 100%;
  border: 1px dashed #94a3b8;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #64748b;
  font-size: 1.8rem;
  background: #f8fafc;
  border-radius: var(--radius-sm);
}

.doc-header-center {
  text-align: center;
}

.doc-title-company {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #0f172a;
  text-transform: uppercase;
  margin-bottom: 3px;
}

.doc-title-main {
  font-size: 0.95rem;
  font-weight: 700;
  color: #1e3a8a;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
}

.doc-subtitle-project {
  font-size: 0.78rem;
  font-weight: 600;
  color: #475569;
  text-transform: uppercase;
}

.doc-header-right {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.meta-box {
  border: 1px solid #94a3b8;
  padding: 3px 6px;
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  background-color: #f8fafc;
}
.meta-label {
  font-weight: 700;
  color: #334155;
}
.meta-val {
  font-weight: 600;
  color: #0f172a;
}

/* Caja de Metadatos de la Partida / Concepto */
.concept-meta-card {
  border: 1px solid #64748b;
  margin-bottom: 12px;
  background-color: #ffffff;
}

.concept-table-header {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.76rem;
}

.concept-table-header td {
  padding: 4px 6px;
  border-right: 1px solid #cbd5e1;
  border-bottom: 1px solid #cbd5e1;
}

.concept-table-header tr td:last-child {
  border-right: none;
}

.col-partida-label,
.col-partida-name-label,
.col-clave-label,
.col-unidad-label {
  font-weight: 700;
  background-color: #f1f5f9;
  width: 70px;
  color: #1e293b;
}

.col-partida-val {
  font-weight: 800;
  width: 35px;
  text-align: center;
}

.col-clave-val {
  font-weight: 700;
  width: 50px;
  text-align: center;
  color: #0369a1;
}

.col-unidad-val {
  font-weight: 700;
  width: 45px;
  text-align: center;
}

.concept-desc-cell {
  background-color: #ffffff;
  padding: 6px 8px !important;
  font-size: 0.78rem;
  line-height: 1.35;
  color: #0f172a;
}

/* Tabla Central de APU */
.apu-formal-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.74rem;
  border: 1px solid #475569;
}

.apu-formal-table th,
.apu-formal-table td {
  border: 1px solid #cbd5e1;
  padding: 4px 6px;
}

.th-main-row th {
  background-color: #1e3a8a;
  color: #ffffff;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-align: center;
}

.col-c-clave { width: 11%; }
.col-c-concepto { width: 42%; }
.col-c-unidad { width: 8%; text-align: center; }
.col-c-cant { width: 11%; text-align: right; }
.col-c-costo { width: 13%; text-align: right; }
.col-c-importe { width: 15%; text-align: right; }

.table-sin-costos .col-c-clave { width: 15%; }
.table-sin-costos .col-c-concepto { width: 63%; }
.table-sin-costos .col-c-unidad { width: 10%; text-align: center; }
.table-sin-costos .col-c-cant { width: 12%; text-align: right; }

/* Filas de Secciones (Mano de Obra, Materiales, etc.) */
.tr-category-header td {
  background-color: #f1f5f9;
  font-weight: 800;
  color: #0f172a;
  font-size: 0.74rem;
  padding: 5px 6px;
  letter-spacing: 0.03em;
  border-top: 1px solid #64748b;
}

.tr-subtotal-row td {
  background-color: #f8fafc;
  font-weight: 700;
  color: #1e293b;
  font-size: 0.74rem;
  border-bottom: 1px solid #94a3b8;
  white-space: nowrap;
}

.text-right { text-align: right; }
.text-center { text-align: center; }

.val-num {
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 0.75rem;
  white-space: nowrap;
}

/* Pie de Tabla / Resumen de Costo Directo y Sobrecostos */
.apu-formal-table tfoot {
  border-top: 2px solid #0f172a;
}

.row-summary td {
  font-size: 0.76rem;
  padding: 4px 8px;
  white-space: nowrap;
}

.row-cd td {
  background-color: #e2e8f0;
  font-size: 0.78rem;
}

.row-subtotal td {
  background-color: #f1f5f9;
  font-weight: 600;
}

.row-pu-final td {
  background-color: #e0f2fe;
  border-top: 2px solid #0284c7;
  border-bottom: 2px solid #0284c7;
  padding: 7px 10px !important;
}

.highlight-title {
  font-size: 0.88rem !important;
  font-weight: 800 !important;
  color: #0369a1 !important;
  white-space: nowrap !important;
}

.highlight-price {
  font-size: 1.05rem !important;
  font-weight: 900 !important;
  color: #0284c7 !important;
  font-family: 'Consolas', monospace;
  white-space: nowrap !important;
  letter-spacing: -0.01em;
}

/* Importe en Letras */
.amount-in-words-box {
  border: 1px solid #94a3b8;
  padding: 6px 10px;
  margin-top: 10px;
  margin-bottom: 18px;
  background-color: #f8fafc;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.74rem;
}

.badge-words {
  font-weight: 700;
  color: #334155;
}

.words-text {
  font-weight: 700;
  color: #0f172a;
  text-transform: uppercase;
}

/* Bloque de Firmas */
.doc-signatures {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 25px;
  margin-top: auto;
  padding-top: 25px;
  margin-bottom: 14px;
}

.signature-column {
  text-align: center;
}

.signature-line {
  border-top: 1px solid #334155;
  width: 80%;
  margin: 0 auto 6px auto;
}

.signature-role {
  font-size: 0.7rem;
  font-weight: 700;
  color: #475569;
  letter-spacing: 0.05em;
}

.signature-name {
  font-size: 0.74rem;
  font-weight: 600;
  color: #0f172a;
}

.doc-footer-legal {
  text-align: center;
  font-size: 0.65rem;
  color: #94a3b8;
  border-top: 1px solid #e2e8f0;
  padding-top: 6px;
}

/* ==========================================================================
   ESTILOS DEL CATÁLOGO DE PARTIDAS Y MODAL
   ========================================================================== */
.badge-count {
  background-color: #f59e0b;
  color: #0f172a;
  font-size: 0.7rem;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 12px;
  margin-left: 4px;
}

.panel-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Modal Backdrop & Dialog */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  padding: 20px;
}

.modal-dialog {
  background-color: #1e293b;
  border: 1px solid #334155;
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
  width: 100%;
  max-width: 1150px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalIn 0.2s ease-out;
}

.modal-dialog.modal-dialog-sm {
  max-width: 520px;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: rgba(30, 41, 59, 0.95);
}

.modal-title-box {
  display: flex;
  align-items: center;
  gap: 14px;
}

.modal-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.modal-title-box h3 {
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
}

.modal-title-box p {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.btn-close-modal {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}
.btn-close-modal:hover {
  color: #fff;
  background-color: rgba(255, 255, 255, 0.1);
}

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

/* Barra de Acciones Masivas */
.bulk-actions-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  background-color: #0f172a;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.bulk-actions-left,
.bulk-actions-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Barra de Reporte por Categoría (Explosión de Insumos - Modalidad B) */
.category-explosion-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 16px;
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.7), rgba(15, 23, 42, 0.9));
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: var(--radius-md);
  margin-top: -6px;
}

.explosion-bar-left,
.explosion-bar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.explosion-bar-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: #38bdf8;
  display: flex;
  align-items: center;
  gap: 6px;
}

.select-explosion-category {
  background-color: #0b1329;
  color: #f8fafc;
  border: 1px solid rgba(56, 189, 248, 0.4);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  min-width: 230px;
  transition: border-color 0.2s;
}

.select-explosion-category:focus {
  border-color: #38bdf8;
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

/* Tabla del Catálogo */
.catalog-table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.catalog-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.catalog-table th {
  background-color: #0f172a;
  color: var(--text-muted);
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
  font-weight: 600;
}

.catalog-table td {
  padding: 10px 12px;
  border-bottom: 1px solid #334155;
  color: var(--text-main);
  vertical-align: middle;
}

.catalog-table tr:hover {
  background-color: rgba(255, 255, 255, 0.03);
}

.catalog-table tr.active-partida-row {
  background-color: rgba(79, 70, 229, 0.15);
  border-left: 3px solid #6366f1;
}

.catalog-table tfoot td {
  background-color: #0f172a;
  border-top: 2px solid var(--border-color);
  padding: 12px;
}

.table-btn-group {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-tbl {
  background-color: #334155;
  border: 1px solid #475569;
  color: var(--text-main);
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-tbl:hover {
  background-color: #475569;
}

.btn-tbl-primary {
  background-color: rgba(79, 70, 229, 0.2);
  border-color: rgba(99, 102, 241, 0.4);
  color: #a5b4fc;
}
.btn-tbl-primary:hover {
  background-color: rgba(79, 70, 229, 0.4);
  color: #fff;
}

.btn-tbl-danger {
  background-color: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}
.btn-tbl-danger:hover {
  background-color: rgba(239, 68, 68, 0.3);
  color: #fff;
}

.modal-footer {
  padding: 14px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: #1a2333;
}

.catalog-summary-text {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ==========================================================================
   LOGIN SIMBÓLICO (OVERLAY & CARD)
   ========================================================================== */
.btn-outline-danger {
  background: transparent;
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  transition: all 0.2s;
}
.btn-outline-danger:hover {
  background-color: rgba(239, 68, 68, 0.2);
  border-color: #ef4444;
  color: #fff;
}

.user-profile-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background-color: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  padding: 5px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #cbd5e1;
}
.user-profile-badge i {
  color: #38bdf8;
  font-size: 0.85rem;
}

/* ==========================================================================
   SEGURIDAD VISUAL: OCULTAR EL GENERADOR CUANDO SE VE EL LOGIN
   ========================================================================== */
html:not(.is-authenticated) body,
body:not(.is-authenticated) {
  overflow: hidden !important;
  background-color: #0b1120 !important;
}

html:not(.is-authenticated) .top-nav,
html:not(.is-authenticated) .app-layout,
html:not(.is-authenticated) .modal-backdrop,
body:not(.is-authenticated) .top-nav,
body:not(.is-authenticated) .app-layout,
body:not(.is-authenticated) .modal-backdrop {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 100000;
  background-color: #0b1120;
  background-image: radial-gradient(circle at 50% 35%, #1e293b 0%, #0b1120 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

html.is-authenticated .login-overlay,
body.is-authenticated .login-overlay,
.login-overlay.logged-in {
  display: none !important;
  visibility: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.login-card {
  width: 100%;
  max-width: 440px;
  background-color: #1a2333;
  border: 1px solid #334155;
  border-radius: 16px;
  box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.7), 0 0 35px rgba(56, 189, 248, 0.09);
  padding: 36px 32px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  animation: loginCardIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes loginCardIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(12px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.login-brand {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.login-logo-icon {
  width: 58px;
  height: 58px;
  border-radius: 14px;
  background: linear-gradient(135deg, #4f46e5, #0284c7);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.6rem;
  box-shadow: 0 8px 20px rgba(2, 132, 199, 0.35);
  margin-bottom: 4px;
}

.login-brand h2 {
  font-size: 1.35rem;
  font-weight: 700;
  color: #fff;
}

.login-brand p {
  font-size: 0.8rem;
  color: #94a3b8;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-error-alert {
  background-color: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: shake 0.3s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.login-field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.login-field-group label {
  font-size: 0.78rem;
  font-weight: 600;
  color: #cbd5e1;
}

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

.login-input-wrapper > i:first-child {
  position: absolute;
  left: 14px;
  color: #64748b;
  font-size: 0.9rem;
  pointer-events: none;
}

.login-input-wrapper input {
  width: 100%;
  background-color: #0f172a;
  border: 1px solid #334155;
  border-radius: var(--radius-md);
  padding: 11px 40px 11px 38px;
  color: #fff;
  font-size: 0.9rem;
  font-family: inherit;
  transition: all 0.2s;
}

.login-input-wrapper input:focus {
  outline: none;
  border-color: #38bdf8;
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

.btn-toggle-pass {
  position: absolute;
  right: 12px;
  background: transparent;
  border: none;
  color: #64748b;
  cursor: pointer;
  padding: 4px;
  font-size: 0.9rem;
  transition: color 0.2s;
}
.btn-toggle-pass:hover {
  color: #38bdf8;
}

.login-demo-hint {
  background-color: rgba(56, 189, 248, 0.08);
  border: 1px dashed rgba(56, 189, 248, 0.25);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: #7dd3fc;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-login-submit {
  background: linear-gradient(135deg, #4f46e5 0%, #0284c7 100%);
  color: #fff;
  border: none;
  padding: 12px;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 4px 15px rgba(2, 132, 199, 0.35);
  transition: all 0.2s ease;
  margin-top: 4px;
}
.btn-login-submit:hover {
  filter: brightness(1.1);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(2, 132, 199, 0.45);
}
.btn-login-submit:active {
  transform: translateY(0);
}

.login-footer {
  text-align: center;
  font-size: 0.72rem;
  color: #64748b;
  border-top: 1px solid #334155;
  padding-top: 14px;
}

/* ==========================================================================
   ESTILOS DE IMPRESIÓN OFICIAL Y EXPORTACIÓN A PDF (@media print)
   ========================================================================== */
@media print {
  body {
    background: transparent !important;
    height: auto !important;
    overflow: visible !important;
  }

  .top-nav,
  .editor-panel,
  .preview-toolbar,
  .modal-backdrop,
  .login-overlay,
  .no-print {
    display: none !important;
  }

  .app-layout {
    display: block !important;
    grid-template-columns: 1fr !important;
  }

  .preview-panel {
    background: transparent !important;
    overflow: visible !important;
    height: auto !important;
  }

  .preview-viewport {
    padding: 0 !important;
    background: transparent !important;
    display: block !important;
  }

  .document-sheet {
    width: 100% !important;
    max-width: 100% !important;
    min-height: auto !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    padding: 10mm 12mm !important;
    margin: 0 !important;
    transform: none !important;
    page-break-after: always !important;
    page-break-inside: avoid !important;
    break-after: page !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Si se imprime cuadernillo masivo */
  body.printing-multi #printableDocument {
    display: none !important;
  }
  body.printing-multi #multiPrintContainer {
    display: block !important;
  }

  .apu-formal-table,
  .concept-meta-card,
  .amount-in-words-box,
  .doc-signatures {
    page-break-inside: avoid;
  }

  @page {
    size: letter portrait;
    margin: 8mm;
  }
}

