/* ============================================================
   TecsyDesk — Estilos globales y variables de tema
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* Variables Light Mode */
:root {
  --color-primary:       #2563EB;
  --color-primary-dark:  #1D4ED8;
  --color-primary-light: #EFF6FF;
  --color-secondary:     #64748B;
  --color-success:       #16A34A;
  --color-success-light: #F0FDF4;
  --color-warning:       #D97706;
  --color-warning-light: #FFFBEB;
  --color-danger:        #DC2626;
  --color-danger-light:  #FEF2F2;
  --color-info:          #0891B2;
  --color-bg:            #F8FAFC;
  --color-surface:       #FFFFFF;
  --color-surface-2:     #F1F5F9;
  --color-border:        #E2E8F0;
  --color-text:          #1E293B;
  --color-text-muted:    #64748B;
  --color-sidebar-bg:    #1E293B;
  --color-sidebar-text:  #CBD5E1;
  --color-sidebar-hover: #334155;
  --color-sidebar-active:#2563EB;
  --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:              0.5rem;
  --radius-lg:           0.75rem;
  --transition:          150ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Variables Dark Mode */
[data-theme="dark"] {
  --color-primary:       #3B82F6;
  --color-primary-dark:  #2563EB;
  --color-primary-light: #1E3A5F;
  --color-success:       #22C55E;
  --color-success-light: #052e16;
  --color-warning:       #F59E0B;
  --color-warning-light: #1c1003;
  --color-danger:        #EF4444;
  --color-danger-light:  #1f0404;
  --color-bg:            #0F172A;
  --color-surface:       #1E293B;
  --color-surface-2:     #0F172A;
  --color-border:        #334155;
  --color-text:          #F1F5F9;
  --color-text-muted:    #94A3B8;
  --color-sidebar-bg:    #0F172A;
  --color-sidebar-text:  #94A3B8;
  --color-sidebar-hover: #1E293B;
  --color-sidebar-active:#3B82F6;
  --shadow-sm:           0 1px 2px 0 rgb(0 0 0 / 0.3);
  --shadow-md:           0 4px 6px -1px rgb(0 0 0 / 0.4);
  --shadow-lg:           0 10px 15px -3px rgb(0 0 0 / 0.5);
}

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

/* Oculta los elementos con x-cloak hasta que Alpine.js termina de inicializar,
   evitando el "destello" de contenido que aún no debería mostrarse. */
[x-cloak] { display: none !important; }

html { font-size: 16px; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
  line-height: 1.5;
  transition: background-color var(--transition), color var(--transition);
  -webkit-font-smoothing: antialiased;
}

/* Layout principal */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 260px;
  min-height: 100vh;
  background: var(--color-sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 50; /* por encima del overlay (45) para que sus enlaces siempre reciban el clic */
  transition: transform var(--transition), width var(--transition);
  overflow-y: auto;
}

.sidebar-logo {
  padding: 1.5rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sidebar-logo-icon {
  width: 40px; height: 40px;
  border-radius: 9px;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sidebar-logo-icon img { width: 100%; height: 100%; object-fit: cover; display: block; }

.sidebar-logo-text {
  color: #F1F5F9;
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}

.sidebar-logo-sub {
  color: var(--color-sidebar-text);
  font-size: 0.7rem;
  margin-top: 1px;
}

.sidebar-nav { padding: 1rem 0.75rem; flex: 1; }

.sidebar-section-label {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-sidebar-text);
  opacity: 0.6;
  padding: 0.75rem 0.5rem 0.35rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius);
  color: var(--color-sidebar-text);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all var(--transition);
  margin-bottom: 2px;
  cursor: pointer;
}

.sidebar-link:hover {
  background: var(--color-sidebar-hover);
  color: #F1F5F9;
}

.sidebar-link.active {
  background: var(--color-sidebar-active);
  color: white;
}

.sidebar-link svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid rgba(255,255,255,0.07);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem;
  border-radius: var(--radius);
}

.sidebar-avatar {
  width: 34px; height: 34px;
  background: var(--color-primary);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 600; color: white;
  flex-shrink: 0;
}

.sidebar-user-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: #F1F5F9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 0.7rem;
  color: var(--color-sidebar-text);
}

