:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --border: #e2e5ea;
  --border-strong: #cfd4dc;
  --text: #1c2027;
  --muted: #646b76;
  --faint: #666d79;
  --accent: #2f6feb;
  --accent-ink: #ffffff;
  --accent-soft: #e8f0ff;
  --ok: #1c7c46;
  --ok-soft: #e3f5ea;
  --warn: #9a6200;
  --warn-soft: #fdf1d8;
  --bad: #b3261e;
  --bad-soft: #fbe6e4;
  --working: #5b4bb7;
  --working-soft: #ece9fb;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(20, 28, 40, 0.06), 0 6px 20px rgba(20, 28, 40, 0.05);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
}

.brand-mark {
  width: 13px;
  height: 13px;
  border-radius: 4px;
  background: linear-gradient(135deg, var(--accent), #6f9dff);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.brand-name {
  font-weight: 650;
  letter-spacing: 0.01em;
  font-size: 15px;
}

.brand-sub {
  color: var(--faint);
  font-size: 12px;
  padding-left: 2px;
}

.user-box {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-box label {
  color: var(--muted);
  font-size: 12.5px;
}

.user-box input {
  width: 118px;
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 13px;
  background: var(--surface-2);
  color: var(--text);
}

.user-box input:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
  background: var(--surface);
}

.user-hint {
  margin: 0;
  padding: 8px 22px 0;
  color: var(--faint);
  font-size: 12px;
}

.who {
  color: var(--muted);
  font-size: 12.5px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.login-card {
  max-width: 420px;
  margin: 48px auto;
}

.login-card h2 {
  margin: 0 0 6px;
  font-size: 16px;
}

.login-card .field {
  margin-top: 12px;
}

.login-card .field input {
  width: 100%;
}

/* ---------- buttons ---------- */

.btn {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 7px 13px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
  white-space: nowrap;
}

.btn:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.btn.primary:hover:not(:disabled) {
  background: #275fcb;
}

.btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.btn.ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn.small {
  padding: 4px 9px;
  font-size: 12px;
}

.btn.danger {
  color: var(--bad);
  border-color: #e8c4c0;
}

.btn.danger:hover:not(:disabled) {
  background: var(--bad-soft);
}

.btn.ok {
  color: var(--ok);
  border-color: #bfe3cd;
}

.btn.ok:hover:not(:disabled) {
  background: var(--ok-soft);
}

/* ---------- banner / messages ---------- */

.banner {
  margin: 14px 22px 0;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

/* A `display` rule above would otherwise defeat the `hidden` attribute and
   leave a 22px empty strip where the banner sits. */
.banner[hidden] {
  display: none;
}

.banner[data-kind="error"] {
  border-color: #e8c4c0;
  background: var(--bad-soft);
  color: #7d1a15;
}

.banner[data-kind="success"] {
  border-color: #bfe3cd;
  background: var(--ok-soft);
  color: #145c33;
}

.banner[data-kind="info"] {
  border-color: #c9d8f5;
  background: var(--accent-soft);
  color: #1d4ea8;
}

.banner button {
  border: none;
  background: transparent;
  cursor: pointer;
  color: inherit;
  font-size: 16px;
  line-height: 1;
  padding: 2px;
}

.msg {
  font-size: 12.5px;
  min-height: 1em;
}

.msg[data-kind="error"] {
  color: var(--bad);
}

.msg[data-kind="success"] {
  color: var(--ok);
}

.msg[data-kind="info"] {
  color: var(--muted);
}

/* ---------- tabs ---------- */

.tabs {
  display: flex;
  gap: 6px;
  padding: 16px 22px 0;
}

.tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
}

.tab:hover {
  background: var(--surface-2);
  color: var(--text);
}

.tab.active {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow);
}

/* ---------- layout ---------- */

.app {
  max-width: 1040px;
  margin: 0 auto;
  padding: 16px 22px 40px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
}

.panel-head .sub {
  color: var(--faint);
  font-size: 12px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 12px;
  color: var(--muted);
}

/* An input with a small action button beside it (e.g. create-a-source). */
.inline-add {
  display: flex;
  gap: 6px;
  align-items: center;
}

.inline-add input {
  flex: 1 1 auto;
  min-width: 0;
}

.field input[type="text"],
.field input[type="number"],
.field input[type="email"],
.field input[type="password"],
.field input[type="file"],
.field select {
  padding: 7px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  background: var(--surface-2);
  color: var(--text);
}

.field input[type="file"] {
  padding: 5px 8px;
}

.field input:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
  background: var(--surface);
}

