:root {
  color-scheme: light;
  --bg: #f7f7f8;
  --surface: #fff;
  --sidebar: #f1f1f3;
  --text: #17181a;
  --muted: #6c7078;
  --line: #dedfe3;
  --accent: #202123;
  --blue: #246bfd;
  --danger: #c43d4b;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
* { box-sizing: border-box; }
html, body { width: 100%; max-width: 100%; margin: 0; min-height: 100%; overflow: hidden; background: var(--bg); color: var(--text); }
button, input, textarea { min-width: 0; font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }

.brand-mark { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 15px; background: linear-gradient(145deg, #111827, #354057); color: #fff; font-weight: 760; box-shadow: 0 9px 24px rgba(17, 24, 39, .18); }
.brand-mark.small { width: 34px; height: 34px; border-radius: 11px; font-size: 14px; }
.brand-mark.large { width: 58px; height: 58px; margin: 0 auto 18px; border-radius: 18px; font-size: 22px; }
.eyebrow { margin: 24px 0 8px; color: var(--blue); font-size: 12px; font-weight: 750; letter-spacing: .16em; }
h1 { margin: 0; font-size: 32px; line-height: 1.15; letter-spacing: -.04em; }
.muted { margin: 12px 0 0; color: var(--muted); line-height: 1.6; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 28px; background: radial-gradient(circle at 15% 10%, rgba(36,107,253,.10), transparent 35%), radial-gradient(circle at 90% 85%, rgba(125,83,255,.08), transparent 35%), var(--bg); }
.login-card { width: min(100%, 420px); padding: 46px 42px 42px; border: 1px solid rgba(226,229,233,.9); border-radius: 28px; background: rgba(255,255,255,.95); box-shadow: 0 24px 80px rgba(31,39,52,.11); }
.login-form { display: grid; gap: 18px; margin-top: 34px; }
.login-form label { display: grid; gap: 8px; color: #4c5360; font-size: 13px; font-weight: 650; }
input { width: 100%; height: 50px; padding: 0 15px; border: 1px solid var(--line); border-radius: 13px; outline: none; background: #fbfcfd; color: var(--text); }
input:focus { border-color: #8fb1fb; box-shadow: 0 0 0 4px rgba(36,107,253,.10); }
.form-error { min-height: 18px; margin: -5px 0 -3px; color: var(--danger); font-size: 13px; }
.primary { min-height: 46px; padding: 0 18px; border: 0; border-radius: 13px; background: var(--accent); color: #fff; cursor: pointer; font-weight: 680; box-shadow: 0 8px 20px rgba(17,24,39,.15); }
.primary.wide { width: 100%; }
.primary:disabled { opacity: .55; cursor: wait; }

.app-shell { width: 100%; max-width: 100%; height: 100vh; display: grid; grid-template-columns: 280px minmax(0, 1fr); overflow: hidden; }
.sidebar { min-width: 0; height: 100vh; display: grid; grid-template-rows: auto auto auto minmax(0,1fr) auto; padding: 14px 12px 12px; border-right: 1px solid #e1e1e4; background: var(--sidebar); }
.sidebar-head { min-height: 48px; display: flex; align-items: center; justify-content: space-between; padding: 0 7px 8px; }
.brand-button { display: flex; align-items: center; gap: 10px; padding: 0; border: 0; background: transparent; cursor: pointer; font-size: 14px; font-weight: 760; }
.new-chat-button { height: 44px; padding: 0 13px; display: flex; align-items: center; gap: 9px; border: 1px solid #d6d7dc; border-radius: 12px; background: #fff; cursor: pointer; text-align: left; font-weight: 650; }
.new-chat-button:hover { background: #fafafa; }
.sidebar-label { padding: 22px 10px 8px; color: #8a8e96; font-size: 11px; font-weight: 700; letter-spacing: .08em; }
.conversation-list { min-height: 0; overflow-y: auto; display: grid; align-content: start; gap: 3px; scrollbar-width: thin; }
.conversation-item { width: 100%; min-width: 0; padding: 10px 11px; display: grid; gap: 4px; border: 0; border-radius: 10px; background: transparent; cursor: pointer; text-align: left; }
.conversation-item:hover, .conversation-item.active { background: #e3e3e7; }
.conversation-item strong, .conversation-item small { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.conversation-item strong { font-size: 13px; font-weight: 580; }
.conversation-item small { color: #8c9098; font-size: 10px; }
.conversation-empty { padding: 16px 10px; color: #9498a0; font-size: 12px; }
.sidebar-footer { min-width: 0; display: grid; grid-template-columns: 34px minmax(0,1fr) auto; align-items: center; gap: 9px; padding: 12px 8px 3px; border-top: 1px solid #dedfe3; }
.user-avatar { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 10px; background: #d8d9de; font-size: 12px; font-weight: 750; }
.account-name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 13px; font-weight: 650; }
.text-button { padding: 6px; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; }

.chat-shell { position: relative; min-width: 0; height: 100vh; display: grid; grid-template-rows: 58px minmax(0,1fr); overflow: hidden; }
.chat-topbar { z-index: 10; min-width: 0; max-width: 100%; padding: 0 22px; display: flex; align-items: center; justify-content: space-between; gap: 14px; overflow: hidden; border-bottom: 1px solid rgba(222,223,227,.8); background: rgba(247,247,248,.90); backdrop-filter: blur(14px); }
.chat-title { flex: 1 1 auto; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 14px; font-weight: 680; }
.top-new-button { flex: 0 0 auto; min-height: 34px; padding: 0 12px; white-space: nowrap; border: 1px solid #d8d9de; border-radius: 10px; background: #fff; cursor: pointer; font-size: 12px; font-weight: 650; }
.icon-button { width: 36px; height: 36px; display: grid; place-items: center; border: 0; border-radius: 9px; background: transparent; cursor: pointer; font-size: 20px; }
.mobile-only { display: none; }

.messages { min-width: 0; min-height: 0; width: 100%; max-width: 100%; overflow-x: hidden; overflow-y: auto; padding: 42px max(24px, calc((100% - 820px) / 2)) 190px; scroll-behavior: smooth; }
.empty-chat { padding: clamp(75px, 16vh, 155px) 10px 40px; text-align: center; }
.empty-chat h1 { font-size: 30px; }
.empty-chat p { color: var(--muted); }
.message-row { width: 100%; max-width: 100%; min-width: 0; display: grid; grid-template-columns: 38px minmax(0,1fr); gap: 14px; margin-bottom: 34px; }
.message-avatar { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 12px; background: #e3e4e8; color: #4d5563; font-size: 13px; font-weight: 750; }
.message-row.assistant .message-avatar { background: var(--accent); color: #fff; }
.message-content { min-width: 0; width: 100%; max-width: 100%; overflow: hidden; padding-top: 2px; }
.message-label { margin-bottom: 8px; font-size: 13px; font-weight: 750; }
.message-text { width: 100%; max-width: 100%; white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; font-size: 16px; line-height: 1.75; }
.message-time { display: block; margin-top: 8px; color: #a0a5ae; font-size: 11px; }
.message-gallery { width: 100%; max-width: 100%; display: flex; flex-wrap: wrap; gap: 8px; overflow: hidden; margin: 0 0 12px; }
.message-image { width: 100%; max-width: 320px; max-height: 360px; object-fit: contain; border: 1px solid #dfe1e5; border-radius: 15px; background: #eee; cursor: zoom-in; }
.thinking-dot { display: inline-block; width: 7px; height: 7px; margin: 8px 4px 0 0; border-radius: 50%; background: #9299a5; animation: pulse 1.2s infinite ease-in-out; }
.thinking-dot:nth-child(2) { animation-delay: .15s; }
.thinking-dot:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { 0%,70%,100% { transform: translateY(0); opacity:.35; } 35% { transform: translateY(-5px); opacity:1; } }

.composer-wrap { position: absolute; z-index: 8; left: 0; right: 0; bottom: 0; width: 100%; max-width: 100%; overflow: hidden; padding: 20px max(18px, calc((100% - 820px) / 2)) max(14px, env(safe-area-inset-bottom)); background: linear-gradient(to bottom, rgba(247,247,248,0), var(--bg) 26%); }
.composer { width: 100%; max-width: 100%; min-width: 0; padding: 9px 9px 9px 11px; display: flex; align-items: flex-end; gap: 8px; border: 1px solid #d2d4d9; border-radius: 20px; background: #fff; box-shadow: 0 12px 42px rgba(31,39,52,.12); }
.composer textarea { flex: 1 1 0; width: 0; min-width: 0; min-height: 40px; max-height: 180px; padding: 8px 2px 5px; resize: none; border: 0; outline: 0; background: transparent; color: var(--text); line-height: 1.5; }
.attach-button, .send-button { flex: 0 0 40px; width: 40px; height: 40px; border: 0; border-radius: 13px; cursor: pointer; }
.attach-button { background: #eff0f2; color: #59606b; font-size: 24px; font-weight: 300; }
.send-button { background: var(--accent); color: #fff; font-size: 23px; }
.send-button:disabled { opacity: .5; cursor: wait; }
.model-note { margin: 8px auto 0; color: #969ca6; text-align: center; font-size: 10px; }
.image-preview { max-width: 820px; margin: 0 auto 8px; padding: 8px 10px; display: grid; grid-template-columns: 46px minmax(0,1fr) 28px; align-items: center; gap: 9px; border: 1px solid #d7d9de; border-radius: 14px; background: #fff; box-shadow: 0 8px 24px rgba(31,39,52,.08); }
.image-preview img { width: 44px; height: 44px; object-fit: cover; border-radius: 9px; }
.image-preview span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 12px; color: #555b65; }
.image-preview button { width: 27px; height: 27px; border: 0; border-radius: 8px; background: #eeeef1; cursor: pointer; }
.toast { position: fixed; z-index: 100; left: 50%; top: 18px; transform: translate(-50%,-18px); padding: 11px 16px; border-radius: 12px; background: #222936; color: #fff; box-shadow: 0 12px 40px rgba(0,0,0,.2); font-size: 13px; opacity: 0; pointer-events: none; transition: .2s; }
.toast.show { opacity: 1; transform: translate(-50%,0); }
.sidebar-overlay { display: none; }

@media (min-width: 761px) and (max-width: 980px) {
  .app-shell { grid-template-columns: 230px minmax(0, 1fr); }
}

@media (max-width: 760px) {
  .login-shell { padding: 16px; }
  .login-card { padding: 34px 24px 30px; border-radius: 22px; }
  .app-shell { width: 100%; max-width: 100%; display: block; }
  .mobile-only { display: grid; }
  .sidebar { position: fixed; z-index: 40; left: 0; top: 0; width: min(86vw, 310px); transform: translateX(-102%); box-shadow: 16px 0 50px rgba(0,0,0,.16); transition: transform .22s ease; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay { position: fixed; z-index: 35; inset: 0; background: rgba(0,0,0,.28); }
  .sidebar-overlay.show { display: block; }
  .chat-topbar { height: 56px; padding: 0 10px; }
  .chat-title { flex: 1; text-align: center; font-size: 13px; }
  .top-new-button { width: 36px; min-height: 36px; padding: 0; overflow: hidden; color: transparent; font-size: 0; }
  .top-new-button::after { content: "+"; color: var(--text); font-size: 23px; }
  .chat-shell { width: 100%; max-width: 100%; height: 100dvh; grid-template-rows: 56px minmax(0,1fr); }
  .messages { padding: 26px 15px 174px; }
  .empty-chat { padding-top: 17vh; }
  .message-row { grid-template-columns: 32px minmax(0,1fr); gap: 10px; margin-bottom: 28px; }
  .message-avatar { width: 31px; height: 31px; border-radius: 10px; font-size: 11px; }
  .message-text { font-size: 15px; line-height: 1.7; }
  .message-image { max-height: 300px; }
  .composer-wrap { padding: 14px 9px max(9px, env(safe-area-inset-bottom)); }
  .composer { border-radius: 18px; }
  .image-preview { margin-inline: 2px; }
}

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