/* ═══════════════════════════════════════════════════════════
   VARIABLES GLOBALES
   ═══════════════════════════════════════════════════════════ */
:root {
  /* Colores principales */
  --color-bg:           #f0f4fa;
  --color-surface:      #ffffff;
  --color-sidebar:      #1a2540;
  --color-sidebar-hover:#243058;
  --color-sidebar-text: #c8d3e8;
  --color-sidebar-active:#ffffff;

  /* Acentos */
  --color-primary:      #1e3a8a;
  --color-primary-dark: #1e3070;
  --color-secondary:    #7c3aed;
  --color-accent:       #06b6d4;

  /* Semánticos */
  --color-success:      #22c55e;
  --color-warning:      #f59e0b;
  --color-danger:       #ef4444;
  --color-info:         #3b82f6;

  /* Texto */
  --color-text-primary:   #1a202c;
  --color-text-secondary: #64748b;
  --color-text-muted:     #94a3b8;

  /* Bordes y sombras */
  --color-border:       #e2e8f0;
  --shadow-sm:          0 1px 3px rgba(0,0,0,.08);
  --shadow-md:          0 4px 12px rgba(0,0,0,.1);
  --shadow-lg:          0 8px 24px rgba(0,0,0,.12);

  /* Tipografía */
  --font-base: 'Inter', system-ui, -apple-system, BlinkMacSystemFont,
               'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

  /* Espaciado */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  /* Layout */
  --sidebar-width:          240px;
  --sidebar-collapsed-width: 64px;
  --topbar-height:          60px;
  --border-radius:          8px;
  --border-radius-lg:       12px;
  --border-radius-xl:       16px;

  /* Transiciones */
  --transition-fast:  0.15s ease;
  --transition-base:  0.25s ease;
  --transition-slow:  0.4s ease;
}

/* ═══════════════════════════════════════════════════════════
   RESET Y BASE
   ═══════════════════════════════════════════════════════════ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-base);
  font-size: 0.9375rem;
  line-height: 1.6;
  color: var(--color-text-primary);
  background-color: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

img, svg {
  display: block;
  max-width: 100%;
}

a {
  color: var(--color-primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
}

ul, ol {
  list-style: none;
}

/* ═══════════════════════════════════════════════════════════
   TIPOGRAFÍA
   ═══════════════════════════════════════════════════════════ */
h1 { font-size: 1.875rem; font-weight: 700; line-height: 1.2; }
h2 { font-size: 1.5rem;   font-weight: 700; line-height: 1.3; }
h3 { font-size: 1.25rem;  font-weight: 600; line-height: 1.3; }
h4 { font-size: 1.125rem; font-weight: 600; line-height: 1.4; }
h5 { font-size: 1rem;     font-weight: 600; line-height: 1.4; }

p { margin-bottom: var(--space-4); }
p:last-child { margin-bottom: 0; }

small { font-size: 0.8125rem; }

/* ═══════════════════════════════════════════════════════════
   LAYOUT PRINCIPAL (APP)
   ═══════════════════════════════════════════════════════════ */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  height: 100dvh;   /* alto real visible en móvil (deja el logout accesible) */
  width: var(--sidebar-width);
  background: var(--color-sidebar);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: width var(--transition-base), transform var(--transition-base);
  overflow: hidden;
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-4);
  border-bottom: 1px solid rgba(255,255,255,.08);
  min-height: var(--topbar-height);
}

.sidebar-logo-icon {
  width: 36px;
  height: 36px;
  background: var(--color-primary);
  border-radius: var(--border-radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1.125rem;
  color: white;
}

.sidebar-logo-text {
  color: white;
  font-weight: 700;
  font-size: 0.9375rem;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-logo-text span {
  display: block;
  font-size: 0.6875rem;
  font-weight: 400;
  color: var(--color-sidebar-text);
  margin-top: 1px;
}

.sidebar-nav {
  flex: 1;
  padding: var(--space-4) var(--space-2);
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,.15);
  border-radius: 2px;
}

.nav-section-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--color-text-muted);
  padding: var(--space-4) var(--space-3) var(--space-2);
  white-space: nowrap;
  overflow: hidden;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3);
  border-radius: var(--border-radius);
  color: var(--color-sidebar-text);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  overflow: hidden;
  text-decoration: none;
  margin-bottom: 2px;
}

.nav-item:hover {
  background: var(--color-sidebar-hover);
  color: white;
  text-decoration: none;
}