/* ---------- usage ---------- */

.usage-panel .panel-head {
  align-items: center;
}

.usage-panel .panel-head h2 {
  flex: 0 0 auto;
}

.usage-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}

.usage-month {
  min-width: 96px;
  text-align: center;
  font-weight: 650;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}

.btn.small:disabled {
  opacity: 0.35;
  cursor: default;
}

.usage-cap {
  margin: 14px 0 6px;
  color: var(--faint);
  font-size: 11.5px;
  letter-spacing: 0.02em;
}

.usage-bars {
  display: grid;
  align-items: end;
  gap: 2px;
  height: 46px;
}

.usage-ticks {
  display: grid;
  gap: 2px;
  margin-top: 4px;
  color: var(--faint);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
}

.usage-ticks span:last-child {
  justify-self: end;
}

.usage-bar {
  border-radius: 2px 2px 0 0;
  background: #b9cdf5;
  transition: background 0.12s ease;
}

.usage-bar.empty {
  background: #e5e8ee;
}

.usage-bar:hover {
  background: var(--accent);
}

.usage-types {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 6px 24px;
  font-size: 13px;
}

.usage-types li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--text);
}

.usage-type-num {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 12.5px;
}

.usage-body {
  font-size: 13.5px;
  min-height: 1.4em;
}

.usage-loading,
.usage-empty {
  color: var(--faint);
  font-size: 13px;
}

.usage-error {
  color: var(--bad);
  font-size: 13px;
}

.usage-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px 26px;
  color: var(--muted);
}

.usage-row strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-size: 15px;
}

.usage-warn {
  margin: 10px 0 0;
  border-left: 3px solid #e5b64d;
  background: var(--warn-soft);
  color: var(--warn);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 8px 12px;
  font-size: 12.5px;
}

/* ---------- event list ---------- */

.event-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.event-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.event-row:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
}

.event-row:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.event-main {
  min-width: 0;
}

.event-sender {
  font-weight: 600;
  font-size: 13.5px;
}

.event-meta {
  color: var(--faint);
  font-size: 11.5px;
  font-family: var(--mono);
}

.event-preview {
  color: var(--muted);
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.event-side {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--faint);
  font-size: 12px;
}

.count-pill {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 9px;
  font-size: 11.5px;
  color: var(--muted);
  background: var(--surface-2);
}

/* ---------- badges ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 11.5px;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.8;
}

.badge.pending {
  color: var(--muted);
  background: var(--surface-2);
  border-color: var(--border);
}

.badge.working {
  color: var(--working);
  background: var(--working-soft);
  border-color: #d8d2f2;
}

.badge.done {
  color: var(--ok);
  background: var(--ok-soft);
  border-color: #bfe3cd;
}

.badge.failed {
  color: var(--bad);
  background: var(--bad-soft);
  border-color: #e8c4c0;
}

.badge.active {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: #c9d8f5;
}

.badge.building {
  color: var(--working);
  background: var(--working-soft);
  border-color: #d8d2f2;
}

.badge.ready {
  color: var(--ok);
  background: var(--ok-soft);
  border-color: #bfe3cd;
}

/* ---------- detail ---------- */

.back-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.detail-grid {
  display: grid;
  gap: 14px;
}

.message-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13.5px;
}

.kv {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 4px 12px;
  font-size: 13px;
}

.kv dt {
  color: var(--faint);
}

.kv dd {
  margin: 0;
}

.hint {
  border-left: 3px solid var(--border-strong);
  padding: 8px 12px;
  background: var(--surface-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--muted);
  font-size: 12.5px;
}

.hint.warn {
  border-left-color: #e5b64d;
  background: var(--warn-soft);
  color: var(--warn);
}

.hint.bad {
  border-left-color: #d9857f;
  background: var(--bad-soft);
  color: #7d1a15;
}

.hint.ok {
  border-left-color: #7fc99b;
  background: var(--ok-soft);
  color: var(--ok);
}

.action-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.request-id {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--faint);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 8px;
  word-break: break-all;
}

/* ---------- candidates ---------- */

.candidates {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.candidate {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  background: var(--surface);
}

.candidate-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  color: var(--faint);
  font-size: 11.5px;
  font-family: var(--mono);
}

.candidate-body {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13.5px;
  margin-bottom: 10px;
}

