:root {
  color-scheme: dark;
  --bg: #050806;
  --surface: #09100b;
  --surface-2: #0d1710;
  --text: #b9d9c0;
  --muted: #6f8c75;
  --green: #6de88d;
  --green-soft: #3e9e59;
  --line: #1d4027;
  --danger: #ff7d7d;
  --warn: #e6c66a;
  --focus: #b6ffca;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }
html { background: var(--bg); font-family: var(--mono); }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.55; }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--green); text-underline-offset: .22em; }

.shell { width: min(100%, 820px); min-height: 100vh; margin: 0 auto; padding: max(18px, env(safe-area-inset-top)) clamp(16px, 4vw, 34px) max(18px, env(safe-area-inset-bottom)); display: grid; grid-template-rows: auto auto auto 1fr auto; gap: 18px; }
.admin-shell { width: min(100%, 1100px); }
.topbar { min-height: 42px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--line); }
.brand { color: var(--green); letter-spacing: .08em; text-decoration: none; font-weight: 700; }
.network-state, .muted, .meta, footer { color: var(--muted); }
.network-state { font-size: .82rem; }
.network-state::before { content: "○ "; }
.network-state.online::before { content: "● "; color: var(--green); }
.warning { color: var(--warn); font-size: .85rem; }

.nav { display: flex; flex-wrap: wrap; gap: 8px 18px; border-bottom: 1px solid var(--line); padding-bottom: 14px; }
.nav button { border: 0; padding: 4px 0; background: transparent; color: var(--muted); cursor: pointer; }
.nav button:hover, .nav button:focus-visible, .nav button.active { color: var(--green); }

main { min-width: 0; }
body.chat-open { height: 100dvh; overflow: hidden; }
body.chat-open .shell { height: 100dvh; min-height: 0; overflow: hidden; }
body.chat-open main { min-height: 0; overflow: hidden; }
body.chat-open footer { display: none; }
.view { display: grid; gap: 20px; animation: appear .12s ease-out; }
.chat-view { height: 100%; min-height: 0; grid-template-rows: auto auto minmax(0, 1fr) auto; }
.chat-view > .stack { grid-row: 1; }
.chat-view > .notification-callout { grid-row: 2; }
.chat-view > .chat-log { grid-row: 3; }
.chat-view > .composer { grid-row: 4; }
@keyframes appear { from { opacity: .35; transform: translateY(2px); } }
h1, h2, h3, p { margin: 0; }
h1 { color: var(--green); font-size: clamp(1.25rem, 4vw, 1.6rem); letter-spacing: .04em; }
h2 { color: var(--green); font-size: 1rem; font-weight: 600; }
h3 { font-size: .95rem; }
.prompt-title::before { content: "/ "; color: var(--muted); }
.lead { max-width: 61ch; color: var(--text); }
.stack { display: grid; gap: 12px; }
.cluster { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.divider { border: 0; border-top: 1px solid var(--line); width: 100%; margin: 4px 0; }

.action { display: flex; align-items: center; width: fit-content; min-height: 42px; border: 1px solid var(--line); background: transparent; color: var(--green); padding: 8px 13px; cursor: pointer; text-align: left; }
.action::before { content: "> "; color: var(--muted); margin-right: 6px; }
.action:hover, .action:focus-visible { border-color: var(--green-soft); background: var(--surface); }
.action.primary { background: var(--green); border-color: var(--green); color: var(--bg); font-weight: 700; }
.action.primary::before { color: var(--bg); }
.action.primary:hover, .action.primary:focus-visible { background: var(--focus); border-color: var(--focus); }
.action.secondary { color: var(--text); }
.action.danger { color: var(--danger); }
.action:disabled { opacity: .48; cursor: not-allowed; }
.text-button { width: fit-content; border: 0; padding: 4px 0; background: transparent; color: var(--muted); cursor: pointer; text-decoration: underline; text-underline-offset: .22em; }
.text-button:hover, .text-button:focus-visible { color: var(--green); }

form { display: grid; gap: 15px; max-width: 540px; }
label { display: grid; gap: 6px; color: var(--muted); font-size: .88rem; }
input, textarea, select { width: 100%; border: 1px solid var(--line); border-radius: 0; background: var(--surface); color: var(--text); padding: 11px 12px; min-height: 45px; outline: none; font-size: 16px; }
textarea { min-height: 120px; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--focus); box-shadow: 0 0 0 1px var(--focus); }
input::placeholder, textarea::placeholder { color: #526b57; }
.checkbox { grid-template-columns: auto 1fr; align-items: start; gap: 10px; color: var(--text); }
.checkbox input { width: 18px; min-height: 18px; margin-top: 3px; }
.hint, .error { font-size: .85rem; }
.error { color: var(--danger); }
.notice { border-left: 2px solid var(--warn); padding: 10px 13px; background: #151307; color: #e9dcae; max-width: 62ch; }
.security-note { border-left-color: var(--green-soft); background: var(--surface); color: var(--text); }
.account-chip { width: fit-content; border: 1px solid var(--line); background: var(--surface); padding: 9px 12px; color: var(--green); }
.advanced { max-width: 540px; border-top: 1px solid var(--line); padding-top: 12px; color: var(--muted); }
.advanced summary { cursor: pointer; color: var(--muted); }
.advanced[open] summary { margin-bottom: 12px; color: var(--text); }

.status-line { display: flex; flex-wrap: wrap; gap: 10px 22px; color: var(--muted); font-size: .88rem; }
.status-line strong { color: var(--text); font-weight: 500; }
.status-active { color: var(--green) !important; }
.status-pending { color: var(--warn) !important; }

.chat-log { display: grid; align-content: start; gap: 20px; padding: 10px 8px 18px 0; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-gutter: stable; }
.message { display: grid; gap: 3px; overflow-wrap: anywhere; }
.message-head { color: var(--muted); font-size: .82rem; }
.message-head .name { color: var(--green-soft); }
.message-body { white-space: pre-wrap; color: var(--text); }
.message-state { color: var(--muted); font-size: .75rem; }
.message.failed .message-state { color: var(--danger); }
.composer { position: static; background: var(--bg); padding-top: 8px; display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 9px; }
.composer textarea { min-height: 48px; max-height: 150px; }

.list { display: grid; border-top: 1px solid var(--line); }
.list-row { display: grid; gap: 4px; padding: 13px 0; border-bottom: 1px solid var(--line); min-width: 0; }
.list-row.compact { grid-template-columns: minmax(130px, 1fr) auto; align-items: center; gap: 12px; }
.member-name::before { content: "○ "; color: var(--muted); }
.member-name.online::before { content: "● "; color: var(--green); }
.fingerprint { color: var(--muted); font-size: .75rem; overflow-wrap: anywhere; }

.invite-box { border: 1px solid var(--line); padding: 12px; display: grid; gap: 10px; background: var(--surface); }
.invite-url { overflow-wrap: anywhere; user-select: all; color: var(--green); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); }
.stat { background: var(--bg); padding: 14px; }
.stat strong { display: block; color: var(--green); font-size: 1.4rem; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; min-width: 680px; font-size: .84rem; }
th, td { text-align: left; padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--green); font-weight: 500; background: var(--surface); }

