:root {
  --ink: #1d2433;
  --ink-2: #4a5468;
  --ink-3: #8a93a6;
  --canvas: #f3f5f9;
  --paper: #ffffff;
  --line: #e2e6ee;
  --phthalo: #0e7c66;
  --phthalo-dark: #0a5e4d;
  --phthalo-tint: #e2f3ee;
  --staff-bubble: #0e7c66;
  --cadmium: #f2b705;
  --cadmium-tint: #fff5cf;
  --alizarin: #c8323c;
  --alizarin-tint: #fde7e8;
  --ultra: #2f4fb3;
  --radius-s: 8px;
  --radius-m: 14px;
  --radius-l: 22px;
  --shadow: 0 1px 2px rgba(29, 36, 51, 0.08), 0 4px 16px rgba(29, 36, 51, 0.06);
  --tab-h: 62px;
  --font: "Hind Siliguri", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e8ecf4;
    --ink-2: #b5bdcc;
    --ink-3: #7d8699;
    --canvas: #12161f;
    --paper: #1b212d;
    --line: #2a3242;
    --phthalo: #2fb894;
    --phthalo-dark: #1f9a7a;
    --phthalo-tint: #15352e;
    --staff-bubble: #12614f;
    --cadmium-tint: #3a3110;
    --alizarin-tint: #3f1a1d;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--phthalo); }
:focus-visible { outline: 2px solid var(--ultra); outline-offset: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ── shell ── */
#app { height: 100%; display: flex; flex-direction: column; }
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: var(--paper); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 20px; font-weight: 700; margin: 0; flex: 1; letter-spacing: -0.01em; }
.topbar .sub { font-size: 12.5px; color: var(--ink-3); line-height: 1.2; }
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom)); }
.pad { padding: 14px; }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--tab-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--paper); border-top: 1px solid var(--line);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--ink-3); font-size: 11.5px; font-weight: 500; position: relative;
}
.tabs a svg { width: 23px; height: 23px; }
.tabs a.on { color: var(--phthalo); }
.tabs a.on::before { content: ""; position: absolute; top: 0; left: 30%; right: 30%; height: 3px; border-radius: 0 0 3px 3px; background: var(--phthalo); }
.tabs .badge { position: absolute; top: 7px; left: calc(50% + 6px); }

.badge {
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--alizarin); color: #fff; font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; line-height: 1;
}
.badge.green { background: var(--phthalo); }
.badge.yellow { background: var(--cadmium); color: #3a2c00; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent;
  display: inline-flex; align-items: center; justify-content: center; color: var(--ink-2); cursor: pointer; flex-shrink: 0;
}
.icon-btn:hover { background: var(--canvas); }
.icon-btn svg { width: 22px; height: 22px; }

