:root {
  --ink: #1b2430;
  --muted: #69727f;
  --accent: #4f6cff;
  --accent-soft: rgba(79, 108, 255, .12);
  --ok: #2f9e6f;
  --warn: #c98a2b;
  --danger: #db5461;

  /* Liquid glass */
  --glass: rgba(255, 255, 255, .55);
  --glass-strong: rgba(255, 255, 255, .72);
  --glass-border: rgba(255, 255, 255, .65);
  --glass-shadow: 0 8px 32px rgba(27, 36, 48, .10);
  --hairline: rgba(27, 36, 48, .08);
  --radius: 16px;
  --radius-sm: 10px;
  --blur: saturate(170%) blur(22px);
  --sidebar-w: 178px;
  --sidebar-w-collapsed: 50px;
  --topbar-h: 46px;
  --bottom-nav-h: 58px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, Segoe UI, Roboto, Arial, sans-serif;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  background: #eef1f6;
  position: relative;
  overflow-x: hidden;
}
/* Fondo minimalista con halos suaves de color */
body::before {
  content: "";
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(46rem 46rem at 12% -8%, rgba(79,108,255,.18), transparent 60%),
    radial-gradient(40rem 40rem at 105% 12%, rgba(150, 120, 255, .14), transparent 60%),
    radial-gradient(48rem 48rem at 78% 110%, rgba(80, 190, 200, .12), transparent 60%),
    linear-gradient(160deg, #eef2f8 0%, #f3f0f7 50%, #eaf0f6 100%);
}

a { color: var(--accent); text-decoration: none; }
a:hover { opacity: .8; }

/* ---------- Nav ---------- */
.nav {
  display: flex; align-items: center; gap: 22px;
  padding: 14px 26px; position: sticky; top: 0; z-index: 50;
  background: var(--glass);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border-bottom: 1px solid var(--glass-border);
}
.nav .brand { font-weight: 650; font-size: 18px; color: var(--ink); letter-spacing: -.2px; }
.nav .brand span { color: var(--accent); }
.nav .spacer { flex: 1; }
.nav a { color: var(--muted); font-size: 14px; }
.nav a:hover { color: var(--ink); opacity: 1; }
/* Los enlaces-botón del nav conservan su color propio (no el gris de .nav a) */
.nav a.btn { color: #fff; }
.nav a.btn:hover { color: #fff; }
.nav a.btn.ghost { color: var(--ink); }

/* ---------- Layout (visitantes anónimos: landing/login/register) ---------- */
.page { min-height: 100vh; display: flex; flex-direction: column; }
.container { max-width: 1060px; margin: 0 auto; padding: 34px 22px; width: 100%; flex: 1; }
.narrow { max-width: 440px; }

/* ---------- App shell (autenticados): sidebar + topbar ---------- */
.app-shell { display: flex; min-height: 100vh; align-items: stretch; }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; overflow-y: auto; overflow-x: hidden;
  background: var(--glass); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border-right: 1px solid var(--glass-border);
  transition: width .15s ease;
}
html.sidebar-collapsed .sidebar { width: var(--sidebar-w-collapsed); }

.sidebar-top { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 12px 10px; border-bottom: 1px solid var(--hairline); }
.sidebar-brand { display: flex; align-items: center; gap: 8px; overflow: hidden; min-width: 0; }
.sidebar-brand-mark {
  width: 20px; height: 20px; border-radius: 6px; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.sidebar-brand-mark .ic { width: 12px; height: 12px; }
.sidebar-brand-text { font-weight: 650; font-size: 12.5px; color: var(--ink); white-space: nowrap; letter-spacing: -.2px; }
.sidebar-brand-text span { color: var(--accent); }
html.sidebar-collapsed .sidebar-brand-text { display: none; }

.sidebar-toggle {
  width: 20px; height: 20px; border-radius: 6px; border: 1px solid var(--hairline); background: transparent;
  display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--muted); flex-shrink: 0;
}
.sidebar-toggle:hover { background: var(--glass-strong); color: var(--ink); }
.sidebar-toggle .ic { width: 11px; height: 11px; transition: transform .15s ease; }
html.sidebar-collapsed .sidebar-toggle .ic { transform: rotate(180deg); }
html.sidebar-collapsed .sidebar-top { justify-content: center; }
html.sidebar-collapsed .sidebar-top .sidebar-toggle { position: absolute; top: 10px; right: 8px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; padding: 8px 7px; flex: 1; }
.sidebar-bottom { padding: 7px; border-top: 1px solid var(--hairline); }

.sidebar-link {
  display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 7px;
  color: var(--muted); font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden;
}
.sidebar-link:hover { background: var(--accent-soft); color: var(--ink); text-decoration: none; opacity: 1; }
.sidebar-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 650; }
.sidebar-icon { display: flex; flex-shrink: 0; }
.sidebar-icon .ic { width: 13.5px; height: 13.5px; }
.sidebar-label { overflow: hidden; text-overflow: ellipsis; }
html.sidebar-collapsed .sidebar-label { display: none; }
html.sidebar-collapsed .sidebar-link { justify-content: center; padding: 7px; }

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h); display: flex; align-items: center; gap: 6px; padding: 0 16px;
  background: var(--glass); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border-bottom: 1px solid var(--glass-border); position: sticky; top: 0; z-index: 40;
}
.topbar-spacer { flex: 1; }
.topbar-item { position: relative; }

