/* =============================================================================
 * ¡A Crear! — Panel del gestor (Fase 5)
 * ============================================================================= */

:root {
  --color-primary: #6F2C91;
  --color-primary-hover: #5A2376;
  --color-primary-soft: #F3E8F8;
  --color-accent: #F2A93B;
  --color-bg: #FFFFFF;
  --color-surface: #FAFAFA;
  --color-text: #1A1A1A;
  --color-text-muted: #6B6B6B;
  --color-success: #2E7D32;
  --color-success-soft: #E8F5E9;
  --color-warning: #ED6C02;
  --color-warning-soft: #FFF3E0;
  --color-danger: #C62828;
  --color-danger-soft: #FFEBEE;
  --color-border: #E5E5E5;
  --color-input-bg: #FFFFFF;
  --color-stripe: #FBF8FC;
  --color-sidebar-bg: #2A1638;
  --color-sidebar-text: #E9D6F1;
  --color-sidebar-active: #6F2C91;

  --font-sans: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(111, 44, 145, 0.10);
  --shadow-lg: 0 8px 24px rgba(111, 44, 145, 0.15);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-surface);
  -webkit-font-smoothing: antialiased;
}

#root { min-height: 100vh; }

/* ---------- Login screen ---------- */
.auth-shell {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 2rem 1.5rem;
  min-height: 100vh;
  background: linear-gradient(160deg, #2A1638 0%, #4A1D62 100%);
  color: #fff;
}
.auth-shell .brand {
  text-align: center;
  margin-bottom: 2rem;
}
.auth-shell .brand .logo {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.auth-shell .brand .tagline {
  font-size: 0.95rem;
  opacity: 0.85;
  margin-top: 0.25rem;
}
.auth-card {
  background: #fff;
  color: var(--color-text);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: var(--shadow-lg);
  max-width: 420px;
  width: 100%;
}
.auth-card h2 {
  margin: 0 0 1rem;
  font-size: 1.15rem;
}

/* ---------- Layout principal del gestor (sidebar + main) ---------- */
.admin-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
@media (max-width: 899px) {
  .admin-shell {
    grid-template-columns: 1fr;
  }
}

.sidebar {
  background: var(--color-sidebar-bg);
  color: var(--color-sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 1rem 0;
}
@media (max-width: 899px) {
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 100;
    padding: 0.5rem 0;
    box-shadow: var(--shadow-md);
  }
}

.sidebar-brand {
  padding: 0.5rem 1.25rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 0.75rem;
}
.sidebar-brand .logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.01em;
}
.sidebar-brand .tag {
  font-size: 0.75rem;
  opacity: 0.7;
  margin-top: 0.125rem;
}
@media (max-width: 899px) {
  .sidebar-brand {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem 0.5rem;
    border-bottom: none;
    margin-bottom: 0;
  }
  .sidebar-brand .logo { font-size: 1rem; }
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  padding: 0 0.5rem;
  flex: 1;
}
@media (max-width: 899px) {
  .sidebar-nav {
    flex-direction: row;
    overflow-x: auto;
    padding: 0 0.5rem 0.5rem;
    gap: 0.25rem;
  }
}

.nav-item {
  background: none;
  border: none;
  color: var(--color-sidebar-text);
  text-align: left;
  padding: 0.625rem 0.875rem;
  border-radius: var(--radius-md);
  font: inherit;
  cursor: pointer;
  transition: background 0.12s;
  white-space: nowrap;
  font-size: 0.9rem;
}
.nav-item:hover {
  background: rgba(255,255,255,0.08);
  color: #fff;
}
.nav-item.activo {
  background: var(--color-sidebar-active);
  color: #fff;
  font-weight: 600;
}

.sidebar-foot {
  padding: 1rem 1.25rem 0.5rem;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 0.75rem;
  opacity: 0.7;
}
@media (max-width: 899px) {
  .sidebar-foot { display: none; }
}

.user-block {
  padding: 0 1.25rem 0.75rem;
  font-size: 0.8125rem;
}
.user-block .nombre {
  color: #fff;
  font-weight: 600;
}
.user-block .rol {
  opacity: 0.65;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.user-block button {
  margin-top: 0.5rem;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.12);
  color: #fff;
  font: inherit;
  font-size: 0.8125rem;
  padding: 0.375rem 0.625rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.user-block button:hover {
  background: rgba(255,255,255,0.12);
}
@media (max-width: 899px) {
  .user-block {
    padding: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }
  .user-block .rol { display: none; }
  .user-block .nombre {
    font-size: 0.875rem;
  }
}

.admin-main {
  padding: 1.5rem 1.75rem;
  background: var(--color-surface);
  min-height: 100vh;
}
@media (max-width: 899px) {
  .admin-main { padding: 1rem 1rem 2rem; }
}

.admin-main h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
  color: var(--color-text);
}
.admin-main .subtitle {
  margin: 0 0 1.5rem;
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

/* ---------- Cards ---------- */
.card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 1rem; }
.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.05rem;
  font-weight: 600;
}

