:root {
  color-scheme: light;
  --page: #f6f5f1;
  --surface: #fcfcfb;
  --surface-2: #f1f0eb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-wash: #e6f0fc;
  --on-accent: #ffffff;
  --bubble-in: #ecebe6;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --critical: #d03b3b;
  --critical-text: #b32f2f;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.05), 0 1px 1px rgba(11, 11, 11, 0.03);
  --shadow-lg: 0 18px 50px rgba(11, 11, 11, 0.18);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232321;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --accent-wash: #16263b;
    --bubble-in: #2a2a28;
    --good-text: #0ca30c;
    --critical-text: #e66767;
    --shadow: none;
    --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.55);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232321;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5;
  --accent-ink: #86b6ef;
  --accent-wash: #16263b;
  --bubble-in: #2a2a28;
  --good-text: #0ca30c;
  --critical-text: #e66767;
  --shadow: none;
  --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 26px; font-weight: 680; letter-spacing: -0.02em; }
h2 { font-size: 15px; font-weight: 640; }
a { color: var(--accent-ink); }
button, input, select, textarea { font: inherit; color: inherit; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.hint { color: var(--muted); font-size: 12.5px; }
.muted-text { color: var(--ink-2); }
.lead { color: var(--ink-2); margin-top: 4px; max-width: 640px; }
.center { text-align: center; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Iconos ---------- */
.ico { width: 18px; height: 18px; flex: none; display: inline-block; }
.ico svg { width: 100%; height: 100%; display: block; }

/* ---------- Estructura ---------- */
.app { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }

.side {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 22px 14px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); padding: 0 6px; }
.brand img { border-radius: 9px; }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.brand-sub { color: var(--muted); font-size: 12px; }
.brand.big .brand-name { font-size: 20px; }

.nav { display: grid; gap: 2px; }
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 10px;
  color: var(--ink-2);
  text-decoration: none;
  font-weight: 560;
}
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent-wash); color: var(--accent-ink); }
.nav-badge {
  margin-left: auto;
  background: var(--surface-2);
  color: var(--ink-2);
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 650;
  border-radius: 999px;
  padding: 0 7px;
  line-height: 18px;
}
.side-foot { margin-top: auto; display: grid; gap: 10px; }
.account-box { display: grid; gap: 5px; padding: 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.account-box select { padding: 7px 9px; font-weight: 600; background: var(--surface); }
.account-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-name small { display: block; font-weight: 500; color: var(--muted); font-size: 12px; }
.who { color: var(--muted); font-size: 12px; }
.who b { color: var(--ink-2); font-weight: 620; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; }

.main { padding: 28px 32px 48px; max-width: 1200px; width: 100%; display: grid; gap: 18px; align-content: start; }
.view { display: grid; gap: 18px; }
.view-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }

@media (max-width: 880px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side {
    min-width: 0;
    position: sticky;
    z-index: 5;
    height: auto;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px 14px;
    padding: 12px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .brand-sub { display: none; }
  .nav { grid-auto-flow: column; justify-content: start; overflow-x: auto; scrollbar-width: none; order: 3; width: 100%; min-width: 0; gap: 4px; padding-bottom: 2px; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { padding: 7px 10px; white-space: nowrap; font-size: 13px; }
  .side-foot { margin: 0 0 0 auto; display: flex; align-items: center; gap: 10px; }
  .side-foot .who { display: none; }
  .account-box { order: 2; width: 100%; grid-template-columns: auto 1fr; align-items: center; padding: 6px 10px; }
  .main { padding: 20px 16px 40px; }
  h1 { font-size: 22px; }
}

/* ---------- Píldoras, estados ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--ink-2);
  white-space: nowrap;
}
.st { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.st .ico { width: 15px; height: 15px; }
.st.good { color: var(--good-text); }
.st.critical { color: var(--critical-text); }
.st.muted { color: var(--muted); }
.st.info { color: var(--accent-ink); }
.st.good .ico { color: var(--good); }
.st.critical .ico { color: var(--critical); }

/* ---------- Controles ---------- */
.segmented {
  display: inline-flex;
  padding: 3px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.segmented button {
  border: 0;
  background: transparent;
  padding: 6px 14px;
  border-radius: 7px;
  cursor: pointer;
  color: var(--ink-2);
  font-weight: 560;
}
.segmented button[aria-selected="true"],
.segmented button[aria-checked="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 0 0 1px var(--border), var(--shadow);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 10px;
  padding: 9px 15px;
  font-weight: 620;
  cursor: pointer;
  border: 1px solid transparent;
  white-space: nowrap;
  text-decoration: none;
}
.btn .ico { width: 16px; height: 16px; }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.07); }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn.ghost { background: var(--surface); border-color: var(--border); color: var(--ink-2); }
.btn.ghost:hover { color: var(--ink); border-color: var(--axis); }
.btn.danger-ghost { background: transparent; color: var(--critical-text); border-color: transparent; }
.btn.danger-ghost:hover { border-color: var(--critical); }
.btn.small { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn.block { width: 100%; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent-ink); cursor: pointer; font-size: 12.5px; font-weight: 600; text-decoration: none; }
.link-btn:hover { text-decoration: underline; }
.icon-btn { background: transparent; border: 1px solid transparent; border-radius: 9px; padding: 6px; cursor: pointer; color: var(--ink-2); display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn:disabled { opacity: 0.35; cursor: default; background: transparent; }

.field { display: grid; gap: 6px; }
.label { font-size: 12.5px; color: var(--ink-2); font-weight: 600; }
.label-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
input, select, textarea {
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  width: 100%;
  min-width: 0;
  color: var(--ink);
}
textarea { resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.input-prefix {
  display: flex;
  align-items: center;
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding-left: 11px;
  color: var(--muted);
}
.input-prefix:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.input-prefix input { border: 0; background: transparent; padding-left: 3px; outline: none; }
.select-wrap select { padding: 6px 30px 6px 10px; font-size: 13px; width: auto; max-width: 220px; }

.switch {
  width: 40px;
  height: 24px;
  border-radius: 999px;
  border: 0;
  background: var(--axis);
  position: relative;
  cursor: pointer;
  flex: none;
  padding: 0;
  transition: background 0.15s;
}
.switch span {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s;
}
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"] span { transform: translateX(16px); }
.switch-row { display: flex; gap: 10px; align-items: center; color: var(--ink-2); font-size: 13px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 12.5px;
  cursor: pointer;
  color: var(--ink-2);
}
.chip:hover { color: var(--ink); border-color: var(--axis); }
.chip[aria-pressed="true"] { background: var(--accent-wash); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.kw {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-wash);
  color: var(--accent-ink);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12.5px;
  font-weight: 600;
}

/* ---------- Banner y tarjetas ---------- */
.banner {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--accent-wash);
  border: 1px solid var(--border);
}
.banner > .ico { color: var(--accent); margin-top: 1px; }
.banner strong { font-weight: 650; }
.banner a { font-weight: 600; }
code, .code {
  font: 12.5px ui-monospace, SFMono-Regular, Consolas, monospace;
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 6px;
  overflow-wrap: anywhere;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  min-width: 0;
  display: grid;
  gap: 12px;
  align-content: start;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.grid-2 { display: grid; gap: 18px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-2.top { align-items: start; }
@media (max-width: 980px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- KPI ---------- */
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(5, minmax(0, 1fr)); }
@media (max-width: 1100px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.kpi .k-label { color: var(--ink-2); font-size: 12.5px; }
.kpi .k-value { font-size: 30px; font-weight: 680; letter-spacing: -0.02em; line-height: 1.15; margin-top: 4px; }
.kpi .k-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.kpi.alert .k-value { color: var(--critical-text); }

/* ---------- Mensajes por período ---------- */
#period-card { margin-bottom: 16px; }
#period-card .card-head { flex-wrap: wrap; gap: 8px; }
.period-kpis { display: grid; gap: 10px; grid-template-columns: repeat(5, minmax(0, 1fr)); }
@media (max-width: 1100px) { .period-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 560px) { .period-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.period-kpis .kpi { background: var(--page); }
.period-bars { display: flex; align-items: flex-end; gap: 4px; height: 84px; margin-top: 14px; }
.period-bars .pb { flex: 1 1 0; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 3px; }
.period-bars .pb i { display: block; width: 100%; max-width: 34px; min-height: 2px; background: var(--accent); opacity: .55; border-radius: 4px 4px 2px 2px; }
.period-bars .pb.today i { opacity: 1; }
.period-bars .pb small { font-size: 10.5px; color: var(--muted); line-height: 1; min-height: 11px; }
.section-title { font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 4px 0 8px; }

/* ---------- Embudo ---------- */
.funnel { display: grid; gap: 4px; }
.f-row {
  display: grid;
  grid-template-columns: minmax(120px, 200px) 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 6px 4px;
  border-radius: 8px;
}
.f-row:hover { background: var(--surface-2); }
.f-label { color: var(--ink-2); font-size: 13px; }
.f-track { height: 20px; }
.f-bar { height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; }
.f-value { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; min-width: 86px; }
.f-value b { font-weight: 650; }
.f-value span { color: var(--muted); font-size: 12.5px; margin-left: 6px; }
@media (max-width: 560px) {
  .f-row { grid-template-columns: 1fr auto; }
  .f-track { grid-column: 1 / -1; grid-row: 2; }
}

/* ---------- Columnas por hora ---------- */
.hourly svg { width: 100%; height: 190px; display: block; overflow: visible; }
.hourly .gridline { stroke: var(--grid); stroke-width: 1; }
.hourly .baseline { stroke: var(--axis); stroke-width: 1; }
.hourly .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.hourly .col { fill: var(--accent); }
.hourly .hit { fill: transparent; }
.hourly .slot:hover .col { fill: var(--accent-ink); }
.hourly .empty { fill: var(--muted); font-size: 13px; }
.table-view { color: var(--ink-2); font-size: 12.5px; }
.table-view summary { cursor: pointer; color: var(--muted); }
.table-view table { border-collapse: collapse; margin-top: 8px; font-variant-numeric: tabular-nums; }
.table-view td, .table-view th { padding: 3px 12px 3px 0; text-align: left; border-bottom: 1px solid var(--grid); }

/* ---------- Listas cortas ---------- */
.mini-feed { list-style: none; margin: 0; padding: 0; display: grid; }
.mini-feed li {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--grid);
}
.mini-feed li:last-child { border-bottom: 0; }
.mini-feed .dot {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  color: var(--ink-2);
}
.mini-feed .dot.out { background: var(--accent-wash); color: var(--accent-ink); }
.mini-feed .dot .ico { width: 15px; height: 15px; }
.mini-feed .what { min-width: 0; }
.mini-feed .what b { font-weight: 620; }
.mini-feed .what div { color: var(--ink-2); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-feed .when { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.sched { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.sched li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.sched .who { font-weight: 620; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sched .when { color: var(--muted); font-size: 12.5px; }
.sched .cd { font-variant-numeric: tabular-nums; font-weight: 680; font-size: 16px; text-align: right; }
.sched .meter { grid-column: 1 / -1; height: 4px; border-radius: 4px; background: var(--grid); overflow: hidden; }
.sched .meter i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.empty-note { color: var(--muted); font-size: 13px; padding: 4px 0; }

/* ---------- Automatizaciones ---------- */
.auto-list { display: grid; gap: 14px; }
.auto-card { gap: 14px; }
.auto-card.off { opacity: 0.62; }
.auto-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.prio {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--ink-2);
  display: grid;
  place-items: center;
  font-size: 12.5px;
  font-weight: 700;
  flex: none;
}
.auto-title { flex: 1; min-width: 160px; }
.auto-title h3 { font-size: 16px; font-weight: 660; }
.auto-title p { color: var(--muted); font-size: 12.5px; }
.auto-actions { display: flex; align-items: center; gap: 4px; }
.auto-kw { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.auto-kw .label { margin-right: 4px; }

.flow-strip { display: flex; align-items: stretch; overflow-x: auto; padding-bottom: 2px; }
.fs-step {
  flex: 1 1 0;
  min-width: 130px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 10px;
  padding: 9px 11px;
  display: grid;
  gap: 1px;
}
.fs-step.trigger { background: var(--accent-wash); }
.fs-step.trigger .fs-title { color: var(--accent-ink); }
.fs-title { font-weight: 620; font-size: 13px; }
.fs-desc { color: var(--ink-2); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fs-count { font-size: 17px; font-weight: 680; margin-top: 3px; }
.fs-count small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 4px; }
.fs-arrow { flex: none; width: 34px; display: grid; place-items: center; color: var(--axis); position: relative; }
.fs-arrow .ico { width: 20px; height: 12px; }
.fs-arrow .delay { position: absolute; top: 50%; transform: translateY(-165%); white-space: nowrap; color: var(--muted); font-size: 11px; }

.menu-wrap { position: relative; }
.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  width: 300px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  padding: 6px;
  display: grid;
}
.menu button {
  text-align: left;
  background: none;
  border: 0;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  display: grid;
  gap: 1px;
}
.menu button:hover, .menu button:focus-visible { background: var(--surface-2); }
.menu b { font-weight: 640; }
.menu span { color: var(--ink-2); font-size: 12.5px; }

/* ---------- Editor ---------- */
.editor-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(11, 11, 11, 0.42);
  display: grid;
  place-items: center;
  padding: 24px;
}
.editor {
  width: min(1100px, 100%);
  max-height: calc(100vh - 48px);
  background: var(--page);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}
.editor-head, .editor-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  background: var(--surface);
}
.editor-head { justify-content: space-between; border-bottom: 1px solid var(--border); }
.editor-head h2 { font-size: 17px; }
.editor-foot { border-top: 1px solid var(--border); }
.editor-foot .form-error { flex: 1; text-align: right; }
.editor-body { display: grid; grid-template-columns: minmax(0, 1fr) 340px; overflow: hidden; min-height: 0; }
.editor-form { overflow-y: auto; padding: 20px; display: grid; gap: 14px; align-content: start; }
.editor-preview { overflow-y: auto; padding: 20px; border-left: 1px solid var(--border); background: var(--surface-2); display: grid; gap: 10px; align-content: start; }
@media (max-width: 860px) {
  .editor-backdrop { padding: 0; }
  .editor { max-height: 100vh; height: 100vh; border-radius: 0; }
  .editor-body { grid-template-columns: 1fr; overflow-y: auto; }
  .editor-form, .editor-preview { overflow: visible; }
  .editor-preview { border-left: 0; border-top: 1px solid var(--border); }
  .editor-foot { flex-wrap: wrap; }
  .editor-foot .form-error { order: -1; flex-basis: 100%; text-align: left; }
}
.step-box {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 12px;
  padding: 14px;
  margin: 0;
  display: grid;
  gap: 12px;
  min-width: 0;
}
.step-box legend { font-weight: 650; padding: 0 6px; display: flex; align-items: center; gap: 8px; }
.step-n {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  display: inline-grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
}
.step-box.disabled { opacity: 0.55; }
.sub-fields { display: grid; gap: 12px; padding-left: 50px; }
.sub-fields.off { display: none; }
@media (max-width: 560px) { .sub-fields { padding-left: 0; } }
.tag-input {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  cursor: text;
}
.tag-input:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.tag-input input { border: 0; background: transparent; flex: 1; min-width: 140px; padding: 4px; outline: none; }
.tag-input .kw button { background: none; border: 0; padding: 0 0 0 2px; cursor: pointer; color: inherit; font-size: 15px; line-height: 1; }
.delay-row { display: flex; gap: 8px; max-width: 280px; }
.delay-row input { width: 100px; }
.form-error { color: var(--critical-text); font-size: 13px; min-height: 1.3em; }
.sub-fields.flush { padding-left: 0; }
.warn-note { font-size: 12.5px; color: var(--ink); background: #fff4d6; border: 1px solid rgba(250, 178, 25, 0.5); border-radius: 8px; padding: 8px 10px; margin: 0; }
@media (prefers-color-scheme: dark) { :root:where(:not([data-theme="light"])) .warn-note { background: #3a2e10; } }
:root[data-theme="dark"] .warn-note { background: #3a2e10; }
.posts-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.posts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; max-height: 330px; overflow-y: auto; padding: 2px; }
.post-tile {
  position: relative;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  border: 2px solid transparent;
  background: var(--surface-2);
  cursor: pointer;
  padding: 0;
  display: block;
}
.post-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.post-tile .pt-cap { position: absolute; inset: auto 0 0 0; background: linear-gradient(transparent, rgba(0,0,0,.72)); color: #fff; font-size: 10.5px; line-height: 1.25; padding: 14px 6px 5px; text-align: left; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.post-tile .pt-type { position: absolute; top: 5px; left: 5px; background: rgba(0,0,0,.6); color: #fff; font-size: 10px; border-radius: 6px; padding: 1px 5px; }
.post-tile .pt-check { position: absolute; top: 5px; right: 5px; width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff; background: rgba(0,0,0,.25); display: grid; place-items: center; color: #fff; font-size: 13px; font-weight: 700; }
.post-tile[aria-pressed="true"] { border-color: var(--accent); }
.post-tile[aria-pressed="true"] .pt-check { background: var(--accent); border-color: var(--accent); }
.post-tile .pt-noimg { width: 100%; height: 100%; display: grid; place-items: center; color: var(--muted); font-size: 11px; padding: 6px; text-align: center; }
.post-chips { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.post-chips img { width: 30px; height: 30px; border-radius: 6px; object-fit: cover; border: 1px solid var(--border); }

/* ---------- Teléfono ---------- */
.try { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 22px; align-items: start; }
.try-side { display: grid; gap: 14px; }
@media (max-width: 980px) { .try { grid-template-columns: 1fr; } .try .phone { justify-self: center; } }
.inline-form { display: flex; gap: 8px; }
.tip-card { grid-template-columns: auto 1fr; align-items: start; color: var(--ink-2); font-size: 13px; }
.tip-card > .ico { color: var(--accent); }
.sim-status { min-height: 1.4em; font-size: 12.5px; color: var(--ink-2); }

.phone {
  width: 100%;
  max-width: 380px;
  height: 680px;
  border-radius: 38px;
  background: var(--surface);
  border: 10px solid #1b1b1a;
  box-shadow: var(--shadow-lg);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  overflow: hidden;
  position: relative;
}
.phone.small { height: 600px; max-width: 300px; margin: 0 auto; border-width: 8px; border-radius: 32px; }
.phone-notch { width: 110px; height: 22px; background: #1b1b1a; border-radius: 0 0 14px 14px; margin: 0 auto; }
.phone-top { display: flex; align-items: center; gap: 10px; padding: 8px 16px 10px; border-bottom: 1px solid var(--border); }
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  display: grid;
  place-items: center;
  font-weight: 700;
  flex: none;
}
.phone-user { font-weight: 650; font-size: 14px; }
.phone-sub { color: var(--muted); font-size: 11.5px; }
.phone-body { overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 8px; background: var(--page); }
.phone.small .phone-body { font-size: 13px; }

.bubble {
  max-width: 82%;
  padding: 8px 12px;
  border-radius: 18px;
  font-size: 13.5px;
  line-height: 1.4;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.bubble.in { align-self: flex-start; background: var(--bubble-in); border-bottom-left-radius: 6px; }
.bubble.out { align-self: flex-end; background: var(--accent); color: var(--on-accent); border-bottom-right-radius: 6px; }
.bubble.out a { color: inherit; text-decoration: underline; }
.bubble.fail { background: transparent; color: var(--critical-text); border: 1px dashed var(--critical); }

/* Bandeja */
.inbox-list { display: grid; gap: 12px; }
.inbox-card { display: grid; gap: 10px; }
.inbox-card.done { opacity: .72; }
.inbox-card.late { border-color: var(--border); }
.inbox-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 14px; }
.inbox-who { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; min-width: 0; }
.inbox-who b { font-size: 15px; overflow-wrap: anywhere; }
.inbox-from { margin: -4px 0 0; }
.inbox-msgs { display: flex; flex-direction: column; gap: 6px; background: var(--page); border-radius: 12px; padding: 10px; }
.inbox-msgs .bubble { display: grid; gap: 2px; }
.inbox-msgs .bubble small { font-size: 11px; opacity: .7; }
.net-tag { font-size: 11px; font-weight: 600; border-radius: 999px; padding: 1px 8px; background: var(--bubble-in); color: var(--ink-2); }
.net-tag.facebook { background: #e7f0fe; color: #1a56c4; }
.net-tag.instagram { background: #fde8f1; color: #b4236b; }
@media (prefers-color-scheme: dark) {
  .net-tag.facebook { background: #1c2b45; color: #9cc0ff; }
  .net-tag.instagram { background: #3d1d2c; color: #ff9cc8; }
}
.post-card {
  align-self: stretch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  display: grid;
  gap: 8px;
}
.post-card .pc-head { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11.5px; }
.post-card .pc-head .ico { width: 14px; height: 14px; }
.post-card .pc-text { font-size: 13.5px; overflow-wrap: anywhere; }
.post-card .pc-text b { font-weight: 650; margin-right: 4px; }
.post-card .pc-reply { border-left: 2px solid var(--grid); padding-left: 10px; font-size: 13px; color: var(--ink-2); }
.post-card .pc-reply b { color: var(--ink); font-weight: 650; margin-right: 4px; }
.note {
  align-self: center;
  text-align: center;
  max-width: 90%;
  font-size: 11.5px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
}
.note.wait { color: var(--accent-ink); }
.note b { font-variant-numeric: tabular-nums; }
.phone-empty { margin: auto; text-align: center; color: var(--muted); font-size: 13px; max-width: 240px; display: grid; gap: 6px; }
.phone-input { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); background: var(--surface); }
.phone-input input { border-radius: 999px; padding: 8px 14px; }
.phone-input button {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: var(--on-accent);
  cursor: pointer;
  display: grid;
  place-items: center;
  flex: none;
}

/* ---------- Actividad ---------- */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
.events { width: 100%; border-collapse: collapse; font-size: 13px; }
.events th {
  text-align: left;
  font-weight: 560;
  color: var(--muted);
  font-size: 12px;
  padding: 0 12px 8px 0;
  border-bottom: 1px solid var(--axis);
  white-space: nowrap;
}
.events td { padding: 9px 12px 9px 0; border-bottom: 1px solid var(--grid); vertical-align: top; }
.events tr.fresh td { animation: fresh 1.6s ease-out; }
@keyframes fresh { from { background: var(--accent-wash); } to { background: transparent; } }
.events .t { font-variant-numeric: tabular-nums; color: var(--ink-2); white-space: nowrap; }
.events .ev { font-weight: 620; white-space: nowrap; }
.events .ev small { display: block; font-weight: 500; color: var(--muted); font-size: 11.5px; }
.events .u { white-space: nowrap; color: var(--ink-2); max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.events .d { min-width: 240px; }
.events .d .quote { color: var(--ink-2); }
.events .d .msg { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--ink-2); }
.events .empty-row td { color: var(--muted); text-align: center; padding: 28px 0; }

/* ---------- Conexión ---------- */
.progress { height: 6px; border-radius: 6px; background: var(--grid); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); border-radius: 6px; transition: width 0.3s; }
.setup { list-style: none; padding: 0; margin: 0; display: grid; }
.setup li { display: grid; grid-template-columns: 20px 1fr; gap: 10px; align-items: start; padding: 8px 0; border-bottom: 1px solid var(--grid); font-size: 13.5px; }
.setup li:last-child { border-bottom: 0; }
.setup .ok > .ico { color: var(--good); }
.setup .no > .ico { color: var(--muted); }
.setup .no .s-text { color: var(--ink-2); }
.setup .s-at { color: var(--muted); font-size: 12px; display: block; }
.copy-row { display: grid; gap: 6px; }
.copy-box { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.copy-box code { flex: 1; min-width: 0; padding: 7px 10px; }
.guide { margin: 0; padding: 0; list-style: none; counter-reset: g; display: grid; gap: 10px; }
.guide > li {
  counter-increment: g;
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}
.guide > li::before {
  content: counter(g);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-wash);
  color: var(--accent-ink);
  font-weight: 700;
  display: grid;
  place-items: center;
}
.guide > li.done::before { content: "✓"; background: var(--good); color: #fff; }
.guide h3 { font-size: 14px; font-weight: 650; margin-bottom: 3px; }
.guide p, .guide ul { color: var(--ink-2); font-size: 13px; margin: 0; }
.guide ul { padding-left: 18px; margin-top: 4px; display: grid; gap: 2px; }
.guide.compact > li { padding: 10px 12px; }

/* ---------- Formularios de cuenta y equipo ---------- */
.form-grid { display: grid; gap: 12px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.form-msg { min-height: 1.3em; font-size: 13px; color: var(--ink-2); }
.form-msg.bad { color: var(--critical-text); }
.form-msg.good { color: var(--good-text); }
.check-row { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--ink-2); }
.check-row input { width: auto; }
.net-row { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-bottom: 10px; }
.people { list-style: none; margin: 0; padding: 0; display: grid; }
.people li {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--grid);
}
.people li:last-child { border-bottom: 0; }
.people .p-name { font-weight: 640; }
.people .p-sub { color: var(--muted); font-size: 12.5px; }
.people .p-actions { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.role {
  display: inline-block;
  font-size: 11px;
  font-weight: 650;
  border-radius: 999px;
  padding: 1px 7px;
  margin-left: 6px;
  background: var(--accent-wash);
  color: var(--accent-ink);
  vertical-align: 1px;
}

/* ---------- Tooltip y aviso ---------- */
.tooltip {
  position: fixed;
  z-index: 40;
  pointer-events: none;
  background: var(--ink);
  color: var(--page);
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 12.5px;
  line-height: 1.4;
  max-width: 260px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.18);
}
.tooltip b { font-weight: 650; }
.toast {
  position: fixed;
  z-index: 50;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--page);
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 13.5px;
  box-shadow: var(--shadow-lg);
  max-width: calc(100vw - 32px);
}

.foot { color: var(--muted); font-size: 12px; text-align: right; }

/* ---------- Entrada ---------- */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login { width: min(400px, 100%); display: grid; gap: 22px; }
.login .brand { justify-content: center; }
.login-card { padding: 24px; gap: 14px; }
.login-card h1 { font-size: 20px; }

@media (prefers-reduced-motion: reduce) {
  .events tr.fresh td { animation: none; }
  .switch, .switch span, .progress i { transition: none; }
}
