/* ==========================================================================
   VARIABLES Y CONFIGURACIÓN GLOBAL
   ========================================================================== */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --secondary: #0d9488;
  --secondary-hover: #0f766e;
  --secondary-light: #f0fdfa;
  
  --bg-app: #f8fafc;
  --bg-surface: #ffffff;
  --bg-sidebar: #0f172a;
  
  --text-main: #1e293b;
  --text-muted: #64748b;
  --text-light: #f8fafc;
  
  --border-color: #e2e8f0;
  --border-focus: #93c5fd;
  
  --color-success: #10b981;
  --color-success-bg: #ecfdf5;
  --color-warning: #f59e0b;
  --color-warning-bg: #fffbeb;
  --color-danger: #ef4444;
  --color-danger-bg: #fef2f2;
  --color-info: #0ea5e9;
  --color-info-bg: #f0f9ff;
  --color-purple: #8b5cf6;
  --color-purple-bg: #f5f3ff;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --transition: all 0.2s ease-in-out;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ==========================================================================
   LAYOUT PRINCIPAL
   ========================================================================== */
.app-container {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background-color: var(--bg-sidebar);
  color: var(--text-light);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.05);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand-icon {
  font-size: 28px;
  background: rgba(255, 255, 255, 0.1);
  padding: 8px;
  border-radius: var(--radius-md);
}

.brand-text h2 {
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.02em;
}

.brand-text span {
  font-size: 0.75rem;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.nav-menu {
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: transparent;
  color: #94a3b8;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  text-align: left;
  width: 100%;
}

.nav-btn:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.nav-btn.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
}

.nav-btn .icon {
  font-size: 1.15rem;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.storage-info {
  text-align: center;
  color: #64748b;
  font-size: 0.75rem;
}

/* Contenido Principal */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow-y: auto;
  padding: 24px 32px;
}

/* Header */
.top-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 28px;
}

.header-title h1 {
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.header-title p {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-top: 2px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Vistas */
.view-section {
  display: none;
  animation: fadeIn 0.25s ease-out;
}

.view-section.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Barra de Búsqueda Global en Header (Mismo estilo que en Inventario) */
.header-search-wrap {
  position: relative;
  width: 250px;
  min-width: 250px;
}

.header-search-wrap input.form-control {
  width: 100%;
  padding-left: 36px;
  padding-right: 32px;
}

.search-clear-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: #e2e8f0;
  border: none;
  font-size: 0.75rem;
  color: var(--text-muted);
  cursor: pointer;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  transition: var(--transition);
}

.search-clear-btn:hover {
  background: #cbd5e1;
  color: var(--text-main);
}

.dashboard-search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 420px;
  max-width: 90vw;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-height: 400px;
  overflow-y: auto;
  z-index: 1000;
  padding: 8px;
}

.search-result-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  border-bottom: 1px solid #f8fafc;
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover {
  background-color: #f1f5f9;
}

