:root {
  --bg: #0b0e14;
  --panel: #0f131c;
  --line: #1c2430;
  --fg: #c3ceda;
  --dim: #6b7a8d;
  /* sampled from the logo's leaf gradient */
  --accent: #4db6ba;
  --accent-2: #6fbc78;
  --accent-3: #297c9e;
  --ink: #1d1d1b;
  --ok: #3fb950;
  --warn: #d6a13a;
  --error: #f85149;
  --info: #58a6ff;
  --mono: ui-monospace, "Cascadia Mono", "JetBrains Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 13px/1.5 var(--mono);
  overflow: hidden;
}
button, input, select { font: inherit; color: inherit; }

/* Author rules like `.gate { display: grid }` outrank the UA stylesheet's
   [hidden] rule, so hiding via el.foo.hidden needs this to actually work. */
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- brand */
/* The mark is near-black ink on a transparent ground, so it needs a light
   disc to read against the dark UI. */
.logo {
  display: block;
  width: 22px;
  height: 22px;
  flex: none;
  border-radius: 50%;
  background: #f2f4f2;
  padding: 2px;
}
.logo-lg {
  width: 56px;
  height: 56px;
  padding: 4px;
  align-self: center;
  margin-bottom: 4px;
  box-shadow: 0 0 0 1px var(--line), 0 6px 22px -8px var(--accent);
}

