:root {
  --bg: #0e1117;
  --panel: #141922;
  --panel-2: #1a2030;
  --line: #232b3a;
  --line-2: #2f394b;
  --text: #e8ebf2;
  --text-2: #b4bccc;
  --muted: #7d8799;
  --accent: #2aabee;
  --accent-strong: #1c93d3;
  --accent-soft: rgba(42, 171, 238, .14);
  --ok: #34d399;
  --warn: #f5b942;
  --danger: #f87171;
  --info: #8ab4ff;
  --st-new: #a78bfa;
  --st-open: #2aabee;
  --st-pending: #f5b942;
  --st-resolved: #34d399;
  --st-blocked: #f87171;
  --r: 10px;
  --shadow: 0 14px 40px rgba(0, 0, 0, .45);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif;
  --mono: ui-monospace, Consolas, "Cascadia Mono", Menlo, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f5f9; --panel: #ffffff; --panel-2: #f3f6fa; --line: #e2e6ee; --line-2: #c9d1de;
    --text: #141a26; --text-2: #3d475b; --muted: #6b7688; --accent-soft: rgba(42, 171, 238, .12);
    --shadow: 0 14px 40px rgba(20, 30, 50, .14);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text); font: 14px/1.45 var(--font);
  display: flex; flex-direction: column; overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: 12.5px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 5px; padding: 1px 5px; }
h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 0 10px; }
h3:first-child { margin-top: 0; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 13px; }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0; }
.row { display: flex; gap: 10px; align-items: center; }
.row.end { justify-content: flex-end; }
.row.wrap { flex-wrap: wrap; }
[hidden] { display: none !important; }

/* ---------- buttons & inputs ---------- */
.btn {
  appearance: none; border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text);
  font: inherit; font-weight: 550; padding: 7px 13px; border-radius: 8px; cursor: pointer; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px; line-height: 1.2; transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover { background: var(--line); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: rgba(248, 113, 113, .12); border-color: rgba(248, 113, 113, .4); }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn.iconbtn { padding: 7px 8px; }
.lnkbtn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; font-size: 12.5px; cursor: pointer; }
.lnkbtn:hover { text-decoration: underline; }
.lnkbtn.danger { color: var(--danger); }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 8px 10px;
  outline: none; transition: border-color .12s, box-shadow .12s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; width: 100%; font-family: inherit; }
input.inline { padding: 4px 8px; border-color: transparent; background: transparent; width: 100%; max-width: 320px; }
input.inline:hover { border-color: var(--line-2); }
input.inline:focus { background: var(--panel-2); border-color: var(--accent); }
input.inline.small { max-width: 130px; font-size: 12.5px; }
kbd { font: 11px var(--mono); color: var(--muted); border: 1px solid var(--line-2); border-radius: 4px; padding: 1px 5px; }

/* ---------- top bar ---------- */
.topbar {
  height: 56px; flex: none; display: flex; align-items: center; gap: 8px; padding: 0 16px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 15px; margin-right: 8px; letter-spacing: -.01em; }