footer { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 20px; border-top: 1px solid var(--line); padding-top: 14px; font-size: .72rem; }
.toast { position: fixed; z-index: 20; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: calc(100vw - 30px); background: var(--surface-2); color: var(--text); border: 1px solid var(--green-soft); padding: 10px 14px; box-shadow: 0 8px 30px #0008; }
.support-project-button { justify-self: end; z-index: 15; border: 1px solid var(--warn); background: #151307; color: var(--warn); padding: 9px 12px; font: 700 .72rem/1.2 var(--mono); cursor: pointer; box-shadow: 0 6px 22px #0009; }
.support-project-dialog { width: min(92vw, 520px); border: 1px solid var(--green-soft); background: var(--bg); color: var(--text); padding: 0; }
.support-project-dialog::backdrop { background: #000c; }
.support-project-card { position: relative; max-width: none; padding: 24px; display: grid; gap: 16px; }
.dialog-close { position: absolute; top: 8px; right: 10px; border: 0; background: transparent; color: var(--muted); font: 1.5rem/1 var(--mono); cursor: pointer; }
.donation-card-number { border: 1px solid var(--line); background: var(--surface); color: var(--green); padding: 13px; font-size: clamp(1rem, 5vw, 1.25rem); letter-spacing: .06em; user-select: all; }
.notification-callout { border: 1px solid var(--line); background: var(--surface); padding: 12px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
.hidden { display: none !important; }

@media (max-width: 560px) {
  .shell { gap: 14px; }
  .nav { flex-wrap: nowrap; overflow-x: auto; gap: 18px; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .composer { grid-template-columns: 1fr; }
  .composer .action { width: 100%; justify-content: center; }
  footer { display: grid; }
  .support-project-button { width: 100%; justify-content: center; }
}

@media (prefers-reduced-motion: reduce) { .view { animation: none; } }
