/* ==========================================================================
   ADMIN LAYOUT - ESTILOS COMPLETOS Y CORREGIDOS
   ========================================================================== */

/* --- TRUCO ANTI-FOUC --- */
/* Mientras el body tenga la clase 'preload', nada se anima */
body.preload * {
  transition: none !important;
  -webkit-transition: none !important;
}

/* --- Layout General --- */
body.layout-admin {
  background-color: #0f172a;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  color: #0f172a;
  height: 100vh; 
  overflow: hidden; 
}

body.layout-admin .navbar {
  display: none; 
}

.admin-shell {
  display: flex;
  height: 100vh; 
  width: 100vw;
  background: #0f172a;
  overflow: hidden; 
}

/* ==========================================================================
   SIDEBAR
   ========================================================================== */
.admin-sidebar {
  width: 260px;
  min-width: 260px;
  height: 100%;
  background: radial-gradient(circle at top left, #1e293b, #020617);
  color: #e5e7eb;
  padding: 1.5rem 1.25rem;
  display: flex;
  flex-direction: column;
  border-right: 1px solid rgba(148, 163, 184, 0.3);
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto; 
  overflow-x: hidden;
  z-index: 50;
  scrollbar-width: thin;
  scrollbar-color: #334155 transparent;
}

/* Logo */
.admin-logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-shrink: 0;
}

