/* nSphere — sistema de diseño (portado de los paneles nicasphere: shadcn/ui + patrón de marca).
   Tema CLARO. Fuente única de estilos de la SPA (sustituye al <style> inline oscuro). */

/* Inter self-hosted (variable, pesos 100-900) — sin CDNs por CSP. */
@font-face {
  font-family: 'Inter';
  src: url('/fonts/InterVariable.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --fg: #020817;
  --muted-fg: #64748b;
  --border: #e2e8f0;
  --soft: #f1f5f9;
  --destructive: #ef4444;
  --page-bg: #f9fafb;
  --card-bg: #ffffff;
  /* Marca del shell de cliente — variables separadas: en el futuro las personaliza cada reseller. */
  --brand-primary: #2563eb;
  --brand-primary-dark: #1d4ed8;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, .05);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--page-bg);
  color: var(--fg);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary-hover); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: .85em;
  background: var(--soft);
  border-radius: 4px;
  padding: .1em .35em;
}

/* Iconos SVG inline (lucide): se alinean con el texto y heredan color. */
.ic { display: inline-flex; flex-shrink: 0; vertical-align: middle; }
.ic svg { display: block; }

/* ============ Layout general (shell dual) ============ */
.layout { min-height: 100vh; }
main {
  padding: 24px;
  max-width: 1152px;
  margin: 0 auto;
  width: 100%;
}

/* Cabecera de página (título + subtítulo de la vista) */
.page-head { margin: 0 0 20px; }
.page-head h1 { margin: 0; font-size: 22px; font-weight: 700; color: var(--fg); letter-spacing: -.02em; }
.page-head p { margin: 4px 0 0; font-size: 14px; color: var(--muted-fg); }

/* Topbar (compartida: blanca en admin, azul de marca en cliente) */
.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar .tb-title { font-size: 16px; font-weight: 600; color: var(--fg); }
.topbar .spacer { flex: 1; }

/* Botón hamburguesa — solo visible en móvil/tablet */
.hamb {
  display: none;
  background: none;
  border: 0;
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: inherit;
  height: auto;
}
.hamb:hover { background: rgba(0, 0, 0, .06); }

/* Avatar circular con iniciales */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  letter-spacing: .02em;
}

/* Overlay del off-canvas móvil */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  z-index: 40;
}
.overlay.show { display: block; }