.candidate textarea {
  width: 100%;
  min-height: 74px;
  resize: vertical;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface-2);
  margin-bottom: 9px;
}

.candidate textarea:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
  background: var(--surface);
}

.candidate-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.candidate-feedback {
  font-size: 12px;
  color: var(--ok);
  font-weight: 600;
}

.candidate-feedback[data-kind="error"] {
  color: var(--bad);
}

/* ---------- persona ---------- */

.version-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.version {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 15px;
  background: var(--surface);
}

.version-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

/* A memory proposal's body: user-facing text that may wrap over several lines. */
.memory-text {
  font-size: 13.5px;
  line-height: 1.65;
  color: var(--text);
  white-space: pre-wrap;
  margin-bottom: 8px;
}

.version-title {
  font-weight: 650;
  font-size: 14px;
}

.version-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-top: 6px;
  color: var(--faint);
  font-size: 12px;
}

/* A tidy candidate that argues with an approved memory. Advisory only: the
   reviewer decides, and the old row has not been touched. */
.version-meta .warn {
  color: var(--warn);
  font-weight: 600;
}

.version-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.version-detail {
  margin-top: 12px;
  border-top: 1px dashed var(--border);
  padding-top: 12px;
}

.claim-group {
  margin-bottom: 10px;
}

.claim-group h4 {
  margin: 0 0 5px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.claim-group ul {
  margin: 0;
  padding-left: 18px;
}

.claim-group li {
  margin: 2px 0;
  font-size: 13px;
}

.conflict-list {
  margin: 6px 0 0;
  padding-left: 18px;
  font-size: 12.5px;
  color: var(--warn);
}

.empty {
  color: var(--faint);
  font-size: 13px;
  padding: 14px 4px;
  text-align: center;
}

.foot {
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 22px 28px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--faint);
  font-size: 11.5px;
}

.foot #api-base {
  font-family: var(--mono);
}

.spin {
  display: inline-block;
  width: 11px;
  height: 11px;
  border: 2px solid var(--working-soft);
  border-top-color: var(--working);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: -1px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 680px) {
  .topbar {
    padding: 12px 14px;
  }
  .user-hint,
  .tabs {
    padding-left: 14px;
    padding-right: 14px;
  }
  .app {
    padding: 14px 14px 32px;
  }
  .event-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .event-side {
    justify-content: flex-start;
  }
}

/* ---------- chat ---------- */

/* The console is a document; a chat is an application. This view fills the
   viewport instead of scrolling the page, so the list and the thread each get
   their own scroll and the composer stays put while the thread runs past it.
   ``--chrome`` is everything above the chat box (topbar, hint, tabs) plus the
   page's bottom padding; 100dvh tracks a mobile browser's toolbar instead of
   overflowing behind it the way 100vh does. */
.chat {
  --chrome: 218px;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 0;
  height: calc(100dvh - var(--chrome));
  min-height: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

/* ---------- conversation list ---------- */

.chat-list {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
  background: var(--surface-2);
}

.chat-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 10px;
}

.chat-list-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
}

.chat-search {
  padding: 0 12px 10px;
}

.chat-search input {
  width: 100%;
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-family: inherit;
  font-size: 13px;
  color: var(--text);
}

.chat-search input:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.chat-list-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 8px 10px;
}

/* A conversation row is a full-bleed list item, not a floating card: the
   selected one is marked by an accent bar down its left edge, the way a
   mailbox or a support inbox marks it. Cards made the list read as a stack of
   unrelated objects rather than one scrollable list. */
.conv {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 11px 12px 11px 13px;
  margin: 0;
  border: 0;
  border-left: 3px solid transparent;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  color: inherit;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.12s ease;
}

.conv:hover {
  background: var(--surface-2);
}

.conv.active {
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

.conv-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.conv-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.conv-top strong {
  font-size: 13.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv-time {
  flex: none;
  color: var(--faint);
  font-size: 11px;
}

.conv-preview {
  color: var(--muted);
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  color: var(--faint);
  font-size: 11px;
}

.conv-group {
  display: inline-block;
  margin-left: 3px;
  padding: 0 4px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-weight: 600;
  vertical-align: 1px;
}

/* ---------- message flow ---------- */

.chat-thread {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-thread-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex: none;
}

.chat-thread-id {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.chat-thread-placeholder {
  color: var(--faint);
  font-size: 13.5px;
}

.chat-thread-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.chat-thread-meta strong {
  font-size: 14.5px;
  font-weight: 650;
}

.chat-thread-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--faint);
  font-size: 11.5px;
}

.chat-thread-sub .mono {
  font-family: var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-thread-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: none;
}

.chat-thread-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 18px 20px;
  background: var(--bg);
  background-image: radial-gradient(
    circle at 1px 1px,
    rgba(28, 32, 39, 0.045) 1px,
    transparent 0
  );
  background-size: 18px 18px;
  display: flex;
  flex-direction: column;
}

