:root {
  --bg: #0c0e0d;
  --panel: #111412;
  --panel-2: #171b18;
  --text: #f1f4ed;
  --muted: #8d968e;
  --line: #272d29;
  --line-strong: #394139;
  --accent: #a7f46a;
  --accent-ink: #0c1308;
  --danger: #ff8073;
  --note: #d7b7ff;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
  margin: 0;
  min-height: 100svh;
  overflow: hidden;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }

.app-frame {
  height: 100svh;
  display: grid;
  grid-template-rows: 48px minmax(0, 1fr) 34px;
}
.global-bar, .global-footer {
  padding: 0 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-color: var(--line);
  background: rgba(12, 14, 13, .96);
}
.global-bar { border-bottom: 1px solid var(--line); }
.global-footer { border-top: 1px solid var(--line); color: var(--muted); font: 600 .65rem/1 ui-monospace, Consolas, monospace; }
.global-footer button { padding: 0; border: 0; color: inherit; background: none; text-decoration: underline; text-underline-offset: 3px; }
.wordmark { color: var(--text); text-decoration: none; font: 800 .79rem/1 ui-monospace, Consolas, monospace; letter-spacing: .13em; }
.wordmark span { color: var(--accent); }
.network-state { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: .69rem; }
.network-dot, .presence-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.network-state.is-safe .network-dot, .presence-dot { background: var(--accent); box-shadow: 0 0 0 4px rgba(167,244,106,.07); }
.network-state.is-warning .network-dot { background: #ffd36a; }

.screen { min-height: 0; display: none; animation: screen-in 220ms cubic-bezier(.22,.8,.3,1) both; }
.screen.is-active { display: flex; }
.eyebrow { margin: 0 0 12px; color: var(--accent); font: 700 .66rem/1 ui-monospace, Consolas, monospace; letter-spacing: .15em; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 24px; font-size: clamp(3rem, 8vw, 6.8rem); line-height: .88; letter-spacing: -.073em; font-weight: 750; }
h2 { margin-bottom: 8px; font-size: 1.25rem; line-height: 1.1; letter-spacing: -.025em; }
.lede { max-width: 620px; color: var(--muted); font-size: clamp(.96rem, 2vw, 1.15rem); line-height: 1.55; }

#landing-screen { padding: clamp(30px, 7vw, 92px); align-items: flex-end; justify-content: space-between; gap: 40px; }
.landing-copy { max-width: 830px; }
.landing-actions { width: min(100%, 330px); }
.landing-actions p { margin: 14px 0 0; color: var(--muted); font-size: .74rem; line-height: 1.5; }
.button { min-height: 48px; padding: 0 15px; border-radius: 6px; display: flex; align-items: center; justify-content: space-between; border: 1px solid var(--line-strong); text-decoration: none; font-weight: 700; transition: transform 120ms ease, border-color 120ms ease, background 120ms ease; }
.button:active { transform: scale(.988); }
.button-primary { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.button-secondary { width: 100%; color: var(--text); background: var(--panel-2); }
.button:disabled { opacity: .42; cursor: not-allowed; }

.auth-screen { padding: clamp(28px, 7vw, 86px); align-items: center; justify-content: space-between; gap: 50px; overflow: auto; }
.auth-copy { max-width: 760px; }
.auth-panel { width: min(100%, 430px); padding: 26px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); }
.auth-panel h2 { margin-bottom: 22px; }
.auth-panel details { margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--line); }
.auth-panel summary { color: var(--muted); font-size: .8rem; font-weight: 700; }
.auth-panel details p { margin: 18px 0 0; color: var(--muted); font-size: .76rem; line-height: 1.5; }
label { display: block; margin: 17px 0 8px; color: var(--muted); font-size: .72rem; font-weight: 700; }
label span { font-weight: 500; }
textarea, input:not([type="checkbox"]) { width: 100%; border: 1px solid var(--line-strong); border-radius: 6px; outline: none; background: var(--panel-2); color: var(--text); }
textarea { padding: 12px; resize: none; line-height: 1.45; }
input:not([type="checkbox"]) { height: 46px; padding: 0 12px; }
textarea:focus, input:focus { border-color: var(--accent); }
.auth-panel textarea { font: .72rem/1.45 ui-monospace, Consolas, monospace; overflow-wrap: anywhere; }
.auth-panel .button { width: 100%; margin-top: 14px; justify-content: center; }