/* ============ Shell ADMIN: sidebar oscura fija ============ */
.layout.admin { display: flex; }
.layout.admin .sidebar {
  width: 256px;
  flex-shrink: 0;
  background: #111827;
  color: #d1d5db;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 50;
}
.layout.admin .content { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.sb-logo {
  display: flex;
  align-items: center;
  padding: 20px 20px 16px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -.02em;
}
.sb-logo .logo-n { color: #fff; }
.sb-logo .logo-sphere { color: var(--primary); }

.layout.admin .sidebar nav { flex: 1; padding: 8px 12px; display: flex; flex-direction: column; gap: 2px; }
.layout.admin .sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  color: #d1d5db;
  text-decoration: none;
}
.layout.admin .sidebar nav a:hover,
.layout.admin .sidebar nav a.cur { background: #1f2937; color: #fff; }

/* Bloque de usuario al pie de la sidebar admin */
.sb-user {
  border-top: 1px solid #1f2937;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.sb-user .sb-name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 500;
  color: #f9fafb;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sb-user .sb-logout {
  background: none;
  border: 0;
  color: #9ca3af;
  cursor: pointer;
  padding: 6px;
  height: auto;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
}
.sb-user .sb-logout:hover { color: #fff; background: #1f2937; }

/* ============ Shell CLIENTE: topbar azul + sidebar blanca ============ */
.topbar.brand {
  background: var(--brand-primary);
  color: #fff;
  border-bottom: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .18);
}
.topbar.brand .hamb:hover { background: var(--brand-primary-dark); }
.brand-logo { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 700; letter-spacing: -.02em; }
.brand-logo .logo-box {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #fff;
  color: var(--brand-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 19px;
  font-weight: 800;
}

/* Menú de usuario (cliente) con dropdown */
.user-menu { position: relative; }
.user-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: 0;
  color: inherit;
  cursor: pointer;
  padding: 6px 8px;
  height: auto;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
}
.topbar.brand .user-btn:hover { background: var(--brand-primary-dark); }
.user-btn .avatar { background: #3b82f6; }
.dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .1);
  min-width: 180px;
  padding: 4px;
  z-index: 60;
}
.dropdown[hidden] { display: none; }
.dropdown button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: 0;
  text-align: left;
  padding: 9px 10px;
  height: auto;
  border-radius: var(--radius-sm);
  font-size: 14px;
  cursor: pointer;
  color: var(--fg);
}
.dropdown button.dd-danger { color: var(--destructive); }
.dropdown button:hover { background: var(--soft); }
.dropdown button.dd-danger:hover { background: #fee2e2; }

.cust-body { display: flex; }
.cust-body .sidebar {
  width: 256px;
  flex-shrink: 0;
  background: var(--card-bg);
  border-right: 1px solid var(--border);
  padding: 12px;
  position: sticky;
  top: 64px;
  height: calc(100vh - 64px);
  overflow-y: auto;
  z-index: 50;
}
.cust-body .sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.cust-body .sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 500;
  color: var(--fg);
  text-decoration: none;
}
.cust-body .sidebar nav a:hover { background: var(--page-bg); }
.cust-body .sidebar nav a.cur { background: #eff6ff; color: #2563eb; }
.cust-body .content { flex: 1; min-width: 0; }

/* ============ Cards ============ */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 24px;
  margin-bottom: 20px;
}
.card h2 { font-size: 16px; font-weight: 600; color: var(--fg); margin: 0 0 14px; }
.card h3 { font-size: 14px; font-weight: 600; color: var(--fg); margin: 20px 0 8px; }
.card p { margin: 0 0 12px; }

/* ============ Tablas ============ */
.tblwrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 12px 16px; border-bottom: 1px solid var(--border); }
th {
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted-fg);
  background: var(--page-bg);
  white-space: nowrap;
}
tbody tr:hover { background: var(--page-bg); }
tbody tr:last-child td { border-bottom: 0; }