/* Main content */
.main-content {
  margin-left: 260px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  /* Evita que contenido ancho (tablas, etc.) fuerce el layout a desbordar
     horizontalmente: los hijos flex por defecto no se achican por debajo
     del tamaño de su contenido (min-width:auto). Con min-width:0 el
     overflow-x:auto interno de las tablas puede hacer su trabajo. */
  min-width: 0;
}

/* Topbar */
.topbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0 1.5rem;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 30;
  box-shadow: var(--shadow-sm);
}

.topbar-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* Página contenido */
.page-content {
  padding: 1.5rem;
  flex: 1;
  min-width: 0;
}

/* Cards */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--color-border);
}

.card-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text);
}

/* Botones */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.25;
}

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

.btn-primary {
  background: var(--color-primary);
  color: white;
  border-color: var(--color-primary);
}
.btn-primary:hover:not(:disabled) { background: var(--color-primary-dark); }

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn-secondary:hover:not(:disabled) { background: var(--color-surface-2); }

.btn-danger {
  background: var(--color-danger);
  color: white;
  border-color: var(--color-danger);
}
.btn-danger:hover:not(:disabled) { background: #B91C1C; }

.btn-success {
  background: var(--color-success);
  color: white;
  border-color: var(--color-success);
}

.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.8rem; }
.btn-lg { padding: 0.7rem 1.4rem; font-size: 0.95rem; }
.btn-icon { padding: 0.45rem; border-radius: var(--radius); }

/* Formularios */
.form-group { margin-bottom: 1rem; }
.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--color-text-muted);
  margin-bottom: 0.35rem;
}
.form-label span.required { color: var(--color-danger); margin-left: 2px; }

.form-control {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  font-size: 0.875rem;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  appearance: none;
}

.form-control:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

.form-control::placeholder { color: var(--color-text-muted); opacity: 0.6; }

textarea.form-control { resize: vertical; min-height: 80px; }

