:root {
  --navy: #07152f;
  --navy-soft: #10264b;
  --gold: #e8bd64;
  --gold-soft: #fff4d8;
  --cyan: #46c9e8;
  --bg: var(--tg-theme-bg-color, #f4f6fa);
  --surface: var(--tg-theme-secondary-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #101828);
  --muted: var(--tg-theme-hint-color, #667085);
  --border: color-mix(in srgb, var(--muted) 22%, transparent);
  --button: var(--tg-theme-button-color, var(--navy));
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  font-synthesis: none;
}
* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); }
button, textarea, input { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
.app-shell { width: 100%; max-width: 440px; min-height: 100vh; margin: 0 auto; padding: max(16px, env(safe-area-inset-top)) 16px calc(84px + env(safe-area-inset-bottom)); }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 22px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand > div { display: grid; gap: 2px; }
.brand span, .eyebrow, .muted { color: var(--muted); font-size: 13px; }
.avatar { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; box-shadow: 0 6px 20px color-mix(in srgb, var(--navy) 20%, transparent); }
.icon-button { width: 40px; height: 40px; border: 0; border-radius: 14px; background: var(--surface); color: var(--text); font-size: 22px; }
.view { display: grid; gap: 18px; }
h1, h2, p { margin: 0; }
h1 { font-size: 26px; line-height: 1.15; font-weight: 700; letter-spacing: -.02em; }
h2 { font-size: 18px; font-weight: 700; }
.hero { display: grid; gap: 8px; }
.hero p, .auth-view p { color: var(--muted); line-height: 1.5; }
.quick-actions { display: grid; grid-template-columns: 1.4fr 1fr; gap: 9px; }
.button { min-height: 44px; border: 1px solid var(--border); border-radius: 14px; padding: 10px 14px; background: var(--surface); color: var(--text); font-weight: 650; }
.button:active, .mode-button:active { transform: scale(.985); }
.button.primary { border-color: transparent; background: linear-gradient(135deg, var(--button), var(--navy-soft)); color: var(--button-text); box-shadow: 0 8px 22px color-mix(in srgb, var(--navy) 18%, transparent); }
.button.full { width: 100%; }
.card { border: 1px solid var(--border); border-radius: 18px; padding: 15px; background: var(--surface); box-shadow: 0 7px 24px color-mix(in srgb, var(--navy) 6%, transparent); }
.session-card { display: grid; gap: 9px; }
.card-top, .section-heading, .chat-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; }
.badge { display: inline-flex; align-items: center; width: fit-content; padding: 5px 9px; border-radius: 999px; background: color-mix(in srgb, var(--gold) 20%, var(--surface)); color: var(--text); font-size: 12px; font-weight: 650; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mode-list { display: grid; gap: 9px; }
.mode-button { width: 100%; display: grid; grid-template-columns: 34px 1fr 14px; align-items: center; gap: 10px; text-align: left; border: 1px solid var(--border); border-radius: 16px; padding: 12px; background: var(--surface); color: var(--text); }
.mode-button.selected { border-color: var(--gold); background: color-mix(in srgb, var(--gold) 11%, var(--surface)); }
.mode-button > span:nth-child(2) { display: grid; gap: 3px; }
.mode-button small { color: var(--muted); font-size: 12px; }
.mode-icon { font-size: 21px; }
.context-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.messages { display: grid; gap: 12px; }
.message { display: grid; gap: 6px; border-radius: 18px; padding: 13px 14px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.user { margin-left: 32px; background: color-mix(in srgb, var(--cyan) 14%, var(--surface)); }
.message.assistant { margin-right: 18px; background: var(--surface); border: 1px solid var(--border); }
.message-meta { color: var(--muted); font-size: 12px; font-weight: 650; }
.thinking { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 13px; }
.thinking span { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); animation: pulse 1.2s infinite ease-in-out; }
.thinking span:nth-child(2) { animation-delay: .15s; }.thinking span:nth-child(3) { animation-delay: .3s; }.thinking b { margin-left: 5px; }
@keyframes pulse { 0%, 70%, 100% { opacity: .25; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-3px); } }
.composer { display: grid; gap: 8px; }
.composer label, .upload-card label { font-size: 13px; font-weight: 650; }
.composer textarea { width: 100%; resize: vertical; min-height: 92px; border: 1px solid var(--border); border-radius: 16px; padding: 12px; background: var(--surface); color: var(--text); outline: none; }
.composer textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 20%, transparent); }
.composer > div { display: flex; justify-content: space-between; gap: 8px; }
.history-list { display: grid; gap: 10px; }
.history-card { display: grid; gap: 9px; }
.history-meta { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; }
.upload-card { display: grid; gap: 12px; }
.upload-card label { display: grid; gap: 4px; }
input[type=file] { width: 100%; color: var(--muted); }
.document-list, .memory-list { padding-block: 6px; }
.list-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; padding: 11px 4px; border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: 0; }
.list-row > div { display: grid; gap: 3px; }
.list-row button { flex: 0 0 auto; border: 0; background: transparent; color: var(--muted); }
.empty { text-align: center; padding: 30px 12px; color: var(--muted); }
.auth-view { justify-items: center; text-align: center; padding-top: 48px; }
.auth-avatar { width: 112px; height: 112px; border-radius: 50%; object-fit: cover; }
.toast { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%); width: min(360px, calc(100% - 32px)); padding: 12px 14px; border-radius: 14px; background: var(--navy); color: #fff; text-align: center; z-index: 5; }
.bottom-nav { position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); width: min(440px, 100%); display: grid; grid-template-columns: repeat(4, 1fr); gap: 2px; padding: 8px 12px max(8px, env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(18px); z-index: 4; }
.bottom-nav button { display: grid; justify-items: center; gap: 2px; border: 0; border-radius: 12px; padding: 6px 2px; background: transparent; color: var(--muted); }
.bottom-nav button.selected { color: var(--text); background: color-mix(in srgb, var(--gold) 16%, transparent); }
.bottom-nav span { font-size: 19px; }.bottom-nav small { font-size: 11px; }
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; animation: none !important; transition: none !important; } }
@media (max-width: 350px) { .quick-actions { grid-template-columns: 1fr; } .app-shell { padding-inline: 12px; } }