/* ============ Badges de estado (tono-100 fondo / tono-700 texto) ============ */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--soft);
  color: #475569;
  white-space: nowrap;
  vertical-align: middle;
}
.b-running { background: #dbeafe; color: #1d4ed8; animation: pulse 1.3s ease-in-out infinite; }
.b-info    { background: #dbeafe; color: #1d4ed8; }
.b-done    { background: #dcfce7; color: #15803d; }
.b-failed  { background: #fee2e2; color: #b91c1c; }
.b-warn    { background: #fef9c3; color: #a16207; }
@keyframes pulse { 50% { opacity: .5; } }

/* Dots de estado on/off/unk */
.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.on .dot { background: #22c55e; }
.off .dot { background: #ef4444; }
.unk .dot { background: #f59e0b; }

/* ============ Botones ============ */
button {
  font-family: inherit;
  height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  border: 0;
  background: var(--primary);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
button:hover { background: var(--primary-hover); }
button.sec {
  background: var(--card-bg);
  border: 1px solid var(--border);
  color: var(--fg);
}
button.sec:hover { background: var(--soft); }
button.danger {
  background: var(--card-bg);
  border: 1px solid #fecaca;
  color: var(--destructive);
}
button.danger:hover { background: #fee2e2; }
button:disabled { opacity: .5; cursor: default; pointer-events: none; }
/* Compactos dentro de tablas para mantener la densidad de filas */
td button { height: 32px; padding: 0 12px; font-size: 13px; }
td button + button { margin-left: 6px; }
td select { width: auto; max-width: 240px; height: 32px; font-size: 13px; margin-right: 6px; }

/* ============ Formularios ============ */
label { display: block; font-size: 14px; font-weight: 500; color: var(--fg); margin: 12px 0 6px; }
input, select {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--fg);
  font-size: 14px;
  font-family: inherit;
}
textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--fg);
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, monospace;
  min-height: 7rem;
  resize: vertical;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
  border-color: #3b82f6;
}
input::placeholder, textarea::placeholder { color: #94a3b8; }

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; }
/* OJO: sin min-width:0 — los divs con flex:0 (botones) tienen flex-basis 0 y con
   min-width:0 colapsarían a 0 de ancho, sacando el botón fuera del layout. */
.row > div { flex: 1 1 12rem; }
.row label { margin-top: 0; }
.row button { margin-bottom: 1px; }

/* ============ Texto auxiliar ============ */
.muted { color: var(--muted-fg); font-size: 13px; }
.err { color: var(--destructive); font-size: 13px; margin-top: 8px; min-height: 1.1em; }
.errtx { color: var(--destructive); }
.oktx { color: #15803d; font-size: 13px; margin-top: 8px; }
pre.raw {
  background: var(--page-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  overflow-x: auto;
  font-size: 12px;
  color: #475569;
  margin: 4px 0 14px;
}

/* ============ Login ============ */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--page-bg);
  padding: 16px;
}
.login-wrap .card { width: 380px; max-width: 100%; margin-bottom: 0; }
.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -.02em;
  margin-bottom: 6px;
}
.login-logo .logo-box {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--brand-primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 800;
}
.login-logo .logo-sphere { color: var(--primary); }
.login-sub { text-align: center; color: var(--muted-fg); font-size: 14px; margin: 0 0 10px; }

/* ============ Responsive: sidebar off-canvas ≤1024px ============ */
@media (max-width: 1024px) {
  .hamb { display: inline-flex; }
  /* Admin: la sidebar sale por la izquierda a pantalla completa de alto */
  .layout.admin .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  .layout.admin .sidebar.open { transform: none; }
  /* Cliente: la sidebar sale bajo la topbar */
  .cust-body .sidebar {
    position: fixed;
    left: 0;
    top: 64px;
    height: calc(100vh - 64px);
    transform: translateX(-100%);
    transition: transform .2s ease;
  }
  .cust-body .sidebar.open { transform: none; }
}

@media (max-width: 640px) {
  main { padding: 16px; }
  .card { padding: 16px; }
  th, td { padding: 10px 12px; }
  .topbar { padding: 0 14px; }
  .user-btn .user-name { display: none; } /* en móvil solo el avatar */
}

/* ============ U8: switcher de org, tabs, ficha (kv) y utilidades ============ */
/* Switcher de organización en la topbar (solo con >1 membership) */
.org-switch { width: auto; max-width: 260px; min-width: 0; height: 34px; font-size: 13px; }
.topbar.brand .org-switch { border: 0; }
@media (max-width: 640px) { .org-switch { max-width: 150px; } }

/* Pestañas del detalle (organización) */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 0 0 16px; flex-wrap: wrap; }
.tabs a {
  padding: 9px 14px;
  font-size: 14px;
  color: var(--muted-fg);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs a:hover { color: var(--fg); text-decoration: none; }
.tabs a.cur { color: var(--primary-hover); border-bottom-color: var(--primary); font-weight: 500; }

/* Pares etiqueta/valor del modo lectura de la ficha */
dl.kv { display: grid; grid-template-columns: minmax(150px, 230px) 1fr; gap: 6px 16px; font-size: 14px; margin: 8px 0; }
dl.kv dt { color: var(--muted-fg); }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 640px) {
  dl.kv { grid-template-columns: 1fr; gap: 0; }
  dl.kv dt { margin-top: 8px; }
}

/* Filas clicables (listados con detalle) */
tr.rowlink { cursor: pointer; }

/* Error de validación del servidor BAJO su campo */
.ferr { color: var(--destructive); font-size: 12px; margin-top: 4px; }
.ferr:empty { display: none; }

/* URL de invitación con botón copiar */
.copyrow { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.copyrow input { flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, monospace; font-size: 12px; }