.form-error {
  font-size: 0.75rem;
  color: var(--color-danger);
  margin-top: 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

/* Badges de estado */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.badge-recibida    { background: var(--color-primary-light); color: var(--color-primary); }
.badge-en_gestion  { background: var(--color-warning-light); color: var(--color-warning); }
.badge-terminada   { background: var(--color-success-light); color: var(--color-success); }
.badge-danger      { background: var(--color-danger-light);  color: var(--color-danger); }
.badge-info        { background: #E0F2FE; color: var(--color-info); }
.badge-gray        { background: var(--color-surface-2); color: var(--color-text-muted); }
.badge-incidente     { background: var(--color-danger-light);  color: var(--color-danger); }
.badge-requerimiento { background: var(--color-primary-light); color: var(--color-primary); }

/* Alertas/Notificaciones */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}
.alert-success { background: var(--color-success-light); color: var(--color-success); border: 1px solid #bbf7d0; }
.alert-danger  { background: var(--color-danger-light);  color: var(--color-danger);  border: 1px solid #fecaca; }
.alert-warning { background: var(--color-warning-light); color: var(--color-warning); border: 1px solid #fde68a; }
.alert-info    { background: #E0F2FE; color: var(--color-info); border: 1px solid #bae6fd; }

/* Tabla */
.table-wrapper { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead th {
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.65rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

tbody td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
  vertical-align: middle;
}

tbody tr {
  transition: background var(--transition);
  cursor: pointer;
}

tbody tr:hover { background: var(--color-surface-2); }
tbody tr:last-child td { border-bottom: none; }

/* Interruptor de tema con iconos de sol y luna a los costados.
   El icono del modo activo se resalta; el otro queda tenue. */
.theme-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}
.theme-switch-icon {
  width: 15px; height: 15px;
  color: var(--color-text-muted);
  flex-shrink: 0;
  transition: color var(--transition);
}
[data-theme="light"] .theme-switch-icon.sun  { color: #F59E0B; }
[data-theme="dark"]  .theme-switch-icon.moon { color: #93C5FD; }

.theme-toggle {
  width: 44px; height: 24px;
  background: var(--color-border);
  border-radius: 9999px;
  position: relative;
  cursor: pointer;
  transition: background var(--transition);
  border: none;
  padding: 0;
}

.theme-toggle.active { background: var(--color-primary); }

.theme-toggle::after {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  background: white;
  border-radius: 50%;
  top: 3px; left: 3px;
  transition: transform var(--transition);
  box-shadow: var(--shadow-sm);
}

.theme-toggle.active::after { transform: translateX(20px); }

/* Spinner */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Drag & Drop zona */
.dropzone {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  background: var(--color-surface-2);
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

.dropzone svg { color: var(--color-text-muted); margin: 0 auto 0.5rem; }

/* Panel lateral detalle */
.detail-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 520px;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  box-shadow: var(--shadow-lg);
  z-index: 50;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(0.4,0,0.2,1);
}

.detail-panel.open { transform: translateX(0); }

.detail-panel-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.detail-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
}

/* Overlay del panel */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  z-index: 45;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.overlay.visible { opacity: 1; pointer-events: all; }

/* Menú desplegable de opciones lista */
.dropdown-lista {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  z-index: 100;
  max-height: 220px;
  overflow-y: auto;
}

.dropdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  font-size: 0.875rem;
  transition: background var(--transition);
  color: var(--color-text);
}
.dropdown-item:hover { background: var(--color-surface-2); }

.dropdown-add {
  padding: 0.5rem 0.75rem;
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--color-primary);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
}
.dropdown-add:hover { background: var(--color-primary-light); }

/* Notificación toast */
.toast-container {
  position: fixed;
  bottom: 1.5rem; right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.875rem 1rem;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.875rem;
  min-width: 280px;
  max-width: 400px;
  animation: slideIn 0.2s ease-out;
}

.toast.success { border-left: 4px solid var(--color-success); }
.toast.error   { border-left: 4px solid var(--color-danger); }
.toast.warning { border-left: 4px solid var(--color-warning); }
.toast.info    { border-left: 4px solid var(--color-primary); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);   opacity: 1; }
}

/* Sin conexión */
.offline-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: var(--color-danger);
  color: white;
  text-align: center;
  padding: 0.5rem;
  font-size: 0.8rem;
  font-weight: 500;
  z-index: 9998;
  display: none;
}
.offline-banner.visible { display: block; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 480px;
  overflow: hidden;
}

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

.modal-body { padding: 1.25rem; }
.modal-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* Paginación */
.pagination {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  justify-content: center;
  padding: 1rem 0;
}

.page-btn {
  width: 32px; height: 32px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}
.page-btn:hover { background: var(--color-surface-2); }
.page-btn.active { background: var(--color-primary); color: white; border-color: var(--color-primary); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Responsive: sidebar en mobile */
.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-text);
  padding: 0.25rem;
}

/* El corte se sube a 1024px (no solo 768px) para cubrir también pantallas
   partidas a la mitad en monitores grandes (ej. 1920px / 2 = 960px), donde
   el sidebar fijo de 260px dejaba muy poco espacio útil y algunos controles
   quedaban inaccesibles. */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
    width: 260px;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
  }
  .sidebar-toggle { display: flex; }
  .detail-panel { width: 100%; }

  .page-content { padding: 1rem; }

  thead th, tbody td { padding: 0.5rem 0.6rem; }

  .topbar { padding: 0 1rem; }
}

/* Ajustes finos para móviles angostos */
@media (max-width: 480px) {
  .topbar { padding: 0 0.75rem; gap: 0.4rem; }
  .topbar-title { font-size: 0.9rem; }
  .topbar-actions { gap: 0.4rem; }
  .topbar-actions .btn span.btn-text-full { display: none; }
  .page-content { padding: 0.75rem; }
}

/* Grillas de 2 columnas que colapsan a 1 en celulares angostos */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; }
@media (max-width: 640px) {
  .grid-2 { grid-template-columns: 1fr; }
}

/* Utilidades extra */
.text-muted    { color: var(--color-text-muted); }
.text-primary  { color: var(--color-primary); }
.text-success  { color: var(--color-success); }
.text-warning  { color: var(--color-warning); }
.text-danger   { color: var(--color-danger); }
.divider       { height: 1px; background: var(--color-border); margin: 1rem 0; }
.relative      { position: relative; }

/* Scrollbar personalizado */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--color-secondary); }

/* Transiciones globales */
*, *::before, *::after {
  transition-property: background-color, border-color, color, fill, stroke;
  transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
  transition-duration: 150ms;
}