/* ---------------------------------------------------------------- gate */
.gate { display: grid; place-items: center; height: 100vh; }
.gate-box {
  width: min(360px, 90vw);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 28px;
  display: flex; flex-direction: column; gap: 12px;
}
.gate-box h1 {
  margin: 0;
  font-size: 16px;
  letter-spacing: .18em;
  text-align: center;
  background: linear-gradient(90deg, var(--accent-3), var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.gate-box p { margin: 0; color: var(--dim); font-size: 12px; }
.gate-box input, .gate-box button {
  background: #0a0d13; border: 1px solid var(--line); border-radius: 6px; padding: 9px 11px;
}
.gate-box button { background: var(--accent); color: #05262b; border: 0; cursor: pointer; font-weight: 600; }
.gate-error { color: var(--error); font-size: 12px; }

/* ---------------------------------------------------------------- shell */
.app { display: grid; grid-template-columns: 232px 1fr; height: 100vh; }

.side {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  overflow-y: auto;
}
.side-head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.brand {
  flex: 1;
  min-width: 0;
  color: var(--fg);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: .04em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* the dot carries the connection state; this only speaks up when it is bad */
.conn-label { font-size: 10px; letter-spacing: .08em; text-transform: uppercase; color: var(--warn); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); flex: none; }
.dot.live { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.down { background: var(--error); }

.side-section { padding: 12px 10px; border-bottom: 1px solid var(--line); }
.side-title {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 4px 8px; color: var(--dim); font-size: 11px; letter-spacing: .1em; text-transform: uppercase;
}
.mini {
  background: none; border: 1px solid var(--line); border-radius: 4px;
  color: var(--dim); cursor: pointer; font-size: 10px; padding: 1px 6px;
}

/* --------------------------------------------------- channels dropdown */
.chan-wrap { position: relative; margin-left: auto; flex: none; }
.chan-btn.on { color: var(--accent); border-color: var(--accent); }
.caret { font-size: 10px; opacity: .8; }

.chan-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: min(330px, 90vw);
  max-height: 65vh;
  overflow-y: auto;
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 40px -12px #000;
  z-index: 40;
}
.chan-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 2px 4px 8px; color: var(--dim);
  font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
}
.chan-dots {
  flex: none; width: 20px; padding: 0; line-height: 1;
  background: none; border: 0; border-radius: 4px;
  color: var(--dim); cursor: pointer; font-size: 15px;
}
.chan-dots:hover { background: #1c2430; color: var(--accent); }

.chan-menu {
  display: flex; flex-direction: column; gap: 1px;
  margin: 2px 0 6px 12px; padding: 5px;
  background: #0a0d13; border: 1px solid var(--line); border-radius: 6px;
}
.chan-id {
  background: none; border: 0; text-align: left;
  padding: 3px 6px; color: var(--accent);
  cursor: pointer; word-break: break-all; font-size: 11px;
}
.chan-id:hover { background: #12202a; }
.chan-id.copied { background: var(--ok); color: #04240f; border-radius: 3px; }
.chan-item {
  background: none; border: 0; text-align: left;
  padding: 5px 6px; border-radius: 4px; color: var(--fg); cursor: pointer;
}
.chan-item:hover { background: #151b26; color: var(--accent); }
.chan-item.danger { color: var(--error); }
.chan-item.danger:hover { background: #2a1416; color: var(--error); }
.chan-rename {
  flex: 1; min-width: 0;
  background: #0a0d13; border: 1px solid var(--accent);
  border-radius: 4px; padding: 2px 6px; font: inherit; color: var(--fg);
}
.chan-rename:focus { outline: none; }

.channels { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1px; }
.channels li {
  display: flex; align-items: center; gap: 7px;
  padding: 5px 6px; border-radius: 5px; cursor: pointer; user-select: none;
}
.channels li:hover { background: #151b26; }
.channels li.off { opacity: .35; }
.channels .swatch { width: 3px; height: 14px; border-radius: 2px; flex: none; }
.channels .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channels .n { color: var(--dim); font-size: 11px; }
.channels .snd {
  flex: none;
  background: #0a0d13;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--dim);
  font-size: 10px;
  padding: 1px 2px;
  max-width: 62px;
  cursor: pointer;
}
.channels .snd:hover { color: var(--accent); border-color: var(--accent); }

.vol-row { display: flex; align-items: center; gap: 8px; padding: 4px; color: var(--dim); font-size: 12px; }
.vol { flex: 1; accent-color: var(--accent); min-width: 0; }

.levels { display: flex; flex-direction: column; gap: 5px; padding: 0 4px; }
.levels label, .toggle { display: flex; align-items: center; gap: 7px; cursor: pointer; font-size: 12px; }
.toggle { padding: 3px 4px; color: var(--dim); }
.lv { width: 8px; height: 8px; border-radius: 2px; }
.lv.ok { background: var(--ok); }
.lv.warn { background: var(--warn); }
.lv.error { background: var(--error); }
.lv.info { background: var(--info); }

.side-foot { margin-top: auto; padding: 10px 14px; color: var(--dim); font-size: 11px; }

/* ---------------------------------------------------------------- main */
/* min-height:0 on both is load-bearing: grid items default to min-height:auto,
   which makes .log grow to fit its rows instead of scrolling them. */
.main { display: grid; grid-template-rows: auto 1fr auto; min-width: 0; min-height: 0; position: relative; }

.bar {
  display: flex; gap: 8px; padding: 9px 12px; flex-wrap: wrap; align-items: center;
  border-bottom: 1px solid var(--line); background: var(--panel);
}

.ranges { display: flex; gap: 2px; flex: none; border: 1px solid var(--line); border-radius: 6px; padding: 2px; }
.chip {
  background: none;
  border: 0;
  border-radius: 4px;
  padding: 4px 9px;
  color: var(--dim);
  cursor: pointer;
}
.chip:hover { color: var(--fg); background: #141a24; }
.chip.on { background: var(--accent); color: #05262b; font-weight: 600; }
.search {
  flex: 1; background: #0a0d13; border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 10px; min-width: 0;
}
.search:focus, .cmd-input:focus { outline: 1px solid var(--accent); }
.btn {
  background: #141a24; border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 12px; cursor: pointer; color: var(--dim);
}
.btn:hover { color: var(--fg); }
.btn.on { background: var(--warn); color: #221a05; border-color: transparent; }
.btn.send { background: var(--accent); color: #05262b; border: 0; font-weight: 600; }

.log { overflow-y: auto; overflow-x: auto; min-height: 0; padding: 8px 0 14px; scrollbar-gutter: stable; }
.row { display: flex; gap: 10px; padding: 1px 14px; border-left: 2px solid transparent; }

/* Multi-line bot cards are clamped to a few lines; click a row to expand it. */
body.compact .row { cursor: pointer; }
body.compact .row + .row { border-top: 1px solid #141a24; }
body.compact .row .m {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
body.compact .row.open .m { display: block; }
.row:hover { background: #10151e; }
.row.error { border-left-color: var(--error); }
.row.warn { border-left-color: var(--warn); }
.row.ok { border-left-color: var(--ok); }
.row .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.row .t { color: #46546a; flex: none; }

/* check + note controls */
.chk, .note-btn {
  flex: none;
  width: 18px;
  height: 18px;
  padding: 0;
  line-height: 1;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
  color: #33405200;        /* invisible until hover, so the log stays quiet */
  cursor: pointer;
}
.row:hover .chk, .row:hover .note-btn { color: var(--dim); }
.chk.on { background: var(--ok); border-color: transparent; color: #04240f !important; }
.note-btn.on { border-color: var(--accent); color: var(--accent) !important; }
.chk:hover { border-color: var(--ok); }
.note-btn:hover { border-color: var(--accent); }

.row.checked { opacity: .45; }
.row.checked:hover { opacity: .8; }

.note {
  border-left: 2px solid var(--accent);
  background: #0c161a;
  border-radius: 0 4px 4px 0;
  padding: 3px 8px;
  color: var(--accent);
  white-space: pre-wrap;
  word-break: break-word;
}
.note-edit {
  width: 100%;
  resize: vertical;
  background: #0a0d13;
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 5px 8px;
  font: inherit;
  color: var(--fg);
}
.note-edit:focus { outline: none; }
/* the note stays readable even when the card above it is clamped */
body.compact .row .note, body.compact .row .note-edit { display: block; }
.row .c { flex: none; width: 15ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .m { white-space: pre-wrap; word-break: break-word; min-width: 0; }
body.nowrap .row .m { white-space: pre; }
.row.error .m { color: #ff9c96; }
.row.warn .m { color: #e8c07a; }
.row.ok .m { color: #8fe0a0; }
.row .tag { color: var(--accent); }
.row a { color: var(--info); text-decoration: underline; text-underline-offset: 2px; }
.row a:hover { color: var(--accent); }
.row .code {
  color: var(--accent);
  border-bottom: 1px dotted currentColor;
  cursor: pointer;
  word-break: break-all;
}
.row .code:hover { background: #12202a; }
.row .code.copied { background: var(--ok); color: #04240f; border-bottom-color: transparent; }
.row mark { background: #3b3a1c; color: #ffe08a; border-radius: 2px; }
.row mark.watch { background: var(--accent-2); color: #04240f; font-weight: 600; }

/* ------------------------------------------------------------- watchlist */
.row.watch {
  border-left-color: var(--accent-2);
  background: linear-gradient(90deg, rgba(111, 188, 120, .13), rgba(111, 188, 120, 0) 45%);
  box-shadow: inset 4px 0 0 0 var(--accent-2);
}
.row.watch:hover { background: linear-gradient(90deg, rgba(111, 188, 120, .2), rgba(111, 188, 120, 0) 45%); }
.watch-badge {
  background: var(--accent-2);
  color: #04240f;
  border-radius: 3px;
  padding: 0 5px;
  margin-right: 6px;
  font-weight: 700;
}

.watch {
  width: 100%;
  resize: vertical;
  background: #0a0d13;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
  color: var(--fg);
}
.watch:focus { outline: 1px solid var(--accent-2); border-color: var(--accent-2); }
.watch::placeholder { color: #3d4b5e; }
.watch-count { color: var(--accent-2); font-size: 11px; padding: 4px 4px 0; }
.sys { color: var(--dim); font-style: italic; padding: 2px 14px; }

.jump {
  position: absolute; bottom: 62px; left: 50%; transform: translateX(-50%);
  background: var(--accent); color: #05262b; border: 0; border-radius: 20px;
  padding: 6px 16px; cursor: pointer; font-weight: 600; z-index: 5;
}

.cmd {
  display: flex; gap: 8px; align-items: center; padding: 9px 12px;
  border-top: 1px solid var(--line); background: var(--panel);
}
.cmd-target {
  background: #0a0d13; border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 8px; max-width: 190px;
}
.prompt { color: var(--accent); }

/* focused on one channel: the feed is filtered and the send box aims at it */
.cmd.focused { box-shadow: inset 0 2px 0 0 var(--accent); }
.cmd.focused .cmd-target { border-color: var(--accent); color: var(--accent); }
.focus-note {
  flex: none;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--accent);
  font-size: 11px;
  letter-spacing: .04em;
}
.focus-clear { flex: none; }
.focus-clear:hover { color: var(--accent); border-color: var(--accent); }
.cmd-input {
  flex: 1; background: #0a0d13; border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 10px; min-width: 0;
}

/* ------------------------------------------------------------- settings */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 10, .72);
  display: grid;
  place-items: center;
  padding: 24px 16px;
  z-index: 50;
}
.modal-box {
  width: min(560px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.modal-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--panel);
}
.modal-head h2 {
  flex: 1;
  margin: 0;
  font-size: 13px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent);
}
.modal-section { padding: 16px; border-bottom: 1px solid var(--line); }
.modal-section:last-child { border-bottom: 0; }
.modal-section h3 {
  margin: 0 0 6px;
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--dim);
}
.hint { margin: 0 0 10px; color: var(--dim); font-size: 11px; line-height: 1.6; }

.upload {
  display: block;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 14px;
  text-align: center;
  color: var(--dim);
  cursor: pointer;
}
.upload:hover { border-color: var(--accent); color: var(--accent); }

.dlg-bar { display: flex; gap: 8px; }
.save-note { font-size: 11px; line-height: 1.6; padding: 6px 2px 0; min-height: 1em; }
.save-note.good { color: var(--accent-2); }
.save-note.bad { color: var(--error); }
.dialogs {
  list-style: none;
  margin: 10px 0;
  padding: 4px;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0a0d13;
}
.dialogs li { border-radius: 4px; }
.dialogs li:hover { background: #141a24; }
.dialogs label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  cursor: pointer;
}
.dialogs li.hint { padding: 8px; }

.uploads, .assign { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.uploads li, .assign li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border-radius: 6px;
  background: #0a0d13;
}
.uploads .name, .assign .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uploads li.hint { background: none; padding: 0; }
.mini.danger { color: var(--error); border-color: transparent; }
.mini.danger:hover { border-color: var(--error); }
.wide-sel { max-width: 140px; }
.btn.wide { width: 100%; margin: 6px 0; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .side { display: none; }
  .row .c { width: 9ch; }
}