.icon-btn {
  width: 32px; height: 32px; border-radius: 8px; border: none; background: transparent;
  display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--muted); position: relative;
}
.icon-btn:hover { background: var(--glass-strong); color: var(--ink); }
.icon-btn .ic { width: 18px; height: 18px; }
.notif-dot {
  position: absolute; top: 1px; right: 1px; min-width: 14px; height: 14px; padding: 0 3px;
  border-radius: 999px; background: var(--danger); color: #fff; font-size: 9px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; line-height: 1;
}

.profile-btn { background: transparent; border: none; cursor: pointer; padding: 0; display: flex; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 12.5px; font-weight: 700;
}

.dropdown {
  position: absolute; top: calc(100% + 8px); right: 0; min-width: 230px; max-width: 300px;
  background: var(--glass-strong); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border: 1px solid var(--glass-border); border-radius: var(--radius-sm); box-shadow: var(--glass-shadow);
  padding: 6px; display: none; z-index: 50;
}
.dropdown.open { display: block; }
.dropdown-title {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  padding: 7px 9px 5px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dropdown-item { display: flex; align-items: center; gap: 8px; padding: 7px 9px; border-radius: 7px; font-size: 12.5px; color: var(--ink); }
.dropdown-item:hover { background: var(--accent-soft); text-decoration: none; opacity: 1; }
.dropdown-item-icon { display: flex; color: var(--muted); flex-shrink: 0; }
.dropdown-item-icon.alert { color: var(--danger); }
.dropdown-item-icon.clock { color: var(--warn); }
.ic-sm { width: 14px; height: 14px; }
.dropdown-empty { display: flex; align-items: center; gap: 7px; padding: 9px; font-size: 12.5px; color: var(--muted); }
.dropdown-empty .ic { width: 14px; height: 14px; color: var(--ok); }

.app-main > .container { padding: 18px 22px; max-width: 1140px; }

/* ---------- Bottom nav (solo móvil): reemplaza al sidebar, siempre visible,
   sin botón de hamburguesa. Mismo destino que el sidebar, icono + etiqueta
   en fila (icono a la izquierda, texto a su derecha). ---------- */
.bottom-nav {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  height: var(--bottom-nav-h);
  padding: 0 4px calc(env(safe-area-inset-bottom, 0px));
  align-items: stretch; justify-content: space-around;
  background: var(--glass-strong);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border-top: 1px solid var(--glass-border);
  box-shadow: 0 -6px 20px rgba(27,36,48,.06);
}
.bottom-nav-link {
  flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center;
  gap: 4px; padding: 0 3px; color: var(--muted); font-size: 10px; font-weight: 600;
}
.bottom-nav-link .ic { width: 17px; height: 17px; flex-shrink: 0; }
.bottom-nav-link span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bottom-nav-link.active { color: var(--accent); }

/* ---------- Footer ---------- */
.site-footer {
  text-align: center; padding: 22px 16px; font-size: 13px; color: var(--muted);
  border-top: 1px solid var(--glass-border);
  background: var(--glass);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
}
.site-footer a { color: var(--accent); font-weight: 600; }

.card {
  background: var(--glass);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  box-shadow: var(--glass-shadow);
  padding: 16px 18px; margin-bottom: 14px;
}
.card h2 { margin-top: 0; font-size: 16px; font-weight: 650; letter-spacing: -.2px; }
.card h3 { font-size: 13.5px; font-weight: 600; margin-top: 0; }
.muted { color: var(--muted); font-size: 12.5px; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px,1fr)); gap: 12px; }
.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 250px; }