.botpill {
  display: inline-flex; align-items: center; gap: 8px; padding: 5px 11px 5px 9px; border-radius: 999px; font: inherit; font-size: 12.5px; font-weight: 550;
  background: var(--panel-2); border: 1px solid var(--line-2); color: var(--text-2); cursor: pointer;
}
.botpill:hover { border-color: var(--accent); }
.botpill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 3px rgba(125, 135, 153, .2); }
.botpill.ok .dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(52, 211, 153, .2); }
.botpill.error .dot { background: var(--danger); box-shadow: 0 0 0 3px rgba(248, 113, 113, .2); }
.botpill.connecting .dot { background: var(--warn); box-shadow: 0 0 0 3px rgba(245, 185, 66, .2); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- layout ---------- */
.layout { flex: 1; display: grid; grid-template-columns: 360px 1fr; min-height: 0; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.content { overflow-y: auto; min-height: 0; }
.pane { padding: 24px 30px 60px; max-width: 1120px; }

/* ---------- sidebar ---------- */
.searchbox { position: relative; padding: 12px 12px 8px; }
.searchbox svg { position: absolute; left: 24px; top: 24px; color: var(--muted); pointer-events: none; }
.searchbox input { width: 100%; padding-left: 34px; padding-right: 34px; }
.searchbox input::-webkit-search-cancel-button { -webkit-appearance: none; }
.searchbox kbd { position: absolute; right: 22px; top: 21px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 12px 8px; }
.chip {
  font: inherit; font-size: 12px; font-weight: 550; color: var(--text-2); background: transparent; border: 1px solid var(--line-2);
  border-radius: 999px; padding: 3px 9px 3px 10px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.chip:hover { border-color: var(--accent); color: var(--text); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.chip .n { font-size: 11px; color: var(--muted); background: var(--panel-2); border-radius: 999px; padding: 0 6px; min-width: 18px; text-align: center; }
.chip.warn .n { color: var(--warn); }
.listmeta { display: flex; align-items: center; justify-content: space-between; padding: 4px 14px 6px; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--line); }
.listmeta select { padding: 3px 6px; font-size: 12px; background: transparent; border-color: transparent; color: var(--muted); }
.listmeta select:hover { border-color: var(--line-2); }
.list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.list .empty { color: var(--muted); padding: 30px 14px; text-align: center; font-size: 13px; }
.item { display: flex; gap: 11px; padding: 9px 10px; border-radius: 9px; cursor: pointer; border: 1px solid transparent; }
.item:hover { background: var(--panel-2); }
.item.sel { background: var(--accent-soft); border-color: rgba(42, 171, 238, .35); }
.item .body { min-width: 0; flex: 1; }
.item .l1, .item .l2 { display: flex; align-items: center; gap: 7px; min-width: 0; }
.item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .time { margin-left: auto; color: var(--muted); font-size: 11.5px; flex: none; }
.item .l2 { color: var(--muted); font-size: 12.5px; margin-top: 1px; flex-wrap: wrap; row-gap: 3px; }
.item .uname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hint-match { color: var(--warn); font-size: 11.5px; font-weight: 550; }
.st { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--muted); }
.st-new { background: var(--st-new); } .st-open { background: var(--st-open); } .st-pending { background: var(--st-pending); } .st-resolved { background: var(--st-resolved); } .st-blocked { background: var(--st-blocked); }
.badge { font-size: 10.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; padding: 1px 6px; border-radius: 5px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line-2); }
.badge.warn { color: var(--warn); border-color: rgba(245, 185, 66, .4); background: rgba(245, 185, 66, .1); }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.tag { font-size: 11.5px; padding: 1px 8px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line-2); color: var(--text-2); display: inline-flex; align-items: center; gap: 4px; }
.tag.former { color: var(--warn); border-color: rgba(245, 185, 66, .35); }
.tag.former small { color: var(--muted); font-size: 10.5px; }
.tag .x { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0 0 0 2px; font-size: 14px; line-height: 1; }
.tag .x:hover { color: var(--danger); }

.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #fff;
  background: hsl(var(--h, 200) 55% 45%);
}
.avatar.lg { width: 56px; height: 56px; font-size: 19px; }