.recovery-screen { overflow: auto; align-items: center; justify-content: center; padding: 30px; }
.recovery-panel { width: min(100%, 620px); }
.recovery-panel h1 { font-size: clamp(3rem, 8vw, 5.6rem); }
.recovery-panel textarea { min-height: 126px; font: .72rem/1.5 ui-monospace, Consolas, monospace; overflow-wrap: anywhere; }
.recovery-panel .button { width: 100%; margin-top: 10px; justify-content: center; }
.confirm-row { display: flex; align-items: flex-start; gap: 9px; margin: 18px 0; color: var(--text); font-size: .78rem; }
.confirm-row input { margin: 2px 0 0; accent-color: var(--accent); }

.visitor-screen { width: min(100%, 880px); margin: 0 auto; flex-direction: column; border-inline: 1px solid var(--line); background: var(--panel); }
.conversation-bar { min-height: 64px; padding: 10px 16px; display: flex; align-items: center; gap: 11px; border-bottom: 1px solid var(--line); background: var(--panel); }
.conversation-bar h2 { margin: 0 0 5px; font-size: .91rem; }
.conversation-bar p { margin: 0; color: var(--muted); font-size: .66rem; }
.avatar { width: 34px; height: 34px; flex: 0 0 auto; display: grid; place-items: center; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-size: .77rem; font-weight: 850; }
.visitor-avatar { color: var(--text); background: var(--panel-2); border: 1px solid var(--line-strong); }
.icon-button { width: 32px; height: 32px; margin-left: auto; padding: 0; border: 1px solid var(--line); border-radius: 50%; background: transparent; color: var(--muted); }
.message-stream { flex: 1; min-height: 0; padding: 22px clamp(14px, 4vw, 34px); overflow-y: auto; scrollbar-color: var(--line-strong) transparent; }
.chat-intro { width: min(100%, 420px); margin: max(5vh, 20px) auto; text-align: center; }
.chat-intro label { text-align: left; }
.chat-intro p, .conversation-empty p { color: var(--muted); font-size: .8rem; line-height: 1.55; }
.lock-mark { display: grid; place-items: center; width: 45px; height: 45px; margin: 0 auto 18px; border: 1px solid var(--line-strong); border-radius: 50%; color: var(--accent); font-size: 1.25rem; }
.composer { min-height: 66px; padding: 10px 12px calc(10px + var(--safe-bottom)); display: grid; grid-template-columns: minmax(0,1fr) 42px; gap: 8px; align-items: end; border-top: 1px solid var(--line); background: var(--panel); }
.composer textarea { max-height: 126px; min-height: 42px; padding: 10px 12px; background: var(--bg); }
.send-button { width: 42px; height: 42px; padding: 0; border: 0; border-radius: 50%; color: var(--accent-ink); background: var(--accent); font-size: 1.25rem; font-weight: 800; }
.send-button:disabled { opacity: .4; }
.message-row { display: flex; margin: 5px 0; }
.message-row.is-own { justify-content: flex-end; }
.message-bubble { max-width: min(78%, 560px); padding: 9px 12px 7px; border: 1px solid var(--line); border-radius: 13px 13px 13px 3px; background: var(--panel-2); }
.is-own .message-bubble { border-color: rgba(167,244,106,.2); border-radius: 13px 13px 3px 13px; background: #1c2a17; }
.message-row.is-note { justify-content: center; }
.is-note .message-bubble { max-width: 88%; border-color: rgba(215,183,255,.23); border-radius: 7px; background: rgba(215,183,255,.07); color: #eadbff; }
.message-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .86rem; line-height: 1.48; }
.message-meta { margin: 5px 0 0; color: var(--muted); text-align: right; font: .58rem/1 ui-monospace, Consolas, monospace; }
.day-divider { margin: 18px 0 10px; color: var(--muted); text-align: center; font-size: .62rem; }

.workspace { min-height: 0; background: var(--panel); }
.inbox-panel { width: 330px; min-width: 280px; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--bg); }
.inbox-head { padding: 18px 16px 12px; display: flex; align-items: center; justify-content: space-between; }
.inbox-head .eyebrow { margin-bottom: 7px; }
.inbox-head h2 { margin: 0; font-size: 1.45rem; }
.count-badge { min-width: 24px; height: 24px; padding: 0 7px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 99px; color: var(--muted); font-size: .65rem; }
.manager-identity { margin: 0 10px 10px; padding: 11px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel); }
.manager-identity > span { display: block; color: var(--muted); font-size: .62rem; }
.manager-identity strong { display: block; margin: 5px 0 10px; overflow: hidden; text-overflow: ellipsis; font: 700 .72rem/1.2 ui-monospace, Consolas, monospace; }
.identity-actions { display: grid; grid-template-columns: 1fr auto; gap: 6px; }
.identity-actions button { min-height: 32px; border: 1px solid var(--line-strong); border-radius: 5px; background: transparent; color: var(--text); font-size: .65rem; font-weight: 700; }
.chat-list { flex: 1; min-height: 0; overflow-y: auto; }
.chat-list-item { width: 100%; padding: 12px 14px; display: grid; grid-template-columns: 35px minmax(0,1fr) auto; gap: 10px; align-items: center; border: 0; border-top: 1px solid var(--line); background: transparent; color: var(--text); text-align: left; }
.chat-list-item:last-child { border-bottom: 1px solid var(--line); }
.chat-list-item:hover, .chat-list-item.is-active { background: var(--panel-2); }
.chat-list-item .avatar { width: 35px; height: 35px; color: var(--text); background: var(--panel); border: 1px solid var(--line-strong); }
.chat-list-copy { min-width: 0; }
.chat-list-copy strong, .chat-list-copy span { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chat-list-copy strong { margin-bottom: 5px; font-size: .77rem; }
.chat-list-copy span, .chat-list-time { color: var(--muted); font-size: .61rem; }
.empty-list { padding: 34px 18px; color: var(--muted); text-align: center; font-size: .72rem; line-height: 1.6; }
.quiet-button { min-height: 42px; border: 0; border-top: 1px solid var(--line); background: transparent; color: var(--muted); font-size: .68rem; }
.manager-conversation { flex: 1; min-width: 0; min-height: 0; position: relative; }
.conversation-empty { position: absolute; inset: 0; display: grid; place-content: center; padding: 30px; text-align: center; }
.conversation-empty .lock-mark { margin-bottom: 18px; }
.conversation-active { height: 100%; display: flex; flex-direction: column; }
.manager-composer { grid-template-columns: auto minmax(0,1fr) 42px; }
.compose-mode { align-self: center; display: flex; gap: 3px; }
.compose-mode button { min-height: 30px; padding: 0 9px; border: 1px solid var(--line); border-radius: 5px; background: transparent; color: var(--muted); font-size: .62rem; }
.compose-mode button.is-active { border-color: var(--line-strong); background: var(--panel-2); color: var(--text); }
.mobile-back { display: none; margin-left: 0; }

dialog { width: min(calc(100% - 28px), 500px); padding: 0; border: 1px solid var(--line-strong); border-radius: 9px; background: var(--panel); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.78); backdrop-filter: blur(5px); }
.dialog-body { padding: 27px; }
.dialog-body h2 { font-size: 2rem; }
.dialog-body > p:not(.eyebrow) { color: var(--muted); font-size: .81rem; line-height: 1.6; }
.dialog-body .button { width: 100%; margin-top: 22px; justify-content: center; }
.toast { position: fixed; z-index: 10; left: 50%; bottom: calc(48px + var(--safe-bottom)); max-width: calc(100% - 32px); padding: 10px 14px; transform: translate(-50%, 12px); opacity: 0; pointer-events: none; border-radius: 6px; background: var(--text); color: var(--bg); font-size: .72rem; font-weight: 750; transition: opacity 150ms ease, transform 150ms ease; }
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }
.toast.is-error { background: var(--danger); }
.is-hidden { display: none !important; }

@keyframes screen-in { from { opacity: 0; transform: translateY(7px); } }
@media (max-width: 820px) {
  #landing-screen, .auth-screen { flex-direction: column; align-items: stretch; justify-content: center; }
  .landing-actions, .auth-panel { width: 100%; }
  .workspace.show-conversation .inbox-panel { display: none; }
  .workspace:not(.show-conversation) .manager-conversation { display: none; }
  .inbox-panel { width: 100%; border-right: 0; }
  .mobile-back { display: block; }
}
@media (max-width: 560px) {
  .app-frame { grid-template-rows: 44px minmax(0,1fr) 30px; }
  .global-bar { padding-inline: 13px; }
  .global-footer { padding-inline: 13px; }
  #landing-screen, .auth-screen, .recovery-screen { padding: 24px 18px; }
  h1 { font-size: clamp(3.1rem, 16vw, 4.8rem); }
  .visitor-screen { border-inline: 0; }
  .manager-composer { grid-template-columns: minmax(0,1fr) 42px; }
  .compose-mode { grid-column: 1 / -1; }
  .message-bubble { max-width: 88%; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
