/* ============================================================
   Vittamia Admin — Sistema de diseño del panel (WI-060)
   Tokens, layout con sidebar, topbar, cards, tablas, badges,
   botones, formulario y overlay de login.
   ============================================================ */

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e5e9f2;
  --text: #17203a;
  --text-2: #5b6478;
  --muted: #8a93a8;
  --brand: #4f46e5;
  --brand-600: #4338ca;
  --brand-soft: #eef2ff;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --info: #0369a1;
  --info-soft: #e0f2fe;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(23, 32, 58, .05), 0 8px 24px -12px rgba(23, 32, 58, .12);
  --sidebar-w: 240px;
}

* { box-sizing: border-box; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 5px; font-size: 12px; }

/* ---------- Layout: sidebar + contenido ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: #111633;
  color: #cbd2e6;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 18px;
  color: #fff;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: .2px;
}
.sidebar .brand .logo {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 17px;
  box-shadow: 0 4px 12px rgba(99, 102, 241, .45);
}

.sidebar nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: #aab2cc;
  font-weight: 500;
  font-size: 13.5px;
  transition: background .15s, color .15s;
}
.sidebar nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; text-decoration: none; }
.sidebar nav a.active { background: var(--brand); color: #fff; box-shadow: 0 4px 14px rgba(79, 70, 229, .4); }
.sidebar nav a .ico { width: 20px; text-align: center; font-size: 15px; }

.sidebar .foot { padding: 12px 10px 0; border-top: 1px solid rgba(255, 255, 255, .08); font-size: 12px; color: #6f7a99; }
.sidebar .foot .who { color: #cbd2e6; font-weight: 600; margin-bottom: 2px; }

.content { flex: 1; padding: 28px 32px 48px; min-width: 0; }

/* ---------- Topbar ---------- */
.topbar { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; flex-wrap: wrap; }
.topbar h1 { font-size: 21px; margin: 0; font-weight: 700; }
.topbar .sub { color: var(--text-2); font-size: 13px; }
.topbar .spacer { flex: 1; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 16px;
  border: 0; border-radius: 10px;
  background: var(--brand); color: #fff;
  font-size: 13.5px; font-weight: 600; font-family: inherit;
  cursor: pointer;
  transition: background .15s, transform .05s;
}
.btn:hover { background: var(--brand-600); }
.btn:active { transform: translateY(1px); }
.btn.ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 5px 11px; font-size: 12px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.card h2 { font-size: 15px; margin: 0 0 12px; font-weight: 700; }
.card .hint { color: var(--text-2); font-size: 12.5px; margin: -6px 0 12px; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.stat .n { font-size: 26px; font-weight: 800; line-height: 1.1; }
.stat .l { color: var(--text-2); font-size: 12.5px; margin-top: 3px; }
.stat.accent-brand .n { color: var(--brand); }
.stat.accent-ok .n { color: var(--ok); }
.stat.accent-warn .n { color: var(--warn); }
.stat.accent-danger .n { color: var(--danger); }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); font-weight: 700;
  border-bottom: 1px solid var(--border);
  padding: 9px 10px;
  white-space: nowrap;
}
table.data td { border-bottom: 1px solid var(--border); padding: 10px; vertical-align: top; }
table.data tr:hover td { background: var(--surface-2); }
table.data td.actions { white-space: nowrap; }
table.data .muted { color: var(--muted); }
tr.reviewed td { opacity: .5; }

/* ---------- Badges / pills ---------- */
.pill { display: inline-block; font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.off { background: #eceef3; color: var(--text-2); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.ERROR { background: var(--danger-soft); color: var(--danger); }
.pill.WARN { background: var(--warn-soft); color: var(--warn); }
.pill.INFO { background: var(--info-soft); color: var(--info); }
.pill.src { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.pill.star { background: rgba(255, 215, 0, 0.15); color: #ffd700; border: 1px solid rgba(255, 215, 0, 0.35); font-weight: 700; }
.zone.green { color: var(--ok); font-weight: 700; }
.zone.yellow { color: var(--warn); font-weight: 700; }
.zone.red { color: var(--danger); font-weight: 700; }

/* Estándar Global: Icono estrella para planes y suscripciones */
.nav-star-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #ffd700;
  filter: drop-shadow(0 0 6px rgba(255, 215, 0, 0.45));
  font-size: 1.15rem;
  transition: transform 0.2s ease, filter 0.2s ease;
  cursor: pointer;
}
.nav-star-badge:hover {
  transform: scale(1.18);
  filter: drop-shadow(0 0 10px rgba(255, 215, 0, 0.7));
}

/* ---------- Filtros ---------- */
.filters { display: flex; gap: 9px; flex-wrap: wrap; margin-bottom: 4px; }
.filters select, .filters input[type="text"], .filters input[type="email"] {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: 13px; font-family: inherit;
  color: var(--text);
}
.filters input[type="text"], .filters input[type="email"] { flex: 1; min-width: 170px; }
.filters select:focus, .filters input:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }

/* ---------- Formulario ---------- */
form.editor label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin: 14px 0 5px; }
form.editor input[type="text"], form.editor select, form.editor textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px; font-family: inherit;
  background: var(--surface);
  color: var(--text);
}
form.editor textarea { min-height: 110px; resize: vertical; }
form.editor input:focus, form.editor select:focus, form.editor textarea:focus {
  outline: 2px solid var(--brand-soft); border-color: var(--brand);
}
.form-actions { display: flex; gap: 10px; margin-top: 18px; }
.char-count { font-size: 11px; color: var(--muted); text-align: right; margin-top: 3px; }

