/* chatmany UI — ManyChat-inspired. Blue #2d7ff9 accent, white cards on light-gray canvas,
   generous rounded corners, sentence case, no emoji in chrome. */

:root {
  --blue: #245dc7;
  --blue-dark: #184aab;
  --blue-soft: #eaf2ff;
  --canvas: #f3f5f9;
  --card: #ffffff;
  --ink: #1c2434;
  --ink-soft: #5b6472;
  --ink-faint: #626c7d;
  --line: #e7eaf0;
  --line-strong: #d6dbe4;
  --green: #146747;
  --amber: #805507;
  --red: #a8202e;
  --red-soft: #fdeef1;
  --red-line: #f0c9d1;
  /* analytics funnel bar shades: tapped, got the link (opened uses --blue-dark) */
  --bar-1: #b9cdf3;
  --bar-2: #6f97e0;
  --field-line: #858e9d;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(20, 30, 55, 0.06), 0 4px 16px rgba(20, 30, 55, 0.05);
  --sidebar-w: 244px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--canvas);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; }

/* ---------- layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--card);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.main { flex: 1; min-width: 0; padding: 26px 30px 60px; }
.main-wrap { max-width: 1120px; margin: 0 auto; }

/* ---------- brand + nav ---------- */
.brand { display: flex; align-items: center; gap: 9px; padding: 6px 8px 20px; }
.brand .spark {
  width: 26px; height: 26px; border-radius: 8px; background: var(--blue);
  display: grid; place-items: center; color: #fff;
}
.brand .spark svg { width: 15px; height: 15px; }
.brand .name { font-weight: 700; font-size: 17px; letter-spacing: -0.2px; }

.nav { display: flex; flex-direction: column; gap: 3px; }
.nav-secondary { display: contents; }
.nav .nav-more { display: none; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: var(--radius-sm);
  color: var(--ink-soft); font-weight: 550; cursor: pointer; border: 0; background: none;
  width: 100%; text-align: left; font-size: 14px;
}
.nav-item svg { width: 18px; height: 18px; opacity: 0.85; }
.nav-item:hover { background: #f5f7fb; color: var(--ink); }
.nav-item.active { background: var(--blue-soft); color: var(--blue-dark); }
.nav-item.active svg { opacity: 1; }

.sidebar-footer { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line); }
.profile { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.profile .avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: var(--line); }
.profile .who { min-width: 0; }
.profile .handle { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag { display: inline-block; font-size: 11px; color: var(--ink-faint); }
.gh-link { display: flex; align-items: center; gap: 7px; margin-top: 8px; padding: 7px 8px; color: var(--ink-soft); font-size: 13px; border-radius: var(--radius-sm); }
.gh-link:hover { background: #f5f7fb; }
.gh-link svg { width: 16px; height: 16px; }
.legal-links { display: flex; gap: 6px; padding: 4px 8px 0; font-size: 11.5px; color: var(--ink-faint); }
.legal-links a { color: var(--ink-faint); }
.legal-links a:hover { color: var(--ink-soft); text-decoration: underline; }

/* ---------- page header ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 16px; flex-wrap: wrap; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.page-title { font-size: 22px; letter-spacing: -0.3px; }
.page-sub { color: var(--ink-soft); margin-top: 3px; }

/* ---------- cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px; margin-bottom: 16px;
}
.card h3 { font-size: 15px; margin-bottom: 3px; }
.card .hint { color: var(--ink-soft); font-size: 13px; margin-bottom: 14px; }
.section-num { color: var(--ink-faint); font-weight: 700; margin-right: 6px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  padding: 9px 16px; border-radius: 10px; font-weight: 600; font-size: 14px;
  border: 1px solid transparent; cursor: pointer; background: #eef1f6; color: var(--ink);
}
.btn:hover { background: #e6eaf1; }
.btn.primary { background: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-dark); }
.btn.ghost { background: transparent; border-color: var(--line-strong); }
.btn.ghost:hover { background: #f5f7fb; }
.btn.danger { background: transparent; color: #d1435b; border-color: #f0c9d1; }
.btn.danger:hover { background: #fdeef1; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
:is(button, a, input, textarea, select, summary):focus-visible { outline: 2px solid var(--blue-dark); outline-offset: 3px; }
.btn.sm { padding: 6px 12px; font-size: 13px; }

/* ---------- form controls ---------- */
label.field { display: block; margin-bottom: 14px; }
.field .label { font-weight: 600; margin-bottom: 6px; display: block; }
input[type="text"], input[type="url"], input[type="password"], textarea, select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--field-line); border-radius: 10px;
  font: inherit; color: var(--ink); background: var(--card);
}
input:focus, textarea:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); }
textarea { resize: vertical; min-height: 66px; }

