:root {
  --bg: #f6f5fb;
  --panel: #ffffff;
  --ink: #17132b;
  --ink-2: #4a4560;
  --ink-3: #7a7591;
  --line: #e7e4f2;
  --violet: #6a2cf0;
  --violet-2: #8b5cf6;
  --pink: #e0389b;
  --amber: #ffb547;
  --green: #14a46c;
  --red: #e5484d;
  --side: #140f2b;
  --side-2: #221a45;
  --grad: linear-gradient(135deg, #ffb547 0%, #e0389b 45%, #6a2cf0 100%);
  --radius: 14px;
  --shadow: 0 1px 2px rgba(23, 19, 43, .04), 0 8px 24px rgba(23, 19, 43, .06);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--violet); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 24px; margin: 0; letter-spacing: -.02em; }
h2 { font-size: 17px; margin: 0 0 4px; letter-spacing: -.01em; }
h3 { font-size: 14px; margin: 0 0 6px; }
p { margin: 0; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.side { background: var(--side); color: #fff; padding: 20px 14px; display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh; }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 20px; letter-spacing: -.03em; padding: 0 8px; color: #fff; }
.logo-mark { width: 30px; height: 30px; border-radius: 9px; background: var(--grad); display: grid; place-items: center; font-size: 18px; color: #fff; }
.acct-switch { background: var(--side-2); border: 1px solid rgba(255,255,255,.12); border-radius: 12px; padding: 10px; color: #fff; width: 100%; display: flex; gap: 10px; align-items: center; cursor: pointer; text-align: left; }
.acct-switch select { appearance: none; background: transparent; border: 0; color: #fff; font-weight: 600; width: 100%; cursor: pointer; outline: none; }
.acct-switch select option { color: var(--ink); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--grad); display: grid; place-items: center; font-weight: 700; color: #fff; flex: none; overflow: hidden; font-size: 13px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { color: #fff; padding: 9px 10px; border-radius: 10px; display: flex; gap: 10px; align-items: center; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.08); }
.nav a.active { background: rgba(255,255,255,.14); }
.nav svg { width: 18px; height: 18px; flex: none; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.env-pill { font-size: 12px; color: #fff; background: rgba(255,181,71,.18); border: 1px solid rgba(255,181,71,.5); border-radius: 10px; padding: 8px 10px; }
.env-pill b { color: #ffd28a; }
.side-user { display: flex; justify-content: space-between; align-items: center; color: #fff; font-size: 12px; padding: 0 6px; }
.side-user button { background: none; border: 0; color: #fff; cursor: pointer; text-decoration: underline; padding: 0; }

.main { padding: 28px 36px 60px; max-width: 1240px; width: 100%; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px; }
.page-head p { color: var(--ink-3); margin-top: 4px; }

/* ---------- Building blocks ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card, .grid > * > .card:first-child { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.sep { height: 1px; background: var(--line); margin: 16px 0; border: 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); padding: 9px 14px; border-radius: 10px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #cfc9e6; }
.btn.primary { background: var(--violet); border-color: var(--violet); color: #fff; }
.btn.primary:hover { background: #5a1fe0; }
.btn.grad { background: var(--grad); border: 0; color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.danger { color: var(--red); }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: default; }

.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 13px; }
.field .hint { font-weight: 400; color: var(--ink-3); font-size: 12px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], select, textarea {
  width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 10px 12px; outline: none; font-weight: 400;
}
input:focus, select:focus, textarea:focus { border-color: var(--violet-2); box-shadow: 0 0 0 3px rgba(139, 92, 246, .15); }
textarea { resize: vertical; min-height: 84px; }

.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #d9d5e8; border-radius: 22px; transition: .15s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--violet); }
.switch input:checked + span::after { transform: translateX(16px); }
.toggle-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; }
.toggle-row + .toggle-row { border-top: 1px solid var(--line); }
.toggle-row b { display: block; font-size: 13px; }

.seg { display: inline-flex; background: #f0eef8; border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 7px 12px; border-radius: 8px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.seg button.on { background: #fff; color: var(--violet); box-shadow: 0 1px 3px rgba(23,19,43,.12); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; border: 1px solid var(--line); border-radius: 10px; padding: 6px; background: #fff; }
.chip { background: #f1ecff; color: var(--violet); border-radius: 999px; padding: 4px 10px; font-weight: 600; font-size: 12px; display: inline-flex; gap: 6px; align-items: center; }
.chip button { border: 0; background: none; color: inherit; cursor: pointer; padding: 0; font-size: 14px; line-height: 1; }
.chips input { border: 0 !important; box-shadow: none !important; flex: 1; min-width: 120px; padding: 4px 6px !important; }

.badge { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 3px 9px; font-size: 12px; font-weight: 600; background: #f0eef8; color: var(--ink-2); }
.badge.green { background: #e3f6ee; color: #0c7a4f; }
.badge.red { background: #fde8e8; color: #b42318; }
.badge.amber { background: #fff3dc; color: #9a5b00; }
.badge.violet { background: #f1ecff; color: var(--violet); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--ink-3); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }

.empty { text-align: center; padding: 36px 20px; color: var(--ink-3); }
.empty h2 { color: var(--ink); }
.empty .btn { margin-top: 14px; }

/* ---------- Overview ---------- */
.stat { padding: 18px; }
.stat .label { color: var(--ink-3); font-size: 12px; font-weight: 600; }
.stat .value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; }
.bars { display: flex; align-items: flex-end; gap: 8px; height: 120px; padding-top: 10px; }
.bars div { flex: 1; background: linear-gradient(180deg, var(--violet-2), var(--violet)); border-radius: 6px 6px 2px 2px; min-height: 3px; position: relative; }
.bars div span { position: absolute; top: -18px; left: 50%; transform: translateX(-50%); font-size: 11px; color: var(--ink-3); }
.bar-labels { display: flex; gap: 8px; margin-top: 6px; }
.bar-labels span { flex: 1; text-align: center; font-size: 11px; color: var(--ink-3); }
.checklist li { display: flex; gap: 10px; align-items: center; padding: 8px 0; }
.checklist { list-style: none; margin: 0; padding: 0; }
.check { width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; flex: none; font-size: 12px; color: #fff; }
.check.done { background: var(--green); border-color: var(--green); }

.hero { background: var(--side); color: #fff; border-radius: 18px; padding: 26px; display: flex; justify-content: space-between; gap: 20px; align-items: center; position: relative; overflow: hidden; }
.hero::after { content: ""; position: absolute; right: -60px; top: -80px; width: 260px; height: 260px; border-radius: 50%; background: var(--grad); opacity: .55; filter: blur(30px); }
.hero h2 { font-size: 22px; color: #fff; }
.hero p { color: #fff; margin-top: 6px; max-width: 560px; }
.hero > * { position: relative; z-index: 1; }

/* ---------- Automations ---------- */
.auto-card { display: flex; gap: 14px; align-items: center; }
.auto-icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; flex: none; color: #fff; }
.auto-icon svg { width: 22px; height: 22px; }
.t-comment_dm { background: linear-gradient(135deg, #e0389b, #6a2cf0); }
.t-comment_ai { background: linear-gradient(135deg, #8b5cf6, #3b82f6); }
.t-dm_ai { background: linear-gradient(135deg, #6a2cf0, #14a46c); }
.t-story { background: linear-gradient(135deg, #ffb547, #e0389b); }
.auto-meta { flex: 1; min-width: 0; }
.auto-meta p { color: var(--ink-3); font-size: 13px; }
.auto-stats { display: flex; gap: 18px; text-align: right; }
.auto-stats b { display: block; font-size: 16px; }
.auto-stats span { font-size: 11px; color: var(--ink-3); }
.type-pick { cursor: pointer; transition: .15s; }
.type-pick:hover { border-color: var(--violet-2); transform: translateY(-1px); }
.type-pick p { color: var(--ink-3); margin-top: 6px; }
.ai-tag { font-size: 10px; font-weight: 700; letter-spacing: .04em; background: var(--grad); color: #fff; padding: 2px 6px; border-radius: 6px; margin-left: 6px; vertical-align: middle; }

.editor { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.section-title { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.step-num { width: 24px; height: 24px; border-radius: 50%; background: var(--violet); color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.media-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.media-grid button { aspect-ratio: 1; border: 2px solid transparent; border-radius: 10px; overflow: hidden; padding: 0; cursor: pointer; background: #eee center/cover; position: relative; }
.media-grid button.on { border-color: var(--violet); }
.media-grid button.on::after { content: "✓"; position: absolute; top: 4px; right: 4px; background: var(--violet); color: #fff; width: 18px; height: 18px; border-radius: 50%; font-size: 11px; display: grid; place-items: center; }
.btn-rows .row { margin-bottom: 8px; }
.prod-pick { display: flex; flex-wrap: wrap; gap: 6px; }
.prod-pick button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 5px 11px; cursor: pointer; font-size: 12px; font-weight: 600; }
.prod-pick button.on { background: var(--violet); border-color: var(--violet); color: #fff; }

/* Phone preview */
.phone { position: sticky; top: 20px; background: var(--side); border-radius: 30px; padding: 12px; box-shadow: var(--shadow); }
.phone-screen { background: #fff; border-radius: 22px; overflow: hidden; min-height: 520px; }
.phone-top { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; font-weight: 600; }
.phone-body { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.ig-comment { display: flex; gap: 8px; font-size: 13px; }
.ig-comment .avatar { width: 26px; height: 26px; font-size: 11px; }
.ig-comment.reply { margin-left: 34px; }
.phone-label { font-size: 11px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; margin-top: 6px; }
.bubble { max-width: 82%; padding: 9px 12px; border-radius: 18px; font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.bubble.in { background: #efeff4; align-self: flex-start; border-bottom-left-radius: 6px; }
.bubble.out { background: var(--violet); color: #fff; align-self: flex-end; border-bottom-right-radius: 6px; }
.bubble.human { background: #14a46c; color: #fff; }
.bubble-btn { align-self: flex-end; max-width: 82%; width: 82%; border: 1px solid var(--line); border-radius: 12px; text-align: center; padding: 8px; font-weight: 600; color: var(--violet); font-size: 13px; background: #fff; }
.pcard { align-self: flex-end; width: 82%; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: #fff; }
.pcard .pimg { height: 90px; background: #f1ecff center/cover; display: grid; place-items: center; color: var(--violet); font-weight: 700; }
.pcard .pbody { padding: 8px 10px; font-size: 12px; }
.pcard .pbody b { display: block; font-size: 13px; }
.pcard .pbtn { border-top: 1px solid var(--line); padding: 7px; text-align: center; font-weight: 600; color: var(--violet); font-size: 12px; }

/* ---------- Inbox ---------- */
.inbox { display: grid; grid-template-columns: 300px 1fr; height: calc(100vh - 150px); min-height: 520px; padding: 0; overflow: hidden; }
.inbox-list { border-right: 1px solid var(--line); overflow-y: auto; }
.inbox-item { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.inbox-item:hover { background: #faf9fd; }
.inbox-item.on { background: #f1ecff; }
.inbox-item .t { flex: 1; min-width: 0; }
.inbox-item .t p { color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.thread { display: flex; flex-direction: column; min-width: 0; }
.thread-head { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.thread-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; background: #fcfbff; }
.thread-foot { border-top: 1px solid var(--line); padding: 12px; display: flex; gap: 8px; }
.msg-meta { font-size: 11px; color: var(--ink-3); }
.msg-meta.right { align-self: flex-end; }

/* ---------- Agent sandbox ---------- */
.sandbox { display: flex; flex-direction: column; height: 520px; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.sandbox .thread-body { background: #fff; }

/* ---------- Activity ---------- */
.ev { font-size: 12px; font-weight: 600; color: var(--ink-2); }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-art { background: var(--side); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-art::before { content: ""; position: absolute; width: 520px; height: 520px; border-radius: 50%; background: var(--grad); filter: blur(60px); opacity: .45; right: -160px; bottom: -160px; }
.auth-art > * { position: relative; }
.auth-art h1 { font-size: 40px; line-height: 1.1; color: #fff; max-width: 520px; letter-spacing: -.03em; }
.auth-art p { color: #fff; font-size: 16px; max-width: 480px; margin-top: 14px; }
.auth-points { display: flex; flex-direction: column; gap: 12px; margin-top: 28px; }
.auth-points div { display: flex; gap: 10px; align-items: center; color: #fff; font-weight: 500; }
.auth-points span { width: 26px; height: 26px; border-radius: 8px; background: rgba(255,255,255,.14); display: grid; place-items: center; }
.auth-form { display: grid; place-items: center; padding: 40px; }
.auth-form form { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px; }
.err { color: var(--red); font-size: 13px; min-height: 18px; }

/* ---------- Misc ---------- */
#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--side); color: #fff; padding: 10px 16px; border-radius: 12px; font-weight: 500; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--red); }
.notice { border-radius: 12px; padding: 12px 14px; background: #fff3dc; color: #6b4300; border: 1px solid #ffe0a6; font-size: 13px; }
.notice.info { background: #f1ecff; color: #3d1d8f; border-color: #ddd0ff; }
.notice.error { background: #fde8e8; color: #8a1c17; border-color: #f8c6c6; }
.copy { display: flex; gap: 8px; }
.copy input { font-family: ui-monospace, Menlo, monospace; font-size: 12px; background: #faf9fd; }
pre.json { background: #140f2b; color: #fff; border-radius: 12px; padding: 14px; overflow: auto; max-height: 340px; font-size: 12px; margin: 0; }
.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Legal pages */
body.legal { background: var(--bg); }
.legal-card { max-width: 760px; margin: 48px auto; background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 36px; }
.legal-card h1 { margin: 18px 0 12px; }
.legal-card h2 { margin-top: 22px; }
.legal-card p { margin: 8px 0; color: var(--ink-2); }
.brand-mark { font-weight: 700; font-size: 20px; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }

@media (max-width: 1100px) {
  .editor { grid-template-columns: 1fr; }
  .phone { position: static; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .main { padding: 20px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .auth { grid-template-columns: 1fr; }
  .auth-art { display: none; }
  .inbox { grid-template-columns: 1fr; height: auto; }
}
