/* FollowMate Business — single stylesheet. White top bar and cards on a light gray ground, a muted context column per workspace.
   Tokens first; every color below references one of them. Values follow docs/prototypes/followmate-business/shared/fm.css. */

:root {
  color-scheme: light;

  /* Surfaces: white canvas (top bar, cards), gray ground (page), muted context column. */
  --canvas: #ffffff;
  --ground: #f2f3f5;
  --muted: #f6f7f8;
  --line: #e0e4e8;
  --track: #e6e9ed;
  --field-border: #7a91a7;
  --control-border: #d3dae1;
  --control-border-hover: #bcc6d0;

  --text: #293e54;
  --secondary: #586d80;

  /* One accent carries action, selection and focus. */
  --accent: #2f6597;
  --accent-hover: #24527d;
  --nav-active: #edf3f8;
  --chip: #edf3f8;
  --selected: #f3f8fd;
  --focus: #2f6597;
  --chat-self: #dfebf7;
  --chat-self-text: #274968;

  /* Yellow marks change and urgency only: new message, about to expire, overdue/today, new progress, charged, paused. */
  --warning: #805015;
  --warning-surface: #fff5df;
  --warning-dot: #d9a520;
  --update: #f6de82;
  --update-text: #5c4614;

  /* Red is for errors and destructive actions. Green only marks a finished step. */
  --error: #a52c32;
  --error-surface: #fff0ef;
  --error-border: #a52c3247;
  --green: #127a4b;
  --green-soft: #e3f3ea;

  --radius-sm: 4px;
  --radius: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-pill: 999px;

  /* Shadows belong to floating layers only: dialogs, toast, menus and narrow-window drawers. */
  --shadow-menu: 0 8px 24px #293e541f;
  --shadow-dialog: 0 24px 64px #293e5438;
  --shadow-toast: 0 12px 32px #293e5442;
  --overlay: #293e5466;
  --on-accent-muted: #ffffffc7;

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft JhengHei", "PingFang TC", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --fs-xs: 12px;
  --fs-sm: 13px;
  --fs-md: 14px;
  --fs-lg: 16px;
  --fs-xl: 20px;

  --control-h: 32px;
  --control-h-sm: 28px;
  --toolbar-h: 56px;
  --statusbar-h: 28px;
  --header-h: var(--toolbar-h);
  --w-context: 200px;
  --w-chat-list: 280px;

  --z-sticky: 10;
  --z-status: 40;
  --z-toast: 100;

  --ease: cubic-bezier(.2, .7, .2, 1);
  --dur: 150ms;
}

/* ---------- base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { min-width: 320px; background: var(--ground); }

body {
  margin: 0;
  min-width: 320px;
  background: var(--ground);
  color: var(--text);
  font-family: var(--font-ui); font-size: var(--fs-md); line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, textarea, select { font: inherit; color: inherit; letter-spacing: inherit; }
button, select, label.upload-button, input[type="file"] { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }

h1, h2, h3, h4, p, dl, dd, dt, ul, figure { margin: 0; }
h1, h2, h3, h4 { font-weight: 600; text-wrap: balance; }
/* Emphasis never goes past the 600 ceiling (browsers default b／strong to 700). */
b, strong { font-weight: 600; }
p { text-wrap: pretty; }
ul { padding-left: 16px; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }
/* Technical identifiers (callback URLs, keys) are the only monospace text. */
code, kbd { font-family: var(--font-mono); font-size: var(--fs-xs); }
code { padding: 1px 4px; border-radius: var(--radius-sm); background: var(--muted); }
img, video { max-width: 100%; display: block; }

[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }

.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; }

/* Counts and times line up as tabular figures in the UI font. */
.numeric, time, .count-badge { font-variant-numeric: tabular-nums; }
/* Board labels: column headings and cell captions. */
.board-label { font-size: var(--fs-xs); font-weight: 600; color: var(--secondary); }

/* Kickers (WORKSPACE / THE SOURCE / …) are retired; headings carry their own weight. */
.section-kicker, .view-index { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

/* ---------- controls ---------- */
/* Three button tones: primary (accent fill), secondary (white, the default) and quiet (no frame). */

.button, .small-button, .upload-button {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  height: var(--control-h); padding: 0 12px;
  border: 1px solid var(--control-border); border-radius: var(--radius);
  background: var(--canvas); color: var(--text);
  font-size: var(--fs-sm); font-weight: 400; line-height: 1.4; white-space: nowrap;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.button:hover, .small-button:hover, .upload-button:hover { background: var(--chip); border-color: var(--control-border-hover); color: var(--text); }

.button-primary, .upload-button.button-primary { background: var(--accent); border-color: var(--accent); color: var(--canvas); }
.button-primary:hover, .upload-button.button-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--canvas); }
.button-primary:disabled, .button-primary[aria-disabled="true"] { background: var(--muted); border-color: var(--line); color: var(--secondary); opacity: 1; cursor: default; }
.button-secondary { background: var(--canvas); border-color: var(--control-border); color: var(--text); }
.button-quiet { background: transparent; border-color: transparent; color: var(--secondary); }
.button-quiet:hover { background: var(--chip); border-color: transparent; color: var(--text); }
.button-quiet[aria-pressed="true"], .conversation-header .button-quiet[aria-expanded="true"] { background: var(--chip); color: var(--accent); }
/* Destructive confirmations only (delete, disconnect, discard). */
.button-danger { background: var(--error); border-color: var(--error); color: var(--canvas); }
.button-danger:hover { background: var(--error); border-color: var(--error); color: var(--canvas); }

.small-button { height: var(--control-h-sm); padding: 0 8px; font-size: var(--fs-xs); }
.text-button { padding: 4px 4px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--accent); font-size: var(--fs-sm); font-weight: 400; text-decoration: none; display: inline-flex; align-items: center; gap: 4px; }
.text-button:hover { background: transparent; color: var(--accent-hover); text-decoration: underline; text-underline-offset: 3px; }
.text-button.danger-text { color: var(--error); }
.text-button.danger-text:hover { color: var(--error); }
.text-button svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

.icon-button {
  display: inline-grid; place-items: center; width: var(--control-h-sm); height: var(--control-h-sm); padding: 0;
  border: 1px solid transparent; border-radius: var(--radius); background: transparent; color: var(--secondary);
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.icon-button:hover { background: var(--chip); color: var(--text); }
.icon-button[aria-pressed="true"], .icon-button[aria-expanded="true"] { background: var(--chip); color: var(--accent); }
.icon-button svg, .nav-link svg, .editor-tab svg, .inbox-empty svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

/* "+" in a list-column heading (新增規則 / 連接社群帳號): an accent glyph, not a filled block. */
.icon-button-primary { color: var(--accent); }
.icon-button-primary:hover { color: var(--accent-hover); }

/* Form fields */
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), textarea, select {
  width: 100%; min-width: 0; margin: 0;
  border: 1px solid var(--field-border); border-radius: var(--radius);
  background: var(--canvas); color: var(--text);
  padding: 8px 12px; font-size: var(--fs-md); line-height: 1.6;
  transition: border-color var(--dur) var(--ease);
}
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]) { height: var(--control-h); padding-block: 0; }
input[readonly] { background: var(--muted); color: var(--text); }
textarea { resize: vertical; }
select { appearance: none; -webkit-appearance: none; height: var(--control-h); padding-block: 0; padding-right: 28px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23586d80' stroke-width='1.5'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 8px center; background-size: 16px; }
::placeholder { color: var(--secondary); opacity: 1; }
input[type="checkbox"], input[type="radio"] { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); flex: 0 0 auto; }

label > span:first-child, .field-label-text, .settings-field > span:first-child {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: var(--fs-sm); font-weight: 500; color: var(--text);
}
/* Explanations open in the browser's top layer, beyond scrolling panels. */
.field-help { display: inline-grid; place-items: center; width: 24px; min-width: 24px; height: 24px; padding: 4px; border: 0; border-radius: 50%; background: transparent; color: var(--secondary); vertical-align: middle; cursor: pointer; }
.field-help svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; }
.field-help:hover, .field-help:focus-visible, .field-help.is-open { background: var(--chip); color: var(--accent); }
.field-help.is-open, .is-help-anchor { anchor-name: --help-anchor; }
.field-help.field-help-inline { margin-left: 4px; }
.help-popover { position: fixed; inset: auto 16px calc(var(--statusbar-h) + 16px) auto; margin: 0; width: min(320px, calc(100vw - 32px)); max-height: min(240px, calc(100dvh - 32px)); overflow-y: auto; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--canvas); color: var(--text); box-shadow: var(--shadow-menu); font-size: var(--fs-sm); line-height: 1.6; overflow-wrap: anywhere; }
@supports (position-area: top) {
  .help-popover { position-anchor: --help-anchor; position-area: top; position-try-fallbacks: flip-block, flip-inline, flip-block flip-inline; inset: auto; margin: 8px; }
}

.field-hint, .muted-copy, small { font-size: var(--fs-xs); color: var(--secondary); line-height: 1.5; }

/* Errors: one bar everywhere — pale red, a 28% red hairline, an exclamation mark, and a white retry button. */
.error-bar, .automation-error { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; padding: 8px 12px; border: 1px solid var(--error-border); border-radius: var(--radius); background: var(--error-surface); color: var(--error); font-size: var(--fs-sm); line-height: 1.5; overflow-wrap: anywhere; }
.error-bar::before, .automation-error::before { content: "!"; display: inline-grid; place-items: center; flex: 0 0 auto; width: 16px; height: 16px; border-radius: 50%; background: var(--error); color: var(--canvas); font-size: var(--fs-xs); font-weight: 600; line-height: 1; }
.error-bar > span, .error-bar > strong { flex: 1 1 160px; min-width: 0; }
.error-bar strong { font-weight: 600; }
.error-bar .button, .error-bar .text-button { height: var(--control-h-sm); margin-left: auto; padding: 0 12px; border: 1px solid var(--error-border); border-radius: var(--radius); background: var(--canvas); color: var(--error); font-size: var(--fs-xs); text-decoration: none; }
.error-bar .button:hover, .error-bar .text-button:hover { background: var(--error-surface); border-color: var(--error); color: var(--error); }

/* Status tags: 20px, 4px corners. Accent tag = connected / enabled, outline = draft, warn / update = change and urgency. */
.status-badge { display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 6px; border-radius: var(--radius-sm); font-size: var(--fs-xs); font-weight: 400; white-space: nowrap; background: var(--ground); color: var(--secondary); }
.status-badge.status-idea { background: var(--chip); color: var(--accent); }
.status-badge.status-draft { background: var(--canvas); color: var(--secondary); box-shadow: inset 0 0 0 1px var(--control-border); }
.status-badge.status-ready { background: var(--chip); color: var(--accent); }
.status-badge.status-archived { background: transparent; color: var(--secondary); box-shadow: inset 0 0 0 1px var(--line); }
.status-badge.status-error { background: var(--error-surface); color: var(--error); font-weight: 600; }
.status-badge.status-alert { background: var(--warning-surface); color: var(--warning); font-weight: 600; }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--control-border-hover); flex: 0 0 auto; }
.dot.is-unknown { background: var(--control-border-hover); }
.dot.is-ok { background: var(--accent); }
.dot.is-warn { background: var(--warning-dot); }
.dot.is-off { background: transparent; box-shadow: inset 0 0 0 1.5px var(--control-border-hover); }
.dot.is-err { background: var(--error); }

.count-badge { display: inline-flex; align-items: center; height: 20px; padding: 0 6px; border-radius: var(--radius-sm); background: var(--ground); color: var(--secondary); font-size: var(--fs-xs); font-weight: 600; white-space: nowrap; }
.count-badge.is-alert { background: var(--warning-surface); color: var(--warning); }

.connection-state { display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 6px; border-radius: var(--radius-sm); background: var(--ground); color: var(--secondary); font-size: var(--fs-xs); font-weight: 400; white-space: nowrap; }
.connection-state.is-connected { background: var(--chip); color: var(--accent); }
.connection-state.is-attention { background: var(--warning-surface); color: var(--warning); font-weight: 600; }
.connection-state.is-disconnected, .connection-state.is-not_connected, .connection-state.is-planned { background: var(--canvas); color: var(--secondary); box-shadow: inset 0 0 0 1px var(--control-border); }
.connection-state.is-expired, .connection-state.is-failed, .connection-state.is-error { background: var(--error-surface); color: var(--error); font-weight: 600; }

.filter-row { display: flex; flex-wrap: wrap; gap: 4px; }
.filter-button { height: var(--control-h-sm); padding: 0 12px; border: 1px solid var(--control-border); border-radius: var(--radius-pill); background: var(--canvas); color: var(--text); font-size: var(--fs-xs); font-weight: 400; white-space: nowrap; }
.filter-button span { margin-left: 2px; color: var(--secondary); font-variant-numeric: tabular-nums; }
.filter-button:hover { background: var(--chip); }
.filter-button.is-active { background: var(--chip); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.filter-button.is-active span { color: var(--accent); }

.search-field { position: relative; display: flex; align-items: center; }
.search-field .search-icon { position: absolute; left: 8px; display: inline-flex; color: var(--secondary); pointer-events: none; }
.search-field .search-icon svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; }
.search-field .search-icon .field-help { display: none; }
.search-field input:not([type="checkbox"]):not([type="radio"]):not([type="file"]) { padding-left: 32px; padding-right: 12px; }
.search-field kbd { position: absolute; right: 8px; color: var(--secondary); background: var(--muted); border-radius: var(--radius-sm); padding: 2px 6px; }

.switch-button { display: inline-flex; align-items: center; gap: 8px; height: var(--control-h-sm); padding: 0 4px; border: 0; border-radius: var(--radius); background: transparent; color: var(--secondary); }
.switch-button > span { position: relative; width: 32px; height: 18px; border-radius: var(--radius-pill); background: var(--control-border); transition: background-color var(--dur) var(--ease); }
.switch-button > span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--canvas); transition: transform var(--dur) var(--ease); }
.switch-button.is-on { color: var(--text); }
.switch-button.is-on > span { background: var(--accent); }
.switch-button.is-on > span::after { transform: translateX(14px); }
.switch-button b { font-size: var(--fs-sm); font-weight: 400; }

/* Segmented control: one choice out of a few, e.g. 全部／待處理／已完成. */
.segmented { display: flex; gap: 2px; padding: 2px; border-radius: var(--radius-md); background: var(--track); }
.segmented button { flex: 1 1 0; display: inline-flex; align-items: center; justify-content: center; gap: 4px; height: var(--control-h-sm); padding: 0 12px; border: 1px solid transparent; border-radius: var(--radius); background: transparent; color: var(--secondary); font-size: var(--fs-sm); font-weight: 400; white-space: nowrap; transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease); }
.segmented button:hover { color: var(--text); }
.segmented button.is-active, .segmented button[aria-pressed="true"], .segmented button[aria-selected="true"] { background: var(--canvas); border-color: var(--control-border); color: var(--accent); font-weight: 600; }
.segmented button span { color: inherit; font-weight: 400; font-variant-numeric: tabular-nums; }
.compact-select { display: block; min-width: 0; }
.compact-select select { height: var(--control-h-sm); padding-left: 8px; font-size: var(--fs-xs); }

/* ---------- app shell ---------- */
/* 56px white top bar (brand, five workspaces, account and sample controls) → one context column per workspace
   → the work area on the gray ground → a 28px status bar fixed to the bottom edge. The page itself scrolls. */

.app-shell {
  display: grid; min-height: 100vh; padding-bottom: var(--statusbar-h);
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: var(--toolbar-h) minmax(0, 1fr);
}
.body-layout { display: contents; }
.topbar { grid-column: 1 / -1; grid-row: 1; }
.sidebar { grid-column: 1; grid-row: 2; }
.main-content { grid-column: 2; grid-row: 2; min-width: 0; }
.app-shell:has(.body-layout.is-wide) .sidebar { display: none; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: var(--z-sticky); display: flex; align-items: center; gap: 24px; height: var(--toolbar-h); min-width: 0; padding: 0 24px; background: var(--canvas); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; flex: none; color: var(--text); font-size: var(--fs-lg); font-weight: 600; white-space: nowrap; text-decoration: none; }
.brand:hover { color: var(--text); text-decoration: none; }
/* Show two regions of the unchanged PNG so the symbol matches the two-line wordmark's height. */
.brand-logo { display: flex; align-items: center; gap: 11px; height: 40px; }
.brand-symbol, .brand-wordmark { position: relative; display: block; height: 28px; overflow: hidden; flex: none; }
.brand-symbol { width: 38px; }
.brand-wordmark { width: 94px; }
.brand-logo img { position: absolute; max-width: none; height: auto; }
.brand-symbol img { width: 122px; left: -4px; top: -8px; }
.brand-wordmark img { width: 168px; left: -69px; top: -20px; }
.brand-mark { display: none; width: 36px; height: 36px; object-fit: contain; flex: none; }
.top-nav { display: flex; align-self: stretch; align-items: stretch; gap: 4px; min-width: 0; }
.nav-link { position: relative; display: flex; align-items: center; gap: 8px; padding: 0 12px; color: var(--secondary); font-size: var(--fs-md); white-space: nowrap; text-decoration: none; }
.nav-link:hover { color: var(--text); text-decoration: none; }
.nav-link[aria-current="page"] { color: var(--accent); font-weight: 600; }
.nav-link[aria-current="page"]::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: -1px; height: 2px; border-radius: 1px; background: var(--accent); }
.nav-link:focus-visible { outline-offset: -2px; }
.nav-count { min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--radius-pill); background: var(--ground); color: var(--secondary); font-size: var(--fs-xs); font-weight: 600; line-height: 20px; text-align: center; font-variant-numeric: tabular-nums; }
.nav-count.is-unread { background: var(--accent); color: var(--canvas); }
.nav-count.is-alert { background: var(--warning-surface); color: var(--warning); }
.topbar-actions { display: flex; align-items: center; gap: 8px; min-width: 0; margin-left: auto; }
.preview-badge { display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 6px; border-radius: var(--radius-sm); background: var(--canvas); box-shadow: inset 0 0 0 1px var(--control-border); color: var(--text); font-size: var(--fs-xs); font-weight: 600; white-space: nowrap; }
.preview-badge-detail { font-weight: 400; color: var(--secondary); }

