:root {
  color-scheme: light dark;
  --bg: #fcfcfb;
  --side: #f3f3ef;
  --raise: #ffffff;
  --line: #e3e2dc;
  --text: #1c1f1e;
  --muted: #626866;
  --accent: #0b6b61;
  --accent-text: #ffffff;
  --accent-soft: #dff0ec;
  --hover: #ebebe6;
  --note: #fbf1cf;
  --note-text: #5c4500;
  --out: #eef5f3;
  --good: #1a6a3a;
  --good-soft: #dcf0e2;
  --warn: #7a5200;
  --warn-soft: #f8ecc8;
  --bad: #ad2018;
  --bad-soft: #fbe3e0;
  --shadow: 0 6px 24px rgb(20 30 28 / 0.14);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161819;
    --side: #1c1f20;
    --raise: #212526;
    --line: #2e3335;
    --text: #e6e9e7;
    --muted: #a1a8a5;
    --accent: #56c4b3;
    --accent-text: #06231f;
    --accent-soft: #1b3834;
    --hover: #262b2c;
    --note: #37300f;
    --note-text: #f1dc8f;
    --out: #1b2928;
    --good: #7fd49a;
    --good-soft: #17301f;
    --warn: #e9c46a;
    --warn-soft: #382f12;
    --bad: #ff9a8f;
    --bad-soft: #40201d;
    --shadow: 0 6px 24px rgb(0 0 0 / 0.5);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.45 var(--font); color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
::selection { background: var(--accent-soft); color: var(--text); }
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
h1, h2, h3, p { margin: 0; }
a { color: var(--accent); text-underline-offset: 2px; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { caret-color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
[hidden] { display: none !important; }
time, .count, .stats b, td { font-variant-numeric: tabular-nums; }

.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* ── layout ── */
.app { display: grid; grid-template-columns: 208px 340px minmax(0, 1fr) 304px; height: 100vh; height: 100dvh; }
#nav, #list, #main, #panel { min-height: 0; min-width: 0; }
#nav { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; gap: 14px; padding: 14px 10px 10px; }
#list { border-right: 1px solid var(--line); display: flex; flex-direction: column; }
#main { display: flex; flex-direction: column; }
#panel { background: var(--side); border-left: 1px solid var(--line); overflow-y: auto; }
.wide-main #list, .wide-main #panel { display: none; }
.wide-main .app { grid-template-columns: 208px minmax(0, 1fr); }
.signed-out .app { display: none; }

/* ── buttons, badges, fields ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 32px; padding: 0 12px; border: 1px solid var(--line); border-radius: 7px; background: var(--raise); cursor: pointer; white-space: nowrap; transition: background 0.15s, border-color 0.15s; }
.btn:hover { background: var(--hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); }
.btn.quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn.quiet:hover { background: var(--hover); color: var(--text); }
.btn.danger { color: var(--bad); }
.btn.icon-only { width: 32px; padding: 0; }
.btn.urgent-on { color: var(--bad); }
.badge { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 10px; font-size: 12px; font-weight: 600; background: var(--hover); color: var(--muted); white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.avatar { display: inline-grid; place-items: center; flex: none; width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 700; }
.avatar.small { width: 26px; height: 26px; font-size: 11px; }
.avatar.tiny { width: 20px; height: 20px; font-size: 9px; }
input[type="text"], input[type="email"], input[type="search"], input[type="password"], select, textarea { background: var(--raise); border: 1px solid var(--line); border-radius: 7px; padding: 6px 9px; min-height: 32px; }
textarea { display: block; width: 100%; resize: none; line-height: 1.5; }
::placeholder { color: var(--muted); opacity: 1; }
.bar { height: 10px; border-radius: 5px; background: var(--hover); margin: 8px 0; animation: pulse 1.2s ease-in-out infinite alternate; }
.w40 { width: 40%; } .w60 { width: 60%; } .w80 { width: 80%; }
@keyframes pulse { from { opacity: 0.55; } to { opacity: 1; } }

/* ── nav ── */
.brand { display: flex; align-items: center; gap: 8px; padding: 0 6px; }
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.dot.on { background: var(--good); }
.nav-group { display: flex; flex-direction: column; gap: 1px; }
.nav-item { white-space: nowrap; display: flex; align-items: center; gap: 9px; width: 100%; height: 32px; padding: 0 8px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); text-align: left; cursor: pointer; }
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.count { font-size: 12px; font-weight: 600; }
.store-pick { width: 100%; }
.store-tag { flex: none; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 6px; border-radius: 4px; background: var(--hover); color: var(--muted); font-size: 11px; font-weight: 600; line-height: 18px; }
.row.on .store-tag { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.me { display: flex; align-items: center; gap: 8px; padding: 8px 4px 0 6px; border-top: 1px solid var(--line); }

/* ── list ── */
.search { display: flex; align-items: center; gap: 8px; margin: 12px 12px 0; padding: 0 10px; height: 34px; border: 1px solid var(--line); border-radius: 8px; background: var(--raise); color: var(--muted); }
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; border: 0; background: transparent; padding: 0; min-height: 0; outline: none; color: var(--text); }
.list-head { display: flex; align-items: center; gap: 6px; padding: 10px 8px 6px 14px; min-height: 48px; }
.list-head h2 { font-size: 15px; font-weight: 700; }
.list-head.picking { background: var(--accent-soft); }
.count-inline { margin-left: 8px; font-weight: 500; font-size: 13px; }
.rows { flex: 1; overflow-y: auto; padding: 0 6px 12px; display: flex; flex-direction: column; gap: 1px; }
.row { position: relative; padding: 9px 10px 9px 22px; border-radius: 8px; cursor: pointer; }
.row:hover { background: var(--hover); }
.row.on { background: var(--accent-soft); }
.row.skeleton { cursor: default; padding-left: 10px; }
.row-top, .row-bottom { display: flex; align-items: center; gap: 6px; }
.row .who { flex: 1; color: var(--muted); }
.row time { font-size: 12px; color: var(--muted); }
.row .subject { color: var(--muted); }
.row .preview { flex: 1; font-size: 13px; color: var(--muted); }
.row.unread .who { color: var(--text); font-weight: 700; }
.row.unread .subject { color: var(--text); font-weight: 600; }
.row.unread::before { content: ""; position: absolute; left: 9px; top: 15px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.row .pick { position: absolute; left: 5px; top: 11px; margin: 0; width: 14px; height: 14px; opacity: 0; accent-color: var(--accent); }
.row:hover .pick, .row.picked .pick, .row .pick:focus-visible { opacity: 1; }
.row:hover::before, .row.picked::before { display: none; }
.row .urgent { color: var(--bad); display: inline-flex; }
.row .watch { color: var(--accent); display: inline-flex; }
.empty { padding: 28px 18px; color: var(--muted); }

/* ── thread ── */
.thread-head { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-bottom: 1px solid var(--line); min-height: 60px; }
.thread-head h1 { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.thread-head .sub { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.viewing { display: inline-flex; align-items: center; gap: 4px; color: var(--accent); }
.assign { max-width: 150px; }
.thread-head .btn[aria-label="Back"], .thread-head .btn[aria-label="Customer"] { display: none; }
.msgs { flex: 1; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; outline: none; }
.msg { max-width: 760px; width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--raise); }
.msg.out { align-self: flex-end; background: var(--out); border-color: transparent; }
.msg.note { background: var(--note); border-color: transparent; color: var(--note-text); }
.msg.note .muted, .msg.note time { color: inherit; opacity: 0.8; }
.msg.sending { opacity: 0.7; }
.msg-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.msg-head time { font-size: 12px; color: var(--muted); }
.body { white-space: pre-wrap; overflow-wrap: anywhere; max-width: 72ch; }
.body.quoted { margin-top: 6px; padding-left: 12px; color: var(--muted); border-left: 1px solid var(--line); }
.msg .btn.quiet { height: 26px; padding: 0 6px; margin: 6px 0 0 -6px; font-size: 13px; }
.event { align-self: center; font-size: 12px; color: var(--muted); display: flex; gap: 8px; }
.files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip { display: inline-flex; align-items: center; gap: 6px; max-width: 280px; height: 30px; padding: 0 10px; border: 1px solid var(--line); border-radius: 7px; background: var(--raise); color: var(--text); text-decoration: none; font-size: 13px; }
.chip .btn { height: 22px; width: 22px; margin-right: -6px; }
.thumb img { display: block; width: 120px; height: 90px; object-fit: cover; border-radius: 7px; border: 1px solid var(--line); background: var(--hover); }
.failed { display: flex; align-items: center; gap: 10px; margin-top: 10px; padding: 8px 10px; border-radius: 7px; background: var(--bad-soft); color: var(--bad); }
.original { display: block; width: 100%; height: 460px; margin-top: 8px; border: 1px solid var(--line); border-radius: 7px; background: #fff; resize: vertical; }
.blank { margin: auto; text-align: center; display: grid; gap: 6px; padding: 24px; }
.blank p:first-child { font-size: 16px; font-weight: 600; }
.thread-skeleton, .panel-skeleton { padding: 24px; }

.ai-bar { display: flex; align-items: center; gap: 8px; padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--side); font-size: 13px; }
.ai-bar .icon, .ai-note > .icon { color: var(--accent); }
.ai-note { display: flex; align-items: flex-start; gap: 8px; padding: 8px 10px; border-radius: 8px; background: var(--accent-soft); font-size: 13px; }
.ai-note ul { margin: 4px 0 0; padding-left: 18px; }
.ai-note .btn { height: 26px; }
.redo { display: flex; gap: 8px; }
.redo input { flex: 1; }
.guard { color: var(--bad); font-size: 13px; text-align: right; }
.topic-pick { max-width: 130px; min-height: 28px; padding: 2px 6px; font-size: 13px; }
.lede { margin: -12px 0 18px; max-width: 70ch; }
.kb-find { margin-bottom: 8px; }
.kb-items { display: grid; gap: 1px; max-height: calc(100vh - 260px); overflow-y: auto; }

/* ── composer ── */
.composer { border-top: 1px solid var(--line); padding: 10px 16px 14px; display: grid; gap: 8px; background: var(--bg); }
.composer.note { background: var(--note); }
.composer.note textarea { background: transparent; border-color: color-mix(in srgb, var(--note-text) 25%, transparent); color: var(--note-text); }
.composer.note ::placeholder { color: var(--note-text); opacity: 0.75; }
.composer-top, .composer-actions { display: flex; align-items: center; gap: 8px; }
.seg { display: inline-flex; padding: 2px; border-radius: 8px; background: var(--hover); }
.seg button { height: 26px; padding: 0 12px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--raise); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / 0.12); }
.to { display: flex; align-items: center; gap: 8px; }
.to input { flex: 1; border-color: transparent; background: transparent; min-height: 28px; padding: 2px 6px; }
.to input:hover, .to input:focus { border-color: var(--line); background: var(--raise); }
.writing { position: relative; }
.macro-menu { position: absolute; left: 0; bottom: calc(100% + 6px); z-index: 5; width: min(520px, 100%); padding: 4px; border: 1px solid var(--line); border-radius: 10px; background: var(--raise); box-shadow: var(--shadow); }
.macro { display: flex; gap: 10px; width: 100%; padding: 7px 9px; border: 0; border-radius: 6px; background: transparent; text-align: left; cursor: pointer; }
.macro.on, .macro:hover { background: var(--accent-soft); }
.macro strong { flex: none; }
.pad { padding: 8px; }

/* ── customer panel ── */
#panel section { padding: 14px 16px; border-bottom: 1px solid var(--line); }
#panel h3 { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 8px; }
.name-edit { width: 100%; font-size: 16px; font-weight: 700; border-color: transparent !important; background: transparent !important; padding: 2px 6px !important; margin-left: -6px; }
.name-edit:hover, .name-edit:focus { border-color: var(--line) !important; background: var(--raise) !important; }
.copy { display: block; max-width: 100%; padding: 0; border: 0; background: none; cursor: pointer; overflow: hidden; text-overflow: ellipsis; }
.copy:hover { color: var(--text); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.stats div { display: grid; }
.stats b { font-size: 16px; }
.order { padding: 9px 0; border-top: 1px solid var(--line); display: grid; gap: 3px; font-size: 13px; }
.order-top, .order-meta, .track { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.order-top a { font-weight: 600; }
.items { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.past { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 8px; margin: 0 -8px; border: 0; border-radius: 6px; background: transparent; text-align: left; cursor: pointer; font-size: 13px; }
.past:hover { background: var(--hover); }
.past time { color: var(--muted); font-size: 12px; }
.notes { background: var(--raise); font-size: 13px; resize: vertical; }

/* ── pages ── */
.page { padding: 28px 36px; overflow-y: auto; height: 100%; max-width: 1000px; }
.page h1 { font-size: 20px; letter-spacing: -0.01em; margin-bottom: 20px; }
.form { display: grid; gap: 12px; max-width: 720px; }
.form label { display: grid; gap: 4px; }
.form label > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.invite { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.invite input[type="email"] { width: 260px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); }
thead th { font-size: 12px; color: var(--muted); font-weight: 700; }
tr.off td { opacity: 0.55; }
td.actions { text-align: right; white-space: nowrap; }
td.actions > * { vertical-align: middle; margin-left: 8px; }
.cell-edit { border-color: transparent !important; background: transparent !important; margin-left: -9px; font-weight: 600; }
.cell-edit:hover, .cell-edit:focus { border-color: var(--line) !important; background: var(--raise) !important; }
table.status th { width: 220px; font-weight: 600; }
table.status td:nth-child(2) { width: 150px; }
.switch { position: relative; display: inline-block; width: 36px; height: 20px; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 10px; background: var(--line); transition: background 0.15s; }
.switch span::after { content: ""; position: absolute; left: 2px; top: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--raise); transition: transform 0.15s; box-shadow: 0 1px 2px rgb(0 0 0 / 0.3); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.split { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 28px; align-items: start; }
.macro-list { display: grid; gap: 1px; }
.macro-list .btn { margin-bottom: 8px; }
.devlink { margin: 0 0 16px; padding: 8px 10px; border-radius: 7px; background: var(--warn-soft); color: var(--warn); overflow-wrap: anywhere; }

/* ── sign-in, toast ── */
#login { display: none; }
.signed-out #login { display: grid; place-items: center; min-height: 100vh; padding: 20px; background: var(--side); }
.login-card { width: min(380px, 100%); padding: 28px; border: 1px solid var(--line); border-radius: 12px; background: var(--raise); box-shadow: var(--shadow); display: grid; gap: 16px; }
.login-card h1 { font-size: 20px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); padding: 9px 14px; border-radius: 8px; background: var(--text); color: var(--bg); box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity 0.18s, transform 0.18s cubic-bezier(0.16, 1, 0.3, 1); z-index: 20; max-width: min(90vw, 520px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--bad); color: #fff; }

/* ── smaller screens ── */
@media (max-width: 1240px) {
  .app { grid-template-columns: 196px 310px minmax(0, 1fr); }
  #panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(320px, 92vw); transform: translateX(100%); transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1); z-index: 10; box-shadow: var(--shadow); }
  .panel-open #panel { transform: none; }
  .thread-head .btn[aria-label="Customer"] { display: inline-flex; }
}
@media (max-width: 860px) {
  .app, .wide-main .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  #nav { flex-direction: row; align-items: center; gap: 4px; padding: 6px 8px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  #nav .brand, #nav > .grow, #nav .me .grow, #nav .me .avatar { display: none; }
  #nav .nav-group { flex-direction: row; }
  #nav .nav-item { width: auto; }
  #nav .me { border: 0; padding: 0; }
  .has-thread #list { display: none; }
  body:not(.has-thread) #main { display: none; }
  .thread-head .btn[aria-label="Back"] { display: inline-flex; }
  .thread-head { flex-wrap: wrap; padding: 8px 10px; }
  .thread-head .title { flex: 1 1 calc(100% - 48px); }
  .thread-head .assign { flex: 1; max-width: none; }
  .msgs { padding: 12px 10px; }
  .composer { padding: 8px 10px 10px; }
  .page { padding: 18px 14px; }
  .split { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* Chats page: the website chat's conversations. */
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.page-head h1 { margin: 0; }
.switch-label { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
a.badge { text-decoration: none; }
a.badge:hover { text-decoration: underline; }
.chat-rows tbody tr { cursor: pointer; }
.chat-rows tbody tr:hover { background: var(--hover); }
.chat-rows tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.chat-rows td.ellipsis { max-width: 200px; }
.chat-log { display: flex; flex-direction: column; gap: 6px; max-width: 700px; padding-bottom: 40px; }
.chat-line { max-width: 82%; padding: 8px 12px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-line.customer { align-self: flex-start; background: var(--raise); border: 1px solid var(--line); }
.chat-line.bot { align-self: flex-end; background: var(--out); }
.chat-line.lookup { align-self: stretch; max-width: none; font-size: 12px; color: var(--muted); border: 1px dashed var(--line); }
.chat-line.event { align-self: center; font-size: 12px; color: var(--muted); padding: 4px 0; }
a.btn { text-decoration: none; color: inherit; }
