/* ============================================
   SGC - Sistema de Gestión de Contratos
   Estilos principales
   ============================================ */

:root {
  /* Paleta corporativa Gestión & Competencias Capacitación */
  --brand-navy: #1C435E;
  --brand-blue: #0F679C;
  --brand-blue-bright: #1A79B9;
  --brand-sky: #6BAFDF;
  --brand-gray: #687482;

  --primary: #0F679C;
  --primary-light: #1A79B9;
  --primary-dark: #1C435E;
  --accent: #6BAFDF;
  --accent-hover: #4a97cc;
  --success: #38a169;
  --danger: #e53e3e;
  --warning: #dd6b20;
  --info: #1A79B9;
  --bg: #f2f5f8;
  --bg-card: #ffffff;
  --text: #1c2a3a;
  --text-light: #687482;
  --border: #d9dfe5;
  --shadow: 0 2px 8px rgba(28,67,94,0.08);
  --shadow-lg: 0 4px 16px rgba(28,67,94,0.14);
  --radius: 8px;
  --radius-sm: 4px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* --- Header --- */
.header {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: white;
  padding: 0;
  box-shadow: var(--shadow-lg);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
}

.header h1 {
  font-size: 1.3rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
}

.header h1 .logo-icon {
  width: 32px;
  height: 32px;
  background: var(--accent);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.header-info {
  font-size: 0.8rem;
  opacity: 0.8;
  display: flex;
  gap: 16px;
  align-items: center;
}

.header-info .badge-demo {
  background: var(--warning);
  color: white;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
}

.user-selector {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-selector label {
  font-size: 0.8rem;
  opacity: 0.9;
}

.user-selector select {
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.15);
  color: white;
  font-size: 0.8rem;
}

.user-selector select option {
  background: var(--primary);
  color: white;
}

/* --- Tabs --- */
.tabs {
  display: flex;
  background: rgba(0,0,0,0.15);
}

.tab {
  padding: 10px 24px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  color: rgba(255,255,255,0.7);
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.tab:hover {
  color: white;
  background: rgba(255,255,255,0.05);
}

.tab.active {
  color: white;
  border-bottom-color: var(--accent);
  background: rgba(255,255,255,0.08);
}

.tab .tab-count {
  background: var(--accent);
  color: var(--primary-dark);
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 700;
}

/* --- Main content --- */
.main-content {
  padding: 20px 24px;
  max-width: 1600px;
  margin: 0 auto;
}

.view { display: none; }
.view.active { display: block; }

/* --- Cards --- */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
  overflow: hidden;
  border: 1px solid var(--brand-gray);
}

.card-header {
  padding: 14px 20px;
  background: var(--primary);
  color: white;
  font-weight: 600;
  font-size: 0.95rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-body {
  padding: 16px 20px;
}

/* --- Toolbar / Filtros --- */
.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.toolbar .search-box {
  flex: 1;
  min-width: 250px;
  position: relative;
}

.toolbar .search-box input {
  width: 100%;
  padding: 8px 12px 8px 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  outline: none;
  transition: border 0.2s;
}

.toolbar .search-box input:focus {
  border-color: var(--primary-light);
}

.toolbar .search-box::before {
  content: '\1F50D';
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.85rem;
}

.filter-group {
  display: flex;
  gap: 8px;
  align-items: center;
}

.filter-group label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-light);
  white-space: nowrap;
}

.filter-group select,
.filter-group input[type="date"] {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  outline: none;
  background: white;
}

/* --- Buttons --- */
.btn {
  padding: 7px 14px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-light); }