/* Context column: the workspace's own list or sections. Chat 280px, the rest 200px. */
.sidebar { position: sticky; top: var(--toolbar-h); width: var(--w-context); height: calc(100vh - var(--toolbar-h) - var(--statusbar-h)); overflow-y: auto; overflow-x: hidden; display: flex; flex-direction: column; background: var(--muted); border-right: 1px solid var(--line); }
#inbox-sidebar { width: var(--w-chat-list); }
.sidebar-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 8px; padding: 16px 12px 12px 16px; }
.sidebar-heading h1 { font-size: var(--fs-lg); font-weight: 600; white-space: nowrap; }
.source-heading-actions { display: flex; align-items: center; gap: 4px; }
.source-heading-actions .count-badge { margin-right: 4px; background: transparent; padding: 0; font-weight: 400; }
.sidebar > .search-field { margin: 0 12px 12px; }
.sidebar > .filter-row, .sidebar-filters { padding: 0 12px 12px; }
.sidebar > .filter-row { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.sidebar > .filter-row::-webkit-scrollbar { display: none; }
.sidebar-filters { display: flex; flex-direction: column; gap: 8px; padding-bottom: 8px; }
.sidebar-selects { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 8px; }
.content-list { display: flex; flex-direction: column; flex: 1; }
.board-cols { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; gap: 12px; padding: 4px 16px; background: var(--muted); }
.sidebar-empty { padding: 28px 16px; text-align: center; color: var(--secondary); font-size: var(--fs-sm); }
.sidebar-footer { padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }

/* Section rows inside a context column (設定). */
.context-list { padding: 0 8px 16px; }
.context-group + .context-group { margin-top: 24px; }
.context-title { padding: 0 8px 4px; font-size: var(--fs-sm); font-weight: 600; }
.context-row { display: flex; width: 100%; align-items: center; gap: 8px; min-height: var(--control-h); padding: 4px 8px; border: 0; border-radius: var(--radius); background: transparent; color: var(--text); font-size: var(--fs-md); text-align: left; text-decoration: none; cursor: pointer; }
.context-row:hover { background: var(--chip); }
.context-row.is-active, .context-row[aria-current] { background: var(--nav-active); color: var(--accent); font-weight: 600; }

/* Status bar: sample marker and platform connections on the left, AI on the right. Platforms only show what the service returned. */
.status-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-status); display: flex; align-items: center; gap: 4px; height: var(--statusbar-h); min-width: 0; padding: 0 8px; overflow: hidden; background: var(--muted); border-top: 1px solid var(--line); color: var(--secondary); font-size: var(--fs-xs); }
.status-item { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--secondary); font-size: var(--fs-xs); white-space: nowrap; text-decoration: none; cursor: pointer; }
a.status-item:hover, button.status-item:hover { background: var(--chip); color: var(--text); text-decoration: none; }
.status-item b { color: var(--text); font-weight: 600; }
.status-sep { width: 1px; height: 14px; flex: none; margin: 0 4px; background: var(--line); }
.status-sample { color: var(--text); font-weight: 600; cursor: default; }
.status-sample, .status-ai { flex: none; }
/* At every width the platforms give way first: when they do not fit they scroll inside the bar, never under AI. */
.status-platforms { display: flex; flex: 0 1 auto; align-items: center; align-self: stretch; gap: 4px; min-width: 0; overflow-x: auto; overflow-y: hidden; }
/* A styled scrollbar is drawn even where the system hides scrollbars until you scroll, so "there is more" shows. */
.status-platforms::-webkit-scrollbar { height: 4px; }
.status-platforms::-webkit-scrollbar-track { background: var(--line); }
.status-platforms::-webkit-scrollbar-thumb { border-radius: 2px; background: var(--control-border-hover); }
/* ≤640px the five platforms become one sentence; it always says in words what the dots mean. */
.status-summary { display: none; }
.status-ai { margin-left: auto; }
.ai-state::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--control-border-hover); }
.ai-state.is-ready::before { background: var(--accent); }
.ai-state.is-offline::before { background: transparent; box-shadow: inset 0 0 0 1.5px var(--control-border-hover); }

/* Main */
.main-content { padding: 0 0 48px; }
.view-panel { min-width: 0; }
.view-panel:not(.canvas-view) { max-width: 1360px; margin-inline: auto; padding: 24px 32px 0; }

/* Cards: white, 1px hairline, 12px corners, no shadow. */
.card, .account-section, .settings-section, .synced-row {
  background: var(--canvas); border: 1px solid var(--line); border-radius: var(--radius-lg);
}

/* ---------- workspace canvas (聊天室 / 自動回覆 / 社群帳號 / AI 設定) ---------- */
/* A tab row spans the canvas; under it the working column sits centered between equal gutters,
   with an optional inspector column (--canvas-aside) on the right. */

.workspace-canvas { --canvas-gutter: minmax(32px, 1fr); --canvas-max: 1200px; --canvas-aside: 0px; --canvas-gap: 0px; display: grid; grid-template-columns: var(--canvas-gutter) minmax(0, var(--canvas-max)) var(--canvas-aside) var(--canvas-gutter); column-gap: var(--canvas-gap); align-content: start; }
.workspace-canvas > * { grid-column: 2; min-width: 0; }
.workspace-canvas > .workflow-tab-row { grid-column: 1 / -1; }
.inbox-canvas { --canvas-max: 960px; padding-top: 16px; }

/* Steps: numbered markers on a rule; done = green check, current = navy, halted = red. */

.agent-stages { display: flex; margin: 0; padding: 0; list-style: none; counter-reset: agent-stage; }
.agent-stages li { position: relative; flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 2px; padding: 24px 8px 0 0; color: var(--secondary); font-size: var(--fs-sm); font-weight: 600; counter-increment: agent-stage; }
.agent-stages li::before { content: counter(agent-stage); position: absolute; top: 0; left: 0; z-index: 1; width: 18px; height: 18px; box-sizing: border-box; border: 1.5px solid var(--control-border); border-radius: 50%; background: var(--canvas); color: var(--secondary); font-weight: 600; font-size: var(--fs-xs); line-height: 15px; font-variant-numeric: tabular-nums; text-align: center; }
.agent-stages li::after { content: ""; position: absolute; top: 8px; left: 24px; right: 6px; height: 2px; border-radius: 1px; background: var(--line); }
.agent-stages li:last-child::after { display: none; }
.agent-stages li small { color: var(--secondary); font-size: var(--fs-xs); font-weight: 400; }
.agent-stages li.is-done { color: var(--text); }
.agent-stages li.is-done::before { content: "✓"; border-color: var(--chip); background: var(--chip); color: var(--accent); }
.agent-stages li.is-current { color: var(--text); }
.agent-stages li.is-current::before { border-color: var(--accent); background: var(--accent); color: var(--canvas); }
.agent-stages li.is-halted::before { border-color: var(--error); background: var(--error); }
.agent-stages li.is-skipped { color: var(--secondary); }
.agent-stages li.is-skipped::before { border-style: dashed; }

/* Shared safe Markdown reports; prose keeps 75ch, tables use the available column. */

@media (max-width: 850px) {
  .agent-stages li { font-size: var(--fs-xs); }
  
  
  
  
  
}

/* The tab row stays under the top bar, so a view's own actions never scroll away. */
.workflow-tab-row { position: sticky; top: var(--toolbar-h); z-index: 6; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; min-height: 52px; margin: 0 0 16px; padding: 0 24px; background: var(--ground); border-bottom: 1px solid var(--line); }
.editor-tabs { display: flex; gap: 24px; }
.editor-tab { display: inline-flex; align-items: center; gap: 8px; height: 46px; padding: 0 2px; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; background: transparent; color: var(--secondary); font-size: var(--fs-md); font-weight: 500; white-space: nowrap; transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease); }
.editor-tab svg { width: 16px; height: 16px; }
.editor-tab span { font-variant-numeric: tabular-nums; font-size: var(--fs-xs); color: var(--secondary); }
.editor-tab:hover { color: var(--text); }
.editor-tab.is-active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.editor-tab.is-active span { color: var(--accent); }
.workflow-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; margin-left: auto; }



.status-select-label { display: inline-flex; align-items: center; gap: 4px; }
.status-select-label select { height: var(--control-h-sm); padding-left: 12px; padding-right: 24px; border-radius: var(--radius-pill); font-size: var(--fs-xs); font-weight: 600; color: var(--text); background-color: var(--muted); border-color: transparent; box-shadow: none; background-position: right 7px center; }

#content-core { min-height: 44vh; padding: 16px 16px; border: 1px solid var(--field-border); border-radius: var(--radius-md); background: var(--canvas); font-size: var(--fs-lg); line-height: 1.85; resize: vertical; box-shadow: none; }
#content-core:focus-visible { border-color: var(--focus); }

.save-state { display: inline-flex; align-items: center; gap: 6px; margin-left: 12px; font-size: var(--fs-xs); color: var(--secondary); white-space: nowrap; }
.save-state::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--control-border-hover); }
.save-state.is-saved::before { background: var(--green); }
.save-state.is-dirty::before { background: var(--warning-dot); }
.save-state.is-error { color: var(--error); }
.save-state.is-error::before { background: var(--error); }

.platform-switcher { display: flex; gap: 4px; padding: 4px; border-radius: var(--radius-md); background: var(--track); align-self: flex-start; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.platform-switcher::-webkit-scrollbar { display: none; }
.platform-switcher button { display: inline-flex; align-items: center; gap: 8px; height: var(--control-h); padding: 0 12px; border: 0; border-radius: var(--radius); background: transparent; color: var(--text); font-size: var(--fs-sm); font-weight: 500; white-space: nowrap; transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease), box-shadow var(--dur) var(--ease); }
.platform-switcher button:hover { color: var(--text); }
.platform-switcher button.is-active { background: var(--canvas); color: var(--accent); box-shadow: 0 0 0 1px var(--control-border); }
.platform-switcher button small { font-size: var(--fs-xs); color: var(--secondary); font-weight: 500; }
.platform-switcher button.is-active small { color: var(--accent); }
.platform-switcher button.is-reviewed::after { content: ""; width: 14px; height: 14px; border-radius: 50%; background: var(--green) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5'/%3E%3C/svg%3E") center / 9px no-repeat; }
.platform-glyph { display: inline-flex; align-items: center; justify-content: center; width: 20px; height: 20px; flex: 0 0 auto; }
.platform-glyph img { display: block; width: 100%; height: 100%; object-fit: contain; }
.platform-switcher button .platform-glyph, .platform-name .platform-glyph, .social-account-row .platform-glyph, .empty-account-summary .platform-glyph, .account-title-line .platform-glyph, .synced-platform .platform-glyph { width: 28px; height: 28px; }
.platform-switcher button .platform-glyph { width: 22px; height: 22px; }

.upload-button input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.upload-button { position: relative; }
.upload-button .field-help { display: none; }

.operation-empty, .knowledge-empty, .inbox-list-empty { padding: 24px 16px; border-radius: var(--radius-md); background: var(--ground); text-align: center; color: var(--secondary); font-size: var(--fs-sm); }
.operation-empty strong, .inbox-list-empty strong { display: block; color: var(--text); font-size: var(--fs-sm); margin-bottom: 2px; }
.inbox-list-empty span { display: block; }

/* ---------- inbox ---------- */

/* Chat list rows: rounded rows on the context column, transparent until hovered; the open conversation sits on --nav-active.
   Initial avatar with the platform icon on its corner, name and a one-line summary, then the remaining reply time
   (yellow only when it is about to run out), the time of the last message and the unread count. */
.inbox-conversation-list { gap: 2px; padding: 0 8px 8px; }
.inbox-conversation-row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 8px; border: 0; border-radius: var(--radius-md); background: transparent; color: var(--text); text-align: left; transition: background-color var(--dur) var(--ease); }
.inbox-conversation-row:hover { background: var(--chip); }
.inbox-conversation-row.is-active, .inbox-conversation-row.is-active:hover { background: var(--nav-active); }
/* The avatar tint equals the hover and selected fill, so on those rows it turns white to stay visible. */
.inbox-conversation-row:hover .inbox-avatar, .inbox-conversation-row.is-active .inbox-avatar { background: var(--canvas); }
.avatar-wrap { position: relative; display: inline-flex; flex: 0 0 auto; }
.inbox-avatar { display: grid; place-items: center; width: 32px; height: 32px; overflow: hidden; border-radius: 50%; background: var(--chip); color: var(--accent); font-size: var(--fs-sm); font-weight: 600; }
.avatar-wrap.is-lg .inbox-avatar { width: 40px; height: 40px; font-size: var(--fs-md); }
.inbox-avatar > span, .inbox-avatar > img { grid-area: 1 / 1; }
.inbox-avatar > img { width: 100%; height: 100%; object-fit: cover; background: var(--chip); }
.avatar-wrap > .platform-glyph { position: absolute; right: -4px; bottom: -4px; width: 16px; height: 16px; border-radius: var(--radius-sm); background: var(--canvas); box-shadow: 0 0 0 2px var(--canvas); }
.avatar-wrap.is-lg > .platform-glyph { width: 18px; height: 18px; }
.inbox-conversation-copy { display: flex; flex: 1 1 auto; flex-direction: column; gap: 2px; min-width: 0; }
.inbox-conversation-copy strong, .inbox-conversation-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inbox-conversation-copy strong { font-size: var(--fs-md); font-weight: 600; line-height: 1.4; }
.inbox-conversation-copy small { font-size: var(--fs-xs); color: var(--secondary); }
.inbox-conversation-row.has-unread .inbox-conversation-copy small { color: var(--text); }
.inbox-conversation-row.is-done strong { font-weight: 500; }
.inbox-row-side { display: flex; flex: 0 0 auto; flex-direction: column; align-items: flex-end; justify-content: space-between; gap: 4px; align-self: stretch; }
.inbox-row-left { font-size: var(--fs-xs); font-weight: 600; line-height: 1.5; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--text); }
.inbox-row-left.is-soon { color: var(--warning); }
.inbox-row-left.is-muted, .inbox-row-left.is-none { font-weight: 400; color: var(--secondary); }
.inbox-row-when { display: flex; align-items: center; gap: 4px; min-height: 20px; font-size: var(--fs-xs); color: var(--secondary); white-space: nowrap; }
.unread-count { display: inline-block; min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--radius-pill); background: var(--accent); color: var(--canvas); font-size: var(--fs-xs); font-weight: 600; line-height: 20px; text-align: center; font-variant-numeric: tabular-nums; }

/* Conversation: the 64px title bar, the messages on the ground, then the composer. They never overlap: the bar stays put
   and the messages scroll on their own. 個人資料 opens beside them as the right-hand sidebar (see 事項詳情 below). */
.inbox-canvas { display: block; padding: 0; }
.inbox-thread { display: flex; flex-direction: column; min-width: 0; min-height: 0; height: calc(100dvh - var(--header-h) - var(--statusbar-h)); overflow: hidden; background: var(--ground); }
.conversation-header { display: flex; flex: 0 0 auto; align-items: center; gap: 12px; min-height: 64px; padding: 4px 24px; background: var(--canvas); border-bottom: 1px solid var(--line); }
.conversation-identity { flex: 1 1 auto; min-width: 0; }
.conversation-identity h2 { font-size: var(--fs-lg); line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-identity p { max-width: none; overflow: hidden; font-size: var(--fs-xs); line-height: 1.5; color: var(--secondary); text-overflow: ellipsis; white-space: nowrap; }
.conversation-window, #conversation-updated { font-variant-numeric: tabular-nums; }
.conversation-window.is-soon { font-weight: 600; color: var(--warning); }
.conversation-header > .button { flex: 0 0 auto; height: var(--control-h-sm); padding: 0 8px; }
.inbox-back { display: none; }
.conversation-menu { position: relative; flex: 0 0 auto; }
.conversation-menu > .icon-button { border-color: var(--control-border); }
.menu-list { position: absolute; top: calc(100% + 4px); right: 0; z-index: var(--z-sticky); min-width: 200px; padding: 4px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--canvas); box-shadow: var(--shadow-menu); }
.menu-list [role="menuitem"] { display: flex; align-items: center; width: 100%; min-height: var(--control-h); padding: 4px 12px; border: 0; border-radius: var(--radius); background: transparent; color: var(--text); font-size: var(--fs-sm); text-align: left; }
.menu-list [role="menuitem"]:hover, .menu-list [role="menuitem"]:focus-visible { background: var(--chip); }
.menu-list [role="menuitem"][aria-expanded="true"] { color: var(--accent); font-weight: 600; }


.inbox-messages { display: flex; flex: 1 1 0; flex-direction: column; min-height: 120px; padding: 12px 24px 20px; overflow-y: auto; overscroll-behavior: contain; }
.inbox-message { display: flex; flex-shrink: 0; flex-direction: column; align-items: flex-start; max-width: 80%; margin-top: 4px; }
.inbox-message.is-run { margin-top: 16px; }
.inbox-message:first-child { margin-top: 4px; }
.inbox-message-author { margin: 0 0 4px 4px; font-size: var(--fs-xs); color: var(--secondary); }
.inbox-message-row { display: flex; align-items: flex-end; gap: 8px; max-width: 100%; }
.inbox-message-row > p { min-width: 0; padding: 8px 12px; border-radius: 16px; background: var(--canvas); font-size: var(--fs-md); line-height: 1.6; overflow-wrap: anywhere; white-space: pre-wrap; }
.inbox-message-row > time, .inbox-message.is-note > time { flex: none; margin-bottom: 2px; font-size: var(--fs-xs); color: var(--secondary); white-space: nowrap; }
.inbox-message.is-inbound.is-run .inbox-message-row > p { border-top-left-radius: var(--radius-sm); }
.inbox-message.is-outbound { align-self: flex-end; align-items: flex-end; }
.inbox-message.is-outbound .inbox-message-row { flex-direction: row-reverse; }
.inbox-message.is-outbound .inbox-message-row > p { background: var(--chat-self); color: var(--chat-self-text); }
.inbox-message.is-outbound.is-run .inbox-message-row > p { border-top-right-radius: var(--radius-sm); }
/* The message just sent lands in place: the list's one motion besides re-ranking. */
.inbox-message.is-fresh .inbox-message-row > p { animation: message-land 420ms var(--ease); }
@keyframes message-land { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
/* Internal notes: centered, dashed, never styled like a message to the customer. */
.inbox-message.is-note { align-self: center; align-items: center; width: 88%; max-width: 88%; }
.inbox-note { align-self: stretch; padding: 8px 12px; border: 1px dashed var(--control-border-hover); border-radius: var(--radius-md); background: var(--muted); font-size: var(--fs-sm); }
.inbox-note b { display: block; margin-bottom: 2px; font-size: var(--fs-xs); font-weight: 600; color: var(--secondary); }
.inbox-note p { max-width: none; white-space: pre-wrap; overflow-wrap: anywhere; }
.inbox-message.is-note > time { margin: 4px 0 0; }

/* Composer: one rounded box — 回覆對方／內部備註 on top, the text, then the tools and the send button. */
.inbox-composer { display: flex; flex: 0 0 auto; flex-direction: column; gap: 8px; min-height: 0; max-height: 46%; padding: 12px 24px 16px; overflow-y: auto; overscroll-behavior: contain; border-top: 1px solid var(--line); background: var(--canvas); }
.inbox-composer label { font-size: var(--fs-xs); font-weight: 600; color: var(--text); }
.composer-notice { max-width: none; padding: 8px 12px; border-radius: var(--radius); background: var(--muted); font-size: var(--fs-xs); line-height: 1.5; color: var(--text); }
.composer-box { flex: 0 0 auto; border: 1px solid var(--field-border); border-radius: var(--radius-lg); background: var(--canvas); }
.composer-box:focus-within { outline: 2px solid var(--focus); outline-offset: 1px; }
.composer-box.is-note { border-style: dashed; background: var(--muted); }
.composer-modes { display: inline-flex; margin: 8px 8px 0; }
.composer-modes button { flex: 0 0 auto; height: 24px; padding: 0 8px; font-size: var(--fs-xs); }
.composer-box textarea { display: block; min-height: 56px; max-height: 160px; padding: 8px 12px 4px; border: 0; border-radius: 0; background: transparent; resize: none; }
.composer-box textarea:focus-visible { outline: none; }
.composer-box textarea:disabled { background: transparent; }
.composer-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 4px 8px 8px; }
.composer-tools .button { height: var(--control-h-sm); padding: 0 8px; }
.composer-tools .button-primary { padding: 0 12px; }
.composer-spacer { flex: 1 1 auto; }
.shortcut-hint { padding-right: 4px; font-size: var(--fs-xs); color: var(--secondary); white-space: nowrap; }
.composer-rule { max-width: none; font-size: var(--fs-xs); line-height: 1.5; color: var(--secondary); }
.board-flag { display: inline-flex; align-items: center; height: 20px; padding: 0 6px; border-radius: var(--radius-sm); font-size: var(--fs-xs); font-weight: 600; white-space: nowrap; }
.board-flag.is-alert { background: var(--update); color: var(--update-text); }
.board-flag.is-muted { background: var(--track); color: var(--secondary); }
.board-flag.is-done { color: var(--secondary); box-shadow: inset 0 0 0 1px var(--control-border); }