/* ==========================================================================
   BOTONES Y CONTROLES
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.25);
}

.btn-secondary {
  background: var(--secondary);
  color: #fff;
}
.btn-secondary:hover {
  background: var(--secondary-hover);
  box-shadow: 0 4px 10px rgba(13, 148, 136, 0.25);
}

.btn-outline {
  background: var(--bg-surface);
  border-color: var(--border-color);
  color: var(--text-main);
}
.btn-outline:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.btn-outline-secondary {
  background: transparent;
  border-color: rgba(255, 255, 255, 0.2);
  color: #cbd5e1;
}
.btn-outline-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.btn-danger-outline {
  background: transparent;
  border-color: #fca5a5;
  color: var(--color-danger);
}
.btn-danger-outline:hover {
  background: var(--color-danger-bg);
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

.btn-link {
  background: transparent;
  color: var(--primary);
  padding: 0;
  border: none;
}
.btn-link:hover {
  text-decoration: underline;
}

.w-100 { width: 100%; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 16px; }
.mt-4 { margin-top: 24px; }
.m-0 { margin: 0 !important; }
.gap-2 { gap: 8px; }
.d-flex { display: flex; }
.justify-between { justify-content: space-between; }
.align-center { align-items: center; }
.d-none { display: none !important; }
.font-bold { font-weight: 600; }
.text-muted { color: var(--text-muted); }
.text-dark { color: var(--text-main); }
.p-0 { padding: 0 !important; }

/* ==========================================================================
   ESTADÍSTICAS & CARDS
   ========================================================================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 18px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-card-clickable {
  cursor: pointer;
}

.stat-card-clickable:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

.bg-blue { background: var(--color-info-bg); color: var(--color-info); }
.bg-green { background: var(--color-success-bg); color: var(--color-success); }
.bg-amber { background: var(--color-warning-bg); color: var(--color-warning); }
.bg-purple { background: var(--color-purple-bg); color: var(--color-purple); }
.bg-red { background: var(--color-danger-bg); color: var(--color-danger); }

.stat-label {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

.stat-value {
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

.stat-desc {
  font-size: 0.76rem;
  color: var(--text-muted);
}
.text-green { color: var(--color-success) !important; font-weight: 600; }
.text-amber { color: #d97706 !important; font-weight: 600; }
.text-red { color: var(--color-danger) !important; font-weight: 600; }

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 20px;
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  background: #ffffff;
}

.card-header h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-main);
}

.card-body {
  padding: 20px;
}

.notes-page-header {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.notes-page-header h3 {
  font-size: 1.2rem;
  margin-bottom: 3px;
}

.notes-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.notes-search-wrap {
  width: 250px;
  min-width: 220px;
}

.notes-search-wrap input {
  width: 100%;
  padding-left: 36px;
  padding-right: 32px;
}

.note-editor {
  margin-bottom: 20px;
}

.markdown-editor {
  min-height: 180px;
  resize: vertical;
  font-family: 'Cascadia Code', 'Consolas', monospace;
  line-height: 1.6;
}

.notes-list {
  display: grid;
  gap: 14px;
}

.note-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}

.note-card-pinned {
  border-left-color: #f59e0b;
  background: #fffbeb;
}

.note-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
}

.note-card-header h4 {
  color: var(--text-main);
  font-size: 1rem;
  margin-bottom: 3px;
}

.note-markdown {
  padding-top: 14px;
  color: var(--text-main);
  line-height: 1.65;
}

.note-markdown p { margin: 0 0 8px; }
.note-markdown h3, .note-markdown h4, .note-markdown h5 { margin: 0 0 8px; color: var(--text-main); }
.note-markdown ul { margin: 0 0 10px 20px; }
.note-markdown code { background: #f1f5f9; padding: 2px 5px; border-radius: 4px; font-size: 0.9em; }
.note-markdown a { color: var(--primary); }
.note-markdown ol { margin: 0 0 10px 20px; }

/* Markdown dentro de tablas y fichas (detalle e incidencias de mantenimiento) */
.md-compact { line-height: 1.45; overflow-wrap: break-word; }
.md-compact p { margin: 0 0 4px; }
.md-compact > :last-child { margin-bottom: 0; }
.md-compact h3, .md-compact h4, .md-compact h5 { margin: 0 0 4px; font-size: 0.95rem; color: inherit; }
.md-compact ul, .md-compact ol { margin: 0 0 4px; padding-left: 18px; }
.md-compact code { background: rgba(15, 23, 42, 0.07); padding: 1px 4px; border-radius: 4px; font-size: 0.9em; }
.md-compact a { color: var(--primary); }

/* Editores de texto que admiten Markdown */
.markdown-input {
  font-family: 'Cascadia Code', 'Consolas', monospace;
  line-height: 1.5;
  resize: vertical;
}

@media (max-width: 640px) {
  .notes-page-header, .note-card-header { align-items: stretch; flex-direction: column; }
  .notes-actions { align-items: stretch; flex-direction: column; }
  .notes-search-wrap { width: 100%; }
}

/* Barras de distribución */
.distribution-item {
  margin-bottom: 14px;
}

.dist-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 5px;
  font-weight: 500;
}

.progress-bar-bg {
  height: 8px;
  background-color: #f1f5f9;
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  transition: width 0.4s ease;
}

/* ==========================================================================
   TABLAS Y FILTROS
   ========================================================================== */
.filters-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  background: #f8fafc !important;
}

.search-input-wrap {
  position: relative;
  flex: 1;
  min-width: 250px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.9rem;
  color: var(--text-muted);
}

.search-icon-button {
  border: 0;
  background: transparent;
  cursor: pointer;
  z-index: 1;
  padding: 6px;
  line-height: 1;
}

.search-icon-button:hover,
.search-icon-button:focus-visible {
  color: var(--primary);
  outline: none;
}

.search-input-wrap input {
  padding-left: 36px;
}

