/* ============================================================
   TitanPort Panel — hoja de estilos única.
   Estructura inspirada en el patrón "appshell" de Proxmox by TG:
   una tarjeta flotante sobre el fondo, con sidebar de navegación y
   panel de contenido, en vez de texto suelto sobre negro plano.
   ============================================================ */

:root {
  --bg: #eef1f6;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --text: #172033;
  --muted: #64748b;
  --line: #dbe3ee;
  --primary: #2f6fed;
  --primary-dark: #2555bd;
  --primary-contraste: #ffffff;
  --peligro: #dc2626;
  --exito: #16a34a;
  --aviso: #d97706;
  --radio-appshell: 22px;
  --radio-tarjeta: 14px;
  --radio-boton: 9px;
  --sombra: 0 18px 45px -22px rgba(23, 32, 51, 0.35);
  --sidebar-ancho: 240px;
  color-scheme: light;
}

:root[data-tema="dark"] {
  --bg: #0b1120;
  --surface: #121a2b;
  --surface-soft: #182235;
  --text: #e5edf7;
  --muted: #93a4bd;
  --line: #2a3752;
  --primary: #5b9bff;
  --primary-dark: #7fb0ff;
  --primary-contraste: #06101f;
  --peligro: #f87171;
  --exito: #4ade80;
  --aviso: #fbbf24;
  --sombra: 0 22px 55px -20px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }

* {
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background-color: var(--line);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background-color: var(--muted); }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background-color .2s ease, color .2s ease;
}

#app { min-height: 100%; }

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

.texto-tenue { color: var(--muted); }
.texto-pequeno { font-size: 12.5px; }

/* ---------------------------- App shell ---------------------------- */

.fondo-app {
  min-height: 100vh;
  display: flex;
  align-items: stretch;
  justify-content: center;
  padding: clamp(0px, 2.4vw, 28px);
}

.appshell {
  position: relative;
  width: 100%;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radio-appshell);
  box-shadow: var(--sombra);
  overflow: hidden;
  display: flex;
  height: calc(100vh - 56px);
}

@media (max-width: 720px) {
  .fondo-app { padding: 0; }
  .appshell { border-radius: 0; height: 100vh; flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 10px 14px; }
  .sidebar-nav { flex-direction: row; overflow-x: auto; overflow-y: hidden; }
  .sidebar-grupo { flex-direction: row; }
  .sidebar-grupo-titulo { display: none; }
  .sidebar-pie { border-top: none; border-left: 1px solid var(--line); padding-top: 0; padding-left: 10px; flex-direction: row; }
  .sidebar-marca { padding: 0 10px 0 0; }
}

/* ---------------------------- Sidebar ---------------------------- */

.sidebar {
  width: var(--sidebar-ancho);
  flex-shrink: 0;
  background: var(--surface-soft);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  gap: 8px;
}

