:root {
  --bg: #0e1116; --panel: #161b22; --panel2: #1c232d; --line: #2a3340; --text: #e6edf3; --muted: #8b96a5;
  --gold: #f2b84b; --green: #3fb950; --red: #f85149; --blue: #58a6ff; --orange: #db8b2c;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button { background: var(--gold); color: #1a1300; border: 0; border-radius: 8px; padding: 7px 14px; font-weight: 600; cursor: pointer; }
button:hover { filter: brightness(1.08); }
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); font-weight: 500; }
button.danger { background: var(--red); color: #fff; }
button.small { padding: 4px 10px; font-size: 12px; }
input, textarea, select { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
textarea { min-height: 90px; resize: vertical; }
label { display: block; color: var(--muted); font-size: 12px; margin: 10px 0 4px; }
a { color: var(--blue); }
h2 { margin: 4px 0 14px; font-size: 18px; }
h3 { margin: 0 0 10px; font-size: 15px; }
.muted { color: var(--muted); }
.small-text { font-size: 12px; }

.top { display: flex; align-items: center; gap: 18px; padding: 10px 18px; border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
.brand { font-weight: 800; color: var(--gold); font-size: 16px; }
.brand span { color: var(--text); font-weight: 500; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav button { background: transparent; color: var(--muted); font-weight: 500; padding: 7px 12px; }
nav button.on { background: var(--panel2); color: var(--text); }
.right { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.badge { background: var(--red); color: #fff; border-radius: 10px; padding: 0 6px; font-size: 11px; margin-left: 4px; }
.pill { border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 700; }
.pill.dry { background: #2d3a4f; color: var(--blue); }
.pill.live { background: #3b1d1d; color: #ff7b72; }
.banner { background: #3b2a12; color: #ffd28a; padding: 10px 18px; border-bottom: 1px solid var(--line); }
main { padding: 18px; max-width: 1400px; margin: 0 auto; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.card .n { font-size: 26px; font-weight: 800; }
.card .l { color: var(--muted); font-size: 12px; }
.card.warn .n { color: var(--orange); }
.card.good .n { color: var(--green); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
tr.click { cursor: pointer; }
tr.click:hover { background: var(--panel2); }
.st { display: inline-block; border-radius: 6px; padding: 2px 8px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.st-delivered, .st-ok { background: #12301b; color: var(--green); }
.st-trade_sent { background: #10253f; color: var(--blue); }
.st-needs_attention, .st-invalid, .st-error { background: #3b1d1d; color: #ff7b72; }
.st-dry_run { background: #2d3a4f; color: #a5c8ff; }
.st-retry, .st-pending, .st-unchecked { background: #3b2a12; color: #ffc46b; }
.st-handled_manually, .st-dismissed, .st-not_ours, .st-off { background: #222a33; color: var(--muted); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* inbox */
.inbox { display: grid; grid-template-columns: 320px 1fr; gap: 0; height: calc(100vh - 140px); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--panel); }
@media (max-width: 800px) { .inbox { grid-template-columns: 1fr; height: auto; } }
.convs { border-right: 1px solid var(--line); overflow-y: auto; }
.conv { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.conv:hover { background: var(--panel2); }
.conv.on { background: var(--panel2); border-left: 3px solid var(--gold); }
.conv .name { font-weight: 600; display: flex; justify-content: space-between; gap: 6px; }
.conv .prev { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv.unread .name::after { content: "●"; color: var(--gold); }
.thread { display: flex; flex-direction: column; min-height: 0; }
.thread-head { padding: 10px 14px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.msgs { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; min-height: 200px; }
.msg { max-width: 72%; padding: 8px 12px; border-radius: 12px; background: var(--panel2); white-space: pre-wrap; word-wrap: break-word; }
.msg.me { align-self: flex-end; background: #3a2e12; }
.msg.sys { align-self: center; background: transparent; color: var(--muted); font-size: 12px; text-align: center; }
.msg .meta { color: var(--muted); font-size: 11px; margin-bottom: 2px; }
.composer { border-top: 1px solid var(--line); padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.composer textarea { min-height: 60px; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; }
.quick button { font-size: 12px; padding: 3px 9px; }

.log { font: 12px/1.5 ui-monospace, Consolas, monospace; max-height: 70vh; overflow-y: auto; }
.log div { padding: 2px 0; border-bottom: 1px solid #1a2029; }
.log .warn { color: #ffc46b; } .log .error { color: #ff7b72; }

.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth .panel { width: 100%; max-width: 380px; }
.auth h2 { color: var(--gold); }
.qr { background: #fff; border-radius: 8px; padding: 8px; display: block; margin: 8px auto; }
.code { font-family: ui-monospace, Consolas, monospace; word-break: break-all; background: var(--bg); padding: 6px 8px; border-radius: 6px; }
.err { color: #ff7b72; min-height: 18px; margin-top: 8px; }

.toast { position: fixed; bottom: 18px; right: 18px; background: var(--panel2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; z-index: 50; max-width: 420px; }
.toast.bad { border-color: var(--red); }
.modal { position: fixed; inset: 0; background: #000a; display: grid; place-items: center; z-index: 40; padding: 20px; }
.modal .box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; }
.hist { font-size: 12px; color: var(--muted); max-height: 220px; overflow-y: auto; }
.hist div { padding: 3px 0; border-bottom: 1px solid #1a2029; }
.switch { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; margin: 8px 0; }
.switch input { width: auto; }
.help { background: var(--panel2); border-radius: 8px; padding: 10px 12px; font-size: 13px; color: var(--muted); }
.help ol { margin: 6px 0 0 18px; padding: 0; }
.items-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; margin-bottom: 6px; }
