:root {
  --bg: #f7f7f5; --surface: #fff; --text: #1d1d1b; --muted: #6b6b66; --border: #e3e3de;
  --accent: #e8590c; --ok: #2b8a3e; --danger: #c92a2a; --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #151514; --surface: #1f1f1d; --text: #ededea; --muted: #9a9a94; --border: #33332f; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem 16px 4rem; }
.topbar { display: flex; align-items: center; gap: 1rem; padding: .6rem 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar .brand { font-weight: 700; color: var(--text); }
.topbar .brand span, .accent { color: var(--accent); }
.spacer { flex: 1; }
.account-switch details { position: relative; }
.account-switch summary { cursor: pointer; padding: .25rem .6rem; border: 1px solid var(--border); border-radius: var(--radius); list-style: none; }
.account-switch ul { position: absolute; z-index: 10; margin: .3rem 0 0; padding: .3rem; list-style: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-width: 220px; }
.account-switch li a { display: flex; justify-content: space-between; gap: 1rem; padding: .35rem .5rem; color: var(--text); border-radius: 6px; }
.account-switch li a:hover { background: var(--bg); }
.tabs { display: flex; gap: .25rem; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs a { padding: .6rem .8rem; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--text); border-color: var(--accent); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem; margin-bottom: 1rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.account-card { display: flex; justify-content: space-between; align-items: center; color: var(--text); }
.module { color: var(--text); }
.module p { color: var(--muted); margin: .3rem 0 0; }
.module.soon { opacity: .7; }
.badge { font-size: .75rem; padding: .1rem .5rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); color: var(--muted); }
.pill { display: inline-block; margin: 0 .4rem 1rem 0; padding: .2rem .7rem; border-radius: 999px; font-size: .85rem; border: 1px solid var(--border); }
.pill.ok { border-color: var(--ok); color: var(--ok); }
.pill.off { color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.error { color: var(--danger); }
table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; }
th, td { text-align: left; padding: .45rem .4rem; border-bottom: 1px solid var(--border); }
th { font-weight: 600; color: var(--muted); font-size: .85rem; }
input, select, button { font: inherit; padding: .45rem .6rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
button { background: var(--accent); border-color: var(--accent); color: #fff; cursor: pointer; }
button.link { background: none; border: none; color: var(--accent); padding: 0; }
button.link.danger { color: var(--danger); }
form.inline { display: flex; flex-wrap: wrap; gap: .5rem; }
form.stack, .login form { display: flex; flex-direction: column; gap: .75rem; max-width: 460px; }
label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; }
.login { max-width: 400px; margin: 10vh auto 0; }
pre.secret { padding: .75rem; background: var(--bg); border-radius: 8px; font-size: 1.1rem; }
.topbar form { margin: 0; }
@media (max-width: 640px) { .topbar .muted { display: none; } }

/* ── Dashboard ─────────────────────────────────────────────────────────── */
:root { --series-1: #2a78d6; --grid: #ececE8; --ok-text: #2b8a3e; --bad-text: #c92a2a; }
@media (prefers-color-scheme: dark) { :root { --series-1: #3987e5; --grid: #2c2c29; --ok-text: #69db7c; --bad-text: #ff8787; } }
.page-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .75rem; }
.page-head h1 { margin: 0; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.filters form { margin: 0; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg a { padding: .35rem .7rem; color: var(--muted); font-size: .9rem; }
.seg a.active { background: var(--text); color: var(--bg); }
button.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.notice { border-color: var(--accent); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .75rem; margin: 1rem 0; }
.kpi { display: flex; flex-direction: column; gap: .15rem; margin: 0; }
.kpi .label { color: var(--muted); font-size: .85rem; }
.kpi strong { font-size: 1.45rem; font-variant-numeric: tabular-nums; }
.delta { font-size: .8rem; }
.delta.up { color: var(--ok-text); }
.delta.down { color: var(--bad-text); }
.delta.neutral { color: var(--muted); }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: .75rem; }
.chart { margin: 0 0 .75rem; }
.chart figcaption { font-weight: 600; margin-bottom: .5rem; }
.chart-empty { padding: 2rem 0; text-align: center; }
svg.viz { width: 100%; height: auto; display: block; overflow: visible; }
svg.viz .grid { stroke: var(--grid); stroke-width: 1; }
svg.viz .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
svg.viz .mark { fill: var(--series-1); }
svg.viz .hit { fill: transparent; }
svg.viz .bar { outline: none; cursor: default; }
svg.viz .bar.hover .hit, svg.viz .bar:focus .hit { fill: var(--text); fill-opacity: .05; }
.viz-tip { position: absolute; z-index: 20; pointer-events: none; padding: .3rem .55rem; border-radius: 6px;
  background: var(--text); color: var(--bg); font-size: .82rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.status { font-size: .8rem; padding: .05rem .45rem; border-radius: 999px; border: 1px solid var(--border); white-space: nowrap; }
.status.s-active { border-color: var(--ok); color: var(--ok-text); }
details summary { cursor: pointer; color: var(--muted); margin-bottom: .5rem; }

/* ── Research ──────────────────────────────────────────────────────────── */
textarea { font: inherit; padding: .45rem .6rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); resize: vertical; }
.research-form { display: flex; flex-direction: column; gap: .8rem; max-width: 720px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: .6rem .9rem .9rem; display: flex; flex-direction: column; gap: .6rem; margin: 0; }
legend { font-weight: 600; padding: 0 .3rem; }
label.check { flex-direction: row; align-items: center; gap: .5rem; }
.status.s-done { border-color: var(--ok); color: var(--ok-text); }
.status.s-draft { border-style: dashed; color: var(--muted); }
.status.s-error { border-color: var(--danger); color: var(--bad-text); }
.error-card { border-color: var(--danger); }
.spinner { display: inline-block; width: .8rem; height: .8rem; margin-right: .4rem; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
.insights { list-style: none; padding: 0; margin: 1rem 0; }
.insight-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: .5rem; }
.insight-title { flex: 1 1 240px; font-size: 1.05rem; }
.rank { color: var(--muted); font-variant-numeric: tabular-nums; }
.kind { font-size: .75rem; padding: .05rem .5rem; border-radius: 999px; border: 1px solid var(--border); white-space: nowrap; }
.kind.k-pain_point { border-color: #e34948; }
.kind.k-outcome { border-color: #1baf7a; }
.kind.k-objection { border-color: #eda100; }
.kind.k-hook { border-color: #2a78d6; }
.mentions { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.insight p { margin: .5rem 0; }
.angle { padding: .4rem .6rem; background: var(--bg); border-radius: 8px; }
blockquote { margin: .4rem 0 0; padding: .2rem 0 .2rem .8rem; border-left: 3px solid var(--border); color: var(--muted); }
blockquote cite { display: block; font-style: normal; font-size: .8rem; margin-top: .15rem; }
button.pick { background: var(--surface); color: var(--text); border-color: var(--border); font-size: .85rem; padding: .25rem .6rem; }
button.pick.on { background: var(--ok); border-color: var(--ok); color: #fff; }
nav.seg { flex-wrap: wrap; }

/* ── Campañas ──────────────────────────────────────────────────────────── */
:root { --m-prep: #2a78d6; --m-launch: #eb6834; --m-test: #1baf7a; --m-optimize: #eda100; --m-report: #e87ba4; }
@media (prefers-color-scheme: dark) { :root { --m-prep: #3987e5; --m-launch: #d95926; --m-test: #199e70; --m-optimize: #c98500; --m-report: #d55181; } }
.row { display: flex; flex-wrap: wrap; gap: .6rem; }
.row label { flex: 1 1 140px; }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.actions form { margin: 0; }
.actions ul { margin: .2rem 0 0; padding-left: 1.2rem; }
.status.s-approved { border-color: var(--accent); color: var(--accent); }
.status.s-published { border-color: var(--ok); color: var(--ok-text); }
.tabs.inner { background: none; padding: 0; margin: 0 0 1rem; }
.pre { white-space: pre-line; }
.adset { margin-bottom: 1.5rem; }
.adset-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: .6rem; }
.adset-head h2 { margin: 0; }
.adset-head form.budget input { width: 7rem; padding: .25rem .4rem; }
.adset-head form.budget label { flex-direction: row; align-items: center; gap: .3rem; }
.ads-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: .75rem; }
.ad { margin: 0; display: flex; flex-direction: column; gap: .4rem; }
.ad-head { display: flex; gap: .5rem; align-items: baseline; flex-wrap: wrap; }
.ad-img { width: 100%; border-radius: 8px; display: block; }
.ad-copy .primary { white-space: pre-line; margin: 0 0 .5rem; }
.ad-link { display: flex; justify-content: space-between; align-items: center; gap: .6rem; padding: .5rem .6rem; background: var(--bg); border-radius: 8px; }
.cta { font-size: .8rem; padding: .25rem .55rem; border-radius: 6px; border: 1px solid var(--border); white-space: nowrap; }
.chip { display: inline-block; margin: .1rem .2rem 0 0; padding: .05rem .45rem; border-radius: 999px; border: 1px solid var(--border); }
.scenes { padding-left: 1.2rem; }
.scenes li { margin-bottom: .35rem; }
.ad-actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-top: auto; padding-top: .4rem; border-top: 1px solid var(--border); }
.ad-actions form { margin: 0; }
.ad-actions .rewrite input { flex: 1 1 140px; padding: .25rem .45rem; font-size: .85rem; }
.small-btn { font-size: .82rem; padding: .25rem .6rem; }
.file-btn { cursor: pointer; display: inline-block; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }
form.stack.wide { max-width: none; }
.calendar { display: flex; flex-direction: column; gap: 2px; overflow-x: auto; }
.cal-row { display: grid; grid-template-columns: repeat(7, minmax(110px, 1fr)); gap: 2px; }
.cal-head div { font-size: .8rem; color: var(--muted); padding: .2rem .4rem; }
.cal-day { min-height: 90px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: .3rem; display: flex; flex-direction: column; gap: .25rem; }
.cal-day.out { opacity: .45; }
.cal-date { font-size: .75rem; color: var(--muted); }
.slot summary { font-size: .8rem; color: var(--text); margin: 0; list-style: none; }
.slot .badge { display: inline-block; margin-bottom: .1rem; }
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: .9rem; padding: 0; margin: 0 0 .8rem; font-size: .85rem; }
.legend li { display: flex; align-items: center; gap: .35rem; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.gantt { display: flex; flex-direction: column; gap: .35rem; }
.gantt-row { display: grid; grid-template-columns: minmax(120px, 220px) 1fr auto; gap: .6rem; align-items: center; }
.gantt-label { font-size: .88rem; }
.gantt-track { position: relative; height: 14px; background: var(--bg); border-radius: 4px; }
.gantt-bar { position: absolute; top: 0; bottom: 0; border-radius: 4px; outline-offset: 2px; }
.m-prep { background: var(--m-prep); } .m-launch { background: var(--m-launch); } .m-test { background: var(--m-test); }
.m-optimize { background: var(--m-optimize); } .m-report { background: var(--m-report); }
@media (max-width: 640px) { .gantt-row { grid-template-columns: 1fr; } .gantt-days { display: none; } }
.ok-text { color: var(--ok-text); }

/* Chat */
.chat-layout { display: grid; grid-template-columns: 240px 1fr; gap: 1rem; align-items: start; }
.chat-list ul { list-style: none; margin: .75rem 0 0; padding: 0; }
.chat-list li a { display: block; padding: .35rem .5rem; border-radius: 6px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-list li.active a, .chat-list li a:hover { background: var(--bg); }
.new-chat { font-weight: 600; }
.chat-head h1 { font-size: 1.2rem; }
.messages { display: flex; flex-direction: column; gap: .75rem; margin-bottom: 1rem; }
.msg { padding: .75rem 1rem; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); max-width: 100%; overflow-x: auto; }
.msg.user { align-self: flex-end; background: var(--bg); max-width: 85%; }
.msg.user p { margin: 0; }
.md > :first-child { margin-top: 0; } .md > :last-child { margin-bottom: 0; }
.md table { border-collapse: collapse; margin: .5rem 0; font-size: .9rem; }
.md th, .md td { border: 1px solid var(--border); padding: .3rem .6rem; text-align: left; }
.md code { background: var(--bg); padding: 0 .25rem; border-radius: 4px; }
.tool-call { font-size: .85rem; color: var(--muted); margin: .25rem 0; }
.tool-call pre { white-space: pre-wrap; background: var(--bg); padding: .5rem; border-radius: 6px; }
.chat-main { min-width: 0; }
.composer { display: flex; flex-direction: column; align-items: flex-end; gap: .5rem; width: 100%; }
.composer textarea { width: 100%; min-height: 5.5rem; }
.examples { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.chat-cost { margin: 0; }
@media (max-width: 760px) { .chat-layout { grid-template-columns: 1fr; } .chat-list ul { max-height: 160px; overflow-y: auto; } }
.token-box { white-space: pre-wrap; word-break: break-all; background: var(--bg); padding: .6rem; border-radius: 6px; font-size: .85rem; }

/* ── Brief de marca ───────────────────────────────────────────────────── */
.brief-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.brief-nav { display: flex; flex-direction: column; gap: .1rem; position: sticky; top: 1rem; }
.brief-nav a { display: flex; justify-content: space-between; gap: .5rem; padding: .35rem .55rem; border-radius: 8px; color: var(--text); font-size: .9rem; }
.brief-nav a:hover { background: var(--surface); }
.brief-nav a.active { background: var(--surface); border: 1px solid var(--border); font-weight: 600; }
.brief-main { min-width: 0; }
.brief-form { display: flex; flex-direction: column; gap: 1rem; }
.brief-form h3 { font-size: 1rem; margin: .75rem 0 0; color: var(--muted); }
.q { display: flex; flex-direction: column; gap: .35rem; }
.q label { font-weight: 500; }
.q input, .q textarea { width: 100%; }
.prio { font-size: .7rem; font-weight: 500; padding: 0 .4rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); white-space: nowrap; }
.prio-obligatorio { border-color: var(--accent); color: var(--accent); }
.bar { display: inline-block; width: 120px; height: 6px; border-radius: 999px; background: var(--border); overflow: hidden; vertical-align: middle; }
.bar span { display: block; height: 100%; background: var(--ok); }
.brief-table input { width: 100%; min-width: 120px; }
.brief-table tr.example td { color: var(--muted); font-style: italic; font-size: .85rem; }
.brief-actions { display: flex; align-items: center; gap: 1rem; margin-top: 1.25rem; position: sticky; bottom: 0; padding: .75rem 0; background: var(--bg); }
.notice-bar { padding: .5rem .75rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.inline-label { flex-direction: row; align-items: center; gap: .4rem; }
.diff { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: .75rem; }
.diff pre { white-space: pre-wrap; word-break: break-word; font: inherit; font-size: .85rem; background: var(--bg); padding: .6rem; border-radius: 8px; margin: .25rem 0 0; max-height: 320px; overflow: auto; }
@media (max-width: 760px) {
  .brief-layout { grid-template-columns: 1fr; }
  .brief-nav { position: static; flex-direction: row; overflow-x: auto; padding-bottom: .25rem; }
  .brief-nav a { white-space: nowrap; }
}