/* ---------- Botones ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 40px;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  border: none;
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.12s, transform 0.05s;
  user-select: none;
}
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { cursor: not-allowed; opacity: 0.5; }

.btn-primary {
  background: var(--color-primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover:not(:disabled) { background: var(--color-primary-hover); }

.btn-secondary {
  background: var(--color-primary-soft);
  color: var(--color-primary);
}
.btn-secondary:hover:not(:disabled) { background: #E9D6F1; }

.btn-danger {
  background: var(--color-danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) { background: #B71C1C; }

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

.btn-danger-ghost {
  background: transparent;
  color: var(--color-danger);
  font-weight: 500;
}
.btn-danger-ghost:hover:not(:disabled) { background: var(--color-danger-soft); }

.btn-block { width: 100%; }
.btn-sm { min-height: 32px; padding: 0.375rem 0.75rem; font-size: 0.8125rem; }
.btn-icon { padding: 0.375rem 0.5rem; min-height: 32px; }

.btn-row { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ---------- Inputs ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  margin-bottom: 1rem;
}
.field label {
  font-size: 0.875rem;
  font-weight: 600;
}
.field .hint {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}
.field .error-text {
  font-size: 0.8125rem;
  color: var(--color-danger);
}
.input, .select {
  width: 100%;
  min-height: 40px;
  padding: 0.5rem 0.75rem;
  background: var(--color-input-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font: inherit;
  font-size: 0.95rem;
  color: var(--color-text);
  transition: border-color 0.12s, box-shadow 0.12s;
}
.input:focus, .select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(111, 44, 145, 0.18);
}
.input.invalid { border-color: var(--color-danger); }
.input:disabled { background: var(--color-surface); color: var(--color-text-muted); }

/* ---------- Toolbar (lista + filtros + acciones) ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.625rem;
  align-items: end;
  margin-bottom: 1rem;
}
.toolbar .grow { flex: 1 1 220px; }
.toolbar .field { margin-bottom: 0; }
.toolbar-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.875rem;
  margin-bottom: 0.25rem;
  cursor: pointer;
  user-select: none;
}

/* ---------- Tabla ---------- */
.tabla-wrap {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--color-bg);
}
.tabla {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.tabla th, .tabla td {
  padding: 0.625rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}
.tabla thead th {
  background: var(--color-primary-soft);
  color: var(--color-primary);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.tabla thead th.no-sort { cursor: default; }
.tabla thead th .sort-icon {
  display: inline-block;
  margin-left: 0.25rem;
  font-size: 0.7rem;
  opacity: 0.5;
}
.tabla thead th.activo .sort-icon { opacity: 1; }
.tabla tbody tr:nth-child(even) { background: var(--color-stripe); }
.tabla tbody tr.eliminado { background: #FAFAFA; color: var(--color-text-muted); }
.tabla tbody tr.eliminado td:not(:last-child) { text-decoration: line-through; opacity: 0.7; }
.tabla tbody tr:hover { background: var(--color-primary-soft); }
.tabla tbody tr.eliminado:hover { background: #F0E4F2; }

.tabla-acciones {
  white-space: nowrap;
  text-align: right;
}
.tabla-acciones .btn { margin-left: 0.25rem; }

.tabla-vacia {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--color-text-muted);
}

/* En móvil: tabla con scroll horizontal */
@media (max-width: 599px) {
  .tabla-wrap {
    overflow-x: auto;
  }
  .tabla {
    min-width: 600px;
  }
}

/* ---------- Paginación ---------- */
.paginacion {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.875rem;
  padding-top: 0.625rem;
}
.paginacion-info {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  text-align: center;
}
.paginacion-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.paginacion-actual {
  font-size: 0.8125rem;
  font-weight: 600;
}
@media (min-width: 600px) {
  .paginacion {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
  .paginacion-info { text-align: left; }
}

/* ---------- Notices ---------- */
.notice {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}
.notice-info { background: var(--color-primary-soft); color: var(--color-primary); }
.notice-success { background: var(--color-success-soft); color: var(--color-success); }
.notice-warning { background: var(--color-warning-soft); color: var(--color-warning); }
.notice-error { background: var(--color-danger-soft); color: var(--color-danger); }

/* ---------- Toast ---------- */
.toast-container {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 380px;
}
.toast {
  padding: 0.875rem 1rem;
  border-radius: var(--radius-md);
  color: #fff;
  font-size: 0.9rem;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.18s ease-out;
}
.toast.success { background: var(--color-success); }
.toast.error { background: var(--color-danger); }
.toast.info { background: var(--color-primary); }

@keyframes toast-in {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* ---------- Spinner ---------- */
.spinner {
  display: inline-block;
  width: 1em;
  height: 1em;
  border: 2px solid currentColor;
  border-bottom-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 8, 28, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
  animation: modal-in 0.12s ease-out;
}
@keyframes modal-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--color-text);
}
.modal-close {
  background: none;
  border: none;
  color: var(--color-text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
}
.modal-close:hover { background: var(--color-surface); }
.modal-body { padding: 1.25rem; }
.modal-footer {
  padding: 0.875rem 1.25rem;
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.pill {
  display: inline-block;
  background: var(--color-warning-soft);
  color: var(--color-warning);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  margin-left: 0.25rem;
  vertical-align: middle;
}
