:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-2: #f0f3f9;
  --text: #111827;
  --muted: #687386;
  --line: #e4e8f0;
  --accent: #645cff;
  --accent-2: #8b5cf6;
  --accent-soft: #eeedff;
  --success: #22c55e;
  --danger: #ef4444;
  --shadow: 0 18px 50px rgba(32, 41, 57, .10);
  --radius: 18px;
  color-scheme: light;
}

html[data-theme="dark"] {
  --bg: #0a0e18;
  --panel: #101625;
  --panel-2: #171e2f;
  --text: #edf1f8;
  --muted: #9aa5b7;
  --line: #222b3e;
  --accent: #8a7cff;
  --accent-2: #a96eff;
  --accent-soft: #211f46;
  --shadow: 0 18px 50px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { overflow: hidden; }
button, textarea, input { font: inherit; }
button { color: inherit; }
button:focus-visible, textarea:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 38%, transparent); outline-offset: 2px; }

.app-shell { height: 100dvh; display: grid; grid-template-columns: 280px minmax(0, 1fr); }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 14px; display: flex; flex-direction: column; min-height: 0; z-index: 30; }
.brand-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 2px 4px 16px; }
.brand { display: flex; gap: 10px; align-items: center; background: none; border: 0; cursor: pointer; text-align: left; padding: 0; }
.logo, .hero-logo { display: grid; place-items: center; color: #fff; font-weight: 850; letter-spacing: -.04em; background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 32%, transparent); }
.logo { width: 38px; height: 38px; border-radius: 12px; font-size: 13px; }
.brand strong { display: block; font-size: 15px; }
.brand small { display: block; color: var(--muted); margin-top: 2px; font-size: 11px; }
.icon-btn { border: 0; background: transparent; width: 38px; height: 38px; border-radius: 11px; cursor: pointer; display: grid; place-items: center; font-size: 20px; }
.icon-btn:hover { background: var(--panel-2); }
.new-chat { border: 1px solid var(--line); background: var(--panel); border-radius: 13px; padding: 11px 12px; font-weight: 700; cursor: pointer; display: flex; gap: 9px; align-items: center; box-shadow: 0 6px 20px rgba(0,0,0,.03); }
.new-chat:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); background: var(--accent-soft); }
.sidebar-label { color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; margin: 22px 9px 8px; }
.chat-list { overflow: auto; display: flex; flex-direction: column; gap: 3px; min-height: 0; }
.chat-item { display: flex; align-items: center; border-radius: 11px; min-width: 0; }
.chat-item.active { background: var(--panel-2); }
.chat-open { flex: 1; border: 0; background: transparent; cursor: pointer; padding: 9px 10px; text-align: left; color: var(--text); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 13px; }
.chat-delete { opacity: 0; width: 30px; height: 30px; border: 0; background: transparent; color: var(--muted); cursor: pointer; border-radius: 8px; }
.chat-item:hover .chat-delete { opacity: 1; }
.chat-delete:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.sidebar-footer { margin-top: auto; border-top: 1px solid var(--line); padding-top: 10px; display: grid; gap: 3px; }
.side-action { border: 0; background: transparent; border-radius: 10px; padding: 9px 10px; cursor: pointer; text-align: left; color: var(--muted); display: flex; align-items: center; gap: 10px; font-size: 13px; }
.side-action:hover { background: var(--panel-2); color: var(--text); }
.connection { font-size: 11px; color: var(--muted); display: flex; gap: 8px; align-items: center; padding: 10px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #94a3b8; }
.status-dot.online { background: var(--success); box-shadow: 0 0 0 4px color-mix(in srgb, var(--success) 12%, transparent); }
.status-dot.offline { background: var(--danger); }

.main { min-width: 0; height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; position: relative; }
.topbar { height: 64px; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(16px); display: flex; align-items: center; padding: 0 18px; gap: 10px; z-index: 10; }
.top-title { min-width: 0; flex: 1; }
.top-title strong { font-size: 14px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-title span { font-size: 10px; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 5px; }
.web-toggle { height: 34px; padding: 0 11px; border: 1px solid var(--line); background: var(--panel); border-radius: 999px; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; cursor: pointer; font-size: 12px; font-weight: 700; }
.web-toggle[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); }

.conversation { overflow-y: auto; overscroll-behavior: contain; }
.welcome { width: min(900px, 100%); min-height: 100%; margin: 0 auto; padding: 9vh 28px 50px; display: flex; flex-direction: column; align-items: center; text-align: center; }
.hero-logo { width: 66px; height: 66px; border-radius: 21px; font-size: 22px; margin-bottom: 22px; }
.eyebrow { color: var(--accent); font-size: 11px; letter-spacing: .18em; font-weight: 900; }
.welcome h1 { margin: 9px 0 10px; font-size: clamp(28px, 4vw, 46px); letter-spacing: -.045em; line-height: 1.05; }
.welcome > p { max-width: 620px; margin: 0; color: var(--muted); line-height: 1.65; font-size: 14px; }
.suggestions { margin-top: 34px; width: min(720px, 100%); display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.suggestion { border: 1px solid var(--line); background: var(--panel); text-align: left; padding: 16px; border-radius: 15px; cursor: pointer; box-shadow: 0 5px 18px rgba(0,0,0,.025); display: grid; grid-template-columns: 28px 1fr; grid-template-rows: auto auto; column-gap: 9px; }
.suggestion span { grid-row: span 2; color: var(--accent); font-weight: 900; padding-top: 2px; }
.suggestion b { font-size: 13px; }
.suggestion small { color: var(--muted); margin-top: 4px; }
.suggestion:hover { transform: translateY(-1px); border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); box-shadow: var(--shadow); }
.messages { display: none; width: min(850px, 100%); margin: 0 auto; padding: 30px 24px 50px; }
.messages.active { display: block; }
.message { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 12px; margin-bottom: 26px; }
.message-avatar { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; font-size: 11px; font-weight: 850; border: 1px solid var(--line); background: var(--panel); }
.message.assistant .message-avatar { color: #fff; border: 0; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }
.message-name { font-size: 12px; font-weight: 800; margin-bottom: 7px; }
.message-body { line-height: 1.72; font-size: 14px; word-break: break-word; }
.message-body p { margin: 0 0 12px; }
.message-body p:last-child { margin-bottom: 0; }
.message-body pre { background: #0b1020; color: #e8edf7; padding: 14px; border-radius: 13px; overflow-x: auto; border: 1px solid rgba(255,255,255,.08); }
.message-body code { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; font-size: .9em; }
.message-body :not(pre) > code { background: var(--panel-2); padding: 2px 5px; border-radius: 5px; }
.message-image { max-width: min(360px, 100%); max-height: 280px; display: block; object-fit: cover; border-radius: 14px; border: 1px solid var(--line); margin: 0 0 10px; }
.message-actions { display: flex; gap: 5px; margin-top: 9px; }
.mini-action { border: 0; background: transparent; color: var(--muted); cursor: pointer; border-radius: 7px; padding: 5px 7px; font-size: 11px; }
.mini-action:hover { background: var(--panel-2); color: var(--text); }
.typing { display: inline-flex; gap: 5px; padding: 8px 0; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: bounce 1s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); opacity: .45; } 40% { transform: translateY(-5px); opacity: 1; } }

.composer-wrap { padding: 8px 22px max(13px, env(safe-area-inset-bottom)); background: linear-gradient(180deg, transparent, var(--bg) 22%); }
.composer, .attachment-preview { width: min(820px, 100%); margin: 0 auto; }
.composer { min-height: 56px; border: 1px solid var(--line); background: var(--panel); border-radius: 18px; box-shadow: 0 12px 35px rgba(0,0,0,.07); display: flex; align-items: flex-end; padding: 8px; gap: 5px; }
.composer:focus-within { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); box-shadow: 0 14px 40px color-mix(in srgb, var(--accent) 10%, transparent); }
.composer textarea { flex: 1; min-height: 39px; max-height: 180px; resize: none; border: 0; outline: 0; background: transparent; color: var(--text); padding: 9px 7px; line-height: 1.5; }
.composer textarea::placeholder { color: var(--muted); }
.composer-btn, .send-btn { flex: 0 0 auto; width: 39px; height: 39px; border-radius: 12px; border: 0; display: grid; place-items: center; cursor: pointer; }
.composer-btn { background: transparent; color: var(--muted); font-size: 18px; }
.composer-btn:hover { background: var(--panel-2); color: var(--text); }
.composer-btn.listening { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.send-btn { background: var(--text); color: var(--panel); font-weight: 900; font-size: 18px; }
.send-btn:disabled { opacity: .35; cursor: not-allowed; }
.composer-note { text-align: center; color: var(--muted); font-size: 10px; margin-top: 7px; }
.attachment-preview { display: flex; gap: 10px; align-items: center; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; margin-bottom: 7px; padding: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.05); }
.attachment-preview[hidden] { display: none; }
.attachment-preview img { width: 45px; height: 45px; object-fit: cover; border-radius: 9px; }
.attachment-preview div { min-width: 0; flex: 1; }
.attachment-preview strong, .attachment-preview small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.attachment-preview strong { font-size: 12px; }
.attachment-preview small { font-size: 10px; color: var(--muted); margin-top: 3px; }
.toast { position: fixed; left: 50%; bottom: 92px; transform: translate(-50%, 16px); padding: 10px 13px; border-radius: 10px; background: var(--text); color: var(--panel); font-size: 12px; opacity: 0; pointer-events: none; transition: .2s ease; z-index: 100; box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.scrim { display: none; }
.mobile-only { display: none; }

@media (max-width: 760px) {
  body { overflow: hidden; }
  .app-shell { display: block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(86vw, 310px); transform: translateX(-105%); transition: transform .22s ease; box-shadow: var(--shadow); padding-top: max(18px, env(safe-area-inset-top)); }
  .sidebar.open { transform: translateX(0); }
  .scrim { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.42); opacity: 0; pointer-events: none; transition: opacity .22s; z-index: 20; }
  .scrim.open { opacity: 1; pointer-events: auto; }
  .mobile-only { display: grid; }
  .main { height: 100dvh; }
  .topbar { padding: max(6px, env(safe-area-inset-top)) 10px 0; height: calc(58px + env(safe-area-inset-top)); }
  .welcome { padding: 6vh 17px 35px; justify-content: flex-start; }
  .hero-logo { width: 58px; height: 58px; border-radius: 18px; }
  .suggestions { grid-template-columns: 1fr; margin-top: 26px; }
  .suggestion:nth-child(n+4) { display: none; }
  .messages { padding: 24px 15px 40px; }
  .message { grid-template-columns: 30px minmax(0, 1fr); gap: 10px; }
  .message-avatar { width: 30px; height: 30px; border-radius: 9px; }
  .composer-wrap { padding-left: 10px; padding-right: 10px; }
  .composer { border-radius: 16px; }
  .web-text { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