/* The composer docks to the bottom edge of the inbox, so the canvas carries no bottom padding there. */
.main-content:has(> #inbox-view:not([hidden])) { padding-bottom: 0; }
.workflow-placeholder { font-size: var(--fs-sm); color: var(--secondary); }
.workflow-title, .automation-tab-title { display: flex; align-items: center; gap: 8px; min-width: 0; padding-block: 8px; }
.workflow-title h2, .automation-tab-title h2 { font-size: var(--fs-lg); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.workflow-title p, .automation-tab-title p { font-size: var(--fs-xs); color: var(--secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.workflow-actions .button { height: var(--control-h); }

.line-delivery-info { display: flex; align-items: flex-start; flex-wrap: wrap; gap: 8px 16px; padding-bottom: 12px; border-bottom: 1px solid var(--line); color: var(--text); }
.line-delivery-info > div { flex: 1 1 160px; min-width: 0; }
.line-delivery-info strong { font-size: var(--fs-sm); }
.line-delivery-info p { margin: 4px 0 0; font-size: var(--fs-xs); line-height: 1.5; color: var(--secondary); }
.line-delivery-info button { flex-shrink: 0; }
.whatsapp-delivery { display: grid; gap: 6px; padding-bottom: 12px; border-bottom: 1px solid var(--line); min-width: 0; }
.whatsapp-delivery-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; font-size: var(--fs-sm); }
.whatsapp-delivery label { display: grid; gap: 6px; min-width: 0; font-size: var(--fs-xs); font-weight: 600; }
.whatsapp-delivery select, .whatsapp-delivery input { width: 100%; min-width: 0; }
.whatsapp-parameters { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(180px, 100%), 1fr)); gap: 8px; }
.whatsapp-delivery p { margin: 0; overflow-wrap: anywhere; }
.whatsapp-cost { color: var(--text); font-weight: 500; font-size: var(--fs-xs); line-height: 1.6; font-variant-numeric: tabular-nums; }
.whatsapp-delivery .field-hint:empty { display: none; }
.ai-suggest-button { color: var(--accent-hover); }
.ai-suggest-button svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }

/* Instagram workflows extend the incumbent account, inbox and single-page views. */

.instagram-workflows { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--line); }
.social-workflow-links { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0; }
.social-scenario { display: flex; align-items: center; gap: 12px; margin-top: 20px; }
.social-scenario select { width: auto; }
.publish-dialog.social-detail-dialog { width: min(640px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow-y: auto; }
.social-detail-shell { padding: 24px; }
.social-detail-shell h2 { margin: 0; }
.social-detail-shell .publish-dialog-heading { align-items: center; padding: 0; margin-bottom: 16px; }
.social-detail-shell .dialog-close { margin: 0; flex: 0 0 auto; }
.social-detail-shell .dialog-actions { flex-wrap: wrap; padding: 20px 0 0; }
.social-facts { margin: 20px 0; }
.social-facts > div { display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.social-facts dt { font-size: var(--fs-xs); color: var(--secondary); }
.social-facts dd { margin: 0; color: var(--text); overflow-wrap: anywhere; }
.social-facts dd small { display: block; margin-top: 2px; color: var(--secondary); font-size: var(--fs-xs); }
.social-preview-step { padding: 16px 0; border-top: 1px solid var(--line); }
.social-preview-step h3 { margin: 0 0 12px; font-size: var(--fs-md); }
.social-preview-step p { margin: 0 0 12px; line-height: 1.75; white-space: pre-wrap; overflow-wrap: anywhere; }
.social-preview-step small { color: var(--secondary); line-height: 1.6; }
.inbox-message > .social-message-status { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 2px; font-size: var(--fs-xs); color: var(--secondary); }
.inbox-message > .social-message-status.is-failed { color: var(--error); font-weight: 600; }
.inbox-message.is-outbound:has(.social-message-status.is-failed) .inbox-message-row > p { background: var(--error-surface); color: var(--error); }

@media (max-width: 850px) {
  
  
  .social-detail-shell { padding: 16px; }
  .social-facts > div { grid-template-columns: 88px minmax(0, 1fr); gap: 12px; }
  .preview-badge-detail { display: none; }
  .shortcut-hint { display: none; }
}
.inbox-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; flex: 1; padding: 48px 16px; text-align: center; }
.inbox-empty > span { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: var(--muted); color: var(--accent); }
.inbox-empty svg { width: 20px; height: 20px; }
.inbox-empty h2 { font-size: var(--fs-lg); }
.inbox-empty p { font-size: var(--fs-sm); color: var(--secondary); max-width: 36ch; }
.inbox-empty .button { margin-top: 8px; }
.empty-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }
.welcome-empty h2 { font-size: var(--fs-xl); letter-spacing: -.02em; }
.welcome-empty p { max-width: 44ch; font-size: var(--fs-md); line-height: 1.7; }

/* ---------- connections ---------- */

