/* Base reset (the artifact skeleton used to provide this) */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
[hidden] { display: none !important; }
img { max-width: 100%; }
/* Layout: ops-room console in the Securiverse palette. Navy channel rail, mist feed, orange only where action happens (send, active channel, Forge). Rail folds into a top strip on phones. */
:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --line: #dce5ee;
  --fg: #102541;
  --muted: #5b6c80;
  --accent: #002147;
  --accent-soft: #e8eef5;
  --orange: #f26722;
  --on-orange: #ffffff;
  --forge: #d9551a;
  --forge-soft: #fdeee6;
  --manus: #2f5f93;
  --manus-soft: #e3ecf6;
  --danger: #b42318;
  --rail: #002147;
  --rail-fg: #f4f7fb;
  --rail-muted: #a9bbd0;
  --rail-line: #12355f;
  --rail-hover: #0b2e5a;
  --rail-active: #f26722;
  --rail-active-fg: #ffffff;
  --f-display: "Michroma", "Manrope", "Arial Black", sans-serif;
  --f-ui: "Manrope", "Inter", system-ui, sans-serif;
  --f-body: "Inter", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #07111e; --panel: #0d1a2b; --line: #1d2f47; --fg: #e6edf5; --muted: #8fa1b6;
    --accent: #d7e5f4; --accent-soft: #14253b; --orange: #f26722; --on-orange: #ffffff;
    --forge: #f68a52; --forge-soft: #2a170d; --manus: #8fb4dc; --manus-soft: #12233a; --danger: #f08a80;
    --rail: #00182f; --rail-fg: #e6edf5; --rail-muted: #8fa1b6; --rail-line: #0f2742; --rail-hover: #0a2340;
    --rail-active: #f26722; --rail-active-fg: #ffffff; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #07111e; --panel: #0d1a2b; --line: #1d2f47; --fg: #e6edf5; --muted: #8fa1b6;
  --accent: #d7e5f4; --accent-soft: #14253b; --orange: #f26722; --on-orange: #ffffff;
  --forge: #f68a52; --forge-soft: #2a170d; --manus: #8fb4dc; --manus-soft: #12233a; --danger: #f08a80;
  --rail: #00182f; --rail-fg: #e6edf5; --rail-muted: #8fa1b6; --rail-line: #0f2742; --rail-hover: #0a2340;
  --rail-active: #f26722; --rail-active-fg: #ffffff; color-scheme: dark;
}
html, body { height: 100%; }
body { background: var(--bg); color: var(--fg); font-family: var(--f-body); font-size: 15px; line-height: 1.5; }
* { box-sizing: border-box; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--orange); outline-offset: 2px; }

.app { height: 100%; display: grid; grid-template-columns: 248px minmax(0, 1fr); }