.nav-item.active {
  background: var(--color-primary);
  color: white;
}

.nav-item-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.nav-item-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Sub-ítem anidado (ej. Agenda EC bajo Esfuerzo Compartido) */
.nav-sub-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 5px var(--space-3) 5px 44px;
  border-radius: var(--border-radius);
  color: var(--color-sidebar-text);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  margin-bottom: 2px;
  opacity: 0.8;
  position: relative;
}
.nav-sub-item::before {
  content: '';
  position: absolute;
  left: 26px;
  width: 10px;
  height: 1px;
  background: rgba(255,255,255,.3);
  top: 50%;
}
.nav-sub-item:hover {
  background: var(--color-sidebar-hover);
  color: white;
  opacity: 1;
  text-decoration: none;
}
.nav-sub-item.active {
  background: var(--color-primary);
  color: white;
  opacity: 1;
}
.nav-sub-item .nav-item-icon { display: none; }

.sidebar-footer {
  padding: var(--space-4);
  border-top: 1px solid rgba(255,255,255,.08);
  flex-shrink: 0;   /* el footer (logout) queda siempre fijo abajo y visible */
}

.user-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  overflow: hidden;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 0.875rem;
  flex-shrink: 0;
  overflow: hidden;
}

.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-info {
  overflow: hidden;
  flex: 1;
}

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

.user-role {
  font-size: 0.6875rem;
  color: var(--color-sidebar-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Contenido principal */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-height: 100vh;
  transition: margin-left var(--transition-base);
  display: flex;
  flex-direction: column;
}

.main-content.expanded {
  margin-left: var(--sidebar-collapsed-width);
}

/* Topbar */
.topbar {
  height: var(--topbar-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 var(--space-6);
  gap: var(--space-4);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

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

.topbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

/* Contenido de página */
.page-content {
  flex: 1;
  padding: var(--space-8) var(--space-6);
  max-width: 1400px;
  width: 100%;
}

/* ═══════════════════════════════════════════════════════════
   PANTALLA DE LOGIN
   ═══════════════════════════════════════════════════════════ */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a2540 0%, #2d3a6b 50%, #1a2540 100%);
  padding: var(--space-6);
  position: relative;
  overflow: hidden;
}

.auth-page::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 20% 50%, rgba(30,58,138,.15) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(30,58,138,.10) 0%, transparent 40%);
}

.auth-card {
  background: white;
  border-radius: var(--border-radius-xl);
  padding: var(--space-10) var(--space-8);
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  position: relative;
  z-index: 1;
  text-align: center;
}

.auth-org-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background: #f0f4fa;
  border-radius: 20px;
  padding: var(--space-1) var(--space-4) var(--space-1) var(--space-2);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: var(--space-6);
}

.auth-org-badge-dot {
  width: 8px;
  height: 8px;
  background: var(--color-primary);
  border-radius: 50%;
}

.auth-logo {
  display: block;
  margin: 0 auto var(--space-6);
  max-width: 220px;
  height: auto;
}

.auth-title {
  font-size: 1.625rem;
  font-weight: 700;
  color: var(--color-text-primary);
  margin-bottom: var(--space-2);
}

.auth-subtitle {
  color: var(--color-text-secondary);
  font-size: 0.9375rem;
  margin-bottom: var(--space-8);
}

/* ═══════════════════════════════════════════════════════════
   BOTONES
   ═══════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--border-radius);
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  border: none;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
}

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

.btn-primary {
  background: var(--color-primary);
  color: white;
  box-shadow: 0 2px 8px rgba(30,58,138,.35);
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-dark);
  box-shadow: 0 4px 12px rgba(30,58,138,.45);
  transform: translateY(-1px);
  text-decoration: none;
  color: white;
}

.btn-secondary {
  background: var(--color-bg);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
}

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

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

.btn-danger:hover:not(:disabled) {
  background: #dc2626;
}

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

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

.btn-sm {
  padding: var(--space-2) var(--space-3);
  font-size: 0.8125rem;
}

.btn-lg {
  padding: var(--space-4) var(--space-6);
  font-size: 1rem;
}

.btn-full {
  width: 100%;
}

/* Botón Google */
.btn-google {
  background: white;
  color: #3c4043;
  border: 1px solid #dadce0;
  gap: var(--space-3);
  font-size: 0.9375rem;
  font-weight: 500;
  padding: var(--space-3) var(--space-5);
}

.btn-google:hover:not(:disabled) {
  background: #f8f9fa;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
  transform: translateY(-1px);
}