/* A short conversation rests just above the composer instead of floating at
   the top of a tall empty pane; margin-top:auto does that without breaking
   scroll for a long one. */
.thread-stack {
  margin-top: auto;
  display: flex;
  flex-direction: column;
}

/* ---------- avatars ---------- */

/* A tinted disc with initials: the colour is derived from the name so a person
   keeps the same one, and nothing extra has to be stored or fetched. */
.avatar {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: hsl(var(--hue, 210) 62% 92%);
  color: hsl(var(--hue, 210) 55% 34%);
  font-size: 12.5px;
  font-weight: 650;
  letter-spacing: 0.01em;
  user-select: none;
}

.avatar.lg {
  width: 40px;
  height: 40px;
  font-size: 14px;
}

/* The platform pill sits beside the name: a thread is a Telegram or a
   WhatsApp thread, and that should be legible before reading a label. */
.conv .avatar {
  position: relative;
}

.platform-pill {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.5;
}

.platform-pill.tg {
  background: #e3f0ff;
  color: #1160a8;
}

.platform-pill.wa {
  background: #e2f6e9;
  color: #1c7c46;
}

.platform-pill.fb {
  background: #e7ecff;
  color: #3b41b8;
}

.platform-pill.file {
  background: var(--surface-2);
  color: var(--muted);
}

.platform-pill.group {
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------- day separator ---------- */

.day-sep {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 14px 0 12px;
}

.day-sep span {
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(28, 32, 39, 0.06);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 500;
}

/* ---------- a message ---------- */

/* A message row spans the pane; the bubble inside it caps at a readable
   width. Letting the row itself be the capped element pushed a full-width
   block to the left edge and made every private message hug the border. */
.msg {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-top: 2px;
}

/* Our own messages sit on the right, mirroring the left-hand side: same
   avatar column, name above, bubble tinted with the accent. The side is the
   strongest signal in a conversation and is what the eye looks for first. */
.msg.mine {
  flex-direction: row-reverse;
}

.msg.mine .msg-body {
  align-items: flex-end;
}

.msg.mine .msg-name,
.msg.mine .msg-meta {
  justify-content: flex-end;
}

.msg.mine .msg-meta {
  padding-right: 2px;
}

.msg.mine .bubble {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* A reply that never went out must not look like one that did: the accent
   fill says "sent", so a failure swaps it for an outline in the error colour
   and keeps the text readable. */
.msg.mine.failed .bubble {
  background: var(--bad-soft);
  border-color: var(--bad);
  color: var(--bad);
}

/*: An avatar sits beside the bubble's top, not its bottom: a multi-line
   message otherwise drags its own face out of line with the name above it. */
.msg .avatar {
  margin-top: 2px;
}

.msg.starts {
  margin-top: 10px;
}

.msg-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: min(76%, 560px);
}

.msg-name {
  margin-bottom: 3px;
  padding-left: 2px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
}

.bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 9px 13px;
  font-size: 13.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 1px 1px rgba(20, 28, 40, 0.04);
}

/* Consecutive messages from one speaker share one rounded shape — the tail
   corners square off in the middle of a run, so a burst reads as one block.
   On our own side the squared corners are the right-hand ones, mirroring
   the bubble. */
.msg:not(.starts) .bubble {
  border-top-left-radius: 5px;
}

.msg:not(.ends) .bubble {
  border-bottom-left-radius: 5px;
}

.msg.mine:not(.starts) .bubble {
  border-top-left-radius: 14px;
  border-top-right-radius: 5px;
}

.msg.mine:not(.ends) .bubble {
  border-bottom-left-radius: 14px;
  border-bottom-right-radius: 5px;
}

.msg-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  min-height: 18px;
  margin-top: 3px;
  padding-left: 2px;
  color: var(--faint);
  font-size: 11px;
}

.msg-time {
  font-variant-numeric: tabular-nums;
}