/* ---------- rail ---------- */
.side { background: var(--rail); color: var(--rail-fg); border-right: 1px solid var(--rail-line); display: flex; flex-direction: column; gap: 18px; padding: 18px 14px; min-height: 0; overflow-y: auto; }
.brand { display: flex; flex-direction: column; gap: 2px; padding-inline: 6px; }
.logo { font-family: var(--f-display); font-size: 22px; letter-spacing: 0.12em; line-height: 1.1; color: var(--rail-fg); }
.logo-rule { height: 3px; width: 44px; background: var(--orange); margin: 6px 0 4px; border-radius: 1px; }
.sub { font-family: var(--f-mono); font-size: 11px; letter-spacing: 0.08em; color: var(--rail-muted); text-transform: uppercase; }
.sec-label { font-family: var(--f-ui); font-weight: 700; font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--rail-muted); padding-inline: 6px; }
.group { display: flex; flex-direction: column; gap: 6px; }
nav.chans { display: flex; flex-direction: column; gap: 2px; }
.chan { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; background: none; border: 0; border-radius: 6px; padding: 7px 8px; font-family: var(--f-ui); font-weight: 600; font-size: 16px; color: var(--rail-muted); }
.chan:hover { background: var(--rail-hover); color: var(--rail-fg); }
.chan[aria-current="true"] { background: var(--rail-active); color: var(--rail-active-fg); }
.chan .hash { font-family: var(--f-mono); font-weight: 500; opacity: 0.7; }
.ghost { background: none; border: 1px dashed var(--rail-line); border-radius: 6px; padding: 6px 8px; font-family: var(--f-ui); font-weight: 600; color: var(--rail-muted); text-align: left; }
.ghost:hover { color: var(--rail-fg); border-color: var(--rail-muted); }
.newchan { display: flex; gap: 6px; }
.newchan input { flex: 1; min-width: 0; border: 1px solid var(--rail-line); background: var(--rail-hover); color: var(--rail-fg); border-radius: 6px; padding: 6px 8px; }
.newchan button { border: 0; border-radius: 6px; background: var(--orange); color: var(--on-orange); padding: 6px 10px; font-family: var(--f-ui); font-weight: 600; }
.roster { list-style: none; margin: 0; padding: 0 6px; display: flex; flex-direction: column; gap: 10px; }
.roster li { display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: center; }
.roster b { font-family: var(--f-ui); font-weight: 700; font-size: 15px; display: block; line-height: 1.2; }
.roster small { color: var(--rail-muted); font-size: 12.5px; line-height: 1.3; display: block; }
.badge { width: 28px; height: 28px; border-radius: 6px; display: grid; place-items: center; font-family: var(--f-mono); font-weight: 500; font-size: 13px; color: var(--panel); flex: none; }
.badge.forge { background: var(--orange); color: var(--on-orange); }
.badge.manus { background: var(--manus); }
.badge img { width: 100%; height: 100%; border-radius: 6px; object-fit: cover; }
.me { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 10px 6px 0; border-top: 1px solid var(--rail-line); font-family: var(--f-ui); font-weight: 600; }
.me img { width: 28px; height: 28px; border-radius: 6px; }