.btn-google svg {
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════════════════
   ALERTAS
   ═══════════════════════════════════════════════════════════ */
.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4);
  border-radius: var(--border-radius);
  font-size: 0.875rem;
  line-height: 1.5;
  margin-bottom: var(--space-4);
}

.alert:last-child { margin-bottom: 0; }

.alert-success {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
}

.alert-warning {
  background: #fffbeb;
  border: 1px solid #fed7aa;
  color: #92400e;
}

.alert-danger {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
}

.alert-info {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
}

.alert-icon {
  flex-shrink: 0;
  font-size: 1rem;
  margin-top: 1px;
}

/* ═══════════════════════════════════════════════════════════
   SPINNER / CARGA
   ═══════════════════════════════════════════════════════════ */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

.spinner-dark {
  border-color: rgba(30,58,138,.25);
  border-top-color: var(--color-primary);
}

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

.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(2px);
}

.loading-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
}

.loading-box p {
  color: var(--color-text-secondary);
  font-size: 0.875rem;
  margin: 0;
}

/* ═══════════════════════════════════════════════════════════
   CARDS
   ═══════════════════════════════════════════════════════════ */
.card {
  background: var(--color-surface);
  border-radius: var(--border-radius-lg);
  border: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text-primary);
  margin: 0;
}

.card-body {
  padding: var(--space-6);
}

/* ═══════════════════════════════════════════════════════════
   FORMULARIOS
   ═══════════════════════════════════════════════════════════ */
.form-group {
  margin-bottom: var(--space-5);
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-primary);
  margin-bottom: var(--space-2);
}

.form-label.required::after {
  content: ' *';
  color: var(--color-danger);
}

.form-control {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--border-radius);
  font-size: 0.9375rem;
  color: var(--color-text-primary);
  background: white;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}

.form-control:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(30,58,138,.15);
}

.form-control.error {
  border-color: var(--color-danger);
}

.form-control.error:focus {
  box-shadow: 0 0 0 3px rgba(239,68,68,.15);
}

.form-hint {
  margin-top: var(--space-2);
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
}

.form-error {
  margin-top: var(--space-2);
  font-size: 0.8125rem;
  color: var(--color-danger);
}

/* ═══════════════════════════════════════════════════════════
   BADGES / ESTADOS
   ═══════════════════════════════════════════════════════════ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge-planificacion { background: #f1f5f9; color: #475569; }
.badge-en_curso      { background: #eff6ff; color: #1d4ed8; }
.badge-demorado      { background: #fffbeb; color: #b45309; }
.badge-critico       { background: #fef2f2; color: #b91c1c; }
.badge-completado    { background: #f0fdf4; color: #15803d; }
.badge-pendiente     { background: #f8fafc; color: #64748b; }
.badge-revision      { background: #faf5ff; color: #7e22ce; }

/* ═══════════════════════════════════════════════════════════
   TABLA
   ═══════════════════════════════════════════════════════════ */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

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

thead th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-text-secondary);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
}

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

tbody tr:last-child td { border-bottom: none; }

tbody tr:hover td { background: var(--color-bg); }

/* ═══════════════════════════════════════════════════════════
   UTILIDADES
   ═══════════════════════════════════════════════════════════ */
.text-muted    { color: var(--color-text-muted); }
.text-secondary{ color: var(--color-text-secondary); }
.text-primary  { color: var(--color-primary); }
.text-success  { color: var(--color-success); }
.text-warning  { color: var(--color-warning); }
.text-danger   { color: var(--color-danger); }

.font-bold     { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-medium   { font-weight: 500; }

.text-sm  { font-size: 0.875rem; }
.text-xs  { font-size: 0.75rem; }

.flex        { display: flex; }
.flex-col    { flex-direction: column; }
.items-center{ align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2       { gap: var(--space-2); }
.gap-3       { gap: var(--space-3); }
.gap-4       { gap: var(--space-4); }

.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.divider {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: var(--space-6) 0;
}

/* ── Logo en sidebar ────────────────────────────────────────── */
.sidebar-logo-img {
  height: 40px;
  width: auto;
  max-width: 180px;
  object-fit: contain;
  filter: brightness(0) invert(1);
  opacity: 0.88;
  transition: opacity var(--transition-base);
}

.sidebar.collapsed .sidebar-logo {
  justify-content: center;
}
.sidebar.collapsed .sidebar-logo-img {
  max-width: 40px;
  height: 36px;
}