.btn-accent { background: var(--accent); color: var(--primary-dark); font-weight: 600; }
.btn-accent:hover { background: var(--accent-hover); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #2f855a; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #c53030; }
.btn-warning { background: var(--warning); color: white; }
.btn-warning:hover { background: #c05621; }
.btn-info { background: var(--info); color: white; }
.btn-info:hover { background: #0F679C; }
.btn-sm { padding: 4px 10px; font-size: 0.75rem; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { background: var(--bg); }

/* --- Table --- */
.table-container {
  overflow-x: auto;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
  font-size: 0.82rem;
}

thead th {
  background: var(--primary);
  color: white;
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  white-space: nowrap;
  position: sticky;
  top: 0;
  font-size: 0.78rem;
}

tbody td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:hover { background: #edf2f7; }

tbody tr.asignada { background: #fff5f5; }
tbody tr.asignada:hover { background: #fee; }

/* Centrado de tablas en Reporte de Resultado y Administración */
#viewResultado table th,
#viewResultado table td,
#viewAdministracion table th,
#viewAdministracion table td {
  text-align: center;
}
/* Mantener nombres (primera columna) alineados al inicio para legibilidad */
#viewResultado table tbody td:first-child,
#viewAdministracion table tbody td:first-child {
  text-align: left;
}

/* --- Status badges --- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
}

.badge-vigente { background: #c6f6d5; color: #22543d; }
.badge-cerrada { background: #fed7d7; color: #742a2a; }
.badge-pendiente { background: #fefcbf; color: #744210; }
.badge-aceptada { background: #c6f6d5; color: #22543d; }
.badge-rechazada { background: #fed7d7; color: #742a2a; }
.badge-adjudicada { background: #d6e9f5; color: #1C435E; }
.badge-no-adjudicada { background: #fbd38d; color: #744210; }
.badge-enviado { background: #d6e9f5; color: #0F679C; }
.badge-asignada { background: #e9d8fd; color: #44337a; }
.badge-libre { background: #c6f6d5; color: #22543d; }
.badge-rol-administrador { background: #fbd38d; color: #7b341e; }
.badge-rol-gestor { background: #d6e9f5; color: #1C435E; }
.badge-rol-visualizador { background: #e2e8f0; color: #2d3748; }

/* Destacado de procesos que cierran en menos de 24h */
tr.cierra-24h {
  background: #fff5f5 !important;
  box-shadow: inset 3px 0 0 #e53e3e;
}
.urgente-icon {
  display: inline-block;
  margin-right: 4px;
  font-size: 1rem;
  animation: pulso 1.4s ease-in-out infinite;
}
.cierre-urgente {
  color: #c53030;
  font-weight: 600;
}
@keyframes pulso {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.15); opacity: 0.85; }
}

/* Modo solo lectura (visualizador) */
body.modo-visualizador .accion-solo-edicion {
  display: none !important;
}

/* Cabeceras ordenables */
.th-sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  transition: background 0.15s;
}
.th-sortable:hover {
  background: var(--primary-dark);
  color: white;
}
.sort-icon {
  display: inline-block;
  font-size: 0.75rem;
  color: rgba(255,255,255,0.7);
  margin-right: 2px;
}
.sort-icon.sort-asc,
.sort-icon.sort-desc { color: var(--brand-sky); }

/* Link de correlativo a OneDrive */
.cr-link {
  color: #0F679C;
  text-decoration: none;
  font-weight: 600;
  border-bottom: 1px dotted #0F679C;
  padding: 1px 2px;
}
.cr-link:hover {
  background: #ebf8ff;
  border-bottom-style: solid;
}

.badge-tipo {
  background: var(--primary-light);
  color: white;
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.7rem;
}

/* --- Modal --- */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  justify-content: center;
  align-items: flex-start;
  padding-top: 60px;
}

.modal-overlay.active {
  display: flex;
}

.modal {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-header {
  padding: 14px 20px;
  background: var(--primary);
  color: white;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: var(--radius) var(--radius) 0 0;
}

.modal-header .close-btn {
  background: none;
  border: none;
  color: white;
  font-size: 1.3rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}

.modal-body {
  padding: 20px;
}

.modal-body .form-group {
  margin-bottom: 14px;
}

.modal-body .form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--text);
}

.modal-body .form-group input,
.modal-body .form-group select,
.modal-body .form-group textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  outline: none;
}

.modal-body .form-group textarea {
  min-height: 80px;
  resize: vertical;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* --- Stats cards --- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
  text-align: center;
  border: 1px solid var(--brand-gray);
  border-left: 5px solid var(--primary);
  transition: transform 0.15s, box-shadow 0.15s;
}
.stat-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-lg);
}

.stat-card.accent { border-left-color: var(--accent); }
.stat-card.success { border-left-color: var(--success); }
.stat-card.danger { border-left-color: var(--danger); }
.stat-card.info { border-left-color: var(--info); }
.stat-card.warning { border-left-color: var(--warning); }

.stat-card .stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--primary);
}

.stat-card .stat-label {
  font-size: 0.78rem;
  color: var(--text-light);
  margin-top: 4px;
}

/* --- Detail panel (inline) --- */
.detail-panel {
  display: none;
  background: #f7fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 8px 0;
}

.detail-panel.active {
  display: block;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.detail-item {
  font-size: 0.82rem;
}

.detail-item .label {
  font-weight: 600;
  color: var(--text-light);
  font-size: 0.75rem;
  text-transform: uppercase;
}

/* --- Toast notifications --- */
.toast-container {
  position: fixed;
  top: 80px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  color: white;
  font-size: 0.85rem;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.3s ease;
  max-width: 350px;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }
.toast.info { background: var(--info); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* --- Monto format --- */
.monto {
  font-weight: 600;
  white-space: nowrap;
}

/* --- Loading --- */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-light);
}

.loading::after {
  content: '';
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-left: 8px;
  vertical-align: middle;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .header-top { flex-direction: column; gap: 8px; }
  .tabs { overflow-x: auto; }
  .tab { padding: 8px 14px; font-size: 0.78rem; }
  .toolbar { flex-direction: column; }
  .toolbar .search-box { min-width: 100%; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .main-content { padding: 12px; }
}

/* --- Pagination --- */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 6px;
  padding: 12px;
}

.pagination .page-btn {
  padding: 6px 10px;
  border: 1px solid var(--border);
  background: white;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.8rem;
}

.pagination .page-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.pagination .page-info {
  font-size: 0.8rem;
  color: var(--text-light);
  margin: 0 8px;
}

/* --- Empty state --- */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-light);
}

.empty-state .icon {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 0.95rem;
}

/* --- Action column --- */
.action-cell {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

/* --- Bitacora inline --- */
.bitacora-entry {
  padding: 8px 12px;
  border-left: 3px solid var(--primary-light);
  margin-bottom: 8px;
  background: #f7fafc;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.8rem;
}

.bitacora-entry .fecha {
  font-size: 0.72rem;
  color: var(--text-light);
}

/* Table link */
.codigo-link {
  color: var(--primary-light);
  cursor: pointer;
  font-weight: 600;
  text-decoration: underline;
}

.codigo-link:hover {
  color: var(--primary-dark);
}