/* ---------- Estado / mensajes ---------- */
.status { font-size: 13px; color: var(--text-2); min-height: 20px; margin: 10px 0; }
.status.err { color: var(--danger); font-weight: 600; }
details pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 10px; border-radius: 8px;
  overflow: auto; max-width: 440px;
  font-size: 11.5px;
}

/* ---------- Health card ---------- */
.hb-row { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.hb-row:last-child { border-bottom: 0; }
.hb-row .name { font-weight: 600; min-width: 220px; }
.hb-row .detail { color: var(--muted); font-size: 12.5px; flex: 1; min-width: 200px; }
.state { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; font-size: 12.5px; }
.state::before { content: ''; width: 8px; height: 8px; border-radius: 50%; }
.state.ok { color: var(--ok); } .state.ok::before { background: var(--ok); }
.state.late { color: var(--warn); } .state.late::before { background: var(--warn); }
.state.fail { color: var(--danger); } .state.fail::before { background: var(--danger); }

/* ---------- Página Tokens de IA (WI-061) ---------- */
.group-card .row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.group-card .row .info { flex: 1; min-width: 240px; }
.group-card .name { font-weight: 700; font-size: 14.5px; }
.group-card .meta { color: var(--text-2); font-size: 12.5px; margin-top: 2px; }
.group-card .meta code { font-size: 11.5px; word-break: break-all; }
.group-card .missing { color: var(--danger); font-size: 12px; margin-top: 4px; }
.runbook { position: relative; }
.runbook pre {
  background: #111633; color: #d6dcf0;
  padding: 14px 16px; border-radius: 10px;
  overflow-x: auto; font-size: 12px; line-height: 1.55;
  margin: 0; max-width: none;
  position: relative; padding-right: 90px;
}
.runbook .copy-btn { position: absolute; top: 8px; right: 8px; }
.runbook h3 { font-size: 13.5px; margin: 18px 0 8px; }
.runbook h3:first-of-type { margin-top: 0; }
.runbook .note { color: var(--text-2); font-size: 12.5px; margin: 6px 0 10px; }
@media (max-width: 900px) {
  .runbook pre { white-space: pre-wrap; word-break: break-all; padding: 12px 14px; }
  .runbook .copy-btn { position: static; margin-top: 8px; }
}

/* ---------- Modal de detalle de usuario ---------- */
/* hidden debe ganar sobre display:flex: sin esta regla el overlay queda visible siempre (WI-063) */
.modal-overlay {
  position: fixed; inset: 0; z-index: 40;
  display: flex; align-items: flex-start; justify-content: center;
  background: rgba(17, 22, 51, .45);
  padding: 40px 16px;
  overflow: auto;
}
.modal-overlay[hidden] { display: none; }
.modal-overlay .card { max-width: 640px; width: 100%; margin: 0; }

/* ---------- Diálogos y toasts (WI-064) ---------- */
.dialog-stack { z-index: 60; align-items: center; padding: 20px 16px; }
.dialog-box { max-width: 460px; }
.dialog-box .dialog-title { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.dialog-box .dialog-body { font-size: 13.5px; color: var(--text); }
.dialog-box .dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.dialog-box .dialog-label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.dialog-box input[type="text"] {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  font-size: 13.5px; font-family: inherit; background: var(--surface); color: var(--text);
}
.dialog-box input[type="text"]:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.dialog-pre {
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 10px; border-radius: 8px; margin: 0;
  white-space: pre-wrap; word-break: break-word; font-size: 12.5px;
}
#toastHolder { position: fixed; right: 18px; bottom: 18px; z-index: 70; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #111633; color: #fff; border-radius: 10px;
  padding: 11px 16px; font-size: 13px; font-weight: 500; font-family: inherit;
  box-shadow: 0 8px 24px -8px rgba(0, 0, 0, .45);
  opacity: 1; transform: translateY(0); transition: opacity .3s, transform .3s;
  max-width: 340px;
}
.toast.ok { border-left: 4px solid var(--ok); }
.toast.err { border-left: 4px solid var(--danger); }
.toast.out { opacity: 0; transform: translateY(8px); }

/* ---------- Overlay de login ---------- */
#loginOverlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(800px 500px at 20% 10%, rgba(99, 102, 241, .25), transparent 60%),
    radial-gradient(700px 500px at 85% 90%, rgba(139, 92, 246, .22), transparent 60%),
    #111633;
  padding: 20px;
}
#loginOverlay[hidden] { display: none; }
.login-box {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border-radius: 18px;
  box-shadow: 0 24px 60px -18px rgba(0, 0, 0, .5);
  padding: 32px 30px 26px;
}
.login-box .logo {
  width: 48px; height: 48px; border-radius: 14px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 22px; font-weight: 800;
  margin-bottom: 14px;
  box-shadow: 0 8px 20px rgba(99, 102, 241, .45);
}
.login-box h2 { margin: 0 0 3px; font-size: 20px; font-weight: 800; }
.login-box .sub { color: var(--text-2); font-size: 13.5px; margin-bottom: 22px; }
.login-box input {
  width: 100%; padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 11px;
  font-size: 14px; font-family: inherit;
  background: var(--surface-2);
  color: var(--text);
}
.login-box input:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); background: #fff; }
.login-box .btn { width: 100%; justify-content: center; padding: 12px; font-size: 14px; margin-top: 4px; }
.login-error { color: var(--danger); font-size: 13px; min-height: 20px; margin: 10px 0 4px; font-weight: 600; }
.login-back { text-align: center; margin-top: 10px; font-size: 12.5px; }
.login-back a { color: var(--muted); }

