/* Faber UI. Warm tinted ground, soft white cards, one action colour.
   Orange (--act) only ever marks something you can press now. */

@font-face {
  font-family: "Figtree";
  font-style: normal;
  font-weight: 300 900;
  font-display: swap;
  src: url("../fonts/figtree-latin.392aed3eb142.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Figtree";
  font-style: normal;
  font-weight: 300 900;
  font-display: swap;
  src: url("../fonts/figtree-latin-ext.8811e895c448.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  /* Colour */
  --ground: #f7f0e6;
  --card: #ffffff;
  --surface: #f7ebdd;
  --surface-2: #fbf5ee;
  --border: #e7dacb;
  --border-strong: #d6c6b3;
  --ink: #2b241f;
  --ink-2: #6f625a;
  --act: #c8410e; /* 4.98:1 with white labels; the world's #FF5B1F fails at button sizes */
  --act-hover: #ad380b;
  --act-ink: #ffffff;
  --act-soft: #ffe7dc;
  --live: #237a4b; /* 4.6:1 on --live-soft */
  --live-ink: #1f6a42; /* status text on white, 6.6:1 */
  --live-soft: #e2f3e8;
  --work: #8a5600; /* 5.5:1 on --work-soft */
  --work-soft: #fdf0d5;
  --bad: #a92e25; /* 5.5:1 on --bad-soft */
  --bad-ink: #8e271f;
  --bad-soft: #fbe3df;

  /* Shape and depth */
  --r-card: 18px;
  --r-ctl: 12px;
  --r-pill: 999px;
  --shadow-card: 0 1px 2px rgb(43 36 31 / 0.04), 0 6px 20px rgb(43 36 31 / 0.06);
  --shadow-lift: 0 2px 4px rgb(43 36 31 / 0.06), 0 12px 32px rgb(43 36 31 / 0.10);
  --shadow-press: 0 1px 2px rgb(43 36 31 / 0.10);

  /* Type */
  --font: "Figtree", ui-sans-serif, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --t-xs: 0.75rem;   /* 12 */
  --t-sm: 0.8125rem; /* 13 */
  --t-md: 0.9375rem; /* 15 */
  --t-lg: 1.0625rem; /* 17 */
  --t-xl: 1.375rem;  /* 22 */
  --t-2xl: 2rem;     /* 32 */

  /* Space (4px base) */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px; --s10: 40px;

  /* Motion */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --spring: cubic-bezier(0.34, 1.4, 0.64, 1);

  color-scheme: light;
  accent-color: var(--act);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 400 var(--t-md)/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
::selection { background: var(--act-soft); color: var(--ink); }
a { color: var(--ink); text-decoration-color: var(--border-strong); text-underline-offset: 3px; }
a:hover { text-decoration-color: currentColor; }
h1, h2, h3 { margin: 0; line-height: 1.2; text-wrap: balance; }
h1 { font-size: var(--t-2xl); font-weight: 750; letter-spacing: -0.02em; }
h2 { font-size: var(--t-lg); font-weight: 700; }
h3 { font-size: var(--t-md); font-weight: 650; }
p { margin: 0; }
.icon { flex: none; display: block; }
.muted { color: var(--ink-2); }
.small { font-size: var(--t-sm); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: 3px solid rgb(200 65 14 / 0.45); outline-offset: 2px; border-radius: 6px; }

/* Thin warm scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

/* ---------- Controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  height: 40px; padding: 0 var(--s4);
  font: 600 var(--t-md)/1 var(--font); color: var(--ink);
  background: var(--card); border: 1px solid var(--border); border-radius: var(--r-ctl);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: transform 0.18s var(--spring), background-color 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.btn:hover { border-color: var(--border-strong); background: var(--surface-2); }
.btn:active { transform: scale(0.97); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--act); border-color: var(--act); color: var(--act-ink); box-shadow: var(--shadow-press); }
.btn-primary:hover { background: var(--act-hover); border-color: var(--act-hover); }
.btn-quiet { background: transparent; border-color: transparent; color: var(--ink-2); padding: 0 var(--s2); }
.btn-quiet:hover { background: var(--surface); border-color: transparent; color: var(--ink); }
.btn-sm { height: 32px; padding: 0 var(--s3); font-size: var(--t-sm); border-radius: 10px; }
.btn-danger { color: var(--bad); }
.compose-box:has(textarea:placeholder-shown):not(:has(.chip)) .btn-primary { background: var(--surface); border-color: transparent; color: var(--ink-2); box-shadow: none; }
.status-ok { display: inline-flex; align-items: center; gap: var(--s2); height: 40px; padding: 0 var(--s3); font: 600 var(--t-md)/1 var(--font); color: var(--live-ink); }
.item-sub.bad { color: var(--bad); }
.detail-h2 { margin: var(--s6) 0 var(--s2); }
.btn.htmx-request { opacity: 0.7; pointer-events: none; }

.field { display: grid; gap: var(--s2); }
.field label { font-size: var(--t-sm); font-weight: 600; color: var(--ink-2); }
.input, .textarea, .select {
  width: 100%; font: 400 var(--t-md)/1.4 var(--font); color: var(--ink);
  background: var(--card); border: 1.5px solid var(--border); border-radius: var(--r-ctl);
  padding: 10px 14px; transition: border-color 0.15s, box-shadow 0.15s;
}
.input::placeholder, .textarea::placeholder { color: var(--ink-2); }
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--act); box-shadow: 0 0 0 4px rgb(200 65 14 / 0.12); }

/* Segmented control (tabs, device toggle) */
.seg { display: inline-flex; gap: 2px; padding: 4px; background: var(--surface); border-radius: var(--r-ctl); }
.seg button, .seg a {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 var(--s3);
  font: 600 var(--t-sm)/1 var(--font); color: var(--ink-2); text-decoration: none;
  background: none; border: 0; border-radius: 9px; cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.seg button:hover { color: var(--ink); }
.seg [aria-pressed="true"], .seg [aria-selected="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow-press); }
.seg.full { display: flex; }
.seg.full > * { flex: 1; justify-content: center; }

/* Status pills */
.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px;
  font: 600 var(--t-xs)/1 var(--font); border-radius: var(--r-pill);
  background: var(--surface); color: var(--ink-2); white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.no-dot::before { display: none; }
.pill-live { background: var(--live-soft); color: var(--live); }
.pill-work { background: var(--work-soft); color: var(--work); }
.pill-bad { background: var(--bad-soft); color: var(--bad); }
.pill-work::before { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

/* Icons in tinted circles */
.bubble { flex: none; display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--surface); color: var(--ink-2); }
.bubble-live { background: var(--live-soft); color: var(--live); }
.bubble-bad { background: var(--bad-soft); color: var(--bad); }
.bubble-work { background: var(--work-soft); color: var(--work); }

/* Cards */
.card { background: var(--card); border-radius: var(--r-card); box-shadow: var(--shadow-card); }
.card-pad { padding: var(--s6); }

/* Notes (inline messages) */
.note { display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s3) var(--s4); border-radius: var(--r-ctl); font-size: var(--t-sm); background: var(--surface-2); color: var(--ink-2); }
.note .icon { margin-top: 1px; }
.note-bad { background: var(--bad-soft); color: var(--bad-ink); }
.note-ok { background: var(--live-soft); color: var(--live-ink); }

/* ---------- App shell ---------- */
.topbar {
  display: flex; align-items: center; gap: var(--s4);
  min-height: 68px; padding: var(--s3) var(--s6);
}
.wordmark { font-size: 1.375rem; font-weight: 800; letter-spacing: -0.035em; color: var(--ink); text-decoration: none; }
.topbar .divider { width: 1px; height: 28px; background: var(--border); }
.topbar .spacer { flex: 1; }
.site-id { display: grid; line-height: 1.25; min-width: 0; }
.site-id strong { font-size: var(--t-md); font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-id span { font-size: var(--t-xs); color: var(--ink-2); }
.live-status { display: inline-flex; align-items: center; gap: var(--s2); height: 36px; padding: 0 var(--s3) 0 var(--s2); background: var(--card); border-radius: var(--r-pill); font-size: var(--t-sm); color: var(--ink-2); box-shadow: var(--shadow-press); min-width: 0; }
.live-status a { font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu { display: flex; align-items: center; gap: var(--s2); font-weight: 600; font-size: var(--t-sm); }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); font-weight: 700; font-size: var(--t-sm); color: var(--ink); }
.user-menu form { margin: 0; }

.flash { max-width: 720px; margin: 0 auto var(--s4); }

/* Simple pages */
.page { max-width: 1080px; margin: 0 auto; padding: var(--s6) var(--s6) var(--s10); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4); margin: var(--s4) 0 var(--s6); }
.page-head p { margin-top: var(--s2); color: var(--ink-2); }

/* ---------- Login ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: var(--s6); }
.auth-card { width: min(400px, 100%); padding: var(--s8); display: grid; gap: var(--s5); }
.auth-card .wordmark { font-size: 1.75rem; }
.auth-card h1 { font-size: var(--t-xl); }
.auth-card p { color: var(--ink-2); margin-top: var(--s1); }
.auth-card .btn { height: 46px; width: 100%; }

/* ---------- Sites list ---------- */
.sites { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--s5); }
.site-card { display: grid; text-decoration: none; color: inherit; overflow: hidden; transition: transform 0.25s var(--ease-out), box-shadow 0.25s var(--ease-out); }
.site-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); }
.site-thumb { position: relative; height: 190px; overflow: hidden; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.site-thumb iframe { position: absolute; top: 0; left: 0; width: 1280px; height: 800px; border: 0; transform: scale(0.25); transform-origin: 0 0; pointer-events: none; background: #fff; }
.site-meta { display: grid; gap: var(--s2); padding: var(--s4) var(--s5) var(--s5); }
.site-meta .row { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
.site-meta h2 { font-size: var(--t-lg); }
.site-meta .addr { font-size: var(--t-sm); color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.client { font-size: var(--t-xs); font-weight: 600; color: var(--ink-2); }
.empty { text-align: center; padding: var(--s10) var(--s6); color: var(--ink-2); }

/* ---------- Editor ---------- */
.editor-page { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.editor { flex: 1; min-height: 0; display: grid; grid-template-columns: clamp(290px, 24vw, 380px) minmax(0, 1fr) clamp(270px, 22vw, 340px); gap: var(--s4); padding: 0 var(--s4) var(--s4); }
.pane { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.pane-head { display: flex; align-items: center; gap: var(--s3); padding: var(--s4) var(--s5) var(--s3); }
.pane-body { flex: 1; min-height: 0; overflow: auto; }

/* Chat */
.chat { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.thread { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: var(--s3); padding: var(--s1) var(--s5) var(--s4); }
.msg-me { align-self: flex-end; max-width: 88%; background: var(--surface); padding: 10px 14px; border-radius: 16px 16px 4px 16px; overflow-wrap: anywhere; }
.msg-ai { max-width: 96%; overflow-wrap: anywhere; }
.steps { display: grid; gap: var(--s2); padding: var(--s3); background: var(--surface-2); border-radius: 14px; font-size: var(--t-sm); color: var(--ink-2); }
.step { display: flex; align-items: center; gap: var(--s2); min-width: 0; }
.step span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step .bubble { width: 26px; height: 26px; }
.step.now { color: var(--ink); font-weight: 600; }
.step.now .bubble { background: var(--work-soft); color: var(--work); animation: pulse 1.2s ease-in-out infinite; }
.thinking { display: inline-flex; align-items: center; gap: var(--s2); font-size: var(--t-sm); color: var(--work); font-weight: 600; }
.thinking i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; animation: pulse 1.2s ease-in-out infinite; }
.thinking i:nth-child(2) { animation-delay: 0.2s; }
.thinking i:nth-child(3) { animation-delay: 0.4s; }
.summary-note { font-size: var(--t-xs); color: var(--ink-2); text-align: center; padding: var(--s2) 0; }
.welcome { display: grid; gap: var(--s3); padding: var(--s2) 0; }
.welcome h2 { font-size: var(--t-xl); letter-spacing: -0.01em; }
.welcome p { color: var(--ink-2); }
.suggestions { display: flex; flex-wrap: wrap; gap: var(--s2); }
.suggestions button { font: 500 var(--t-sm)/1.2 var(--font); color: var(--ink); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-pill); padding: 8px 12px; cursor: pointer; text-align: left; transition: background-color 0.15s, border-color 0.15s; }
.suggestions button:hover { background: var(--surface); border-color: var(--border-strong); }

.composer { padding: var(--s3) var(--s4) var(--s4); border-top: 1px solid var(--border); display: grid; gap: var(--s2); min-width: 0; container-type: inline-size; }
.compose-box { border: 1.5px solid var(--border); border-radius: 14px; padding: 10px 10px 8px 14px; transition: border-color 0.15s, box-shadow 0.15s; background: var(--card); }
.compose-box:focus-within { border-color: var(--act); box-shadow: 0 0 0 4px rgb(200 65 14 / 0.12); }
.compose-box textarea { display: block; width: 100%; min-height: 48px; max-height: 160px; border: 0; padding: 0; resize: none; font: 400 var(--t-md)/1.45 var(--font); color: var(--ink); background: none; outline: none; field-sizing: content; }
.compose-box textarea::placeholder { color: var(--ink-2); }
.compose-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); margin-top: var(--s2); min-width: 0; }
.compose-row > .btn-primary { flex: none; }
.compose-box { min-width: 0; }
.usage { display: flex; align-items: center; gap: var(--s3); font-size: var(--t-xs); color: var(--ink-2); padding: 0 var(--s1); min-width: 0; }
.usage > span:first-child { flex: none; }
.usage .meter { flex: 1; min-width: 24px; height: 4px; border-radius: 4px; background: var(--surface); overflow: hidden; }
.usage .meter i { display: block; height: 100%; border-radius: 4px; background: var(--ink-2); }
.usage .meter.high i { background: var(--work); }

/* Preview */
.preview-pane { background: var(--card); }
.preview-tools { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); min-width: 0; }
.preview-state { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-tools .spacer { flex: 1; }
.page-select { position: relative; }
.page-select select { appearance: none; height: 36px; padding: 0 34px 0 var(--s3); font: 600 var(--t-sm)/1 var(--font); color: var(--ink); background: var(--surface); border: 0; border-radius: 10px; cursor: pointer; }
.page-select .icon { position: absolute; right: 10px; top: 9px; pointer-events: none; color: var(--ink-2); }
.preview-state { font-size: var(--t-sm); color: var(--ink-2); display: inline-flex; align-items: center; gap: var(--s2); }
.frame-wrap { position: relative; flex: 1; min-height: 0; display: flex; justify-content: center; padding: 0 var(--s4) var(--s4); }
.frame-wrap iframe { width: 100%; height: 100%; border: 1px solid var(--border); border-radius: 14px; background: #fff; transition: width 0.35s var(--ease-out), opacity 0.3s var(--ease-out), filter 0.3s var(--ease-out); }
.frame-wrap iframe.mobile { width: 390px; }
.frame-wrap iframe.loading { opacity: 0.55; filter: blur(2px); }
.updated-toast { position: absolute; left: 50%; top: var(--s4); transform: translate(-50%, -8px); display: inline-flex; align-items: center; gap: var(--s2); padding: 8px 14px; background: var(--ink); color: #fff; font-size: var(--t-sm); font-weight: 600; border-radius: var(--r-pill); box-shadow: var(--shadow-lift); opacity: 0; pointer-events: none; transition: opacity 0.25s var(--ease-out), transform 0.35s var(--ease-out); }
.updated-toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Side panel */
.side-tabs { padding: var(--s4) var(--s4) var(--s2); }
.side-body { flex: 1; min-height: 0; overflow: auto; padding: var(--s2) var(--s4) var(--s4); }
.list { list-style: none; margin: 0; padding: 0; display: grid; }
.item { display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: var(--s3); row-gap: 6px; padding: var(--s3); border-radius: 14px; transition: background-color 0.15s; }
.item > .bubble { grid-row: span 3; }
.item { position: relative; }
.item + .item::before { content: ""; position: absolute; top: 0; left: var(--s3); right: var(--s3); height: 1px; background: var(--border); }
.item:hover { background: var(--surface-2); }
.item.current::before, .item.current + .item::before { display: none; }
.item.current { background: var(--surface); }
.item-main { display: grid; gap: 6px; min-width: 0; }
.item-top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s2); }
.item-title { font-weight: 650; font-size: var(--t-sm); line-height: 1.35; }
.item-time { font-size: var(--t-xs); color: var(--ink-2); white-space: nowrap; }
.item-sub { font-size: var(--t-xs); color: var(--ink-2); }
.item-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.item-actions .btn-sm { background: var(--card); border-color: var(--border); }
.item-actions .btn-sm:hover { border-color: var(--border-strong); }
.section-label { font-size: var(--t-xs); font-weight: 700; color: var(--ink-2); margin: var(--s4) 2px var(--s2); }
.section-label:first-child { margin-top: var(--s1); }

.publish-box { display: grid; gap: var(--s3); padding: var(--s4); border-radius: 14px; background: var(--surface-2); margin-bottom: var(--s3); }
.publish-box h2 { font-size: var(--t-xl); letter-spacing: -0.01em; }
.publish-box .addr { display: flex; align-items: center; gap: var(--s2); font-size: var(--t-sm); min-width: 0; }
.publish-box .addr a { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.publish-box .addr .icon { color: var(--ink-2); }
.publish-box .row { display: flex; gap: var(--s2); }
.publish-box .row .btn { flex: 1; }

.files { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.files button { display: flex; align-items: center; gap: var(--s2); width: 100%; padding: 8px 10px; font: 500 var(--t-sm)/1.3 var(--font); color: var(--ink); background: none; border: 0; border-radius: 10px; cursor: pointer; text-align: left; }
.files button:hover { background: var(--surface-2); }
.files button .icon { color: var(--ink-2); }
.file-edit { display: grid; gap: var(--s3); }
.file-edit h3 { font-size: var(--t-sm); font-family: var(--mono); font-weight: 500; overflow-wrap: anywhere; }
.code { font: 400 0.8125rem/1.55 var(--mono); min-height: 52vh; white-space: pre; tab-size: 2; }

/* ---------- Compare & log pages ---------- */
.compare { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s5); }
.compare figure { margin: 0; display: grid; gap: var(--s2); }
.compare figcaption { font-weight: 650; font-size: var(--t-sm); color: var(--ink-2); }
.compare iframe { width: 100%; height: 440px; border: 1px solid var(--border); border-radius: 14px; background: #fff; }
.changes { display: grid; gap: var(--s4); margin-top: var(--s8); }
.change h3 { display: flex; align-items: center; gap: var(--s2); margin-bottom: var(--s2); font-family: var(--mono); font-size: var(--t-sm); font-weight: 500; }
.codeblock { margin: 0; background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: var(--s4); overflow: auto; font: 400 0.8125rem/1.6 var(--mono); color: var(--ink); max-height: 560px; }
.codeblock .add { display: block; background: var(--live-soft); color: var(--live-ink); }
.codeblock .del { display: block; background: var(--bad-soft); color: var(--bad-ink); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: var(--s2) var(--s6); font-size: var(--t-sm); margin: var(--s5) 0 var(--s6); }
.facts dt { color: var(--ink-2); }
.facts dd { margin: 0; overflow-wrap: anywhere; }

@media (max-width: 1320px) {
  .item-actions .btn-sm .icon { display: none; }
  .item-actions { flex-wrap: nowrap; }
  .seg [data-device] .label-text { display: none; }
  .topbar .live-status .label { display: none; }
}
@media (max-width: 1080px) {
  .editor-page { height: auto; overflow: visible; }
  .editor { grid-template-columns: 1fr; }
  .preview-pane { min-height: 70vh; }
  .side-pane { min-height: 480px; }
  .topbar { flex-wrap: wrap; }
  /* Chat becomes a popover opened from the floating "Ask Faber" button. */
  .editor > #chat { position: fixed; right: var(--s4); bottom: 84px; z-index: 20; width: min(420px, calc(100vw - 32px)); height: min(640px, calc(100dvh - 120px)); box-shadow: var(--shadow-lift); display: none; transform-origin: bottom right; }
  .editor[data-chat="open"] > #chat { display: flex; animation: pop-in 0.25s var(--ease-out); }
}
@media (max-width: 640px) {
  .topbar { padding: var(--s3) var(--s4); gap: var(--s3); }
  .topbar .divider, .live-status .label, .preview-state, .preview-tools .seg, .user-menu > span:not(.avatar) { display: none; }
  .topbar .live-status { order: 10; width: 100%; }
  .topbar .spacer { display: none; }
  .user-menu { margin-left: auto; }
  .topbar #open-preview { display: none; }
  .editor-page .user-menu form { display: none; }
  .page { padding: var(--s4); }
  .compare { grid-template-columns: 1fr; }
  .frame-wrap iframe.mobile { width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: 0.01ms !important; }
}

/* Chat reply text (escaped Markdown subset) */
.msg-ai p + p, .msg-ai p + ul, .msg-ai ul + p { margin-top: var(--s2); }
.msg-ai ul { margin: var(--s1) 0 0; padding-left: 1.1em; display: grid; gap: 2px; }
.msg-ai code, .note code { font: 0.85em/1 var(--mono); background: var(--surface); padding: 2px 5px; border-radius: 5px; }
.item .pill { flex: none; }

/* Confirm dialog (replaces the browser's confirm()) */
dialog.confirm { border: 0; padding: var(--s6); width: min(420px, calc(100% - 32px)); border-radius: var(--r-card); background: var(--card); color: var(--ink); box-shadow: var(--shadow-lift); }
dialog.confirm::backdrop { background: rgb(43 36 31 / 0.35); }
dialog.confirm[open] { animation: dialog-in 0.25s var(--ease-out); }
@keyframes dialog-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
dialog.confirm p { font-size: var(--t-lg); font-weight: 600; line-height: 1.4; }
dialog.confirm .row { display: flex; justify-content: flex-end; gap: var(--s2); margin-top: var(--s6); }

/* Floating chat button (smaller screens) */
.chat-fab { display: none; position: fixed; right: var(--s4); bottom: var(--s4); z-index: 21; align-items: center; gap: var(--s2); height: 52px; padding: 0 var(--s5) 0 var(--s4); font: 600 var(--t-md)/1 var(--font); color: #fff; background: var(--ink); border: 0; border-radius: var(--r-pill); box-shadow: var(--shadow-lift); cursor: pointer; transition: transform 0.18s var(--spring), background-color 0.15s; }
.chat-fab:hover { background: #3d342d; }
.chat-fab:active { transform: scale(0.96); }
.chat-fab .when-open, .editor[data-chat="open"] .chat-fab .when-closed { display: none; }
.editor[data-chat="open"] .chat-fab .when-open { display: inline-flex; }
.chat-fab .working { display: none; width: 8px; height: 8px; border-radius: 50%; background: var(--work-soft); box-shadow: 0 0 0 3px rgb(253 240 213 / 0.35); animation: pulse 1.2s ease-in-out infinite; }
.editor:has(#chat .thinking) .chat-fab .working { display: block; }
@keyframes pop-in { from { opacity: 0; transform: translateY(12px) scale(0.98); } }
@media (max-width: 1080px) {
  .chat-fab { display: inline-flex; }
}
@media (max-width: 640px) {
  .editor > #chat { left: var(--s2); right: var(--s2); bottom: 80px; width: auto; height: calc(100dvh - 96px); }
}
.languages-box { display: grid; gap: var(--s3); padding: var(--s3) var(--s4) var(--s4); border-radius: 14px; background: var(--surface-2); margin-bottom: var(--s3); }
.lang-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); padding: 6px 0; font-size: var(--t-sm); font-weight: 600; }
.lang-row + .lang-row { border-top: 1px solid var(--border); }
.languages-box .btn { justify-self: start; }
.domain { display: grid; gap: var(--s2); padding-bottom: var(--s3); border-bottom: 1px solid var(--border); }
.domain-name { overflow-wrap: anywhere; }
.dns-record { display: grid; grid-template-columns: max-content 1fr; align-items: center; gap: 4px var(--s3); margin: 0; padding: var(--s3); background: var(--card); border: 1px solid var(--border); border-radius: var(--r-ctl); font-size: var(--t-sm); }
.dns-record dt { color: var(--ink-2); }
.dns-record dd { margin: 0; display: flex; align-items: center; gap: var(--s2); min-width: 0; }
.dns-record code { font: 0.85em/1.3 var(--mono); overflow-wrap: anywhere; }
.domain-form { display: flex; gap: var(--s2); }
.domain-form .input { height: 32px; padding: 0 10px; font-size: var(--t-sm); }
.messages { gap: var(--s3); }
.message { padding: var(--s5) var(--s6); display: grid; gap: var(--s2); }
.message .facts { margin: var(--s2) 0; }
.upload-box { display: grid; gap: var(--s2); margin-bottom: var(--s3); }
.upload-button { justify-self: start; position: relative; }
.upload-button:focus-within { outline: 3px solid rgb(200 65 14 / 0.45); outline-offset: 2px; }
.media-grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: var(--s2); }
.media-grid li { display: grid; gap: 4px; min-width: 0; }
.media-thumb { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); display: grid; place-items: center; color: var(--ink-2); }
.media-name { font-size: var(--t-xs); color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-row { display: flex; align-items: center; gap: var(--s1); flex: 1; min-width: 0; }
.msg-page { align-self: flex-end; font-size: var(--t-xs); color: var(--ink-2); margin-bottom: -6px; }
.edit-toggle[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.updated-toast.bad { background: var(--bad); }
dialog.picker { width: min(560px, calc(100% - 32px)); }
dialog.picker h2 { margin-bottom: var(--s4); }
.picker-grid { margin-bottom: var(--s4); }
.picker-item { display: grid; gap: 4px; width: 100%; padding: 0; border: 0; background: none; cursor: pointer; text-align: left; border-radius: 10px; }
.picker-item:hover .media-thumb { border-color: var(--ink); }
.updated-toast .bad-icon, .updated-toast.bad .ok-icon { display: none; }
.updated-toast.bad .bad-icon { display: inline-flex; }
/* Narrow chat panel (smaller desktop windows, popover): Undo becomes icon-only. */
@container (max-width: 330px) { .undo-label { display: none; } }
.qr { display: grid; place-items: center; padding: var(--s3); background: #fff; border: 1px solid var(--border); border-radius: var(--r-ctl); }
.qr svg { width: 200px; height: 200px; }
.steps-details summary { cursor: pointer; font-size: var(--t-xs); color: var(--ink-2); padding: 2px 0; width: fit-content; }
.steps-details summary:hover { color: var(--ink); }
.steps-details[open] summary { margin-bottom: var(--s2); }
.thinking-step { color: var(--ink-2); font-weight: 500; }
.lang-picker { margin: 0; }
.lang-picker select { appearance: none; padding-right: var(--s3); cursor: pointer; }
.auth .lang-picker { position: fixed; top: var(--s4); right: var(--s4); }
.live-status .label, .site-id a { white-space: nowrap; }
.visit-totals { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); margin-bottom: var(--s4); }
.visit-totals div { display: flex; flex-direction: column; }
.visit-totals strong { font-size: var(--t-xl); line-height: 1.1; }
.visit-totals span { font-size: var(--t-xs); color: var(--ink-2); }
.visit-chart { display: flex; align-items: flex-end; gap: 2px; height: 96px; }
.visit-chart span { flex: 1; min-height: 2px; background: var(--act); border-radius: 2px 2px 0 0; }
.visit-axis { display: flex; justify-content: space-between; margin: var(--s1) 0 var(--s4); }
.visit-list li span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tray { display: flex; flex-wrap: wrap; gap: var(--s2); margin-bottom: var(--s2); }
.tray[hidden] { display: none; }
.chip { display: inline-flex; align-items: center; gap: var(--s2); max-width: 100%; padding: 4px 4px 4px 4px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); font-size: var(--t-xs); }
.chip img, .chip-video { width: 36px; height: 36px; flex: none; border-radius: 7px; object-fit: cover; }
.chip-video { display: grid; place-items: center; background: var(--surface); color: var(--ink-2); }
.chip-name { min-width: 0; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.chip-x { flex: none; width: 24px; height: 24px; border: 0; border-radius: 6px; background: none; color: var(--ink-2); font-size: 18px; line-height: 1; cursor: pointer; }
.chip-x:hover { background: var(--surface); color: var(--ink); }
.compose-box.htmx-request .tray::after { content: attr(data-uploading); align-self: center; font-size: var(--t-xs); color: var(--ink-2); }
#chat.dropping .compose-box { border-color: var(--act); border-style: dashed; box-shadow: 0 0 0 4px rgb(200 65 14 / 0.12); }
