/* ==========================================================================
   PLATTY v2 · Design System compartido
   Paleta heredada de Platty v1: dorado #eea139 + negros #111 / #1B1B1D
   Tema: [data-theme="light|dark"] en <html>; sin atributo = sigue al sistema
   ========================================================================== */

:root {
  --brand: #eea139;
  --brand-600: #d48b2a;
  --brand-ink: #1a1204;
  --brand-soft: rgba(238, 161, 57, .14);
  --ink: #111111;
  --ink-2: #1B1B1D;
  --ink-3: #2a2a2a;

  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-3: #eef0f3;
  --text: #1F2937;
  --muted: #6b7280;
  --line: #e5e7eb;

  --ok: #16a34a;   --ok-soft: rgba(22, 163, 74, .12);
  --warn: #d97706; --warn-soft: rgba(217, 119, 6, .13);
  --err: #dc2626;  --err-soft: rgba(220, 38, 38, .11);
  --info: #2563eb; --info-soft: rgba(37, 99, 235, .11);
  --vio: #7c3aed;  --vio-soft: rgba(124, 58, 237, .12);

  --r-sm: 8px; --r: 12px; --r-lg: 18px; --r-xl: 26px;
  --sh-1: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --sh-2: 0 10px 30px -12px rgba(16, 24, 40, .22);
  --sh-3: 0 24px 60px -20px rgba(16, 24, 40, .35);
  --font: 'Poppins', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0e0f; --surface: #1B1B1D; --surface-2: #222225; --surface-3: #2a2a2e;
    --text: #f3f4f6; --muted: #9ca3af; --line: #2f2f34;
    --brand-soft: rgba(238, 161, 57, .16);
    --sh-1: 0 1px 2px rgba(0, 0, 0, .4); --sh-2: 0 10px 30px -12px rgba(0, 0, 0, .7); --sh-3: 0 24px 60px -20px rgba(0, 0, 0, .8);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e0e0f; --surface: #1B1B1D; --surface-2: #222225; --surface-3: #2a2a2e;
  --text: #f3f4f6; --muted: #9ca3af; --line: #2f2f34;
  --brand-soft: rgba(238, 161, 57, .16);
  --sh-1: 0 1px 2px rgba(0, 0, 0, .4); --sh-2: 0 10px 30px -12px rgba(0, 0, 0, .7); --sh-3: 0 24px 60px -20px rgba(0, 0, 0, .8);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { font-family: var(--font); font-size: 15px; line-height: 1.55; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
img, svg { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
ul { list-style: none; }
h1, h2, h3, h4 { line-height: 1.2; font-weight: 700; letter-spacing: -.01em; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
::selection { background: var(--brand); color: #111; }
.ic { display: inline-block; vertical-align: -.18em; width: 1.15em; height: 1.15em; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.tiny { font-size: .72rem; }
.num { font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; gap: .6rem; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.stack { display: grid; gap: .8rem; }
.grow { flex: 1; min-width: 0; }
.hide { display: none !important; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* ---------- Botones ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; height: 42px; padding: 0 1.1rem; border-radius: var(--r); font-weight: 600; font-size: .9rem; white-space: nowrap; transition: transform .15s var(--ease), background .2s, box-shadow .2s, border-color .2s; border: 1px solid transparent; }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn-primary { background: var(--brand); color: var(--brand-ink); box-shadow: 0 6px 18px -8px var(--brand); }
.btn-primary:hover { background: var(--brand-600); }
.btn-dark { background: var(--ink); color: #fff; }
.btn-ghost { background: var(--surface-3); color: var(--text); }
.btn-ghost:hover { background: var(--line); }
.btn-outline { border-color: var(--line); background: var(--surface); }
.btn-outline:hover { border-color: var(--brand); color: var(--brand-600); }
.btn-ok { background: var(--ok); color: #fff; }
.btn-err { background: var(--err-soft); color: var(--err); }
.btn-sm { height: 34px; padding: 0 .8rem; font-size: .82rem; border-radius: 10px; }
.btn-lg { height: 52px; padding: 0 1.6rem; font-size: 1rem; border-radius: 14px; }
.btn-block { width: 100%; }
.btn-icon { width: 40px; padding: 0; }
.btn-icon.btn-sm { width: 34px; }

/* ---------- Superficies ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 1.1rem; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-bottom: .9rem; }
.card-h h3 { font-size: 1rem; }
.divider { height: 1px; background: var(--line); margin: .9rem 0; }

/* ---------- Badges / chips ---------- */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .18rem .55rem; border-radius: 999px; font-size: .72rem; font-weight: 600; background: var(--surface-3); color: var(--muted); white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.plain::before { display: none; }
.b-ok { background: var(--ok-soft); color: var(--ok); }
.b-warn { background: var(--warn-soft); color: var(--warn); }
.b-err { background: var(--err-soft); color: var(--err); }
.b-info { background: var(--info-soft); color: var(--info); }
.b-vio { background: var(--vio-soft); color: var(--vio); }
.b-brand { background: var(--brand-soft); color: var(--brand-600); }
.chip { display: inline-flex; align-items: center; gap: .35rem; height: 34px; padding: 0 .9rem; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: .84rem; font-weight: 500; white-space: nowrap; transition: .2s; }
.chip.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.lock { display: inline-flex; align-items: center; gap: .25rem; font-size: .66rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: .12rem .45rem; border-radius: 6px; background: var(--brand-soft); color: var(--brand-600); }

/* ---------- Formularios ---------- */
.field { display: grid; gap: .35rem; }
.field > span, .label { font-size: .8rem; font-weight: 600; color: var(--muted); }
.input, .select, .textarea { width: 100%; height: 44px; padding: 0 .9rem; border-radius: var(--r); border: 1px solid var(--line); background: var(--surface); transition: border-color .2s, box-shadow .2s; }
.textarea { height: auto; min-height: 90px; padding: .7rem .9rem; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.input-group { position: relative; }
.input-group .input { padding-left: 2.4rem; }
.input-group .ic { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .8rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .8rem; }
@media (max-width: 640px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 99px; background: var(--surface-3); border: 1px solid var(--line); transition: .2s; }
.switch i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: var(--sh-1); transition: transform .25s var(--ease); }
.switch input:checked + i { background: var(--brand); border-color: var(--brand); }
.switch input:checked + i::after { transform: translateX(18px); }

.seg { display: inline-flex; padding: 3px; gap: 2px; border-radius: 12px; background: var(--surface-3); max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.seg button { flex: none; }
.seg button { height: 32px; padding: 0 .85rem; border-radius: 9px; font-size: .82rem; font-weight: 600; color: var(--muted); transition: .2s; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--sh-1); }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.table th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: .75rem 1rem; background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: .8rem 1rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .9rem; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 1rem 1.1rem; }
.kpi .k-l { font-size: .78rem; color: var(--muted); font-weight: 500; display: flex; align-items: center; gap: .4rem; }
.kpi .k-v { font-size: 1.6rem; font-weight: 700; margin-top: .25rem; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi .k-d { font-size: .76rem; font-weight: 600; margin-top: .1rem; }
.up { color: var(--ok); } .down { color: var(--err); }

/* ---------- Overlays: modal / sheet / toast ---------- */
.overlay { position: fixed; inset: 0; z-index: 900; background: rgba(10, 10, 12, .55); backdrop-filter: blur(3px); display: flex; align-items: center; justify-content: center; padding: 1rem; opacity: 0; pointer-events: none; transition: opacity .25s; }
.overlay.open { opacity: 1; pointer-events: auto; }
.modal { width: min(560px, 100%); max-height: calc(100dvh - 2rem); overflow: auto; background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--sh-3); padding: 1.4rem; transform: translateY(14px) scale(.98); transition: transform .3s var(--ease); }
.overlay.open .modal { transform: none; }
.modal-h { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.modal-h h3 { font-size: 1.15rem; }
.overlay.sheet-wrap { align-items: flex-end; padding: 0; }
.sheet { width: min(560px, 100%); max-height: 92dvh; overflow: auto; background: var(--surface); border-radius: 24px 24px 0 0; padding: .6rem 1.2rem 1.4rem; transform: translateY(100%); transition: transform .35s var(--ease); overscroll-behavior: contain; }
.overlay.open .sheet { transform: none; }
.sheet .grab { width: 42px; height: 5px; border-radius: 9px; background: var(--line); margin: .2rem auto .9rem; }
@media (min-width: 700px) { .overlay.sheet-wrap { align-items: center; padding: 1rem; } .sheet { border-radius: var(--r-xl); } .sheet .grab { display: none; } }

.toasts { position: fixed; z-index: 1000; left: 50%; bottom: 1.2rem; transform: translateX(-50%); display: grid; gap: .5rem; width: min(420px, calc(100% - 2rem)); pointer-events: none; }
.toast { display: flex; align-items: center; gap: .6rem; padding: .8rem 1rem; border-radius: 14px; background: var(--ink-2); color: #fff; font-size: .88rem; box-shadow: var(--sh-3); animation: toastIn .35s var(--ease); pointer-events: auto; }
.toast .ic { color: var(--brand); }
.toast.ok .ic { color: #4ade80; } .toast.err .ic { color: #f87171; }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px) scale(.96); } }

/* ---------- App shell (panel / admin) ---------- */
.shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100dvh; }
.side { position: sticky; top: 0; height: 100dvh; overflow-y: auto; background: var(--ink-2); color: #d1d5db; padding: 1.1rem .8rem; display: flex; flex-direction: column; gap: .3rem; }
.side .brand { display: flex; align-items: center; gap: .6rem; padding: .3rem .6rem 1.1rem; }
.side .brand img { height: 26px; width: auto; }
.side .sec { font-size: .66rem; text-transform: uppercase; letter-spacing: .1em; color: #6b7280; padding: .9rem .7rem .35rem; font-weight: 600; }
.side a { display: flex; align-items: center; gap: .7rem; padding: .62rem .75rem; border-radius: 10px; font-size: .88rem; font-weight: 500; color: #b8bcc4; transition: .15s; }
.side a:hover { background: rgba(255, 255, 255, .05); color: #fff; }
.side a.on { background: rgba(238, 161, 57, .14); color: var(--brand); }
.side a .lock, .side a .cnt { margin-left: auto; }
.side .cnt { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 99px; background: var(--brand); color: #111; font-size: .7rem; font-weight: 700; display: grid; place-items: center; }
.side .foot { margin-top: auto; padding-top: 1rem; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: .8rem; padding: .8rem 1.4rem; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 1.15rem; }
.content { padding: 1.4rem; display: grid; gap: 1.2rem; align-content: start; }
.content > *, .stack > *, .two > * { min-width: 0; }
.menu-btn { display: none; }
@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 800; left: 0; width: 270px; transform: translateX(-100%); transition: transform .3s var(--ease); }
  body.nav-open .side { transform: none; box-shadow: var(--sh-3); }
  .menu-btn { display: inline-flex; }
  .content { padding: 1rem; }
  .topbar { padding: .7rem 1rem; }
}
@media (max-width: 640px) {
  .net, .top-rate .muted, .top-rate.opt { display: none !important; }
  .topbar h1 { font-size: 1rem; }
}

/* ---------- Varios ---------- */
.empty { text-align: center; padding: 2.4rem 1rem; color: var(--muted); }
.empty .ic { display: block; width: 38px; height: 38px; margin: 0 auto .6rem; opacity: .5; }
.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: .8rem; background: var(--brand-soft); color: var(--brand-600); flex: none; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.dot-live { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 rgba(22, 163, 74, .6); animation: live 1.8s infinite; }
@keyframes live { 70% { box-shadow: 0 0 0 8px rgba(22, 163, 74, 0); } 100% { box-shadow: 0 0 0 0 rgba(22, 163, 74, 0); } }
.banner { display: flex; align-items: center; gap: .8rem; padding: .8rem 1rem; border-radius: var(--r); font-size: .86rem; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.err { background: var(--err-soft); color: var(--err); }
.banner.info { background: var(--info-soft); color: var(--info); }
.banner.ok { background: var(--ok-soft); color: var(--ok); }
.banner.brand { background: var(--brand-soft); color: var(--brand-600); }
.banner b { color: inherit; }
.skeleton { background: linear-gradient(90deg, var(--surface-3), var(--surface-2), var(--surface-3)); background-size: 200% 100%; animation: sk 1.2s infinite; border-radius: 8px; }
@keyframes sk { to { background-position: -200% 0; } }
.bar { height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: inherit; background: var(--brand); }
.spark { width: 100%; height: 64px; }
.fade-in { animation: fadeIn .35s var(--ease); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } }

/* ---------- Chat IA ---------- */
.ai-chat { display: flex; flex-direction: column; height: 100%; min-height: 420px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.ai-log { flex: 1; overflow-y: auto; padding: 1rem; display: flex; flex-direction: column; gap: .8rem; scroll-behavior: smooth; }
.ai-msg { display: flex; gap: .55rem; align-items: flex-end; max-width: 92%; animation: fadeIn .3s var(--ease); }
.ai-msg.me { align-self: flex-end; }
.ai-av { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; flex: none; background: linear-gradient(135deg, var(--brand), #f6c56b); color: #111; }
.ai-bub { padding: .7rem .9rem; border-radius: 16px 16px 16px 4px; background: var(--surface-2); border: 1px solid var(--line); font-size: .88rem; line-height: 1.5; }
.ai-msg.me .ai-bub { background: var(--ink-2); color: #fff; border-color: var(--ink-2); border-radius: 16px 16px 4px 16px; }
:root[data-theme="dark"] .ai-msg.me .ai-bub { background: var(--brand); color: #111; border-color: var(--brand); }
.ai-list { margin: .4rem 0 .2rem 1rem; list-style: disc; display: grid; gap: .15rem; }
.ai-alert { display: inline-flex; align-items: center; gap: .3rem; font-weight: 700; color: var(--err); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.ai-chips { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .6rem; }
.ai-chips .chip { height: auto; min-height: 30px; padding: .3rem .7rem; font-size: .76rem; white-space: normal; text-align: left; }
.ai-act { display: flex; align-items: center; gap: .5rem; margin-top: .7rem; }
.ai-form { display: flex; gap: .4rem; padding: .6rem; border-top: 1px solid var(--line); background: var(--surface); }
.ai-in { flex: 1; min-width: 0; height: 44px; border-radius: 99px; border: 1px solid var(--line); background: var(--surface-2); padding: 0 1rem; }
.ai-in:focus { outline: none; border-color: var(--brand); }
.ai-send, .ai-mic { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.ai-send { background: var(--brand); color: #111; }
.ai-mic { background: var(--surface-3); }
.ai-mic.rec { background: var(--err); color: #fff; animation: live 1.2s infinite; }
.ai-dots { display: inline-flex; gap: 4px; }
.ai-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: dots 1s infinite; }
.ai-dots i:nth-child(2) { animation-delay: .15s; } .ai-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dots { 50% { opacity: .2; transform: translateY(-3px); } }[hidden] { display: none !important; }

/* ---------- Código de verificación (6 casillas) ---------- */
/* Los inputs tienen un ancho mínimo propio: sin min-width:0 no se encogen y desbordan la cuadrícula */
.otp { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: .45rem; width: 100%; max-width: 360px; }
.otp input { min-width: 0; width: 100%; padding: 0; }
.otp input:focus { outline: none; border-color: var(--brand) !important; box-shadow: 0 0 0 3px var(--brand-soft); }
/* Botones secundarios dentro de tarjetas oscuras de acceso */
.auth .btn-ghost { background: transparent; color: #9ca3af; }
.auth .btn-ghost:hover { background: #232326; color: #fff; }
/* ---------- Menú lateral en móvil: fondo para cerrar y botón X ---------- */
.nav-backdrop { display: none; }
.nav-x { display: none; }
@media (max-width: 960px) {
  .nav-backdrop { display: block; position: fixed; inset: 0; z-index: 790; background: rgba(10, 10, 12, .5); backdrop-filter: blur(2px); opacity: 0; pointer-events: none; transition: opacity .25s; }
  body.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }
  .nav-x { display: grid; place-items: center; width: 34px; height: 34px; margin-left: auto; border-radius: 10px; color: #cbd5e1; background: rgba(255, 255, 255, .06); }
}