:root {
  --bg: #f6f7f9; --panel: #ffffff; --ink: #1b1f24; --muted: #6a737d; --line: #e3e6ea;
  --accent: #7a1f3d; --accent-ink: #ffffff; --ok: #1a7f37; --warn: #9a6700; --err: #cf222e;
  --chip: #f0f2f5; --mine: #f3e8ec; --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216; --panel: #171b21; --ink: #e6e8eb; --muted: #8b949e; --line: #2a3038;
    --accent: #d06a8c; --accent-ink: #14070c; --chip: #222831; --mine: #3a2230;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
h2 { font-size: 18px; margin: 0; } h3 { font-size: 14px; margin: 16px 0 8px; }
.muted { color: var(--muted); } small { color: var(--muted); display: block; font-weight: normal; }
button, .button { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 6px 12px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { color: var(--err); }
button.link { border: 0; background: none; color: var(--accent); padding: 4px 0; }
button:disabled { opacity: .5; cursor: progress; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; width: 100%; }
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
label { display: grid; gap: 4px; font-weight: 500; }
label.check { display: flex; align-items: center; gap: 6px; font-weight: normal; }
label.check input { width: auto; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; font-size: 16px; } .brand .muted { font-weight: 400; }
.badge { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--chip); color: var(--muted); margin-left: 6px; vertical-align: middle; }
.whoami { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; font-size: 13px; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--chip); }
.chip.on { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.chip.bad { background: color-mix(in srgb, var(--err) 18%, transparent); color: var(--err); }

.layout { display: grid; grid-template-columns: 180px minmax(0, 1fr) 340px; min-height: calc(100vh - 53px); }
.tabs { display: flex; flex-direction: column; gap: 2px; padding: 12px 8px; border-right: 1px solid var(--line); background: var(--panel); }
.tabs button { border: 0; background: none; text-align: left; justify-content: space-between; padding: 8px 12px; }
.tabs button.active { background: var(--chip); font-weight: 600; }
.pill { background: var(--accent); color: var(--accent-ink); border-radius: 99px; font-size: 11px; padding: 0 7px; }
.rt-status { margin-top: auto; padding: 8px 12px; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.on { background: var(--ok); } .dot.err { background: var(--err); }

main { padding: 20px; min-width: 0; }
.view { display: grid; gap: 14px; align-content: start; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 12px; align-content: start; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; } .spacer { flex: 1; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; } .row.end { justify-content: flex-end; } .grow { flex: 1; min-width: 160px; width: auto; }
.auth-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.photo { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: grid; }
.photo img { width: 100%; aspect-ratio: 3/4; object-fit: cover; background: var(--chip); }
.photo .row { padding: 8px; justify-content: space-between; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.match { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: grid; }
.match .head { display: flex; gap: 12px; padding: 12px; align-items: center; }
.avatar { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; background: var(--chip); flex: none; display: grid; place-items: center; color: var(--muted); font-weight: 700; }
.score { margin-left: auto; font-size: 22px; font-weight: 700; color: var(--accent); }
.factors { padding: 0 12px; margin: 0; font-size: 12px; color: var(--muted); }
.match .actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px; border-top: 1px solid var(--line); }
.match .actions button { padding: 4px 9px; font-size: 12.5px; }

.three-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.list { display: grid; gap: 6px; align-content: start; }
.item { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; display: flex; align-items: center; gap: 10px; }
.item .avatar { width: 36px; height: 36px; font-size: 12px; }
.item.unread { border-left: 3px solid var(--accent); }
.item.clickable { cursor: pointer; } .item.selected { outline: 2px solid var(--accent); }
.empty { color: var(--muted); padding: 12px; text-align: center; border: 1px dashed var(--line); border-radius: 8px; }

.chat { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 14px; height: calc(100vh - 100px); }
.chat aside { display: grid; grid-template-rows: auto 1fr; gap: 8px; overflow: auto; }
.thread { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); display: grid; grid-template-rows: auto 1fr auto; min-height: 0; }
.thread-title { padding: 12px 14px; border-bottom: 1px solid var(--line); font-weight: 600; }
.messages { overflow: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 72%; padding: 8px 12px; border-radius: 12px; background: var(--chip); white-space: pre-wrap; word-break: break-word; }
.msg.mine { align-self: flex-end; background: var(--mine); }
.msg time { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.composer { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }

.log { border-left: 1px solid var(--line); background: var(--panel); padding: 12px; display: grid; grid-template-rows: auto 1fr; gap: 8px; height: calc(100vh - 53px); position: sticky; top: 53px; }
#log { overflow: auto; display: grid; gap: 4px; align-content: start; }
.entry summary { cursor: pointer; display: grid; grid-template-columns: 52px 1fr auto; gap: 6px; font: 12px ui-monospace, Menlo, monospace; padding: 4px 6px; border-radius: 6px; list-style: none; }
.entry summary::-webkit-details-marker { display: none; }
.entry summary:hover { background: var(--chip); }
.entry .s2 { color: var(--ok); } .entry .s4 { color: var(--warn); } .entry .s5, .entry .s0 { color: var(--err); }
.entry .path { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
pre.json { margin: 0; font: 12px/1.4 ui-monospace, Menlo, monospace; white-space: pre-wrap; word-break: break-word; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px; max-height: 360px; overflow: auto; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--ink); width: min(640px, 92vw); padding: 16px; }
dialog::backdrop { background: rgb(0 0 0 / .45); }
#toasts { position: fixed; right: 360px; bottom: 16px; display: grid; gap: 8px; z-index: 20; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 20px rgb(0 0 0 / .2); max-width: 340px; font-size: 13px; }
.toast.err { background: var(--err); color: #fff; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .tabs { flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--line); }
  .rt-status { margin-top: 0; margin-left: auto; }
  .log { position: static; height: 360px; border-left: 0; border-top: 1px solid var(--line); }
  .chat { grid-template-columns: 1fr; height: auto; } .messages { max-height: 50vh; }
  #toasts { right: 16px; }
}
