/* webui/style.css — self-hosted, no webfonts, no CDN: the CSP in services/webconfig.py
   forbids every external origin, so anything loaded from outside would silently fail. */

:root {
  --bg: #16171b;
  --panel: #1e2025;
  --panel-2: #24262c;
  --line: #32353d;
  --text: #e6e8ec;
  --muted: #9aa0ab;
  --accent: #5865f2;
  --ok: #2f9e64;
  --err: #d8464a;
  --radius: 8px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 20px;
  border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 5;
}
header h1 { font-size: 16px; margin: 0; letter-spacing: .2px; }
.who { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--muted); }
.who img { border-radius: 50%; }

.shell { display: grid; grid-template-columns: 260px 1fr; min-height: calc(100vh - 49px); }

nav {
  border-right: 1px solid var(--line); background: var(--panel);
  padding: 12px; display: flex; flex-direction: column; gap: 2px;
  max-height: calc(100vh - 49px); overflow-y: auto; position: sticky; top: 49px;
}

.stem {
  display: flex; align-items: center; gap: 6px; width: 100%;
  padding: 7px 10px; border: 0; border-radius: var(--radius);
  background: transparent; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.stem:hover:not(:disabled) { background: var(--panel-2); }
.stem.active { background: var(--accent); color: #fff; }
.stem:disabled { opacity: .45; cursor: not-allowed; }
.stem-name { flex: 1; }

.tag { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; padding: 2px 5px; border-radius: 4px; }
.tag.owner { background: #4b3a12; color: #f0c674; }
.tag.locked { background: #3a2020; color: #d99; }
.tag.warn { background: #3a3320; color: #d8c07a; }

main { padding: 24px 28px 80px; max-width: 900px; }
.empty { padding-top: 60px; }
.muted { color: var(--muted); }

.pane-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 20px; padding-bottom: 12px; border-bottom: 1px solid var(--line);
}
.pane-head h2 { margin: 0; font-size: 20px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.btn {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  padding: 8px 14px; border-radius: var(--radius); font: inherit; cursor: pointer;
}
.btn:hover:not(:disabled) { border-color: #4a4e58; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:disabled { background: var(--panel-2); border-color: var(--line); color: var(--muted); cursor: default; }
.btn.ghost { background: transparent; padding: 5px 10px; font-size: 13px; }
.btn.danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn.danger:hover:not(:disabled) { background: #c23b3f; border-color: #c23b3f; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.ok:hover:not(:disabled) { background: #298855; border-color: #298855; }
.btn:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }

.group { margin-bottom: 30px; }
.group h3 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--muted); margin: 0 0 12px; padding-bottom: 6px; border-bottom: 1px solid var(--line);
}

.field { margin-bottom: 18px; }
.field-label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 4px; }
.crumb { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 8px; }
.desc { margin: 0 0 8px; color: var(--muted); font-size: 13px; }

input[type=text], input[type=number], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); color: var(--text); font: inherit;
}
textarea { resize: vertical; }
textarea.json { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
textarea.bad { border-color: var(--err); }
.jsonerr { color: var(--err); font-size: 12px; margin: 4px 0 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
input:disabled, select:disabled, textarea:disabled { opacity: .55; cursor: not-allowed; }

.switch { display: inline-flex; align-items: center; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.slider { width: 42px; height: 24px; border-radius: 999px; background: var(--line); position: relative; transition: background .15s; }
.slider::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; transition: transform .15s;
}
.switch input:checked + .slider { background: var(--ok); }
.switch input:checked + .slider::after { transform: translateX(18px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Chip selector (channels / roles) ───────────────────────────────────── */

.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chips-none { color: var(--muted); font-size: 13px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 6px 4px 10px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line);
  font-size: 13px; max-width: 100%;
}
.chip.unknown { border-color: var(--err); color: #f0a0a2; }
.chip-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip-label.as-button {
  background: none; border: 0; padding: 0; margin: 0;
  color: inherit; font: inherit; cursor: pointer;
}
.chip-label.as-button:hover { text-decoration: underline; }

.chip-x {
  display: flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; flex: none;
  border: 0; border-radius: 50%; background: transparent;
  color: var(--muted); font-size: 15px; line-height: 1; cursor: pointer; padding: 0;
}
.chip-x:hover { background: var(--err); color: #fff; }

.chip.add {
  padding: 4px 12px; cursor: pointer; color: var(--muted);
  border-style: dashed; background: transparent; font-size: 15px; line-height: 18px;
}
.chip.add:hover { color: var(--text); border-color: var(--accent); border-style: solid; }
.chip.add:focus-visible, .chip-x:focus-visible, .chip-label.as-button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: #99aab5; }
.dot.nocolor { box-shadow: inset 0 0 0 1px var(--line); background: transparent; }

/* ── Inline markup + rich text field ────────────────────────────────────── */

.emoji {
  width: 1.35em; height: 1.35em;
  vertical-align: -0.28em; object-fit: contain;
}

.mention {
  background: rgba(88, 101, 242, .28); color: #c9cdfb;
  border-radius: 4px; padding: 0 3px; white-space: nowrap;
  -webkit-user-select: all; user-select: all;   /* atomic: select it whole, or not at all */
}

/* A contenteditable that looks exactly like the plain inputs next to it. */
.rich {
  width: 100%; min-height: 38px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); color: var(--text); font: inherit;
  white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere;
}
.rich.multi { min-height: 84px; }
.rich:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.rich.ro { opacity: .55; }
.rich:empty::before {
  content: attr(data-placeholder);
  color: var(--muted); pointer-events: none;
}

/* ── Emoji autocomplete (typing ":") ────────────────────────────────────── */

.ac {
  position: fixed; z-index: 60; width: 250px; max-height: 216px; overflow-y: auto;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0, 0, 0, .5); padding: 4px;
}
.ac-row {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 5px 8px; border: 0; border-radius: 5px;
  background: transparent; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.ac-row.active, .ac-row:hover { background: var(--accent); color: #fff; }
.ac-row .emoji { width: 20px; height: 20px; vertical-align: middle; }
.ac-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }

/* ── Array item cards ───────────────────────────────────────────────────── */

.array { display: flex; flex-direction: column; gap: 6px; }

.card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.card[open] { border-color: #454a55; }
.card-head {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; cursor: pointer; list-style: none;
}
.card-head::-webkit-details-marker { display: none; }
.card-head::before { content: "▸"; color: var(--muted); font-size: 11px; flex: none; }
.card[open] .card-head::before { content: "▾"; }
.card-idx {
  flex: none; min-width: 20px; height: 20px; border-radius: 4px;
  background: var(--panel-2); color: var(--muted);
  font-size: 11px; display: flex; align-items: center; justify-content: center;
}
.card-sum { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.card-tools { display: flex; gap: 2px; flex: none; }
.card-body { padding: 4px 12px 12px 12px; border-top: 1px solid var(--line); }
.card-body .field:last-child { margin-bottom: 0; }

.icon-btn {
  width: 24px; height: 24px; border: 0; border-radius: 5px;
  background: transparent; color: var(--muted); cursor: pointer;
  font-size: 13px; line-height: 1; padding: 0;
}
.icon-btn:hover:not(:disabled) { background: var(--panel-2); color: var(--text); }
.icon-btn:disabled { opacity: .3; cursor: default; }

.array-add { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }

/* ── Confirm modal ──────────────────────────────────────────────────────── */
/* Shares .picker-overlay as its backdrop; only the panel differs. */

.modal {
  width: 100%; max-width: 440px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, .5);
}
.modal-title { margin: 0 0 8px; font-size: 17px; }
.modal-body { margin: 0 0 20px; color: var(--muted); font-size: 14px; }

/* Destructive alone on the left, the safe pair on the right, so the red button is
   nowhere near where the thumb lands for "yes". */
.modal-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.modal-left, .modal-right { display: flex; gap: 8px; }
.modal-left:empty { display: none; }

@media (max-width: 480px) {
  .modal-foot { flex-direction: column-reverse; align-items: stretch; }
  .modal-left, .modal-right { flex-direction: column; }
  .modal-foot .btn { width: 100%; }
}

/* ── Picker modal ───────────────────────────────────────────────────────── */

.picker-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, .55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 12vh 16px 16px;
}
.picker {
  width: 100%; max-width: 440px; max-height: 70vh;
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
  box-shadow: 0 18px 48px rgba(0, 0, 0, .5);
}
.picker-head { padding: 10px; border-bottom: 1px solid var(--line); }
.picker-search { width: 100%; }
.picker-list { overflow-y: auto; padding: 6px; }
.picker-empty:empty { display: none; }
.picker-empty { margin: 0; padding: 14px; text-align: center; color: var(--muted); font-size: 13px; }

.picker-row {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 7px 10px; border: 0; border-radius: var(--radius);
  background: transparent; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.picker-row:hover, .picker-row.active { background: var(--accent); color: #fff; }
.picker-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-cat { font-size: 11px; color: var(--muted); flex: none; }
.picker-row:hover .picker-cat, .picker-row.active .picker-cat { color: rgba(255, 255, 255, .75); }

.perm-grid { display: flex; flex-direction: column; gap: 6px; }
.perm-row { display: grid; grid-template-columns: 1fr 90px; gap: 10px; align-items: center; }
.perm-key { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }

.gate { max-width: 460px; margin: 15vh auto; text-align: center; padding: 0 20px; }
.gate h1 { font-size: 20px; }
.gate .btn { display: inline-block; text-decoration: none; margin-top: 12px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--panel-2); border: 1px solid var(--line); border-left: 3px solid var(--ok);
  padding: 12px 18px; border-radius: var(--radius); max-width: 640px;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-left-color: var(--err); }

@media (max-width: 720px) {
  .shell { grid-template-columns: 1fr; }
  nav { position: static; max-height: 220px; border-right: 0; border-bottom: 1px solid var(--line); }
  main { padding: 18px 16px 60px; }
}
