/* WhatsApp CRM Hub — plain CSS, no build step. */

:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --surface-3: #f1f3f6;
  --border: #e3e7ec;
  --border-strong: #cfd6de;
  --text: #0f1b2a;
  --text-2: #3f4d5c;
  --muted: #6a7888;
  --accent: #0f9d6b;
  --accent-strong: #0a7c54;
  --accent-soft: #e5f6ee;
  --accent-contrast: #ffffff;
  --info: #2466d1;
  --info-soft: #e9f0fc;
  --warning: #a85a06;
  --warning-soft: #fdf2e2;
  --danger: #c8321f;
  --danger-soft: #fcebe8;
  --note: #8a6a00;
  --note-soft: #fff8db;
  --bubble-in: #ffffff;
  --bubble-out: #dcf5e8;
  --thread-bg: #eef1f4;
  --sidebar-bg: #0f1d27;
  --sidebar-text: #b9c7d2;
  --sidebar-active: #1b3140;
  --shadow-sm: 0 1px 2px rgba(15, 27, 42, .06);
  --shadow: 0 4px 16px rgba(15, 27, 42, .08);
  --shadow-lg: 0 18px 48px rgba(15, 27, 42, .18);
  --radius: 12px;
  --radius-sm: 8px;
  --font: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0e13;
    --surface: #11171e;
    --surface-2: #151c24;
    --surface-3: #1b232d;
    --border: #232d38;
    --border-strong: #34414f;
    --text: #e5ecf2;
    --text-2: #b4c0cb;
    --muted: #8593a2;
    --accent: #2fbf8a;
    --accent-strong: #4fd6a2;
    --accent-soft: rgba(47, 191, 138, .14);
    --accent-contrast: #062117;
    --info: #74a9ff;
    --info-soft: rgba(116, 169, 255, .14);
    --warning: #f0aa45;
    --warning-soft: rgba(240, 170, 69, .14);
    --danger: #ff7a6b;
    --danger-soft: rgba(255, 122, 107, .14);
    --note: #f2cf5b;
    --note-soft: rgba(242, 207, 91, .12);
    --bubble-in: #1b232d;
    --bubble-out: #16392c;
    --thread-bg: #0d1318;
    --sidebar-bg: #0c1218;
    --sidebar-text: #9aa8b5;
    --sidebar-active: #18222c;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 4px 16px rgba(0, 0, 0, .35);
    --shadow-lg: 0 18px 48px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0a0e13;
  --surface: #11171e;
  --surface-2: #151c24;
  --surface-3: #1b232d;
  --border: #232d38;
  --border-strong: #34414f;
  --text: #e5ecf2;
  --text-2: #b4c0cb;
  --muted: #8593a2;
  --accent: #2fbf8a;
  --accent-strong: #4fd6a2;
  --accent-soft: rgba(47, 191, 138, .14);
  --accent-contrast: #062117;
  --info: #74a9ff;
  --info-soft: rgba(116, 169, 255, .14);
  --warning: #f0aa45;
  --warning-soft: rgba(240, 170, 69, .14);
  --danger: #ff7a6b;
  --danger-soft: rgba(255, 122, 107, .14);
  --note: #f2cf5b;
  --note-soft: rgba(242, 207, 91, .12);
  --bubble-in: #1b232d;
  --bubble-out: #16392c;
  --thread-bg: #0d1318;
  --sidebar-bg: #0c1218;
  --sidebar-text: #9aa8b5;
  --sidebar-active: #18222c;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 4px 16px rgba(0, 0, 0, .35);
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, .55);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: 18px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
h4 { font-size: 13px; font-weight: 650; }
a { color: var(--accent-strong); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon { flex: none; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.stack { display: grid; gap: 12px; align-content: start; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: 228px minmax(0, 1fr); height: 100vh; }
.sidebar { display: flex; flex-direction: column; gap: 6px; padding: 14px 10px; background: var(--sidebar-bg); color: var(--sidebar-text); overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 16px; color: #fff; font-weight: 650; font-size: 15px; }
.brand-mark { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: linear-gradient(135deg, #16b27c, #0b7c54); color: #fff; }
.brand-mark.large { width: 56px; height: 56px; border-radius: 16px; }
.nav { display: grid; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 11px; width: 100%; padding: 9px 11px; border: 0; border-radius: 9px; background: transparent; color: inherit; font-size: 14px; text-align: left; text-decoration: none; cursor: pointer; }
.nav-item:hover { background: var(--sidebar-active); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 #2fbf8a; }
.sidebar-footer { display: grid; gap: 2px; margin-top: auto; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, .07); }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar { display: flex; align-items: center; gap: 12px; height: 58px; padding: 0 20px; border-bottom: 1px solid var(--border); background: var(--surface); flex: none; }
.topbar h1 { flex: 1; min-width: 0; }
.scope { display: flex; align-items: center; gap: 8px; min-width: 0; }
.chip { display: inline-flex; align-items: center; gap: 7px; max-width: 220px; padding: 4px 11px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2); color: var(--text-2); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip { padding-left: 4px; }
.menu-button { display: none; }
.view { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.nav-backdrop { display: none; }
.boot, .auth-screen { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-card { display: grid; justify-items: center; gap: 14px; width: min(400px, 100%); padding: 36px 28px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); text-align: center; box-shadow: var(--shadow); }
.auth-card p { color: var(--text-2); }
.auth-actions { display: grid; gap: 10px; width: 100%; }

/* ---------- controls ---------- */
.button { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 36px; padding: 7px 14px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font-weight: 550; text-decoration: none; cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s; }
.button:hover:not(:disabled) { background: var(--surface-3); }
.button.primary { border-color: var(--accent); background: var(--accent); color: var(--accent-contrast); }
.button.primary:hover:not(:disabled) { background: var(--accent-strong); border-color: var(--accent-strong); }
.button.small { min-height: 30px; padding: 4px 10px; font-size: 13px; }
.button.ghost { border-style: dashed; background: transparent; color: var(--text-2); }
.button:disabled { opacity: .5; cursor: not-allowed; }
.icon-button { display: inline-grid; place-items: center; width: 34px; height: 34px; padding: 0; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-2); cursor: pointer; flex: none; }
.icon-button:hover { background: var(--surface-3); color: var(--text); }
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select, textarea {
  width: 100%; min-width: 0; min-height: 36px; padding: 7px 10px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field { display: grid; gap: 5px; min-width: 0; }
.field > span { color: var(--text-2); font-size: 12px; font-weight: 550; }
.field.inline { grid-template-columns: auto 1fr; align-items: center; gap: 10px; }
.field-error { color: var(--danger); font-size: 12px; }
.inline-error { color: var(--danger); font-size: 13px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; align-items: end; }
.file-button { position: relative; }
.segmented { display: inline-flex; padding: 3px; border-radius: 9px; background: var(--surface-3); gap: 2px; flex: none; }
.segmented button { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border: 0; border-radius: 7px; background: transparent; color: var(--text-2); font-size: 13px; font-weight: 550; cursor: pointer; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.segmented button:disabled { opacity: .45; cursor: not-allowed; }
.tabs { display: flex; gap: 2px; overflow-x: auto; }
.tabs button { padding: 8px 12px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font-weight: 600; cursor: pointer; white-space: nowrap; }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.filter-chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip-button { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text-2); font-size: 12px; font-weight: 550; cursor: pointer; white-space: nowrap; }
.chip-button.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-strong); }
.chip-count { color: var(--muted); font-size: 11px; }
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; white-space: nowrap; background: var(--surface-3); color: var(--text-2); }
.badge-success { background: var(--accent-soft); color: var(--accent-strong); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.tag { padding: 2px 7px; border-radius: 6px; background: var(--surface-3); font-family: var(--mono); font-size: 12px; }
.count { min-width: 22px; padding: 1px 7px; border-radius: 999px; background: var(--surface-3); color: var(--muted); font-size: 12px; font-weight: 600; text-align: center; }
.avatar { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; flex: none; background: hsl(var(--avatar-hue, 160) 55% 88%); color: hsl(var(--avatar-hue, 160) 45% 28%); font-size: 13px; font-weight: 700; letter-spacing: .02em; }
:root[data-theme="dark"] .avatar { background: hsl(var(--avatar-hue, 160) 35% 24%); color: hsl(var(--avatar-hue, 160) 60% 80%); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .avatar { background: hsl(var(--avatar-hue, 160) 35% 24%); color: hsl(var(--avatar-hue, 160) 60% 80%); } }
.avatar.small { width: 26px; height: 26px; font-size: 11px; }

/* ---------- feedback ---------- */
.state-block { display: grid; justify-items: center; gap: 6px; padding: 32px 16px; color: var(--muted); text-align: center; }
.state-block strong { color: var(--text-2); font-weight: 600; }
.state-block small { font-size: 12px; word-break: break-all; }
.state-block.error { color: var(--danger); }
.state-block.error strong { color: var(--danger); }
.state-block .button { margin-top: 6px; }
.spinner { width: 22px; height: 22px; border: 2.5px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }
.notice { display: flex; gap: 8px; align-items: flex-start; padding: 9px 12px; border-radius: var(--radius-sm); background: var(--note-soft); color: var(--note); font-size: 12.5px; }
.notice.warning { background: var(--warning-soft); color: var(--warning); }
.notice.block ul { margin: 4px 0 0; padding-left: 18px; }
.result { margin: 0; padding: 9px 12px; border-radius: var(--radius-sm); font-size: 13px; }
.result strong { display: block; }
.result span, .result small { display: block; }
ul.result { padding-left: 30px; }
.result.success { background: var(--accent-soft); color: var(--accent-strong); }
.result.pending, .result.warning { background: var(--warning-soft); color: var(--warning); }
.result.danger { background: var(--danger-soft); color: var(--danger); }
.toast-region { position: fixed; right: 16px; bottom: 16px; z-index: 100; display: grid; gap: 8px; width: min(380px, calc(100vw - 32px)); }
.toast { display: flex; gap: 10px; align-items: flex-start; padding: 12px 12px 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-lg); animation: toast-in .2s ease-out; }
.toast div { flex: 1; min-width: 0; }
.toast strong { display: block; font-weight: 600; }
.toast small { color: var(--muted); word-break: break-all; }
.toast-success .icon { color: var(--accent); }
.toast-error .icon:first-child { color: var(--danger); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

/* ---------- cards & data ---------- */
.card { display: grid; gap: 10px; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.form-card h4, .form-card h3 { margin-bottom: 2px; }
.data-list { display: grid; grid-template-columns: minmax(80px, auto) 1fr; gap: 6px 12px; margin: 0; font-size: 13px; }
.data-list dt { color: var(--muted); }
.data-list dd { margin: 0; word-break: break-word; }
.data-list.compact { font-size: 12.5px; }
.meta-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.amount { font-weight: 650; }
.section-title { display: flex; align-items: center; gap: 8px; }
.section-title h3 { flex: 1; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.data-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.data-table caption { padding: 8px 10px; color: var(--muted); text-align: left; }
.data-table th, .data-table td { padding: 7px 10px; border-top: 1px solid var(--border); text-align: left; white-space: nowrap; }
.data-table th { background: var(--surface-2); color: var(--text-2); font-weight: 600; }

/* ---------- pages ---------- */
.page { display: grid; gap: 18px; align-content: start; width: 100%; max-width: 1280px; margin: 0 auto; padding: 22px 24px 40px; overflow-y: auto; height: 100%; }
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px; }
.page-header h2 { font-size: 20px; margin-bottom: 4px; }
.page-header p { max-width: 680px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.toolbar .field { width: 150px; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.kpi { display: grid; gap: 10px; padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
.kpi-label { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12.5px; font-weight: 550; }
.kpi-value { font-size: 24px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi-value.empty { font-size: 15px; font-weight: 550; color: var(--muted); }
.report-summary { display: grid; gap: 14px; }
.evidence { display: flex; flex-wrap: wrap; gap: 10px; }
.evidence-item { display: grid; gap: 2px; padding: 9px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); font-size: 12px; }
.evidence-item span { color: var(--muted); }
.campaign-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 14px; }
.sublist { display: grid; gap: 6px; padding-top: 10px; border-top: 1px solid var(--border); }
.sublist-row { display: flex; justify-content: space-between; gap: 10px; font-size: 12.5px; }

/* ---------- source mapping ---------- */
.source-tabs { display: flex; flex-wrap: wrap; gap: 10px; }
.source-tab { display: grid; gap: 6px; min-width: 180px; padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); text-align: left; cursor: pointer; }
.source-tab.active { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.source-tab-meta { display: flex; flex-wrap: wrap; gap: 10px; color: var(--muted); font-size: 12px; }
.source-tab-sync { display: grid; gap: 2px; font-size: 11.5px; color: var(--muted); }
.sync-line.failed { color: var(--danger); max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.booking-line { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.booking-line span:first-child { display: inline-flex; align-items: center; gap: 5px; }
.booking-line .badge { margin-left: auto; }
.step-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 14px; align-items: start; }
.step { padding: 18px; }
.step-header { display: flex; align-items: center; gap: 10px; }
.step-header-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.step-number { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--surface-3); color: var(--text-2); font-size: 13px; font-weight: 700; }
.step-number.done { background: var(--accent); color: var(--accent-contrast); }
.dropzone { position: relative; display: grid; justify-items: center; gap: 6px; padding: 26px 16px; border: 1.5px dashed var(--border-strong); border-radius: var(--radius); color: var(--text-2); cursor: pointer; text-align: center; }
.dropzone:hover { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.busy { opacity: .6; }
.fieldset { display: grid; gap: 8px; min-width: 0; margin: 0; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); }
.fieldset legend { padding: 0 6px; color: var(--text-2); font-size: 12.5px; font-weight: 600; }
.fieldset > .button { justify-self: start; }
.mapping-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.mapping-row select, .mapping-row input { flex: 1 1 160px; width: auto; }
.mapping-row .field-error, .mapping-row .row-hint { flex-basis: 100%; }
.field-name { width: 150px; font-size: 13px; font-weight: 550; }
.field-name em { margin-left: 6px; color: var(--warning); font-size: 11px; font-style: normal; }

/* ---------- inbox ---------- */
.inbox { display: grid; grid-template-columns: 320px minmax(0, 1fr) 360px; height: 100%; min-height: 0; }
.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--surface); }
.list-pane { border-right: 1px solid var(--border); }
.context-pane { border-left: 1px solid var(--border); }
.pane-header { display: flex; align-items: center; gap: 10px; min-height: 58px; padding: 10px 16px; border-bottom: 1px solid var(--border); flex: none; }
.pane-header h2 { flex: 1; }
.list-tools { display: grid; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.search { position: relative; display: block; }
.search .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 32px !important; background: var(--surface-2) !important; }
.conversation-list { flex: 1; overflow-y: auto; padding: 6px; }
.conversation-item { display: flex; gap: 11px; width: 100%; padding: 10px; border: 0; border-radius: 10px; background: transparent; text-align: left; cursor: pointer; }
.conversation-item:hover { background: var(--surface-3); }
.conversation-item.selected { background: var(--accent-soft); }
.conversation-body { display: grid; gap: 3px; flex: 1; min-width: 0; }
.conversation-top { display: flex; justify-content: space-between; gap: 8px; }
.conversation-top strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.conversation-top time { color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.conversation-meta { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none; }
.status-open { background: var(--accent); }
.status-pending { background: var(--warning); }
.unread { margin-left: auto; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: var(--accent-contrast); font-size: 11px; font-weight: 700; line-height: 20px; text-align: center; }
.thread-pane { background: var(--thread-bg); }
.thread-header { background: var(--surface); flex-wrap: wrap; }
.thread-title { display: grid; flex: 1; min-width: 120px; }
.thread-title h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-title small { color: var(--muted); font-size: 12px; }
.thread-scroll { flex: 1; overflow-y: auto; padding: 18px 22px; }
.message-list, .notes-list { display: flex; flex-direction: column; gap: 8px; max-width: 820px; margin: 0 auto; }
.day-separator { display: flex; justify-content: center; margin: 10px 0 4px; }
.day-separator span { padding: 3px 12px; border-radius: 999px; background: var(--surface); color: var(--muted); font-size: 11.5px; box-shadow: var(--shadow-sm); }
.message { display: grid; gap: 6px; max-width: min(72%, 560px); padding: 9px 12px; border-radius: 14px; background: var(--bubble-in); box-shadow: var(--shadow-sm); align-self: flex-start; border-top-left-radius: 4px; }
.message.outbound { align-self: flex-end; background: var(--bubble-out); border-top-left-radius: 14px; border-top-right-radius: 4px; }
.message p { white-space: pre-wrap; word-break: break-word; }
.message-meta { color: var(--muted); font-size: 11px; text-align: right; }
.attachment { margin: 0; }
.attachment img { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; }
.attachment figcaption { margin-top: 4px; color: var(--text-2); font-size: 12.5px; }
.attachment.file { display: inline-flex; align-items: center; gap: 7px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); font-size: 13px; text-decoration: none; }
.note-card { display: grid; gap: 6px; padding: 11px 13px; border: 1px solid color-mix(in srgb, var(--note) 25%, transparent); border-left: 3px solid var(--note); border-radius: var(--radius-sm); background: var(--note-soft); }
.note-card p { white-space: pre-wrap; word-break: break-word; }
.note-card small { color: var(--muted); font-size: 11.5px; }
.composer { display: flex; align-items: flex-end; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); background: var(--surface); flex: none; }
.composer textarea { min-height: 40px; max-height: 180px; resize: none; }
.note-composer { background: var(--note-soft); }
.composer-disabled { padding: 14px 16px; border-top: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: 13px; }
.context-header { padding-top: 0; padding-bottom: 0; align-items: flex-end; }
.context-header .tabs { flex: 1; }
.context-body { flex: 1; overflow-y: auto; padding: 16px; display: grid; gap: 14px; align-content: start; }
.candidate { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); text-align: left; cursor: pointer; }
.candidate:hover { border-color: var(--accent); }
.candidate span { display: grid; }
.candidate small { color: var(--muted); }
.option-list { display: grid; gap: 8px; }
.booking-option { display: grid; gap: 5px; width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); text-align: left; cursor: pointer; }
.booking-option:hover:not(:disabled) { border-color: var(--accent); }
.booking-option.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.booking-option.stale { opacity: .55; cursor: not-allowed; }
.booking-option small { color: var(--muted); }
.option-top { display: flex; justify-content: space-between; gap: 8px; }
.option-time { display: flex; align-items: center; gap: 6px; color: var(--text-2); font-size: 13px; }
.confirm-card { border-color: var(--accent); }
.currency { max-width: 84px; text-transform: uppercase; }
.consent-status { display: grid; gap: 4px; justify-items: start; }
.context-toggle { display: none; }
.mobile-only { display: none; }

/* Medium screens: the customer panel becomes a drawer. */
@media (max-width: 1240px) {
  .inbox { grid-template-columns: 300px minmax(0, 1fr); }
  .context-toggle { display: inline-grid; }
  .context-pane { position: fixed; top: 0; right: 0; bottom: 0; z-index: 40; width: min(400px, 100vw); box-shadow: var(--shadow-lg); transform: translateX(100%); visibility: hidden; transition: transform .2s ease, visibility 0s .2s; }
  .inbox[data-pane="context"] .context-pane { transform: none; visibility: visible; transition: transform .2s ease; }
  .context-pane .mobile-only { display: inline-grid; }
}

/* Small screens: one pane at a time, sidebar slides in. */
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 60; width: 248px; transform: translateX(-100%); visibility: hidden; transition: transform .2s ease, visibility 0s .2s; }
  body.nav-open .sidebar { transform: none; visibility: visible; transition: transform .2s ease; }
  body.nav-open .nav-backdrop { display: block; position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .4); }
  .menu-button { display: inline-grid; }
  .topbar { padding: 0 12px; }
  .scope .chip:first-child { display: none; }
  .inbox { grid-template-columns: minmax(0, 1fr); }
  .list-pane, .thread-pane { display: none; }
  .inbox[data-pane="list"] .list-pane, .inbox:not([data-pane]) .list-pane { display: flex; }
  .inbox[data-pane="thread"] .thread-pane, .inbox[data-pane="context"] .thread-pane { display: flex; }
  .mobile-only { display: inline-grid; }
  .thread-header .segmented { order: 5; width: 100%; }
  .thread-scroll { padding: 14px 12px; }
  .message { max-width: 86%; }
  .page { padding: 16px 16px 32px; }
  .step-grid, .campaign-list { grid-template-columns: minmax(0, 1fr); }
  .field-name { width: 100%; }
  .toolbar .field { width: calc(50% - 5px); }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px; gap: 6px; }
  .kpi-value { font-size: 20px; }
}