/* ---------- main ---------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--panel); }
.chan-head { display: flex; align-items: flex-start; gap: 12px; padding: 14px 20px 12px; border-bottom: 1px solid var(--line); }
.chan-head .t { flex: 1; min-width: 0; }
.chan-head h1 { margin: 0; font-family: var(--f-ui); font-weight: 700; font-size: 22px; line-height: 1.2; letter-spacing: 0.01em; }
.chan-head h1 .hash { font-family: var(--f-mono); color: var(--muted); font-weight: 400; margin-right: 2px; }
.topic { margin: 2px 0 0; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.repos { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.repo { font-family: var(--f-mono); font-size: 11.5px; padding: 2px 7px; border-radius: 4px; background: var(--accent-soft); color: var(--fg); }
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 6px 12px; font-family: var(--f-ui); font-weight: 600; font-size: 14px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--panel); }
.btn:disabled { opacity: 0.5; cursor: default; }

.brief { padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--bg); display: grid; gap: 10px; }
.brief label { display: grid; gap: 4px; font-family: var(--f-ui); font-weight: 600; font-size: 13px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.brief textarea { width: 100%; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); padding: 8px 10px; font-family: var(--f-body); font-size: 14px; text-transform: none; letter-spacing: 0; color: var(--fg); resize: vertical; }
.brief .row { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

.feed { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 20px 8px; display: flex; flex-direction: column; gap: 2px; }
.day { align-self: center; margin: 14px 0 8px; font-family: var(--f-mono); font-size: 11px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.msg { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 12px; padding: 6px 8px; border-radius: 8px; }
.msg:hover { background: color-mix(in srgb, var(--bg) 60%, transparent); }
.msg.cont { padding-top: 1px; }
.msg.cont .av { visibility: hidden; height: 0; }
.msg.forge { background: color-mix(in srgb, var(--forge-soft) 70%, transparent); border-left: 3px solid var(--orange); padding-left: 5px; }
.msg.manus { background: color-mix(in srgb, var(--manus-soft) 55%, transparent); border-left: 3px solid var(--manus); padding-left: 5px; }
.av { width: 34px; height: 34px; border-radius: 7px; overflow: hidden; display: grid; place-items: center; }
.av img { width: 34px; height: 34px; object-fit: cover; }
.av .badge { width: 34px; height: 34px; border-radius: 7px; font-size: 14px; }
.meta { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.who { font-family: var(--f-ui); font-weight: 700; font-size: 15.5px; }
.msg.forge .who { color: var(--forge); }
.msg.manus .who { color: var(--manus); }
.tag { font-family: var(--f-mono); font-size: 10.5px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.time { font-family: var(--f-mono); font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.body { overflow-wrap: anywhere; min-width: 0; }
.body p { margin: 0 0 6px; }
.body p:last-child { margin-bottom: 0; }
.body ul, .body ol { margin: 2px 0 8px; padding-left: 22px; }
.body h4 { margin: 8px 0 4px; font-family: var(--f-ui); font-size: 16px; }
.body code { font-family: var(--f-mono); font-size: 0.86em; background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; }
.body pre { margin: 6px 0 8px; background: var(--rail); border: 1px solid var(--line); border-radius: 6px; padding: 10px 12px; overflow-x: auto; }
.body pre code { background: none; padding: 0; font-size: 12.5px; line-height: 1.55; }
.body a { color: var(--accent); }
.mention { font-weight: 600; border-radius: 4px; padding: 0 3px; }
.mention.forge { color: var(--forge); background: var(--forge-soft); }
.mention.manus { color: var(--manus); background: var(--manus-soft); }
.files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.thumb { display: block; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; max-width: 260px; }
.thumb img { display: block; max-height: 200px; width: auto; max-width: 100%; }
.filechip { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; text-decoration: none; color: var(--fg); background: var(--panel); max-width: 100%; }
.filechip .ext { font-family: var(--f-mono); font-size: 10.5px; padding: 1px 5px; border-radius: 3px; background: var(--accent); color: var(--panel); text-transform: uppercase; flex: none; }
.filechip .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.filechip .sz { font-family: var(--f-mono); font-size: 11px; color: var(--muted); flex: none; }
.cursor { display: inline-block; width: 8px; height: 1em; background: var(--orange); vertical-align: text-bottom; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .cursor { animation: none; } }
.live-row { display: flex; gap: 10px; align-items: center; margin-top: 6px; }
.empty { margin: auto; text-align: center; max-width: 420px; color: var(--muted); padding: 30px 10px; }
.empty h2 { font-family: var(--f-display); font-weight: 400; font-size: 18px; color: var(--fg); margin: 0 0 8px; letter-spacing: 0.08em; }
.empty p { margin: 0 0 6px; }

.notice { margin: 0 20px 6px; padding: 8px 12px; border-radius: 6px; font-size: 14px; background: var(--bg); border: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-start; }
.notice.err { border-color: var(--danger); color: var(--danger); }
.notice .x { margin-left: auto; background: none; border: 0; color: var(--muted); font-size: 16px; line-height: 1; padding: 0 2px; }

.composer { border-top: 1px solid var(--line); padding: 10px 20px calc(12px + env(safe-area-inset-bottom, 0px)); display: grid; gap: 8px; background: var(--panel); }
.composer.drag { background: var(--accent-soft); }
.tray { display: flex; flex-wrap: wrap; gap: 6px; }
.tray .filechip { padding: 4px 8px; font-size: 13px; }
.tray .filechip button { background: none; border: 0; color: var(--muted); padding: 0 0 0 2px; font-size: 15px; line-height: 1; }
.inputrow { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; align-items: end; }
.inputrow textarea { width: 100%; resize: none; min-height: 44px; max-height: 220px; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--bg); line-height: 1.45; }
.iconbtn { width: 44px; height: 44px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); display: grid; place-items: center; color: var(--muted); }
.iconbtn:hover { color: var(--fg); border-color: var(--muted); }
.iconbtn svg { width: 20px; height: 20px; }
.send { height: 44px; padding: 0 18px; border-radius: 8px; border: 0; background: var(--orange); color: var(--on-orange); font-family: var(--f-ui); font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; font-size: 14px; }
.send:disabled { opacity: 0.5; cursor: default; }
.helpers { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 13px; color: var(--muted); }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 2px 10px; font-family: var(--f-mono); font-size: 12px; }
.chip.forge { color: var(--forge); }
.chip.manus { color: var(--manus); }
.chip[aria-pressed="true"] { background: var(--manus); border-color: var(--manus); color: var(--panel); }
.helpers .hint { font-family: var(--f-mono); font-size: 11px; }
.helpers .hint:last-child { margin-left: 0; }
#forgeStatus { color: var(--orange); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .side { flex-direction: row; align-items: center; gap: 12px; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--line); overflow-x: auto; overflow-y: hidden; }
  .brand .sub, .logo-rule, .side .sec-label, .roster, .me, #rosterGroup { display: none; }
  .logo { font-size: 16px; }
  .group { flex-direction: row; align-items: center; }
  nav.chans { flex-direction: row; gap: 4px; }
  .chan { white-space: nowrap; padding: 5px 9px; font-size: 15px; }
  .newchan input { width: 120px; }
  .chan-head, .feed, .composer, .brief { padding-left: 16px; padding-right: 16px; }
  .notice { margin-inline: 16px; }
  .helpers .hint { display: none; }
  .helpers #forgeStatus { display: inline; }
}

/* ---------- v1 additions ---------- */
.msg.system { opacity: 0.85; }
.msg.system .who { color: var(--muted); }
.badge.system { background: var(--muted); }
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; background: var(--rail); }
.login form { width: 100%; max-width: 380px; background: var(--panel); border-radius: 12px; padding: 28px 24px; display: grid; gap: 14px; }
.login .logo { color: var(--fg); font-size: 26px; }
.login label { display: grid; gap: 6px; font-family: var(--f-ui); font-weight: 600; font-size: 14px; }
.login input { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; background: var(--bg); }
.login .err { color: var(--danger); font-size: 14px; min-height: 1.2em; }
.login .send { width: 100%; }
.setup-notice { width: 100%; max-width: 460px; background: var(--panel); border-radius: 12px; padding: 28px 24px; color: var(--fg); }
.setup-notice .logo { color: var(--fg); font-size: 26px; }
.setup-notice h1 { margin: 14px 0 8px; font-family: var(--f-ui); font-size: 20px; }
.setup-notice p { margin: 0; color: var(--muted); }
.usage { padding-inline: 6px; font-family: var(--f-mono); font-size: 11px; color: var(--rail-muted); display: grid; gap: 4px; }
.usage .bar { height: 4px; border-radius: 2px; background: var(--rail-line); overflow: hidden; }
.usage .bar span { display: block; height: 100%; background: var(--orange); }
.me { justify-content: space-between; }
.me .who-me { display: flex; align-items: center; gap: 10px; min-width: 0; }
.me .linkish { background: none; border: 0; color: var(--rail-muted); font-family: var(--f-mono); font-size: 11px; padding: 2px 4px; }
.me .linkish:hover { color: var(--rail-fg); }
.modal-back { position: fixed; inset: 0; background: rgba(0, 10, 25, 0.55); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal { width: 100%; max-width: 380px; max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); overflow: hidden; background: var(--panel); border-radius: 12px; padding: 22px; display: grid; grid-template-rows: auto minmax(0, 1fr); gap: 12px; }
.modal h3 { margin: 0; font-family: var(--f-ui); }
.modal label { display: grid; gap: 6px; font-size: 14px; font-family: var(--f-ui); font-weight: 600; }
.modal input { border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; background: var(--bg); }
.modal .row { display: flex; gap: 8px; justify-content: flex-end; }
.modal .err { color: var(--danger); font-size: 13px; min-height: 1.1em; }