.filters-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.form-control {
  padding: 8px 12px;
  font-size: 0.88rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background-color: var(--bg-surface);
  color: var(--text-main);
  outline: none;
  font-family: inherit;
  transition: var(--transition);
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* Campo de solo lectura: gris claro típico, para que se vea que no se puede modificar */
.form-control[readonly] {
  background-color: #e9ecef;
  color: var(--text-muted);
  cursor: not-allowed;
}

.form-control[readonly]:focus {
  border-color: var(--border-color);
  box-shadow: none;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.88rem;
}

.data-table th {
  background: #f8fafc;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border-color);
}

.data-table td {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

.data-table tbody tr {
  transition: background-color 0.15s ease;
}

.data-table tbody tr:hover {
  background-color: #f8fafc;
}

/* Mantenimiento de Software: reparto de anchos (la impresión tiene sus propias reglas más abajo).
   Columnas: 1 ID · 2 Fecha · 3 Equipo/Sede · 4 Usuario · 5 Tipo · 6 Técnico · 7 Detalle · 8 Incidencias
   · 9 Gestionable · 10 Estado · 11 Acciones. Las cortas no se parten en dos líneas y el espacio sobrante
   va sobre todo a Detalle e Incidencias, que son las que llevan texto largo. */
@media screen {
  .mant-table { min-width: 1100px; }
  .mant-table th, .mant-table td { padding: 12px 8px; }
  .mant-table th:first-child, .mant-table td:first-child { padding-left: 14px; }
  .mant-table th:last-child, .mant-table td:last-child { padding-right: 14px; }
  .mant-table :is(th, td):is(:nth-child(1), :nth-child(2), :nth-child(9), :nth-child(10), :nth-child(11)) { white-space: nowrap; }
  /* Un correo largo no debe ensanchar la columna: se parte donde haga falta */
  .mant-table td:nth-child(4) { overflow-wrap: anywhere; }
  .mant-table th:nth-child(3) { width: 13%; }
  .mant-table th:nth-child(4) { width: 10%; }
  .mant-table th:nth-child(5) { width: 9%; }
  .mant-table th:nth-child(6) { width: 8%; }
  .mant-table th:nth-child(7) { width: 24%; }
  .mant-table th:nth-child(8) { width: 16%; }
}

/* Badges y Pills */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-operativo { background: var(--color-success-bg); color: #047857; }
.badge-mantenimiento { background: var(--color-warning-bg); color: #b45309; }
.badge-almacen { background: #f1f5f9; color: #475569; }
.badge-baja { background: var(--color-danger-bg); color: #b91c1c; }

.badge-amber { background: #fef3c7; color: #92400e; }
.badge-blue { background: #e0f2fe; color: #0369a1; }
.badge-teal { background: #ccfbf1; color: #0f766e; }
.badge-purple { background: #ede9fe; color: #6d28d9; }

.badge-warning-issue {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fca5a5;
  font-size: 0.76rem;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  display: inline-block;
  max-width: 280px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Incidencias con formato Markdown: se muestran completas, en varias líneas si hace falta */
.badge-warning-issue.issue-markdown {
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
}
.badge-warning-issue.issue-markdown .md-compact { display: inline-block; vertical-align: top; }
.badge-warning-issue.issue-markdown .md-compact a { color: inherit; text-decoration: underline; }

.action-buttons {
  display: flex;
  align-items: center;
  gap: 6px;
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: 0.6;
}

/* ==========================================================================
   SEDES GRID
   ========================================================================== */
.sedes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.sede-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.sede-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
}

.sede-card-header h4 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
}

.sede-stat-pill {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 700;
  font-size: 0.85rem;
  padding: 4px 10px;
  border-radius: var(--radius-full);
}

/* ==========================================================================
   MODALES (HTML5 <dialog>)
   ========================================================================== */
.modal {
  margin: auto;
  border: none;
  background: transparent;
  padding: 16px;
  max-width: 100vw;
  max-height: 100vh;
}

.modal::backdrop {
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
}

.modal-box {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 540px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}

.modal-lg { max-width: 780px; }
.modal-xl { max-width: 960px; }

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f8fafc;
}

.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 1.25rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.modal-close:hover {
  background: #e2e8f0;
  color: var(--text-main);
}

.modal-form, .modal-body {
  padding: 24px;
  overflow-y: auto;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group.full-width {
  grid-column: 1 / -1;
}

.form-group label {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-main);
}

.form-help-text {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.mechanical-issues-box {
  background: #fffbeb;
  border: 1px dashed #f59e0b;
  border-radius: var(--radius-md);
  padding: 14px;
  margin-top: 6px;
}

.bg-light-warning {
  background-color: #ffffff !important;
  border-color: #fcd34d !important;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: #f8fafc;
}

/* ==========================================================================
   FICHA TÉCNICA Y DETALLE
   ========================================================================== */
.detalle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  background: #f8fafc;
  padding: 18px;
  border-radius: var(--radius-md);
  margin-bottom: 24px;
  border: 1px solid var(--border-color);
}

.detalle-item span {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
}

.detalle-item strong {
  font-size: 0.95rem;
  color: var(--text-main);
}

.history-item {
  border-left: 3px solid var(--secondary);
  padding: 12px 16px;
  background: #ffffff;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  margin-bottom: 14px;
  border-top: 1px solid var(--border-color);
  border-right: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
}

.history-item.has-mechanical-issue {
  border-left: 4px solid var(--color-danger);
}

/* Archivos y fotos adjuntos de la ficha del equipo */
.adjuntos-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}

.adjuntos-list > p {
  grid-column: 1 / -1;
  margin: 0;
}

.adjunto-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  background: #ffffff;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
}

.adjunto-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 130px;
  background: #f1f5f9;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.adjunto-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.adjunto-icon {
  font-size: 2.6rem;
}

.adjunto-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.adjunto-info a {
  font-weight: 600;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.adjunto-actions {
  display: flex;
  gap: 6px;
}

.adjuntos-hint {
  display: block;
  margin-top: 8px;
}

/* Adjuntos en el formulario de equipo */
.adjuntos-pendientes {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.adjuntos-pendientes:empty { display: none; }

.adjuntos-pendientes li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

.adjunto-pendiente-nombre {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.86rem;
}

/* ==========================================================================
   TOAST NOTIFICACIONES
   ========================================================================== */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 9999;
}

.toast {
  background: #1e293b;
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: 0.88rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: slideInRight 0.25s ease-out;
}

.toast.toast-success { border-left: 4px solid var(--color-success); }
.toast.toast-warning { border-left: 4px solid var(--color-warning); }
.toast.toast-danger { border-left: 4px solid var(--color-danger); }

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ==========================================================================
   ESTILOS DE IMPRESIÓN (@media print)
   ========================================================================== */
.print-only {
  display: none;
}

@page {
  size: A4 portrait;
  margin: 12mm;
}

@media print {
  html, body {
    background: #fff;
    color: #000;
    height: auto;
    overflow: visible;
  }
  .sidebar, .top-header, .filters-bar, .modal-footer, .action-buttons, #btn-imprimir-ficha, .modal-close, .toast-container {
    display: none !important;
  }
  .app-container, .main-content {
    display: block;
    min-height: 0;
    overflow: visible;
    padding: 0;
    margin: 0;
  }

  /* Los diálogos cerrados no deben ocupar hojas */
  .modal:not([open]) {
    display: none !important;
  }

  /* Ficha del equipo abierta: se imprime solo ella, fluyendo en varias hojas A4 */
  body:has(#modal-detalle-equipo[open]) > *:not(#modal-detalle-equipo) {
    display: none !important;
  }
  #modal-detalle-equipo[open] {
    position: absolute;
    inset: 0 auto auto 0;
    display: block;
    width: 100%;
    height: auto;
    max-width: 100%;
    max-height: none;
    margin: 0;
    padding: 0;
    overflow: visible;
    background: #fff;
  }
  #modal-detalle-equipo .modal-box {
    display: block;
    max-width: 100% !important;
    max-height: none;
    overflow: visible;
    box-shadow: none;
    border: none;
    border-radius: 0;
  }
  #modal-detalle-equipo .modal-header {
    padding: 0 0 10px;
    background: transparent;
  }
  #modal-detalle-equipo .modal-body {
    padding: 12px 0 0;
    overflow: visible;
  }
  #modal-detalle-equipo .detalle-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  #modal-detalle-equipo .detalle-grid,
  #modal-detalle-equipo .history-item,
  #modal-detalle-equipo .adjunto-item {
    break-inside: avoid;
  }
  #modal-detalle-equipo .modal-body button,
  #modal-detalle-equipo .adjuntos-add,
  #modal-detalle-equipo .adjunto-actions,
  #modal-detalle-equipo .adjuntos-hint {
    display: none !important;
  }
  #modal-detalle-equipo .adjuntos-list {
    grid-template-columns: repeat(3, 1fr);
  }

  /* Listado de mantenimientos (A4 horizontal, en varias hojas si hace falta) */
  .print-only {
    display: block;
  }
  .print-header h2 {
    font-size: 1.2rem;
    margin: 0;
  }
  .print-header p {
    font-size: 0.8rem;
    color: #475569;
    margin: 2px 0 10px;
  }
  body.print-landscape .view-section.active .card {
    border: none;
    box-shadow: none;
    overflow: visible;
  }
  body.print-landscape .view-section.active .table-responsive {
    overflow: visible;
  }
  body.print-landscape .view-section.active .data-table {
    font-size: 0.7rem;
  }
  body.print-landscape .view-section.active .data-table th,
  body.print-landscape .view-section.active .data-table td {
    padding: 5px 6px;
    max-width: none !important;
  }
  /* Panel principal: se conserva el aspecto de tarjetas y barras */
  body.print-landscape #view-dashboard .card,
  body.print-landscape #view-dashboard .stat-card {
    border: 1px solid var(--border-color);
  }
  body.print-landscape #view-dashboard .stat-card,
  body.print-landscape #view-dashboard .dashboard-grid .card {
    break-inside: avoid;
  }
  body.print-landscape #view-dashboard .stats-grid {
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
    margin-bottom: 14px;
  }
  body.print-landscape #view-dashboard .stat-card {
    padding: 8px 10px;
    gap: 8px;
  }
  body.print-landscape #view-dashboard .stat-icon {
    width: 34px;
    height: 34px;
    font-size: 1.1rem;
  }
  body.print-landscape #view-dashboard .stat-value {
    font-size: 1.3rem;
    line-height: 1.1;
  }
  body.print-landscape #view-dashboard .stat-label,
  body.print-landscape #view-dashboard .stat-desc {
    display: block;
    line-height: 1.2;
  }
  body.print-landscape #view-dashboard .stats-grid {
    margin-bottom: 10px;
  }
  body.print-landscape #view-dashboard .card-header {
    padding: 8px 14px;
  }
  body.print-landscape #view-dashboard .card-body {
    padding: 10px 14px;
  }
  body.print-landscape #view-dashboard .card.mt-4 {
    margin-top: 12px;
  }
  body.print-landscape #view-dashboard #dashboard-sedes-distribution {
    column-count: 2;
    column-gap: 24px;
  }
  body.print-landscape #view-dashboard .distribution-item {
    margin-bottom: 8px;
    break-inside: avoid;
  }
  body.print-landscape #view-dashboard .dashboard-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
  }
  body.print-landscape #view-dashboard .stat-icon,
  body.print-landscape #view-dashboard .progress-bar-bg,
  body.print-landscape #view-dashboard .progress-bar-fill {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  #btn-view-all-mantenimientos {
    display: none !important;
  }
  body.print-landscape .view-section.active .data-table thead {
    display: table-header-group;
  }
  body.print-landscape .view-section.active .data-table tr {
    break-inside: avoid;
  }
  body.print-landscape .view-section.active .data-table th:last-child,
  body.print-landscape .view-section.active .data-table td:last-child,
  body.print-landscape #sort-icon-mant-id,
  body.print-landscape #sort-icon-mant-fecha {
    display: none;
  }
  body.print-landscape .view-section.active .data-table td div,
  body.print-landscape .view-section.active .data-table td small {
    font-size: 0.7rem !important;
    line-height: 1.25;
  }
  body.print-landscape .view-section.active .badge,
  body.print-landscape .view-section.active .badge-warning-issue {
    display: inline-block;
    padding: 1px 6px;
    font-size: 0.68rem;
    line-height: 1.3;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}

