/* Mostrador — panel */

:root {
  --ground: oklch(97.4% 0.008 85);
  --surface: oklch(99.6% 0.003 85);
  --sunken: oklch(95.2% 0.01 85);
  --ink: oklch(23% 0.025 160);
  --ink-2: oklch(44% 0.02 160);
  --ink-3: oklch(56% 0.015 160);
  --line: oklch(89.5% 0.012 85);
  --line-strong: oklch(82% 0.014 85);

  --rail: oklch(25% 0.04 162);
  --rail-hi: oklch(31% 0.045 162);
  --rail-ink: oklch(93% 0.02 140);
  --rail-ink-2: oklch(76% 0.03 150);

  --accent: oklch(52% 0.13 155);
  --accent-ink: oklch(99% 0.01 155);
  --accent-soft: oklch(94% 0.045 155);
  --accent-line: oklch(84% 0.07 155);

  --agent-soft: oklch(94.5% 0.04 250);
  --agent-ink: oklch(42% 0.12 255);
  --warn: oklch(72% 0.15 70);
  --warn-soft: oklch(95% 0.05 80);
  --warn-ink: oklch(43% 0.1 60);
  --danger: oklch(55% 0.18 25);
  --danger-soft: oklch(95% 0.03 25);

  --glass: oklch(99.6% 0.003 85 / 0.72);
  --shadow-1: 0 1px 2px oklch(25% 0.03 160 / 0.06), 0 2px 8px oklch(25% 0.03 160 / 0.04);
  --shadow-2: 0 4px 12px oklch(25% 0.03 160 / 0.08), 0 16px 40px oklch(25% 0.03 160 / 0.10);

  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --radius: 10px;
  --radius-lg: 14px;
  --rail-w: 15rem;

  color-scheme: light;
  font: 100%/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color: var(--ink);
  background: var(--ground);
  accent-color: var(--accent);
  caret-color: var(--accent);
  scrollbar-color: var(--line-strong) transparent;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: oklch(18.5% 0.015 160);
    --surface: oklch(22% 0.016 160);
    --sunken: oklch(16.5% 0.014 160);
    --ink: oklch(94% 0.012 140);
    --ink-2: oklch(77% 0.014 150);
    --ink-3: oklch(66% 0.014 150);
    --line: oklch(30% 0.016 160);
    --line-strong: oklch(38% 0.018 160);
    --rail: oklch(15% 0.02 162);
    --rail-hi: oklch(23% 0.03 162);
    --accent: oklch(68% 0.14 155);
    --accent-ink: oklch(18% 0.03 160);
    --accent-soft: oklch(30% 0.06 155);
    --accent-line: oklch(42% 0.08 155);
    --agent-soft: oklch(30% 0.05 250);
    --agent-ink: oklch(82% 0.08 250);
    --warn-soft: oklch(30% 0.06 75);
    --warn-ink: oklch(86% 0.1 80);
    --danger-soft: oklch(30% 0.06 25);
    --glass: oklch(22% 0.016 160 / 0.72);
    --shadow-1: 0 1px 2px oklch(0% 0 0 / 0.3);
    --shadow-2: 0 8px 30px oklch(0% 0 0 / 0.45);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body { min-height: 100dvh; background: var(--ground); -webkit-font-smoothing: antialiased; }
::selection { background: var(--accent-soft); color: var(--ink); }
a { color: inherit; text-underline-offset: 0.2em; text-decoration-thickness: 1px; }
img { display: block; max-width: 100%; }
.num, td.num, .stat b { font-variant-numeric: tabular-nums; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.icon { width: 1.15rem; height: 1.15rem; flex: none; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Shell ---------- */

.shell { display: grid; grid-template-columns: var(--rail-w) 1fr; min-height: 100dvh; }

.rail {
  position: sticky; top: 0; height: 100dvh;
  display: flex; flex-direction: column; gap: 1.5rem;
  padding: 1.25rem 0.75rem;
  background: var(--rail); color: var(--rail-ink);
}
.brand { display: flex; align-items: center; gap: 0.6rem; padding: 0 0.5rem; font-weight: 650; letter-spacing: -0.01em; text-decoration: none; }
.brand-mark { width: 1.75rem; height: 1.75rem; border-radius: 8px; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); }
.brand-mark .icon { width: 1rem; height: 1rem; }

.store-switch { padding: 0.65rem 0.75rem; border-radius: var(--radius); background: var(--rail-hi); font-size: 0.8125rem; }
.store-switch small { display: block; color: var(--rail-ink-2); font-size: 0.75rem; }
.store-switch strong { font-weight: 600; letter-spacing: 0.005em; }
.store-switch a { color: var(--rail-ink-2); font-size: 0.75rem; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { padding: 0.75rem 0.75rem 0.25rem; font-size: 0.6875rem; color: var(--rail-ink-2); letter-spacing: 0.04em; text-transform: uppercase; font-weight: 600; }
.nav a {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.55rem 0.75rem; border-radius: 8px;
  color: var(--rail-ink-2); text-decoration: none; font-size: 0.9375rem; font-weight: 500;
  transition: background-color 120ms ease, color 120ms ease;
}
.nav a[aria-current="page"] { background: var(--rail-hi); color: var(--rail-ink); }
@media (hover: hover) and (pointer: fine) { .nav a:hover { color: var(--rail-ink); background: oklch(100% 0 0 / 0.05); } }
.nav .count { margin-left: auto; min-width: 1.4rem; padding: 0 0.4rem; border-radius: 99px; background: var(--warn); color: oklch(25% 0.05 60); font-size: 0.75rem; font-weight: 700; text-align: center; line-height: 1.4rem; }

.rail-foot { margin-top: auto; display: flex; flex-direction: column; gap: 0.5rem; padding: 0 0.5rem; font-size: 0.8125rem; color: var(--rail-ink-2); }
.rail-foot a { display: inline-flex; align-items: center; gap: 0.5rem; color: var(--rail-ink-2); text-decoration: none; }
@media (hover: hover) and (pointer: fine) { .rail-foot a:hover { color: var(--rail-ink); } }

.main { min-width: 0; padding: 2rem clamp(1rem, 3vw, 2.5rem) 3rem; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.75rem; }
.page-head h1 { margin: 0; font-size: 1.75rem; line-height: 1.15; letter-spacing: -0.022em; font-weight: 700; text-wrap: balance; }
.page-head p { margin: 0.35rem 0 0; color: var(--ink-2); font-size: 0.9375rem; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

h2 { font-size: 1.0625rem; letter-spacing: -0.01em; margin: 0 0 0.75rem; font-weight: 650; }

/* ---------- Controles ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  height: 2.375rem; padding: 0 0.95rem; border-radius: 9px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font: inherit; font-size: 0.875rem; font-weight: 550; text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: transform 100ms var(--ease-out), background-color 120ms ease, border-color 120ms ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-danger { color: var(--danger); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn .icon { width: 1rem; height: 1rem; }
@media (hover: hover) and (pointer: fine) {
  .btn:hover { border-color: var(--ink-3); }
  .btn-primary:hover { background: color-mix(in oklch, var(--accent) 88%, var(--ink)); }
  .btn-quiet:hover { background: var(--sunken); color: var(--ink); }
}

.field { display: flex; flex-direction: column; gap: 0.35rem; }
.field > span { font-size: 0.8125rem; font-weight: 600; }
.field small { color: var(--ink-3); font-size: 0.8125rem; line-height: 1.4; }
.input, textarea.input, select.input {
  width: 100%; min-height: 2.5rem; padding: 0.55rem 0.75rem;
  border: 1px solid var(--line-strong); border-radius: 9px; background: var(--surface); color: var(--ink);
  font: inherit; font-size: 0.9375rem;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
textarea.input { resize: vertical; line-height: 1.5; }
.input::placeholder { color: var(--ink-3); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in oklch, var(--accent) 22%, transparent); }

.switch { display: inline-flex; align-items: center; gap: 0.55rem; cursor: pointer; font-size: 0.875rem; font-weight: 550; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { position: relative; width: 2.6rem; height: 1.55rem; border-radius: 99px; background: var(--line-strong); transition: background-color 160ms ease; }
.switch .track::after {
  content: ""; position: absolute; top: 0.15rem; left: 0.15rem; width: 1.25rem; height: 1.25rem; border-radius: 50%;
  background: white; box-shadow: 0 1px 3px oklch(0% 0 0 / 0.25);
  transition: transform 220ms var(--ease-out);
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(1.05rem); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

.tag { display: inline-flex; align-items: center; gap: 0.3rem; height: 1.4rem; padding: 0 0.5rem; border-radius: 99px; font-size: 0.75rem; font-weight: 600; background: var(--sunken); color: var(--ink-2); white-space: nowrap; }
.tag-ok { background: var(--accent-soft); color: color-mix(in oklch, var(--accent) 70%, var(--ink)); }
.tag-warn { background: var(--warn-soft); color: var(--warn-ink); }
.tag-off { background: var(--danger-soft); color: var(--danger); }
.dot { width: 0.5rem; height: 0.5rem; border-radius: 50%; background: currentColor; flex: none; }

/* ---------- Superficies ---------- */

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-1); }
.panel-pad { padding: 1.25rem; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; }
.muted { color: var(--ink-2); }
.small { font-size: 0.8125rem; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); }
.stat { padding: 1.1rem 1.25rem; }
.stat + .stat { border-left: 1px solid var(--line); }
.stat span { display: block; font-size: 0.8125rem; color: var(--ink-2); }
.stat b { display: block; margin-top: 0.15rem; font-size: 1.625rem; font-weight: 680; letter-spacing: -0.02em; line-height: 1.2; }
.stat em { font-style: normal; font-size: 0.8125rem; color: var(--ink-3); }
.stat.is-warn b { color: var(--warn-ink); }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 1.25rem; margin-top: 1.25rem; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 1.25rem; }