/* ---------- Responsive Navbar & Menu Drawer ---------- */
.menu-btn {
  display: none;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s;
}
.menu-btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

.mobile-menu-drawer {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #111633;
  border-bottom: 3px solid var(--brand);
  padding: 16px 20px;
  z-index: 9999;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
  max-height: 90vh;
  overflow-y: auto;
}
.mobile-menu-drawer.open {
  display: block;
}
.mobile-menu-drawer nav {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px;
}
.mobile-menu-drawer nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 8px;
  color: #cbd2e6;
  font-weight: 500;
  background: rgba(255, 255, 255, 0.04);
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.mobile-menu-drawer nav a:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}
.mobile-menu-drawer nav a.active {
  background: var(--brand);
  color: #fff;
  font-weight: 700;
}

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: sticky;
    top: 0; z-index: 100;
    flex-direction: row; align-items: center;
    padding: 10px 14px; gap: 10px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  }
  .sidebar .brand { padding: 0 8px 0 2px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
  .sidebar .brand .logo { width: 30px; height: 30px; font-size: 15px; }
  .sidebar nav {
    flex-direction: row; flex: 1;
    overflow-x: auto;
    scrollbar-width: thin;
    gap: 4px;
  }
  .sidebar nav a { padding: 8px 11px; white-space: nowrap; flex-shrink: 0; }
  .sidebar nav a span.lbl { display: none; }
  .sidebar nav a.active span.lbl { display: inline-block; margin-left: 6px; font-weight: 600; font-size: 12.5px; }
  .sidebar .foot { display: none; }
  .menu-btn { display: inline-flex; }
  .content { padding: 18px 14px 40px; }
}
/* ---------- Paginación (WI-094) ---------- */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  border-bottom-left-radius: var(--radius);
  border-bottom-right-radius: var(--radius);
  font-size: 13px;
}
.pagination-info { color: var(--text-2); }
.pagination-controls { display: flex; gap: 6px; }
.page-btn {
  padding: 6px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
}
.page-btn:hover:not(:disabled) {
  background: var(--surface-2);
  border-color: var(--brand-soft);
}
.page-btn.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}
.page-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Rediseño moderno de forms y tablas (WI-094) */
table.data { border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); overflow: hidden; }
table.data th { background: #f8fafc; font-size: 11.5px; padding: 12px 14px; border-bottom: 2px solid var(--border); }
table.data td { padding: 12px 14px; vertical-align: middle; }

/* Grid genérico */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

@media (max-width: 768px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .pagination { flex-direction: column; gap: 10px; align-items: center; }
}

/* Tooltips básicos */
[data-tooltip] {
  position: relative;
  cursor: help;
}
[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-6px);
  background: #111633;
  color: #fff;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 11px;
  white-space: nowrap;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  pointer-events: none;
}