/* ---------- overview ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; }
.stat .v { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.stat .k { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.stat.warn .v { color: var(--warn); }
.stat.accent .v { color: var(--accent); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 18px 20px; margin-bottom: 18px; }
.card.slim { padding: 12px 16px; color: var(--text-2); }
.card h3 { margin-top: 0; }
.card ol { margin: 8px 0; padding-left: 20px; } .card li { margin: 5px 0; }
.section { margin-top: 26px; }
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; align-items: baseline; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.feed .txt { flex: 1; min-width: 0; }
.feed .time { color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.feed .ic { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--muted); position: relative; top: -1px; }
.feed .ic.username_changed, .feed .ic.username_removed { background: var(--warn); }
.feed .ic.discovered, .feed .ic.linked, .feed .ic.username_set { background: var(--ok); }
.feed .ic.added { background: var(--accent); }
.feed .ic.name_changed { background: var(--info); }
.feed.compact li { padding: 6px 0; font-size: 13px; }
.lnk { font-weight: 600; }

/* ---------- detail ---------- */
.back { display: none; margin-bottom: 10px; }
.dhead { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.dtitle { flex: 1; min-width: 220px; }
.dtitle h2 { font-size: 22px; }
.dsub { color: var(--text-2); display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 4px; }
.dsub .sep { color: var(--line-2); }
.copy { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0 3px; font-size: 13px; }
.copy:hover { color: var(--accent); }
.dactions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.status-select { font-weight: 600; padding: 6px 10px; border-width: 1.5px; }
.status-select.st-new { border-color: var(--st-new); color: var(--st-new); background: var(--panel); }
.status-select.st-open { border-color: var(--st-open); color: var(--st-open); background: var(--panel); }
.status-select.st-pending { border-color: var(--st-pending); color: var(--st-pending); background: var(--panel); }
.status-select.st-resolved { border-color: var(--st-resolved); color: var(--st-resolved); background: var(--panel); }
.status-select.st-blocked { border-color: var(--st-blocked); color: var(--st-blocked); background: var(--panel); }
.alert { border-radius: 9px; padding: 10px 14px; margin-top: 14px; border: 1px solid; font-size: 13px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.alert.warn { border-color: rgba(245, 185, 66, .4); background: rgba(245, 185, 66, .08); }
.alert.err { border-color: rgba(248, 113, 113, .4); background: rgba(248, 113, 113, .08); }
.alert.info { border-color: rgba(138, 180, 255, .4); background: rgba(138, 180, 255, .08); }
.cols { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 34px; margin-top: 26px; }
.compose { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 10px; margin-bottom: 14px; }
.compose textarea { border: 0; background: transparent; padding: 4px 6px; margin-bottom: 6px; }
.compose textarea:focus { box-shadow: none; }
.note { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; margin-bottom: 10px; }
.note .ntext { white-space: pre-wrap; word-wrap: break-word; }
.note .nmeta { display: flex; gap: 12px; align-items: center; margin-top: 8px; color: var(--muted); font-size: 12px; }
.note.editing textarea { margin-bottom: 8px; }
.info .kv { display: grid; grid-template-columns: 130px 1fr; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); align-items: center; }
.info .k { color: var(--muted); font-size: 12.5px; }
.info .v { min-width: 0; display: flex; flex-wrap: wrap; gap: 5px; align-items: center; word-break: break-word; }
.tagedit { gap: 5px; }

/* ---------- photos, files, follow-ups ---------- */
.avatar { position: relative; overflow: hidden; }
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 50%; background: var(--panel-2); }
.dropzone { border: 1.5px dashed var(--line-2); border-radius: var(--r); padding: 12px 14px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; background: var(--panel); transition: border-color .12s, background .12s; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.progress { flex: 1 1 100%; height: 6px; background: var(--line); border-radius: 3px; position: relative; margin-bottom: 14px; }
.progress .bar { height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width .15s; }
.progress .ptext { position: absolute; right: 0; top: 9px; font-size: 11px; color: var(--muted); }
.file { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 10px 12px; margin-bottom: 10px; display: grid; gap: 8px; }
.file .fhead { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.file .fname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 55%; }
.file .fmeta { color: var(--muted); font-size: 12px; }
.file audio { width: 100%; height: 36px; }
.file video { max-width: 100%; border-radius: 8px; }
.file img.thumb { max-width: 240px; max-height: 180px; border-radius: 8px; display: block; }
.file input.inline { max-width: 100%; font-size: 13px; }
.fkind { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 2px 6px; border-radius: 5px; background: var(--accent-soft); color: var(--accent); }
.fkind.image { background: rgba(52, 211, 153, .15); color: var(--ok); }
.fkind.file, .fkind.pdf, .fkind.video { background: var(--panel-2); color: var(--muted); }
.followup { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 14px; padding: 10px 14px; border-radius: 9px; border: 1px solid var(--line); background: var(--panel); font-size: 13px; }
.followup.due { border-color: rgba(245, 185, 66, .5); }
.followup.overdue { border-color: rgba(248, 113, 113, .5); }
.followup input[type=datetime-local] { padding: 5px 8px; font-size: 13px; }
.badge.due { color: var(--warn); border-color: rgba(245, 185, 66, .4); background: rgba(245, 185, 66, .1); }
.badge.overdue { color: var(--danger); border-color: rgba(248, 113, 113, .4); background: rgba(248, 113, 113, .1); }
.note.pinned { border-color: rgba(42, 171, 238, .45); }
.note .pin { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); margin-bottom: 4px; }
.feed .ic.file_added, .feed .ic.file_removed { background: var(--accent); }
.feed .ic.followup_set, .feed .ic.followup_due { background: var(--warn); }
.feed .ic.status_changed { background: var(--info); }

/* ---------- dialogs ---------- */
.modal { border: 1px solid var(--line-2); border-radius: 14px; background: var(--panel); color: var(--text); padding: 0; width: min(560px, calc(100vw - 32px)); box-shadow: var(--shadow); }
.modal::backdrop { background: rgba(5, 8, 14, .6); backdrop-filter: blur(2px); }
.modal form { padding: 22px 24px; display: flex; flex-direction: column; gap: 12px; }
.modal h2 { font-size: 18px; margin-bottom: 4px; }
.modal label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--text-2); font-weight: 550; flex: 1; }
.modal label .hint { margin: 0; font-weight: 400; }
.modal label input, .modal label select, .modal label textarea { font-size: 14px; font-weight: 400; color: var(--text); }
.modal label.check { flex-direction: row; align-items: center; gap: 8px; }
.modal label.check input { width: 16px; height: 16px; }
.modal label.inlinelabel { flex-direction: row; align-items: center; gap: 8px; flex-wrap: wrap; }
.modal label.inlinelabel input { width: 80px; }
.modal section { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.modal section h3 { margin: 0; }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.form-error { color: var(--danger); font-size: 13px; margin: 0; }

/* ---------- toasts ---------- */
#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; pointer-events: none; }
.toast { background: var(--panel); border: 1px solid var(--line-2); color: var(--text); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-size: 13px; opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; max-width: 80vw; }
.toast.show { opacity: 1; transform: none; }
.toast.ok { border-color: rgba(52, 211, 153, .5); }
.toast.err { border-color: rgba(248, 113, 113, .5); }

/* ---------- narrow screens ---------- */
@media (max-width: 900px) {
  .cols { grid-template-columns: 1fr; gap: 20px; }
  .pane { padding: 18px 16px 50px; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: flex; }
  .content { display: none; }
  body.has-selection .sidebar { display: none; }
  body.has-selection .content { display: block; }
  .back { display: inline-flex; }
  .topbar { padding: 0 10px; gap: 6px; }
  .brand span { display: none; }
  #btn-bulk, #btn-refresh { display: none; }
}