.sidebar-marca {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 18px;
}
.sidebar-marca-icono {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--primary);
  color: var(--primary-contraste);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
  overflow: hidden;
}
.sidebar-marca-icono img { width: 100%; height: 100%; object-fit: cover; }
.sidebar-titulo { font-weight: 700; font-size: 15px; }

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.sidebar-grupo { display: flex; flex-direction: column; gap: 3px; }
.sidebar-grupo-titulo {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  padding: 0 10px;
  margin-bottom: 4px;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 9px 10px;
  border-radius: var(--radio-boton);
  font-size: 13.5px;
  cursor: pointer;
  outline: none;
  white-space: nowrap;
}
.sidebar-item:hover { background: var(--line); }
.sidebar-item.activo { background: var(--primary); color: var(--primary-contraste); }
.sidebar-item-icono {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.sidebar-item-icono svg { width: 16px; height: 16px; }

.sidebar-pie {
  border-top: 1px solid var(--line);
  padding-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sidebar-usuario {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px 10px 8px;
  font-size: 12.5px;
}
.sidebar-usuario-email { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-usuario-badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge {
  display: inline-flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}
.badge-primario { border-color: var(--primary); color: var(--primary); }

.sidebar-item-peligro:hover { background: color-mix(in srgb, var(--peligro) 15%, transparent); color: var(--peligro); }

/* ---------------------------- Contenido ---------------------------- */

.contenido {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.contenido-cabecera {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.contenido-cabecera h1 { font-size: 19px; margin: 0; }
.contenido-cabecera p { margin: 4px 0 0; font-size: 13px; color: var(--muted); }

.contenido-cuerpo {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px 28px 40px;
}

.contenido-cuerpo-centrado {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

/* ---------------------------- Pantallas centradas (login) ------------- */

.pantalla-centrada {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}

.tarjeta-auth {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radio-tarjeta);
  box-shadow: var(--sombra);
  padding: 32px;
}

.marca-auth {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}
.marca-auth .sidebar-marca-icono { width: 38px; height: 38px; font-size: 16px; border-radius: 11px; }
.marca-auth h1 { font-size: 19px; margin: 0; }

.tarjeta-auth p.subtitulo {
  color: var(--muted);
  font-size: 13px;
  margin: 4px 0 22px;
}

/* ---------------------------- Formularios ------------------------------ */

.campo { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; margin-bottom: 14px; }
.campo label { font-weight: 600; color: var(--text); font-size: 13px; }

.campo input[type="text"],
.campo input[type="email"],
.campo input[type="password"],
.campo input[type="number"],
.campo select {
  border: 1px solid var(--line);
  border-radius: var(--radio-boton);
  padding: 10px 12px;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color .15s ease;
  width: 100%;
}
.campo input:focus, .campo select:focus { border-color: var(--primary); }

.campo input.codigo-otp {
  letter-spacing: 6px;
  font-size: 20px;
  text-align: center;
}

.campo-checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}
.campo-checkbox label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
  cursor: pointer;
}
.campo-checkbox input { width: 16px; height: 16px; }

/* ---------------------------- Botones ---------------------------- */

.boton {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  border-radius: var(--radio-boton);
  padding: 10px 18px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: filter .15s ease, transform .05s ease;
  text-decoration: none;
}
.boton:active { transform: translateY(1px); }
.boton:disabled { opacity: .55; cursor: default; pointer-events: none; }

.boton-primario { background: var(--primary); color: var(--primary-contraste); }
.boton-primario:hover { filter: brightness(1.08); }
.boton-primario.boton-ancho { width: 100%; justify-content: center; }

.boton-secundario { background: var(--surface-soft); color: var(--text); border: 1px solid var(--line); }
.boton-secundario:hover { filter: brightness(0.97); }

.boton-enlace {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}
.boton-enlace:hover { color: var(--text); }

/* ---------------------------- Tarjetas / secciones --------------------- */

.cabecera-seccion {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
  gap: 12px;
  flex-wrap: wrap;
}
.cabecera-seccion h2 { margin: 0; font-size: 16px; }

.tarjeta {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radio-tarjeta);
  padding: 20px;
}
.tarjeta-formulario { margin-top: 20px; max-width: 440px; }
.tarjeta-formulario h3 { margin: 0 0 16px; font-size: 15px; }
.tarjeta-formulario .boton { margin-right: 10px; }

/* ---------------------------- Tabla de datos --------------------------- */

.tabla-datos {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radio-tarjeta);
  overflow: hidden;
  font-size: 13.5px;
}
.tabla-datos th, .tabla-datos td {
  padding: 11px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.tabla-datos th {
  color: var(--muted);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .04em;
  background: var(--surface-soft);
}
.tabla-datos tbody tr:last-child td { border-bottom: none; }
.tabla-datos tbody tr:hover td { background: var(--surface-soft); }

/* ---------------------------- Toasts ------------------------------------ */

.toasts-contenedor {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}

.toast {
  min-width: 240px;
  max-width: 360px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--sombra);
  font-size: 13.5px;
  color: var(--text);
  display: flex;
  align-items: flex-start;
  gap: 8px;
  animation: toast-entrada 0.18s ease-out;
}
.toast.exito { border-left: 3px solid var(--exito); }
.toast.error { border-left: 3px solid var(--peligro); }

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