.radio-row { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px; border: 1px solid var(--line-strong); border-radius: 12px; cursor: pointer; margin-bottom: 8px; }
.radio-row.selected { border-color: var(--blue); background: var(--blue-soft); }
.radio-row.disabled { opacity: 0.55; cursor: not-allowed; }
.radio-dot { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line-strong); flex: 0 0 auto; margin-top: 1px; }
.radio-row.selected .radio-dot { border-color: var(--blue); background: radial-gradient(circle at center, var(--blue) 0 5px, #fff 6px); }
.radio-row .rr-title { font-weight: 600; }
.radio-row .rr-sub { color: var(--ink-soft); font-size: 13px; }
.trigger-choices { border: 0; padding: 0; margin: 0; min-inline-size: 0; }
.trigger-choices input { margin: 3px 0 0; accent-color: var(--blue); }

/* toggle */
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-top: 1px solid var(--line); }
.toggle-row:first-child { border-top: 0; }
.toggle-row .tr-title { font-weight: 600; }
.toggle-row .tr-sub { color: var(--ink-soft); font-size: 13px; }
.toggle-row.disabled { opacity: 0.55; }
.toggle-row.disabled .switch { cursor: not-allowed; }
.switch { position: relative; display: block; width: 44px; height: 44px; flex: 0 0 auto; cursor: pointer; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 10px 1px; background: #cdd4df; border-radius: 999px; transition: 0.15s; }
.switch .slider::before { content: ""; position: absolute; height: 18px; width: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: 0.15s; box-shadow: 0 1px 2px rgba(0,0,0,0.2); }
.switch input:checked + .slider { background: var(--blue); }
.switch input:checked + .slider::before { transform: translateX(18px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--blue-dark); outline-offset: 4px; }

.chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 8px; }
.chip { padding: 5px 11px; border-radius: 999px; background: #eef1f6; color: var(--ink-soft); font-size: 12px; cursor: pointer; border: 1px solid transparent; }
.chip:hover { background: var(--blue-soft); color: var(--blue-dark); }

/* media picker */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; margin-top: 6px; }
.media-thumb { position: relative; aspect-ratio: 1; padding: 0; border-radius: 10px; overflow: hidden; cursor: pointer; border: 2px solid transparent; background: var(--line); }
.media-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-thumb.selected { border-color: var(--blue); }
.media-thumb.selected::after { content: "✓"; position: absolute; top: 4px; right: 6px; color: #fff; background: var(--blue); border-radius: 50%; width: 18px; height: 18px; display: grid; place-items: center; font-size: 12px; }

/* ---------- builder + preview split ---------- */
.builder { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
.preview-col { position: sticky; top: 26px; }
@media (max-width: 940px) { .builder { grid-template-columns: 1fr; } .preview-col { position: static; } }

.builder-topbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.builder-topbar input.name { max-width: 320px; font-weight: 600; }
.builder-title { margin-bottom: 12px; }
.builder-actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.builder-feedback { margin: 0; color: var(--ink-soft); font-weight: 600; }
.builder-feedback:empty { height: 0; overflow: hidden; }
.builder-modes { display: none; }
.status-pill { padding: 4px 11px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.status-pill.live { background: #e4f7ee; color: var(--green); }
.status-pill.stopped { background: #eef1f6; color: var(--ink-soft); }

/* ---------- phone preview ---------- */
.phone { width: min(300px, 100%); background: #000; border-radius: 34px; padding: 10px; box-shadow: var(--shadow); margin: 0 auto; }
.phone-screen { background: #000; border-radius: 26px; overflow: hidden; color: #fff; }
.seg { display: flex; background: #111; border-radius: 10px; padding: 3px; margin: 10px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; color: #9aa0aa; font: inherit; font-size: 12px; font-weight: 600; padding: 6px; border-radius: 8px; cursor: pointer; }
.seg button.active { background: #2a2c31; color: #fff; }
.ig { padding: 0 12px 16px; min-height: 430px; }
.ig-top { display: flex; align-items: center; gap: 8px; padding: 8px 2px; }
.ig-top img { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; }
.ig-top .u { font-weight: 600; font-size: 13px; }
.ig-media { width: 100%; aspect-ratio: 1; border-radius: 8px; object-fit: cover; background: #222; display: block; }
.ig-actions { display: flex; gap: 14px; padding: 9px 2px; color: #fff; }
.ig-actions .heart.liked { color: #ed4956; }
.ig-caption { font-size: 12.5px; color: #eee; padding: 0 2px; }
.ig-caption .u { font-weight: 600; margin-right: 5px; }

.cmt { display: flex; gap: 8px; padding: 8px 2px; }
.cmt .av { width: 26px; height: 26px; border-radius: 50%; background: #444; flex: 0 0 auto; display: grid; place-items: center; font-size: 11px; color: #ccc; }
.cmt .body { font-size: 12.5px; }
.cmt .body .u { font-weight: 600; margin-right: 5px; }
.cmt .body .meta { color: #8a8f98; font-size: 11px; margin-top: 2px; }
.cmt.reply { margin-left: 30px; }

.dm { display: flex; flex-direction: column; gap: 8px; padding: 6px 2px; }
.bubble { max-width: 82%; padding: 9px 12px; border-radius: 16px; font-size: 12.5px; overflow-wrap: anywhere; }
.bubble.in { background: #262930; color: #fff; align-self: flex-start; border-bottom-left-radius: 5px; }
.bubble.out { background: var(--blue); color: #fff; align-self: flex-end; border-bottom-right-radius: 5px; }
/* DM text whose line breaks matter (opening versions, tracked link on its own line) */
.bubble.pre { white-space: pre-wrap; }
.dm-btn { align-self: flex-start; max-width: 82%; border: 1px solid #3a3d44; color: #6cb0ff; background: #1a1c20; border-radius: 16px; padding: 9px 12px; font-size: 12.5px; font-weight: 600; text-align: center; }
.qr { align-self: flex-end; display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.qr .pill { border: 1px solid var(--blue); color: #6cb0ff; border-radius: 999px; padding: 6px 12px; font-size: 12px; font-weight: 600; }
.dm-note { color: #8a8f98; font-size: 11px; text-align: center; padding: 2px; }
.dm-divider { color: #8a8f98; font-size: 11px; text-align: center; padding: 6px 2px 2px; display: flex; align-items: center; gap: 8px; }
.dm-divider::before, .dm-divider::after { content: ""; flex: 1; height: 1px; background: #3a3d44; }

/* ---------- health (every page) ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.health-dot { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--ink-soft); white-space: nowrap; }
.health-dot:empty { display: none; }
.health-light { width: 9px; height: 9px; border-radius: 50%; background: var(--line-strong); flex: 0 0 auto; }
.health-dot.ok .health-light { background: var(--green); }
.health-dot.red { color: var(--red); }
.health-dot.red .health-light { background: var(--red); }
.health-dot.amber { color: var(--amber); }
.health-dot.amber .health-light { background: var(--amber); }
.health-banners:empty { display: none; }
.health-banner { padding: 11px 15px; border-radius: 12px; margin-bottom: 12px; font-size: 13px; border: 1px solid; overflow-wrap: anywhere; }
.health-banner ul { margin: 0; padding-left: 18px; }
.health-banner li + li { margin-top: 4px; }
.health-banner a { color: inherit; text-decoration: underline; font-weight: 600; }
.health-banner.red { background: var(--red-soft); border-color: var(--red-line); color: var(--red); }
.health-banner.amber { background: #fdf3dd; border-color: #f0dca6; color: #7a5b12; }

/* ---------- analytics ---------- */
.analytics .page-head .btn { min-height: 44px; }
.an-controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 20px; margin-bottom: 8px; }
.an-range { display: flex; flex-wrap: wrap; gap: 4px; border: 0; margin: 0; padding: 0; min-inline-size: 0; }
.an-range legend { width: 100%; padding: 0; margin-bottom: 4px; font-size: .8125rem; font-weight: 600; color: var(--ink-soft); }
.an-range label { position: relative; }
.an-range input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.an-range span { display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--card); font-weight: 600; color: var(--ink-soft); }
.an-range input:checked + span { background: var(--blue-soft); border-color: var(--blue); color: var(--blue-dark); }
.an-range input:focus-visible + span { outline: 2px solid var(--blue-dark); outline-offset: 3px; }
.an-select { display: grid; gap: 4px; font-size: .8125rem; font-weight: 600; color: var(--ink-soft); min-width: 0; }
.an-select select { width: auto; max-width: 100%; min-height: 44px; }
.an-note { margin: 4px 0; color: var(--ink-soft); font-size: 13px; }
#an-body { margin-top: 14px; }
.an-panel h2 { font-size: 16px; margin-bottom: 3px; }
.an-small { display: block; color: var(--ink-soft); font-size: 12px; font-weight: 400; }
.an-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 0 0 16px; }
.an-kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.an-kpi dt { color: var(--ink-soft); font-size: 13px; font-weight: 600; }
.an-kpi dd { margin: 4px 0 0; overflow-wrap: anywhere; }
.an-kpi-num { display: block; font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.an-kpi small { display: block; color: var(--ink-soft); font-size: 12px; margin-top: 2px; }
.an-change { display: block; font-size: 12px; margin-top: 4px; color: var(--ink-soft); }
.an-change.up { color: var(--green); }
.an-main { border-color: var(--line-strong); padding: 22px 24px; }
.an-main h2 { font-size: 19px; }
.an-table { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: auto; }
.an-table th, .an-table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
.an-table thead th { font-size: 12px; color: var(--ink-soft); font-weight: 600; }
.an-table td.num { font-weight: 650; font-variant-numeric: tabular-nums; }
.an-table tbody th { font-weight: 600; }
.an-kw { font-weight: 650; font-size: 14px; }
.an-sort { border: 0; background: none; padding: 6px 0; min-height: 32px; font: inherit; font-weight: 600; color: var(--blue-dark); cursor: pointer; text-align: left; }
.an-sort:hover { text-decoration: underline; }
.muted-row { color: var(--ink-soft); }
.muted-row .an-bar-track { opacity: .6; }
.an-tag { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; vertical-align: middle; }
.an-tag.best { background: #e4f7ee; color: var(--green); }
.an-bar { min-width: 110px; }
.an-bar-track { position: relative; height: 16px; background: var(--line); border-radius: 6px; overflow: hidden; }
.an-seg { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 6px; }
.an-seg.tapped { background: var(--bar-1); }
.an-seg.got { background: var(--bar-2); }
.an-seg.opened { background: var(--blue-dark); }
.an-vgroup + .an-vgroup { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.an-vgroup h3 { font-size: 14px; }
.an-verdict { margin: 2px 0 10px; color: var(--ink-soft); font-size: 13px; }
.an-versions { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); gap: 10px; }
.an-version { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; min-width: 0; }
.an-version h4 { font-size: 13.5px; }
.an-excerpt { margin: 6px 0 10px; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
.an-version dl, .an-facts { margin: 0; display: grid; gap: 6px; }
.an-version dl div, .an-facts div { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.an-version dt, .an-facts dt { color: var(--ink-soft); }
.an-version dd, .an-facts dd { margin: 0; font-weight: 600; text-align: right; overflow-wrap: anywhere; }
.an-facts { margin-top: 14px; }
.an-facts.grid { grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); gap: 12px; }
.an-facts.grid div { display: block; }
.an-facts.grid dd { text-align: left; font-size: 20px; font-variant-numeric: tabular-nums; }
.an-facts small { display: block; font-size: 12px; font-weight: 400; color: var(--ink-soft); }
.an-step-top { display: flex; justify-content: space-between; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.an-step-track { height: 22px; background: var(--line); border-radius: 8px; overflow: hidden; }
.an-step-track div { height: 100%; background: var(--blue); border-radius: 8px; }
.an-loss { margin: 6px 0 12px 12px; padding-left: 10px; border-left: 2px solid var(--line-strong); font-size: 13px; color: var(--ink-soft); }
.an-hours, .an-days { display: flex; align-items: flex-end; gap: 2px; height: 90px; margin-top: 8px; }
.an-days.dense { gap: 0; }
.an-hour, .an-day { flex: 1 1 0; min-width: 0; height: 100%; display: flex; align-items: flex-end; background: var(--canvas); border-radius: 3px 3px 0 0; }
.an-hour span, .an-day span { display: block; width: 100%; background: var(--blue); border-radius: 3px 3px 0 0; min-height: 1px; }
.an-hour-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--ink-soft); margin-top: 4px; }
.an-sub { font-size: 14px; margin-top: 18px; }
.an-details summary { min-height: 44px; padding: 12px 0; color: var(--blue-dark); font-weight: 600; cursor: pointer; width: fit-content; }
.an-list { columns: 3 140px; margin: 0; padding-left: 18px; font-size: 13px; }
.an-problems { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.an-problems li { display: flex; gap: 12px; align-items: baseline; }
.an-pnum { min-width: 3ch; font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; }
@media (max-width: 860px) { .an-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 720px) {
  .an-main { padding: 14px; }
  .an-table, .an-table tbody, .an-table tr, .an-table th, .an-table td { display: block; width: 100%; }
  .an-table thead tr { display: flex; flex-wrap: wrap; gap: 0 14px; border-bottom: 1px solid var(--line); }
  .an-table thead th { display: block; width: auto; border: 0; padding: 0; }
  .an-table thead th[aria-sort] { display: block; }
  .an-table thead th:not([aria-sort]) { display: none; }
  .an-sort { min-height: 44px; }
  .an-table tbody tr { padding: 10px 0; border-bottom: 1px solid var(--line); }
  .an-table tbody th, .an-table td { border: 0; padding: 3px 0; }
  .an-table td::before { content: attr(data-label); display: block; font-size: 11.5px; color: var(--ink-soft); font-weight: 600; }
  .an-range { width: 100%; }
  .an-range label { flex: 1 1 0; min-width: 0; }
  .an-range span { width: 100%; justify-content: center; padding: 0 4px; }
  .an-select, .an-select select { width: 100%; }
}
@media (max-width: 400px) { .an-kpis { grid-template-columns: minmax(0, 1fr); } }

/* ---------- contacts ---------- */
.contact-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(100px, .85fr) minmax(68px, .55fr) minmax(0, 1.2fr) minmax(80px, .6fr); gap: 12px; align-items: center; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px; background: var(--card); overflow-wrap: anywhere; }
.contact-row .who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.contact-row .av { width: 30px; height: 30px; border-radius: 50%; background: var(--line); display: grid; place-items: center; font-size: 12px; color: var(--ink-soft); flex: 0 0 auto; }
.contact-row .uname { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; display: inline-block; }
.pill.done { background: #e4f7ee; color: var(--green); }
.pill.wait { background: #fdf3dd; color: var(--amber); }
.pill.open { background: var(--blue-soft); color: var(--blue-dark); }
.muted { color: var(--ink-faint); }
.dash { color: var(--line-strong); }
.narrow-label { display: none; }

/* ---------- misc ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.spacer { flex: 1; }
.empty { text-align: center; color: var(--ink-soft); padding: 40px 20px; }
.empty svg { width: 40px; height: 40px; opacity: 0.4; margin-bottom: 10px; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; font-weight: 550; box-shadow: var(--shadow); opacity: 0; transition: opacity 0.2s, transform 0.2s; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.toast.err { background: #d1435b; }
.banner { background: #fdf3dd; border: 1px solid #f0dca6; color: #7a5b12; padding: 11px 15px; border-radius: 12px; margin-bottom: 16px; font-size: 13px; }
.banner a { color: #7a5b12; text-decoration: underline; font-weight: 600; }
.select-inline { display: inline-flex; align-items: center; gap: 8px; }
.select-inline select { width: auto; }

/* ---------- automations list ---------- */
.automations-toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.automations-toolbar select { width: auto; }
.folder-btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 9px 14px; border-radius: 10px;
  border: 1.5px dashed var(--line-strong); color: var(--blue); font-weight: 600; font-size: 13px;
  background: transparent; cursor: pointer;
}
.folder-btn:hover { background: var(--blue-soft); }
.auto-list-head {
  display: grid; grid-template-columns: 26px 1fr 90px 70px 110px; gap: 12px; align-items: center;
  padding: 0 16px 8px; color: var(--ink-faint); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em;
}
.auto-row {
  display: grid; grid-template-columns: 26px 1fr 90px 70px 110px; gap: 12px; align-items: center;
  padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 8px;
  background: var(--card); transition: border-color 0.1s;
}
.auto-row:hover { border-color: var(--line-strong); box-shadow: var(--shadow); }
.auto-row input[type="checkbox"] { width: 16px; height: 16px; }
.auto-check { display: grid; min-height: 44px; place-items: center; cursor: pointer; }
.auto-open { max-width: 100%; border: 0; background: transparent; padding: 9px 0; color: var(--blue-dark); text-align: left; cursor: pointer; }
.auto-open:hover { text-decoration: underline; }
.auto-row .auto-name-cell { min-width: 0; }
.auto-row .auto-name-line { display: flex; align-items: center; gap: 9px; margin-bottom: 4px; }
.auto-row .auto-name { font-weight: 650; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.auto-row .auto-trigger { display: flex; align-items: center; gap: 6px; color: var(--ink-soft); font-size: 12.5px; }
.auto-row .auto-trigger img { width: 18px; height: 18px; border-radius: 4px; object-fit: cover; flex: 0 0 auto; }
.auto-row .auto-trigger .kw-pill { background: var(--blue-soft); color: var(--blue-dark); padding: 1px 8px; border-radius: 999px; font-weight: 600; }
.auto-row .num { font-weight: 600; }
.auto-row .num-sub { color: var(--ink-faint); font-size: 11px; }
.auto-row.selected { border-color: var(--blue); background: var(--blue-soft); }

/* Archive tab: same row shape as Automations, but the middle stat columns are replaced with a
   wider actions slot (Restore/Delete need more room than the Runs/CTR numbers they stand in for). */
#archlist .auto-list-head, .archived-row { grid-template-columns: 26px 1fr 0 170px 110px; }
.archive-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* search box with a leading icon */
.search-wrap { position: relative; flex: 1; min-width: 200px; max-width: 340px; display: flex; align-items: center; }
.search-wrap svg { position: absolute; left: 12px; width: 16px; height: 16px; color: var(--ink-faint); pointer-events: none; }
.search-wrap input.search { padding-left: 36px; max-width: none; }

/* row 2: New folder (left) + Trash (right); row 3: View as grid (right) */
.automations-row2 { display: flex; align-items: center; margin-bottom: 6px; }
.automations-row3 { display: flex; justify-content: flex-end; margin-bottom: 16px; }
.trash-link, .grid-link {
  display: inline-flex; align-items: center; gap: 6px; margin-left: auto; padding: 7px 10px;
  color: var(--ink-soft); font-size: 13px; font-weight: 600; background: none; border: 0; border-radius: var(--radius-sm); cursor: pointer;
}
.trash-link svg, .grid-link svg { width: 15px; height: 15px; }
.trash-link:hover, .grid-link:hover { background: #f5f7fb; color: var(--ink); }

/* bulk selection bar */
.bulk-bar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; margin-bottom: 8px;
  background: var(--blue-soft); border: 1px solid var(--blue); border-radius: 12px; font-weight: 600; font-size: 13px; color: var(--blue-dark);
}
.bulk-bar .btn.danger { background: #fdeef1; border-color: #f0c9d1; }
.bulk-bar .btn svg { width: 14px; height: 14px; }

/* ---------- phone: iOS status bar ---------- */
.ios-status { display: flex; align-items: center; justify-content: space-between; padding: 8px 18px 2px; font-size: 13px; font-weight: 600; color: #fff; }
.ios-status .time { min-width: 40px; }
.ios-status .icons { display: flex; align-items: center; gap: 4px; }
.ios-status .bars { display: flex; align-items: flex-end; gap: 1.5px; height: 9px; }
.ios-status .bars span { width: 2.5px; background: #fff; border-radius: 1px; }
.ios-status .bars span:nth-child(1) { height: 40%; }
.ios-status .bars span:nth-child(2) { height: 60%; }
.ios-status .bars span:nth-child(3) { height: 80%; }
.ios-status .bars span:nth-child(4) { height: 100%; }
.ios-status .battery { width: 22px; height: 11px; border: 1.3px solid #fff; border-radius: 3px; position: relative; margin-left: 2px; }
.ios-status .battery::after { content: ""; position: absolute; right: -3px; top: 3px; width: 2px; height: 5px; background: #fff; border-radius: 0 1px 1px 0; }
.ios-status .battery::before { content: ""; position: absolute; inset: 1.5px; background: #fff; border-radius: 1px; width: 80%; }

/* ---------- phone: post tab stats + caption toggle ---------- */
.ig-stats { font-size: 12.5px; font-weight: 600; color: #fff; padding: 2px 2px 4px; }
.ig-caption-toggle { display: inline-flex; align-items: center; min-height: 44px; padding: 0 2px; border: 0; background: transparent; color: #9ba3af; font: inherit; font-weight: 600; cursor: pointer; }
.ig-caption-toggle:hover { color: #fff; }

/* ---------- phone: comments sheet ---------- */
.sheet { background: #1c1e22; border-radius: 18px 18px 0 0; margin-top: -6px; padding-top: 8px; min-height: 380px; display: flex; flex-direction: column; }
.sheet-handle { width: 36px; height: 4px; background: #4a4d54; border-radius: 999px; margin: 0 auto 10px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 0 14px 10px; border-bottom: 1px solid #2a2c31; font-weight: 700; font-size: 13.5px; }
.sheet-body { flex: 1; padding: 4px 14px; }
.sheet-emojis { display: flex; justify-content: space-between; padding: 8px 14px; font-size: 17px; }
.sheet-input-row { display: flex; align-items: center; gap: 8px; padding: 8px 14px 14px; }
.sheet-input-row .av { width: 24px; height: 24px; border-radius: 50%; background: #444; flex: 0 0 auto; object-fit: cover; }
.sheet-input-row .fake-input { flex: 1; background: #2a2c31; color: #6b7078; border-radius: 999px; padding: 8px 14px; font-size: 12.5px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 30px 28px; }
.login-card .brand { justify-content: center; padding-bottom: 8px; }
.login-card h2 { text-align: center; margin-bottom: 4px; }
.login-card p { text-align: center; color: var(--ink-soft); margin: 0 0 20px; }
.connect-box { text-align: center; padding: 8px 0 4px; }
.connect-box .ig-avatar { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; margin: 0 auto 10px; display: block; background: var(--line); }

/* ---------- connect gate (automations locked until Instagram is connected) ---------- */
.gate-wrap { display: grid; place-items: center; min-height: 55vh; padding: 20px; }
.gate-card { width: 100%; max-width: 420px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 34px 30px; text-align: center; }
.gate-icon { width: 52px; height: 52px; margin: 0 auto 14px; border-radius: 50%; background: var(--line); display: grid; place-items: center; color: var(--ink-soft); }
.gate-icon svg { width: 24px; height: 24px; }
.gate-card h2 { margin-bottom: 6px; }
.gate-card p { color: var(--ink-soft); margin: 0 0 18px; }
.gate-card .btn { display: inline-block; text-decoration: none; }
.gate-hint { font-size: 12.5px; margin-top: 14px; margin-bottom: 0 !important; }

/* Post analytics */
.posts-view { --post-rule: #d9e0e8; }
.posts-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin: 14px 0 30px; }
.posts-head h1 { font-size: clamp(2rem, 1.4rem + 2vw, 3rem); line-height: 1.08; letter-spacing: -0.055em; }
.posts-head p { max-width: 53ch; margin: 9px 0 0; color: var(--ink-soft); }
.posts-head .btn { min-height: 44px; flex-shrink: 0; }
.posts-toolbar { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 12px 16px; margin-bottom: 14px; }
.posts-toolbar label { display: grid; gap: 4px; font-size: .8125rem; font-weight: 600; color: var(--ink-soft); }
.posts-toolbar select { width: auto; min-height: 44px; }
.posts-totals { display: flex; flex-wrap: wrap; gap: 16px 38px; margin: 6px 0 14px; padding: 8px 0 16px; }
.posts-totals[hidden] { display: none; }
.posts-totals > div { min-width: 0; }
.posts-totals dt { color: var(--ink-soft); font-size: .8125rem; }
.posts-totals dd { margin: 2px 0 0; font-size: clamp(1.4rem, 1.2rem + .75vw, 1.85rem); font-weight: 650; line-height: 1.2; font-variant-numeric: tabular-nums; }
:is(.post-metrics, .posts-totals) small { display: block; margin-top: 3px; font-size: .75rem; font-weight: 400; color: var(--ink-soft); }
#posts-count { color: var(--ink-soft); margin: 0 0 12px auto; }
#posts-list { border-top: 1px solid var(--post-rule); }
.post-row { display: grid; grid-template-columns: minmax(0, 1.12fr) minmax(0, 1fr); gap: 12px 24px; padding: 20px 0; border-bottom: 1px solid var(--post-rule); }
.post-summary { display: grid; grid-template-columns: 76px minmax(0, 1fr); align-items: start; gap: 14px; }
.post-image { display: grid; place-items: center; aspect-ratio: 1; overflow: hidden; border-radius: var(--radius-sm); background: var(--blue-soft); color: var(--blue); }
.post-image img { width: 100%; height: 100%; object-fit: cover; }
.post-image svg { width: 24px; }
.post-meta { display: flex; flex-wrap: wrap; gap: 0 6px; color: var(--ink-soft); font-size: .8125rem; }
.post-hook { margin: 4px 0; font-size: 1.0625rem; line-height: 1.3; overflow-wrap: anywhere; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
.post-actions { display: flex; flex-wrap: wrap; column-gap: 14px; }
.post-actions a, .post-build { display: inline-flex; align-items: center; min-height: 44px; padding: 0; background: none; border: 0; color: var(--blue-dark); font: inherit; font-size: .8125rem; font-weight: 600; cursor: pointer; }
.post-actions :is(a, button):hover { text-decoration: underline; }
.post-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-self: center; gap: 10px 8px; margin: 0; }
.post-metrics div { display: grid; }
.post-metrics dt { grid-row: 2; color: var(--ink-soft); font-size: .75rem; }
.post-metrics dd { margin: 0; font-size: 1.25rem; font-weight: 650; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.post-caption { grid-column: 1 / -1; }
:is(.post-caption, .posts-definitions) summary { width: fit-content; min-height: 44px; padding: 12px 0; color: var(--blue-dark); font-weight: 600; cursor: pointer; }
.post-caption p { margin: 8px 0 0; max-width: 70ch; white-space: pre-wrap; overflow-wrap: anywhere; }
.posts-definitions { margin-top: 16px; color: var(--ink-soft); max-width: 70ch; }
.posts-empty { margin: 0; padding: 24px 0; color: var(--ink-soft); }

@media (max-width: 980px) {
  .layout { display: block; }
  .sidebar { width: 100%; height: auto; position: static; border-right: 0; border-bottom: 1px solid var(--line); padding: 6px 16px 10px; }
  .brand { padding-bottom: 6px; }
  .nav { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 4px; }
  .nav-item { justify-content: center; min-height: 44px; text-align: center; padding: 6px; }
  .sidebar-footer { margin-top: 8px; padding-top: 6px; display: flex; align-items: center; flex-wrap: wrap; gap: 2px 8px; }
  .gh-link, .legal-links { margin-top: 0; }
}

@media (min-width: 681px) and (max-width: 800px) {
  .nav-item { flex-direction: column; gap: 3px; font-size: .8125rem; }
}

@media (max-width: 680px) {
  .layout {
    --phone-nav-height: 60px;
    --phone-bottom: calc(var(--phone-nav-height) + env(safe-area-inset-bottom, 0px));
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
  }
  .main { padding: 16px 16px calc(var(--phone-bottom) + 24px); }
  .sidebar { padding: 13px 16px 12px; }
  .sidebar > .brand { padding: 0; }
  .sidebar-footer { margin: 8px 0 0; padding: 0; border: 0; }
  .sidebar-footer .profile { padding: 0; }
  .sidebar-footer .profile .avatar { width: 22px; height: 22px; }
  .sidebar-footer .tag { display: none; }
  .sidebar-footer .gh-link { display: none; }
  .sidebar-footer .legal-links { margin-left: auto; padding: 0; }
  .sidebar-footer .legal-links a { display: inline-flex; align-items: center; min-height: 44px; }
  .nav {
    position: fixed;
    inset: auto 0 0;
    z-index: 20;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 2px;
    padding: 4px max(6px, env(safe-area-inset-right, 0px)) calc(4px + env(safe-area-inset-bottom, 0px)) max(6px, env(safe-area-inset-left, 0px));
    background: var(--card);
    border-top: 1px solid var(--line);
  }
  .nav-item { flex-direction: column; min-height: 51px; font-size: .6875rem; line-height: 1.15; gap: 3px; padding: 4px 1px; }
  .nav-item svg { flex: 0 0 18px; }
  .nav-item span { max-width: 100%; overflow-wrap: anywhere; }
  .nav .nav-more { display: flex; }
  .nav-secondary { display: none; }
  .nav-more[aria-expanded="true"] + .nav-secondary {
    position: absolute;
    display: grid;
    right: max(10px, env(safe-area-inset-right, 0px));
    bottom: calc(100% + 8px);
    width: min(235px, calc(100% - 20px));
    gap: 3px;
    padding: 6px;
    background: var(--card);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
  }
  .nav-secondary .nav-item { flex-direction: row; justify-content: flex-start; gap: 11px; padding: 8px 12px; font-size: .9375rem; }
  .layout:has(:is(input:not([type=checkbox]):not([type=radio]), textarea):focus) .nav { visibility: hidden; }
  .toast { bottom: calc(73px + env(safe-area-inset-bottom, 0px)); width: max-content; max-width: calc(100% - 32px); }
  .posts-head { align-items: flex-start; flex-direction: column; gap: 15px; margin-bottom: 20px; }
  .posts-head .btn { width: 100%; }
  .posts-toolbar label { flex: 1 1 120px; min-width: 0; }
  .posts-toolbar select { width: 100%; min-width: 0; }
  .posts-totals { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  #posts-count { margin: 0; flex-basis: 100%; }
  .post-row { display: block; padding: 16px 0 6px; }
  .post-summary { grid-template-columns: 64px minmax(0, 1fr); gap: 10px; }
  .post-metrics { margin: 8px 0 4px; padding: 10px 0; border-top: 1px solid var(--post-rule); grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .builder { grid-template-columns: minmax(0, 1fr); }
  .builder-modes { display: flex; gap: 3px; margin: 0 0 14px; padding: 3px; background: var(--line); border-radius: var(--radius-sm); }
  .builder-modes button { flex: 1; min-height: 44px; border: 0; border-radius: 7px; color: var(--ink-soft); background: transparent; font: inherit; font-weight: 600; cursor: pointer; }
  .builder-modes button[aria-pressed="true"] { color: var(--ink); background: var(--card); }
  .builder[data-mode="edit"] .preview-col, .builder[data-mode="preview"] .sections { display: none; }
  .builder-topbar { gap: 8px; }
  .builder-topbar .spacer { display: none; }
  .builder-topbar input.name { max-width: none; }
  .builder-actions {
    position: fixed;
    inset: auto 0 var(--phone-bottom);
    z-index: 19;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 8px;
    padding: 8px 16px;
    background: var(--card);
    border-top: 1px solid var(--line);
  }
  .builder-actions .btn { min-height: 44px; }
  .builder-feedback { grid-column: 1 / -1; }
  .builder-feedback:empty { position: absolute; }
  .main:has(.builder-actions) { padding-bottom: calc(var(--phone-bottom) + 118px); }
  .layout:has(:is(input:not([type=checkbox]):not([type=radio]), textarea):focus) .builder-actions { position: static; width: 100%; padding: 0; border: 0; background: transparent; }
  :is(input[type="text"], input[type="url"], input[type="password"], input.name, textarea, select) { font-size: 16px; }
  .ig-caption-toggle { font-size: inherit; }
  .builder-topbar select, .select-inline select { max-width: 100%; min-width: 0; }
  .select-inline, .toolbar { min-width: 0; max-width: 100%; }
  .select-inline > span { flex-shrink: 0; }
  .card { padding: 14px; }
  .auto-list-head, #archlist .auto-list-head { display: none; }
  .auto-row, .archived-row { grid-template-columns: 44px minmax(0, 1fr); gap: 7px 9px; padding: 12px; }
  .auto-row > :nth-child(n+3) { grid-column: 2; }
  .narrow-label { display: inline; color: var(--ink-soft); }
  .auto-row .auto-trigger, .bulk-bar, .archive-actions { flex-wrap: wrap; }
  .archive-actions { justify-content: flex-start; }
}

/* Keep the app clear of the notch in either orientation. */
@media (max-width: 980px) {
  .sidebar, .main, .login-wrap {
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
  }
  .sidebar { padding-top: max(12px, env(safe-area-inset-top, 0px)); }
  .login-wrap { padding-top: max(20px, env(safe-area-inset-top, 0px)); padding-bottom: max(20px, env(safe-area-inset-bottom, 0px)); }
}

@media (max-width: 720px) {
  .contact-row { grid-template-columns: minmax(0, 1fr) auto; gap: 6px 8px; overflow-wrap: anywhere; }
  .contact-detail { grid-column: 1 / -1; }
  .contact-detail .narrow-label { display: inline; margin-right: 4px; }
}

@media (max-width: 360px) {
  .nav > .nav-item, .nav .nav-more { font-size: .625rem; }
}

@media (pointer: coarse) {
  .btn, .auto-open, .chip, .seg button { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .toast, .switch .slider, .switch .slider::before { transition: none; }
}
