:root {
  --bg: #f6f7f9; --panel: #ffffff; --panel-2: #f1f3f6; --border: #e3e6eb; --text: #151a21; --muted: #667085;
  --accent: #5b4ce6; --accent-soft: #eeebff; --hot: #e8590c; --hot-soft: #fff1e8; --ok: #13795b; --ok-soft: #e6f6ef;
  --warn: #b54708; --warn-soft: #fef4e6; --danger: #c01048; --danger-soft: #fdecf1;
  --lead: #f1f3f6; --muse: #eeebff; --owner: #e6f6ef;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1); --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --panel: #161a20; --panel-2: #1d222a; --border: #2a303a; --text: #e8ebf0; --muted: #98a2b3;
    --accent: #8f84ff; --accent-soft: #25224a; --hot: #ff8a4c; --hot-soft: #3a2415; --ok: #3ccb95; --ok-soft: #133226;
    --warn: #f5a524; --warn-soft: #3a2c10; --danger: #ff6b9a; --danger-soft: #3a1522;
    --lead: #1d222a; --muse: #25224a; --owner: #133226; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
#app { height: 100%; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 14px; }
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 20px; margin: 0 0 16px; } h2 { font-size: 15px; margin: 0 0 10px; } h3 { font-size: 13px; margin: 0 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.btn { border: 1px solid var(--border); background: var(--panel); padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--panel-2); }
.btn { transition: transform 160ms var(--ease-out); }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.hot { background: var(--hot); border-color: var(--hot); color: #fff; }
.btn.sm { padding: 4px 8px; font-size: 12px; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); }
textarea { min-height: 80px; resize: vertical; }
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); } .small { font-size: 12px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }

/* Auth */
.auth { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.auth .card { width: 100%; max-width: 380px; }
.auth .brand { font-weight: 700; font-size: 18px; margin-bottom: 4px; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* Shell */
.shell { display: grid; grid-template-columns: 240px 1fr; height: 100vh; height: 100dvh; }
.nav { background: var(--panel); border-right: 1px solid var(--border); padding: 16px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav .brand { font-weight: 700; padding: 4px 10px 16px; }
.nav .brand span { color: var(--accent); }
.nav a { color: var(--text); padding: 8px 10px; border-radius: 8px; display: flex; justify-content: space-between; }
.nav a.active, .nav a:hover { background: var(--accent-soft); color: var(--accent); }
.nav .spacer { flex: 1; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.main > .content { flex: 1; min-height: 0; overflow: auto; padding: 20px; }
.main.flush > .content { padding: 0; overflow: hidden; }
.foot { flex: none; padding: 10px 16px; border-top: 1px solid var(--border); background: var(--panel); color: var(--muted); font-size: 12px; text-align: center; }
.auth .foot { border: 0; background: none; margin-top: 16px; }
.auth { grid-auto-flow: row; align-content: center; }
.mobile-only { display: none; }
.mobile-bar { display: none; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.hot { background: var(--hot-soft); color: var(--hot); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.score { font-weight: 700; min-width: 34px; text-align: center; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* Inbox */
.inbox { display: grid; grid-template-columns: 320px 1fr 340px; height: 100%; }
.list { border-right: 1px solid var(--border); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.list .filters { padding: 12px; border-bottom: 1px solid var(--border); display: grid; gap: 8px; }
.list .items { overflow-y: auto; flex: 1; }
.convo { display: flex; gap: 10px; padding: 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
.convo:hover { background: var(--panel-2); }
.convo.active { background: var(--accent-soft); }
.convo .body { flex: 1; min-width: 0; }
.convo .top { display: flex; justify-content: space-between; gap: 6px; }
.convo .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.convo .preview { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin: 2px 0 4px; }
.convo.unread .name::after { content: ""; display: inline-block; width: 8px; height: 8px; background: var(--accent); border-radius: 50%; margin-left: 6px; }

.thread { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.thread header { padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--panel); display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.tabs { display: flex; gap: 2px; padding: 0 12px; border-bottom: 1px solid var(--border); background: var(--panel); overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 10px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabpane { flex: 1; overflow-y: auto; padding: 16px; }
.msg { max-width: 72%; margin: 6px 0; padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg.in { background: var(--lead); border-bottom-left-radius: 4px; }
.msg.out { margin-left: auto; border-bottom-right-radius: 4px; }
.msg.MUSE { background: var(--muse); } .msg.OWNER, .msg.SALESPERSON { background: var(--owner); } .msg.AUTOMATION, .msg.PRESET { background: var(--panel-2); }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.timeline-item { border-left: 2px solid var(--border); padding: 0 0 14px 12px; position: relative; }
.timeline-item::before { content: ""; position: absolute; left: -5px; top: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.timeline-item .when { font-size: 12px; color: var(--muted); }
.observe { padding: 10px 16px; border-top: 1px solid var(--border); background: var(--panel); font-size: 12px; color: var(--muted); }

.intel { border-left: 1px solid var(--border); background: var(--panel); overflow-y: auto; padding: 16px; display: grid; gap: 14px; align-content: start; }
.bigscore { display: flex; align-items: center; gap: 12px; }
.bigscore .n { font-size: 34px; font-weight: 800; line-height: 1; }
.meters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.meter { background: var(--panel-2); border-radius: 8px; padding: 8px; text-align: center; }
.meter b { display: block; font-size: 18px; } .meter span { font-size: 11px; color: var(--muted); }
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 6px 10px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; overflow-wrap: anywhere; }
.nba { background: var(--accent-soft); border-radius: 10px; padding: 12px; }
.nba .act { font-weight: 700; color: var(--accent); }
.alert { background: var(--hot-soft); border: 1px solid var(--hot); color: var(--text); border-radius: 10px; padding: 12px; }
.alert.dnc { background: var(--danger-soft); border-color: var(--danger); }
.seg { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: var(--panel); padding: 6px; cursor: pointer; font-size: 12px; }
.seg button.on { background: var(--accent); color: #fff; }
.empty { display: grid; place-items: center; height: 100%; color: var(--muted); padding: 24px; text-align: center; }

/* Pipeline */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.col { background: var(--panel-2); border-radius: var(--radius); width: 260px; flex: none; padding: 8px; min-height: 120px; }
.col.drop { outline: 2px dashed var(--accent); }
.col h2 { display: flex; justify-content: space-between; padding: 4px 6px; font-size: 13px; }
.lcard { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-bottom: 8px; cursor: grab; box-shadow: var(--shadow); }
.lcard.hot { border-color: var(--hot); }
.lcard { transition: opacity 150ms var(--ease-out); }
.lcard.saving { opacity: .6; }
.lcard .preview { color: var(--muted); font-size: 12px; margin: 6px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Tables */
table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--panel-2); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat b { display: block; font-size: 24px; } .stat span { color: var(--muted); font-size: 12px; }
dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--panel); color: var(--text); width: min(560px, calc(100vw - 32px)); padding: 20px; }
dialog::backdrop { background: rgba(0,0,0,.4); }
/* Dialog: fade + slight scale in from center, same path out. Browsers without @starting-style just open instantly. */
dialog { opacity: 0; transform: scale(0.96);
  transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out), overlay 200ms allow-discrete, display 200ms allow-discrete; }
dialog[open] { opacity: 1; transform: none; }
dialog::backdrop { opacity: 0; transition: opacity 200ms var(--ease-out), overlay 200ms allow-discrete, display 200ms allow-discrete; }
dialog[open]::backdrop { opacity: 1; }
@starting-style { dialog[open] { opacity: 0; transform: scale(0.96); } dialog[open]::backdrop { opacity: 0; } }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.keybox { background: var(--panel-2); padding: 10px; border-radius: 8px; word-break: break-all; }

#toast { position: fixed; bottom: 16px; left: 50%; transform: translate(-50%, calc(100% + 16px)); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity 400ms ease, transform 400ms ease; z-index: 50; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Responsive */
@media (max-width: 1200px) { .inbox { grid-template-columns: 280px 1fr; } .inbox .intel { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--border); } .inbox { grid-template-rows: 1fr auto; overflow-y: auto; } }
@media (max-width: 800px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .nav { position: fixed; inset: 0 30% 0 0; z-index: 40; box-shadow: var(--shadow);
    transform: translateX(-100%); visibility: hidden; transition: transform 300ms var(--ease-drawer), visibility 0s linear 300ms; }
  .nav.open { transform: translateX(0); visibility: visible; transition: transform 300ms var(--ease-drawer), visibility 0s; }
  .mobile-bar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--border); }
  .main > .content { padding: 16px; }
  .main.flush > .content { overflow: auto; }
  .mobile-only { display: inline-flex; }
  .inbox { grid-template-columns: 1fr; height: auto; }
  .inbox.has-lead .list { display: none; }
  .inbox:not(.has-lead) .thread, .inbox:not(.has-lead) .intel { display: none; }
  .list .items { max-height: none; }
  .thread { min-height: 70vh; }
  .grid2 { grid-template-columns: 1fr; }
  .msg { max-width: 88%; }
  table { display: block; overflow-x: auto; }
}
.list, .thread, .intel { min-width: 0; }
.list .filters select { min-width: 0; flex: 1; }
@media (max-width: 800px) { .inbox { grid-template-columns: minmax(0, 1fr); } }

/* Analytics */
.filterbar { margin-bottom: 16px; gap: 8px; }
.stat .ans { font-size: 15px; line-height: 1.3; margin: 4px 0 2px; overflow-wrap: anywhere; }
.hbars { display: grid; gap: 10px; }
.hbar { display: grid; grid-template-columns: 120px 1fr auto; gap: 10px; align-items: center; font-size: 13px; border-radius: 6px; padding: 2px 4px; }
.hbar:hover { background: var(--panel-2); }
.hbar-label { color: var(--muted); }
.hbar-track { height: 10px; background: transparent; border-radius: 4px; position: relative; }
.hbar-fill { display: block; height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; }
.hbar-val { font-weight: 600; min-width: 48px; text-align: right; white-space: nowrap; }
.thbtn { border: 0; background: none; padding: 0; cursor: pointer; color: inherit; font: inherit; font-weight: 600; }
.thbtn.on { color: var(--accent); }
.thumb { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; flex: none; }
.thumb.ph { background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 14px; }
label.check input { width: auto; }
@media (max-width: 800px) { .hbar { grid-template-columns: 90px 1fr auto; } }
#settings-form select { max-width: 320px; }

/* Sequences & approvals */
ol.steps { margin: 10px 0 0; padding-left: 20px; display: grid; gap: 8px; }
ol.steps li { padding-left: 4px; }
.approval-row { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--border); }
.approval-row:first-of-type { border-top: 0; }
.nav a .badge { margin-left: 6px; }
@media (max-width: 800px) { .approval-row { flex-direction: column; } }

/* Muse check schedule */
.banner { background: var(--hot-soft); color: var(--text); border-bottom: 1px solid var(--hot); padding: 8px 16px; font-size: 13px; }
.main.flush > .content { display: flex; flex-direction: column; }
.main.flush > .content > .inbox { flex: 1; min-height: 0; height: auto; }
#check-form [hidden] { display: none !important; }
details summary { cursor: pointer; color: var(--accent); }

/* "Need help?" Instagram banner (sidebar) */
.help-card { padding: 10px 0 2px; flex-shrink: 0; }
.nav a.help-banner { display: block; margin: 0 auto; padding: 0;
  /* Full sidebar width, but only as tall as the free space under the menu (shrinks evenly on short screens). */
  width: min(100%, calc(max(170px, 100vh - 500px) * 360 / 664)); background: none; border-radius: 16px; line-height: 0; transition: box-shadow .2s ease; }
.nav a.help-banner:hover { background: none; box-shadow: 0 8px 22px rgba(91, 76, 230, .30); }
.nav a.help-banner:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
/* Fixed box with the video's exact shape: nothing is ever cropped or stretched. */
.help-media { position: relative; display: block; width: 100%; aspect-ratio: 360 / 664; border-radius: 16px; overflow: hidden; background: #ddd6fb; }
.help-media img, .help-media video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.help-media video { opacity: 0; transition: opacity .15s ease; }
.help-banner.playing .help-media video { opacity: 1; }
.nav a.help-profile { display: block; padding: 8px 0 0; background: none; text-align: center; font-size: 11px; color: var(--muted); }
.nav a.help-profile:hover { background: none; color: var(--accent); }
@media (prefers-reduced-motion: reduce) { .nav a.help-banner, .help-media video { transition: none; } }

/* Public comments in the conversation */
.msg.comment { border: 1px dashed var(--accent); }
.msg-tag { font-size: 11px; font-weight: 600; color: var(--accent); margin-bottom: 4px; }
.msg-tag a { color: inherit; text-decoration: underline; }

/* v2: SaaS pages */
.banner.danger { background: var(--danger-soft); border-bottom-color: var(--danger); }
.alert { margin-bottom: 12px; }
.alert.ok { background: var(--ok-soft); border-color: var(--ok); }
.alert.danger { background: var(--danger-soft); border-color: var(--danger); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-top: 10px; }
.plan.current { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.plan .price { font-size: 20px; font-weight: 700; min-height: 26px; }
.plan ul { padding-left: 18px; line-height: 1.7; }
.usage-bar { height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.usage-bar span { display: block; height: 100%; background: var(--accent); }
.codes { display: grid; grid-template-columns: repeat(2, max-content); gap: 4px 24px; margin: 10px 0; font-size: 15px; }
.qr svg { width: 180px; height: 180px; background: #fff; border-radius: 8px; }
.composer { padding: 10px 12px; border-top: 1px solid var(--border); background: var(--panel); }
.composer textarea { min-height: 44px; }
.warn-text { color: var(--warn); }
.acct-switch { margin: 0 0 10px; }
label.check { display: flex; gap: 8px; align-items: flex-start; color: var(--text); font-size: 13px; }
label.check input { width: auto; margin-top: 2px; flex: none; }
@media (max-width: 900px) { .grid2 { grid-template-columns: minmax(0, 1fr); } }
[hidden] { display: none !important; }
.badge.fb { background: #e7f0ff; color: #1b5fd1; } .badge.ig { background: #fdeaf3; color: #c1306b; }
@media (prefers-color-scheme: dark) { .badge.fb { background: #13264a; color: #7fb0ff; } .badge.ig { background: #3a1427; color: #ff8fbf; } }
/* Checkbox labels with links/bold text: keep text flowing inline. */
label.check { display: block; padding-left: 24px; text-indent: -24px; line-height: 1.45; }
label.check input { margin: 0 8px 0 0; vertical-align: -2px; }

/* Reduced motion: keep the fades, drop the movement. */
@media (prefers-reduced-motion: reduce) {
  .btn, .btn:active { transform: none; transition: none; }
  dialog, dialog[open] { transform: none; }
  @starting-style { dialog[open] { transform: none; } }
  #toast, #toast.show { transform: translate(-50%, 0); transition: opacity 200ms ease; }
  .nav { transition: none !important; }
}
