:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1b1f24;
  --muted: #5b6573;
  --border: #dde1e7;
  --accent: #1f5fbf;
  --accent-text: #ffffff;
  --accent-soft: #e6eefb;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #9a5b00;
  --warn-soft: #fff4e0;
  --ok: #1d7a3e;
  --ok-soft: #e5f5ea;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #1a1e24;
    --surface-2: #222830;
    --text: #e7eaee;
    --muted: #9aa4b1;
    --border: #2e3540;
    --accent: #5b9bff;
    --accent-text: #0b1220;
    --accent-soft: #1c2b44;
    --danger: #ff7b6e;
    --danger-soft: #3a1f1d;
    --warn: #f0b04a;
    --warn-soft: #3a2c15;
    --ok: #5fd08a;
    --ok-soft: #173224;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

a { color: var(--accent); }
code, .mono { font-family: var(--mono); font-size: 0.9em; }
h1 { font-size: 1.4rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 16px 0 8px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.boot { padding: 40px; color: var(--muted); }

/* ---------- Layout ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; white-space: nowrap; }
.brand img { width: 26px; height: 26px; }
.nav { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.nav a {
  padding: 6px 10px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--muted);
  white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.who { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.main { max-width: 1180px; margin: 0 auto; padding: 24px 20px 48px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.footer { text-align: center; color: var(--muted); font-size: 0.8rem; padding: 0 0 24px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); margin-bottom: 16px; }
.tile .label { color: var(--muted); font-size: 0.85rem; }
.tile .value { font-size: 1.8rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.tile .sub { color: var(--muted); font-size: 0.85rem; }

/* ---------- Sign-in ---------- */

.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth { width: 100%; max-width: 420px; }
.auth .brand { justify-content: center; font-size: 1.2rem; margin-bottom: 16px; }
.qr { display: block; margin: 8px auto 12px; width: 200px; height: 200px; image-rendering: pixelated; background: #fff; padding: 8px; border-radius: 8px; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; font-family: var(--mono); background: var(--surface-2); padding: 12px 16px; border-radius: 8px; margin-bottom: 12px; }

/* ---------- Forms ---------- */

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 0.9rem; }
.field .hint { color: var(--muted); font-size: 0.82rem; }
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > .field { flex: 1 1 200px; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }

button, .btn {
  font: inherit;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 7px 14px;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { background: var(--surface-2); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); }
button.danger:hover { background: var(--danger-soft); }
button.link { border: none; background: none; color: var(--accent); padding: 4px 6px; font-weight: 500; }
button:disabled { opacity: 0.55; cursor: default; }
button.block { width: 100%; padding: 10px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- Notices, badges ---------- */

.notice { border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; }
.notice.error { background: var(--danger-soft); color: var(--danger); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.info { background: var(--accent-soft); color: var(--text); }

.badge { display: inline-block; font-size: 0.75rem; font-weight: 600; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: none; }
td .sub { color: var(--muted); font-size: 0.85rem; }
.details { font-family: var(--mono); font-size: 0.8rem; color: var(--muted); word-break: break-word; max-width: 360px; }
.empty { text-align: center; color: var(--muted); padding: 28px 8px; }

/* ---------- Modal ---------- */

.overlay { position: fixed; inset: 0; background: rgb(0 0 0 / 45%); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal { background: var(--surface); border-radius: var(--radius); padding: 22px; width: 100%; max-width: 620px; max-height: calc(100vh - 32px); overflow-y: auto; border: 1px solid var(--border); }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }

.copy { position: relative; margin-bottom: 12px; }
.copy pre {
  margin: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  padding-right: 76px;
  font-family: var(--mono);
  font-size: 0.82rem;
  white-space: pre-wrap;
  word-break: break-all;
}
.copy button { position: absolute; top: 6px; right: 6px; padding: 3px 10px; font-size: 0.8rem; }

@media (max-width: 720px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 10px 16px; gap: 8px; }
  .nav { order: 3; flex-basis: 100%; }
  .main { padding: 16px 16px 40px; }
  .hide-sm { display: none; }
}

.mt { margin-top: 12px; }
.mb { margin-bottom: 12px; }
.mb-s { margin-bottom: 8px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.details { min-width: 200px; }
::placeholder { color: var(--muted); opacity: 0.6; }

/* ---------- Messages explorer & threads ---------- */

.filters .row > .field { flex: 1 1 170px; margin-bottom: 10px; }
.filters .grow { flex: 3 1 260px; }
table.clickable tbody tr { cursor: pointer; }
table.clickable tbody tr:hover { background: var(--surface-2); }
tr.fresh { animation: fresh 3s ease-out; }
@keyframes fresh { from { background: var(--accent-soft); } to { background: transparent; } }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }
a.btn { display: inline-block; text-decoration: none; }

.thread { display: flex; flex-direction: column; gap: 10px; }
.msg { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; background: var(--surface); }
.msg.system { background: var(--surface-2); }
.msg.request { border-left: 3px solid var(--accent); }
.msg.response { border-left: 3px solid var(--ok); }
.msg header { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
.msg-subject { font-weight: 600; margin-bottom: 4px; }
.msg-body { white-space: pre-wrap; word-break: break-word; margin-bottom: 6px; }
pre.data { background: var(--surface-2); padding: 8px; border-radius: 6px; overflow-x: auto; font-size: 0.8rem; }

/* ---------- Overview chart ---------- */

.bars { display: grid; grid-template-columns: repeat(30, 1fr); gap: 3px; height: 110px; align-items: end; }
.bar { height: 100%; display: flex; align-items: flex-end; }
.bar span { display: block; width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; }
.bars-axis { display: flex; justify-content: space-between; margin-top: 4px; }
.bar span.h0 { height: 0%; }
.bar span.h1 { height: 5%; }
.bar span.h2 { height: 10%; }
.bar span.h3 { height: 15%; }
.bar span.h4 { height: 20%; }
.bar span.h5 { height: 25%; }
.bar span.h6 { height: 30%; }
.bar span.h7 { height: 35%; }
.bar span.h8 { height: 40%; }
.bar span.h9 { height: 45%; }
.bar span.h10 { height: 50%; }
.bar span.h11 { height: 55%; }
.bar span.h12 { height: 60%; }
.bar span.h13 { height: 65%; }
.bar span.h14 { height: 70%; }
.bar span.h15 { height: 75%; }
.bar span.h16 { height: 80%; }
.bar span.h17 { height: 85%; }
.bar span.h18 { height: 90%; }
.bar span.h19 { height: 95%; }
.bar span.h20 { height: 100%; }
.bar span.h0 { background: var(--border); }

/* Compact filter panel */
.filters { padding: 14px 16px; }
.filters .row { gap: 8px 10px; }
.filters .row > .field { flex: 1 1 140px; margin-bottom: 6px; gap: 2px; }
.filters .field label { font-size: 0.78rem; color: var(--muted); font-weight: 600; }
.filters select, .filters input { padding: 5px 8px; font-size: 0.9rem; }

/* ---------- Requests board, approvals, map, post box ---------- */

.board { display: grid; grid-template-columns: repeat(4, minmax(220px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.lane { background: var(--surface-2); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.lane h3 { margin: 4px 4px 10px; font-size: 0.9rem; }
.req-card { display: block; width: 100%; text-align: left; font-weight: 400; margin-bottom: 8px; padding: 10px; background: var(--surface); border: 1px solid var(--border); white-space: normal; }
.req-card:hover { border-color: var(--accent); background: var(--surface); }
.req-card.overdue { border-left: 3px solid var(--danger); }
.req-subject { font-weight: 600; margin-bottom: 4px; }
@media (max-width: 720px) { .board { grid-template-columns: repeat(4, 240px); } }

.approval h2 { font-size: 1.05rem; }

svg.map { width: 100%; max-width: 620px; height: auto; display: block; margin: 0 auto; }
svg.map .edge { stroke: var(--accent); stroke-opacity: 0.45; stroke-linecap: round; }
svg.map .node { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 2; }
svg.map .node.owner { fill: var(--accent); }
svg.map .node.observer { stroke-dasharray: 3 3; }
svg.map .label { fill: var(--text); font-size: 12px; }

.postbox textarea { min-height: 70px; }
.postbox .field { max-width: 260px; }

/* ---------- Ideas ---------- */

hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }
ul.ideas { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
li.idea { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; }
li.idea .msg-body { margin: 6px 0; }
.idea-admin { align-items: center; gap: 6px; }
.idea-admin select { width: auto; }
.idea-admin input { flex: 1 1 200px; width: auto; }

/* Dialogs opened from the header must not inherit its no-wrap text. */
.overlay { white-space: normal; }

/* ---------- Attachments ---------- */
.attachments { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 6px; }
a.attachment { display: inline-flex; gap: 6px; align-items: center; padding: 3px 10px; border: 1px solid var(--border); border-radius: 99px; text-decoration: none; background: var(--surface-2); font-size: 0.88rem; }
a.attachment:hover { border-color: var(--accent); }
