@import "modules.css";

/* =============================================================
   REDATAS — Global CSS (Modo Claro + Estructura Persistente)
   ============================================================= */

:root {
  /* Paleta Light */
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-surface-2: #f1f5f9;
  --color-surface-3: #e2e8f0;
  --color-border: #e2e8f0;
  --color-border-m: #cbd5e1;

  /* Brand */
  --color-primary: #6366f1;
  --color-primary-h: #4f46e5;
  --color-secondary: #8b5cf6;
  --color-accent: #0ea5e9;

  /* Semantic */
  --color-success: #10b981;
  --color-warning: #f59e0b;
  --color-danger: #ef4444;
  --color-info: #3b82f6;

  /* Text */
  --color-text: #0f172a;
  --color-text-muted: #475569;
  --color-text-faint: #94a3b8;

  /* Dimensiones */
  --sidebar-w: 260px;
  --sidebar-collapsed-w: 80px;
  --topbar-h: 64px;

  /* Utils */
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --radius-full: 9999px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --duration: 400ms;
  /* Un poco más lento para que sea más suave */
}

/* ── Reset ─────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background-color: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
  overflow-x: hidden;
}

/* ── Layout ────────────────────────────────────────────────── */
.app-body {
  display: flex;
  min-height: 100vh;
}

/* Sidebar persistente por defecto */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transition: width var(--duration) var(--ease),
    transform var(--duration) var(--ease),
    background var(--duration) 0.1s var(--ease);
  will-change: width, transform;
}

.main-wrapper {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-w);
  /* Espacio para el sidebar */
  transition: margin-left var(--duration) var(--ease);
  display: flex;
  flex-direction: column;
}

/* Estado: Sidebar Colapsado / Cerrado */
.app-body.sidebar-closed .sidebar {
  width: var(--sidebar-collapsed-w);
}

.app-body.sidebar-closed .main-wrapper {
  margin-left: var(--sidebar-collapsed-w);
}

/* Ocultar textos cuando está colapsado con suavidad */
.logo-text,
.nav-label {
  transition: opacity calc(var(--duration) / 2) var(--ease),
    transform calc(var(--duration) / 2) var(--ease),
    width var(--duration) var(--ease),
    margin var(--duration) var(--ease),
    padding var(--duration) var(--ease);
  white-space: nowrap;
  display: inline-block;
  opacity: 1;
  visibility: visible;
}

.app-body.sidebar-closed .logo-text,
.app-body.sidebar-closed .nav-label {
  opacity: 0;
  visibility: hidden;
  width: 0;
  margin: 0;
  padding: 0;
  transform: translateX(-10px);
  pointer-events: none;
}

.app-body.sidebar-closed .nav-link {
  justify-content: center;
  padding: 0.75rem 0;
  gap: 0;
  transition: padding var(--duration) var(--ease);
}

.app-body.sidebar-closed .sidebar__brand {
  justify-content: center;
  padding: 0;
}

.app-body.sidebar-closed .sidebar__toggle {
  display: none;
  /* Ocultamos el toggle interno del sidebar al estar colapsado si se prefiere usar solo el del topbar, o lo reposicionamos */
}

.app-body.sidebar-closed .sidebar__logo {
  gap: 0;
}

/* ── Sidebar Components ────────────────────────────────────── */
.sidebar__brand {
  height: var(--topbar-h);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--color-border);
  transition: padding var(--duration) var(--ease), justify-content var(--duration) var(--ease);
}

.sidebar__logo {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  transition: all var(--duration) var(--ease);
  overflow: hidden;
}

.logo-text {
  font-size: 1.25rem;
  font-weight: 800;
  background: linear-gradient(135deg, #4f46e5 0%, #2563eb 50%, #0ea5e9 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
  /* La transición ya está definida en la regla global .logo-text */
}

.sidebar__logo:hover .logo-text {
  filter: drop-shadow(0 0 12px rgba(37, 99, 235, 0.4));
}



/* Navegación */
.sidebar__nav {
  flex: 1;
  padding: 1.5rem 0.75rem;
  overflow-y: auto;
}

.sidebar__footer {
  margin-top: auto;
  padding: 1.5rem 0.75rem;
  border-top: 1px solid var(--color-border);
}

.nav-list {
  list-style: none;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  text-decoration: none;
  font-weight: 500;
  transition: all var(--duration) var(--ease);
}

.nav-link:hover,
.nav-item--active .nav-link {
  background: var(--color-surface-2);
  color: var(--color-primary);
}

/* CORRECCIÓN DE ICONOS: Regla estricta */
.nav-icon {
  width: 20px !important;
  height: 20px !important;
  flex-shrink: 0;
  display: block;
}

/* ── Topbar User ───────────────────────────────────────────── */
.topbar__user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.topbar__user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), var(--color-secondary));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.25);
}

.topbar__user-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
}

.topbar__logout {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  color: var(--color-text-muted);
  background: transparent;
  transition: all 0.2s var(--ease);
  flex-shrink: 0;
}

.topbar__logout:hover {
  background: #fef2f2;
  color: var(--color-danger);
  transform: translateY(-1px);
}

.topbar__logout:active {
  transform: scale(0.92);
}

.topbar__logout svg {
  width: 20px;
  height: 20px;
}