.social-account-row { display: flex; align-items: center; gap: 8px; width: calc(100% - 16px); min-height: 48px; margin: 0 8px 2px; padding: 8px; border: 0; border-radius: var(--radius-md); background: transparent; color: var(--text); text-align: left; transition: background-color var(--dur) var(--ease); flex-wrap: wrap; }
button.social-account-row:hover { background: var(--chip); }
.social-account-row.is-active { background: var(--nav-active); }
.social-account-row.is-active strong { color: var(--accent); }
.social-account-row.is-planned strong { color: var(--secondary); font-weight: 500; }
.social-account-row > span:not(.platform-glyph) { flex: 1 1 96px; min-width: 0; }
.social-account-row strong { display: block; font-size: var(--fs-sm); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.social-account-row .connection-state { flex: 0 0 auto; }
.social-account-row small { display: block; font-size: var(--fs-xs); color: var(--secondary); }

.connection-panel-stack { display: flex; flex-direction: column; gap: 16px; }
.account-section { display: flex; flex-direction: column; gap: 16px; padding: 20px 24px; }
.account-section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.account-section-heading h2 { font-size: var(--fs-lg); font-weight: 600; }
.account-section-heading p { margin-top: 4px; font-size: var(--fs-xs); color: var(--secondary); max-width: 64ch; }
.empty-account-summary { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.empty-account-summary h2 { font-size: var(--fs-lg); margin-top: 8px; }
.empty-account-summary p { font-size: var(--fs-sm); color: var(--secondary); max-width: 48ch; }
.connected-account-summary { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.account-title-line { display: flex; align-items: center; gap: 12px; min-width: 0; }
.account-title-line > div { min-width: 0; overflow-wrap: anywhere; }
.account-title-line h2 { font-size: var(--fs-lg); }
.account-title-line p { font-size: var(--fs-xs); color: var(--secondary); }
.permission-summary { display: flex; flex-wrap: wrap; gap: 6px; }
.permission-summary span { font-size: var(--fs-xs); padding: 2px 8px; border-radius: var(--radius-sm); background: var(--ground); color: var(--secondary); }
.permission-summary span.is-attention { background: var(--warning-surface); color: var(--warning); }
.account-summary-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; font-size: var(--fs-xs); color: var(--secondary); }
.account-summary-actions .text-button { flex: 0 0 auto; white-space: nowrap; }
.credential-form { display: flex; flex-direction: column; gap: 20px; }
.credential-form fieldset { min-width: 0; margin: 0; padding: 0; border: 0; display: flex; flex-direction: column; gap: 12px; }
.credential-form legend { font-size: var(--fs-sm); font-weight: 600; margin-bottom: 4px; }
.credential-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.credential-fields label { position: relative; display: flex; flex-direction: column; gap: 6px; }
.field-reveal { position: absolute; right: 6px; bottom: 5px; height: 24px; padding: 0 8px; border: 0; border-radius: var(--radius-sm); background: var(--muted); color: var(--accent); font-size: var(--fs-xs); font-weight: 600; }
.callback-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 12px; align-items: start; padding: 12px 12px; border-radius: var(--radius-md); background: var(--ground); }
.callback-row label { display: flex; flex-direction: column; gap: 2px; }
.callback-row label span { font-size: var(--fs-xs); font-weight: 600; color: var(--text); }
.callback-row small { font-size: var(--fs-xs); color: var(--secondary); }
.callback-row > div { display: flex; align-items: center; gap: 6px; min-width: 0; }
.callback-row > div > input { flex: 1; width: auto; min-width: 0; }
.credential-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: var(--fs-xs); color: var(--secondary); }
.selection-fields { display: grid; grid-template-columns: minmax(0, 560px); gap: 12px; }
.selection-fields label { display: flex; flex-direction: column; gap: 6px; }
.sync-scope-list { display: flex; flex-direction: column; gap: 6px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 12px; border: 1px solid var(--line); border-radius: var(--radius-md); }
.setting-row > span:first-child, .knowledge-toggle > span:first-child { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; font-size: var(--fs-sm); font-weight: 400; color: var(--text); }
.setting-row strong { display: block; font-size: var(--fs-sm); font-weight: 600; }
.setting-row strong.field-label-text { display: inline-flex; }
.setting-row small { display: block; font-size: var(--fs-xs); color: var(--secondary); }
.sync-result-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: var(--fs-xs); color: var(--secondary); }
.synced-list { display: flex; flex-direction: column; gap: 8px; }
.synced-row { display: flex; align-items: center; gap: 12px; padding: 12px 12px; }
.synced-platform { display: flex; align-items: center; gap: 6px; font-size: var(--fs-xs); color: var(--secondary); flex: 0 0 auto; }
.synced-row > div { flex: 1; min-width: 0; }
.synced-row strong { display: block; font-size: var(--fs-sm); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.synced-row span:not(.platform-glyph) { font-size: var(--fs-xs); color: var(--secondary); }

.operation-list { display: flex; flex-direction: column; gap: 6px; }
.operation-row { display: flex; align-items: flex-start; gap: 8px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.operation-row:last-child { border-bottom: 0; }
.operation-dot { width: 8px; height: 8px; margin-top: 6px; border-radius: 50%; background: var(--control-border-hover); flex: 0 0 auto; }
.operation-dot.is-scheduled, .operation-dot.is-warning { background: var(--control-border-hover); }
.operation-dot.is-processing { background: var(--accent); }
.operation-dot.is-published, .operation-dot.is-success, .operation-dot.is-connected { background: var(--green); }
.operation-dot.is-failed, .operation-dot.is-error, .operation-dot.is-cancelled { background: var(--error); }
.operation-row > div { flex: 1; min-width: 0; }
.operation-row strong { display: block; font-size: var(--fs-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.operation-row span { display: block; font-size: var(--fs-xs); color: var(--secondary); }
.operation-row small { display: block; margin-top: 4px; font-size: var(--fs-xs); color: var(--error); }
.operation-row > time { flex: 0 0 auto; font-size: var(--fs-xs); color: var(--secondary); white-space: nowrap; }

/* ---------- automations ---------- */
.automations-canvas { --canvas-max: 960px; }
.automations-canvas:has(> .automation-simulation:not([hidden])) { --canvas-max: clamp(720px, 58vw, 1040px); --canvas-aside: clamp(336px, 22vw, 400px); --canvas-gap: clamp(20px, 1.5vw, 28px); --canvas-gutter: minmax(24px, 1fr); }
.automations-canvas > .automation-simulation { grid-column: 3; grid-row: 2 / span 40; position: sticky; top: calc(var(--toolbar-h) + 68px); align-self: start; max-height: calc(100vh - var(--toolbar-h) - var(--statusbar-h) - 84px); overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--canvas); scrollbar-gutter: stable; }
.automation-simulation > summary { padding: 16px; cursor: pointer; font-size: var(--fs-md); font-weight: 600; }
.automation-simulation > summary > span { margin-left: 8px; font-size: var(--fs-xs); font-weight: 400; color: var(--secondary); }
.automation-simulation > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }
#automation-simulation-body { padding: 0 16px 16px; display: flex; flex-direction: column; gap: 12px; }
.simulation-screen { display: grid; place-items: start center; min-width: 0; padding: 4px 0; }
.simulation-phone { width: min(100%, 304px); aspect-ratio: 1 / 2; display: flex; flex-direction: column; overflow: hidden; border: 6px solid var(--text); border-radius: 32px; background: var(--text); box-shadow: none; color: var(--canvas); }
.simulation-phone-status { height: 24px; padding: 4px 12px 0; display: flex; align-items: center; justify-content: space-between; flex: 0 0 auto; color: var(--canvas); font-size: 10px; font-weight: 600; }
.simulation-phone-status > span { display: flex; align-items: center; gap: 4px; }
.simulation-phone-signal { width: 12px; height: 7px; background: currentColor; clip-path: polygon(0 100%, 0 78%, 18% 78%, 18% 58%, 38% 58%, 38% 38%, 58% 38%, 58% 18%, 78% 18%, 78% 0, 100% 0, 100% 100%); }
.simulation-phone-wifi { width: 10px; height: 7px; border: 2px solid var(--canvas); border-width: 2px 2px 0 0; border-radius: 0 8px 0 0; transform: rotate(-45deg); }
.simulation-phone-battery { position: relative; width: 15px; height: 7px; border: 1px solid var(--canvas); border-radius: 2px; }
.simulation-phone-battery::before { content: ""; position: absolute; inset: 1px; background: var(--canvas); border-radius: 1px; }
.simulation-phone-battery::after { content: ""; position: absolute; right: -3px; top: 2px; width: 2px; height: 3px; background: var(--canvas); border-radius: 0 1px 1px 0; }
.simulation-phone-appbar { min-height: 44px; padding: 4px 12px; display: grid; grid-template-columns: 30px 30px minmax(0, 1fr) 54px; align-items: center; border-bottom: 1px solid var(--text); flex: 0 0 auto; }
.simulation-phone-back, .simulation-phone-trailing { display: grid; place-items: center; width: 30px; height: 30px; }
.simulation-phone-header-icon, .simulation-phone-account > svg, .simulation-phone-actions svg, .simulation-phone-composer svg, .simulation-sheet-heading svg, .simulation-sheet-comment > svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.simulation-phone-trailing { grid-column: 4; width: 54px; display: flex; justify-content: flex-end; gap: 8px; }
.simulation-phone-title { min-width: 0; text-align: center; grid-column: 2 / 4; }
.simulation-phone-appbar > .simulation-phone-avatar + .simulation-phone-title { grid-column: 3; text-align: left; }
.simulation-phone-title strong, .simulation-phone-title small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.simulation-phone-title strong { font-size: var(--fs-xs); line-height: 1.2; }
.simulation-phone-title small { margin-top: 1px; font-size: 10px; color: var(--on-accent-muted); }
.simulation-phone-avatar { width: 28px; height: 28px; display: grid; place-items: center; overflow: hidden; border-radius: 50%; background: var(--muted); color: var(--text); flex: 0 0 auto; }
.simulation-phone-avatar img { width: 100%; height: 100%; object-fit: cover; }
.simulation-phone-avatar svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.simulation-phone-avatar .platform-glyph { width: 20px; height: 20px; }
.simulation-phone-avatar.is-visitor { background: var(--muted); }
.simulation-phone-viewport { position: relative; min-height: 0; flex: 1; overflow: hidden; overscroll-behavior: contain; scrollbar-width: none; }
.simulation-phone[data-screen="dm"] .simulation-phone-viewport { overflow-y: auto; }
.simulation-phone-viewport::-webkit-scrollbar { display: none; }
.simulation-phone-home { width: 92px; height: 4px; margin: 8px auto 4px; border-radius: var(--radius-pill); background: var(--canvas); flex: 0 0 auto; }
.simulation-phone-account { height: 42px; padding: 6px 12px; display: flex; align-items: center; gap: 8px; }
.simulation-phone-account > div { min-width: 0; flex: 1; }
.simulation-phone-account strong, .simulation-phone-account small { display: block; }
.simulation-phone-account strong { font-size: var(--fs-xs); }
.simulation-phone-account small { font-size: 10px; color: var(--on-accent-muted); }
.simulation-phone-account > svg { width: 16px; height: 16px; }
.simulation-phone-media { position: relative; width: 100%; aspect-ratio: 4 / 3; overflow: hidden; background: var(--ground); }
.simulation-phone-media > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.simulation-phone-media > b { position: absolute; top: 8px; right: 8px; padding: 4px 8px; border-radius: var(--radius-pill); background: var(--text); color: var(--canvas); font-size: 10px; font-weight: 600; }
.simulation-phone-media-empty { width: 100%; height: 100%; display: grid; place-content: center; justify-items: center; gap: 6px; color: var(--secondary); }
.simulation-phone-media-empty svg { width: 32px; height: 32px; fill: none; stroke: currentColor; stroke-width: 1.4; }
.simulation-phone-media-empty span { font-size: 10px; }
.simulation-phone-actions { height: 34px; padding: 8px 12px 4px; display: flex; justify-content: space-between; align-items: center; }
.simulation-phone-actions > span { display: flex; gap: 12px; }
.simulation-phone-actions svg { width: 19px; height: 19px; }
.simulation-phone-likes, .simulation-phone-caption { padding-inline: 12px; font-size: 10px; line-height: 1.45; }
.simulation-phone-likes { font-weight: 600; }
.simulation-phone-caption { margin-top: 4px; display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 4; }
.simulation-phone-caption strong { font-weight: 600; }
.simulation-view-comments { margin: 4px 12px; padding: 0; border: 0; background: transparent; color: var(--on-accent-muted); font-size: 10px; text-align: left; }
.simulation-view-comments:hover { color: var(--canvas); }
.simulation-post-underlay { min-height: 100%; filter: brightness(.55); }
.simulation-comments-sheet { position: absolute; inset: auto 0 0; height: 60%; display: flex; flex-direction: column; overflow: hidden; border-radius: 22px 22px 0 0; background: var(--text); color: var(--canvas); box-shadow: none; }
.simulation-sheet-handle { width: 24px; height: 3px; margin: 8px auto 4px; border-radius: var(--radius-pill); background: var(--on-accent-muted); }
.simulation-sheet-heading { min-height: 36px; padding: 0 12px 8px; display: flex; align-items: center; justify-content: center; border-bottom: 1px solid var(--secondary); }
.simulation-sheet-heading strong { flex: 1; padding-left: 16px; text-align: center; font-size: var(--fs-xs); }
.simulation-sheet-list { min-height: 0; flex: 1; padding: 8px 12px; overflow-y: auto; }
.simulation-sheet-comment { display: grid; grid-template-columns: 26px minmax(0, 1fr) 16px; align-items: start; gap: 8px; padding: 4px 0; }
.simulation-sheet-comment.is-reply { padding-left: 24px; }
.simulation-sheet-comment .simulation-phone-avatar { width: 26px; height: 26px; }
.simulation-sheet-comment > div { min-width: 0; }
.simulation-sheet-comment p { font-size: 10px; line-height: 1.35; overflow-wrap: anywhere; }
.simulation-sheet-comment p:first-child { display: flex; align-items: baseline; gap: 4px; }
.simulation-sheet-comment p span, .simulation-sheet-comment small { color: var(--on-accent-muted); font-size: 10px; }
.simulation-sheet-comment small { display: block; margin-top: 2px; }
.simulation-sheet-comment > svg { width: 14px; height: 14px; margin-top: 8px; }
.simulation-sheet-composer { min-height: 42px; padding: 6px 12px; display: flex; align-items: center; gap: 8px; border-top: 1px solid var(--secondary); }
.simulation-sheet-composer .simulation-phone-avatar { width: 26px; height: 26px; }
.simulation-sheet-composer > span { min-width: 0; flex: 1; padding: 6px 8px; border: 1px solid var(--secondary); border-radius: var(--radius-pill); color: var(--on-accent-muted); font-size: 10px; }
.simulation-phone-chat { min-height: 100%; padding: 12px 8px 12px; display: flex; flex-direction: column; justify-content: flex-end; }
.simulation-phone-date { align-self: center; margin-bottom: 8px; color: var(--on-accent-muted); font-size: 10px; }
.simulation-dm-group { max-width: 86%; display: flex; align-items: flex-end; gap: 4px; margin-top: 8px; }
.simulation-dm-group .simulation-phone-avatar { width: 24px; height: 24px; }
.simulation-dm-card { min-width: 0; overflow: hidden; border-radius: 14px 14px 14px 5px; background: var(--text); }
.simulation-dm-card p { padding: 8px 8px; font-size: 10px; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }
.simulation-dm-card button, .simulation-dm-card a { display: block; width: calc(100% - 8px); min-height: 28px; margin: 0 4px 4px; padding: 6px 8px; border: 0; border-radius: var(--radius-sm); background: var(--overlay); color: var(--canvas); font-size: 10px; font-weight: 600; line-height: 1.35; text-align: center; text-decoration: none; }
.simulation-dm-card button:hover, .simulation-dm-card a:hover { background: var(--secondary); color: var(--canvas); text-decoration: none; }
.simulation-dm-user { max-width: 76%; align-self: flex-end; margin-top: 8px; padding: 8px 12px; border-radius: 14px 14px 5px; background: var(--accent); color: var(--canvas); font-size: 10px; line-height: 1.35; overflow-wrap: anywhere; }
.simulation-phone-composer { min-height: 40px; padding: 4px 8px; display: flex; align-items: center; gap: 8px; border-top: 1px solid var(--text); flex: 0 0 auto; }
.simulation-phone-composer > span { min-width: 0; flex: 1; padding: 6px 8px; border: 1px solid var(--secondary); border-radius: var(--radius-pill); color: var(--on-accent-muted); font-size: 10px; }
.simulation-phone-composer svg { width: 17px; height: 17px; }
.simulation-phone.is-threads { background: var(--canvas); color: var(--text); }
.simulation-phone.is-threads .simulation-phone-status { color: var(--text); }
.simulation-phone.is-threads .simulation-phone-wifi { border-color: var(--text); }
.simulation-phone.is-threads .simulation-phone-battery { border-color: var(--text); }
.simulation-phone.is-threads .simulation-phone-battery::before, .simulation-phone.is-threads .simulation-phone-battery::after, .simulation-phone.is-threads .simulation-phone-home { background: var(--text); }
.simulation-phone.is-threads .simulation-phone-viewport { overflow-y: auto; }
.simulation-threads-appbar { min-height: 44px; padding: 4px 12px 8px; display: grid; grid-template-columns: 32px minmax(0, 1fr) 32px; align-items: center; border-bottom: 1px solid var(--line); flex: 0 0 auto; }
.simulation-threads-appbar > span { width: 32px; height: 32px; display: grid; place-items: center; }
.simulation-threads-appbar > span:last-child { grid-column: 3; }
.simulation-threads-appbar strong { text-align: center; font-size: var(--fs-xs); }
.simulation-threads-view { min-height: 100%; padding: 6px 0 16px; }
.simulation-thread-post { display: grid; grid-template-columns: 38px minmax(0, 1fr); gap: 8px; padding: 12px 12px 8px; }
.simulation-thread-post + .simulation-thread-post { border-top: 1px solid var(--line); }
.simulation-thread-avatar-column { position: relative; min-height: 28px; display: flex; justify-content: center; }
.simulation-thread-avatar-column .simulation-phone-avatar { position: relative; z-index: 1; width: 30px; height: 30px; border: 1px solid var(--line); background: var(--canvas); color: var(--text); }
.simulation-thread-post.has-next .simulation-thread-avatar-column::after { content: ""; position: absolute; top: 34px; bottom: -19px; left: 50%; width: 2px; transform: translateX(-50%); background: var(--control-border); }
.simulation-thread-content { min-width: 0; }
.simulation-thread-content > header { min-height: 22px; display: grid; grid-template-columns: minmax(0, 1fr) auto 20px; align-items: start; gap: 4px; }
.simulation-thread-content > header strong { overflow: hidden; font-size: var(--fs-xs); font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.simulation-thread-content > header time { color: var(--secondary); font-size: 10px; }
.simulation-thread-content > header span { display: grid; place-items: center; }
.simulation-thread-content > header svg, .simulation-thread-actions svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.simulation-thread-content > p { font-size: 10px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
.simulation-thread-media { position: relative; width: 100%; aspect-ratio: 4 / 3; margin-top: 8px; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--ground); }
.simulation-thread-media > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.simulation-thread-actions { min-height: 30px; display: flex; align-items: center; gap: 12px; padding-top: 8px; }
.simulation-thread-content > small { display: block; color: var(--secondary); font-size: 10px; }
.simulation-channel-tabs { width: fit-content; max-width: 100%; margin-inline: auto; padding: 4px; display: flex; align-items: center; gap: 2px; border-radius: var(--radius-pill); background: var(--muted); }
.simulation-channel-tabs button { min-width: 64px; height: 28px; padding: 0 12px; border: 0; border-radius: var(--radius-pill); background: transparent; color: var(--secondary); font-size: var(--fs-xs); }
.simulation-channel-tabs button.is-active { background: var(--canvas); color: var(--text); box-shadow: none; }
.simulation-version-control { width: min(100%, 304px); margin-inline: auto; }
.simulation-caption { font-size: var(--fs-xs); color: var(--secondary); line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
@media (min-width: 1400px) and (max-width: 1680px) {
  .automations-canvas:has(> .automation-simulation:not([hidden])) { --canvas-max: 720px; --canvas-aside: 320px; --canvas-gap: 24px; --canvas-gutter: minmax(24px, 1fr); }
}
@media (max-width: 1399px) {
  .automations-canvas:has(> .automation-simulation:not([hidden])) { --canvas-max: 960px; --canvas-aside: 0px; --canvas-gap: 0px; --canvas-gutter: 16px; }
  .automations-canvas > .automation-simulation { grid-column: 2; grid-row: auto; position: static; max-height: none; margin-bottom: 16px; }
}
.automation-row { display: grid; grid-template-columns: 20px minmax(0, 1fr); align-items: start; gap: 4px 8px; width: calc(100% - 16px); min-height: 0; margin: 0 8px 2px; padding: 8px; border: 0; border-radius: var(--radius-md); background: transparent; color: var(--text); text-align: left; transition: background-color var(--dur) var(--ease); }
.automation-row:hover { background: var(--chip); }
.automation-row.is-active { background: var(--nav-active); }
.automation-row.is-active strong { color: var(--accent); }
.automation-row .platform-glyph { width: 20px; height: 20px; flex: 0 0 auto; }
.automation-row > span:not(.platform-glyph) { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.automation-row strong { display: block; font-size: var(--fs-sm); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.automation-row small { font-size: var(--fs-xs); color: var(--secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.automation-row .status-badge { grid-column: 2; justify-self: start; }
.automations-poll-copy { font-size: var(--fs-xs); color: var(--secondary); line-height: 1.5; }
.automation-detail { display: flex; flex-direction: column; gap: 16px; min-width: 0; padding-bottom: 32px; }

.automation-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.automation-stats > div { padding: 12px 12px; border-radius: var(--radius); background: var(--ground); }
.automation-stats span { display: block; font-size: var(--fs-xs); color: var(--secondary); }
.automation-stats strong { display: block; margin-top: 2px; font-size: var(--fs-md); font-variant-numeric: tabular-nums; }
.automation-error { font-size: var(--fs-xs); color: var(--error); line-height: 1.5; }
.automation-field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: 16px; align-items: end; }
.automation-field-grid > label, .automation-platform-field, .automation-detail .account-section > label:not(.setting-row) { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.automation-field-grid .platform-switcher { align-self: stretch; flex-wrap: wrap; overflow: visible; padding: 4px; }
.automation-field-grid .platform-switcher button { height: var(--control-h-sm); flex: 1 1 auto; justify-content: center; }
.automation-choice { display: flex; flex-direction: column; gap: 6px; }
.automation-choice .setting-row { justify-content: flex-start; align-items: flex-start; cursor: pointer; }
.automation-choice .setting-row.is-selected { border-color: var(--control-border); background: var(--muted); }
.automation-choice .setting-row > span { display: flex; flex-direction: column; gap: 2px; font-size: var(--fs-sm); }
.automation-choice .setting-row input { margin-top: 2px; }
.automation-choice-body { display: flex; flex-direction: column; gap: 8px; padding-left: 28px; }
.automation-choice-body select { max-width: 100%; }
.automation-record-picker { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.automation-record-picker-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 4px 0 8px; }
.automation-record-picker-heading > div { min-width: 0; }
.automation-record-picker-heading strong, .automation-record-current > span { display: block; font-size: var(--fs-xs); font-weight: 600; color: var(--text); }
.automation-record-picker-heading span { display: block; margin-top: 2px; font-size: var(--fs-xs); color: var(--secondary); }
.automation-record-picker-heading .text-button { flex: 0 0 auto; }
.automation-record-list, .automation-record-history { display: flex; flex-direction: column; min-width: 0; }
.automation-record-current { display: flex; flex-direction: column; gap: 6px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.automation-record-card { display: grid; grid-template-columns: 64px minmax(0, 1fr) 24px; align-items: center; gap: 12px; width: 100%; min-width: 0; min-height: 80px; padding: 8px; border: 1px solid transparent; border-bottom-color: var(--line); border-radius: var(--radius-md); background: transparent; color: var(--text); text-align: left; transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease); }
.automation-record-card:last-child { border-bottom-color: transparent; }
.automation-record-card:hover { background: var(--ground); }
.automation-record-card.is-selected { border-color: var(--control-border); background: var(--muted); }
.automation-record-thumb { position: relative; display: grid; place-items: center; width: 64px; height: 64px; overflow: hidden; border-radius: var(--radius); background: var(--muted); color: var(--control-border-hover); }
.automation-record-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.automation-record-thumb-empty svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.automation-record-copy { min-width: 0; }
.automation-record-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.automation-record-meta b { display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: var(--radius-pill); background: var(--chip); color: var(--accent-hover); font-size: var(--fs-xs); font-weight: 600; }
.automation-record-meta time { min-width: 0; color: var(--secondary); font-size: var(--fs-xs); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.automation-record-copy > strong { display: -webkit-box; overflow: hidden; color: var(--text); font-size: var(--fs-sm); font-weight: 500; line-height: 1.45; overflow-wrap: anywhere; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.automation-record-check { display: grid; place-items: center; width: 20px; height: 20px; border: 1px solid var(--control-border); border-radius: var(--radius-pill); color: var(--accent); font-size: var(--fs-xs); font-weight: 600; }
.automation-record-card.is-selected .automation-record-check { border-color: var(--accent); }
.automation-variants { display: flex; flex-direction: column; gap: 8px; }
.automation-variant-row { display: flex; align-items: flex-start; gap: 8px; }
.automation-variant-row textarea { flex: 1; min-height: 64px; }
.automation-variant-row .icon-button { margin-top: 2px; }
.automation-variant-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.automation-switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.automation-switch-row > .switch-button { flex-shrink: 0; white-space: nowrap; }
.automation-message-block { display: flex; flex-direction: column; gap: 8px; padding-top: 16px; margin-top: 16px; border-top: 1px solid var(--line); }
.automation-message-block + .automation-message-block { padding-top: 20px; }
.automation-message-heading h3 { font-size: var(--fs-sm); font-weight: 600; }
.automation-message-heading p { margin-top: 4px; color: var(--secondary); font-size: var(--fs-xs); line-height: 1.5; }
.automation-message-block .setting-row { margin-top: 2px; }
.automation-link-fields { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(180px, .5fr); gap: 16px; }
.automation-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.automation-footer-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.automation-log { display: flex; flex-direction: column; gap: 6px; }
.automation-notice { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 12px; border-radius: var(--radius-md); background: var(--warning-surface); color: var(--warning); font-size: var(--fs-xs); line-height: 1.5; }
.automation-notice .text-button { flex: 0 0 auto; }
/* New rule = guided steps; saved rule = read-only overview with its own actions. */
.automation-create-head { display: flex; flex-direction: column; gap: 12px; padding: 4px 0 4px; }
.automation-steps .automation-step-link { padding: 0; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.automation-steps .automation-step-link:hover { color: var(--accent); }
.automation-step-error { padding: 12px 12px; border-radius: var(--radius-md); background: var(--error-surface); }
.automation-detail .account-section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
/* Rule flow: comment → public reply → DM → link, read top to bottom like the follower experiences it. */
.automation-flow { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; }
.automation-flow-step { position: relative; display: grid; grid-template-columns: 32px minmax(0, 1fr); gap: 12px; padding-bottom: 20px; }
.automation-flow-step:not(:last-child)::after { content: ""; position: absolute; top: 36px; bottom: 4px; left: 15.5px; width: 1px; background: var(--control-border-hover); }
.automation-flow-icon { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--chip); color: var(--accent-hover); }
.automation-flow-icon svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.automation-flow-step.is-off .automation-flow-icon { background: var(--ground); color: var(--control-border-hover); }
.automation-flow-step.is-off .automation-flow-head h3, .automation-flow-step.is-off .automation-flow-line { color: var(--secondary); }
.automation-flow-body { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; min-width: 0; padding-top: 6px; }
.automation-flow-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; width: 100%; }
.automation-flow-head h3 { font-size: var(--fs-md); font-weight: 600; color: var(--text); }
.automation-flow-line { font-size: var(--fs-sm); line-height: 1.6; color: var(--text); }
.automation-flow-line strong { color: var(--text); font-weight: 600; }
.automation-flow-note { font-size: var(--fs-xs); line-height: 1.5; color: var(--secondary); overflow-wrap: anywhere; }
.automation-keywords { display: inline-flex; flex-wrap: wrap; gap: 6px; margin-left: 4px; vertical-align: middle; }
.automation-keyword { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: var(--radius-pill); background: var(--muted); color: var(--text); font-size: var(--fs-xs); font-weight: 600; }
.automation-flow-posts { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.automation-flow-post { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 12px; align-items: center; max-width: 560px; padding: 8px; border: 1px solid var(--line); border-radius: var(--radius-md); }
.automation-flow-post > span:last-child { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.automation-flow-post strong { font-size: var(--fs-sm); font-weight: 600; line-height: 1.45; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.automation-flow-post small { font-size: var(--fs-xs); color: var(--secondary); }
.automation-flow-thumb { position: relative; width: 44px; height: 44px; overflow: hidden; border-radius: var(--radius); background: var(--muted); }
.automation-flow-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.automation-bubble { max-width: min(100%, 520px); padding: 8px 12px; border-radius: var(--radius-sm) 14px 14px 14px; background: var(--ground); border: 1px solid var(--line); color: var(--text); font-size: var(--fs-sm); line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.automation-bubble.is-missing { border-style: dashed; color: var(--warning); background: var(--canvas); }
.automation-bubble-button { display: inline-flex; align-items: center; height: var(--control-h-sm); padding: 0 12px; border: 1px solid var(--control-border); border-radius: var(--radius); background: var(--canvas); color: var(--text); font-size: var(--fs-xs); font-weight: 600; }
.automation-flow-settings { display: flex; flex-wrap: wrap; gap: 8px 24px; padding-top: 12px; border-top: 1px solid var(--line); font-size: var(--fs-xs); color: var(--secondary); }
.automation-flow-settings b { margin-left: 4px; color: var(--text); font-weight: 600; }
.automation-missing { color: var(--warning); }
.automation-fact-edit { flex: 0 0 auto; font-size: var(--fs-xs); }
.automation-step-title { display: flex; flex-direction: column; gap: 4px; padding-top: 12px; }
.automation-step-title h2 { font-size: var(--fs-xl); font-weight: 600; letter-spacing: -.02em; color: var(--text); }
.automation-step-title p { font-size: var(--fs-sm); line-height: 1.6; color: var(--secondary); }
#automation-detail[data-mode="create"] .automation-basics > .account-section-heading { display: none; }
.automation-action-bar { position: static; padding: 12px 12px 12px 16px; border: 1px solid var(--control-border); border-radius: var(--radius-lg); background: var(--canvas); box-shadow: none; }
.automation-state-note { display: flex; flex-direction: column; gap: 2px; padding: 12px 12px; border: 1px solid var(--control-border-hover); border-radius: var(--radius-md); background: var(--chip); }
.automation-state-note strong { color: var(--accent-hover); font-size: var(--fs-sm); }
.automation-state-note span { color: var(--text); font-size: var(--fs-xs); line-height: 1.5; }
.automation-detail-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 64px 24px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--canvas); text-align: center; }
.automation-detail-empty strong { font-size: var(--fs-lg); color: var(--text); }
.automation-detail-empty > span:not(.empty-icon) { max-width: 40ch; font-size: var(--fs-sm); color: var(--secondary); }
.automation-detail-empty .button { margin-top: 12px; }
.empty-icon { display: grid; place-items: center; width: 44px; height: 44px; margin-bottom: 6px; border-radius: 50%; background: var(--muted); color: var(--accent); }
.empty-icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- settings ---------- */

.settings-form { display: flex; flex-direction: column; gap: 16px; }
.settings-section { display: flex; flex-direction: column; gap: 16px; padding: 20px 24px; }
.settings-section-heading { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px; }
.settings-section-heading > div { flex: 1 1 240px; min-width: 0; }
.settings-section-heading h2 { font-size: var(--fs-lg); font-weight: 600; }
.settings-section-heading p { margin-top: 4px; font-size: var(--fs-xs); color: var(--secondary); max-width: 64ch; }
.settings-section-state { display: inline-flex; align-items: center; min-height: 22px; max-width: 100%; padding: 0 8px; border-radius: var(--radius-pill); background: var(--muted); color: var(--secondary); font-size: var(--fs-xs); font-weight: 600; white-space: normal; }
.settings-fields { display: flex; flex-direction: column; gap: 16px; }
.settings-field { display: flex; flex-direction: column; gap: 6px; }
.settings-field-pair, .settings-select-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.knowledge-toggle { display: flex; align-items: flex-start; gap: 12px; padding: 12px 12px; border: 1px solid var(--line); border-radius: var(--radius-md); }
.knowledge-toggle input { margin-top: 4px; }
.knowledge-toggle strong { display: block; font-size: var(--fs-sm); font-weight: 600; }
.knowledge-toggle small { display: block; font-size: var(--fs-xs); color: var(--secondary); }
.knowledge-list { display: flex; flex-direction: column; gap: 6px; }
.knowledge-row { display: flex; align-items: center; gap: 12px; padding: 12px 12px; border: 1px solid var(--line); border-radius: var(--radius-md); }
.knowledge-file-mark { display: grid; place-items: center; height: 24px; padding: 0 8px; border-radius: var(--radius-sm); background: var(--muted); color: var(--accent); font-size: var(--fs-xs); font-weight: 600; flex: 0 0 auto; }
.knowledge-row > div { flex: 1; min-width: 0; }
.knowledge-row strong { display: block; font-size: var(--fs-sm); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.knowledge-row span:not(.knowledge-file-mark):not(.knowledge-ready) { font-size: var(--fs-xs); color: var(--secondary); }
.knowledge-ready { font-size: var(--fs-xs); color: var(--green); white-space: nowrap; }
.settings-scope { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: var(--fs-xs); }
.settings-scope strong { margin-right: 4px; color: var(--text); }
.settings-scope span { padding: 4px 8px; border-radius: var(--radius-pill); background: var(--muted); color: var(--text); }

/* ---------- content-to-conversation workflow extensions ---------- */
.studio-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.automation-priority-field { max-width: 320px; }
.studio-field-pair, .studio-custom-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.studio-custom-row { margin-top: 16px; align-items: end; }
.studio-custom-row > button { justify-self: start; }
.studio-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }

.studio-test-form, .studio-test-result { display: flex; flex-direction: column; gap: 12px; }
.social-detail-shell .studio-test-form { padding: 0; margin-top: 16px; }
.studio-test-result { margin-top: 20px; }
.studio-test-result > button { align-self: flex-start; }
.studio-test-message { padding: 12px 12px; border-radius: var(--radius); background: var(--muted); color: var(--text); font-size: var(--fs-sm); white-space: pre-wrap; overflow-wrap: anywhere; }
.studio-test-message.is-incoming { margin-left: 24px; background: var(--chip); }
.studio-contact-body, .studio-contact-body form { display: flex; flex-direction: column; gap: 16px; }

.studio-ai { display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px solid var(--control-border); border-radius: var(--radius-md); background: var(--ground); }

@media (max-width: 850px) {
  .studio-field-pair, .studio-custom-row { grid-template-columns: minmax(0, 1fr); }
  
}

/* ---------- dialogs & toast ---------- */

.modal-backdrop { display: none; }
dialog { margin: auto; padding: 0; border: 0; border-radius: var(--radius-lg); background: var(--canvas); color: var(--text); box-shadow: var(--shadow-dialog); }
dialog::backdrop { background: var(--overlay); backdrop-filter: blur(2px); }
.confirm-dialog { width: min(420px, calc(100vw - 32px)); }
.confirm-dialog > div { padding: 24px; }
.confirm-dialog h2 { font-size: var(--fs-lg); }
.confirm-dialog p:not(.section-kicker) { margin-top: 8px; font-size: var(--fs-sm); color: var(--secondary); line-height: 1.6; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.publish-dialog { width: min(620px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto; }
.publish-dialog form { display: flex; flex-direction: column; gap: 16px; padding: 24px; }
.publish-dialog fieldset { min-width: 0; margin: 0; padding: 0; border: 0; display: flex; flex-direction: column; gap: 8px; }
.publish-dialog legend { font-size: var(--fs-sm); font-weight: 600; margin-bottom: 6px; }
.publish-dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.publish-dialog-heading h2 { font-size: var(--fs-lg); }
.publish-dialog-heading p { margin-top: 4px; font-size: var(--fs-sm); color: var(--secondary); }
.dialog-close { display: inline-grid; place-items: center; width: 32px; height: 32px; margin: -6px -6px 0 0; border: 0; border-radius: var(--radius); background: transparent; color: var(--secondary); font-size: var(--fs-xl); line-height: 1; }
.dialog-close:hover { background: var(--chip); color: var(--text); }

.automation-record-dialog { width: min(520px, 100vw); height: 100dvh; max-height: 100dvh; margin: 0 0 0 auto; border-radius: var(--radius-lg) 0 0 var(--radius-lg); overflow: hidden; }
.automation-record-dialog[open] { animation: automation-record-drawer-in var(--dur) var(--ease); }
.automation-record-dialog-shell { display: flex; flex-direction: column; height: 100%; min-height: 0; padding: 24px; }
.automation-record-dialog-shell .publish-dialog-heading { flex: 0 0 auto; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.automation-record-dialog-shell h2 { font-size: var(--fs-lg); }
.automation-record-dialog-shell p { margin-top: 4px; color: var(--secondary); font-size: var(--fs-xs); }
.automation-record-history { flex: 1; min-height: 0; overflow-y: auto; padding-top: 8px; scrollbar-gutter: stable; }
@keyframes automation-record-drawer-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }

.toast { position: fixed; right: 20px; bottom: calc(var(--statusbar-h) + 12px); z-index: var(--z-toast); max-width: 360px; padding: 12px 12px; border-radius: var(--radius-md); background: var(--text); color: var(--canvas); font-size: var(--fs-sm); box-shadow: var(--shadow-toast); opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease); }
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast.is-error { background: var(--error); }

/* ---------- responsive ---------- */

@media (max-width: 1100px) {
  /* Names and short states stay, with tighter padding. 範例模式 · 不會實際傳送 never shrinks (the top-bar badge drops its detail here);
     platforms that do not fit scroll inside the bar as on wider windows. */
  .status-bar { gap: 2px; }
  .status-item { gap: 4px; padding: 0 6px; }
  .status-sample, .status-ai { flex: none; }
  .status-platforms .status-item { height: 20px; }
  /* The status bar already says 不會實際傳送; the top bar keeps the short badge. */
  .preview-badge-detail { display: none; }
}
/* Browsers without ::-webkit-scrollbar (Firefox) get their own thin, always-coloured scrollbar. */
@supports not selector(::-webkit-scrollbar) {
  .status-platforms { scrollbar-width: thin; scrollbar-color: var(--control-border-hover) var(--line); }
}
@media (max-width: 1000px) {
  :root { --w-context: 184px; --w-chat-list: 232px; }
  .sidebar > .filter-row, .sidebar-filters { padding-inline: 8px; }
}
@media (max-width: 1200px) {
  .brand-logo { display: none; }
  .brand-mark { display: block; }
}
@media (max-width: 960px) {
  .topbar { gap: 12px; padding: 0 16px; }
  .nav-link { padding: 0 8px; }
  .nav-link[aria-current="page"]::after { left: 8px; right: 8px; }
}
@media (max-width: 760px) {
  .nav-label { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
}
/* Phones: the five workspaces move to their own row under the brand and account controls; counts become corner marks. */
@media (max-width: 640px) {
  /* 44px workspace row plus the top bar's 1px bottom hairline. */
  :root { --header-h: calc(var(--toolbar-h) + 45px); }
  .topbar { flex-wrap: wrap; gap: 0 8px; height: auto; padding: 0 8px; }
  .brand { height: var(--toolbar-h); }
  .topbar-actions { gap: 4px; }
  .top-nav { order: 3; flex: 1 0 100%; height: 44px; justify-content: space-around; gap: 0; margin: 0 -8px; border-top: 1px solid var(--line); }
  .nav-link { justify-content: center; flex: 1 1 0; padding: 0 8px; }
  .nav-link[aria-current="page"]::after { left: 25%; right: 25%; }
  .nav-count { position: absolute; top: 4px; left: calc(50% + 4px); min-width: 16px; height: 16px; padding: 0 4px; line-height: 16px; }
  .status-bar .status-platform { display: none; }
  .status-bar .status-summary { display: inline-flex; }
  /* The summary never gives way; the short place sentence (已登入, 範例 · 不會實際傳送 …) is flex: none above, never cut. */
  .status-bar .status-platforms { flex: none; }
}

@media (max-width: 1050px) {
  .workspace-canvas { --canvas-gutter: 24px; --canvas-max: 1fr; --canvas-aside: 0px; --canvas-gap: 0px; }
  .view-panel:not(.canvas-view) { padding-inline: 24px; }
}

@media (max-width: 850px) {
  .app-shell, .app-shell:has(.body-layout.is-wide) { display: block; }
  .body-layout { display: block; }
  .sidebar, #inbox-sidebar, #broadcasts-sidebar { position: static; width: auto; height: auto; display: flex; }
  .app-shell:has(.body-layout.is-wide) .sidebar { display: none; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); max-height: 50vh; overflow-y: auto; }
  .sidebar-footer { display: none; }
  .topbar { position: static; }
  /* Section rows sit in one scrollable line above the work area. */
  .context-list { flex-direction: row; gap: 4px; padding-bottom: 12px; overflow-x: auto; scrollbar-width: none; }
  .context-group { display: flex; gap: 4px; }
  .context-group + .context-group { margin-top: 0; padding-left: 4px; border-left: 1px solid var(--line); }
  .context-title { display: none; }
  .context-row { width: auto; white-space: nowrap; }
  .main-content { padding: 0 0 40px; }
  .workspace-canvas { --canvas-gutter: 16px; }
  .view-panel:not(.canvas-view) { padding-inline: 16px; }
  .workflow-tab-row { position: static; margin: 0 0 16px; padding: 0 16px; overflow-x: auto; }
  
  .editor-tabs { gap: 16px; }
  
  
  
   .credential-fields, .selection-fields, .settings-field-pair, .settings-select-grid, .callback-row { grid-template-columns: minmax(0, 1fr); }
  .automation-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .automation-field-grid { grid-template-columns: minmax(0, 1fr); }
  .automation-link-fields { grid-template-columns: minmax(0, 1fr); }
  .automation-detail-empty { padding-block: 40px; }
  .automation-choice-body { padding-left: 0; }
  .automation-record-picker-heading { align-items: center; }
  .automation-record-card { grid-template-columns: 56px minmax(0, 1fr) 20px; gap: 8px; min-height: 72px; }
  .automation-record-thumb { width: 56px; height: 56px; }
  .automation-record-dialog { width: 100vw; border-radius: 0; }
  .automation-record-dialog-shell { padding: 16px; }
  
  
  
  
  
  .operation-row { flex-wrap: wrap; }
  .operation-row > div { flex: 1 1 calc(100% - 20px); }
  .operation-row > time, .operation-row > .text-button { margin-left: 16px; }
  .operation-row > time + .text-button { margin-left: 0; }
  .automation-action-bar { bottom: 8px; }
  
  .toast { left: 16px; right: 16px; max-width: none; }
}

/* ---------- 待辦 · 群發 ----------
   Both open with a page header on the ground (name, counts, the view's own actions — no bar, no rule).
   待辦 = 開始前三步, a segmented view switch, two columns of white cards (待確認｜待辦); the detail is a 340px panel on the right
   from 1180px, a 380px drawer below that. 群發 = a 200px context column of records, 內容｜收件人 panels, the 傳送間隔 row
   and a bottom bar whose one primary button builds the per-customer preview. */
.work-number { font-variant-numeric: tabular-nums; font-size: var(--fs-xs); }
.work-check { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-sm); white-space: nowrap; }
.work-check input, .work-recipient input { width: 16px; height: 16px; flex-shrink: 0; }

/* Page header: the workspace name with its counts on the left, status text and actions on the right. */
.workflow-tab-row.page-header { position: static; z-index: auto; min-height: 0; margin: 0; padding: 16px 24px 12px; gap: 12px 24px; background: transparent; border-bottom: 0; }
.page-heading { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; min-width: 0; }
.page-heading h2 { font-size: var(--fs-xl); font-weight: 600; line-height: 1.5; }
.page-count { font-size: var(--fs-sm); color: var(--secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }
.page-lead { flex-basis: 100%; font-size: var(--fs-sm); color: var(--secondary); }
.archive-links { display: inline-flex; align-items: center; gap: 8px; padding-left: 12px; border-left: 1px solid var(--line); font-size: var(--fs-sm); color: var(--secondary); white-space: nowrap; }
.archive-link { padding: 0; border: 0; background: transparent; color: var(--secondary); font-size: var(--fs-sm); }
.archive-link span { font-variant-numeric: tabular-nums; }
.archive-link:hover { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
/* The archive view that is open is the current place: accent, semibold; 回到看板 appears next to it. */
.archive-link[aria-current] { color: var(--accent); font-weight: 600; }
.archive-back { padding: 0; border: 0; background: transparent; color: var(--accent); font-size: var(--fs-sm); white-space: nowrap; }
.archive-back:hover { color: var(--accent-hover); text-decoration: underline; text-underline-offset: 3px; }
.page-actions { flex: 0 1 auto; flex-wrap: wrap; justify-content: flex-end; gap: 8px 12px; min-width: 0; }
.run-state { max-width: 52ch; font-size: var(--fs-xs); line-height: 1.5; color: var(--secondary); font-variant-numeric: tabular-nums; text-align: right; overflow-wrap: anywhere; }

/* Split button: the action on the left, its options under the arrow. */
.split-button { position: relative; display: inline-flex; flex: none; }
.split-button > .button:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.split-toggle { width: var(--control-h); padding: 0; border-left-color: var(--accent-hover); border-radius: 0 var(--radius) var(--radius) 0; }
.split-toggle svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; transition: transform var(--dur) var(--ease); }
.split-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }
.analyze-menu { display: grid; gap: 8px; width: 280px; padding: 12px; }
.menu-field { display: grid; gap: 4px; }
.menu-field > span:first-child { font-size: var(--fs-xs); font-weight: 600; color: var(--secondary); }
.menu-field select { font-size: var(--fs-sm); }
.analyze-menu hr { margin: 0; border: 0; border-top: 1px solid var(--line); }
.menu-check { min-height: var(--control-h); }
.menu-note { font-size: var(--fs-xs); line-height: 1.5; color: var(--secondary); }

/* 開始前三步: a white panel with three steps side by side. Ticks only come from saved data. */
.onboarding { margin: 0 24px; }
.onboarding-card { padding: 16px 20px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--canvas); }
.onboarding-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; }
.onboarding-head h3 { font-size: var(--fs-lg); font-weight: 600; }
.onboarding-head p { font-size: var(--fs-sm); color: var(--secondary); }
.onboarding-tools { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; }
.onboarding-tools .button-quiet { height: var(--control-h-sm); padding: 0 8px; }
.onboarding-steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 12px 0 0; padding: 0; list-style: none; }
.onboarding-step { display: grid; grid-template-columns: 24px minmax(0, 1fr); grid-template-rows: auto 1fr auto; align-content: start; gap: 4px 8px; padding: 12px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--canvas); }
.onboarding-step .step-mark { grid-row: 1 / span 3; width: 24px; height: 24px; margin: 0; border: 0; background: var(--canvas); box-shadow: inset 0 0 0 1px var(--control-border-hover); color: var(--secondary); vertical-align: baseline; }
.onboarding-step .step-mark.is-current { background: var(--accent); box-shadow: none; color: var(--canvas); }
.onboarding-step .step-mark.is-done { background: var(--chip); box-shadow: none; color: var(--accent); }
.onboarding-step h4 { font-size: var(--fs-md); font-weight: 600; }
.onboarding-step p { font-size: var(--fs-sm); line-height: 1.5; color: var(--secondary); }
.onboarding-step-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 4px; }
.onboarding-step-foot .button { height: var(--control-h-sm); padding: 0 8px; }
.onboarding-state { font-size: var(--fs-xs); font-weight: 600; color: var(--secondary); }
.onboarding-state.is-done { color: var(--accent); }
.onboarding-recall { display: flex; align-items: center; gap: 8px; margin: 0; font-size: var(--fs-xs); color: var(--secondary); }
.onboarding-recall .text-button { margin-left: -4px; font-size: var(--fs-xs); }

/* Step marks: the number of each step, accent while it is the current one, a check once done. */
.step-mark { display: inline-grid; place-items: center; flex: 0 0 auto; width: 22px; height: 22px; margin-right: 8px; border: 1.5px solid var(--control-border); border-radius: 50%; background: var(--canvas); color: var(--secondary); font-weight: 600; font-size: var(--fs-xs); line-height: 1; font-variant-numeric: tabular-nums; vertical-align: 2px; }
.step-mark.is-current { border-color: var(--accent); background: var(--accent); color: var(--canvas); }
.step-mark.is-done { border-color: var(--chip); background: var(--chip); color: var(--accent); }

/* Guidance: an empty state that teaches the steps, and a callout that says what to do next. */
.work-guide-empty { max-width: 640px; margin: 32px auto; padding: 32px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--canvas); text-align: left; }
.work-guide-empty h3 { font-size: var(--fs-xl); font-weight: 600; letter-spacing: -.01em; margin: 0 0 8px; }
.work-guide-empty > p { margin: 0 0 20px; font-size: var(--fs-md); line-height: 1.6; color: var(--text); }
.work-guide-steps { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; counter-reset: guide; }
.work-guide-steps li { display: grid; grid-template-columns: 30px minmax(0, 1fr); column-gap: 12px; counter-increment: guide; }
.work-guide-steps li::before { content: counter(guide); grid-row: 1 / 3; display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--chip); color: var(--accent-hover); font-weight: 600; font-size: var(--fs-sm); line-height: 1; font-variant-numeric: tabular-nums; }
.work-guide-steps strong { font-size: var(--fs-md); }
.work-guide-steps span { font-size: var(--fs-sm); color: var(--secondary); line-height: 1.5; }
.work-guide { display: flex; flex-direction: column; gap: 4px; margin: 16px 0; padding: 12px 16px; border-radius: var(--radius-md); background: var(--chip); color: var(--accent-hover); }
.work-guide strong { font-size: var(--fs-md); }
.work-guide span { font-size: var(--fs-sm); line-height: 1.6; color: var(--text); }
.work-guide.is-alert { background: var(--warning-surface); color: var(--warning); box-shadow: inset 0 0 0 1px var(--update); }

/* 待辦: the page uses the full width up to 1600px; the open detail panel takes 340px on the right. */
.tasks-canvas { --canvas-gutter: minmax(0, 1fr); --canvas-max: 1600px; }
@media (min-width: 1180px) {
  body:has(#task-dialog[open]:not(:modal)) .tasks-view { padding-right: 340px; }
  body:has(#studio-contact[open]:not(:modal)) .inbox-view { padding-right: 340px; }
}
.task-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 16px 24px 0; }
.task-views { flex: 0 1 auto; max-width: 100%; }
.task-views button { flex: 0 0 auto; }
.task-views button span { margin-left: 4px; }
.task-toolbar .compact-select select { width: 132px; }
.task-search { width: 200px; margin-left: auto; }
.task-search input:not([type="checkbox"]):not([type="radio"]):not([type="file"]) { font-size: var(--fs-sm); }

/* Two columns of white cards; each column heading says its name, count and job on one line. */
.task-board { padding: 16px 24px 24px; }
.task-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.task-column { min-width: 0; }
.task-column-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; margin-bottom: 8px; }
.task-column-head h3 { font-size: var(--fs-lg); font-weight: 600; }
.task-column-count { font-size: var(--fs-sm); color: var(--secondary); }
.task-column-head p { font-size: var(--fs-xs); color: var(--secondary); }
.task-cards { display: grid; gap: 12px; }
.task-cards-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); align-items: start; }
.task-column-empty { padding: 24px 16px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--muted); font-size: var(--fs-sm); line-height: 1.6; color: var(--secondary); text-align: center; }
.task-group-title { margin-top: 12px; font-size: var(--fs-sm); font-weight: 600; color: var(--secondary); }

/* Task card: 12px corners, a 1px hairline, no shadow; the selected card has the accent frame on the selected tint. */
.task-card { display: grid; gap: 4px; min-width: 0; padding: 12px 16px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--canvas); transition: border-color var(--dur) var(--ease); }
.task-card:hover { border-color: var(--control-border-hover); }
.task-card.is-selected, .task-card.is-selected:hover { border-color: var(--accent); background: var(--selected); }
.task-card-title { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: var(--fs-md); font-weight: 600; line-height: 1.45; overflow-wrap: anywhere; }
.task-card-title button { padding: 0; border: 0; background: transparent; color: inherit; font-weight: inherit; line-height: inherit; text-align: left; }
.task-card-title button:hover, .task-card-title button.is-active { color: var(--accent-hover); }
.task-card-title button:hover { text-decoration: underline; text-decoration-color: var(--control-border-hover); text-underline-offset: 3px; }
.task-card-src { max-width: none; overflow: hidden; font-size: var(--fs-sm); color: var(--secondary); text-overflow: ellipsis; white-space: nowrap; }
.task-card-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: var(--fs-xs); color: var(--secondary); }
.task-card-update { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-top: 4px; font-size: var(--fs-xs); color: var(--update-text); }
.task-card-actions { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 0 -8px; }
/* Card actions: 24px frameless text buttons; the card's main step is the accent, the rest stay secondary. */
.card-action { height: 24px; padding: 0 8px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--secondary); font-size: var(--fs-sm); white-space: nowrap; transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease); }
.card-action:hover { background: var(--chip); color: var(--text); }
.card-action.is-go { color: var(--accent); font-weight: 600; }
.card-action.is-go:hover { color: var(--accent-hover); }

