/* A quiet working tool: white cards on a warm grey ground, JoyLearn blue for actions, LINE green
   for our side of a conversation, one red for what is important. */
:root {
  --ground: #f4f3ef;
  --card: #ffffff;
  --ink: #1d2320;
  --muted: #6a716c;
  --rule: #e2e0d8;
  --rule-strong: #cfccc1;
  --accent: #1570ef;
  --accent-deep: #0d56c2;
  --accent-wash: #e9f1fe;
  --green: #06c755;
  --green-deep: #04883b;
  --green-wash: #e3f6ea;
  --red: #c4321f;
  --red-wash: #fdebe7;
  --amber: #a15c00;
  --amber-wash: #fcf0dc;
  --violet: #6b45c2;
  --violet-wash: #f0ebfb;
  --teal: #0b7a70;
  --teal-wash: #def4f0;
  --radius: 12px;
  --bar: 52px;
  --text: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--ground); color: var(--ink); font: 15px/1.55 var(--text); }
a { color: var(--accent-deep); }
h1, h2, h3, h4 { margin: 0; line-height: 1.3; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
h4 { font-size: 13px; color: var(--muted); margin-top: 6px; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }
.nowrap { white-space: nowrap; }
.error { color: var(--red); }
.pre { white-space: pre-wrap; word-break: break-word; }
.empty, .loading { padding: 40px 20px; text-align: center; color: var(--muted); }

button, .button, select, input, textarea { font: inherit; color: inherit; }
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 14px; border: 1px solid var(--rule-strong); border-radius: 8px;
  background: var(--card); cursor: pointer; text-decoration: none; white-space: nowrap;
}
button:hover, .button:hover { border-color: var(--muted); }
button:disabled { opacity: 0.55; cursor: progress; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: var(--accent-deep); border-color: var(--accent-deep); }
button.small, .button.small { padding: 4px 10px; font-size: 13px; }
button.on { background: var(--ink); border-color: var(--ink); color: #fff; }
button.link { border: 0; background: none; padding: 0; color: var(--accent-deep); text-decoration: underline; }
button.quiet { border-color: transparent; background: none; color: var(--muted); }
button.quiet:hover { background: var(--ground); border-color: transparent; color: var(--ink); }
input, select, textarea { padding: 7px 10px; border: 1px solid var(--rule-strong); border-radius: 8px; background: #fff; min-width: 0; }
textarea { width: 100%; resize: vertical; line-height: 1.6; }
:focus-visible { outline: 3px solid #9cc2f8; outline-offset: 1px; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
label.check { display: inline-flex; align-items: center; gap: 6px; color: var(--ink); font-size: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.stack { display: grid; gap: 12px; }
/* forms read down the page: fields a sensible width, buttons the size of their words */
.stack > label > input:not([type="checkbox"]), .stack > label > select, .stack > label > .row { max-width: 420px; }
.stack > label > .row > input { flex: 1; }
.stack > button, .stack > .row { justify-self: start; }

/* sign-in */
.signin-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.signin { width: min(380px, 100%); display: grid; gap: 14px; padding: 28px; background: var(--card); border: 1px solid var(--rule); border-radius: 16px; }
.signin input { padding: 10px 12px; }
.signin .primary { padding: 10px; }
.signin-logo { width: 132px; height: auto; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 24px; height: var(--bar); padding: 0 18px; background: var(--card); border-bottom: 1px solid var(--rule); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--ink); text-decoration: none; white-space: nowrap; }
.brand-mark { height: 24px; width: auto; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; white-space: nowrap; }
.topbar nav a.active { background: var(--accent-wash); color: var(--accent-deep); font-weight: 600; }
.me { margin-left: auto; display: flex; gap: 8px; align-items: center; font-size: 14px; white-space: nowrap; }
.role { margin-left: 6px; padding: 1px 7px; border-radius: 99px; background: var(--ground); font-size: 12px; color: var(--muted); }

.page { padding: 22px; max-width: 1240px; margin: 0 auto; display: grid; gap: 16px; }
/* the inbox fills the window below the bar; its columns scroll on their own */
.page.wide { display: block; max-width: none; padding: 0; height: calc(100vh - var(--bar)); height: calc(100dvh - var(--bar)); overflow: hidden; }
.page-head { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.head-tools { margin-left: auto; align-self: center; }
.card { background: var(--card); border: 1px solid var(--rule); border-radius: var(--radius); padding: 16px; display: grid; gap: 10px; align-content: start; }

/* tabs */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; padding: 6px 10px; border-radius: 8px; color: var(--muted); font-size: 14px; }
.tabs button.active { background: var(--ink); color: #fff; }

/* chips and badges */
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { display: inline-flex; align-items: center; gap: 2px; padding: 1px 8px; border-radius: 99px; background: var(--ground); font-size: 12px; color: var(--muted); border: 1px solid transparent; white-space: nowrap; }
.chip.staff { background: var(--accent-wash); color: var(--accent-deep); }
.chip.important { background: var(--red-wash); color: var(--red); font-weight: 600; }
.chip.snooze, .chip.done { background: #fff; border-color: var(--rule); }
.chip.due { background: var(--amber-wash); color: var(--amber); font-weight: 600; }
.chip.gone { background: var(--red-wash); color: var(--red); margin-left: 6px; }
.chips.toggles .chip { cursor: pointer; padding: 3px 10px; font-size: 13px; border-color: var(--rule); background: #fff; }
.chips.toggles .chip.staff { background: var(--accent-wash); border-color: #a8c8f8; color: var(--accent-deep); font-weight: 600; }
.chip .ai-mark { font-size: 10px; color: var(--muted); }
.chip.removable button { color: var(--muted); text-decoration: none; margin-left: 2px; }
.badge { padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 700; background: var(--ground); white-space: nowrap; }
.badge.group-important { background: var(--red-wash); color: var(--red); }
.badge.group-normal { background: var(--ground); color: var(--ink); }
.badge.group-quote { background: var(--amber-wash); color: var(--amber); }
.badge.group-invoice { background: var(--violet-wash); color: var(--violet); }
.badge.group-activation { background: var(--teal-wash); color: var(--teal); }
.badge.group-none { background: var(--green-wash); color: var(--green-deep); }
.badge.staff { background: var(--accent-wash); color: var(--accent-deep); }

.avatar { width: 36px; height: 36px; border-radius: 50%; flex: none; object-fit: cover; background: var(--ground); }
.avatar.initial { display: grid; place-items: center; font-weight: 700; color: var(--muted); }
.avatar.large { width: 44px; height: 44px; }
.avatar.small { width: 26px; height: 26px; font-size: 12px; }

/* the inbox: list | chat */
.inbox { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; grid-template-rows: minmax(0, 1fr); height: 100%; }
.list-pane { display: flex; flex-direction: column; border-right: 1px solid var(--rule); background: var(--card); min-height: 0; }
.list-head { padding: 12px; border-bottom: 1px solid var(--rule); display: grid; gap: 8px; }
.list-head-row { display: flex; align-items: center; gap: 8px; min-height: 34px; }
.list-head-row .tabs { flex: 1; }
button.search-toggle { flex: none; width: 34px; height: 34px; padding: 0; border-radius: 50%; border-color: transparent; background: none; }
button.search-toggle:hover { background: var(--ground); border-color: transparent; }
button.search-toggle img { width: 18px; height: 18px; }
button.cancel { flex: none; text-decoration: none; color: var(--muted); }
input.inbox-search { flex: 1; width: 100%; padding: 7px 10px 7px 32px; border-radius: 99px; background: var(--ground) url("/search-icon.svg") no-repeat 10px center / 16px; border-color: transparent; }
input.inbox-search:focus { background-color: #fff; border-color: var(--rule-strong); }
.chat-row mark { background: #fff1a8; color: inherit; border-radius: 3px; padding: 0 1px; }
.chat-list { overflow-y: auto; flex: 1; }
.group-title { display: flex; align-items: center; gap: 6px; padding: 12px 14px 6px; font-size: 13px; position: sticky; top: 0; background: var(--card); z-index: 1; }
.group-title .count { padding: 0 7px; border-radius: 99px; background: var(--ground); font-size: 12px; }
.group-title .hint { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: auto; }
.group-title button.fold { width: 22px; height: 22px; padding: 0; border-color: transparent; border-radius: 6px; background: none; color: var(--muted); }
.group-title button.fold:hover { background: var(--ground); border-color: transparent; color: var(--ink); }
@media (prefers-reduced-motion: no-preference) { .group-title button.fold span { transition: transform 0.15s; } }
.group-title button.fold span { width: 7px; height: 7px; margin-top: -3px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg); }
.group.folded button.fold span { margin-top: 0; margin-left: -3px; transform: rotate(-45deg); }
/* a folded group still shows the chat that is open */
.group.folded > .chat-row:not(.open) { display: none; }
.group.flash > .group-title { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: var(--accent-wash); } to { background: var(--card); } }
.group-important .dot { color: var(--red); }
.group-normal .dot { color: #9a9a92; }
.group-pending .dot { color: var(--muted); }
.group-quote .dot { color: var(--amber); }
.group-invoice .dot { color: var(--violet); }
.group-activation .dot { color: var(--teal); }
.group-none .dot { color: var(--green); }
.chat-row { display: flex; gap: 10px; padding: 8px 14px; color: inherit; text-decoration: none; border-left: 3px solid transparent; }
.chat-row:hover { background: #fafaf7; }
.chat-row.open { background: var(--accent-wash); border-left-color: var(--accent); }
.chat-row.group-important { border-left-color: var(--red); }
.chat-row-body { min-width: 0; flex: 1; display: grid; gap: 1px; }
.chat-row-top { display: flex; gap: 6px; align-items: center; }
.chat-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-row .wait { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; }
.chat-row.group-important .wait { color: var(--red); font-weight: 600; }
.chat-row.group-quote { border-left-color: var(--amber); }
.chat-row.group-invoice { border-left-color: var(--violet); }
.chat-row.group-activation { border-left-color: var(--teal); }
.chat-row .summary { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-row-bottom { display: flex; gap: 4px; align-items: center; min-width: 0; }
.chat-row-bottom .chip { flex: none; }
.chat-row .preview { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; margin-left: 2px; }

.chat-pane { min-width: 0; min-height: 0; display: flex; }
.pane-empty { margin: auto; text-align: center; display: grid; gap: 8px; color: var(--muted); padding: 20px; justify-items: center; }
.tally { display: flex; gap: 10px; margin-bottom: 18px; }
.tally button { display: grid; justify-items: center; gap: 0; min-width: 92px; padding: 12px 10px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--rule); }
.tally button:hover { border-color: var(--muted); }
.tally strong { font-size: 26px; color: var(--ink); line-height: 1.2; }
.tally span { font-size: 13px; }
.tally .group-important strong { color: var(--red); }
.tally .group-quote strong { color: var(--amber); }
.tally .group-invoice strong { color: var(--violet); }
.tally .group-activation strong { color: var(--teal); }
.tally .group-none strong { color: var(--green-deep); }
.chat { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 12px 18px; background: var(--card); border-bottom: 1px solid var(--rule); }
.chat-head .who { min-width: 0; }
.chat-head h2 { display: flex; align-items: center; min-width: 0; }
.chat-head h2 .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head .back { display: none; font-size: 28px; line-height: 1; padding: 0 6px 4px 0; color: var(--ink); text-decoration: none; }
.head-actions { margin-left: auto; display: flex; gap: 10px; align-items: center; }
/* LINE's own green: where staff go to reply */
a.line-button { background: #06c755; border-color: #06c755; color: #fff; font-weight: 700; }
a.line-button:hover { background: #05b04b; border-color: #05b04b; }
a.line-button img { width: 18px; height: 18px; }
.chat-body { display: grid; grid-template-columns: 1fr minmax(320px, 400px); grid-template-rows: minmax(0, 1fr); flex: 1; min-height: 0; }
.thread { min-height: 0; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 4px; }
/* the side panel: one list that scrolls, and the actions always in view below it */
.side { min-height: 0; display: flex; flex-direction: column; border-left: 1px solid var(--rule); background: var(--card); }
.side-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 18px 18px; }
.side-section { display: grid; gap: 6px; padding: 10px 0; }
.side-section h4 { margin: 0; font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: 0.06em; }
/* at a glance: four tiles, coloured only when they need attention */
.glance { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 14px 0 6px; }
.glance-tile { display: grid; align-content: start; justify-content: stretch; justify-items: start; gap: 0; padding: 8px 12px; border: 0; border-radius: 10px; background: var(--ground); color: var(--ink); text-align: left; white-space: normal; }
button.glance-tile { cursor: pointer; }
button.glance-tile:hover { filter: brightness(0.97); }
.glance-label { font-size: 12px; color: var(--muted); }
.glance-value { font-size: 17px; font-weight: 700; line-height: 1.35; }
.glance-sub { font-size: 12px; color: var(--muted); }
.glance-tile.warn { background: var(--amber-wash); }
.glance-tile.warn > * { color: var(--amber); }
.glance-tile.alert { background: var(--red-wash); }
.glance-tile.alert > * { color: var(--red); }
.glance-tile.ok { background: var(--green-wash); }
.glance-tile.ok > * { color: var(--green-deep); }
.section-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.section-head h4 { flex: 1; }
.status-reason { margin: 0; font-size: 13px; color: var(--muted); }
.side-summary { margin: 0; font-size: 17px; font-weight: 700; line-height: 1.45; }
.reply-tools { display: inline-flex; align-items: center; gap: 10px; margin-left: auto; }
.reply-tools select.saved { padding: 3px 6px; font-size: 13px; }
p.blank-hint { margin: 0; color: var(--amber); font-size: 13px; font-weight: 600; }
p.blank-hint:empty { display: none; }
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr) auto; gap: 5px 12px; align-items: baseline; font-size: 14px; }
.kv-label { color: var(--muted); }
.kv-value { overflow-wrap: anywhere; }
.kv-value.strong { font-weight: 700; }
.ce2-rows { display: grid; gap: 6px; font-size: 14px; }
.ce2-account p { margin: 1px 0 0; }
.fb-progress { margin: 0; }
.add-note { justify-self: start; }
.record ul { display: grid; gap: 2px; }
details.side-more > summary { padding: 2px 0; }
details.side-more > :not(summary) { margin: 6px 0 4px; }
.ce2-lookup { display: flex; gap: 6px; }
.ce2-lookup input { flex: 1; min-width: 0; }
.side-bar { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 18px 14px; border-top: 1px solid var(--rule); background: var(--card); box-shadow: 0 -6px 16px rgba(20, 24, 22, 0.06); }
.side-bar:empty { display: none; }
.side-bar button { padding: 9px 16px; }
.side-bar .bar-copy { flex: 1; }
.bar-note { flex-basis: 100%; font-size: 13px; color: var(--muted); }
.bar-note.due { color: var(--amber); font-weight: 600; }
details.later { position: relative; }
details.later > summary { list-style: none; display: inline-flex; align-items: center; padding: 9px 14px; border: 1px solid var(--rule-strong); border-radius: 8px; background: var(--card); color: var(--ink); font-size: 15px; cursor: pointer; white-space: nowrap; }
details.later > summary::-webkit-details-marker { display: none; }
details.later[open] > summary { border-color: var(--muted); }
.later-menu { position: absolute; right: 0; bottom: calc(100% + 6px); z-index: 5; display: grid; gap: 4px; min-width: 170px; padding: 6px; border: 1px solid var(--rule); border-radius: 10px; background: var(--card); box-shadow: 0 10px 30px rgba(20, 24, 22, 0.16); }
.later-menu button { justify-content: flex-start; border: 0; padding: 8px 10px; }
.later-menu button:hover { background: var(--ground); }

.day { align-self: center; margin: 10px 0 4px; padding: 2px 10px; border-radius: 99px; background: #e9e7e0; font-size: 12px; color: var(--muted); }
.event { align-self: center; font-size: 12px; color: var(--muted); }
.bubble-row { display: flex; align-items: flex-end; gap: 6px; max-width: 78%; }
.bubble-row.theirs { align-self: flex-start; }
.bubble-row.ours { align-self: flex-end; flex-direction: row-reverse; }
.bubble { padding: 8px 12px; border-radius: 16px; background: var(--card); border: 1px solid var(--rule); white-space: pre-wrap; word-break: break-word; }
.ours .bubble { background: #d6f5e1; border-color: #bfe9cf; }
/* what a bot or LINE sent on its own: outlined, so a person's answer stands out */
.ours.auto .bubble { background: #fff; border: 1px dashed #9fd9b5; color: #3b4a41; }
.bubble.media { padding: 4px; background: transparent; border: 0; }
.bubble.nofile { background: var(--ground); border-color: var(--rule); color: var(--muted); }
.ours .bubble.nofile { background: #eef8f1; }
.bubble-row .time { font-size: 11px; color: var(--muted); white-space: nowrap; }
.sticker { width: 96px; height: 96px; object-fit: contain; }
.photo { max-width: 240px; max-height: 240px; border-radius: 10px; display: block; }

.reason { font-weight: 600; }
.stale { padding: 6px 10px; border-radius: 8px; background: var(--amber-wash); color: var(--amber); font-size: 13px; }
textarea.reply { font-size: 15px; background: #fff; resize: none; overflow: hidden; }
select.saved { max-width: 140px; }
.tag-input { width: 110px; padding: 3px 8px; font-size: 13px; border-radius: 99px; }
form.inline { display: inline-flex; }
button.done-button { background: var(--ink); border-color: var(--ink); color: #fff; font-weight: 600; }
button.done-button:hover { background: #000; }
.notes { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.notes li { padding: 8px 10px; border-radius: 8px; background: var(--amber-wash); display: grid; gap: 2px; }
.note-form { display: grid; gap: 6px; justify-items: start; }
ul.plain { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
details summary { cursor: pointer; color: var(--muted); font-size: 13px; }
details > :not(summary) { margin-top: 6px; }

/* customers */
.customers { display: grid; grid-template-columns: 1fr 260px; gap: 16px; align-items: start; }
.customers-main { min-width: 0; }
.filters { display: grid; gap: 8px; margin-bottom: 12px; }
.search-row input.search { flex: 1; max-width: 520px; }
.segments { display: grid; gap: 8px; }
.segment { display: flex; gap: 6px; align-items: baseline; }
.table-wrap, .table-scroll { overflow-x: auto; }
.table-wrap { background: var(--card); border: 1px solid var(--rule); border-radius: var(--radius); }
/* nothing to show yet: no empty box */
.table-wrap:has(> .loading), .table-wrap:has(> .error) { background: none; border: 0; }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--rule); white-space: nowrap; }
table.list td { padding: 8px 10px; border-bottom: 1px solid #efede7; vertical-align: top; }
table.list tr.disabled td { color: var(--muted); text-decoration: line-through; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wide { min-width: 160px; }
td.pre { white-space: pre-wrap; max-width: 340px; font-size: 13px; }
td.draw { min-width: 180px; }
.table-note { padding: 10px; }
.customer { display: inline-flex; align-items: center; gap: 8px; color: var(--ink); text-decoration: none; font-weight: 600; }

/* reports */
.reports { display: grid; gap: 16px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.bar { position: relative; height: 20px; background: var(--ground); border-radius: 5px; overflow: hidden; }
.bar span { position: absolute; inset: 0 auto 0 0; background: #a9c9f6; }
.bar.group-important span { background: #f0a597; }
.bar.group-normal span { background: #c9c6bc; }
.bar.group-none span { background: #9fdcb7; }
.bar em { position: relative; font-style: normal; font-size: 12px; padding-left: 6px; line-height: 20px; font-variant-numeric: tabular-nums; }
.tag-row { display: grid; grid-template-columns: 120px 1fr; gap: 10px; align-items: center; font-size: 14px; }

/* settings */
.settings { display: grid; grid-template-columns: 180px 1fr; gap: 16px; align-items: start; }
.side-tabs { display: grid; gap: 2px; }
.side-tabs a { padding: 8px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; white-space: nowrap; }
.side-tabs a.active { background: var(--card); color: var(--ink); font-weight: 600; border: 1px solid var(--rule); }
.settings-body { display: grid; gap: 16px; min-width: 0; }
textarea.guide { font-size: 14px; }
.example, .saved-reply { padding: 10px; border: 1px solid var(--rule); border-radius: 10px; display: grid; gap: 4px; justify-items: start; }
form.card.row input { flex: 1; max-width: 320px; }
a.primary-link { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
a.primary-link:hover { background: var(--accent-deep); border-color: var(--accent-deep); }
ol.steps { margin: 0; padding-left: 22px; display: grid; gap: 14px; }
ol.steps li strong { display: block; margin-bottom: 2px; }
ul.faq { margin: 0; padding-left: 18px; display: grid; gap: 8px; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.92em; padding: 1px 5px; border-radius: 5px; background: var(--ground); }

/* history review */
.stats { grid-template-columns: repeat(6, 1fr); text-align: center; }
.stats div { display: grid; align-content: start; }
.stats strong { font-size: 22px; }
.stats span { font-size: 12px; color: var(--muted); }
.review { grid-template-columns: 1.2fr 1fr 1fr; gap: 16px; }
.review-convo { display: flex; flex-direction: column; gap: 6px; }
.review-convo .bubble-row { max-width: 100%; }
.review-ai, .review-staff { display: grid; gap: 6px; align-content: start; }
.suggest { padding: 10px; background: var(--accent-wash); border-radius: 10px; }
.review-staff .pre { padding: 10px; background: var(--ground); border-radius: 10px; }
.pager { justify-content: center; }
.grade-controls { margin-left: auto; align-self: center; }
.verdict { padding: 8px 10px; border-radius: 10px; font-size: 13px; background: var(--ground); }
.verdict.good { background: var(--green-wash); }
.verdict.edit { background: var(--amber-wash); }
.verdict.bad { background: var(--red-wash); }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); padding: 10px 18px; border-radius: 10px; background: var(--ink); color: #fff; font-size: 14px; z-index: 20; box-shadow: 0 6px 20px rgb(0 0 0 / 0.15); max-width: calc(100vw - 32px); }
#toast.error { background: var(--red); }

/* laptops: an open chat takes the whole width, with a way back to the list */
@media (max-width: 1100px) {
  .inbox:has(.chat) { grid-template-columns: 1fr; }
  .inbox:has(.chat) .list-pane { display: none; }
  .chat-head .back { display: block; }
  .review { grid-template-columns: 1fr; }
  .customers, .two { grid-template-columns: 1fr; }
}

/* phones */
@media (max-width: 760px) {
  :root { --bar: 48px; }
  .topbar { gap: 4px; padding: 0 10px; }
  .brand-name, .who-am-i { display: none; }
  .topbar nav a { padding: 6px 9px; }
  .page { padding: 14px; gap: 12px; }
  .inbox { grid-template-columns: 1fr; }
  /* the list alone until a chat is picked */
  .inbox:not(:has(.chat)) .chat-pane { display: none; }

  /* the chat: a short head, then the AI card, then the conversation, all in one scroll */
  .chat-head { flex-wrap: wrap; padding: 10px 12px; gap: 8px 10px; }
  .chat-head .avatar.large { width: 36px; height: 36px; }
  .chat-head .who { flex: 1; }
  .head-actions { width: 100%; margin-left: 0; justify-content: space-between; }
  .chat-body { display: flex; flex-direction: column; overflow-y: auto; }
  .chat-body .side { order: -1; }
  .thread, .side, .side-scroll { flex: none; min-height: auto; overflow: visible; }
  .thread { padding: 12px; }
  .side { border-left: 0; border-bottom: 1px solid var(--rule); }
  .side-scroll { padding: 0 12px 8px; }
  /* the actions stay at the bottom of the screen while the panel is in view */
  .side-bar { position: sticky; bottom: 0; z-index: 3; padding: 10px 12px; }
  .bubble-row { max-width: 90%; }

  .tally button { min-width: 70px; }
  .settings { grid-template-columns: 1fr; }
  .side-tabs { display: flex; overflow-x: auto; gap: 4px; }
  .stats { grid-template-columns: repeat(3, 1fr); }
  .tag-row { grid-template-columns: 90px 1fr; }
  .head-tools { margin-left: 0; width: 100%; }

  /* customers as cards: name and time on top, the rest below */
  table.customers-table thead { display: none; }
  table.customers-table tr { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px 12px; border-bottom: 1px solid #efede7; }
  table.customers-table td { padding: 0; border: 0; }
  table.customers-table td.email, table.customers-table td.tags, table.customers-table td.draw { grid-column: 1 / -1; }
  table.customers-table td.email:empty, table.customers-table td.draw:empty { display: none; }
  table.customers-table td.count { display: none; }
  table.customers-table td.last { order: 1; }
  table.customers-table td.email, table.customers-table td.tags, table.customers-table td.draw { order: 2; }
}

/* the customer's Chat Everywhere account, in the chat's side panel */
.ce2-state { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--ground); color: var(--muted); }
.ce2-state.active { background: var(--green-wash); color: var(--green-deep); }
/* the server's chat.line.biz reading needs someone (app.js) */
.server-alert { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 14px; padding: 8px 18px; background: var(--amber-wash); color: var(--amber); border-bottom: 1px solid var(--rule); font-weight: 600; }

/* customer feedback: a summary in the chat's side panel, the details in a popup */
.feedback h3 { display: flex; align-items: center; gap: 8px; }
.fb-status { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--ground); color: var(--muted); white-space: nowrap; flex: none; }
.fb-status.open { background: var(--red-wash); color: var(--red); }
.fb-status.promised { background: var(--amber-wash); color: var(--amber); }
.fb-status.answered { background: var(--green-wash); color: var(--green-deep); }
.fb-status.resolved { background: var(--accent-wash); color: var(--accent-deep); }
.fb-lines { gap: 2px; }
button.fb-line { display: flex; justify-content: flex-start; gap: 8px; align-items: center; width: calc(100% + 12px); padding: 5px 6px; margin: 0 -6px; border: 0; border-radius: 6px; background: none; text-align: left; font-size: 14px; }
button.fb-line:hover { background: var(--ground); }
.fb-line-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }

/* the popup: the list on the left, the picked item in full on the right */
dialog.fb-dialog { width: min(1120px, calc(100vw - 48px)); height: min(720px, calc(100vh - 48px)); max-width: none; max-height: none; padding: 0; border: 0; border-radius: 14px; background: var(--card); color: var(--ink); box-shadow: 0 24px 64px rgba(20, 24, 22, 0.3); overflow: hidden; }
dialog.fb-dialog[open] { display: flex; flex-direction: column; }
dialog.fb-dialog::backdrop { background: rgba(20, 24, 22, 0.42); }
.fb-dialog-head { display: flex; align-items: center; gap: 14px; padding: 16px 20px 14px 24px; border-bottom: 1px solid var(--rule); }
.fb-dialog-title { flex: 1; min-width: 0; }
.fb-dialog-title h2 { font-size: 19px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fb-dialog-title p { margin-top: 2px; }
button.fb-close { width: 40px; height: 40px; padding: 0; border: 0; border-radius: 8px; background: none; font-size: 26px; line-height: 1; color: var(--muted); }
button.fb-close:hover { background: var(--ground); color: var(--ink); }
.fb-panes { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(300px, 400px) 1fr; }

.fb-list-pane { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--rule); background: #fbfaf7; }
.fb-filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 14px; border-bottom: 1px solid var(--rule); }
button.fb-filter { padding: 5px 12px; border-radius: 999px; font-size: 13px; border-color: var(--rule); }
button.fb-filter.on { background: var(--ink); border-color: var(--ink); color: #fff; }
.fb-filter-count { opacity: 0.7; }
.fb-list { flex: 1; min-height: 0; overflow-y: auto; padding: 6px; gap: 2px; align-content: start; }
button.fb-list-item { display: block; width: 100%; padding: 10px 12px; border: 0; border-radius: 10px; background: none; text-align: left; white-space: normal; }
button.fb-list-item:hover { background: var(--ground); }
button.fb-list-item.picked { background: var(--accent-wash); }
.fb-list-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.fb-list-title { min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fb-list-meta { display: block; margin-top: 2px; font-size: 12px; color: var(--muted); }
.fb-list-empty { padding: 16px 12px; }

.fb-detail { min-height: 0; overflow-y: auto; padding: 22px 28px 0; display: flex; flex-direction: column; gap: 20px; }
.fb-detail-empty { margin: auto; }
.fb-detail-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
h3.fb-detail-title { margin-top: 10px; font-size: 21px; line-height: 1.35; }
.fb-detail-context { margin-top: 8px; max-width: 64ch; color: #3a423d; }
.fb-label { font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.fb-answer-box { padding: 12px 16px; border-radius: 10px; background: var(--ground); }
.fb-answer-box .link { margin-top: 4px; }
.fb-no-answer { color: var(--red); font-weight: 600; }
.fb-messages { gap: 12px; }
.fb-message { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.fb-bubble { max-width: min(460px, 100%); padding: 8px 12px; border-radius: 16px; background: var(--card); border: 1px solid var(--rule); white-space: pre-wrap; word-break: break-word; }
.fb-bubble.nofile { background: var(--ground); color: var(--muted); }
a.fb-shot img { display: block; max-width: 220px; max-height: 280px; border-radius: 10px; border: 1px solid var(--rule); }
.fb-message-time { font-size: 12px; color: var(--muted); white-space: nowrap; }
/* staff's controls, kept in view at the bottom of the item */
.fb-detail-foot { margin-top: auto; position: sticky; bottom: 0; padding: 12px 0 16px; border-top: 1px solid var(--rule); background: var(--card); display: grid; gap: 10px; }
.fb-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.fb-status-picker { display: inline-flex; flex-wrap: wrap; gap: 3px; padding: 3px; border-radius: 10px; background: var(--ground); }
button.fb-status-option { padding: 4px 11px; border: 0; border-radius: 7px; background: none; font-size: 13px; color: var(--muted); }
button.fb-status-option:hover { background: var(--card); color: var(--ink); }
button.fb-status-option.on { font-weight: 700; box-shadow: 0 1px 2px rgba(20, 24, 22, 0.15); }
button.fb-status-option.open.on { background: var(--red-wash); color: var(--red); }
button.fb-status-option.promised.on { background: var(--amber-wash); color: var(--amber); }
button.fb-status-option.answered.on { background: var(--green-wash); color: var(--green-deep); }
button.fb-status-option.resolved.on { background: var(--accent-wash); color: var(--accent-deep); }
button.fb-status-option.dismissed.on { background: var(--card); color: var(--ink); }
.fb-category { display: inline-flex; align-items: center; gap: 6px; }
.fb-category select { padding: 4px 8px; border-radius: 8px; border: 1px solid var(--rule-strong); background: var(--card); font-size: 13px; }
.fb-foot-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.fb-step { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; }

/* a message shown from the popup */
.bubble-row.flash .bubble { box-shadow: 0 0 0 3px var(--accent); transition: box-shadow 0.3s; }

@media (max-width: 760px) {
  dialog.fb-dialog { width: calc(100vw - 16px); height: calc(100vh - 16px); }
  .fb-dialog-head { flex-wrap: wrap; }
  .fb-panes { grid-template-columns: 1fr; grid-template-rows: minmax(0, 2fr) minmax(0, 3fr); }
  .fb-list-pane { border-right: 0; border-bottom: 1px solid var(--rule); }
  .fb-detail { padding: 16px 16px 0; }
}

/* 回饋: the same question or problem across customers (views/feedback.js) */
a.fb-issue-link { font-size: 13px; font-weight: 600; text-decoration: none; padding: 1px 8px; border-radius: 999px; background: var(--accent-wash); color: var(--accent-deep); }
a.fb-issue-link:hover { text-decoration: underline; }
.iss-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.iss-toolbar .fb-filters { padding: 0; border: 0; }
.iss-toolbar select { padding: 5px 8px; border-radius: 8px; border: 1px solid var(--rule-strong); background: var(--card); font-size: 14px; }
.iss-check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; }
.card.iss-panes { padding: 0; gap: 0; display: grid; grid-template-columns: minmax(300px, 400px) 1fr; height: calc(100vh - var(--bar) - 190px); min-height: 460px; overflow: hidden; }
.iss-list-pane { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--rule); background: #fbfaf7; }
button.fb-list-item.iss-item { border-radius: 0; }
.iss-item-top { display: flex; align-items: baseline; gap: 10px; }
.iss-item-top .fb-list-title { flex: 1; white-space: normal; }
.iss-count { flex: none; font-weight: 700; font-variant-numeric: tabular-nums; }
.iss-bar { display: block; height: 4px; margin: 6px 0 4px; border-radius: 2px; background: var(--rule); overflow: hidden; }
.iss-bar span { display: block; height: 100%; border-radius: 2px; background: var(--accent); }
.iss-waiting { color: var(--red); font-weight: 600; }
.iss-detail { min-height: 0; overflow-y: auto; padding: 22px 28px; display: flex; flex-direction: column; gap: 18px; }
h2.iss-title { margin-top: 10px; font-size: 21px; line-height: 1.35; }
.iss-title-row { display: flex; align-items: flex-start; gap: 12px; }
.iss-title-row h2.iss-title { flex: 1; min-width: 0; }
.iss-more-wrap { position: relative; flex: none; margin-top: 8px; }
button.iss-more { width: 36px; height: 32px; padding: 0; border-radius: 8px; font-size: 18px; line-height: 1; color: var(--muted); }
button.iss-more:hover, button.iss-more[aria-expanded="true"] { background: var(--ground); color: var(--ink); }
.iss-menu { position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; min-width: 180px; padding: 4px; border: 1px solid var(--rule); border-radius: 10px; background: var(--card); box-shadow: 0 8px 24px rgba(20, 24, 22, 0.14); display: grid; }
button.iss-menu-item { padding: 8px 12px; border: 0; border-radius: 6px; background: none; text-align: left; font-size: 14px; }
button.iss-menu-item:hover, button.iss-menu-item:focus-visible { background: var(--ground); }
button.iss-move { flex: none; white-space: nowrap; }
dialog.iss-pick-dialog { width: min(520px, calc(100vw - 32px)); max-height: min(640px, calc(100vh - 48px)); padding: 0; border: 0; border-radius: 14px; background: var(--card); color: var(--ink); box-shadow: 0 24px 64px rgba(20, 24, 22, 0.3); }
dialog.iss-pick-dialog[open] { display: flex; flex-direction: column; }
dialog.iss-pick-dialog::backdrop { background: rgba(20, 24, 22, 0.42); }
.iss-pick-head { display: flex; align-items: center; gap: 12px; padding: 14px 14px 10px 20px; }
.iss-pick-head h2 { flex: 1; min-width: 0; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
dialog.iss-pick-dialog input[type="search"] { margin: 0 20px 10px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--rule-strong); font: inherit; }
.iss-pick-list { flex: 1; min-height: 0; overflow-y: auto; padding: 0 8px 10px; gap: 2px; }
button.iss-pick { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; width: 100%; padding: 9px 12px; border: 0; border-radius: 8px; background: none; text-align: left; white-space: normal; }
button.iss-pick:hover, button.iss-pick:focus-visible { background: var(--accent-wash); }
button.iss-pick .muted { flex: none; }
button.iss-pick.extra { color: var(--accent-deep); font-weight: 600; }
.iss-pick-empty { padding: 12px; }
.iss-rename { display: grid; gap: 10px; max-width: 560px; }
.iss-rename label { display: grid; gap: 4px; }
.iss-rename input, .iss-rename textarea { padding: 6px 10px; border-radius: 8px; border: 1px solid var(--rule-strong); font: inherit; }
.iss-summary { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-bottom: 12px; border-bottom: 1px solid var(--rule); }
.iss-customers { gap: 0; }
.iss-customer { display: grid; grid-template-columns: 170px 1fr auto; gap: 12px; align-items: start; padding: 12px 0; border-bottom: 1px solid var(--rule); }
.iss-customer.dismissed { opacity: 0.55; }
a.iss-who { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--ink); text-decoration: none; font-weight: 600; }
a.iss-who:hover span { text-decoration: underline; }
a.iss-who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.iss-said { display: grid; gap: 3px; min-width: 0; }
.iss-said-title { font-weight: 600; min-width: 0; }
.iss-status { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }
.iss-admin { display: inline-flex; gap: 6px; }

@media (max-width: 760px) {
  .card.iss-panes { grid-template-columns: 1fr; grid-template-rows: minmax(0, 2fr) minmax(0, 3fr); height: calc(100vh - var(--bar) - 150px); }
  .iss-list-pane { border-right: 0; border-bottom: 1px solid var(--rule); }
  .iss-detail { padding: 16px; }
  .iss-customer { grid-template-columns: 1fr; gap: 6px; }
}

/* call recordings from the Plaud card (views/recordings.js), and on a customer's chat */
.rec-list { display: grid; gap: 12px; max-width: 760px; }
.rec-card { gap: 8px; }
.rec-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; }
.rec-name { flex-basis: 100%; }
.rec-audio { width: 100%; height: 40px; }
details.rec-more summary { cursor: pointer; font-size: 13px; }
.rec-preview { color: var(--muted); }
.rec-open { color: var(--accent-deep); white-space: nowrap; }
.rec-transcript { display: grid; gap: 6px; padding-top: 8px; }
.rec-segments { display: grid; gap: 6px; font-size: 13px; max-height: 360px; overflow-y: auto; }
.rec-at { color: var(--muted); font-variant-numeric: tabular-nums; margin-right: 8px; }
.rec-picker { display: grid; gap: 10px; border-top: 1px solid var(--rule); padding-top: 10px; }
.rec-results { display: grid; gap: 4px; margin-top: 4px; }
button.rec-choice { width: 100%; justify-content: flex-start; gap: 10px; padding: 8px 10px; white-space: normal; text-align: left; }
.rec-choice-name { font-weight: 600; }
.rec-choice .muted { margin-left: auto; text-align: right; }
input.rec-search { width: 100%; }
.rec-who { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chat-recording { display: grid; gap: 4px; padding: 6px 0; }
.chat-recording + .chat-recording { border-top: 1px solid var(--rule); }

@media (max-width: 760px) {
  /* six pages in the bar: it scrolls sideways on a phone */
  .topbar nav { flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .rec-choice .muted { flex-basis: 100%; margin-left: 36px; text-align: left; }
  button.rec-choice { flex-wrap: wrap; }
}

/* customers not on LINE (views/contacts.js) */
.contact-page { display: grid; gap: 14px; max-width: 760px; }
.contact-facts { display: grid; grid-template-columns: 80px 1fr; gap: 6px 12px; margin: 0; font-size: 14px; }
.contact-facts dt { color: var(--muted); }
.contact-facts dd { margin: 0; }
.contact-form textarea { max-width: 420px; }
.rec-create { display: grid; gap: 8px; }
.rec-create .contact-form { padding: 12px; border: 1px solid var(--rule); border-radius: 10px; background: var(--ground); }
a.back-link { flex-basis: 100%; font-size: 13px; text-decoration: none; }
/* on the page ground, an initial needs the card colour to show as a circle */
.page-head .avatar.initial { background: var(--card); border: 1px solid var(--rule); }

/* a moment in a call where a feedback item came from (views/recordings.js callMoment) */
.fb-bubble.fb-call { background: var(--accent-wash); }
.fb-call-label { display: block; font-size: 12px; font-weight: 600; color: var(--accent-deep); margin-bottom: 2px; }
.fb-call-play { margin-top: 4px; }
.contact-feedback { gap: 12px; }
.contact-item { display: grid; gap: 4px; padding-bottom: 12px; border-bottom: 1px solid var(--rule); }
.contact-item:last-child { border-bottom: 0; padding-bottom: 0; }
.contact-item .fb-list-top { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
