/* Visual conventions taken from the ManyChat web app references (see docs/ui-references.md):
   narrow icon rail, light grey canvas, white cards, blue primary, small uppercase status tags,
   two-pane builder with a phone preview and a Post/Comments/DM segmented control. */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f7f7f8;
  --border: #e3e5e8;
  --text: #1d1f23;
  --muted: #6b7079;
  --primary: #0a6cf0;
  --primary-hover: #0659c8;
  --danger: #e0322b;
  --danger-bg: #fdecec;
  --ok: #1e8e3e;
  --ok-bg: #e6f4ea;
  --warn: #b26a00;
  --warn-bg: #fff4e0;
  --sim: #6941c6;
  --sim-bg: #f1ecfd;
  --radius: 8px;
  --rail: 64px;
  font-family: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); min-height: 100vh; }
a { color: var(--primary); text-decoration: none; }
code { font-size: 12px; background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; }
.row.between { justify-content: space-between; }
.pre { white-space: pre-wrap; }

/* Top notices (ManyChat shows a thin notice strip above the app) */
.topbar { padding: 8px 16px; font-size: 13px; text-align: center; border-bottom: 1px solid var(--border); background: var(--surface); }
.topbar a { margin-left: 6px; font-weight: 600; }
.topbar--danger { background: var(--danger-bg); color: #8a1c17; }
.topbar--sim { background: var(--sim-bg); color: #3e2481; }

/* Shell: icon rail + main */
.shell { display: flex; min-height: 100vh; }
.rail { width: var(--rail); flex: 0 0 var(--rail); background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; align-items: center; padding: 12px 0; gap: 6px; position: sticky; top: 0; height: 100vh; }
.rail__logo { width: 32px; height: 32px; border-radius: 8px; background: var(--text); color: #fff; font-weight: 800; display: grid; place-items: center; font-size: 16px; margin-bottom: 8px; }
.rail__avatar { width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg, #f58529, #dd2a7b 50%, #8134af); color: #fff; font-weight: 700; display: grid; place-items: center; font-size: 13px; margin-bottom: 10px; }
.rail__item { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 8px; color: #4a4f57; background: none; border: 0; cursor: pointer; position: relative; }
.rail__item:hover, .rail__item.is-active { background: #e9ebee; color: var(--text); }
.rail__label { position: absolute; left: 48px; background: #1d1f23; color: #fff; font-size: 12px; padding: 4px 8px; border-radius: 6px; white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .1s; z-index: 10; }
.rail__item:hover .rail__label, .rail__item:focus-visible .rail__label { opacity: 1; }
.rail__bottom { margin-top: auto; }
.main { flex: 1; min-width: 0; }

.pagebar { height: 56px; display: flex; align-items: center; gap: 12px; padding: 0 24px; border-bottom: 1px solid var(--border); background: var(--surface); }
.pagebar h1 { font-size: 20px; font-weight: 700; }
.content { max-width: 1040px; margin: 0 auto; padding: 24px; }
.content__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0 16px; flex-wrap: wrap; }
.content__head h2 { font-size: 20px; }
.section-title { font-size: 15px; margin: 24px 0 10px; }
.flash { margin: 12px 24px 0; padding: 10px 14px; border-radius: var(--radius); font-size: 13px; }
.flash--ok { background: var(--ok-bg); color: #145c29; }
.flash--error { background: var(--danger-bg); color: #8a1c17; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 6px; font: inherit; font-weight: 600; font-size: 13px; cursor: pointer; border: 1px solid transparent; white-space: nowrap; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn--secondary { background: var(--surface); color: var(--text); border-color: #cfd3d8; }
.btn--secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn--ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger-outline { background: var(--surface); color: var(--danger); border-color: #f3b4b0; }
.btn--block { width: 100%; }
.icon-btn { border: 0; background: none; cursor: pointer; font-size: 16px; color: var(--muted); }
.link { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }

/* Inputs */
.label { display: block; font-size: 12px; font-weight: 600; margin: 12px 0 6px; color: #3b3f45; }
.input { width: 100%; height: 36px; border: 1px solid #cfd3d8; border-radius: 6px; padding: 0 10px; font: inherit; background: #fff; color: var(--text); }
.input:focus { outline: 2px solid #b6d3fb; border-color: var(--primary); }
.textarea { height: auto; padding: 10px; resize: vertical; line-height: 1.45; }
.field-error { color: var(--danger); font-size: 12px; margin: 6px 0 0; }
.check { display: flex; gap: 8px; align-items: center; margin: 10px 0 4px; font-size: 13px; }
.search { display: flex; align-items: center; gap: 8px; width: 280px; max-width: 100%; height: 34px; border: 1px solid #cfd3d8; border-radius: 6px; padding: 0 10px; background: #fff; color: var(--muted); margin-bottom: 16px; }
.search input { border: 0; outline: 0; font: inherit; flex: 1; min-width: 0; }

/* Status tags (ManyChat: small uppercase LIVE / STOPPED) and chips */
.tag { display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: .04em; padding: 2px 6px; border-radius: 4px; background: #eceef1; color: #5c6168; vertical-align: middle; }
.tag--live { background: var(--danger); color: #fff; }
.tag--sim { background: var(--sim-bg); color: var(--sim); }
.chip { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.chip--ok { background: var(--ok-bg); color: var(--ok); }
.chip--err { background: var(--danger-bg); color: var(--danger); }
.chip--warn { background: var(--warn-bg); color: var(--warn); }
.chip--wait { background: #e8f0fe; color: #1a56c4; }
.chip--sim { background: var(--sim-bg); color: var(--sim); }
.chip--muted { background: #eceef1; color: #5c6168; }
.pill { display: inline-flex; gap: 6px; align-items: center; border: 1px solid #c9dcfb; background: #eef4ff; color: #1a56c4; border-radius: 999px; padding: 2px 10px; font: inherit; font-size: 12px; cursor: pointer; margin-right: 4px; }
.pill.is-on { background: var(--primary); color: #fff; border-color: var(--primary); }
.pill.is-on .muted { color: #dce8ff; }

/* Tables (ManyChat automation list: white rows on grey) */
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--border); }
.table td { padding: 12px 14px; border-bottom: 1px solid #f0f1f3; vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; }
.table .clip { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-link { color: var(--text); display: inline-flex; align-items: center; gap: 8px; }
.row-name { font-weight: 600; }
.row-link:hover .row-name { color: var(--primary); }
.thumb { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; background: #e9ebee; display: block; }
.thumb--xs { width: 36px; height: 36px; border-radius: 4px; }
.thumb--md { width: 72px; height: 90px; margin: 8px 0; }
.thumb--empty { border: 1px dashed #c9cdd2; }
.empty { background: var(--surface); border: 1px dashed #cfd3d8; border-radius: var(--radius); padding: 28px; text-align: center; margin-bottom: 16px; }
.empty--card { border-style: solid; }
.filters { display: flex; flex-wrap: wrap; gap: 4px; margin: 12px 0; }
.tabs { display: flex; gap: 20px; }
.tabs a { color: var(--muted); padding: 6px 0; border-bottom: 2px solid transparent; font-weight: 600; }
.tabs a.is-on { color: var(--text); border-color: var(--primary); }
.tabs--page { border-bottom: 1px solid var(--border); margin-bottom: 8px; }

/* Builder: left panel + preview (ManyChat Quick Automation) */
.builder { display: flex; min-height: calc(100vh - 0px); }
.builder__panel { width: 380px; flex: 0 0 380px; background: var(--surface); border-right: 1px solid var(--border); padding: 16px 20px 32px; overflow-y: auto; max-height: 100vh; position: sticky; top: 0; }
.builder__title { font-size: 18px; font-weight: 700; margin: 22px 0 10px; }
.builder__actions { margin-top: 20px; display: flex; gap: 8px; }
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-size: 13px; }
.opt-card { display: block; background: var(--surface-2); border: 1px solid transparent; border-radius: var(--radius); padding: 12px; margin-bottom: 8px; cursor: default; }
label.opt-card { cursor: pointer; }
.opt-card.is-selected { border-color: #e1e3e6; }
.opt-card__head { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 8px; }
.opt-card input[type=radio] { accent-color: var(--primary); width: 16px; height: 16px; margin: 0; }
.radio { width: 16px; height: 16px; border-radius: 50%; border: 2px solid #b8bdc4; display: inline-block; }
.radio.is-on { border: 5px solid var(--primary); }
.media-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 8px; min-height: 40px; }
.media-strip button, .media-grid button { border: 2px solid transparent; padding: 0; border-radius: 6px; background: none; cursor: pointer; overflow: hidden; }
.media-strip button.is-selected, .media-grid button.is-selected { border-color: var(--primary); }
.media-strip img { width: 100%; aspect-ratio: 4 / 5; object-fit: cover; display: block; }
.example-row { margin: 6px 0 0; color: var(--muted); }
.any-warning { margin: 0; }
.readonly-field { background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; font-size: 13px; }
.hint summary { cursor: pointer; color: var(--primary); font-size: 12px; display: flex; gap: 4px; align-items: center; }
.hint p { font-size: 12px; color: var(--muted); }
.builder__preview { flex: 1; min-width: 0; padding: 16px 24px; display: flex; flex-direction: column; align-items: center; }
.builder__preview--detail { align-items: stretch; }
.preview__top { width: 100%; display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.detail-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.detail-name { font-weight: 600; flex: 1; }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 12px 0; }
.metric { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.metric__label { color: var(--muted); font-size: 13px; }
.metric__value { font-size: 28px; font-weight: 700; margin-top: 18px; }

/* Phone preview (ManyChat shows a dark Instagram mock + Post / Comments / DM switch) */
.phone { width: 300px; height: 600px; border-radius: 44px; background: #101114; border: 8px solid #2a2d34; overflow: hidden; color: #f2f2f2; box-shadow: 0 10px 30px rgba(0,0,0,.15); }
.phone__screen { height: 100%; display: flex; flex-direction: column; font-size: 12px; position: relative; }
.phone__status { display: flex; justify-content: space-between; padding: 10px 22px 6px; font-weight: 600; font-size: 11px; }
.pane { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.pane[hidden] { display: none; }
.ig-head { display: flex; align-items: center; gap: 10px; padding: 6px 12px; text-align: center; }
.ig-head > div { flex: 1; margin-right: 20px; }
.ig-sub { font-size: 9px; color: #9a9da4; }
.ig-title { font-weight: 700; }
.ig-back { font-size: 20px; line-height: 1; }
.ig-user { display: flex; align-items: center; gap: 8px; padding: 8px 12px; font-weight: 600; }
.avatar-dot { width: 24px; height: 24px; border-radius: 50%; background: linear-gradient(135deg, #f58529, #dd2a7b 50%, #8134af); display: inline-block; flex: 0 0 auto; }
.avatar-dot--light { background: #d9d9d9; }
.avatar-dot--lg { width: 40px; height: 40px; }
.ig-media { aspect-ratio: 4 / 5; background: #23262d center / cover no-repeat; display: grid; place-items: center; color: #777; }
.ig-media--dim { filter: brightness(.5); aspect-ratio: auto; flex: 0 0 120px; }
.ig-caption { padding: 8px 12px; margin: 0; line-height: 1.4; max-height: 90px; overflow: hidden; }
.sheet { flex: 1; background: #262626; border-radius: 14px 14px 0 0; padding: 8px 12px; }
.sheet__grip { width: 36px; height: 4px; background: #555; border-radius: 4px; margin: 0 auto 8px; }
.sheet__title { text-align: center; font-weight: 700; margin-bottom: 12px; }
.comment { display: flex; gap: 8px; }
.comment__user { font-weight: 600; font-size: 11px; }
.dm-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid #222; }
.dm-body { flex: 1; padding: 12px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; }
.dm-ref { align-self: center; color: #9a9da4; font-size: 10px; }
.bubble { align-self: flex-start; max-width: 82%; background: #262626; border-radius: 16px; padding: 9px 12px; white-space: pre-wrap; word-break: break-word; line-height: 1.4; }
.bubble a { color: #8ab4ff; text-decoration: underline; }
.bubble--empty { color: #888; font-style: italic; }
.dm-input { margin: 8px 12px 14px; border: 1px solid #333; border-radius: 20px; padding: 8px 12px; color: #888; }
.segmented { display: inline-flex; background: #e6e8eb; border-radius: 999px; padding: 3px; margin-top: 12px; }
.segmented button { border: 0; background: none; padding: 4px 12px; border-radius: 999px; font: inherit; font-size: 12px; color: var(--muted); cursor: pointer; }
.segmented button.is-on { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* Modals */
.modal { border: 0; border-radius: 12px; padding: 20px 22px; width: min(480px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal::backdrop { background: rgba(20, 22, 26, .45); }
.modal h3 { font-size: 18px; margin-bottom: 10px; }
.modal--wide { width: min(780px, calc(100vw - 32px)); background: #f4f5f7; }
.modal__head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; max-height: 60vh; overflow-y: auto; }
.media-card { background: #fff; text-align: left; display: block; width: 100%; color: var(--text); }
.media-card img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.media-card__text { padding: 8px 10px; font-size: 12px; }
.media-card__caption { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.summary { padding-left: 18px; margin: 0 0 12px; line-height: 1.6; }
.alert { border-radius: var(--radius); padding: 10px 12px; font-size: 13px; margin: 8px 0; }
.alert ul { margin: 6px 0 0; padding-left: 18px; }
.alert p { margin: 0; }
.alert--info { background: #eef4ff; color: #1a3f7a; }
.alert--warn { background: var(--warn-bg); color: #6b4000; }
.alert--danger { background: var(--danger-bg); color: #8a1c17; }

/* Connect screen (ManyChat onboarding: grey left half, form right) */
.split { display: flex; min-height: 100vh; }
.split__left { flex: 1; background: #f2f2f2; padding: 28px 56px; display: flex; flex-direction: column; justify-content: space-between; }
.split__right { flex: 1; background: #fff; display: grid; place-items: center; padding: 28px; }
.split__hero h1 { font-size: 30px; margin: 20px 0 10px; }
.wordmark { font-weight: 800; font-size: 18px; letter-spacing: -.02em; }
.blob { width: 96px; height: 96px; border-radius: 30px; background: conic-gradient(from 200deg, #9ed8db, #4f6bd8, #f72585, #9ed8db); display: grid; place-items: center; color: #fff; transform: rotate(-8deg); }
.blob svg { width: 44px; height: 44px; transform: rotate(8deg); }
.connect-box { width: 100%; max-width: 380px; }
.connect-box h2 { font-size: 15px; margin-bottom: 6px; }
.connect-box p { line-height: 1.5; }
.perm-box { background: var(--surface-2); border-radius: var(--radius); padding: 12px; margin-top: 14px; }
.perm-box__title { font-weight: 600; margin: 0 0 6px; }
.perm-list { margin: 0; padding-left: 18px; line-height: 1.7; font-size: 13px; }
.demo-form { margin-top: 14px; }

/* Settings rows (ManyChat Settings › Instagram: title | control | description) */
.content--settings { display: flex; gap: 24px; max-width: 1100px; }
.subnav { width: 160px; flex: 0 0 160px; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.subnav__group { font-weight: 700; margin: 0 0 4px; }
.subnav a { color: var(--muted); padding: 2px 0; }
.subnav a.is-on { color: var(--text); font-weight: 600; }
.settings-card { flex: 1; min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 20px 12px; }
.settings-card__title { display: flex; align-items: center; gap: 8px; font-size: 17px; padding: 16px 0 8px; }
.setting { display: grid; grid-template-columns: 200px minmax(220px, 300px) 1fr; gap: 20px; padding: 18px 0; border-top: 1px solid #eef0f2; align-items: start; }
.setting__title { font-weight: 600; }
.setting__desc { color: var(--muted); font-size: 13px; line-height: 1.5; }
.account-line { display: flex; gap: 10px; align-items: center; }

/* Simulator */
.pagebar--sim { background: var(--sim-bg); }
.sim-form { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 16px 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; margin-bottom: 14px; }

/* Login */
.auth-body { display: grid; place-items: center; min-height: 100vh; }
.auth-card { width: min(360px, calc(100vw - 32px)); background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 24px; display: flex; flex-direction: column; }
.auth-card h1 { font-size: 18px; margin: 14px 0 4px; }
.auth-card .btn { margin-top: 16px; }

@media (max-width: 860px) {
  .rail { width: 52px; flex-basis: 52px; }
  .builder { flex-direction: column; }
  .builder__panel { width: 100%; flex-basis: auto; position: static; max-height: none; border-right: 0; border-bottom: 1px solid var(--border); }
  .split { flex-direction: column; }
  .split__left { padding: 20px 16px; }
  .content { padding: 16px; }
  .content--settings { flex-direction: column; }
  .subnav { width: auto; flex-direction: row; gap: 12px; flex-basis: auto; }
  .setting { grid-template-columns: 1fr; gap: 8px; }
  .grid2 { grid-template-columns: 1fr; }
  .phone { width: 260px; height: 520px; }
}
.setting .perm-list { list-style: none; padding-left: 0; }
.scope-note { margin: 0; }