/* Actions stay out of the way until the reader is on the message; a wall of
   buttons under every line is what made the old view hard to scan. */
.msg-actions {
  display: inline-flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.msg:hover .msg-actions,
.msg:focus-within .msg-actions {
  opacity: 1;
}

.msg-action {
  padding: 1px 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
}

.msg-action:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.msg-action.danger:hover {
  border-color: var(--bad);
  color: var(--bad);
}

.msg-status {
  padding: 0 5px;
  border-radius: 4px;
  font-size: 10.5px;
}

.msg-status.analyzing,
.msg-status.received {
  background: var(--working-soft);
  color: var(--working);
}

.msg-status.analysis_failed {
  background: var(--bad-soft);
  color: var(--bad);
}

.replies {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.reply {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 8px 10px;
}

.reply-text {
  flex: 1;
  font-size: 13px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------- empty states ---------- */

.chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 100%;
  min-height: 220px;
  color: var(--faint);
  text-align: center;
}

.chat-empty.small {
  min-height: 160px;
  padding: 24px 12px;
}

.chat-empty-art {
  font-size: 30px;
  opacity: 0.55;
}

.chat-empty p {
  margin: 0;
  font-size: 13.5px;
  color: var(--muted);
}

.chat-empty span {
  font-size: 11.5px;
}

/* ---------- composer ---------- */

.composer {
  flex: none;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 10px 14px 12px;
}

.composer[hidden] {
  display: none;
}

.composer-attach {
  padding-bottom: 8px;
}

.composer-attach[hidden] {
  display: none;
}

.composer-attach select {
  width: 100%;
  max-width: 320px;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-family: inherit;
  font-size: 12.5px;
  color: var(--text);
}

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.composer textarea {
  flex: 1;
  resize: none;
  min-height: 38px;
  max-height: 160px;
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  padding: 8px 14px;
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.5;
  background: var(--surface-2);
  color: var(--text);
  overflow-y: auto;
}

.composer textarea:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
  background: var(--surface);
}

.composer .btn.send {
  flex: none;
  border-radius: 999px;
  padding: 8px 20px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* While recording: a filled red button and a hint beside the box. The dot
   pulses so a recording that has been left running is visible at a glance. */
.icon-btn.recording {
  border-color: var(--bad);
  background: var(--bad);
  color: #fff;
}

.recording-hint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  padding: 0 10px;
  color: var(--bad);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.recording-hint[hidden] {
  display: none;
}

.recording-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--bad);
  animation: rec-pulse 1.2s ease-in-out infinite;
}

@keyframes rec-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.25; }
}

/* A pulse is motion, and motion is not free for everyone: the dot still
   reads as "recording" from its colour and the timer beside it. */
@media (prefers-reduced-motion: reduce) {
  .recording-dot {
    animation: none;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 860px) {
  /* One column: the list on top, the thread below. The list gets a fixed
     ceiling so a busy inbox cannot push the conversation out of reach, and
     the thread keeps enough height for the composer to stay on screen. */
  .chat {
    --chrome: 200px;
    grid-template-columns: minmax(0, 1fr);
    min-height: 460px;
  }
  .chat-list {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    flex: none;
    /* A horizontal strip of conversations, not half the screen: on a phone a
       vertical list would leave almost nothing for the thread. */
    max-height: 132px;
  }
  .chat-list-head,
  .chat-search {
    display: none;
  }
  .chat-list-body {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0 10px 10px;
  }
  .conv {
    flex: none;
    width: 232px;
    margin-bottom: 0;
  }
  .chat-thread {
    min-height: 0;
    flex: 1;
  }
  .msg-body {
    max-width: 88%;
  }
}

/* The original media of a message. Capped so a tall photo does not push the
   conversation off screen; clicking opens it full size. */
.event-media {
  display: block;
  margin-top: 8px;
  max-width: 100%;
  max-height: 360px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.event-media.small {
  max-height: 220px;
}

audio.event-media {
  width: 100%;
}

/* Library of images the assistant may send. A grid so the operator can see
   what is in it at a glance — checking the picture is faster than reading the
   description. */
.asset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}

.asset-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: var(--panel);
}

.asset-thumb {
  display: block;
  width: 100%;
  height: 130px;
  object-fit: cover;
  background: var(--bg);
}

.asset-desc {
  padding: 8px 10px 0;
  font-size: 13px;
  line-height: 1.4;
}

.asset-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 10px 10px;
}