/* Transición para el icono del toggle */
#sidebarIcon {
  transition: transform 0.3s var(--ease), opacity 0.2s var(--ease);
  display: inline-block;
}

/* ── Topbar ────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  padding: 0 15px;
  /* Margen lateral de 15px */
  position: sticky;
  top: 0;
  z-index: 900;
}

.topbar__hamburger {
  cursor: pointer;
  background: #4f46e5 !important;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
  transition: none !important;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
}

.topbar__hamburger i {
  color: white !important;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.topbar__hamburger:hover,
.topbar__hamburger:active {
  background: #4f46e5 !important;
  transform: none !important;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
}

.topbar__hamburger svg {
  width: 20px;
  height: 20px;
  transition: transform 0.3s ease;
}

.sidebar-open .topbar__hamburger svg,
.sidebar-open .topbar__hamburger i {
  transform: rotate(180deg);
  transition: transform 0.4s var(--ease);
}

/* ── UI Elements (Light Mode Adapts) ───────────────────────── */
.alert {
  padding: 1rem 1.5rem;
  border-radius: var(--radius-md);
  margin: 1rem 15px;
  /* Margen lateral de 15px */
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.alert--error {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  color: #991b1b;
}

.alert--success {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
}

.role-badge--admin {
  background: #e0e7ff;
  color: #4338ca;
}

/* ── Status & Badges ───────────────────────────────────────── */
.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
}

.status-pill--ok {
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.status-pill--err {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fca5a5;
}

/* ── Buttons & Inputs Premium ──────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0.625rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  text-decoration: none;
  border: 1px solid transparent;
  line-height: 1.2;
}

.btn svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  display: block;
  /* Evita desalineación por línea de base de texto */
}

.btn--primary {
  background: var(--color-primary);
  color: white;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.2);
}

.btn--primary:hover {
  background: var(--color-primary-h);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.3);
}

.btn--secondary {
  background: white;
  color: var(--color-text);
  border-color: var(--color-border);
}

.btn--secondary:hover {
  background: var(--color-surface-2);
  border-color: var(--color-border-m);
}

.btn:active {
  transform: scale(0.96);
}

/* ── Page Content ───────────────────────────────────────────── */
.page-content {
  flex: 1;
  padding: 1.5rem 15px;
  /* Estrictamente 15px por cada lado */
  width: 100%;
}

/* ── Mobile ────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .main-wrapper {
    margin-left: 0;
  }

  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar-open .sidebar {
    transform: translateX(0);
  }

  /* Overlay */
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
  }

  .sidebar-open .sidebar-overlay {
    opacity: 1;
    visibility: visible;
  }
}

/* ── Footer ────────────────────────────────────────────────── */
.app-footer {
  padding: 1.25rem 15px;
  background: transparent;
  border-top: 1px solid var(--color-border);
  margin-top: auto;
}

.app-footer__inner {
  display: flex;
  justify-content: center;
  align-items: center;
}

.app-footer__text {
  font-size: 0.8125rem;
  color: var(--color-text-faint);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}

.env-label-dev {
  background: #fef2f2;
  color: #ef4444;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  border: 1px solid #fee2e2;
}

.env-label-pro {
  background: #f0fdf4;
  color: #10b981;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  border: 1px solid #dcfce7;
}

/* ── Formularios Globales ───────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.required-mark {
  color: var(--color-danger);
  margin-left: 2px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.65rem 0.9rem;
  font-size: 0.9rem;
  font-family: inherit;
  font-weight: 500;
  color: var(--color-text);
  background: white;
  border: 1.5px solid var(--color-border);
  border-radius: 10px;
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.form-input:hover,
.form-select:hover,
.form-textarea:hover {
  border-color: var(--color-border-m);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

.form-textarea {
  resize: vertical;
  min-height: 90px;
}

.form-select {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 0.75rem center;
  background-repeat: no-repeat;
  background-size: 1.2em;
  padding-right: 2.5rem;
  cursor: pointer;
}

.form-help {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  margin-top: 0.15rem;
}

.text-danger {
  color: var(--color-danger);
}

.text-sm {
  font-size: 0.82rem;
}

.text-muted {
  color: var(--color-text-muted);
}

.mt-4 {
  margin-top: 1rem;
}

/* ── Animaciones ────────────────────────────────────────────── */
@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in {
  animation: fadeUp 0.4s ease-out;
}

/* ── Botón ghost ────────────────────────────────────────────── */
.btn--ghost {
  background: transparent;
  color: var(--color-text-muted);
  border-color: var(--color-border);
}

.btn--ghost:hover {
  background: var(--color-surface-2);
  color: var(--color-text);
}

/* ── Utilities ──────────────────────────────────────────────── */
.d-none {
  display: none !important;
}

.mb-1 {
  margin-bottom: 0.25rem !important;
}

.mb-2 {
  margin-bottom: 0.5rem !important;
}

.mb-3 {
  margin-bottom: 1rem !important;
}

.mb-4 {
  margin-bottom: 1.5rem !important;
}

.mb-5 {
  margin-bottom: 2.5rem !important;
}

.mt-1 {
  margin-top: 0.25rem !important;
}

.mt-2 {
  margin-top: 0.5rem !important;
}

.mt-3 {
  margin-top: 1rem !important;
}

.mt-4 {
  margin-top: 1.5rem !important;
}

.mt-5 {
  margin-top: 2.5rem !important;
}