:root {
  --green: #86df68;
  --green-dark: #38a95a;
  --chat-bg: #edf0ee;
  --rail: #29312f;
  --ink: #1c2421;
  --muted: #7c8581;
  --line: #dce1de;
  --panel: #fff;
  --danger: #ad5151;
  --shadow: 0 10px 35px rgba(21, 38, 30, .07);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; color: var(--ink); background: #d9dedb; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
img { display: block; }
h1, h2, h3, p { margin-top: 0; }
.app-shell { width: min(1420px, 100%); min-height: 100vh; margin: auto; display: grid; grid-template-columns: 74px 280px minmax(0,1fr); background: var(--chat-bg); box-shadow: 0 0 40px rgba(0,0,0,.14); }
.main-stage { min-width: 0; }
.view { display: none; min-height: 100vh; }
.view.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: .45; } }

.side-rail { position: sticky; top: 0; z-index: 20; height: 100vh; padding: 22px 10px 16px; display: flex; flex-direction: column; align-items: center; background: var(--rail); }
.side-rail nav { width: 100%; display: grid; gap: 18px; margin-top: 35px; }
.nav-item { border: 0; background: transparent; color: #98a19d; text-align: center; }
.nav-item:hover, .nav-item.active { color: var(--green); }
.nav-icon { display: block; font-size: 1.7rem; line-height: 1; }
.nav-item small { display: block; margin-top: 5px; font-size: .65rem; }
.mini-avatar { position: relative; width: 42px; height: 42px; padding: 0; border-radius: 8px; overflow: hidden; }
.mini-avatar small { display: none; }
.logout-form { margin-top: auto; }
.logout-form button { border: 0; color: #a5aaa8; background: transparent; font-size: 1.35rem; }
.contact-avatar { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; }
.contact-avatar.ready { opacity: 1; }
.avatar-fallback { width: 100%; height: 100%; display: grid; place-items: center; color: #fff; background: linear-gradient(145deg,#b6a49c,#776a65); font-weight: 650; }
.primary, .send-button { border: 0; border-radius: 6px; padding: 9px 14px; color: #fff; background: var(--green-dark); font-weight: 600; }
.primary:disabled, .send-button:disabled { opacity: .5; cursor: wait; }
.secondary { border: 1px solid #cad1cd; border-radius: 6px; padding: 8px 13px; color: #555; background: #fff; }
.panel { border: 1px solid #e0e5e2; border-radius: 9px; background: #fff; box-shadow: var(--shadow); }
.empty { width: 100%; padding: 50px 15px; color: #9aa09d; text-align: center; }
.empty.compact { padding: 24px 12px; font-size: .78rem; }

.contacts-pane { position: sticky; top: 0; z-index: 10; height: 100vh; min-width: 0; display: grid; grid-template-rows: auto auto 1fr auto; border-right: 1px solid #d5dbd7; background: #f7f9f8; overflow: hidden; }
.mobile-logout-form { display: none; }
.contacts-header { min-height: 78px; padding: 18px 16px 10px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.contacts-header h1 { margin: 0; font-size: 1.15rem; }
.contacts-header p { margin: 3px 0 0; color: var(--muted); font-size: .68rem; }
.contact-add { width: 34px; height: 34px; border: 0; border-radius: 7px; color: #36423c; background: #e5eae7; font-size: 1.25rem; }
.contact-add:hover { background: #dce4df; }
.contact-search { margin: 0 12px 10px; display: flex; align-items: center; gap: 6px; border-radius: 7px; padding: 0 9px; color: #8a938e; background: #e9eeeb; }
.contact-search input { width: 100%; min-width: 0; border: 0; padding: 8px 0; outline: 0; background: transparent; font-size: .78rem; }
.contact-list { min-height: 0; overflow-y: auto; }
.contact-item { width: 100%; min-height: 70px; border: 0; border-left: 3px solid transparent; padding: 10px 12px 10px 13px; display: grid; grid-template-columns: 46px minmax(0,1fr) auto; gap: 10px; align-items: center; color: var(--ink); background: transparent; text-align: left; }
.contact-item:hover { background: #eef2ef; }
.contact-item.active { border-left-color: var(--green-dark); background: #e2e8e4; }
.contact-list-avatar { position: relative; width: 46px; height: 46px; overflow: hidden; border-radius: 8px; }
.contact-copy { min-width: 0; }
.contact-copy strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.contact-copy small { margin-top: 5px; display: flex; gap: 7px; align-items: center; overflow: hidden; color: #89918d; white-space: nowrap; font-size: .65rem; }
.contact-copy em { flex: 0 0 auto; border-radius: 9px; padding: 2px 5px; color: #65716b; background: #fff; font-style: normal; }
.primary-contact-badge { align-self: start; border-radius: 8px; padding: 2px 5px; color: #39784b; background: #e7f5e9; font-size: .58rem; }
.contacts-footnote { padding: 10px 14px 14px; color: #98a09c; font-size: .62rem; line-height: 1.45; text-align: center; }
.mobile-contacts-back { display: none; border: 0; padding: 8px 8px 8px 0; color: #4b5550; background: transparent; font-size: 1.7rem; }
.mobile-section-contacts { display: none; }

.chat-view { height: 100vh; grid-template-rows: 64px auto 1fr auto; overflow: hidden; }
.chat-view.active { display: grid; }
.chat-header { height: 64px; padding: 0 22px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid #d4dad6; background: rgba(239,242,240,.95); }
.header-title { display: flex; gap: 12px; align-items: baseline; }
.chat-header h1 { margin: 0; font-size: 1rem; font-weight: 650; }
.private-state { color: var(--muted); font-size: .72rem; }
.private-state i { display: inline-block; width: 6px; height: 6px; margin-right: 4px; border-radius: 50%; background: #5fb974; }
.plain-icon { border: 0; padding: 10px; background: transparent; font-size: 1.35rem; letter-spacing: 2px; }
.truth-banner { margin: 10px auto 0; max-width: calc(100% - 30px); padding: 8px 12px; display: flex; gap: 16px; justify-content: center; align-items: center; border-radius: 7px; color: #736d65; background: #e8e2da; font-size: .72rem; }
.truth-banner button { border: 0; color: #847b6d; background: transparent; }
.chat-scroll { min-height: 0; padding: 18px 24px 30px; overflow-y: auto; }
.chat-day { width: max-content; margin: 2px auto 20px; padding: 3px 8px; border-radius: 5px; color: #fff; background: #bbc2be; font-size: .68rem; }
.chat-row { width: 100%; margin-bottom: 20px; display: flex; gap: 10px; align-items: flex-start; }
.chat-row.user { flex-direction: row-reverse; }
.message-avatar { position: relative; flex: 0 0 38px; width: 38px; height: 38px; border-radius: 8px; overflow: hidden; }
.chat-row.user .message-avatar { display: none; }
.message-body { max-width: min(68%, 620px); }
.chat-bubble { position: relative; padding: 10px 12px; border: 1px solid #dbe0dd; border-radius: 7px; background: #fff; line-height: 1.58; white-space: pre-wrap; word-break: break-word; font-size: .92rem; }
.chat-row.assistant .chat-bubble:before { content: ""; position: absolute; left: -6px; top: 13px; width: 10px; height: 10px; border-left: 1px solid #dbe0dd; border-bottom: 1px solid #dbe0dd; background: #fff; transform: rotate(45deg); }
.chat-row.user .chat-bubble { background: var(--green); border-color: #77d45c; }
.chat-row.user .chat-bubble:after { content: ""; position: absolute; right: -6px; top: 13px; width: 10px; height: 10px; border-right: 1px solid #70cd56; border-top: 1px solid #70cd56; background: var(--green); transform: rotate(45deg); }
.chat-image { max-width: min(320px, 62vw); max-height: 380px; border-radius: 6px; object-fit: cover; cursor: pointer; }
.chat-row.image .chat-bubble { padding: 3px; border: 0; background: transparent; }
.chat-row.image .chat-bubble:after { display: none; }
.voice-bubble { min-width: 180px; display: flex; align-items: center; gap: 10px; }
.voice-play { border: 0; padding: 0; background: transparent; font-size: 1.2rem; }
.voice-wave { flex: 1; height: 16px; background: repeating-linear-gradient(90deg,currentColor 0 2px,transparent 2px 5px); opacity: .4; mask-image: linear-gradient(to top,transparent,#000 40%,#000 60%,transparent); }
.transcript { display: block; margin-top: 7px; padding-top: 7px; border-top: 1px solid rgba(0,0,0,.08); color: #4c4c4c; font-size: .75rem; }
.synthetic-label { margin: 5px 2px 0; color: var(--muted); font-size: .65rem; }
.evidence { margin-top: 7px; color: #747d78; font-size: .68rem; }
.evidence summary { cursor: pointer; }
.evidence ol { margin: 7px 0 0; padding-left: 18px; }
.evidence li { margin: 6px 0; line-height: 1.45; }
.message-time { margin-top: 4px; color: #9ca39f; font-size: .62rem; }
.chat-row.user .message-time { text-align: right; }

.composer-wrap { border-top: 1px solid #d4dad6; background: #f8faf9; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.voice-reply-line { min-height: 28px; padding: 5px 18px 0; display: flex; align-items: center; gap: 7px; color: #707872; font-size: .68rem; }
.voice-reply-line small { margin-left: auto; color: #909793; }
.switch input { display: none; }
.switch span { position: relative; width: 28px; height: 16px; display: block; border-radius: 10px; background: #cbd0cd; transition: .15s; }
.switch span:after { content: ""; position: absolute; left: 2px; top: 2px; width: 12px; height: 12px; border-radius: 50%; background: #fff; transition: .15s; }
.switch input:checked + span { background: #4fbb68; }
.switch input:checked + span:after { transform: translateX(12px); }
.chat-composer { min-height: 58px; padding: 8px 14px; display: grid; grid-template-columns: 36px 36px 1fr auto; gap: 7px; align-items: end; }
.composer-icon { height: 36px; border: 0; padding: 0; color: #46504b; background: transparent; font-size: 1.55rem; }
.record-button.recording { color: #e04a4a; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .4; } }
.chat-composer textarea { width: 100%; min-height: 38px; max-height: 110px; resize: none; border: 1px solid #e0e5e2; border-radius: 7px; padding: 9px 10px; outline: 0; background: #fff; line-height: 1.4; }
.send-button { height: 38px; }
.recording-status { padding: 0 14px 7px; color: #c94747; text-align: center; font-size: .72rem; }
.recording-status span { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #e04a4a; }

.moments-view, .records-view, .settings-view { padding-bottom: 60px; background: #f5f7f6; }
.moments-cover { position: relative; height: clamp(210px, 38vw, 360px); overflow: hidden; background: radial-gradient(circle at 25% 20%,#8a918d,#37403c 65%); }
.cover-shade { position: absolute; inset: 0; background: linear-gradient(transparent 50%,rgba(0,0,0,.48)); }
.cover-identity { position: absolute; right: 35px; bottom: 18px; display: flex; gap: 14px; align-items: center; color: #fff; }
.cover-identity strong { text-shadow: 0 1px 4px #000; }
.large-avatar { position: relative; width: 78px; height: 78px; border: 3px solid #fff; border-radius: 8px; overflow: hidden; box-shadow: 0 3px 12px rgba(0,0,0,.25); }
.moment-toolbar { max-width: 820px; margin: 26px auto 16px; padding: 0 18px; display: flex; justify-content: space-between; align-items: end; gap: 20px; }
.moment-toolbar h2 { margin-bottom: 4px; font-size: 1.2rem; }
.moment-toolbar p, .section-header p { margin-bottom: 0; color: var(--muted); font-size: .8rem; }
.moment-form { max-width: 820px; margin: 0 auto 16px; padding: 18px; }
.moment-form textarea { width: 100%; border: 0; border-bottom: 1px solid var(--line); padding: 8px 0; resize: vertical; outline: 0; }
.form-grid { margin: 12px 0; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
label { color: #66706a; font-size: .78rem; }
input, textarea { font-size: .9rem; }
label input, label textarea, label select, .browser-panel > input { width: 100%; margin-top: 5px; border: 1px solid var(--line); border-radius: 6px; padding: 9px 10px; outline: 0; background: #fff; }
input:focus, textarea:focus, select:focus { border-color: #76c98a; box-shadow: 0 0 0 2px rgba(38,168,91,.08); }
.moment-file { display: block; padding: 15px; border: 1px dashed #aeb8b2; border-radius: 6px; text-align: center; background: #fafcfb; }
.moment-file input { border: 0; width: auto; }
.form-actions { margin-top: 14px; display: flex; justify-content: flex-end; gap: 8px; }
.moment-feed { max-width: 820px; margin: auto; padding: 0 18px; }
.moment-card { padding: 20px 0; display: grid; grid-template-columns: 48px 1fr; gap: 12px; border-bottom: 1px solid #dce2de; }
.moment-avatar { position: relative; width: 48px; height: 48px; overflow: hidden; border-radius: 7px; }
.moment-content h3 { margin: 0 0 8px; color: #506d8b; font-size: .92rem; }
.moment-text { margin-bottom: 10px; line-height: 1.55; white-space: pre-wrap; }
.moment-images { display: grid; grid-template-columns: repeat(3, minmax(0, 150px)); gap: 4px; max-width: 460px; }
.moment-images.one { grid-template-columns: minmax(0, 300px); }
.moment-images a { aspect-ratio: 1; overflow: hidden; background: #d9dedb; }
.moment-images.one a { aspect-ratio: auto; max-height: 380px; }
.moment-images img { width: 100%; height: 100%; object-fit: cover; }
.moment-meta { margin-top: 9px; display: flex; gap: 12px; color: #949c98; font-size: .68rem; }
.moment-location { color: #506d8b; }

.section-header { min-height: 105px; padding: 26px clamp(18px,4vw,46px) 18px; display: flex; justify-content: space-between; align-items: end; border-bottom: 1px solid var(--line); background: #fff; }
.section-header h2 { margin-bottom: 5px; font-size: 1.3rem; }
.section-header > span { color: var(--muted); font-size: .75rem; }
.records-grid, .settings-grid { max-width: 1040px; margin: 22px auto; padding: 0 18px; display: grid; grid-template-columns: 330px 1fr; gap: 16px; }
.records-grid .panel, .settings-grid .panel { padding: 20px; }
.panel h3 { margin-bottom: 8px; font-size: 1rem; }
.panel > p { color: var(--muted); font-size: .78rem; line-height: 1.6; }
.file-drop { min-height: 145px; margin: 15px 0 10px; display: grid; place-items: center; align-content: center; gap: 5px; border: 1px dashed #aeb8b2; border-radius: 7px; background: #fafcfb; text-align: center; }
.file-drop span { font-size: 1.8rem; color: #6f7c75; }
.file-drop small { color: #9aa29e; }
.full { width: 100%; }
.success-box { margin-top: 10px; padding: 9px; border-radius: 6px; color: #347643; background: #edf8ee; font-size: .75rem; }
.speaker-list { margin-top: 12px; display: flex; flex-wrap: wrap; gap: 5px; }
.speaker-list span { padding: 3px 7px; border-radius: 10px; color: #68716d; background: #e9eeeb; font-size: .65rem; }
.browser-panel { min-width: 0; }
.memory-list { max-height: calc(100vh - 220px); margin-top: 10px; overflow-y: auto; }
.memory-item { padding: 11px 2px; border-bottom: 1px solid #edf0ee; }
.memory-meta { display: flex; gap: 10px; color: #949c98; font-size: .68rem; }
.memory-meta strong { color: #506d8b; }
.memory-item p { margin: 5px 0 0; line-height: 1.55; white-space: pre-wrap; font-size: .86rem; }

.settings-grid { grid-template-columns: 1.15fr .85fr; }
.settings-column { display: grid; align-content: start; gap: 16px; }
.avatar-form { margin: 12px 0 22px; display: grid; grid-template-columns: 72px 1fr 1fr; gap: 8px; align-items: center; }
.settings-avatar { position: relative; width: 64px; height: 64px; border-radius: 8px; overflow: hidden; }
.file-button { text-align: center; }
.stack-form { display: grid; gap: 12px; }
.consent-check { display: flex; gap: 8px; align-items: flex-start; line-height: 1.45; }
.consent-check input { width: auto; margin: 3px 0 0; }
.config-status, .model-state { margin-top: 12px; padding: 7px 9px; border-radius: 6px; color: #7c8581; background: #f0f3f1; font-size: .72rem; }
.config-status.ready, .model-state.ready { color: #347643; background: #edf8ee; }
.model-panel dl { margin: 14px 0 0; }
.model-panel dl div { padding: 8px 0; display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid #edf0ee; }
.model-panel dt { color: #6f7974; font-size: .75rem; }
.model-panel dd { margin: 0; font-family: ui-monospace, monospace; font-size: .7rem; }
.boundary-panel ul { margin: 12px 0 0; padding-left: 18px; color: #66706a; font-size: .76rem; line-height: 1.6; }
.secure-label { color: #489356 !important; }

dialog { width: min(440px, calc(100% - 30px)); max-height: calc(100dvh - 30px); overflow-y: auto; border: 0; border-radius: 10px; padding: 28px; box-shadow: 0 20px 80px rgba(0,0,0,.25); line-height: 1.65; }
dialog::backdrop { background: rgba(0,0,0,.38); }
.dialog-close { position: absolute; right: 10px; top: 8px; border: 0; background: transparent; font-size: 1.4rem; }
dialog > p { color: var(--muted); font-size: .78rem; }
.toast { position: fixed; z-index: 100; left: 50%; bottom: 30px; max-width: min(400px,calc(100% - 30px)); padding: 10px 15px; border-radius: 7px; color: #fff; background: rgba(30,40,35,.92); opacity: 0; transform: translate(-50%,10px); pointer-events: none; transition: .18s; }
.toast.show { opacity: 1; transform: translate(-50%,0); }
.toast.error { background: rgba(150,55,55,.95); }

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: #edf0ee; }
.login-card { width: min(400px,100%); padding: 38px 34px; border-radius: 12px; background: #fff; box-shadow: var(--shadow); text-align: center; }
.login-card .mark { width: 58px; height: 58px; margin: auto; display: grid; place-items: center; border-radius: 12px; color: #fff; background: var(--green-dark); font-size: 1.5rem; }
.login-card .eyebrow { margin: 18px 0 5px; color: #87918c; font-size: .62rem; letter-spacing: .18em; }
.login-card h1 { margin-bottom: 8px; font-size: 1.5rem; }
.muted, .privacy-note { color: #7c8581; line-height: 1.55; }
.login-form { margin-top: 22px; display: grid; gap: 8px; text-align: left; }
.login-form input { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 11px; }
.wide { width: 100%; }
.privacy-note { margin: 18px 0 0; font-size: .68rem; }
.form-error:empty { display: none; }
.form-error { padding: 7px; color: var(--danger); background: #fff0f0; font-size: .75rem; }

@media (max-width: 980px) and (min-width: 721px) {
  .app-shell { grid-template-columns: 70px 220px minmax(0,1fr); }
  .contacts-header { padding-left: 12px; padding-right: 12px; }
  .contact-item { padding-left: 9px; padding-right: 9px; grid-template-columns: 42px minmax(0,1fr); }
  .contact-list-avatar { width: 42px; height: 42px; }
  .primary-contact-badge { display: none; }
}

@media (max-width: 720px) {
  .app-shell { display: block; min-height: 100dvh; }
  .contacts-pane { position: fixed; inset: 0 0 calc(60px + env(safe-area-inset-bottom)) 0; z-index: 18; width: 100%; height: auto; display: none; border-right: 0; background: #f7f9f8; }
  .app-shell.mobile-contact-mode .contacts-pane { display: grid; }
  .app-shell.mobile-contact-mode .main-stage { display: none; }
  .app-shell.mobile-contact-mode .side-rail { display: none; }
  .app-shell.mobile-contact-mode .contacts-pane { bottom: 0; grid-template-rows: auto auto 1fr auto auto; }
  .contacts-header { min-height: 72px; padding-top: max(17px, env(safe-area-inset-top)); }
  .contact-item { min-height: 72px; padding-left: 16px; padding-right: 16px; }
  .contacts-footnote { padding-bottom: 16px; }
  .contact-add { min-width: 44px; min-height: 44px; }
  .mobile-logout-form { display: block; padding: 0 14px max(14px, env(safe-area-inset-bottom)); text-align: center; }
  .mobile-logout-form button { min-height: 44px; border: 0; color: #77817c; background: transparent; }
  .side-rail { position: fixed; top: auto; bottom: 0; width: 100%; height: calc(60px + env(safe-area-inset-bottom)); padding: 5px 8px env(safe-area-inset-bottom); flex-direction: row; background: rgba(250,252,251,.97); border-top: 1px solid #d8dedb; }
  .mini-avatar, .logout-form { display: none; }
  .side-rail nav { margin: 0; display: grid; grid-template-columns: repeat(4,1fr); gap: 0; }
  .nav-item { color: #66706a; }
  .nav-icon { font-size: 1.35rem; }
  .view { min-height: calc(100dvh - 60px); padding-bottom: 70px; }
  .chat-view { height: calc(100dvh - 60px); padding-bottom: 0; }
  .chat-header { height: 54px; padding: 0 13px; justify-content: flex-start; }
  .mobile-contacts-back { display: block; min-width: 40px; min-height: 44px; }
  .mobile-section-contacts { display: block; min-height: 44px; border: 0; color: #40514a; background: transparent; font-weight: 600; }
  .moments-cover > .mobile-section-contacts { position: absolute; z-index: 3; left: 10px; top: max(8px, env(safe-area-inset-top)); padding: 8px 10px; border-radius: 7px; color: #fff; background: rgba(20,28,24,.45); }
  .section-header > .mobile-section-contacts { align-self: center; margin-right: 8px; padding: 6px 4px 6px 0; }
  .chat-header .plain-icon { margin-left: auto; }
  .private-state { display: none; }
  .truth-banner { margin-top: 6px; }
  .chat-scroll { padding: 14px 10px 20px; }
  .message-body { max-width: 78%; }
  .chat-composer { grid-template-columns: 34px 34px 1fr auto; padding: 7px; gap: 3px; }
  .send-button { padding: 8px 10px; }
  .voice-reply-line { padding-left: 10px; padding-right: 10px; }
  .moments-cover { height: 230px; }
  .cover-identity { right: 16px; }
  .moment-toolbar { align-items: center; }
  .moment-toolbar p { display: none; }
  .moment-images { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .records-grid, .settings-grid { grid-template-columns: 1fr; margin-top: 14px; }
  .memory-list { max-height: none; }
  .section-header { min-height: 90px; padding: 20px 18px 14px; }
  .section-header p { max-width: 240px; }
  .form-grid { grid-template-columns: 1fr; }
  .avatar-form { grid-template-columns: 70px 1fr; }
  .avatar-form .primary { grid-column: 2; }
}