/* Tags: 20px, 4px corners. Blue = today, amber = overdue, outline = a plain state such as 等對方. */
.tag { display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 6px; border-radius: var(--radius-sm); background: var(--ground); color: var(--secondary); font-size: var(--fs-xs); white-space: nowrap; }
.tag-blue { background: var(--chip); color: var(--accent); }
.tag-warn { background: var(--warning-surface); color: var(--warning); font-weight: 600; }
.tag-outline { background: var(--canvas); box-shadow: inset 0 0 0 1px var(--control-border); }

/* Task detail: a non-modal panel under the top bar from 1180px (a hairline on its left), a modal drawer below that. */
.task-detail-dialog { position: fixed; inset: var(--toolbar-h) 0 var(--statusbar-h) auto; z-index: 5; width: 340px; height: auto; max-width: none; max-height: none; margin: 0; padding: 0; overflow: hidden; border: 0; border-left: 1px solid var(--line); border-radius: 0; background: var(--canvas); box-shadow: none; }
.task-detail-dialog[open] { display: flex; flex-direction: column; }
.task-detail-dialog:modal { inset: 0 0 0 auto; width: min(380px, 100vw); height: 100dvh; max-height: 100dvh; border-left: 0; border-radius: var(--radius-lg) 0 0 var(--radius-lg); box-shadow: var(--shadow-dialog); }
body:not([data-view="tasks"]) .task-detail-dialog:not(:modal) { display: none; }
.work-dialog-head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; padding: 8px 12px 8px 16px; border-bottom: 1px solid var(--line); }
.work-dialog-head h2 { font-size: var(--fs-md); font-weight: 600; margin: 0; }
.work-dialog-head .button { height: var(--control-h-sm); padding: 0 8px; }
.work-dialog-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.task-detail-dialog .work-sheet { padding: 16px; border: 0; border-radius: 0; }
.task-detail-dialog .work-sheet-heading { flex-wrap: wrap; gap: 8px; }
.task-detail-dialog .work-sheet-heading h2 { font-size: var(--fs-lg); }
.task-detail-dialog .work-actions { gap: 8px; }
.task-detail-dialog .work-fields { grid-template-columns: minmax(0, 1fr); }
/* 個人資料 (聊天室): the same two modes as 事項詳情, reusing its head and body. The account and tags line sits after the
   title and gives way first; the form is one column like 事項詳情. Outside the chat the panel never shows. */