/* ---------- private account and worker-state controls ---------- */
.optional { color: var(--muted); font-family: var(--f-body); font-size: 12px; font-weight: 400; text-transform: none; letter-spacing: 0; }
.account-btn { white-space: nowrap; }
.me-actions { display: inline-flex; align-items: center; gap: 2px; }
.channel-working { margin-left: auto; font-family: var(--f-mono); font-size: 9px; letter-spacing: 0.05em; text-transform: uppercase; opacity: 0.78; }
.state-tag { border: 1px solid var(--line); border-radius: 999px; padding: 1px 6px; color: var(--muted); font-family: var(--f-mono); font-size: 9px; font-weight: 500; letter-spacing: 0.06em; text-transform: uppercase; }
.state-tag.pending, .state-tag.running { border-color: var(--orange); color: var(--orange); }
.state-tag.waiting { border-color: var(--manus); color: var(--manus); }
.state-tag.error { border-color: var(--danger); color: var(--danger); }
.status-pending, .status-running, .status-waiting { opacity: 0.94; }
.work-state { margin-top: 2px; }
.modal-head { display: flex; align-items: flex-start; gap: 12px; }
.modal-head h3 { flex: 1; }
.modal-close { width: 30px; height: 30px; margin: -4px -5px 0 0; border: 0; border-radius: 5px; background: none; color: var(--muted); font-size: 24px; line-height: 1; }
.modal-close:hover { background: var(--accent-soft); color: var(--fg); }
.modal-content, .modal-form, .modal-actions, .connection-summary, .totp-body { display: grid; gap: 12px; }
.modal-content { min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.modal-content > p { margin: 0; color: var(--muted); font-size: 14px; }
.modal-form label { display: grid; gap: 6px; font-size: 14px; font-family: var(--f-ui); font-weight: 600; }
.modal-form input { border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; background: var(--bg); min-width: 0; }
.modal-form label.check { display: flex; align-items: center; gap: 8px; color: var(--muted); font-family: var(--f-body); font-size: 13px; font-weight: 400; }
.modal-form label.check input { width: 16px; height: 16px; padding: 0; }
.modal-actions { grid-template-columns: 1fr; }
.modal-actions .btn { text-align: left; }
.modal-actions.split-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.modal-actions.split-actions .btn { text-align: center; }
.modal-actions.split-actions .btn.primary { grid-column: 1 / -1; }
.connection-summary { border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: var(--bg); color: var(--muted); font-size: 13px; }
.connection-line { display: grid; grid-template-columns: minmax(120px, auto) 1fr; column-gap: 10px; row-gap: 2px; align-items: baseline; }
.connection-line strong { color: var(--fg); font-family: var(--f-ui); }
.connection-line small { grid-column: 2; font-family: var(--f-mono); font-size: 10px; overflow-wrap: anywhere; }
.connection-state { overflow-wrap: anywhere; }
.connection-state.good { color: var(--manus); }
.connection-state.waiting { color: var(--orange); }
.connection-state.off { color: var(--muted); }
.totp-body > .btn { width: fit-content; }

@media (max-width: 760px) {
  .account-btn { display: inline-block; }
  .channel-working { display: none; }
  .connection-line { grid-template-columns: 1fr; row-gap: 3px; }
  .connection-line small { grid-column: 1; }
}

@media (max-width: 440px) {
  .chan-head { gap: 8px; }
  .chan-head h1 { font-size: 19px; }
  .account-btn { padding-inline: 8px; font-size: 13px; }
  #briefBtn { padding-inline: 8px; font-size: 13px; }
  .inputrow { grid-template-columns: 42px minmax(0, 1fr); }
  .inputrow .send { grid-column: 1 / -1; width: 100%; }
  .iconbtn { width: 42px; }
  .modal-actions.split-actions { grid-template-columns: 1fr; }
  .modal-actions.split-actions .btn.primary { grid-column: auto; }
}
