@font-face { font-family: Inter; src: url(inter.woff2) format("woff2"); font-weight: 100 900; font-display: swap; }
:root {
  --navy: #232263; --navy-deep: #101035; --green: #00983a; --green-dark: #007a2e; --mint: #defae8;
  --ink: #1d2939; --text: #344054; --muted: #667085; --line: #eaecf0; --bg: #f2f4f7; --card: #fff;
  --red: #d92d20; --red-soft: #fef3f2; --amber: #b54708; --amber-soft: #fffaeb; --blue-soft: #eef0fb;
  --side-width: 232px; --side-bar-height: 56px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { display: flex; font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--green-dark); }
h1, h2, h3 { color: var(--ink); margin: 0; letter-spacing: -.01em; }
h2 { font-size: 17px; }
h3 { font-size: 14px; }
code, pre { font: 12px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; }

/* Sidebar */
.side {
  position: fixed; inset: 0 auto 0 0; z-index: 30; width: var(--side-width);
  display: flex; flex-direction: column; background: var(--navy); color: #fff; padding: 22px 14px;
}
.side-panel { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior-y: contain; }
.side-toggle { display: none; }
.brand { display: flex; flex-shrink: 0; align-items: center; gap: 10px; padding: 0 8px 22px; }
.brand img { height: 28px; }
.brand span { font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: #9fe3b8; }
.brand-pick { display: grid; gap: 4px; margin: 0 6px 18px; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: rgba(255,255,255,.55); }
.brand-pick select { width: 100%; background: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.2); font-weight: 600; font-size: 14px; text-transform: none; letter-spacing: 0; }
.brand-pick select option { color: var(--ink); }
nav { display: grid; gap: 2px; }
nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; color: rgba(255,255,255,.78); text-decoration: none; font-weight: 500; }
nav a b { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 99px; background: rgba(255,255,255,.12); font-size: 11px; }
nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
nav a.active { background: rgba(255,255,255,.14); color: #fff; }
nav a.active b { background: var(--green); }
nav a.sub { margin-top: 10px; padding-left: 42px; font-size: 13px; }
.side-job { margin-top: 16px; padding: 10px 12px; border-radius: 10px; background: rgba(255,255,255,.1); font-size: 12px; }
.spin { display: inline-block; width: 10px; height: 10px; margin-right: 6px; border: 2px solid var(--green); border-right-color: transparent; border-radius: 99px; animation: spin .8s linear infinite; }
.side-job .spin { display: inline-block; width: 10px; height: 10px; margin-right: 6px; border: 2px solid #9fe3b8; border-right-color: transparent; border-radius: 99px; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.side-foot { margin-top: auto; font-size: 12px; color: rgba(255,255,255,.55); padding: 0 8px; }

/* Main */
main { flex: 1; min-width: 0; padding: 28px 32px 64px; }
.side + main { margin-inline-start: var(--side-width); }
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.top h1 { font-size: 26px; }
.top p { margin: 4px 0 0; color: var(--muted); }
#top-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.card { background: var(--card); border-radius: 16px; padding: 20px; box-shadow: 0 1px 2px rgba(16,24,40,.06); min-width: 0; }
.card > h2 { margin-bottom: 4px; }
.card > .hint { margin: 0 0 14px; color: var(--muted); font-size: 13px; }
.muted { color: var(--muted); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }

/* Alerts */
.alert { padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; font-size: 13px; }
.alert b { color: inherit; }
.alert.err { background: var(--red-soft); color: #912018; border: 1px solid #fecdca; }
.alert.warn { background: var(--amber-soft); color: #93370d; border: 1px solid #fedf89; }
.alert.info { background: var(--blue-soft); color: var(--navy); }
.alert.ok { background: #ecfdf3; color: #05603a; }

/* Buttons & inputs */
button, .btn { font: inherit; font-weight: 600; font-size: 13px; border: 0; border-radius: 10px; padding: 9px 16px; cursor: pointer; background: var(--green); color: #fff; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover, .btn:hover { background: var(--green-dark); }
button.secondary, .btn.secondary { background: #fff; color: var(--ink); border: 1.5px solid #d0d5dd; }
button.secondary:hover { background: var(--bg); }
button.danger { background: var(--navy); }
button.danger:hover { background: var(--navy-deep); }
button.link { background: none; color: var(--green-dark); padding: 0; font-weight: 600; }
button[disabled] { opacity: .5; cursor: not-allowed; }
input, select, textarea { font: inherit; font-size: 13px; color: var(--ink); border: 1.5px solid #d0d5dd; border-radius: 9px; padding: 7px 10px; background: #fff; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px rgba(0,152,58,.15); }
input[type=number] { width: 90px; }
label.field { display: grid; gap: 4px; font-size: 12px; font-weight: 600; color: var(--ink); }
.fields { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }

/* Switch */
.switch { position: relative; display: inline-block; width: 36px; height: 20px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #d0d5dd; border-radius: 99px; cursor: pointer; transition: .15s; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; background: #fff; border-radius: 99px; transition: .15s; }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::before { transform: translateX(16px); }
.switch input:focus-visible + span { box-shadow: 0 0 0 3px rgba(0,152,58,.3); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 700; color: var(--ink); }

/* Chips & badges */
.chip { display: inline-block; padding: 2px 8px; margin: 2px 4px 2px 0; border-radius: 99px; background: var(--bg); color: var(--text); font-size: 12px; }
.chip.kw { background: var(--blue-soft); color: var(--navy); }
.chip.block { background: var(--red-soft); color: #912018; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.ok { background: #ecfdf3; color: #05603a; }
.badge.no { background: var(--red-soft); color: #912018; }
.badge.draft { background: var(--amber-soft); color: var(--amber); }
.badge.na { background: var(--bg); color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 99px; margin-right: 6px; }
.dot.ok { background: var(--green); } .dot.no { background: var(--red); } .dot.opt { background: #d0d5dd; }

/* Plan */
.seg { margin-bottom: 14px; }
.seg-head { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; cursor: pointer; }
.seg-head h2 { min-width: 170px; }
.seg-head .plat { font-size: 13px; }
.seg-head .plat b { color: var(--ink); }
.seg-body { margin-top: 14px; }
.seg:not(.open) .seg-body { display: none; }
.caret { margin-left: auto; transition: transform .15s; color: var(--muted); }
.seg.open .caret { transform: rotate(180deg); }
.copy-h { font-weight: 700; color: var(--ink); }
.copy-small { font-size: 12px; color: var(--muted); }
.adset-name { font-weight: 700; color: var(--ink); }
.url { font-size: 11px; color: var(--muted); word-break: break-all; }
.url.mismatch { color: var(--amber); }

/* Landings preview */
.preview { display: grid; gap: 12px; }
.preview iframe { width: 100%; height: 720px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.preview.mobile iframe { width: 390px; max-width: 100%; }

/* Creatives gallery */
.gallery { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.gallery figure { margin: 0; background: var(--bg); border-radius: 12px; overflow: hidden; }
.gallery img { display: block; width: 100%; aspect-ratio: 4 / 5; object-fit: cover; background: #e4e7ec; }
.gallery figcaption { padding: 8px 10px; font-size: 12px; }

/* Publish */
.steps { display: grid; gap: 12px; counter-reset: s; }
.step { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.step h3 { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.step h3::before { counter-increment: s; content: counter(s); display: grid; place-items: center; width: 22px; height: 22px; border-radius: 99px; background: var(--navy); color: #fff; font-size: 11px; }
.step p { margin: 0 0 10px; font-size: 13px; color: var(--muted); }
.step.write { border-color: #fedf89; background: #fffcf5; }

/* Jobs */
.job { border-left: 3px solid var(--line); }
.job.running { border-left-color: #9fe3b8; } .job.ok { border-left-color: var(--green); } .job.error { border-left-color: var(--red); }
.job pre { margin: 8px 0 0; padding: 12px; max-height: 320px; overflow: auto; background: var(--navy-deep); color: #e4e7ec; border-radius: 10px; white-space: pre-wrap; word-break: break-word; }

/* IA */
.ai-card { border: 1.5px dashed #b9c1f0; background: linear-gradient(180deg, #fbfbff, #fff); }
.ai-tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; background: var(--blue-soft); color: var(--navy); font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
textarea { width: 100%; min-height: 110px; resize: vertical; line-height: 1.5; }
.proposal { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-top: 12px; }
.proposal h3 { margin-bottom: 4px; }
.rationale { font-size: 13px; color: var(--muted); margin: 2px 0 8px; }
.variant { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: start; border-top: 1px solid var(--line); padding: 12px 0; }
.variant:first-child { border-top: 0; }
.errs { margin: 6px 0 0; padding-left: 18px; color: #912018; font-size: 12px; }
input[type=color] { width: 44px; height: 34px; padding: 2px; }
details > summary { cursor: pointer; }

/* Estudio de creatividades */
.swatch { display: inline-block; width: 22px; height: 22px; border-radius: 6px; border: 1px solid rgba(0,0,0,.1); }
.cr-layout { display: grid; grid-template-columns: 300px 1fr; gap: 18px; align-items: start; }
.cr-list { max-height: 1100px; overflow: auto; padding: 14px; }
.cr-item { display: flex; gap: 10px; width: 100%; text-align: left; background: #fff; color: var(--text); border: 1.5px solid transparent; border-radius: 12px; padding: 8px; margin-top: 6px; font-weight: 400; white-space: normal; }
.cr-item:hover { background: var(--bg); }
.cr-item.on { border-color: var(--green); background: #f6fbf8; }
.cr-thumb { width: 52px; height: 65px; flex-shrink: 0; border-radius: 6px; background: #e4e7ec; overflow: hidden; }
.cr-thumb img { width: 100%; height: 100%; object-fit: cover; }
.cr-edit { display: grid; grid-template-columns: 380px 1fr; gap: 22px; margin-top: 12px; }
.ad-frame { position: relative; overflow: hidden; border-radius: 10px; box-shadow: 0 6px 20px rgba(16,24,40,.18); background: #e4e7ec; }
.ad-frame iframe { position: absolute; top: 0; left: 0; border: 0; transform-origin: 0 0; pointer-events: none; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 6px; margin-top: 6px; max-height: 250px; overflow: auto; }
.photo-grid button { position: relative; padding: 0; border: 2px solid transparent; border-radius: 8px; overflow: hidden; background: none; aspect-ratio: 4 / 5; }
.photo-grid button.on { border-color: var(--green); }
.photo-grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-grid .ai-tag { position: absolute; left: 3px; top: 3px; font-size: 9px; padding: 1px 5px; }
.render-card { width: 200px; }
.render-card img { width: 100%; border-radius: 8px; box-shadow: 0 4px 14px rgba(16,24,40,.15); display: block; }
.render-empty { display: grid; place-items: center; height: 250px; border-radius: 8px; background: var(--bg); color: var(--muted); font-size: 12px; }
.concepts { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; margin-top: 12px; }
.md h2, .md h3, .md h4, .md h5 { margin: 16px 0 6px; } .md p, .md li { font-size: 14px; } .md pre { background: var(--bg); padding: 10px; border-radius: 8px; overflow: auto; }
@media (max-width: 1200px) { .cr-layout, .cr-edit { grid-template-columns: 1fr; } }

/* Barra de peticiones a la IA en contexto */
.ai-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 10px 0 4px; padding: 8px; border: 1.5px dashed #b9c1f0; border-radius: 12px; background: #fbfbff; }
.ai-bar input { flex: 1; min-width: 220px; }

pre.diff { max-height: 420px; overflow: auto; background: #0f172a; color: #cbd5e1; padding: 12px; border-radius: 10px; font-size: 12px; }
pre.diff .d-add { color: #86efac; } pre.diff .d-del { color: #fca5a5; } pre.diff .d-hunk { color: #93c5fd; }

/* Chat */
.chat-launch { position: fixed; right: 20px; bottom: 20px; z-index: 60; border-radius: 99px; padding: 12px 20px; box-shadow: 0 10px 30px rgba(16,24,40,.25); }
.chat { position: fixed; right: 20px; bottom: 20px; z-index: 61; width: min(440px, calc(100vw - 40px)); height: min(680px, calc(100vh - 40px));
  display: flex; flex-direction: column; background: #fff; border-radius: 18px; box-shadow: 0 24px 60px rgba(16,24,40,.3); overflow: hidden; }
.chat[hidden] { display: none; }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; background: var(--navy); color: #fff; }
.chat-head .link { color: #9fe3b8; } .chat-head .copy-small { color: rgba(255,255,255,.6); }
.chat-log { flex: 1; overflow: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; background: var(--bg); }
.msg { max-width: 88%; padding: 9px 13px; border-radius: 14px; font-size: 13.5px; line-height: 1.45; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--green); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: #fff; border-bottom-left-radius: 4px; box-shadow: 0 1px 2px rgba(16,24,40,.06); white-space: normal; }
.msg.assistant p { margin: 0 0 6px; } .msg.assistant ul { margin: 4px 0; padding-left: 18px; }
.msg.tool, .msg.note { align-self: center; background: none; color: var(--muted); font-size: 11.5px; padding: 0; }
.msg.confirm { align-self: stretch; max-width: none; background: #fffcf5; border: 1px solid #fedf89; }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.chat-form textarea { flex: 1; min-height: 0; resize: none; }
.chat-empty { color: var(--muted); font-size: 13px; }
.chat-empty button { margin: 4px 4px 0 0; font-weight: 500; }

/* Toasts */
.toasts { position: fixed; right: 20px; top: 20px; display: grid; gap: 8px; z-index: 50; }
.toast { max-width: 420px; padding: 12px 16px; border-radius: 12px; background: var(--ink); color: #fff; box-shadow: 0 10px 30px rgba(16,24,40,.25); font-size: 13px; }
.toast.err { background: #912018; } .toast.ok { background: #05603a; }

@media (max-width: 900px) {
  body { flex-direction: column; }
  .side { inset: 0 0 auto; width: auto; padding: 0; }
  .side .brand { height: var(--side-bar-height); padding: 0 94px 0 16px; }
  .side .app-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .side-toggle {
    position: absolute; inset-block-start: 6px; inset-inline-end: 12px;
    display: inline-flex; min-height: 44px; background: rgba(255,255,255,.14);
  }
  .side-toggle:hover { background: rgba(255,255,255,.24); }
  .side-panel { display: none; max-height: calc(100dvh - var(--side-bar-height)); padding: 8px 14px 20px; }
  .side-toggle[aria-expanded="true"] + .side-panel { display: flex; }
  nav { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .side + main { margin-inline-start: 0; padding: calc(var(--side-bar-height) + 20px) 16px 48px; }
  .grid-2 { grid-template-columns: 1fr; }
}

.alt-strip { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.alt-thumb { display: flex; flex-direction: column; gap: 4px; width: 96px; text-decoration: none; color: inherit; }
.alt-thumb img { width: 96px; height: 120px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }

/* Login y usuario */
body.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; background: var(--navy); }
.login-card { width: min(360px, 100%); display: grid; gap: 14px; }
.login-card h1 { font-size: 22px; }
.login-card .hint { margin: -8px 0 0; color: var(--muted); }
.login-card .alert { margin: 0; }
.brand .app-name { font-size: 15px; letter-spacing: .02em; text-transform: none; color: #fff; }
.side-user { display: grid; gap: 4px; margin-top: 16px; padding: 10px 8px 0; border-top: 1px solid rgba(255,255,255,.12); font-size: 12px; color: rgba(255,255,255,.7); }
.side-user b { color: #fff; }
.side-user .row { gap: 12px; }
.side-user button.link { color: #9fe3b8; font-size: 12px; }
.user-logo { height: 28px; max-width: 140px; padding: 4px 8px; border-radius: 8px; background: var(--navy); object-fit: contain; }
.brand-checks { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.brand-checks label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