.profile-dialog { position: fixed; inset: var(--toolbar-h) 0 var(--statusbar-h) auto; z-index: 5; width: 340px; height: auto; max-width: none; max-height: none; margin: 0; padding: 0; overflow: hidden; border: 0; border-left: 1px solid var(--line); border-radius: 0; background: var(--canvas); box-shadow: none; }
.profile-dialog[open] { display: flex; flex-direction: column; }
body:not([data-view="inbox"]) .profile-dialog:not(:modal) { display: none; }
.profile-dialog:modal { inset: 0 0 0 auto; width: min(380px, 100vw); height: 100dvh; max-height: 100dvh; border-left: 0; border-radius: var(--radius-lg) 0 0 var(--radius-lg); box-shadow: var(--shadow-dialog); }
.profile-dialog .work-dialog-head { justify-content: flex-start; gap: 8px; }
.profile-dialog .work-dialog-head h2 { white-space: nowrap; }
.profile-dialog .work-dialog-head span { flex: 1 1 auto; min-width: 0; overflow: hidden; font-size: var(--fs-xs); color: var(--secondary); text-overflow: ellipsis; white-space: nowrap; }
.profile-dialog .work-dialog-head .button { flex: 0 0 auto; }
.profile-dialog .studio-contact-body { padding: 16px; scrollbar-gutter: stable; }
.profile-dialog .studio-field-pair, .profile-dialog .studio-custom-row { grid-template-columns: minmax(0, 1fr); }
.profile-dialog .text-button { white-space: normal; text-align: left; }

/* Shared sheet, forms, updates and sources */
.work-actions, .work-recipient-tools { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; }
.work-sheet { padding: 24px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--canvas); }
.work-sheet-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 16px; }
.work-sheet-heading h2 { font-size: var(--fs-xl); font-weight: 600; letter-spacing: -.01em; margin: 0; overflow-wrap: anywhere; }
.work-sheet-heading p { font-size: var(--fs-sm); margin: 6px 0 0; color: var(--secondary); }
.work-actions { margin: 16px 0; }
.work-form { display: flex; flex-direction: column; gap: 16px; }
.work-form label, .work-fields label { display: flex; flex-direction: column; gap: 6px; min-width: 0; font-size: var(--fs-sm); font-weight: 600; }
.work-form input, .work-form select, .work-form textarea { width: 100%; min-width: 0; font-weight: 400; }
.work-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.work-source { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--line); }
.work-source summary { cursor: pointer; font-weight: 600; font-size: var(--fs-sm); }
.work-source blockquote, .work-update blockquote { margin: 12px 0; padding: 12px 16px; background: var(--muted); color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; font-size: var(--fs-md); }
.work-update { margin: 20px 0; padding: 16px; background: var(--warning-surface); border: 1px solid var(--line); border-radius: var(--radius-md); }
.work-update h3 { font-size: var(--fs-lg); margin: 0 0 8px; }