/* Responsive */
@media (max-width: 768px) {
  .app-container {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  }
  .nav-menu {
    flex-direction: row;
    overflow-x: auto;
  }
  .main-content {
    padding: 16px;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
}

/* ==========================================================================
   RESALTADO ESPECIAL ESTADO OPERATIVO
   ========================================================================== */
.badge-operativo-highlight {
  background: #ecfdf5 !important;
  color: #065f46 !important;
  border: 1.5px solid #10b981 !important;
  font-weight: 700 !important;
  padding: 4px 10px !important;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.15) !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 4px !important;
}

/* ==========================================================================
   SISTEMA DE AUTENTICACIÓN & LOGIN OVERLAY
   ========================================================================== */
.login-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.82);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  padding: 20px;
}

.login-card {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.2);
  width: 100%;
  max-width: 420px;
  padding: 32px 28px;
  animation: fadeIn 0.3s ease-out;
}

.login-header {
  text-align: center;
  margin-bottom: 24px;
}

.login-logo {
  font-size: 2.5rem;
  background: #eff6ff;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.15);
}

.login-header h2 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 4px;
}

.login-header p {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.alert {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 500;
}

.alert-danger {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border: 1px solid #fecaca;
}

.quick-access-box {
  background: #f8fafc;
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-top: 16px;
}

.quick-access-title {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

.user-profile-card {
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-md);
  padding: 10px 12px;
}

.btn-logout-icon {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.4);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn-logout-icon:hover {
  background: var(--color-danger);
  color: #fff;
}

.badge-admin {
  background: rgba(37, 99, 235, 0.25) !important;
  color: #93c5fd !important;
  border: 1px solid rgba(96, 165, 250, 0.4) !important;
  font-size: 0.72rem !important;
}

.badge-tecnico {
  background: rgba(13, 148, 136, 0.25) !important;
  color: #5eead4 !important;
  border: 1px solid rgba(45, 212, 191, 0.4) !important;
  font-size: 0.72rem !important;
}

.badge-viewer {
  background: rgba(100, 116, 139, 0.25) !important;
  color: #cbd5e1 !important;
  border: 1px solid rgba(148, 163, 184, 0.4) !important;
  font-size: 0.72rem !important;
}

.app-blurred {
  filter: blur(4px);
  pointer-events: none;
}

.highlight-box-estado-equipo,
.highlight-box-estado-mant,
.highlight-box-usuario { padding: 14px; border-radius: var(--radius-md); box-shadow: var(--shadow-sm); }
.highlight-box-estado-equipo { background: #ecfdf5; border: 2px solid #6ee7b7; }
.highlight-box-estado-mant { background: #fffbeb; border: 2px solid #fbbf24; }
.highlight-box-usuario { background: #fff7ed; border: 2px solid #fdba9f; }
.highlight-box-estado-equipo select { border-color: #10b981; }
.highlight-box-estado-mant select { border-color: #f59e0b; }
.highlight-box-usuario input { border-color: #fb923c; }
.user-form-box { background: #f8fafc; border: 1px solid var(--border-color); border-radius: var(--radius-md); }
.password-value { display: inline-block; min-width: 80px; }
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 20% 10%, #dbeafe, transparent 40%), #0f172a; }
.login-page .login-card { max-width: 440px; }
.login-page .form-group { margin-bottom: 16px; }
.login-page .btn-primary { width: 100%; justify-content: center; }

.password-input-wrap {
  position: relative;
}

.password-input-wrap .form-control {
  width: 100%;
  padding-right: 44px;
}

.password-toggle-button {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  line-height: 1;
}

.password-toggle-button:hover {
  color: var(--primary);
}

@media (max-width: 900px) {
  .header-search-wrap { width: 100%; min-width: 220px; }
}

/* ==========================================================================
   HISTORIAL DE CAMBIOS (solo Administrador)
   ========================================================================== */
.historial-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 16px;
  height: 60vh;
}

.historial-log {
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: #f8fafc;
}

.historial-log-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  padding: 10px 14px;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  text-align: left;
  transition: var(--transition);
}

.historial-log-item:hover {
  background: #eef2f7;
}

.historial-log-item.active {
  background: var(--primary-light);
  border-left: 3px solid var(--primary);
}

.historial-log-item strong {
  font-size: 0.85rem;
  color: var(--text-main);
}

.historial-detalle {
  overflow-y: auto;
  padding-right: 4px;
}

.historial-detalle-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 4px 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
}

.historial-change-card {
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--text-muted);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 12px;
  background: var(--bg-surface);
}

.historial-change-added { border-left-color: var(--color-success); }
.historial-change-removed { border-left-color: var(--color-danger); }
.historial-change-modified { border-left-color: var(--color-info); }

.historial-change-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.historial-change-label {
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 6px;
}

.historial-fields {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.historial-field-diff {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
  font-size: 0.85rem;
  padding: 4px 0;
  border-top: 1px dashed var(--border-color);
}

.historial-field-name {
  font-weight: 600;
  color: var(--text-muted);
  min-width: 130px;
}

.historial-field-values {
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}

.historial-field-before {
  color: var(--color-danger);
  text-decoration: line-through;
}

.historial-field-after {
  color: var(--color-success);
  font-weight: 600;
}

.historial-field-arrow {
  color: var(--text-muted);
}

@media (max-width: 900px) {
  .historial-layout { grid-template-columns: 1fr; height: auto; }
  .historial-log { max-height: 220px; }
}