.admin-logo-mark {
  width: 32px;
  height: 32px;
  border-radius: 0.75rem;
  background: linear-gradient(135deg, #22c55e, #0ea5e9);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  color: #0b1120;
  flex-shrink: 0;
}

.admin-logo-text {
  display: flex;
  flex-direction: column;
  white-space: nowrap;
  overflow: hidden;
  transition: opacity 0.2s;
}

.admin-logo-text span:first-child {
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #9ca3af;
}

.admin-logo-text span:last-child {
  font-size: 1.15rem;
  font-weight: 700;
  color: #e5e7eb;
}

/* --- BOTÓN TOGGLE (Flecha) --- */
.sidebar-toggle-wrapper {
    margin-bottom: 1.5rem;
    flex-shrink: 0;
}

.sidebar-toggle-btn {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(148, 163, 184, 0.1);
    color: #9ca3af;
    width: 100%;
    padding: 6px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    outline: none !important;
}

.sidebar-toggle-btn:hover {
    background: rgba(34, 197, 94, 0.1);
    color: #22c55e;
    border-color: rgba(34, 197, 94, 0.3);
}

/* ============================================================== */
/* ESTADOS COLAPSADOS (Basados en la clase HTML)           */
/* ============================================================== */

/* Al usar 'html.sidebar-collapsed', el estilo aplica INSTANTÁNEAMENTE 
   porque el script del HEAD añade la clase antes del render. */

html.sidebar-collapsed .admin-sidebar {
  width: 70px; 
  min-width: 70px;
  padding-left: 0.75rem;
  padding-right: 0.75rem;
}

/* Ocultar textos al colapsar */
html.sidebar-collapsed .admin-logo-text,
html.sidebar-collapsed .sidebar-section-title,
html.sidebar-collapsed .sidebar-link span,
html.sidebar-collapsed .sidebar-footer,
html.sidebar-collapsed .admin-user {
  opacity: 0;
  pointer-events: none;
  display: none; 
}

/* Rotar flecha al colapsar (180 grados para apuntar a la derecha) */
html.sidebar-collapsed .sidebar-toggle-btn i {
    transform: rotate(180deg);
}

/* Ajustes visuales en colapsado */
html.sidebar-collapsed .admin-logo {
    justify-content: center;
}
html.sidebar-collapsed .sidebar-link {
    justify-content: center;
    padding: 0.75rem 0;
}
html.sidebar-collapsed .sidebar-link i {
    margin-right: 0;
    font-size: 1.1rem;
}
html.sidebar-collapsed .sidebar-toggle-wrapper {
    text-align: center;
    padding: 0;
}

/* Usuario */
.admin-user {
  font-size: 0.85rem;
  color: #9ca3af;
  margin-bottom: 1.25rem;
  white-space: nowrap;
  overflow: hidden;
  flex-shrink: 0;
}

.admin-user strong { color: #e5e7eb; }

/* Navegación */
.sidebar-section-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: #6b7280;
  margin: 1.25rem 0 0.35rem;
  white-space: nowrap;
  flex-shrink: 0;
}

.sidebar-nav {
  margin: 0;
  padding: 0;
  list-style: none;
  flex-shrink: 0;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.65rem;
  border-radius: 0.55rem;
  font-size: 0.9rem;
  color: #9ca3af;
  text-decoration: none;
  transition: all 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
}

.sidebar-link i {
  font-size: 0.95rem;
  opacity: 0.9;
  min-width: 1.2rem;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-link:hover {
  background: rgba(148, 163, 184, 0.12);
  color: #e5e7eb;
}

.sidebar-link.is-active {
  background: linear-gradient(135deg, #22c55e, #0ea5e9);
  color: #0b1120;
  font-weight: 600;
}

.sidebar-link.is-active i {
  opacity: 1;
}

.sidebar-spacer {
  flex: 1 1 auto;
}

.sidebar-footer {
  font-size: 0.75rem;
  color: #6b7280;
  margin-top: 1rem;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ==========================================================================
   MAIN CONTENT
   ========================================================================== */
.admin-main {
  flex: 1;
  height: 100%;
  background: #f3f4f6;
  padding: 1.75rem 2rem;
  padding-bottom: 5rem;
  overflow-y: auto; /* SCROLL DE CONTENIDO */
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Ajuste de padding main cuando colapsado */
html.sidebar-collapsed .admin-main {
    /* No es necesario ajustar padding si usamos flex, 
       pero si en móvil ocultas el sidebar, esto ayuda */
}

/* Flashes y Headers */
.admin-flashes .alert { border-radius: 0.75rem; font-size: 0.85rem; }
.admin-header { display: flex; flex-direction: column; gap: 0.4rem; }
.admin-header-title { font-size: 1.5rem; font-weight: 700; color: #111827; }
.admin-header-subtitle { font-size: 0.9rem; color: #6b7280; }

/* ==========================================================================
   RESTO DE ESTILOS (Cards, Tablas, Auth, etc.) - IGUALES QUE ANTES
   ========================================================================== */
.admin-card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1.25rem; }
.admin-stat-card { background: #ffffff; border-radius: 0.9rem; padding: 1.1rem 1.25rem; box-shadow: 0 18px 40px -24px rgba(15, 23, 42, 0.35); border: 1px solid rgba(148, 163, 184, 0.3); display: flex; flex-direction: column; gap: 0.35rem; }
.admin-stat-label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.12em; color: #6b7280; }
.admin-stat-value { font-size: 1.6rem; font-weight: 700; color: #111827; }
.admin-stat-caption { font-size: 0.8rem; color: #9ca3af; }

.admin-panels-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1.5fr); gap: 1.25rem; }
.admin-panel { background: #ffffff; border-radius: 0.9rem; padding: 1.1rem 1.25rem; box-shadow: 0 18px 40px -24px rgba(15, 23, 42, 0.25); border: 1px solid rgba(148, 163, 184, 0.25); margin-bottom: 1rem; }
.admin-panel-header { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.75rem; }
.admin-panel-title { font-size: 0.95rem; font-weight: 600; color: #111827; }
.admin-panel-subtitle { font-size: 0.8rem; color: #9ca3af; }

.table-modern { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.table-modern th, .table-modern td { padding: 0.45rem 0.4rem; border-bottom: 1px solid #e5e7eb; white-space: nowrap; }
.table-modern th { text-align: left; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; color: #9ca3af; }
.table-modern tbody tr:hover { background: #f9fafb; }

.table-excel { width: 100%; border-collapse: collapse; font-family: 'Segoe UI', system-ui, sans-serif; font-size: 0.8rem; background: #fff; color: #333; }
.table-excel thead th { background-color: #f8f9fa; color: #5f6368; font-weight: 600; border: 1px solid #e0e0e0; padding: 6px 8px; text-align: left; white-space: nowrap; position: sticky; top: 0; z-index: 10; }
.table-excel tbody td { border: 1px solid #e0e0e0; padding: 4px 8px; vertical-align: middle; }
.table-excel tbody tr:hover { background-color: #f1f3f4; }
.excel-toolbar { background-color: #fff; border-bottom: 1px solid #e0e0e0; padding: 10px 15px; display: flex; gap: 10px; align-items: center; }
.excel-filter-input { border: 1px solid #ccc; border-radius: 4px; padding: 4px 8px; font-size: 0.85rem; }
.table-link { color: #1a73e8; text-decoration: none; font-weight: 500; }
.table-link:hover { text-decoration: underline; }

.badge-soft { display: inline-flex; align-items: center; padding: 0.1rem 0.4rem; border-radius: 999px; font-size: 0.7rem; font-weight: 500; }
.badge-soft-green { background: rgba(34, 197, 94, 0.12); color: #166534; }
.badge-soft-amber { background: rgba(245, 158, 11, 0.16); color: #92400e; }
.badge-soft-slate { background: rgba(148, 163, 184, 0.22); color: #374151; }
.badge-soft-blue  { background: rgba(59, 130, 246, 0.16); color: #1d4ed8; }
.badge-soft-red   { background: rgba(248, 113, 113, 0.18); color: #b91c1c; }
.badge-soft-gray  { background: rgba(156, 163, 175, 0.2);  color: #374151; }

.status-dot { height: 8px; width: 8px; border-radius: 50%; display: inline-block; margin-right: 5px; }
.status-dot.green { background-color: #22c55e; }
.status-dot.gray  { background-color: #9ca3af; }
.status-dot.red   { background-color: #ef4444; }

/* Solicitudes y Calendarios */
.solicitud-resumen-calendar { margin-bottom: 1rem; }
.solicitud-header-inline { margin-bottom: 0.5rem; }
.solicitud-header-inline .admin-page-title { font-size: 1.25rem; }
.solicitud-header-inline .admin-page-subtitle { font-size: 0.85rem; }
.solicitud-resumen-body { padding: 0.35rem 0.15rem 0.4rem; font-size: 0.8rem; }
.solicitud-resumen-body dl.row { margin-bottom: 0; }
.solicitud-resumen-body dt, .solicitud-resumen-body dd { margin-bottom: 0.2rem; }
.solicitud-calendar-header { margin-bottom: 0.35rem; }
.solicitud-calendar-header .admin-panel-title { font-size: 0.85rem; }
.solicitud-calendar-header .admin-panel-subtitle { font-size: 0.75rem; }
.solicitud-calendar-header .btn-xs { padding: 0.1rem 0.5rem; font-size: 0.7rem; border-radius: 999px; }
.solicitud-calendar-card { padding: 0.15rem 0.3rem; }
.solicitud-calendar-card #solicitud-obra-calendar .fc { font-size: 0.65rem; }
.solicitud-calendar-card .fc-toolbar { margin-bottom: 0.15rem; }
.solicitud-calendar-card .fc-toolbar h2 { font-size: 0.70rem; text-transform: uppercase; letter-spacing: 0.08em; color: #6b7280; }
.solicitud-calendar-card .fc-button { border-radius: 999px; padding: 0.05rem 0.35rem; font-size: 0.60rem; }
.solicitud-calendar-card .fc-day-number { font-size: 0.65rem; padding: 1px; }
.solicitud-calendar-card .fc-day-grid .fc-row .fc-content-skeleton td,
.solicitud-calendar-card .fc-day-grid .fc-row .fc-content-skeleton th { padding: 1px 0; }
.cal-solicitud-range { background-color: rgba(34, 197, 94, 0.15); }

/* Tablas filtrables y admin simple */
.filterable-table { border-radius: 0.75rem; overflow: hidden; border: 1px solid #e5e7eb; background-color: #ffffff; }
.filterable-table thead .header-row th { font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; background-color: #f9fafb; color: #4b5563; padding: 0.35rem 0.75rem; border-bottom: 1px solid #e5e7eb; }
.filterable-table thead .filter-row th { background-color: #f9fafb; padding: 0.2rem 0.5rem 0.3rem; border-bottom: 1px solid #e5e7eb; }
.table-filter-input { width: 100%; border-radius: 9999px; border: 1px solid #d1d5db; padding: 0.15rem 0.6rem; font-size: 0.75rem; color: #111827; background-color: #ffffff; box-sizing: border-box; }
.filterable-table tbody tr { font-size: 0.8rem; }
.filterable-table tbody tr:nth-child(even) { background-color: #f9fafb; }
.filterable-table tbody tr:hover { background-color: #e5f2ff; }
.table-admin th, .table-admin td { padding-top: 0.2rem; padding-bottom: 0.2rem; line-height: 1.1; }
.table-admin tbody td:first-child, .table-admin tbody td:nth-child(2) { white-space: nowrap; }

/* Actions Bar */
.admin-actions-bar {
  position: fixed;
  bottom: 0;
  left: 260px; /* Coincide con el sidebar abierto */
  right: 0;
  z-index: 1030;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.6rem 1.5rem;
  background: rgba(243, 244, 246, 0.98);
  border-top: 1px solid #e5e7eb;
  box-shadow: 0 -6px 18px rgba(15, 23, 42, 0.22);
  transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Ajuste Actions Bar cuando colapsado (HTML class) */
html.sidebar-collapsed .admin-actions-bar {
  left: 70px;
}

.admin-actions-text { max-width: 520px; }
.admin-actions-buttons { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.admin-actions-form { margin: 0; display: flex; flex-wrap: wrap; gap: 0.5rem; }

/* Auth */
body.layout-auth { background-color: #0f172a; min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; overflow: auto; }
body.layout-auth .navbar { display: none !important; }
.auth-card { background: #ffffff; width: 100%; max-width: 400px; border-radius: 1rem; padding: 2.5rem; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25); text-align: center; }
.auth-logo { width: 48px; height: 48px; background: linear-gradient(135deg, #22c55e, #0ea5e9); color: #0b1120; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; margin: 0 auto 1.5rem; }
.auth-title { font-size: 1.5rem; font-weight: 700; color: #111827; margin-bottom: 0.5rem; }
.auth-subtitle { color: #6b7280; font-size: 0.9rem; margin-bottom: 2rem; }
.auth-card .form-group label { display: block; text-align: left; font-size: 0.85rem; font-weight: 600; color: #374151; margin-bottom: 0.4rem; }
.btn-auth { width: 100%; padding: 0.75rem; font-weight: 600; margin-top: 1rem; background-color: #22c55e; border: none; color: #0b1120; }
.btn-auth:hover { background-color: #16a34a; }
.auth-footer { margin-top: 1.5rem; font-size: 0.85rem; color: #6b7280; }
.auth-footer a { color: #22c55e; font-weight: 600; text-decoration: none; }

/* Nav Tabs */
.nav-tabs { border-bottom: 1px solid #e5e7eb; margin-bottom: 1rem; }
.nav-tabs .nav-link { color: #6b7280 !important; border: none; border-bottom: 2px solid transparent; font-size: 0.9rem; background-color: transparent !important; }
.nav-tabs .nav-link.active, .nav-tabs .nav-item.show .nav-link { color: #111827 !important; border-bottom: 2px solid #22c55e !important; font-weight: 700 !important; background-color: transparent !important; }
.nav-tabs .nav-link:hover { color: #111827 !important; border-bottom-color: #d1d5db; }

/* Media Queries */
@media (max-width: 960px) {
  .admin-sidebar { display: none; }
  .admin-main { padding: 1.25rem 1rem 5rem; }
  .admin-actions-bar { left: 0; padding-left: 1rem; padding-right: 1rem; }
}
@media (min-width: 768px) {
  .admin-actions-bar { flex-direction: row; align-items: center; justify-content: space-between; }
}

/* Helpers */
.btn-xs { padding: 0.15rem 0.4rem !important; font-size: 0.75rem !important; line-height: 1.2 !important; border-radius: 0.2rem; margin: 0 1px; }
.btn-xs i { font-size: 0.8rem; vertical-align: middle; }
.table-compact td { vertical-align: middle !important; padding: 0.3rem 0.5rem !important; }
.table-compact form { display: inline-block; margin: 0; }
/* En app/static/css/admin_layout.css o styles.css */
.hover-underline:hover {
  text-decoration: underline !important;
  color: #0056b3 !important;
}
/* Corrección para que el calendario se vea por encima de los Modales */
/* ============================================================
   FIX CALENDARIOS FLOTANTES (FLATPICKR)
   ============================================================ */
.flatpickr-calendar {
    z-index: 1060 !important; /* Por encima de los modales de Bootstrap (que son 1050) */
}

.editable-date-trigger {
    cursor: pointer;
    transition: background-color 0.2s;
    padding: 2px 6px;
    border-radius: 4px;
}

.editable-date-trigger:hover {
    background-color: #e2e6ea;
    border-color: #adb5bd !important;
}