html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
.app { position: fixed; inset: 0 0 auto 0; display: flex; height: 100dvh; height: var(--app-h, 100dvh); background: var(--panel); }

.sidebar { width: 300px; border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; padding: 16px 12px calc(16px + env(safe-area-inset-bottom)); gap: 8px; background: var(--panel); }
.side-top { padding: 4px 8px 12px; }
.friend-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.friend { display: flex; gap: 12px; align-items: center; padding: 10px; border-radius: 14px; cursor: pointer; border: none; background: none; width: 100%; text-align: left; font: inherit; color: inherit; }
.friend:hover { background: var(--panel-2); }
.friend.active { background: var(--accent-soft); }
.friend .name { font-weight: 600; }
.friend .tagline { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.friend > div:last-child { min-width: 0; }
.create-btn { margin: 0 4px; }

.account { border-top: 1px solid var(--border); padding: 12px 6px 0; font-size: 14px; }
.account .meter { height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; margin: 6px 0 10px; }
.account .meter > div { height: 100%; background: var(--accent); }
.account .acts { display: flex; flex-wrap: wrap; gap: 6px; }
.account .who { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.account .who b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tier { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; padding: 2px 6px; border-radius: 6px; background: var(--panel-2); color: var(--muted); }
.tier.plus { background: var(--accent); color: var(--accent-text); }

.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.chat-header { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--panel); }
.chat-header .who { min-width: 0; }
.chat-header .name { font-weight: 700; }
.chat-header .tagline { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-actions { margin-left: auto; display: flex; gap: 6px; position: relative; }
.menu { position: absolute; right: 0; top: 40px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; z-index: 10; min-width: 180px; }
.menu button, .menu a { display: block; text-decoration: none; width: 100%; text-align: left; background: none; border: none; padding: 8px 10px; border-radius: 8px; font: inherit; color: var(--text); cursor: pointer; }
.menu button:hover, .menu a:hover { background: var(--panel-2); }
.back { display: none; background: none; border: none; font-size: 30px; line-height: 1; color: var(--text); cursor: pointer; padding: 0 4px; }


.messages { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 20px 16px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 72%; padding: 9px 14px; border-radius: 18px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; animation: pop 0.18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(4px); } }
.msg.user { align-self: flex-end; background: var(--bubble-user); color: var(--bubble-user-text); border-bottom-right-radius: 5px; }
.msg.model { align-self: flex-start; background: var(--bubble-bot); border-bottom-left-radius: 5px; }
.msg.typing::after { content: ""; display: inline-block; width: 28px; height: 8px; background: radial-gradient(circle, var(--muted) 3px, transparent 3.5px) 0 50% / 9px 8px repeat-x; animation: dots 1s infinite linear; vertical-align: middle; }
.msg.has-photo { padding: 4px 12px 9px; max-width: min(290px, 85%); }
.msg-photo { margin: 0 -8px 8px; }
.msg-photo img { display: block; width: min(260px, 100%); aspect-ratio: 3 / 4; object-fit: cover; border-radius: 14px; background: var(--border); }
.msg-photo figcaption { font-size: 10px; color: var(--muted); margin: 3px 6px 0; }
.choice { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.choice label { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 90px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; margin: 0; }
.choice label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { width: auto; margin: 0; }
@keyframes dots { 50% { opacity: 0.3; } }
.sys { align-self: center; max-width: 90%; font-size: 13px; color: var(--muted); text-align: center; padding: 6px 12px; }
.sys.error { color: var(--danger); }
.notice { align-self: center; max-width: 92%; font-size: 13px; background: var(--accent-soft); color: var(--text); border-radius: 12px; padding: 8px 12px; text-align: center; }
.crisis { align-self: stretch; background: var(--warn-bg); color: var(--warn-text); border-radius: 14px; padding: 14px 16px; font-size: 14px; }
.crisis b { display: block; margin-bottom: 6px; font-size: 15px; }
.crisis ul { margin: 8px 0 0; padding-left: 18px; }
.crisis a { color: inherit; font-weight: 600; }
.day { align-self: center; font-size: 12px; color: var(--muted); margin: 8px 0; }

.composer { flex-shrink: 0; display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); background: var(--panel); }
.composer textarea { flex: 1; resize: none; border-radius: 22px; padding: 10px 16px; max-height: 140px; background: var(--bg); }
.composer .btn { border-radius: 50%; width: 44px; height: 44px; padding: 0; flex-shrink: 0; align-self: flex-end; }
.usage { font-size: 12px; color: var(--muted); text-align: center; padding: 0 12px calc(8px + env(safe-area-inset-bottom)); background: var(--panel); min-height: 8px; }
.usage a { cursor: pointer; }

.memory-notes { background: var(--panel-2); border-radius: 12px; padding: 12px 14px; white-space: pre-wrap; font-size: 14px; }

@media (max-width: 760px) {
  .app { border: none; }
  .sidebar { width: 100%; border-right: none; }
  .chat { display: none; }
  .app.in-chat .sidebar { display: none; }
  .app.in-chat .chat { display: flex; }
  .back { display: block; }
  .msg { max-width: 85%; }
  #memoryBtn .lbl { display: none; }
}

/* Notifications */
.side-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.bell { position: relative; }
.bell[hidden] { display: none; }
.bell-count { position: absolute; top: -6px; right: -6px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }
.push-row { background: var(--panel-2); border-radius: 12px; padding: 10px 12px; font-size: 14px; display: flex; gap: 10px; align-items: center; justify-content: space-between; margin: 8px 0 12px; }
.push-row:empty { display: none; }
.push-row .btn { flex-shrink: 0; }
.notif-list { list-style: none; margin: 0; padding: 0; }
.notif-list li { padding: 10px 4px; border-bottom: 1px solid var(--border); }
.notif-list li:last-child { border-bottom: none; }
.notif-list li.unread b::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 6px; vertical-align: middle; }
.notif-list p { margin: 2px 0 0; font-size: 14px; }
.notif-list a { text-decoration: none; color: inherit; display: block; }
.notif-list .when { font-size: 12px; color: var(--muted); }
.toasts { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 70; display: flex; flex-direction: column; gap: 8px; width: min(420px, calc(100% - 32px)); pointer-events: none; }
.toast { pointer-events: auto; background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 12px; box-shadow: var(--shadow); padding: 10px 14px; font-size: 14px; cursor: pointer; animation: pop 0.18s ease-out; }
.toast b { display: block; }
