:root {
  --bg: #0b0d12;
  --panel: #11151c;
  --panel-2: #161b25;
  --border: #232a37;
  --fg: #e7eaf0;
  --muted: #8a93a4;
  --accent: #6ea8fe;
  --accent-2: #4cc9a4;
  --warn: #f0a34a;
  --danger: #f06a6a;
  --kind-fyi: #4cc9a4;
  --kind-question: #f0a34a;
  --kind-answer: #6ea8fe;
  --kind-status: #8a93a4;
  --kind-unblock: #f06a6a;
  --radius: 10px;
  --tap: 44px;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
               Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
}

#topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: env(safe-area-inset-top) 14px 8px;
  padding-top: max(env(safe-area-inset-top), 8px);
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; letter-spacing: .02em; }
.status { font-size: 12px; color: var(--muted); }
.status.ok { color: var(--accent-2); }
.status.err { color: var(--danger); }

#tabs {
  display: flex;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 38px;
  z-index: 9;
}
.tab {
  flex: 1 1 auto;
  min-height: var(--tap);
  background: transparent;
  color: var(--muted);
  border: 0;
  border-bottom: 2px solid transparent;
  font: inherit;
  font-weight: 600;
  letter-spacing: .02em;
  cursor: pointer;
}
.tab.active { color: var(--fg); border-bottom-color: var(--accent); }

main#views { padding: 12px; padding-bottom: max(env(safe-area-inset-bottom), 24px); }
.view { display: none; }
.view.active { display: block; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.btn-primary, .btn-secondary {
  min-height: var(--tap);
  padding: 0 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--accent); color: #07101e; border-color: var(--accent); }
.btn-primary:disabled { opacity: .5; }
.btn-secondary { background: var(--panel-2); color: var(--fg); }

label {
  display: block;
  margin-bottom: 12px;
  font-size: 14px;
  color: var(--muted);
}
input, select, textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 12px;
  background: var(--panel-2);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  font-size: 16px;
}
textarea { resize: vertical; min-height: 120px; }

.muted { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); padding: 20px; text-align: center; }
.hidden { display: none; }

.msg-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.msg {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.msg-h {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
.msg-from { color: var(--fg); font-weight: 600; }
.msg-to { color: var(--fg); font-weight: 600; }
.msg-arrow { color: var(--muted); }
.msg-kind {
  margin-left: auto;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 11px;
  text-transform: uppercase;
  background: var(--panel-2);
  border: 1px solid var(--border);
}
.msg-kind.fyi      { color: var(--kind-fyi); }
.msg-kind.question { color: var(--kind-question); }
.msg-kind.answer   { color: var(--kind-answer); }
.msg-kind.status   { color: var(--kind-status); }
.msg-kind.unblock  { color: var(--kind-unblock); }
.msg-time { font-variant-numeric: tabular-nums; }
.msg-reply {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
}
.msg-reply:hover, .msg-reply:active { color: var(--accent); border-color: var(--accent); }
.msg-body {
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.4;
  max-height: 4.5em;
  overflow: hidden;
  position: relative;
  cursor: pointer;
}
.msg-body.expanded { max-height: none; }
.msg-body:not(.expanded)::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 1.4em;
  background: linear-gradient(transparent, var(--panel));
  pointer-events: none;
}
.msg-body a {
  color: var(--accent);
  text-decoration: underline;
}
.msg-body a.action {
  display: inline-block;
  padding: 6px 14px;
  margin: 2px 4px 2px 0;
  min-height: var(--tap);
  line-height: calc(var(--tap) - 14px);
  background: var(--panel-2);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  -webkit-tap-highlight-color: rgba(110, 168, 254, 0.3);
}
.msg-body a.action:active {
  background: var(--accent);
  color: var(--bg);
}

/* Highlights tree */
details.cat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
}
details.cat > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
details.cat > summary::-webkit-details-marker { display: none; }
details.cat .cat-count {
  background: var(--panel-2);
  color: var(--muted);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 600;
}
details.cat .cat-list {
  border-top: 1px solid var(--border);
  padding: 8px 12px;
}
details.cat .cat-list .msg {
  background: var(--panel-2);
}

.legal { margin-top: 24px; }
.legal code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }

/* ---- Automations tab ---- */
.automation-card { padding: .6rem .75rem; border-bottom: 1px solid var(--border, #2a2a35); }
.automation-card.disabled { opacity: .55; }
.auto-row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.auto-name { font-weight: 600; }
.auto-trigger { font-size: .85rem; margin-top: .2rem; }
.auto-meta { font-size: .75rem; opacity: .7; margin-top: .15rem; }
.auto-toggle {
  border: 1px solid var(--border, #2a2a35); border-radius: 999px;
  padding: .2rem .7rem; font-size: .75rem; cursor: pointer;
  background: transparent; color: inherit;
}
.auto-toggle.on { background: var(--accent, #3a7); color: #fff; border-color: transparent; }
.note { font-size: .72rem; opacity: .6; padding: .5rem .75rem; }

/* ---- Services tab (LLM fleet) ---- */
.service-card { padding: .6rem .8rem; border-bottom: 1px solid var(--border, #2a2a35); }
.svc-row { display: flex; justify-content: space-between; align-items: center; }
.svc-name { font-weight: 600; }
.svc-state.on { color: #3fb950; }
.svc-state.off { color: #8b949e; }
.svc-meta { font-size: .75rem; opacity: .7; margin-top: .15rem; }
.svc-controls { display: flex; gap: .4rem; margin-top: .4rem; flex-wrap: wrap; }
.svc-controls button, .svc-model { font-size: .85rem; }

/* ---- Launched lanes ---- */
.lanes-head { display: flex; justify-content: space-between; align-items: center; margin: .6rem .8rem .2rem; }
.lane-ctrls { display: inline-flex; gap: .4rem; align-items: center; }
.lane-n { width: 3em; }
.lane-ctrls button, .lane-n { font-size: .85rem; }
#new-lane-form { display: flex; flex-wrap: wrap; gap: .4rem; padding: .6rem .8rem; }
#new-lane-form input, #new-lane-form select, #new-lane-form textarea { font-size: .85rem; }
#nl-context { width: 100%; min-height: 4rem; font-family: inherit; }
.ctx-editor { margin: 0.4rem 0 0; display: flex; flex-direction: column; gap: 0.3rem; padding: .4rem .8rem; }
.ctx-editor.hidden { display: none; }
.ctx-text { width: 100%; min-height: 5rem; font-family: inherit; box-sizing: border-box; }
.ctx-file { display: block; font-size: .85rem; }
.ctx-save { align-self: flex-start; font-size: .85rem; }
.lane-ctx { /* inherits .lane-ctrls button sizing */ }

/* ---- Meta-Edge SSO sign-in (Settings) ---- */
.sso-block { margin-bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; }
.sso-label { margin: 0 0 .25rem; font-weight: 600; }
.btn-sso {
  display: block; text-align: center; padding: .7rem 1rem; border-radius: 8px;
  background: #1f2937; color: #fff; text-decoration: none; font-weight: 600;
  border: 1px solid #374151;
}
.btn-sso:hover { background: #111827; }
.sso-rec { font-size: .72rem; font-weight: 700; color: #34d399; margin-left: .35rem; }
.sso-or { text-align: center; color: #8a8f98; font-size: .8rem; margin: .25rem 0 0; }

/* ---- SSO connected state (Settings) ---- */
.sso-connected {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem;
  background: #0f2a1d; border: 1px solid #1f7a4d; color: #d1fae5; font-weight: 600;
}
.sso-connected button { margin-left: auto; }
