/* ── Quiet Signal ─ calm, intelligent, received communication ────────────────
   Ink is the primary voice. Signal-green is spent only on a live event —
   a message received, a channel connected, work done. Green is an event,
   never decoration. Warm paper surfaces, hairline chrome, generous quiet. */
@font-face {
  font-family: "Instrument Serif"; font-style: normal; font-weight: 400;
  src: url("/fonts/InstrumentSerif-Regular.ttf") format("truetype"); font-display: swap;
}
@font-face {
  font-family: "Instrument Serif"; font-style: italic; font-weight: 400;
  src: url("/fonts/InstrumentSerif-Italic.ttf") format("truetype"); font-display: swap;
}
:root {
  --bg: #ece8de;
  --panel: #fbf9f3;
  --panel-2: #f3efe5;
  --panel-3: #e9e4d8;
  --border: #e4dece;
  --border-2: #d9d2c2;
  --text: #16181a;
  --ink: #16181a;
  --text-2: #4c4f4c;
  --muted: #9c978b;
  --accent: #1e2022;        /* ink — primary actions, focus, active */
  --accent-h: #34383a;
  --accent-weak: #ebe7dd;   /* warm neutral tint (active bg / focus ring) */
  --signal: #1f5c4d;        /* green — reserved for received / live events */
  --signal-weak: #e3ede8;
  --ok: #1f5c4d;
  --warn: #a9640a;
  --danger: #b23a34;
  --out-bubble: #e7ede9;    /* faintest green — "ours", sent */
  --in-bubble: #fcfaf5;
  --radius: 7px;
  --radius-lg: 11px;
  --font-serif: "Instrument Serif", Georgia, "Songti SC", serif;
  --shadow: 0 1px 2px rgba(28,24,16,.03), 0 8px 22px rgba(28,24,16,.05);
  --shadow-sm: 0 1px 2px rgba(28,24,16,.05);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Noto Sans", sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h2, h3, h4 { color: var(--text); }

/* ── Buttons ── */
.btn { background: var(--accent); color: #fff; border: none; padding: 7px 14px; border-radius: var(--radius);
  cursor: pointer; font-weight: 500; font-size: 13px; transition: background .15s, box-shadow .15s; }
.btn:hover { background: var(--accent-h); }
.btn:active { transform: translateY(.5px); }
.btn-ghost { background: var(--panel); color: var(--text-2); border: 1px solid var(--border-2); font-weight: 500; }
.btn-ghost:hover { background: var(--panel-2); border-color: #cdd0d6; color: var(--text); }
.btn-sm { padding: 5px 11px; font-size: 12.5px; }
.btn-danger { background: var(--danger); color: #fff; border: none; }
.btn-danger:hover { background: #d93732; }

/* ── Pills / tags / hints ── */
.pill { padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 500; display: inline-flex; align-items: center; gap: 5px; }
.pill::before { content: "●"; font-size: 8px; }
.pill-unknown { background: var(--panel-3); color: var(--text-2); }
.pill-working { background: #e5f6e8; color: #1a7f37; }
.pill-scan { background: #fff2d6; color: #a9640a; }
.pill-off { background: #fde7e6; color: #c9302c; }
.hint { color: var(--muted); font-size: 12.5px; font-weight: 400; }
.logo { font-size: 20px; }

/* ── Language switcher ── */
.lang-bar { position: fixed; top: 12px; right: 16px; z-index: 60; }
.lang-bar select { padding: 5px 26px 5px 10px; border-radius: 999px; border: 1px solid var(--border-2);
  background: var(--panel); color: var(--text-2); font: inherit; font-size: 12.5px; cursor: pointer; box-shadow: var(--shadow-sm);
  appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath d='M2 3.5L5 6.5L8 3.5' stroke='%238f959e' stroke-width='1.4' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center; }

/* ── Shell ── */
.shell { display: grid; grid-template-columns: 88px 1fr; grid-template-rows: auto 1fr; height: 100vh;
  grid-template-areas: "nav bar" "nav main"; }
.sidenav { grid-area: nav; background: var(--panel); border-right: 1px solid var(--border); color: var(--text-2);
  display: flex; flex-direction: column; align-items: stretch; padding: 12px 8px; gap: 2px; min-height: 0; overflow: hidden; }
.nav-brand { text-align: center; font-size: 24px; padding: 2px 0 10px; flex-shrink: 0; }
/* The item list scrolls on its own so a long nav never pushes the footer
   off-screen; the scrollbar is hidden for a clean rail but scroll still works. */
.nav-scroll { flex: 1 1 auto; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px;
  scrollbar-width: none; }
.nav-scroll::-webkit-scrollbar { width: 0; height: 0; }
.nav-item { background: none; border: none; color: var(--text-2); cursor: pointer; padding: 7px 4px; border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 10.5px; font-weight: 500; transition: background .12s, color .12s; flex-shrink: 0; }
.nav-item:hover { color: var(--text); background: var(--panel-2); }
.nav-item.active { color: var(--accent); background: var(--accent-weak); font-weight: 600; }
.ni-ico { font-size: 19px; line-height: 1; }
.nav-div { height: 1px; background: var(--border); margin: 7px 12px; flex-shrink: 0; }
.nav-me { display: flex; flex-direction: column; align-items: center; gap: 6px; border-top: 1px solid var(--border); padding-top: 10px; margin-top: 6px; flex-shrink: 0; }
.nav-whoami { font-size: 10px; color: var(--muted); text-align: center; padding: 0 2px; line-height: 1.25; word-break: break-all; }
.conn { font-size: 9px; } .conn-on { color: var(--ok); } .conn-off { color: var(--danger); }

.admin-bar { grid-area: bar; background: #fff8e6; color: #8a6100; padding: 8px 18px;
  font-size: 13px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid #f2e2b8; z-index: 3; }
.admin-bar input { width: 72px; padding: 5px 9px; border-radius: 6px; border: 1px solid var(--border-2); background: var(--panel); color: var(--text); }

.main { grid-area: main; min-height: 0; overflow: hidden; display: flex; background: var(--bg); }
.view { flex: 1; min-height: 0; min-width: 0; }
.view-inbox { display: grid; grid-template-columns: 320px 1fr 300px; }

/* ── Pages (tables) ── */
.view-page { display: flex; flex-direction: column; overflow: hidden; }
.page-head { display: flex; align-items: center; gap: 14px; padding: 18px 118px 18px 26px; background: var(--panel); border-bottom: 1px solid var(--border); }
.page-head h2 { margin: 0; font-size: 19px; font-weight: 600; }
.page-head input[type=search] { margin-left: auto; padding: 8px 12px; border-radius: var(--radius); border: 1px solid var(--border-2);
  background: var(--panel); color: var(--text); min-width: 240px; font: inherit; }
.page-head input[type=search]:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.section-toggle { margin: 16px 26px 0; }
.table-wrap { overflow: auto; flex: 1; padding: 16px 26px 26px; }
.tbl { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden; }
.tbl th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .02em;
  padding: 11px 14px; border-bottom: 1px solid var(--border); background: var(--panel-2); position: sticky; top: 0; }
.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--text-2); }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover td { background: var(--panel-2); }
.tag { display: inline-block; background: var(--accent-weak); color: var(--accent); padding: 2px 9px; border-radius: 999px;
  font-size: 11px; margin: 1px 4px 1px 0; font-weight: 500; }
.role-badge { font-size: 11px; padding: 2px 9px; border-radius: 6px; background: var(--panel-3); color: var(--text-2); font-weight: 500; }
.placeholder { text-align: center; margin: auto; padding: 60px; color: var(--muted); }
.ph-emoji { font-size: 54px; margin-bottom: 12px; }

/* ── Config sections ── */
.cfg-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; padding: 22px 26px; overflow: auto; align-content: start; }
@media (max-width: 900px) { .cfg-cols { grid-template-columns: 1fr; } }
.cfg-section { border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; background: var(--panel); box-shadow: var(--shadow-sm); }
.cfg-section h4 { margin: 0 0 14px; font-size: 15px; font-weight: 600; }
.cfg-section label { display: block; font-size: 12.5px; font-weight: 500; color: var(--text-2); margin: 12px 0 5px; }
.cfg-section input, .cfg-section select, .cfg-section textarea { width: 100%; padding: 9px 11px; border-radius: var(--radius);
  border: 1px solid var(--border-2); background: var(--panel); color: var(--text); font: inherit; }
.cfg-section input:focus, .cfg-section select:focus, .cfg-section textarea:focus, .crm-input:focus,
.login-card input:focus, .assign-row select:focus, .composer textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.cfg-row { display: flex; align-items: center; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.cfg-status { font-size: 12.5px; color: var(--ok); font-weight: 500; }
.hook-label { margin-top: 14px; }
.hook-box { display: flex; align-items: center; gap: 8px; background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; margin-top: 5px; }
.hook-box code { flex: 1; font-size: 11.5px; word-break: break-all; color: var(--text-2); }
.hook-box .copy { padding: 3px 10px; font-size: 12px; }
.cfg-google { margin: 0 26px 22px; }
.toggle { display: flex; align-items: center; gap: 9px; margin-top: 14px; font-size: 13px; font-weight: 500; cursor: pointer; }
.toggle input, .row-label input, .day-chip input { width: auto; accent-color: var(--accent); }
.drive-list { list-style: none; margin: 14px 0 0; padding: 0; max-height: 50vh; overflow-y: auto; }
.drive-item { display: flex; align-items: center; gap: 10px; padding: 10px 4px; border-bottom: 1px solid var(--border); }
.drive-name { flex: 1; font-size: 13px; word-break: break-all; }
.row-label { display: flex; align-items: center; gap: 9px; font-size: 13px; font-weight: 500; color: var(--text); margin: 10px 0; cursor: pointer; }
.days-row { display: flex; gap: 7px; flex-wrap: wrap; margin: 6px 0 10px; }
.day-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; padding: 6px 10px; border: 1px solid var(--border-2);
  border-radius: 999px; cursor: pointer; background: var(--panel); }
.day-chip:hover { border-color: var(--accent); }
.time-row { display: flex; align-items: center; gap: 9px; margin-top: 8px; font-size: 13px; color: var(--text-2); }
.time-row input { width: auto; padding: 7px 9px; border-radius: var(--radius); border: 1px solid var(--border-2); background: var(--panel); color: var(--text); font: inherit; }
.rule-form { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }
.rule-form input, .rule-form select { width: auto; flex: 1; min-width: 130px; padding: 9px 11px; border-radius: var(--radius);
  border: 1px solid var(--border-2); background: var(--panel); color: var(--text); font: inherit; }

/* ── Dashboard ── */
.dash-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; padding: 22px 26px 4px; }
.dash-card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 18px 20px; box-shadow: var(--shadow-sm); }
.dc-val { font-size: 28px; font-weight: 700; color: var(--text); letter-spacing: -.01em; }
.dc-label { font-size: 12.5px; color: var(--text-2); margin-top: 4px; }
.dc-sub { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.dash-chart { display: flex; align-items: flex-end; gap: 7px; height: 170px; padding-top: 8px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; }
.bars { flex: 1; display: flex; align-items: flex-end; gap: 3px; width: 100%; justify-content: center; }
.bar { width: 42%; min-height: 2px; border-radius: 4px 4px 0 0; }
.bar-in { background: var(--accent); } .bar-out { background: #6db8ff; }
.bar-label { font-size: 9px; color: var(--muted); margin-top: 6px; transform: rotate(-45deg); white-space: nowrap; }
.chart-legend { font-size: 12.5px; color: var(--text-2); margin-top: 22px; display: flex; align-items: center; gap: 6px; }
.chart-legend .lg { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.chart-legend .lg-in { background: var(--accent); } .chart-legend .lg-out { background: #6db8ff; margin-left: 12px; }
.ch-row { display: flex; align-items: center; gap: 10px; margin: 10px 0; font-size: 13px; }
.ch-name { width: 130px; flex-shrink: 0; color: var(--text-2); } .ch-count { width: 40px; text-align: right; font-weight: 600; }
.ch-bar-wrap { flex: 1; background: var(--panel-3); border-radius: 999px; overflow: hidden; height: 12px; }
.ch-bar { height: 100%; background: var(--accent); border-radius: 999px; }
.ai-row { display: flex; justify-content: space-between; font-size: 13px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.ai-row:last-child { border-bottom: none; }
.ai-k { color: var(--muted); } .ai-v { font-weight: 600; }

/* ── Quick-reply picker ── */
.qr-picker { margin: 0 16px; border: 1px solid var(--border-2); border-radius: var(--radius-lg); background: var(--panel);
  box-shadow: var(--shadow); max-height: 240px; overflow-y: auto; }
.qr-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--border); font-size: 13px; }
.qr-item:last-child { border-bottom: none; }
.qr-item:hover { background: var(--accent-weak); }
.qr-sc { font-family: ui-monospace, monospace; font-size: 12px; color: var(--accent); background: var(--accent-weak);
  padding: 2px 7px; border-radius: 5px; flex-shrink: 0; }
.qr-title { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Inbox columns ── */
.col { min-height: 0; display: flex; flex-direction: column; background: var(--panel); }
.col-list { border-right: 1px solid var(--border); }
.col-profile { border-left: 1px solid var(--border); background: var(--panel); }
.list-search { padding: 12px; border-bottom: 1px solid var(--border); }
.list-search input { width: 100%; padding: 9px 12px; border-radius: var(--radius); border: 1px solid var(--border-2); background: var(--panel-2); color: var(--text); font: inherit; }
.list-search input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); background: var(--panel); }
.list-scroll { overflow-y: auto; flex: 1; }
.list-group h3 { margin: 0; padding: 14px 16px 6px; font-size: 11.5px; font-weight: 600; letter-spacing: .03em; color: var(--muted);
  text-transform: uppercase; position: sticky; top: 0; background: var(--panel); z-index: 1; }
.conv-list { list-style: none; margin: 0; padding: 0 6px; }
/* Sheets view: picker + editable grid */
.sheets-bar { display: flex; align-items: center; gap: 10px; padding: 12px 20px; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.sh-picker-wrap { position: relative; min-width: 260px; }
.sh-picker-wrap #shPick { width: 100%; padding: 8px 12px; border-radius: 9px; border: 1px solid var(--border-2); background: var(--panel); color: var(--text); }
.sh-pick-list { position: absolute; top: 40px; left: 0; right: 0; margin: 0; z-index: 30; max-height: 300px; overflow-y: auto; }
.sh-tab { padding: 8px 10px; border-radius: 9px; border: 1px solid var(--border-2); background: var(--panel); color: var(--text); }
.sh-sep { width: 1px; height: 22px; background: var(--border); }
/* Docs view: a plain-text editor for the doc body */
.doc-wrap { flex: 1; padding: 16px clamp(16px, 6vw, 90px); overflow: auto; }
.doc-body { width: 100%; min-height: 60vh; padding: 20px 22px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--panel); color: var(--text); font: inherit; font-size: 14.5px; line-height: 1.7; resize: vertical; }
.doc-body:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
/* Slides view: per-slide text cards + add-a-slide bar */
.sl-addbar { display: flex; gap: 8px; padding: 10px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.sl-addbar input { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border-2); background: var(--panel); color: var(--text); }
.sl-addbar #slAddTitle { min-width: 200px; } .sl-addbar #slAddBody { flex: 1; min-width: 220px; }
.sl-list { flex: 1; overflow: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; }
.sl-card { border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; background: var(--panel); max-width: 760px; }
.sl-num { font-size: 12px; font-weight: 700; color: var(--accent); margin-bottom: 5px; }
.sl-text { white-space: pre-wrap; line-height: 1.6; color: var(--ink); }
/* Calendar view */
.cal-tz-lbl { margin-left: auto; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.page-head #calTz { max-width: 220px; }
.cal-cols { display: grid; grid-template-columns: 300px 1fr; gap: 22px; padding: 20px; overflow: auto; }
.cal-new { display: flex; flex-direction: column; gap: 4px; align-self: start; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.cal-new h4 { margin: 0 0 8px; }
.cal-new label { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.cal-new input, .cal-new textarea { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border-2); background: var(--panel); color: var(--text); font: inherit; }
.cal-meet-ck { display: inline-flex !important; flex-direction: row !important; align-items: center; gap: 6px; margin-top: 10px; color: var(--text); }
.cal-new #calCreate { margin-top: 12px; }
.cal-list { list-style: none; margin: 0; padding: 0; }
.cal-item { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; background: var(--panel); }
.cal-when { flex: none; min-width: 128px; font-variant-numeric: tabular-nums; color: var(--accent); font-weight: 600; font-size: 13px; }
.cal-summary { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-meet { font-size: 12px; font-weight: 600; color: #1f7a44; background: #e7f4ec; padding: 2px 9px; border-radius: 999px; text-decoration: none; }
.cal-open { color: var(--muted); text-decoration: none; font-size: 15px; padding: 0 4px; }
@media (max-width: 720px) { .cal-cols { grid-template-columns: 1fr; } }
.sheets-log { display: flex; align-items: center; gap: 12px; padding: 9px 20px; flex-wrap: wrap; background: var(--panel-2); border-bottom: 1px solid var(--border); font-size: 13px; }
.sh-log-target { font-weight: 600; color: var(--ink); }
.sh-log-ck { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.sh-grid-wrap { flex: 1; overflow: auto; padding: 12px 20px; }
.sh-grid { border-collapse: collapse; }
.sh-grid td { border: 1px solid var(--border); padding: 0; }
.sh-grid .sh-rownum { background: var(--panel-3); color: var(--muted); text-align: center; font-size: 11px; padding: 0 8px; min-width: 34px; user-select: none; }
.sh-cell { border: none; background: transparent; color: var(--text); padding: 6px 9px; min-width: 130px; font: inherit; font-size: 13px; }
.sh-cell:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--panel); }
/* Unread: red dot on the Inbox nav item + count on the conversation row */
.nav-item { position: relative; }
.nav-badge { position: absolute; top: 6px; right: 12px; min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 10.5px; font-weight: 700; line-height: 17px; text-align: center; }
.conv-item.unread .ci-name { font-weight: 700; color: var(--ink); }
.conv-item.unread .ci-last-text { color: var(--ink); font-weight: 500; }
.ci-last-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread-count { flex: none; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }
.list-filters { display: flex; gap: 6px; padding: 0 12px 10px; flex-wrap: wrap; }
.filter-chip { font-size: 12.5px; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--border-2); background: var(--panel); color: var(--muted); cursor: pointer; }
.filter-chip:hover { border-color: var(--accent); color: var(--ink); }
.filter-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.conv-item { display: flex; gap: 11px; padding: 10px 10px; cursor: pointer; border-radius: 10px; align-items: center; margin: 2px 0; }
.conv-item:hover { background: var(--panel-2); }
.conv-item.active { background: var(--accent-weak); }
.ci-avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 600; flex: none; font-size: 15px; }
.ci-avatar.group { background: #7a5cff; } .ci-avatar.channel { background: #b054e0; }
.ci-body { flex: 1; min-width: 0; }
.ci-top { display: flex; justify-content: space-between; gap: 8px; }
.ci-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.ci-time { color: var(--muted); font-size: 11px; flex: none; }
.ci-last { display: flex; align-items: center; gap: 6px; margin-top: 2px; color: var(--muted); font-size: 12.5px; }
.badge { font-size: 10px; padding: 1px 6px; border-radius: 4px; margin-left: 6px; font-weight: 500; }
.badge-waha { background: #e5f6e8; color: #1a7f37; } .badge-ezchat { background: var(--accent-weak); color: var(--accent); }

.col-thread { background: var(--bg); }
.thread-header { padding: 14px 18px; background: var(--panel); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; min-height: 60px; }
.thread-header .th-title { font-weight: 600; font-size: 15px; } .thread-header.empty .th-title { color: var(--muted); font-weight: 400; }
.thread-header .th-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.th-status { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.status-badge { font-size: 11.5px; font-weight: 600; padding: 3px 10px; border-radius: 999px; }
.status-badge.open { color: #1f7a44; background: #e7f4ec; }
.status-badge.closed { color: var(--muted); background: var(--panel-3); }
.conv-item.closed { opacity: .62; }
.conv-item.closed .ci-name { color: var(--muted); }
.badge-closed { background: var(--panel-3); color: var(--muted); }
@media (prefers-color-scheme: dark) { .status-badge.open { color: #7fd39d; background: #17321f; } }
.messages { flex: 1; overflow-y: auto; padding: 18px 18px 8px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 66%; padding: 9px 13px; border-radius: 14px; box-shadow: var(--shadow-sm); word-wrap: break-word; white-space: pre-wrap; font-size: 13.5px; line-height: 1.45; }
.msg.in { align-self: flex-start; background: var(--in-bubble); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.out { align-self: flex-end; background: var(--out-bubble); border-bottom-right-radius: 4px; }
.msg .sender { font-size: 11px; font-weight: 700; color: var(--accent); margin-bottom: 3px; }
.msg .meta { font-size: 10.5px; color: var(--muted); text-align: right; margin-top: 4px; }
.msg .mtype { font-style: italic; color: var(--muted); }
.msg .media { margin: 2px 0 4px; }
.msg .media-img { max-width: 260px; max-height: 320px; border-radius: 10px; display: block; cursor: pointer; }
.msg .media audio { width: 240px; }
.msg .media-file { display: inline-flex; align-items: center; gap: 7px; padding: 8px 12px; margin: 2px 0 4px;
  background: rgba(51,112,255,.08); border-radius: 10px; color: var(--accent); text-decoration: none; font-size: 13px; font-weight: 500; }
.msg .media-file:hover { background: rgba(51,112,255,.14); }
.msg .media-file-ic { font-size: 15px; }
.day-sep { align-self: center; background: var(--panel-3); color: var(--muted); font-size: 11px; padding: 3px 12px; border-radius: 999px; margin: 10px 0; }
.composer { display: flex; gap: 10px; padding: 14px 18px; background: var(--panel); border-top: 1px solid var(--border); }
.composer textarea { flex: 1; resize: none; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--border-2); background: var(--panel-2); color: var(--text); font: inherit; max-height: 120px; }
.composer textarea:focus { background: var(--panel); }
.btn-send { align-self: flex-end; padding: 9px 18px; }

.profile-empty { padding: 20px; text-align: center; margin-top: 40px; color: var(--muted); }
.profile { padding: 22px 20px; overflow-y: auto; }
.avatar { width: 68px; height: 68px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 27px; font-weight: 600; margin: 0 auto 12px; }
.avatar.group { background: #7a5cff; } .avatar.channel { background: #b054e0; }
.p-name { text-align: center; font-weight: 600; font-size: 17px; }
.p-meta { text-align: center; color: var(--muted); font-size: 12px; margin-bottom: 18px; word-break: break-all; white-space: pre-line; }
.p-section { border-top: 1px solid var(--border); padding-top: 16px; margin-top: 16px; }
.p-section > label { display: block; font-weight: 600; font-size: 12.5px; margin-bottom: 9px; color: var(--text); }
.assign-row { display: flex; gap: 7px; }
.assign-row select { flex: 1; padding: 8px; border-radius: var(--radius); border: 1px solid var(--border-2); background: var(--panel); color: var(--text); font: inherit; }
.crm-input { width: 100%; padding: 8px 11px; margin-bottom: 7px; border-radius: var(--radius); border: 1px solid var(--border-2); background: var(--panel); color: var(--text); font: inherit; }
.notes { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.note { background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; font-size: 13px; }
.note .n-meta { color: var(--muted); font-size: 11px; margin-top: 5px; }
.note-form { display: flex; flex-direction: column; gap: 7px; }
.note-form textarea { padding: 9px; border-radius: var(--radius); border: 1px solid var(--border-2); background: var(--panel); color: var(--text); font: inherit; resize: vertical; }
.kb-item .n-body { white-space: pre-wrap; }

/* ── Login ── */
.login-overlay { position: fixed; inset: 0; background: linear-gradient(160deg, #eef2ff 0%, #f4f5f7 60%); display: grid; place-items: center; z-index: 40; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 32px 30px; width: 360px; display: flex; flex-direction: column; gap: 7px; box-shadow: 0 12px 40px rgba(20,30,60,.12); }
.login-brand { font-size: 20px; font-weight: 700; text-align: center; margin-bottom: 16px; }
.login-card label { font-size: 12.5px; font-weight: 500; color: var(--text-2); margin-top: 8px; }
.login-card input { padding: 10px 12px; border-radius: var(--radius); border: 1px solid var(--border-2); background: var(--panel); color: var(--text); font: inherit; }
.login-btn { margin-top: 16px; padding: 11px; font-size: 15px; }
.login-error { background: #fde7e6; color: #c9302c; padding: 9px 11px; border-radius: var(--radius); font-size: 13px; }

/* ── Modals ── */
.modal { position: fixed; inset: 0; background: rgba(20,30,60,.4); display: grid; place-items: center; z-index: 30; backdrop-filter: blur(2px); }
.modal-card { background: var(--panel); border-radius: var(--radius-lg); padding: 26px; width: 380px; max-width: 94vw; max-height: 90vh; overflow-y: auto; position: relative; box-shadow: 0 16px 48px rgba(20,30,60,.2); }
.modal-card h3 { margin: 0 0 14px; font-size: 17px; }
.modal-close { position: absolute; top: 12px; right: 16px; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
.modal-close:hover { color: var(--text); }
.qr-box { margin: 16px auto; width: 240px; height: 240px; display: grid; place-items: center; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); }
.qr-box img { width: 100%; height: 100%; object-fit: contain; }
.dlg-field { margin-bottom: 12px; }
.dlg-field label { display: block; font-size: 12.5px; font-weight: 500; color: var(--text-2); margin-bottom: 5px; }
.dlg-field input, .dlg-field select { width: 100%; padding: 9px 11px; border-radius: var(--radius); border: 1px solid var(--border-2); background: var(--panel); color: var(--text); font: inherit; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 16px; }

/* ── AI companion (智能伙伴) · Lark-style chat ── */
.view-assistant { background: var(--bg); display: grid; grid-template-columns: 260px 1fr; overflow: hidden; }
/* Thread list (Lark-style conversation column) */
.companion-threads { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); background: var(--panel); }
.ct-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 12px; font-size: 13px; font-weight: 700; color: var(--muted); text-transform: none; }
.thread-list { flex: 1; overflow-y: auto; list-style: none; margin: 0; padding: 0 8px 12px; }
.thread-item { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 10px; cursor: pointer; margin-bottom: 2px; }
.thread-item:hover { background: var(--panel-3); }
.thread-item.active { background: var(--accent-weak); }
.thread-item .ti-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; color: var(--ink); }
.thread-item.active .ti-title { color: var(--accent); font-weight: 600; }
.thread-item .ti-del { flex: none; border: none; background: transparent; color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1; padding: 2px 5px; border-radius: 6px; opacity: 0; }
.thread-item:hover .ti-del { opacity: 1; }
.thread-item .ti-del:hover { background: rgba(0,0,0,.08); color: var(--danger); }
.thread-empty { padding: 18px 14px; color: var(--muted); font-size: 12.5px; text-align: center; }
.companion-main { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
/* narrower main column than the old full-width chat → tighter side padding */
.companion-main .chat-thread { padding: 24px clamp(16px, 5vw, 72px); }
.companion-main .chat-composer { padding: 16px clamp(16px, 5vw, 72px) 22px; }
.companion-main .chat-mentions { left: clamp(16px, 5vw, 72px); right: clamp(16px, 5vw, 72px); }
.companion-main .chat-ctx-bar { padding-left: clamp(16px, 5vw, 72px); padding-right: clamp(16px, 5vw, 72px); }
@media (max-width: 720px) { .view-assistant { grid-template-columns: 1fr; } .companion-threads { display: none; } }
.chat-head { align-items: center; gap: 12px; border-bottom: 1px solid var(--border); padding-right: 150px; }
.chat-head-av { flex: none; width: 40px; height: 40px; border-radius: 50%; background: linear-gradient(135deg, #eaf0ff, #f3e9ff);
  display: grid; place-items: center; font-size: 21px; }
.chat-head-info { min-width: 0; }
.chat-head-name { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 600; }
/* Lark-style amber "BOT/AI" pill */
.agent-badge { font-size: 10.5px; font-weight: 700; color: #b8860b; background: rgba(230,168,23,.16); padding: 1px 7px; border-radius: 5px; letter-spacing: .04em; }
.chat-head-sub { margin-top: 1px; }
.chat-thread { flex: 1; overflow-y: auto; padding: 24px clamp(16px, 8vw, 130px); display: flex; flex-direction: column; gap: 18px; }
.chat-msg { display: flex; gap: 11px; max-width: 780px; width: 100%; margin: 0 auto; align-items: flex-start; }
.chat-msg.user { flex-direction: row-reverse; }
.chat-av { flex: none; width: 34px; height: 34px; border-radius: 50%; background: linear-gradient(135deg, #eaf0ff, #f3e9ff);
  display: grid; place-items: center; font-size: 18px; }
.chat-body { line-height: 1.65; word-break: break-word; font-size: 14.5px; }
.chat-msg.ai .chat-body { background: var(--panel); border: 1px solid var(--border); border-radius: 4px 12px 12px 12px;
  padding: 13px 17px; box-shadow: var(--shadow-sm); max-width: 88%; }
.chat-msg.user .chat-body { background: #d6e8ff; color: #14314f; border-radius: 12px 4px 12px 12px; padding: 11px 15px;
  white-space: pre-wrap; max-width: 78%; }
.chat-msg.thinking .chat-body { color: var(--muted); }
.chat-msg.chat-err .chat-body { background: #fde7e6; color: #c9302c; border-color: #f6c9c6; }
/* Markdown inside AI replies */
.chat-body p { margin: 0 0 7px; } .chat-body p:last-child { margin-bottom: 0; }
.chat-body ol, .chat-body ul { margin: 7px 0; padding-left: 22px; }
.chat-body li { margin: 4px 0; }
.chat-body li::marker { color: var(--accent); font-weight: 600; }
.chat-body strong { font-weight: 700; color: var(--ink); }
.md-code { background: var(--panel-3); border-radius: 5px; padding: 1px 6px; font-family: ui-monospace, monospace; font-size: .88em; color: var(--accent); }
.md-sp { height: 6px; }
/* Composer — rounded Lark-style bar with a circular send button */
.chat-composer { display: flex; gap: 10px; padding: 16px clamp(16px, 8vw, 130px) 22px; background: var(--bg); }
.chat-composer textarea { flex: 1; resize: none; padding: 13px 16px; border-radius: 14px; border: 1px solid var(--border-2);
  background: var(--panel); color: var(--text); font: inherit; max-height: 140px; box-shadow: var(--shadow-sm); }
.chat-composer textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.chat-composer .btn-send { align-self: flex-end; height: 46px; border-radius: 13px; padding: 0 20px; }
.chat-composer .btn-mention { align-self: flex-end; height: 46px; width: 46px; border-radius: 13px; padding: 0; font-size: 20px;
  font-weight: 700; color: var(--accent); border: 1px solid var(--border-2); background: var(--panel); }
.chat-composer .btn-mention:hover { border-color: var(--accent); }
/* @-mention conversation picker (floats above the composer) */
.chat-compose-wrap { position: relative; }
.chat-mentions { position: absolute; left: clamp(16px, 8vw, 130px); right: clamp(16px, 8vw, 130px); bottom: 84px;
  margin: 0; z-index: 20; max-height: 260px; overflow-y: auto; }
/* Pinned-conversation context chip */
.chat-ctx-bar { padding: 6px clamp(16px, 8vw, 130px) 0; }
.chat-ctx-chip { display: inline-flex; align-items: center; gap: 7px; padding: 5px 6px 5px 11px; border-radius: 999px;
  background: var(--accent-weak); color: var(--accent); border: 1px solid var(--border-2); font-size: 12.5px; font-weight: 600; }
.chat-ctx-chip .cc-x { border: none; background: transparent; color: inherit; cursor: pointer; font-size: 17px; line-height: 1;
  padding: 0 4px; border-radius: 50%; }
.chat-ctx-chip .cc-x:hover { background: rgba(0,0,0,.08); }
/* Action chips — real side effects the companion performed */
.chat-actions { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 8px; }
.chat-action { display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 999px; font-size: 12.5px;
  font-weight: 600; border: 1px solid var(--border-2); background: var(--panel-3); color: var(--ink); }
.chat-action.send { background: #e7f4ec; color: #1f7a44; border-color: #cbe8d6; }
.chat-action.tag { background: #eef0ff; color: #4a52c4; border-color: #d8dcfb; }
.chat-action .ca-ico { font-size: 13px; }
@media (prefers-color-scheme: dark) {
  .chat-action.send { background: #17321f; color: #7fd39d; border-color: #23482f; }
  .chat-action.tag { background: #1e2140; color: #a3aaf0; border-color: #2c3060; }
}
@media (prefers-color-scheme: dark) { .chat-msg.user .chat-body { background: #24466b; color: #dbe9fb; } .chat-head-av, .chat-av { background: linear-gradient(135deg, #26314d, #2f2a49); } }
:root[data-theme="dark"] .chat-msg.user .chat-body { background: #24466b; color: #dbe9fb; }
:root[data-theme="dark"] .chat-head-av, :root[data-theme="dark"] .chat-av { background: linear-gradient(135deg, #26314d, #2f2a49); }

/* ── AI copilot bar ── */
.ai-bar { display: flex; align-items: center; gap: 8px; padding: 10px 18px; background: var(--panel); border-top: 1px solid var(--border); flex-wrap: wrap; }
.ai-text { white-space: pre-wrap; line-height: 1.6; max-height: 55vh; overflow-y: auto; padding: 4px 2px; }

/* ── Toast ── */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--text); color: #fff;
  padding: 11px 18px; border-radius: 10px; z-index: 50; box-shadow: 0 8px 24px rgba(0,0,0,.2); font-size: 13.5px; }
.toast.err { background: var(--danger); }

/* ═══════════════════ QUIET SIGNAL — expression layer ═══════════════════════ */

/* Editorial serif for display headings — a quiet, confident voice. */
.page-head h2 { font-family: var(--font-serif); font-weight: 400; font-size: 27px; letter-spacing: .01em; }
.cfg-section h4 { font-family: var(--font-serif); font-weight: 400; font-size: 19px; letter-spacing: .01em; }
.login-brand { font-family: var(--font-serif); font-weight: 400; }
.dc-val { font-family: var(--font-serif); font-weight: 400; letter-spacing: 0; }

/* Clinical, tracked labels — the apparatus voice (hints, table heads, group heads). */
.hint, .tbl th, .list-group h3, .cfg-status { letter-spacing: .02em; }

/* GREEN IS AN EVENT — a message received, a line that is live, work done. */
.nav-badge, .unread-count { background: var(--signal); }
.pill-working { background: var(--signal-weak); color: var(--signal); }
.conn-on { color: var(--signal); }
.cfg-status { color: var(--signal); }
.filter-chip.active { background: var(--signal); border-color: var(--signal); }

/* Ink avatars — presence rendered as weight, not color. */
.ci-avatar { background: #26282a; }
.ci-avatar.group { background: #4a5248; }
.ci-avatar.channel { background: #5a4e44; }

/* Softer, warmer chrome: hairline over shadow, calmer radii, lighter weights. */
.btn { font-weight: 500; letter-spacing: .01em; box-shadow: none; }
.nav-item.active { font-weight: 500; }
.conv-item.unread .ci-name { font-weight: 600; }
.pill { font-weight: 500; }

/* The message thread: incoming on paper-white, ours in the faintest green. */
.chat-msg.user .chat-body, .msg.out .msg-body { background: var(--out-bubble); }