/* ---------- Forms ---------- */
label { display: block; font-size: 12px; font-weight: 600; margin: 11px 0 4px; color: var(--ink); }
input[type=text], input[type=email], input[type=password], input[type=url],
input[type=color], select, textarea {
  width: 100%; padding: 8px 11px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  font-size: 13px; font-family: inherit; color: var(--ink);
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { min-height: 78px; resize: vertical; }
input[type=color] { height: 38px; padding: 4px; }

/* ---------- Selector de icono del widget ---------- */
.icon-picker { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.icon-option { cursor: pointer; }
.icon-option input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.icon-swatch {
  display: flex; align-items: center; justify-content: center;
  width: 46px; height: 46px; border-radius: 14px; color: var(--ink);
  border: 1px solid var(--hairline); background: var(--glass-strong);
  transition: border-color .15s, box-shadow .15s;
}
.icon-swatch svg { width: 22px; height: 22px; }
.icon-option input:checked + .icon-swatch {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); color: var(--accent);
}

/* ---------- Vista previa del widget ---------- */
.widget-preview {
  display: flex; align-items: center; justify-content: center; height: 110px;
  border-radius: var(--radius-sm); border: 1px dashed var(--hairline);
  background: repeating-linear-gradient(45deg, rgba(27,36,48,.025), rgba(27,36,48,.025) 10px,
    transparent 10px, transparent 20px);
}
.widget-preview-btn {
  width: 58px; height: 58px; border-radius: 18px; color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 26px rgba(0,0,0,.18);
}
.widget-preview-btn svg { width: 26px; height: 26px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  background: var(--accent); color: #fff; border: 1px solid transparent;
  padding: 8px 14px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600; cursor: pointer; text-decoration: none;
  box-shadow: 0 4px 14px rgba(79,108,255,.28);
  transition: transform .12s ease, box-shadow .15s ease, background .15s;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(79,108,255,.34); opacity: 1; }
.btn:active { transform: translateY(0); }
.btn.secondary { background: var(--accent-soft); color: var(--accent); box-shadow: none; }
.btn.ghost {
  background: var(--glass-strong); color: var(--ink);
  border: 1px solid var(--glass-border); box-shadow: none;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.btn.danger { background: var(--danger); box-shadow: 0 4px 14px rgba(219,84,97,.26); }
.btn.ok { background: var(--ok); box-shadow: 0 4px 14px rgba(47,158,111,.26); }
.btn.sm { padding: 6px 10px; font-size: 12px; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600;
  border: 1px solid var(--hairline);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.badge.trial { background: rgba(201,138,43,.14); color: #9a6816; }
.badge.pending_activation { background: rgba(79,108,255,.14); color: #3346c0; }
.badge.active, .badge.ready, .badge.approved { background: rgba(47,158,111,.16); color: #1f6f4d; }
.badge.disabled, .badge.error, .badge.rejected { background: rgba(219,84,97,.16); color: #a63b46; }
.badge.indexing, .badge.pending { background: rgba(27,36,48,.08); color: #46505e; }

/* ---------- Flash ---------- */
.flash {
  padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 10px; font-size: 13px;
  border: 1px solid var(--glass-border);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
}
.flash.success { background: rgba(47,158,111,.14); color: #1f6f4d; }
.flash.danger  { background: rgba(219,84,97,.14); color: #a63b46; }
.flash.warning { background: rgba(201,138,43,.14); color: #9a6816; }
.flash.info    { background: rgba(79,108,255,.12); color: #3346c0; }

/* ---------- Table ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: fixed; }
th, td { text-align: left; padding: 8px 7px; border-bottom: 1px solid var(--hairline); }
th { color: var(--muted); font-weight: 600; font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; }
.table-scroll { overflow-x: auto; max-width: 100%; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.row-actions form { display: inline-flex; }

/* ---------- Site list (evita que las acciones se desborden en columnas estrechas) ---------- */
.site-list { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.site-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px;
  padding: 12px 14px; border: 1px solid var(--hairline); border-radius: var(--radius-sm);
  background: rgba(255,255,255,.35);
}
.site-row-main { flex: 1 1 180px; min-width: 0; }
.site-url {
  font-size: 13.5px; font-weight: 600; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.site-meta { display: flex; align-items: center; gap: 10px; margin-top: 5px; flex-wrap: wrap; }
.site-meta .st-pages-wrap { font-size: 12.5px; }
.site-actions { display: flex; gap: 8px; flex-wrap: wrap; flex-shrink: 0; }
.site-actions form { display: inline-flex; }
.site-error {
  flex-basis: 100%; font-size: 12.5px; color: var(--danger);
  background: rgba(219,84,97,.08); border-radius: 8px; padding: 8px 10px;
  white-space: pre-wrap; word-break: break-word;
}

/* ---------- Stats ---------- */
.stat { text-align: center; }
.stat .n { font-size: 24px; font-weight: 680; color: var(--accent); letter-spacing: -.4px; }
.stat .l { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

/* ---------- Code box ---------- */
.code-box {
  background: rgba(20, 26, 38, .82);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  color: #e6ebf5; border: 1px solid rgba(255,255,255,.08);
  border-radius: var(--radius-sm); padding: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
  white-space: pre-wrap; word-break: break-all; max-height: 340px; overflow: auto;
}

/* ---------- Charts (SVG server-rendered) ---------- */
.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px,1fr)); gap: 10px; margin-bottom: 14px; }
.stat-tile {
  background: var(--glass-strong); border: 1px solid var(--glass-border); border-radius: var(--radius-sm);
  padding: 10px 13px;
}
.stat-tile .n { font-size: 20px; font-weight: 680; color: var(--ink); letter-spacing: -.3px; }
.stat-tile .l { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 1px; }

.chart-wrap { width: 100%; }
.chart-svg { width: 100%; height: 92px; display: block; overflow: visible; }
.chart-bar { fill: var(--accent); transition: opacity .1s; }
.chart-bar:hover { opacity: .75; }
.chart-axis { display: flex; margin-top: 4px; }
.chart-axis-label { font-size: 10px; color: var(--muted); text-align: center; white-space: nowrap; }

.donut-wrap { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.donut-svg { width: 92px; height: 92px; flex-shrink: 0; transform: rotate(-90deg); transform-origin: 50% 50%; }
.donut-track { fill: transparent; stroke: var(--hairline); stroke-width: 5; }
.donut-legend { display: flex; flex-direction: column; gap: 5px; font-size: 12px; }
.donut-legend-item { display: flex; align-items: center; gap: 7px; color: var(--ink); }
.donut-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

.chart-card h3 { margin-bottom: 8px; }

/* ---------- Preview chat ---------- */
.chat {
  display: flex; flex-direction: column; height: 380px;
  border: 1px solid var(--glass-border); border-radius: var(--radius);
  overflow: hidden;
  background: var(--glass-strong);
  -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
}
.chat-body { flex: 1; overflow-y: auto; padding: 13px; }
.chat-foot { display: flex; gap: 7px; padding: 8px; border-top: 1px solid var(--hairline); }
.chat-foot input { flex: 1; }
.msg { margin: 7px 0; display: flex; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: 82%; padding: 8px 11px; border-radius: 13px; font-size: 13px;
  white-space: pre-wrap; line-height: 1.4;
}
.msg.bot .bubble {
  background: rgba(255,255,255,.7); border: 1px solid var(--glass-border); color: var(--ink);
}
.msg.user .bubble { background: var(--accent); color: #fff; }
.bubble p { margin: 0 0 6px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble ul { margin: 4px 0; padding-left: 18px; }
.bubble li { margin: 2px 0; }
.bubble code {
  background: rgba(27,36,48,.08); border-radius: 4px; padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px;
}
.bubble strong { font-weight: 700; }
.msg.bot .bubble a { color: var(--accent); font-weight: 600; }

.typing-dots { display: inline-flex; gap: 4px; padding: 3px 2px; }
.typing-dots span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--muted);
  animation: cbpBounceDots 1.2s infinite ease-in-out both;
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes cbpBounceDots {
  0%, 80%, 100% { transform: translateY(0); opacity: .4; }
  40% { transform: translateY(-4px); opacity: 1; }
}

/* ---------- Mobile (móvil / PWA): SIEMPRE al final del archivo para que
   estas reglas ganen la cascada sobre cualquier regla base de igual
   especificidad definida más arriba (.card, .grid, .stat, .btn, table...).
   Reemplaza el sidebar por el bottom-nav y reduce fuente/tamaño de cards. ---------- */
@media (max-width: 760px) {
  .sidebar { display: none; }
  .bottom-nav { display: flex; }
  .app-main { padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px)); }
  .app-main > .container { padding: 12px; }

  body { font-size: 13.5px; }
  .card { padding: 12px 13px; margin-bottom: 10px; border-radius: 13px; }
  .card h2 { font-size: 14.5px; }
  .card h3 { font-size: 12.5px; }
  .muted { font-size: 11.5px; }
  .stat-tiles { grid-template-columns: repeat(auto-fit, minmax(96px,1fr)); gap: 7px; }
  .stat-tile { padding: 8px 10px; }
  .stat-tile .n { font-size: 16px; }
  .stat-tile .l { font-size: 9.5px; }
  .grid { grid-template-columns: repeat(auto-fit, minmax(130px,1fr)); gap: 8px; }
  .stat .n { font-size: 19px; }
  .stat .l { font-size: 9.5px; }
  .btn { padding: 7px 12px; font-size: 12.5px; }
  .btn.sm { padding: 5px 9px; font-size: 11.5px; }
  table { font-size: 12px; }
  th, td { padding: 7px 6px; }
  th { font-size: 9.5px; }
  .topbar { padding: 0 10px; }
}
