:root {
  --bg: #f7f5f5; --panel: #ffffff; --sunk: #f1eeef; --line: #e6e0e2;
  --fg: #1c191b; --muted: #716a6e; --accent: #e8364a; --accent-fg: #ffffff;
  --me: #fde8ea; --them: #f1eeef; --ok: #1f8a5b;
  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121014; --panel: #18161a; --sunk: #201d22; --line: #2b272d;
    --fg: #f0ecee; --muted: #a0989e; --accent: #ff5d6a; --accent-fg: #1a0b0d;
    --me: #3a1c21; --them: #241f25; --ok: #4cc28a; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.5 var(--font); }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; border-radius: 8px; background: var(--accent); color: var(--accent-fg); padding: 8px 14px; font-weight: 600; }
button.ghost { background: transparent; color: var(--muted); font-weight: 500; }
button.ghost:hover { background: var(--sunk); color: var(--fg); }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input, select, textarea { width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
label { font-size: 12px; color: var(--muted); font-weight: 500; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 15px; }
.error { color: var(--accent); margin: 0; }
.empty { color: var(--muted); padding: 24px; max-width: 44ch; }
.center { display: grid; place-items: center; height: 100%; max-width: none; }

.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(340px, 100%); display: grid; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; }
.login-card img { justify-self: start; }
.login-card h1 { font-size: 22px; margin-bottom: 8px; }

.shell { height: 100%; display: grid; grid-template-columns: 200px 340px minmax(0, 1fr); }
.sidebar { border-right: 1px solid var(--line); padding: 16px 10px; display: flex; flex-direction: column; gap: 16px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; padding: 4px 8px; }
.sidebar nav { display: grid; gap: 2px; flex: 1; align-content: start; }
.nav { background: transparent; color: var(--muted); text-align: left; font-weight: 500; display: flex; justify-content: space-between; }
.nav:hover { background: var(--sunk); color: var(--fg); }
.nav.active { background: var(--sunk); color: var(--fg); }
.count { font: 12px var(--mono); color: var(--accent); }

.pane-head { height: 52px; display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--line); }
.list-pane { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.conversations { list-style: none; margin: 0; padding: 6px; overflow-y: auto; }
.conversations li button { width: 100%; text-align: left; background: transparent; color: var(--fg); font-weight: 400; padding: 10px; display: grid; gap: 2px; border-radius: 10px; }
.conversations li button:hover, .conversations li button.active { background: var(--sunk); }
.row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.time { color: var(--muted); font: 12px var(--mono); flex: none; }
.preview { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font: 11px var(--mono); color: var(--muted); }
.unread .name::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-right: 6px; vertical-align: 2px; }

.thread-pane { min-width: 0; min-height: 0; }
.thread { height: 100%; display: flex; flex-direction: column; }
.thread-head .who { flex: 1; min-width: 0; }
.thread-head p { margin: 0; color: var(--muted); font-size: 12px; }
.back { display: none; }
.thread-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 260px; }
.messages { list-style: none; margin: 0; padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 72%; padding: 8px 12px; border-radius: 14px; background: var(--them); white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.agent { align-self: flex-end; background: var(--me); }
.msg small { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
.details { border-left: 1px solid var(--line); padding: 16px; overflow-y: auto; display: grid; gap: 14px; align-content: start; }
.details dl { margin: 0; display: grid; gap: 6px; }
.details dt { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.details dd { margin: 0; overflow-wrap: anywhere; }
.reply { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); align-items: flex-end; }
.reply textarea { resize: none; }

.apps-pane { grid-column: 2 / 4; overflow-y: auto; }
.apps-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; padding: 20px; align-items: start; }
.apps { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: grid; gap: 8px; }
.apps code, .secret code { font: 12px var(--mono); background: var(--sunk); padding: 2px 6px; border-radius: 6px; overflow-wrap: anywhere; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.edit-form { display: grid; gap: 8px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 4px; }
.actions .spacer { flex: 1; }
button.danger { color: var(--accent); }
.danger-solid { background: var(--accent); justify-self: start; }
button:disabled { opacity: .45; cursor: not-allowed; }
.confirm { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--accent); border-radius: 10px; }
.confirm p { margin: 0; }
.secret { display: grid; gap: 6px; font-size: 13px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { flex-direction: row; align-items: center; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px 12px; }
  .sidebar nav { display: flex; }
  .list-pane, .thread-pane, .apps-pane { grid-row: 2; min-height: 0; }
  .thread-pane { display: none; }
  .shell.reading .list-pane { display: none; }
  .shell.reading .thread-pane { display: block; }
  .back { display: inline-block; }
  .thread-body { grid-template-columns: 1fr; }
  .details { display: none; }
  .apps-pane { grid-column: 1; }
  .apps-grid { grid-template-columns: 1fr; }
}