/* 群發 context column: 建立群發 on top, then 進行中 and 最近 records, a one-line reminder at the foot. */
#broadcasts-sidebar .sidebar-heading { display: block; padding: 16px 8px; }
#broadcasts-sidebar .sidebar-heading h1 { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.broadcast-new { width: 100%; }
.broadcast-modes { display: none; }
.broadcast-records { padding: 0 8px; }
.broadcast-record { display: grid; grid-template-columns: 8px minmax(0, 1fr); align-items: center; gap: 0 8px; width: 100%; padding: 6px 8px; border: 0; border-radius: var(--radius); background: transparent; color: var(--text); text-align: left; transition: background-color var(--dur) var(--ease); }
.broadcast-record .dot { grid-row: 1; }
.broadcast-record:hover { background: var(--chip); }
.broadcast-record.is-active { background: var(--nav-active); }
.broadcast-record strong { overflow: hidden; font-size: var(--fs-md); font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.broadcast-record-sub { grid-column: 2; overflow: hidden; font-size: var(--fs-xs); color: var(--secondary); text-overflow: ellipsis; white-space: nowrap; }
.context-foot { margin-top: auto; padding: 16px; font-size: var(--fs-xs); line-height: 1.6; color: var(--secondary); }

/* 群發 main area: header, then the scrolling form on the ground (max 1120px), then the bottom bar. */
.main-content:has(> #broadcasts-view:not([hidden])) { padding-bottom: 0; }
.broadcast-canvas { display: flex; flex-direction: column; height: calc(100dvh - var(--header-h) - var(--statusbar-h)); min-height: 0; }
.workflow-tab-row.broadcast-head { flex: none; padding-inline: max(24px, calc((100% - 1120px) / 2 + 24px)); }
.broadcast-head .page-heading { flex: 1 1 320px; }
.broadcast-compose { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.broadcast-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.broadcast-inner { max-width: 1120px; margin: 0 auto; padding: 4px 24px 24px; }
.broadcast-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: stretch; }
.broadcast-panel { min-width: 0; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--canvas); }
.panel-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 12px; }
.panel-head h3 { font-size: var(--fs-lg); font-weight: 600; }
.panel-aside { margin-left: auto; font-size: var(--fs-xs); color: var(--secondary); white-space: nowrap; }
.panel-stack { display: grid; gap: 12px; }
.broadcast-field { display: grid; gap: 4px; min-width: 0; }
.broadcast-field > label { font-size: var(--fs-sm); font-weight: 500; }
.broadcast-field small { font-size: var(--fs-xs); color: var(--secondary); }
.textarea-tools { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: var(--fs-xs); color: var(--secondary); }
.textarea-tools-start { display: inline-flex; align-items: center; gap: 2px; margin-left: -8px; }
.broadcast-preview-toggle > summary { color: var(--accent); cursor: pointer; font-size: var(--fs-sm); }
.broadcast-preview { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; margin-top: 8px; padding: 12px; border-radius: var(--radius-md); background: var(--ground); }
.broadcast-preview-who { align-self: flex-start; font-size: var(--fs-xs); color: var(--secondary); }
.broadcast-bubble { max-width: min(420px, 100%); margin: 0; padding: 8px 12px; border-radius: 16px 4px 16px 16px; background: var(--chat-self); color: var(--chat-self-text); font-size: var(--fs-md); line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.broadcast-bubble.is-empty { background: var(--canvas); color: var(--secondary); box-shadow: inset 0 0 0 1px var(--line); }

/* 收件人: platform and its rule, search, tags, select tools, then a scrolling list of customers (max 296px). */
.broadcast-people { display: flex; flex-direction: column; }
.broadcast-tags { gap: 4px; }
.work-recipient-tools { gap: 8px; }
.work-recipients { flex: 1 1 auto; min-height: 0; max-height: 296px; margin-top: 4px; overflow-y: auto; overscroll-behavior: contain; border-top: 1px solid var(--line); }
.work-recipient { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 6px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.work-recipient:hover { background: var(--muted); }
.work-recipient.is-excluded { cursor: default; }
.work-recipient.is-excluded:hover { background: transparent; }
.work-recipient-copy { display: grid; flex: 1; min-width: 0; }
.work-recipient strong { overflow: hidden; font-size: var(--fs-md); font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.work-recipient.is-excluded strong { font-weight: 500; color: var(--secondary); }
.work-recipient small { display: block; font-size: var(--fs-xs); color: var(--secondary); overflow-wrap: anywhere; }
.work-recipient-note .board-flag { vertical-align: middle; }
.work-recipients .sidebar-empty { padding: 24px 8px; }

/* 傳送間隔: one summary row (每 n 秒一位) and 修改…; the choices open under it. */
.broadcast-interval { margin-top: 16px; padding: 12px 20px; }
.interval-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; }
.interval-row h3 { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-lg); font-weight: 600; }
.interval-summary { font-size: var(--fs-sm); color: var(--secondary); }
.interval-row > .button { margin-left: auto; }
.interval-body { display: grid; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.interval-label { font-size: var(--fs-sm); font-weight: 500; }
.broadcast-intervals { justify-self: start; max-width: 100%; flex-wrap: wrap; }
.broadcast-intervals button { flex: 0 0 auto; min-width: 64px; }
.broadcast-interval-custom { max-width: 240px; }

/* Bottom bar: what is still missing on the left, the one primary button on the right. */
.broadcast-dock { flex: none; display: flex; align-items: center; gap: 12px; padding: 12px 24px; background: var(--canvas); border-top: 1px solid var(--line); }
.broadcast-next { min-width: 0; max-width: none; font-size: var(--fs-sm); line-height: 1.5; color: var(--secondary); }
.broadcast-next b, .broadcast-next strong { font-weight: 600; color: var(--text); }
.broadcast-next strong { display: block; }
.broadcast-dock .button { flex: none; min-width: 96px; margin-left: auto; }

/* 群發 record: header, progress, what to do next, then each customer. */
.broadcast-detail { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 4px 24px 32px; }
.broadcast-detail > .work-sheet { max-width: 1072px; margin: 0 auto; }
.broadcast-progress { display: flex; flex-direction: column; gap: 8px; }
.broadcast-progress-bar { width: 100%; height: 8px; border: 0; border-radius: var(--radius-sm); background: var(--track); overflow: hidden; appearance: none; -webkit-appearance: none; }
.broadcast-progress-bar::-webkit-progress-bar { background: var(--track); border-radius: var(--radius-sm); }
.broadcast-progress-bar::-webkit-progress-value { background: var(--accent); border-radius: var(--radius-sm); }
.broadcast-progress-bar::-moz-progress-bar { background: var(--accent); border-radius: var(--radius-sm); }
.broadcast-progress .work-number { margin: 0; color: var(--text); }
.broadcast-progress b { font-weight: 500; }
.broadcast-progress b.is-error { color: var(--error); font-weight: 600; }
.broadcast-job .work-actions { margin-top: 0; }
.work-deliveries { margin-top: 16px; border-top: 1px solid var(--control-border); }
.work-delivery { display: grid; grid-template-columns: 150px minmax(0, 1fr) 190px; gap: 16px; align-items: start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.work-delivery-who { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; min-width: 0; }
.work-delivery-who strong { font-size: var(--fs-md); overflow-wrap: anywhere; }
.work-message { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; padding: 12px 12px; background: var(--muted); border-radius: var(--radius); font-size: var(--fs-sm); line-height: 1.6; }
.work-delivery-meta { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-width: 0; }
.work-delivery-meta .text-button { margin-left: -6px; }

@media (max-width: 1100px) {
  .broadcast-grid { grid-template-columns: minmax(0, 1fr); }
  .work-delivery { grid-template-columns: 130px minmax(0, 1fr); }
  .work-delivery-meta { grid-column: 2; }
}
@media (max-width: 1050px) {
  .onboarding-steps { grid-template-columns: minmax(0, 1fr); gap: 8px; }
}
@media (max-width: 960px) {
  .workflow-tab-row.page-header { padding: 16px 16px 12px; }
  .workflow-tab-row.broadcast-head { padding-inline: 16px; }
  .onboarding { margin-inline: 16px; }
  .task-toolbar { padding-inline: 16px; }
  .task-board { padding: 12px 16px 24px; gap: 12px; }
  .task-columns { gap: 12px; }
  .task-column-head p { display: none; }
  .broadcast-inner { padding: 4px 16px 16px; }
  .broadcast-detail { padding-inline: 16px; }
  .broadcast-dock { padding: 12px 16px; }
}
/* Narrow windows and phones: columns stack; 群發 flows with the page — the context column becomes a 建立／紀錄 switch on top,
   the customer list is at most half the window high and the bar sits at the end of the form, never over it. */
@media (max-width: 850px) {
  .task-columns { grid-template-columns: minmax(0, 1fr); }
  .main-content:has(> #broadcasts-view:not([hidden])) { padding-bottom: 40px; }
  .broadcast-canvas { display: block; height: auto; }
  .broadcast-compose { display: block; }
  .broadcast-scroll, .broadcast-detail { overflow: visible; }
  .work-recipients { max-height: 50vh; }
  .broadcast-dock { flex-wrap: wrap; margin: 0 16px; border: 1px solid var(--line); border-radius: var(--radius-lg); }
  #broadcasts-sidebar .sidebar-heading { padding: 12px 16px; }
  .broadcast-new { display: none; }
  .broadcast-modes { display: flex; }
  #broadcasts-sidebar[data-pane="compose"] .broadcast-records, #broadcasts-sidebar[data-pane="compose"] .context-foot { display: none; }
  .broadcast-records { padding: 0 8px 8px; }
  .context-foot { padding-top: 8px; }
  .work-sheet { padding: 16px; }
  .work-fields { grid-template-columns: minmax(0, 1fr); }
  .work-sheet-heading { flex-wrap: wrap; }
  .work-guide-empty { margin: 16px 0; padding: 20px; }
  .work-delivery { grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .work-delivery-who { flex-direction: row; align-items: center; justify-content: space-between; }
  .work-delivery-meta { grid-column: auto; }
}
@media (max-width: 640px) {
  /* The analysis state sits beside 分析對話 instead of on its own line, so the first card shows on a 667px-tall phone. */
  .page-actions { width: 100%; flex-wrap: nowrap; align-items: center; justify-content: space-between; margin-left: 0; }
  .run-state { flex: 1 1 0; min-width: 0; max-width: none; text-align: left; }
  .page-actions .split-button { margin-left: auto; }
  .task-views { flex-wrap: wrap; }
  .task-search { width: 100%; margin-left: 0; }
  .onboarding-tools { margin-left: 0; width: 100%; justify-content: space-between; }
  /* Touch: the frameless card actions keep a 32px target. */
  .card-action { height: 32px; }
  .broadcast-dock .button { width: 100%; }
}

/* Browser-only fixture navigator; inherits the existing dialog and board grammar. */
.demo-dialog { width: min(920px, calc(100vw - 32px)); max-height: 88vh; padding: 0; border: 0; border-radius: var(--radius-lg); background: var(--canvas); color: var(--text); box-shadow: var(--shadow-dialog); }
.demo-dialog-header { position: sticky; top: 0; z-index: 1; display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding: 24px; border-bottom: 1px solid var(--line); background: var(--canvas); }
.demo-dialog-header h2 { margin: 0; font-size: var(--fs-xl); }
.demo-dialog-header p { max-width: 640px; margin: 8px 0 0; font-size: var(--fs-sm); color: var(--secondary); line-height: 1.6; }
.demo-dialog-header button { flex-shrink: 0; }
.demo-group-controls { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.demo-group-controls [aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--canvas); }
.demo-groups { padding: 24px; }
.demo-group { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 24px; }
.demo-group h3 { grid-column: 1 / -1; font-size: var(--fs-lg); margin: 0 0 12px; }
.demo-scene { display: block; width: 100%; padding: 12px; text-align: left; color: var(--text); border: 0; border-bottom: 1px solid var(--line); background: var(--canvas); cursor: pointer; }
.demo-scene:hover { background: var(--chip); }
.demo-scene.is-active { background: var(--chip); color: var(--accent-hover); }
.demo-scene strong { display: block; font-size: var(--fs-md); font-weight: 600; }
.demo-scene span { display: block; margin-top: 4px; color: var(--secondary); font-size: var(--fs-xs); line-height: 1.6; }
@media (max-width: 850px) {
  .is-preview .topbar-actions { gap: 4px; }
  .is-preview .topbar-actions .button { padding-inline: 8px; }
  .is-preview .preview-badge { padding-inline: 6px; }
  .demo-dialog-header { padding: 16px; gap: 8px; }
  .demo-groups { padding: 16px; }
  .demo-group { grid-template-columns: minmax(0, 1fr); }
}

.platform-glyph { vertical-align: middle; }
.platform-select-wrap { position: relative; display: block; min-width: 0; width: 100%; }
.platform-select-wrap > .platform-glyph { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 20px; height: 20px; pointer-events: none; }
.platform-select-wrap.has-platform > select { padding-left: 38px; }
.whatsapp-options > summary { color: var(--accent); font-size: var(--fs-sm); font-weight: 600; cursor: pointer; padding: 4px 0; }
.whatsapp-options-fields { display: grid; gap: 8px; padding: 8px 0; }
.whatsapp-options-fields > .text-button { justify-self: start; }
.whatsapp-cost-row { display: flex; align-items: center; gap: 6px; }
.whatsapp-cost-row > p { flex: 1; }
.whatsapp-delivery-head strong { font-weight: 500; }

.whatsapp-send-summary { display: grid; gap: 4px; }
.whatsapp-send-summary p { margin: 0; }
.whatsapp-send-summary .field-hint:empty { display: none; }

/* ---------- 新訊息提醒 ---------- */
/* Reminder settings live next to the board heading; the notice under it is yellow because it means "new" or "about to expire". */
.icon-button.is-on { color: var(--accent); }
.inbox-alert-panel { display: grid; gap: 8px; margin: 0 16px 12px; padding: 12px 12px; border: 1px solid var(--control-border-hover); border-radius: var(--radius-md); background: var(--canvas); }
.inbox-alert-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.inbox-alert-panel-head h2 { margin: 0; font-size: var(--fs-lg); font-weight: 600; }
.inbox-alert-panel-head .button-quiet { height: var(--control-h-sm); padding-inline: 8px; }
.alert-setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.alert-setting-row > span { min-width: 0; }
.alert-setting-row strong { display: block; font-size: var(--fs-sm); font-weight: 600; }
.alert-setting-row small { display: block; font-size: var(--fs-xs); line-height: 1.5; color: var(--secondary); }
.alert-setting-row .switch-button { flex: 0 0 auto; height: var(--control-h-sm); }
/* Sound chosen but not yet allowed by the browser: the knob shows the choice, the neutral track and label say it is not live. */
.switch-button.is-pending > span::after { transform: translateX(14px); }
.alert-setting-row small.alert-sound-waiting { color: var(--text); font-weight: 600; }
.alert-help { margin: 0; padding: 8px 12px; border-radius: var(--radius); background: var(--muted); font-size: var(--fs-xs); line-height: 1.5; color: var(--text); }
.alert-limit { margin: 0; padding-top: 8px; border-top: 1px solid var(--line); font-size: var(--fs-xs); line-height: 1.5; color: var(--text); }
.inbox-alert-notice { margin: 0 16px 12px; padding: 12px 12px; border-radius: var(--radius-md); background: var(--warning-surface); box-shadow: inset 0 0 0 1px var(--update); color: var(--text); }
.inbox-alert-notice-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.inbox-alert-notice-head strong { font-size: var(--fs-sm); font-weight: 600; color: var(--warning); }
.inbox-alert-notice-head .button-quiet { height: var(--control-h-sm); padding-inline: 8px; font-size: var(--fs-xs); }
.inbox-alert-notice ul { display: grid; gap: 2px; margin: 4px 0 0; padding: 0; list-style: none; }
.inbox-alert-notice .text-button { margin-left: -6px; font-size: var(--fs-sm); text-align: left; white-space: normal; }
.inbox-alert-notice small { display: block; margin-top: 4px; font-size: var(--fs-xs); color: var(--warning); }

@media (max-width: 1100px) {
  .inbox-alert-panel, .inbox-alert-notice { margin-inline: 8px; }
}

/* ---------- 聊天室：手機 ---------- */

/* Phones and narrow windows: the list and the conversation are two steps; 返回對話清單 goes back. */
@media (max-width: 850px) {
  body[data-view="inbox"] .main-content { padding-bottom: 0; }
  body[data-view="inbox"]:not(.inbox-show-list) #inbox-sidebar { display: none; }
  body[data-view="inbox"].inbox-show-list .main-content { display: none; }
  body[data-view="inbox"].inbox-show-list #inbox-sidebar { height: calc(100dvh - var(--header-h) - var(--statusbar-h)); max-height: none; overflow-y: auto; }
  .inbox-back { display: inline-grid; flex: 0 0 auto; }
  .conversation-header { gap: 8px; padding: 4px 12px; }
  .inbox-messages { padding: 8px 12px 16px; }
  .inbox-message { max-width: 88%; }
  .inbox-composer { max-height: 50%; padding: 8px 12px 12px; }
}

/* Short windows (820×600, 400×667): the messages keep 96px and the composer tightens. */
@media (max-height: 720px) {
  .inbox-messages { min-height: 96px; }
  .inbox-composer { gap: 4px; padding-block: 8px; }
  .composer-modes { margin-top: 4px; }
  .composer-box textarea { min-height: 40px; padding-top: 4px; }
  .composer-tools { padding-bottom: 4px; }
}

/* ---------- 設定 (R06): five sections in the context column, one 760px column of white panels ---------- */
.context-state { display: inline-flex; align-items: center; margin-left: auto; }
.settings-version { margin-top: auto; font-size: var(--fs-xs); color: var(--secondary); }
.settings-canvas { grid-template-columns: var(--canvas-gutter) minmax(0, var(--canvas-max)) var(--canvas-aside) var(--canvas-gutter); padding-bottom: 32px; }
.settings-canvas > .workflow-tab-row { grid-column: 2; }
/* 設定 on wide screens (使用者 2026-11-03「設定也一起改」): the centred canvas like 聯絡人. Up to 1239px one column of
   at most 760px (851–1050px keeps its 24px sides); from 1240px up to 1360px, and only as columns by what each section
   holds, so no input is stretched across the screen. DOM and Tab order stay as they are. */
@media (min-width: 851px) { .settings-canvas { --canvas-max: 760px; } }
@media (min-width: 1240px) {
  .settings-canvas { --canvas-max: 1360px; }
  /* 準備狀態 and 在這台電腦運行: equal rows in two columns; the last row of each column has no rule under it. */
  .settings-group[data-settings-section="ready"] .status-list,
  .settings-group[data-settings-section="local"] .status-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 32px; }
  .settings-group[data-settings-section="ready"] .status-list li:nth-last-child(2),
  .settings-group[data-settings-section="local"] .status-list li:nth-last-child(2) { border-bottom: 0; }
  /* 社群帳號: the platforms on the left, the chosen platform's tabs and panel on the right. */
  /* The tabs row keeps its own height; when the platform list is taller, the panel's row takes the rest. */
  .settings-group[data-settings-section="accounts"] { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); grid-template-rows: auto 1fr; align-items: start; }
  .settings-group[data-settings-section="accounts"] > .account-picker { grid-column: 1; grid-row: 1 / span 2; }
  .settings-group[data-settings-section="accounts"] > .connections-tabs { grid-column: 2; grid-row: 1; }
  .settings-group[data-settings-section="accounts"] > .connection-panel-stack { grid-column: 2; grid-row: 2; }
  /* AI 設定: 回覆語氣 is the main editor (7), 參考文件 and 進階 sit beside it (5). */
  .settings-group[data-settings-section="ai"] { display: grid; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); grid-template-rows: auto 1fr; align-items: start; }
  .settings-group[data-settings-section="ai"] > #settings-writing { grid-row: 1 / span 2; }
  .settings-group[data-settings-section="ai"] #ai-model { max-width: 320px; }
  /* 店家資料: the name on its own, then the introduction beside 常見顧客 and 回覆目標; the introduction grows to their height. */
  #settings-background .settings-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  #settings-background .settings-fields > .settings-field:first-child { grid-column: 1; grid-row: 1; }
  #settings-background .settings-fields > .settings-field:nth-child(2) { grid-column: 1; grid-row: 2; align-self: stretch; }
  #settings-background .settings-fields > .settings-field:nth-child(2) textarea { flex: 1 1 auto; }
  #settings-background .settings-fields > .settings-field-pair { grid-column: 2; grid-row: 2; grid-template-columns: minmax(0, 1fr); }
  /* 標籤: 新增標籤 on the left, the list on the right. */
  .settings-group[data-settings-section="tags"] { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); align-items: start; }
}
/* 1240–1439px: the sign-in return address would leave its field 171px wide, so its label goes above it. */
@media (min-width: 1240px) and (max-width: 1439px) {
  .settings-group[data-settings-section="accounts"] .callback-row { grid-template-columns: minmax(0, 1fr); }
}
/* The header names the section once; cards below never repeat it. It stays under the top bar so 儲存設定 is in reach. */
.workflow-tab-row.settings-head { position: sticky; top: var(--toolbar-h); z-index: 6; flex-wrap: nowrap; align-items: flex-start; padding: 16px 0 12px; background: var(--ground); }
.settings-head .page-heading { flex: 1 1 auto; }
.settings-head .page-actions { flex: none; display: flex; align-items: center; gap: 8px; padding-top: 2px; }
.settings-head .save-state { margin-left: 0; }
.settings-group { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.settings-section:has(> .status-list) { padding-block: 4px; }
.status-list { margin: 0; padding: 0; list-style: none; }
.status-list li { display: grid; grid-template-columns: 112px minmax(0, 1fr) auto; gap: 12px; align-items: center; min-height: 48px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.status-list li:last-child { border-bottom: 0; }
.status-key { font-size: var(--fs-sm); font-weight: 600; }
.status-value { display: flex; align-items: baseline; gap: 8px; min-width: 0; font-size: var(--fs-sm); line-height: 1.6; overflow-wrap: anywhere; }
.status-value .dot { flex: none; transform: translateY(-1px); }
/* 社群帳號: the platform list is the first panel; the four tabs and their panels follow for the chosen platform. */
.account-picker { gap: 8px; padding: 16px 16px 8px; }
.account-picker .panel-head { align-items: center; margin: 0 8px; }
.account-picker .panel-head .panel-aside { margin-left: 0; }
.account-picker .panel-head .button { margin-left: auto; }
.social-account-list { display: flex; flex-direction: column; gap: 2px; }
.account-picker .social-account-row { width: 100%; margin: 0; }
.account-picker .social-account-row > span:not(.platform-glyph) { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 12px; }
.account-picker .social-account-row small { display: inline; }
.settings-group > .connections-tabs { overflow-x: auto; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.settings-group > .connections-tabs::-webkit-scrollbar { display: none; }
.connections-tabs .editor-tab { flex: none; }

/* 自動回覆 (R06, rules.html): rule rows keep name and trigger on the left and the state tag on the right,
   so the rule column is 240px like the prototype (the shared 200px below 1000px). */
#automations-sidebar { width: 240px; }
@media (max-width: 1000px) { #automations-sidebar { width: var(--w-context); } }
.automation-row { grid-template-columns: 20px minmax(0, 1fr) auto; align-items: center; }
.automation-row .platform-glyph { align-self: start; margin-top: 2px; }
.automation-row strong { font-size: var(--fs-md); }
.automation-row .status-badge { grid-column: 3; grid-row: 1; justify-self: end; }
#automations-sidebar .status-badge.status-archived, .automation-tab-title .status-badge.status-archived { background: var(--ground); box-shadow: none; }
.automation-tab-title h2 { font-size: var(--fs-xl); }
.automation-simulation > summary > span { display: block; margin: 2px 0 0; }

@media (max-width: 850px) {
  .settings-canvas { grid-template-columns: 16px minmax(0, 1fr) 0 16px; }
  .workflow-tab-row.settings-head { position: static; overflow: visible; }
  .account-picker { padding-inline: 8px; }
  #automations-sidebar { width: auto; }
}
@media (max-width: 640px) {
  .workflow-tab-row.settings-head { flex-wrap: wrap; }
  .status-list li { grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; }
  .status-list .status-key { grid-column: 1 / -1; }
}

/* ---------- 聯絡人: a 280px list of the chat's contacts, then the contact on the centred canvas: one 760px column,
   two columns up to 1360px from 1240px (who the person is | what the shop keeps), so a wide screen is not left empty. ---------- */
#contacts-sidebar { width: var(--w-chat-list); }
.contacts-canvas { padding-bottom: 32px; }
/* The header spans the content, so its buttons end where the right column ends. */
.contacts-canvas > .workflow-tab-row { grid-column: 2; }
/* Only from 1051px: below that the shell's --canvas-max: 1fr lets the content fill the window. */
@media (min-width: 1051px) { .contacts-canvas { --canvas-max: 760px; } }
.contacts-sheet { display: flex; flex-direction: column; gap: 16px; padding-bottom: 8px; }
.contacts-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
@media (min-width: 851px) {
  /* 顧客狀態 has six short choices: as wide as one field of a pair, not the whole panel. */
  .contacts-sheet .contact-section select { max-width: calc(50% - 8px); }
}
@media (min-width: 1240px) {
  .contacts-canvas { --canvas-max: 1360px; }
  .contacts-sheet { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
}
/* Platform, customer state, tag and order wrap two to a row in the 280px column. */
.contacts-selects { grid-auto-flow: row; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.contacts-list { gap: 2px; padding: 0 8px 8px; }
.contacts-note { padding: 12px 8px; font-size: var(--fs-xs); color: var(--secondary); }
.contacts-error { margin: 0 4px; }
.contacts-foot p + p { margin-top: 4px; }
/* Contact rows follow the chat rows: 56px, 8px corners, chip on hover, nav-active for the open one. Customer state is text only. */
.contact-row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 8px; border: 0; border-radius: var(--radius-md); background: transparent; color: var(--text); text-align: left; transition: background-color var(--dur) var(--ease); }
.contact-row:hover { background: var(--chip); }
.contact-row.is-active, .contact-row.is-active:hover { background: var(--nav-active); }
.contact-row:hover .inbox-avatar, .contact-row.is-active .inbox-avatar { background: var(--canvas); }
.contact-row-copy { display: flex; flex: 1 1 auto; flex-direction: column; gap: 2px; min-width: 0; }
.contact-row-copy strong, .contact-row-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-row-copy strong { font-size: var(--fs-md); font-weight: 600; line-height: 1.4; }
.contact-row-copy small { font-size: var(--fs-xs); color: var(--secondary); }
.contact-row-when { flex: none; font-size: var(--fs-xs); color: var(--secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }
/* Header: avatar, name and 平台 · 帳號 on the left; save state, 開啟對話 and the one primary 儲存聯絡人資料 on the right. */
.contacts-head { gap: 12px; }
.contacts-back { display: none; }
.contacts-person { display: flex; flex: 1 1 auto; align-items: center; gap: 12px; min-width: 0; }
.contacts-person-text { min-width: 0; }
.contacts-person-text h2 { overflow: hidden; font-size: var(--fs-xl); font-weight: 600; line-height: 1.5; text-overflow: ellipsis; white-space: nowrap; }
.contacts-person-text p { font-size: var(--fs-xs); color: var(--secondary); }
.contacts-save-state { font-size: var(--fs-xs); color: var(--secondary); white-space: nowrap; }
.contacts-save-state.is-error { color: var(--error); white-space: normal; }
.contacts-none { padding: 32px 0; font-size: var(--fs-sm); color: var(--secondary); }
/* The shared form (聯絡人 panels and the chat's 個人資料 sidebar). */
.contact-section { display: flex; flex-direction: column; gap: 12px; }
.contact-section h3 { font-size: var(--fs-md); font-weight: 600; }
.contact-section.settings-section { gap: 16px; padding-block: 20px; }
.contact-section.settings-section h3 { font-size: var(--fs-lg); }
.contact-section .status-value .platform-glyph { align-self: center; }
/* Custom fields: the first row sits 16px under the title like every panel; an empty list takes no room. */
.contact-section .studio-custom-row:first-child { margin-top: 0; }
.contact-custom-list:empty { display: none; }
.contact-field-error { display: block; font-size: var(--fs-xs); color: var(--error); }
/* A field that needs fixing has the error frame; written to outrank the base field rule (0,3,1). */
.studio-field input[aria-invalid="true"]:not([type="checkbox"]):not([type="radio"]) { border-color: var(--error); }
.contact-tags-meta { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.contact-tags-count { margin-left: auto; font-size: var(--fs-xs); color: var(--secondary); font-variant-numeric: tabular-nums; }
.profile-dialog .studio-contact-body > .contact-section + #studio-source-context { margin-top: -4px; }

@media (max-width: 850px) {
  /* The list and the details are two steps, like the chat; 返回聯絡人清單 goes back. */
  #contacts-sidebar { width: auto; }
  body[data-view="contacts"]:not(.contacts-show-list) #contacts-sidebar { display: none; }
  body[data-view="contacts"].contacts-show-list .main-content { display: none; }
  body[data-view="contacts"].contacts-show-list #contacts-sidebar { height: calc(100dvh - var(--header-h) - var(--statusbar-h)); max-height: none; overflow-y: auto; }
  .contacts-back { display: inline-grid; flex: 0 0 auto; }
  .contact-section.settings-section { padding: 16px; }
}
@media (max-width: 640px) {
  .contacts-selects { grid-template-columns: minmax(0, 1fr); }
  /* 返回 and the name share the first row; 開啟對話 and 儲存聯絡人資料 split the second. */
  .contacts-head .contacts-person { flex: 1 1 0; }
  .contacts-head .contacts-actions { display: grid; flex: 1 0 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); margin-left: 0; padding-top: 0; }
  .contacts-head .contacts-save-state { grid-column: 1 / -1; }
}

/* ---------- 標籤 (使用者 2026-11-03): chosen from the shop's list in the contact form, managed in 設定 › 標籤 ---------- */
/* The picker: the chosen tags as chips, 選擇標籤, then a panel inside the form (never floating: the sidebar scrolls). */
.tag-picker { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.tag-picker-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.tag-picker-label { font-size: var(--fs-sm); font-weight: 500; color: var(--text); }
.tag-picker-selected { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-width: 0; }
.tag-picker-chips { display: contents; }
/* A tag is plain data: ground, text colour, no accent. */
.tag-chip { display: inline-flex; align-items: center; gap: 2px; max-width: 100%; height: 24px; padding: 0 2px 0 10px; border-radius: var(--radius-pill); background: var(--ground); color: var(--text); font-size: var(--fs-sm); }
.tag-chip-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag-chip-remove { position: relative; display: inline-grid; place-items: center; flex: none; width: 20px; height: 20px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: var(--secondary); }
.tag-chip-remove svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; }
.tag-chip-remove:hover { background: var(--chip); color: var(--text); }
.tag-picker-toggle[aria-expanded="true"] { background: var(--chip); color: var(--accent); }
.tag-picker-toggle[aria-invalid="true"] { border-color: var(--error); }
.tag-picker-panel { display: flex; flex-direction: column; gap: 8px; padding: 8px; border: 1px solid var(--control-border); border-radius: var(--radius-md); background: var(--canvas); }
.tag-option-list { display: flex; flex-direction: column; gap: 2px; max-height: 240px; overflow-y: auto; overscroll-behavior: contain; }
.tag-option { display: grid; grid-template-columns: 16px minmax(0, 1fr) auto; align-items: center; gap: 8px; min-height: 32px; padding: 4px 8px; border-radius: var(--radius); color: var(--text); font-size: var(--fs-md); cursor: pointer; }
.tag-option:hover { background: var(--chip); }
.tag-option.is-active { background: var(--chip); outline: 2px solid var(--focus); outline-offset: -2px; }
.tag-option[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.tag-option-check { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: var(--radius-sm); background: var(--canvas); box-shadow: inset 0 0 0 1.5px var(--control-border-hover); }
.tag-option[aria-selected="true"] .tag-option-check { background: var(--accent); box-shadow: none; color: var(--canvas); }
.tag-option-check svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tag-option-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag-option-count { font-size: var(--fs-xs); color: var(--secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tag-option.is-create { grid-template-columns: minmax(0, 1fr); color: var(--accent); }
.tag-picker-note { padding: 4px 8px; font-size: var(--fs-xs); color: var(--secondary); }
.tag-picker-manage { align-self: flex-start; }
/* 設定 › 標籤: 新增標籤 (the section's one primary button), then the list with rename and delete on each row. */
.tag-create-row { display: flex; align-items: flex-start; gap: 8px; }
.tag-create-field { flex: 1 1 auto; min-width: 0; }
.tag-create-row > .button { flex: none; }
.tag-create-field input[aria-invalid="true"]:not([type="checkbox"]):not([type="radio"]) { border-color: var(--error); }
.tag-list-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; }
.tag-list-head h2 { font-size: var(--fs-lg); font-weight: 600; }
.tag-list-search { width: 200px; }
.tag-list { display: flex; flex-direction: column; }
.tag-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 12px; min-height: 48px; padding: 8px 0; border-bottom: 1px solid var(--line); transition: background-color 300ms var(--ease); }
.tag-row:last-child { border-bottom: 0; }
.tag-row.is-new { background: var(--selected); }
.tag-row-main { display: contents; }
.tag-row-name { font-size: var(--fs-md); font-weight: 600; overflow-wrap: anywhere; }
.tag-row-count { font-size: var(--fs-xs); color: var(--secondary); font-variant-numeric: tabular-nums; white-space: nowrap; }
.tag-row-actions { display: flex; align-items: center; gap: 4px; }
.tag-row.is-editing { grid-template-columns: minmax(0, 1fr); gap: 4px; }
.tag-rename { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.tag-rename input { flex: 1 1 200px; min-width: 0; height: var(--control-h); }
.tag-rename input[aria-invalid="true"]:not([type="checkbox"]):not([type="radio"]) { border-color: var(--error); }
.tag-rename-actions { display: flex; gap: 8px; }
.tag-list-none { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 0; font-size: var(--fs-sm); color: var(--secondary); }
@media (max-width: 640px) {
  /* Touch: rows and the × reach at least 32px; what you see stays the same size. */
  .tag-chip-remove::after { content: ""; position: absolute; inset: -6px; }
  .tag-create-row { flex-wrap: wrap; }
  .tag-create-row > .button { flex: 1 0 100%; }
  .tag-list-search { width: 100%; }
  .tag-row { grid-template-columns: minmax(0, 1fr) auto; }
  .tag-row-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
  .tag-row-actions .card-action, .tag-row-actions .text-button { min-height: 32px; }
  .tag-rename input { flex-basis: 100%; }
}

/* ---------- 帳號模式 (docs/specs/p1-account-ui.md): welcome board, 登入 dialog, account menu, 尚未開放 ---------- */
/* Existing tokens and components only: the welcome board and login dialog come back from before MeFresh was removed. */
.nav-link.requires-login { color: var(--secondary); }
.account-control { position: relative; display: flex; flex: none; }
.account-button { gap: 6px; max-width: 100%; }
.account-button svg { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.account-button .account-button-caret { width: 12px; height: 12px; }
.account-button-email { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-sm); font-weight: 500; }
.account-button[aria-expanded="true"] { background: var(--chip); color: var(--accent); }
.account-menu { width: min(280px, calc(100vw - 32px)); }
.account-menu-head { display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; }
.account-menu-head strong { font-size: var(--fs-sm); font-weight: 600; overflow-wrap: anywhere; }
.account-menu-head span { font-size: var(--fs-xs); color: var(--secondary); overflow-wrap: anywhere; }
.account-menu-sep { margin: 4px 0; border: 0; border-top: 1px solid var(--line); }

.account-board { padding: 0 32px; }
.account-loading { padding: 48px 0; text-align: center; font-size: var(--fs-xs); color: var(--secondary); }
.account-board-error { max-width: 640px; margin: 32px auto; }
.account-context-error { margin-bottom: 16px; }
.welcome-board { display: grid; grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); align-items: center; gap: 48px; min-height: calc(100vh - var(--toolbar-h) - 140px); padding: 24px 0 48px; }
.welcome-copy { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }
.welcome-copy h2 { font-size: var(--fs-xl); font-weight: 600; letter-spacing: -.02em; line-height: 1.25; }
.welcome-copy p { max-width: 40ch; font-size: var(--fs-md); line-height: 1.75; color: var(--text); }
.welcome-copy .welcome-account-note { font-size: var(--fs-sm); line-height: 1.6; color: var(--secondary); }
.welcome-copy small { font-size: var(--fs-xs); color: var(--secondary); }
.welcome-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.welcome-sample { position: relative; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.welcome-sample-tag { position: absolute; top: -26px; right: 0; }
.welcome-sample .conversation-header { border: 1px solid var(--line); border-radius: var(--radius-lg); }
.welcome-rows { overflow: hidden; padding: 4px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--muted); }

.login-dialog { width: min(460px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto; }
.login-dialog form { display: flex; flex-direction: column; gap: 16px; padding: 24px; }
.login-dialog h2:focus { outline: none; }
.login-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.login-field > label { font-size: var(--fs-sm); font-weight: 500; }
.login-field input.is-invalid:not([type="checkbox"]):not([type="radio"]) { border-color: var(--error); }
.login-field-error { font-size: var(--fs-xs); color: var(--error); line-height: 1.5; }
.login-password-control { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.login-password-control .small-button { height: var(--control-h); }
.login-forgot { display: flex; justify-content: flex-end; margin-top: -2px; }
.login-forgot .text-button { font-size: var(--fs-sm); }
.login-notice { padding: 8px 12px; border-radius: var(--radius); background: var(--muted); font-size: var(--fs-sm); line-height: 1.6; color: var(--text); overflow-wrap: anywhere; }
.login-security-note { display: flex; flex-direction: column; padding-top: 12px; border-top: 1px solid var(--line); color: var(--secondary); font-size: var(--fs-xs); line-height: 1.6; }
.login-help { font-size: var(--fs-sm); line-height: 1.6; color: var(--secondary); }
.login-email { font-weight: 600; overflow-wrap: anywhere; }
.login-links { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.login-links .text-button[aria-disabled="true"] { color: var(--secondary); text-decoration: none; cursor: default; }
.text-button.is-counting { font-variant-numeric: tabular-nums; }
.login-actions { align-items: flex-start; justify-content: space-between; margin-top: 0; }
.login-switch { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding-top: 4px; font-size: var(--fs-sm); color: var(--secondary); }
.login-submit { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; margin-left: auto; }
.login-submit .button { min-width: 120px; }
/* The button already shows the step; this line only announces it to screen readers, so it is never drawn. */
.login-progress { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.code-field { max-width: 200px; font-size: var(--fs-lg); font-variant-numeric: tabular-nums; letter-spacing: .08em; }
.password-rules { display: flex; flex-direction: column; gap: 2px; margin: 0; padding: 0; list-style: none; font-size: var(--fs-xs); line-height: 1.6; color: var(--secondary); }
.password-rules li { display: flex; align-items: center; gap: 6px; }
.password-rules .rule-mark { display: inline-grid; place-items: center; width: 12px; height: 12px; flex: none; border-radius: 50%; box-shadow: inset 0 0 0 1.5px var(--control-border-hover); color: var(--accent); }
.password-rules li.is-met { color: var(--text); }
.password-rules li.is-met .rule-mark { box-shadow: none; }
.password-rules li.is-met .rule-mark::before { content: "✓"; font-size: var(--fs-xs); font-weight: 600; line-height: 1; }
.password-rules.is-checked li:not(.is-met), .password-rules li.is-error { color: var(--error); }

.settings-group.is-account[data-settings-section] { display: block; }
.account-social h3 { font-size: var(--fs-lg); font-weight: 600; }
.account-social-copy { margin: 4px 0 12px; font-size: var(--fs-sm); line-height: 1.6; color: var(--secondary); }

@media (max-width: 1100px) {
  .account-button-email { max-width: 140px; }
}
@media (max-width: 850px) {
  .account-board { padding: 0 16px; }
  .welcome-board { grid-template-columns: minmax(0, 1fr); gap: 32px; min-height: 0; }
}
@media (max-width: 760px) {
  .account-button { width: var(--control-h); padding: 0; justify-content: center; }
  .account-button-email, .account-button .account-button-caret { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
}
@media (max-width: 640px) {
  .welcome-actions { width: 100%; }
  .welcome-actions .button { flex: 1; }
  .login-dialog form { padding: 16px; }
  .login-actions { flex-direction: column-reverse; align-items: stretch; gap: 12px; }
  .login-submit { align-items: stretch; margin-left: 0; }
  .login-submit .button { width: 100%; }
  .login-switch { justify-content: center; }
  .code-field { max-width: none; }
}
/* Signed out or still reading the account, the bar has no platform list, so no separator either. */
.status-sep:has(+ .status-platforms:empty) { display: none; }

/* ---------- 帳號模式 P2 (docs/specs/p2-social-accounts-ui.md): 設定 › 社群帳號, the Instagram row ----------
   Only existing tokens. Yellow only on 需要重新連接 and the 需要設定 reminder lines; the error is the one .error-bar. */
.account-social-list .status-key { display: flex; align-items: center; gap: 6px; }
.account-social-lines { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.account-social-headline { overflow-wrap: anywhere; }
.account-social-headline[data-tone="warn"] { color: var(--warning); font-weight: 600; }
.account-social-note { font-size: var(--fs-xs); line-height: 1.5; color: var(--secondary); overflow-wrap: anywhere; }
.account-social-note[data-tone="text"] { color: var(--text); }
.account-social-attention { display: flex; align-items: baseline; gap: 6px; font-size: var(--fs-xs); line-height: 1.5; color: var(--warning); overflow-wrap: anywhere; }
.account-social-attention .dot { transform: translateY(-1px); }
.account-social-actions { display: flex; align-items: center; gap: 8px; }
.account-social-actions .text-button { min-height: var(--control-h-sm); }
.account-social-error { grid-column: 2 / -1; margin: 4px 0 8px; }
@media (max-width: 640px) {
  .account-social-actions { grid-column: 1 / -1; margin-top: 4px; }
  .account-social-actions > .button, .account-social-actions > .text-button { flex: 1 1 0; justify-content: center; }
  .account-social-actions.is-pair > .button, .account-social-actions.is-pair > .text-button { height: var(--control-h); }
  .account-social-error { grid-column: 1 / -1; }
}

/* ---------- 帳號模式 P2B (docs/specs/p2b-social-accounts-ui.md §3.3, §10.3): the Facebook Page dialog ----------
   Only existing tokens, radii and the dialog shadow every dialog already has: the .login-dialog size, .publish-dialog-heading,
   .dialog-close, .dialog-actions, native radios, the .tag-option row and the one .error-bar. The list scrolls by itself so the
   heading, the deadline and the buttons stay in view. */
.social-page-dialog { width: min(460px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: hidden; }
.social-page-form { display: flex; flex-direction: column; gap: 16px; max-height: calc(100dvh - 32px); padding: 24px; }
.social-page-form h2:focus { outline: none; }
.social-page-form .publish-dialog-heading p { line-height: 1.6; }
.social-page-list { flex: 0 1 auto; min-width: 0; min-height: 0; max-height: min(320px, 45dvh); margin: 0; padding: 4px; overflow-y: auto; overscroll-behavior: contain; border: 1px solid var(--control-border); border-radius: var(--radius-md); background: var(--canvas); }
.social-page-option { display: grid; grid-template-columns: 16px minmax(0, 1fr); align-items: start; gap: 2px 8px; min-height: 40px; padding: 8px 12px; border-radius: var(--radius); color: var(--text); cursor: pointer; }
.social-page-option:hover { background: var(--chip); }
.social-page-option:has(input:checked) { background: var(--selected); }
.social-page-option input { width: 16px; height: 16px; margin: 2px 0 0; accent-color: var(--accent); }
.social-page-option input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.social-page-option.is-ineligible { cursor: not-allowed; }
.social-page-option.is-ineligible:hover { background: transparent; }
.social-page-words { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.social-page-name { font-size: var(--fs-md); font-weight: 600; overflow-wrap: anywhere; }
.social-page-option.is-ineligible .social-page-name { color: var(--secondary); font-weight: 400; }
.social-page-note { margin: 0; font-size: var(--fs-xs); line-height: 1.5; color: var(--secondary); overflow-wrap: anywhere; }
.social-page-deadline { font-variant-numeric: tabular-nums; }
.social-page-form .dialog-actions { margin-top: 0; }
.social-page-form .dialog-actions .button-primary { min-width: 120px; }
@media (max-width: 640px) {
  .social-page-form { padding: 16px; }
  .social-page-form .dialog-actions { flex-direction: column-reverse; align-items: stretch; }
  .social-page-form .dialog-actions .button { width: 100%; justify-content: center; }
}