.btn {
  border: 0; border-radius: 999px; padding: 10px 18px; font-weight: 600; cursor: pointer;
  background: var(--phthalo); color: #fff; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px;
}
.btn:hover { background: var(--phthalo-dark); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.ghost { background: transparent; color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn.ghost:hover { background: var(--canvas); }
.btn.danger { background: var(--alizarin); }
.btn.yellow { background: var(--cadmium); color: #3a2c00; }
.btn.small { padding: 6px 12px; min-height: 34px; font-size: 13.5px; }
.btn.block { width: 100%; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.center { text-align: center; }

/* ── forms ── */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
.input, textarea.input, select.input {
  width: 100%; border: 1.5px solid var(--line); background: var(--paper); border-radius: var(--radius-s);
  padding: 10px 12px; outline: none; min-height: 44px;
}
.input:focus { border-color: var(--phthalo); }
textarea.input { resize: vertical; min-height: 84px; }
.help { font-size: 12.5px; color: var(--ink-3); margin-top: 3px; }
.switch { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.switch:last-child { border-bottom: 0; }
.switch .grow b { display: block; font-weight: 600; }
.switch .grow small { color: var(--ink-3); font-size: 12.5px; display: block; line-height: 1.35; }
.toggle { appearance: none; width: 46px; height: 28px; border-radius: 14px; background: var(--line); position: relative; cursor: pointer; flex-shrink: 0; transition: background 0.15s; margin: 0; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: transform 0.15s; }
.toggle:checked { background: var(--phthalo); }
.toggle:checked::after { transform: translateX(18px); }

.card { background: var(--paper); border-radius: var(--radius-m); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; }
.card h3 { margin: 0 0 8px; font-size: 16px; }
.section-title { font-size: 14px; font-weight: 700; color: var(--ink-2); margin: 18px 4px 8px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 10px 14px; scrollbar-width: none; background: var(--paper); border-bottom: 1px solid var(--line); }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0; border: 1.5px solid var(--line); background: var(--paper); border-radius: 999px;
  padding: 5px 13px; font-size: 13.5px; font-weight: 500; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; white-space: nowrap;
}
.chip.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.search { padding: 10px 14px 0; background: var(--paper); }
.search .input { border-radius: 999px; padding-left: 40px; background: var(--canvas) no-repeat 14px 50%/18px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a93a6' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E"); border-color: transparent; }

/* ── conversation list ── */
.conv { display: flex; gap: 12px; padding: 12px 14px; text-decoration: none; color: inherit; border-bottom: 1px solid var(--line); background: var(--paper); align-items: center; }
.conv:hover, .conv.active { background: var(--phthalo-tint); }
.avatar {
  width: 48px; height: 48px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 17px; color: #fff; position: relative; background-size: cover; background-position: center;
}
.avatar .ring { position: absolute; inset: -3px; border-radius: 50%; border: 2.5px solid transparent; }
.avatar .ring.bot { border-color: var(--cadmium); }
.avatar .ring.human { border-color: var(--alizarin); }
.avatar.sm { width: 34px; height: 34px; font-size: 13px; }
.conv .mid { flex: 1; min-width: 0; }
.conv .top { display: flex; gap: 8px; align-items: baseline; }
.conv .name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .time { font-size: 12px; color: var(--ink-3); flex-shrink: 0; }
.conv .last { font-size: 13.5px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; gap: 6px; align-items: center; }
.conv.unread .name, .conv.unread .last { font-weight: 700; color: var(--ink); }
.conv .meta { display: flex; gap: 6px; margin-top: 3px; align-items: center; }
.tag { font-size: 11.5px; padding: 1px 8px; border-radius: 999px; background: var(--canvas); color: var(--ink-2); font-weight: 500; white-space: nowrap; }
.tag.bot { background: var(--cadmium-tint); color: #6b5200; }
.tag.human { background: var(--alizarin-tint); color: var(--alizarin); }
.tag.green { background: var(--phthalo-tint); color: var(--phthalo); }
@media (prefers-color-scheme: dark) { .tag.bot { color: var(--cadmium); } }

.empty { text-align: center; padding: 48px 24px; color: var(--ink-3); }
.empty b { display: block; color: var(--ink); font-size: 17px; margin-bottom: 6px; }

/* ── chat ── */
.chat { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--canvas); }
.mode-strip {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px; font-size: 13.5px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.mode-strip .swatch { width: 14px; height: 14px; border-radius: 4px; flex-shrink: 0; }
.mode-strip.bot { background: var(--cadmium-tint); }
.mode-strip.bot .swatch { background: var(--cadmium); }
.mode-strip.human { background: var(--phthalo-tint); }
.mode-strip.human .swatch { background: var(--phthalo); }
.mode-strip.need { background: var(--alizarin-tint); color: var(--alizarin); font-weight: 600; }
.mode-strip.need .swatch { background: var(--alizarin); }
.mode-strip.off { background: var(--paper); color: var(--ink-2); }
.mode-strip.off .swatch { background: var(--line); }
.mode-strip .grow small { display: block; color: var(--ink-3); font-weight: 400; font-size: 12px; }

.messages { flex: 1; overflow-y: auto; padding: 14px 12px 8px; display: flex; flex-direction: column; gap: 4px; }
.day { align-self: center; font-size: 12px; color: var(--ink-3); background: var(--paper); padding: 2px 10px; border-radius: 999px; margin: 10px 0 6px; }
.msg { max-width: 82%; display: flex; flex-direction: column; }
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.msg .bubble { padding: 8px 12px; border-radius: 18px; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.in .bubble { background: var(--paper); border-bottom-left-radius: 6px; box-shadow: var(--shadow); }
.msg.out.staff .bubble, .msg.out.page .bubble { background: var(--staff-bubble); color: #fff; border-bottom-right-radius: 6px; }
.msg.out.bot .bubble { background: var(--cadmium-tint); color: var(--ink); border-bottom-right-radius: 6px; box-shadow: inset 0 0 0 1.5px var(--cadmium); }
.msg .who { font-size: 11.5px; color: var(--ink-3); margin: 2px 6px 6px; }
.msg .who.fail { color: var(--alizarin); font-weight: 600; }
.msg .att img { max-width: 220px; border-radius: 14px; display: block; }
.msg.sys { align-self: center; max-width: 92%; }
.msg.sys .bubble { background: transparent; color: var(--ink-2); font-size: 12.5px; text-align: center; padding: 2px 8px; }
.cards { display: flex; gap: 8px; overflow-x: auto; max-width: 100%; padding-bottom: 2px; }
.pcard { width: 150px; flex-shrink: 0; background: var(--paper); border-radius: var(--radius-m); overflow: hidden; box-shadow: var(--shadow); text-decoration: none; color: var(--ink); }
.pcard img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--canvas); }
.pcard div { padding: 6px 8px; font-size: 12.5px; line-height: 1.3; }
.pcard b { display: block; color: var(--phthalo); }

.composer { background: var(--paper); border-top: 1px solid var(--line); padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
.composer .tools { display: flex; gap: 2px; margin-bottom: 4px; }
.composer .tools button { border: 0; background: var(--canvas); border-radius: 999px; padding: 5px 11px; font-size: 13px; font-weight: 500; cursor: pointer; display: inline-flex; gap: 5px; align-items: center; color: var(--ink-2); }
.composer .line { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; border: 1.5px solid var(--line); border-radius: 22px; padding: 10px 14px; max-height: 140px; min-height: 44px; background: var(--canvas); outline: none; line-height: 1.35; }
.composer textarea:focus { border-color: var(--phthalo); background: var(--paper); }
.send { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--phthalo); color: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.send:disabled { background: var(--line); }
.window-warn { font-size: 12.5px; color: var(--alizarin); padding: 0 6px 6px; }

/* ── bottom sheet ── */
.sheet-back { position: fixed; inset: 0; background: rgba(15, 20, 30, 0.45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; animation: fade 0.15s; }
.sheet {
  background: var(--paper); width: 100%; max-width: 640px; max-height: 92vh; border-radius: var(--radius-l) var(--radius-l) 0 0;
  display: flex; flex-direction: column; animation: up 0.2s ease-out; padding-bottom: env(safe-area-inset-bottom);
}
.sheet header { display: flex; align-items: center; padding: 14px 16px 10px; gap: 8px; border-bottom: 1px solid var(--line); }
.sheet header h2 { margin: 0; font-size: 18px; flex: 1; }
.sheet .body { overflow-y: auto; padding: 14px 16px; flex: 1; }
.sheet footer { padding: 10px 16px 14px; border-top: 1px solid var(--line); display: flex; gap: 8px; }
@keyframes up { from { transform: translateY(40px); opacity: 0.4; } }
@keyframes fade { from { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet, .sheet-back { animation: none; } }

.plist .p { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.plist .p img { width: 52px; height: 52px; border-radius: var(--radius-s); object-fit: cover; background: var(--canvas); flex-shrink: 0; }
.plist .p .grow { min-width: 0; }
.plist .p .n { font-size: 14px; font-weight: 500; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.plist .p .pr { font-size: 13px; color: var(--phthalo); font-weight: 600; }
.plist .p .pr s { color: var(--ink-3); font-weight: 400; margin-left: 4px; }
.plist .p.sel { background: var(--phthalo-tint); margin: 0 -16px; padding: 8px 16px; }
.check { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: #fff; }
.sel .check { background: var(--phthalo); border-color: var(--phthalo); }

.qty { display: inline-flex; align-items: center; border: 1.5px solid var(--line); border-radius: 999px; }
.qty button { border: 0; background: none; width: 32px; height: 32px; font-size: 18px; cursor: pointer; color: var(--ink-2); }
.qty span { min-width: 22px; text-align: center; font-weight: 600; }

.sum { background: var(--canvas); border-radius: var(--radius-m); padding: 12px 14px; margin: 12px 0; }
.sum .l { display: flex; justify-content: space-between; padding: 2px 0; font-size: 14px; }
.sum .l.total { font-weight: 700; font-size: 16px; border-top: 1px dashed var(--line); margin-top: 6px; padding-top: 8px; }

/* ── comments ── */
.comment { background: var(--paper); border-bottom: 1px solid var(--line); padding: 12px 14px; }
.comment .post { display: flex; gap: 10px; font-size: 12.5px; color: var(--ink-3); margin-bottom: 8px; align-items: center; }
.comment .post img { width: 38px; height: 38px; border-radius: 6px; object-fit: cover; flex-shrink: 0; }
.comment .post span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.comment .body { display: flex; gap: 10px; }
.comment .text { background: var(--canvas); border-radius: 4px 16px 16px 16px; padding: 8px 12px; margin-top: 2px; white-space: pre-wrap; }
.comment .reply { margin: 6px 0 0 44px; font-size: 13.5px; color: var(--ink-2); border-left: 3px solid var(--phthalo); padding-left: 10px; }
.comment .reply.bot { border-left-color: var(--cadmium); }
.comment .actions { margin: 10px 0 0 44px; display: flex; gap: 6px; flex-wrap: wrap; }

/* ── orders ── */
.order { background: var(--paper); border-radius: var(--radius-m); box-shadow: var(--shadow); padding: 12px 14px; margin-bottom: 10px; }
.order .head { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.order .head b { flex: 1; }
.order .items { font-size: 13.5px; color: var(--ink-2); margin: 6px 0; }
.order .total { font-weight: 700; font-size: 16px; }
.order .err { color: var(--alizarin); font-size: 13px; margin-top: 4px; }

/* ── report ── */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--paper); border-radius: var(--radius-m); padding: 12px 14px; box-shadow: var(--shadow); }
.stat .n { font-size: 26px; font-weight: 700; line-height: 1.1; }
.stat .k { font-size: 13px; color: var(--ink-3); }
.stat.wide { grid-column: span 2; }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 120px; padding-top: 8px; }
.bars .b { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 3px; min-width: 0; }
.bars .b i { display: block; width: 100%; max-width: 26px; border-radius: 4px 4px 0 0; background: var(--phthalo); min-height: 2px; }
.bars .b i.bot { background: var(--cadmium); }
.bars .b small { font-size: 10.5px; color: var(--ink-3); }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--ink-2); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ── settings list ── */
.list-link { display: flex; align-items: center; gap: 12px; padding: 14px; background: var(--paper); border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.list-link:first-child { border-radius: var(--radius-m) var(--radius-m) 0 0; }
.list-link:last-child { border-radius: 0 0 var(--radius-m) var(--radius-m); border-bottom: 0; }
.list-link .ico { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.list-link .ico svg { width: 20px; height: 20px; }
.list-link .grow small { display: block; color: var(--ink-3); font-size: 12.5px; }
.group { border-radius: var(--radius-m); box-shadow: var(--shadow); margin-bottom: 14px; }
.notice { border-radius: var(--radius-m); padding: 12px 14px; margin-bottom: 12px; font-size: 14px; }
.notice.warn { background: var(--cadmium-tint); }
.notice.err { background: var(--alizarin-tint); color: var(--alizarin); }
.notice.ok { background: var(--phthalo-tint); }
code { background: var(--canvas); padding: 1px 6px; border-radius: 5px; font-size: 13px; word-break: break-all; }

/* ── auth ── */
.auth { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 24px; max-width: 420px; margin: 0 auto; width: 100%; }
.auth .mark { display: flex; gap: 6px; margin-bottom: 18px; }
.auth .mark i { width: 22px; height: 22px; border-radius: 6px; }
.auth h1 { font-size: 30px; line-height: 1.1; margin: 0 0 6px; letter-spacing: -0.02em; }
.auth p { color: var(--ink-2); margin: 0 0 24px; }

.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + 20px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 999px; z-index: 60; font-size: 14px; max-width: 90vw; box-shadow: var(--shadow); animation: up 0.2s; }
.toast.err { background: var(--alizarin); color: #fff; }

/* test chat */
.test-msgs { display: flex; flex-direction: column; gap: 4px; min-height: 240px; }
.tool-trace { font-size: 11.5px; color: var(--ink-3); align-self: flex-end; margin: -2px 6px 6px; }

/* ── wide screens: list + chat side by side ── */
@media (min-width: 900px) {
  body { font-size: 15px; }
  .tabs { position: fixed; top: 0; bottom: 0; left: 0; right: auto; width: 84px; height: auto; grid-template-columns: 1fr; grid-auto-rows: 74px; align-content: start; padding-top: 16px; border-top: 0; border-right: 1px solid var(--line); }
  .tabs a.on::before { top: 20%; bottom: 20%; left: 0; right: auto; width: 3px; height: auto; border-radius: 0 3px 3px 0; }
  #app { padding-left: 84px; }
  .scroll { padding-bottom: 24px; }
  .split { flex: 1; display: grid; grid-template-columns: minmax(320px, 380px) 1fr; min-height: 0; }
  .split > .screen:first-child { border-right: 1px solid var(--line); }
  .wide-hide { display: none !important; }
  .pane-empty { display: flex; align-items: center; justify-content: center; color: var(--ink-3); }
  .scroll.narrow > * { max-width: 760px; margin-left: auto; margin-right: auto; }
  .toast { bottom: 24px; }
  .sheet-back { align-items: center; }
  .sheet { border-radius: var(--radius-l); max-height: 86vh; }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .stat.wide { grid-column: span 4; }
}
@media (max-width: 899px) { .wide-only { display: none !important; } }

/* small inline text buttons under messages (feedback / teach) */
.linkbtn{background:none;border:0;padding:2px 4px;margin-left:6px;font:inherit;font-size:12px;color:var(--phthalo);cursor:pointer;border-radius:6px;min-height:28px}
.linkbtn:hover{background:var(--canvas)}
.msg.in .linkbtn{display:none}