.statusline { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; margin-bottom: 1.25rem; padding: 0.75rem 1rem; border-radius: var(--radius); background: var(--sunken); font-size: 0.875rem; color: var(--ink-2); }
.statusline strong { color: var(--ink); font-weight: 600; }
.statusline .sep { width: 1px; height: 1rem; background: var(--line-strong); }

/* Gráfico de barras */
.chart { padding: 1rem 1.25rem 1.1rem; }
.chart svg { width: 100%; height: auto; max-height: 11rem; display: block; overflow: visible; }
.chart .bar { fill: var(--accent-line); }
.chart .bar.today { fill: var(--accent); }
.chart .bar-human { fill: var(--warn); }
.chart .axis { fill: var(--ink-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .gridline { stroke: var(--line); stroke-width: 1; }
.legend { display: flex; gap: 1rem; font-size: 0.8125rem; color: var(--ink-2); padding: 0 1.25rem 1rem; }
.legend i { display: inline-block; width: 0.65rem; height: 0.65rem; border-radius: 3px; margin-right: 0.35rem; vertical-align: -1px; }

/* Listas */
.list { list-style: none; margin: 0; padding: 0; }
.list li + li { border-top: 1px solid var(--line); }
.list a, .list .row { display: flex; align-items: center; gap: 0.85rem; padding: 0.8rem 1.25rem; text-decoration: none; }
@media (hover: hover) and (pointer: fine) { .list a:hover { background: var(--sunken); } }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; font-size: 0.9375rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .sub { font-size: 0.8125rem; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thumb { width: 2.75rem; height: 2.75rem; border-radius: 8px; object-fit: cover; background: var(--sunken); flex: none; }
.avatar { width: 2.4rem; height: 2.4rem; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: 0.8125rem; font-weight: 650; background: var(--sunken); color: var(--ink-2); }

.empty { padding: 2.5rem 1.5rem; text-align: center; color: var(--ink-2); font-size: 0.9375rem; }
.empty strong { display: block; color: var(--ink); margin-bottom: 0.25rem; }

/* Tablas */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.table th { text-align: left; font-weight: 600; font-size: 0.75rem; color: var(--ink-2); padding: 0.7rem 1rem; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--sunken); }
.table td { padding: 0.7rem 1rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; }
.table .prod { display: flex; align-items: center; gap: 0.75rem; min-width: 16rem; }
.table .prod .thumb { width: 2.5rem; height: 2.5rem; }
.strike { text-decoration: line-through; color: var(--ink-3); font-size: 0.8125rem; }

.toolbar { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; padding: 0.85rem 1rem; border-bottom: 1px solid var(--line); }
.search { position: relative; flex: 1; min-width: 12rem; }
.search .icon { position: absolute; left: 0.7rem; top: 50%; transform: translateY(-50%); color: var(--ink-3); width: 1rem; height: 1rem; }
.search .input { padding-left: 2.1rem; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 0.8rem 1rem; font-size: 0.8125rem; color: var(--ink-2); border-top: 1px solid var(--line); }

.row-actions { white-space: nowrap; text-align: right; }
.table td.nowrap { white-space: nowrap; }
.row-actions form { display: inline; }
.row-actions .btn { height: 2rem; padding: 0 0.6rem; font-size: 0.8125rem; }
.row-actions .btn-quiet { padding: 0 0.45rem; }

/* Formularios en secciones */
.form-section { display: grid; grid-template-columns: 16rem 1fr; gap: 2rem; padding: 1.5rem 1.25rem; }
.form-section + .form-section { border-top: 1px solid var(--line); }
.form-section h2 { margin-bottom: 0.3rem; }
.form-section > div:first-child p { margin: 0; color: var(--ink-2); font-size: 0.875rem; line-height: 1.5; }
.fields { display: grid; gap: 1rem; max-width: 40rem; }
.fields-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-foot { display: flex; justify-content: flex-end; gap: 0.5rem; padding: 1rem 1.25rem; border-top: 1px solid var(--line); background: var(--sunken); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.secret-set { font-size: 0.8125rem; color: color-mix(in oklch, var(--accent) 70%, var(--ink)); }

/* Aviso flotante */
.toast {
  position: fixed; top: 1rem; left: 50%; z-index: 50;
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.7rem 1rem; border-radius: 12px;
  background: var(--ink); color: var(--surface); font-size: 0.875rem; font-weight: 550; box-shadow: var(--shadow-2);
  transform: translate(-50%, 0); opacity: 1;
  transition: transform 260ms var(--ease-out), opacity 260ms var(--ease-out);
}
@starting-style { .toast { transform: translate(-50%, -0.75rem); opacity: 0; } }
.toast.is-hiding { transform: translate(-50%, -0.75rem); opacity: 0; }
.toast.is-error { background: var(--danger); color: white; }
.notice { padding: 0.8rem 1rem; border-radius: var(--radius); background: var(--warn-soft); color: var(--warn-ink); font-size: 0.875rem; line-height: 1.45; }
.notice.ok { background: var(--accent-soft); color: color-mix(in oklch, var(--accent) 65%, var(--ink)); }
.notice code { font-size: 0.8125rem; word-break: break-all; }

/* ---------- Conversaciones ---------- */

.inbox { display: grid; grid-template-columns: 21rem 1fr; height: 100dvh; }
.shell.is-inbox .main { padding: 0; }
.inbox-list { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: var(--surface); }
.inbox-list header { padding: 1.25rem 1rem 0.75rem; }
.inbox-list header h1 { margin: 0 0 0.75rem; font-size: 1.375rem; letter-spacing: -0.02em; }
.seg { display: flex; gap: 2px; padding: 3px; border-radius: 10px; background: var(--sunken); margin-top: 0.6rem; }
.seg a { flex: 1; text-align: center; padding: 0.35rem 0.2rem; border-radius: 8px; font-size: 0.78rem; white-space: nowrap; font-weight: 550; color: var(--ink-2); text-decoration: none; transition: background-color 120ms ease; }
.seg a[aria-current="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }
.threads { flex: 1; overflow-y: auto; list-style: none; margin: 0; padding: 0.25rem 0.5rem 1rem; }
.threads a { display: flex; gap: 0.75rem; padding: 0.7rem 0.6rem; border-radius: 10px; text-decoration: none; }
.threads a[aria-current="true"] { background: var(--accent-soft); }
@media (hover: hover) and (pointer: fine) { .threads a:not([aria-current="true"]):hover { background: var(--sunken); } }
.threads .grow { flex: 1; min-width: 0; }
.threads .top { display: flex; justify-content: space-between; gap: 0.5rem; align-items: baseline; }
.threads .name { font-weight: 600; font-size: 0.9375rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.threads time { font-size: 0.75rem; color: var(--ink-3); flex: none; font-variant-numeric: tabular-nums; }
.threads .preview { display: flex; gap: 0.4rem; align-items: center; margin-top: 0.1rem; font-size: 0.8125rem; color: var(--ink-2); }
.threads .preview > span:not(.flag) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.threads .flag { display: inline-flex; flex: none; }
.threads .flag .icon { width: 0.95rem; height: 0.95rem; }
.threads .unread { min-width: 1.25rem; height: 1.25rem; padding: 0 0.35rem; border-radius: 99px; background: var(--accent); color: var(--accent-ink); font-size: 0.6875rem; font-weight: 700; display: grid; place-items: center; }
.threads .is-unread .name { font-weight: 700; }
.threads .flag { color: var(--warn-ink); }
.threads .tags { display: flex; gap: 0.3rem; margin-top: 0.3rem; flex-wrap: wrap; }
.mini { display: inline-flex; align-items: center; height: 1.15rem; padding: 0 0.4rem; border-radius: 5px; background: var(--sunken); color: var(--ink-2); font-size: 0.6875rem; font-weight: 600; }
.mini-user { background: var(--agent-soft); color: var(--agent-ink); }
.threads a[aria-current="true"] .mini { background: var(--surface); }

.thread { position: relative; display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--ground); }
.thread-head {
  position: absolute; inset: 0 0 auto 0; z-index: 2;
  display: flex; flex-direction: column; gap: 0.55rem; padding: 0.75rem 1.25rem 0.65rem;
  background: var(--glass); backdrop-filter: blur(20px) saturate(170%); -webkit-backdrop-filter: blur(20px) saturate(170%);
  border-bottom: 1px solid color-mix(in oklch, var(--line) 70%, transparent);
}
.thread-row { display: flex; align-items: center; gap: 0.85rem; min-width: 0; }
.thread-tools { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; padding-left: 3.25rem; }
.tool { display: inline-flex; align-items: center; gap: 0.35rem; height: 1.9rem; padding: 0 0.3rem 0 0.55rem; border-radius: 8px; background: var(--sunken); color: var(--ink-2); font-size: 0.8125rem; }
.tool .icon { width: 0.95rem; height: 0.95rem; flex: none; }
.tool select, .tool input { border: 0; background: transparent; color: var(--ink); font: inherit; font-weight: 550; padding: 0.2rem 0.25rem; min-width: 0; }
.tool input { width: 15rem; max-width: 52vw; }
.tool select:focus-visible, .tool input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-radius: 5px; }
.tool-static { padding-right: 0.65rem; font-weight: 550; }
.thread-tools .btn { height: 1.9rem; padding: 0 0.7rem; font-size: 0.8125rem; }
.thread-head .who { flex: 1; min-width: 0; }
.thread-head .who b, .thread-head .who span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-head .who b { display: block; font-weight: 650; font-size: 0.9875rem; letter-spacing: -0.005em; }
.thread-head .who span { font-size: 0.8125rem; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.back { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 7.75rem clamp(1rem, 4vw, 3rem) 7.5rem; display: flex; flex-direction: column; gap: 0.35rem; }
.day { align-self: center; margin: 1rem 0 0.5rem; padding: 0.2rem 0.65rem; border-radius: 99px; background: var(--sunken); font-size: 0.75rem; color: var(--ink-2); font-weight: 550; }

.msg { max-width: min(34rem, 82%); display: flex; flex-direction: column; gap: 0.2rem; }
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.msg + .msg.sender-change { margin-top: 0.6rem; }
.bubble { padding: 0.55rem 0.8rem; border-radius: 16px; font-size: 0.9375rem; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: var(--shadow-1); }
.msg.in .bubble { background: var(--surface); border-bottom-left-radius: 6px; }
.msg.bot .bubble { background: var(--accent-soft); border-bottom-right-radius: 6px; }
.msg.agent .bubble { background: var(--agent-soft); border-bottom-right-radius: 6px; }
.meta { display: flex; gap: 0.4rem; align-items: center; font-size: 0.6875rem; color: var(--ink-3); padding: 0 0.3rem; font-variant-numeric: tabular-nums; }
.meta .who-bot { color: color-mix(in oklch, var(--accent) 75%, var(--ink)); font-weight: 600; }
.meta .who-agent { color: var(--agent-ink); font-weight: 600; }
.meta .failed { color: var(--danger); font-weight: 600; }

/* Sello: productos que el bot puso en el mostrador */
.counter { display: flex; flex-direction: column; gap: 0.35rem; margin-top: 0.15rem; width: min(22rem, 100%); }
.counter a {
  display: flex; align-items: center; gap: 0.65rem; padding: 0.45rem 0.6rem 0.45rem 0.45rem;
  border-radius: 12px; background: var(--surface); border: 1px dashed var(--accent-line);
  text-decoration: none; font-size: 0.8125rem;
}
.counter .thumb { width: 2.6rem; height: 3.2rem; border-radius: 7px; }
.counter .grow { flex: 1; min-width: 0; }
.counter .pname { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.3; }
.counter .price { font-variant-numeric: tabular-nums; color: var(--ink-2); margin-top: 0.1rem; }
.counter .price b { color: var(--ink); font-weight: 650; }
@media (hover: hover) and (pointer: fine) { .counter a:hover { border-style: solid; } }

/* Entrada de mensaje nuevo: confirma que llegó, sin distraer */
.msg.is-new { transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out); }
@starting-style { .msg.is-new { opacity: 0; transform: translateY(6px); } }

.composer {
  position: absolute; inset: auto 0 0 0; z-index: 2;
  padding: 0.75rem clamp(1rem, 4vw, 3rem) 1rem;
  background: var(--glass); backdrop-filter: blur(20px) saturate(170%); -webkit-backdrop-filter: blur(20px) saturate(170%);
  border-top: 1px solid color-mix(in oklch, var(--line) 70%, transparent);
}
.composer form { display: flex; gap: 0.5rem; align-items: flex-end; }
.composer textarea { flex: 1; min-height: 2.75rem; max-height: 9rem; border-radius: 22px; padding: 0.65rem 1rem; resize: none; }
.composer .btn { height: 2.75rem; width: 2.75rem; padding: 0; border-radius: 50%; }
.composer .hint { margin: 0 0 0.5rem; font-size: 0.8125rem; color: var(--ink-2); }
.composer .hint.warn { color: var(--warn-ink); }

.thread-empty { display: grid; place-items: center; height: 100%; color: var(--ink-2); text-align: center; padding: 2rem; }
.thread-empty .icon { width: 2rem; height: 2rem; margin: 0 auto 0.75rem; color: var(--ink-3); }

/* Simulador */
.inbox.sim { grid-template-columns: minmax(0, 1fr); }
.avatar-bot { background: var(--accent); color: var(--accent-ink); }
.avatar-bot .icon { width: 1.1rem; height: 1.1rem; }
.sim-start { align-self: center; max-width: 34rem; margin: 2.5rem auto 0; text-align: center; color: var(--ink-2); }
.sim-start p { margin: 0 0 0.85rem; }
.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.sim-start .chips { justify-content: center; }
.chip-btn {
  padding: 0.5rem 0.85rem; border-radius: 99px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font: inherit; font-size: 0.875rem; cursor: pointer; transition: border-color 120ms ease, transform 100ms var(--ease-out);
}
.chip-btn:active { transform: scale(0.97); }
@media (hover: hover) and (pointer: fine) { .chip-btn:hover { border-color: var(--accent); } }
.sim-note { align-self: flex-end; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 0.3rem; max-width: min(34rem, 82%); margin: -0.1rem 0 0.5rem; }
.sim-note span { padding: 0.15rem 0.5rem; border-radius: 6px; background: var(--sunken); color: var(--ink-2); font-size: 0.75rem; }
.sim-note .warn { background: var(--warn-soft); color: var(--warn-ink); font-weight: 600; }
.sim-note .err { background: var(--danger-soft); color: var(--danger); font-weight: 600; }
.sim-note.is-new { transition: opacity 200ms var(--ease-out); }
@starting-style { .sim-note.is-new { opacity: 0; } }
.typing .bubble { display: flex; gap: 0.25rem; padding: 0.8rem 0.9rem; }
.typing i { width: 0.4rem; height: 0.4rem; border-radius: 50%; background: color-mix(in oklch, var(--accent) 70%, var(--ink)); opacity: 0.35; animation: typing 1.1s linear infinite; }
.typing i:nth-child(2) { animation-delay: 0.18s; }
.typing i:nth-child(3) { animation-delay: 0.36s; }
@keyframes typing { 0%, 60%, 100% { opacity: 0.35; } 30% { opacity: 1; } }

/* Campos de ajustes */
[hidden] { display: none !important; }
.seg-field { display: inline-flex; border: 0; margin: 0; padding: 3px; width: fit-content; }
.seg-field label { position: relative; }
.seg-field input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seg-field span { display: block; padding: 0.4rem 1rem; border-radius: 8px; font-size: 0.875rem; font-weight: 550; color: var(--ink-2); transition: background-color 120ms ease; }
.seg-field input:checked + span { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-1); }
.seg-field input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
.chip { position: relative; display: inline-flex; }
.chip input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.chip span { padding: 0.25rem 0.65rem; border-radius: 99px; border: 1px solid var(--line-strong); font-size: 0.8125rem; color: var(--ink-2); transition: background-color 120ms ease, border-color 120ms ease; }
.chip input:checked + span { background: var(--accent-soft); border-color: var(--accent-line); color: var(--ink); font-weight: 600; }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.list .row form.chips { flex-basis: 100%; padding-left: 3.25rem; }

/* Consumo del plan */
.meter { height: 0.4rem; border-radius: 99px; background: var(--sunken); overflow: hidden; margin-top: 0.5rem; }
.meter > i { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.meter.is-warn > i { background: var(--warn); }
.meter.is-over > i { background: var(--danger); }

/* ---------- Login ---------- */

.auth { min-height: 100dvh; display: grid; grid-template-columns: 1fr 1fr; }
.auth-side { background: var(--rail); color: var(--rail-ink); padding: 2.5rem; display: flex; flex-direction: column; justify-content: space-between; }
.auth-side h2 { font-size: clamp(1.75rem, 3vw, 2.5rem); line-height: 1.1; letter-spacing: -0.03em; font-weight: 700; max-width: 18ch; margin: 0; text-wrap: balance; }
.auth-side p { color: var(--rail-ink-2); max-width: 38ch; margin: 1rem 0 0; }
.auth-demo { display: flex; flex-direction: column; gap: 0.4rem; max-width: 22rem; }
.auth-demo .bubble { box-shadow: none; font-size: 0.875rem; }
.auth-demo .in { align-self: flex-start; background: oklch(100% 0 0 / 0.09); color: var(--rail-ink); }
.auth-demo .out { align-self: flex-end; background: var(--accent); color: var(--accent-ink); }
.auth-main { display: grid; place-items: center; padding: 2rem 1rem; }
.auth-card { width: min(23rem, 100%); display: grid; gap: 1rem; }
.auth-card h1 { margin: 0 0 0.25rem; font-size: 1.5rem; letter-spacing: -0.02em; }
.auth-card .btn { height: 2.75rem; }

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .form-section { grid-template-columns: 1fr; gap: 1rem; }
}
@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat:nth-child(3) { border-left: 0; }
  .stat:nth-child(n+3) { border-top: 1px solid var(--line); }
  .inbox { grid-template-columns: minmax(0, 1fr); }
  .inbox.has-thread .inbox-list { display: none; }
  .inbox:not(.has-thread) .thread { display: none; }
  .back { display: inline-flex; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .rail {
    position: fixed; inset: auto 0 0 0; top: auto; height: auto; z-index: 20;
    flex-direction: row; padding: 0.35rem 0.5rem calc(0.35rem + env(safe-area-inset-bottom));
    background: color-mix(in oklch, var(--rail) 92%, transparent); backdrop-filter: blur(20px);
  }
  .rail .brand, .rail .store-switch, .rail .nav-label, .rail-foot { display: none; }
  .nav { flex-direction: row; flex: 1; justify-content: space-around; }
  .nav a { flex-direction: column; gap: 0.15rem; font-size: 0.6875rem; padding: 0.4rem 0.5rem; position: relative; }
  .nav .count { position: absolute; top: 0; right: 0.2rem; min-width: 1.1rem; line-height: 1.1rem; font-size: 0.625rem; }
  .main { padding: 1.25rem 1rem 6rem; }
  .shell.is-inbox .main { padding-bottom: 0; }
  .inbox { height: calc(100dvh - 3.6rem - env(safe-area-inset-bottom)); }
  .fields-2 { grid-template-columns: 1fr; }
  .statusline .sep { display: none; }
  .thread-tools { padding-left: 0; }
  .sim .tool-static, .sim [data-sim-reset] span { display: none; }
  .tool input { width: 12rem; }
  .messages { padding-top: 8.25rem; }
  .statusline { flex-direction: column; align-items: flex-start; gap: 0.4rem; }
  .page-head h1 { font-size: 1.5rem; }
  .auth { grid-template-columns: 1fr; }
  .auth-side { display: none; }
}

/* ---------- Accesibilidad ---------- */

@media (prefers-reduced-motion: reduce) {
  .typing i { animation: none; opacity: 0.7; }
  .msg.is-new, .toast { transition: opacity 150ms ease; }
  @starting-style { .msg.is-new { transform: none; } .toast { transform: translate(-50%, 0); } }
  .toast.is-hiding { transform: translate(-50%, 0); }
  .switch .track::after { transition: none; }
  .btn:active { transform: none; }
}
@media (prefers-reduced-transparency: reduce) {
  .thread-head, .composer { background: var(--surface); backdrop-filter: none; -webkit-backdrop-filter: none; }
}
@media (prefers-contrast: more) {
  :root { --line: var(--line-strong); --ink-2: var(--ink); }
}
