:root {
  --font-scale: .94;
  --sidebar-w: 232px;
  --topbar-h: 60px;
  --navy: #08172f;
  --navy-2: #10284d;
  --blue: #1267e8;
  --blue-2: #0a4fb8;
  --orange: #ff9e1a;
  --green: #22b573;
  --red: #e84855;
  --text: #152238;
  --muted: #6d7890;
  --muted-2: #8d98ac;
  --bg: #f3f6fb;
  --panel: #ffffff;
  --panel-2: #f8faff;
  --line: #dfe6f0;
  --line-strong: #cdd7e5;
  --shadow-sm: 0 5px 16px rgba(18, 39, 73, .06);
  --shadow-md: 0 16px 40px rgba(14, 35, 68, .12);
  --radius: 14px;
}

body[data-theme="dark"] {
  --text: #e9eef9;
  --muted: #a7b3c9;
  --muted-2: #7f8ba2;
  --bg: #0d1422;
  --panel: #131e30;
  --panel-2: #182438;
  --line: #29364b;
  --line-strong: #384760;
  --shadow-sm: 0 5px 16px rgba(0,0,0,.16);
  --shadow-md: 0 16px 40px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { font-size: calc(16px * var(--font-scale)); }
body {
  margin: 0;
  overflow: hidden;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}
button, textarea, select, input { font: inherit; color: inherit; }
button, select { cursor: pointer; }
a { color: inherit; }
[hidden] { display: none !important; }

.app-shell { display: flex; width: 100%; height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  width: var(--sidebar-w);
  height: 100vh;
  display: flex;
  flex-direction: column;
  color: #fff;
  background:
    radial-gradient(circle at -15% -5%, rgba(28, 111, 232, .42), transparent 33%),
    linear-gradient(180deg, #0c2041 0%, #061226 74%, #050e1e 100%);
  box-shadow: 8px 0 28px rgba(4, 13, 28, .15);
}
.brand-row { height: 69px; display: flex; align-items: center; gap: 6px; padding: 13px 14px 10px; }
.brand { min-width: 0; flex: 1; display: flex; align-items: center; gap: 10px; text-decoration: none; }
.brand-mark {
  flex: 0 0 36px; width: 36px; height: 36px; border-radius: 11px;
  display: grid; place-items: center; color: #fff; font-size: 21px; font-weight: 800;
  background: linear-gradient(145deg, #1c79f0, #0a47ad);
  border: 1px solid rgba(255,255,255,.22);
  box-shadow: 0 8px 20px rgba(4, 78, 184, .25), inset 0 1px 0 rgba(255,255,255,.2);
}
.brand-copy { min-width: 0; }
.brand-copy b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; letter-spacing: .09em; }
.brand-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; color: #94a9cc; font-size: 9px; letter-spacing: .035em; }
.sidebar-close { display: none; width: 30px; height: 30px; border: 0; border-radius: 8px; color: #b7c6df; background: transparent; font-size: 23px; }
.new-chat {
  margin: 3px 14px 12px; height: 38px; border: 1px solid rgba(255,255,255,.17); border-radius: 10px;
  display: flex; align-items: center; justify-content: center; gap: 8px; color: #fff;
  background: rgba(255,255,255,.075); transition: .18s ease;
}
.new-chat:hover { background: rgba(255,255,255,.13); transform: translateY(-1px); }
.nav-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 0 10px 12px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.17) transparent; }
.nav-group { margin: 0 0 12px; }
.nav-group > p, .group-head p { margin: 0; padding: 7px 9px 5px; color: #5f789f; font-size: 9px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.mode {
  width: 100%; min-height: 33px; padding: 6px 9px; border: 0; border-radius: 9px;
  display: flex; align-items: center; gap: 9px; color: #a9bad7; background: transparent; text-align: left;
  transition: .16s ease;
}
.mode i {
  flex: 0 0 22px; width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center;
  color: #7894c0; background: rgba(255,255,255,.035); font-size: 9px; font-style: normal; font-weight: 700;
}
.mode span { font-size: 12px; }
.mode:hover { color: #fff; background: rgba(255,255,255,.06); }
.mode.active { color: #fff; background: linear-gradient(90deg, rgba(26, 107, 231, .88), rgba(24, 84, 176, .34)); box-shadow: inset 2px 0 0 var(--orange); }
.mode.active i { color: #fff; background: rgba(255,255,255,.12); }
.group-head { display: flex; align-items: center; justify-content: space-between; }
.group-head button { border: 0; padding: 3px 8px; color: #607ba7; background: transparent; font-size: 9px; }
.group-head button:hover { color: #c8d6ed; }
.history-list { display: grid; gap: 2px; }
.history-item {
  width: 100%; border: 0; border-radius: 8px; padding: 7px 9px; color: #8299bd; background: transparent; text-align: left;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px;
}
.history-item:hover, .history-item.active { color: #d8e3f4; background: rgba(255,255,255,.055); }
.empty-history { padding: 6px 9px; color: #536a90; font-size: 9px; }
.sidebar-tools { padding: 10px 10px 8px; border-top: 1px solid rgba(255,255,255,.08); display: grid; gap: 4px; }
.tool-link {
  position: relative; min-height: 34px; padding: 7px 9px; border: 0; border-radius: 9px;
  display: flex; align-items: center; gap: 9px; color: #9fb1cf; background: transparent; text-decoration: none; text-align: left;
}
.tool-link:hover { color: #fff; background: rgba(255,255,255,.06); }
.tool-link span { flex: 0 0 22px; width: 22px; text-align: center; font-size: 10px; }
.tool-link b { font-size: 11px; font-weight: 500; }
.tool-link em { position: absolute; right: 10px; width: 7px; height: 7px; border-radius: 50%; background: #f3b33f; box-shadow: 0 0 0 3px rgba(243,179,63,.12); }
.tool-link em.online { background: #2fd184; box-shadow: 0 0 0 3px rgba(47,209,132,.12); }
.sidebar-footer { min-height: 63px; padding: 9px 14px 12px; border-top: 1px solid rgba(255,255,255,.07); }
.service-status { display: flex; align-items: center; gap: 7px; color: #8fa4c4; font-size: 9px; }
.service-status i { width: 7px; height: 7px; border-radius: 50%; background: #e9ae3c; box-shadow: 0 0 0 3px rgba(233,174,60,.11); }
.service-status i.online { background: #2fd184; box-shadow: 0 0 0 3px rgba(47,209,132,.11); }
.service-status i.offline { background: #f05f69; box-shadow: 0 0 0 3px rgba(240,95,105,.11); }
.sidebar-footer small { display: block; margin-top: 7px; color: #4f678d; font-size: 7px; line-height: 1.45; letter-spacing: .055em; }

.main-panel { min-width: 0; width: calc(100% - var(--sidebar-w)); height: 100vh; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }
.topbar {
  flex: 0 0 var(--topbar-h); height: var(--topbar-h); padding: 0 20px; display: flex; align-items: center;
  border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--panel) 93%, transparent); backdrop-filter: blur(14px);
}
.menu-btn { display: none; width: 32px; height: 32px; margin-right: 8px; border: 0; border-radius: 8px; background: transparent; font-size: 18px; }
.mode-heading { min-width: 0; }
.mode-heading b { display: block; font-size: 13px; }
.mode-heading span { display: block; margin-top: 2px; color: var(--muted); font-size: 9px; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 7px; }
.provider-box {
  position: relative; height: 34px; display: flex; align-items: center; gap: 5px; padding: 0 7px 0 10px;
  border: 1px solid var(--line); border-radius: 9px; background: var(--panel); box-shadow: var(--shadow-sm);
}
.provider-status { width: 7px; height: 7px; border-radius: 50%; background: #e3ab3e; }
.provider-status.online { background: var(--green); }
.provider-status.offline { background: var(--red); }
.provider-box select { min-width: 170px; max-width: 260px; height: 31px; border: 0; outline: 0; background: transparent; font-size: 10px; }
.top-icon { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); box-shadow: var(--shadow-sm); font-size: 13px; }
.top-icon:hover { border-color: #a8c4ec; color: var(--blue); }
.connection-banner {
  min-height: 46px; padding: 8px 20px; display: flex; align-items: center; justify-content: center; gap: 22px;
  color: #7b4a06; background: #fff8e9; border-bottom: 1px solid #f0dfb6;
}
body[data-theme="dark"] .connection-banner { color: #f1c46e; background: #342b1b; border-color: #574522; }
.connection-banner div { display: flex; align-items: baseline; gap: 8px; }
.connection-banner b { font-size: 11px; }
.connection-banner span { font-size: 9px; }
.connection-banner a { padding: 5px 9px; border-radius: 7px; color: #fff; background: #b66b0d; text-decoration: none; font-size: 9px; }

.chat-area { flex: 1; min-height: 0; overflow-y: auto; padding: 22px max(18px, calc((100vw - var(--sidebar-w) - 900px) / 2)); scroll-behavior: smooth; }
.welcome { min-height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 24px 0; }
.hero-mark { position: relative; width: 58px; height: 58px; margin-bottom: 14px; }
.hero-mark span {
  position: relative; z-index: 2; width: 58px; height: 58px; border-radius: 18px; display: grid; place-items: center;
  color: #fff; background: linear-gradient(145deg, #1877ed, #0845a8); font-size: 32px; font-weight: 800;
  box-shadow: 0 14px 28px rgba(17, 94, 205, .24), inset 0 1px 0 rgba(255,255,255,.24);
}
.hero-mark i { position: absolute; inset: 8px -9px -8px 10px; border-radius: 18px; background: rgba(18, 103, 232, .10); transform: rotate(8deg); }
.eyebrow { margin: 0 0 6px; color: var(--blue); font-size: 8px; font-weight: 800; letter-spacing: .18em; }
.welcome h1 { margin: 0; font-size: clamp(24px, 3vw, 34px); letter-spacing: -.035em; }
.welcome > p:not(.eyebrow) { max-width: 610px; margin: 9px auto 21px; color: var(--muted); line-height: 1.65; font-size: 12px; }
.quick-grid { width: 100%; max-width: 820px; display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 9px; }
.quick-grid button {
  min-height: 72px; padding: 12px 13px; border: 1px solid var(--line); border-radius: 13px; display: flex; align-items: center; gap: 11px;
  color: var(--text); background: var(--panel); text-align: left; box-shadow: var(--shadow-sm); transition: .18s ease;
}
.quick-grid button:hover { transform: translateY(-2px); border-color: #a9c7ef; box-shadow: var(--shadow-md); }
.quick-grid button > i { flex: 0 0 34px; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: var(--blue); background: #eaf3ff; font-size: 10px; font-style: normal; font-weight: 800; }
body[data-theme="dark"] .quick-grid button > i { background: #203b61; }
.quick-grid span { min-width: 0; flex: 1; }
.quick-grid b { display: block; margin-bottom: 4px; font-size: 11px; }
.quick-grid small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 9px; }
.quick-grid em { color: #9eb2ce; font-style: normal; }
.messages { display: none; width: 100%; max-width: 900px; margin: 0 auto; padding: 5px 0 12px; }
.messages.active { display: block; }
.message-row { display: flex; align-items: flex-start; gap: 9px; margin: 0 0 16px; }
.message-row.user { flex-direction: row-reverse; }
.avatar {
  flex: 0 0 30px; width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  color: #fff; background: var(--navy); font-size: 9px; font-weight: 800; box-shadow: var(--shadow-sm);
}
.user .avatar { color: #275589; background: #dceafb; }
.message-body { min-width: 0; max-width: min(80%, 760px); }
.bubble {
  width: fit-content; max-width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 13px; color: var(--text); background: var(--panel);
  line-height: 1.68; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: var(--shadow-sm); font-size: 12px;
}
.assistant .bubble { border-top-left-radius: 4px; }
.user .bubble { margin-left: auto; color: #fff; background: linear-gradient(145deg, #176ee5, #0d5bca); border-color: transparent; border-top-right-radius: 4px; }
.bubble code { padding: 1px 4px; border-radius: 5px; color: #c83d4e; background: #f4edf0; font-family: Consolas, monospace; font-size: .92em; }
body[data-theme="dark"] .bubble code { color: #ffadb6; background: #36272d; }
.bubble .error-hint { display: block; margin-top: 7px; padding-top: 7px; border-top: 1px dashed var(--line); color: var(--muted); font-size: 10px; }
.answer-meta { margin: 5px 2px 0; color: var(--muted-2); font-size: 8px; }
.message-actions { margin-top: 4px; display: flex; gap: 3px; }
.message-actions button { padding: 3px 6px; border: 0; border-radius: 6px; color: var(--muted-2); background: transparent; font-size: 9px; }
.message-actions button:hover { color: var(--blue); background: var(--panel-2); }
.typing { display: inline-flex; align-items: center; gap: 4px; height: 16px; }
.typing i { width: 5px; height: 5px; border-radius: 50%; background: #8392a9; animation: bounce 1.2s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .14s; }
.typing i:nth-child(3) { animation-delay: .28s; }
@keyframes bounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-4px); } }

.composer-wrap { flex: 0 0 auto; padding: 7px max(18px, calc((100vw - var(--sidebar-w) - 900px) / 2)) 10px; background: linear-gradient(180deg, transparent, var(--bg) 26%); }
.composer-toolbar { max-width: 900px; height: 24px; margin: 0 auto 4px; display: flex; align-items: center; gap: 7px; }
.composer-toolbar span { padding: 3px 8px; border-radius: 999px; color: var(--blue); background: #e9f2ff; font-size: 8px; font-weight: 700; }
body[data-theme="dark"] .composer-toolbar span { background: #203b61; }
.composer-toolbar button { margin-left: auto; padding: 3px 6px; border: 0; color: var(--muted-2); background: transparent; font-size: 8px; }
.composer-toolbar button + button { margin-left: 0; }
.composer-toolbar button:hover { color: var(--blue); }
.composer {
  max-width: 900px; margin: 0 auto; display: flex; align-items: flex-end; gap: 6px; padding: 6px;
  border: 1px solid var(--line-strong); border-radius: 14px; background: var(--panel); box-shadow: 0 10px 28px rgba(18, 39, 73, .09);
}
.composer:focus-within { border-color: #8db8ed; box-shadow: 0 12px 32px rgba(18, 103, 232, .12); }
.composer textarea { flex: 1; min-height: 36px; max-height: 130px; padding: 8px 4px; border: 0; outline: 0; resize: none; color: var(--text); background: transparent; line-height: 1.45; font-size: 12px; }
.composer textarea::placeholder { color: var(--muted-2); }
.voice-btn, .send-btn { flex: 0 0 36px; width: 36px; height: 36px; border: 0; border-radius: 10px; }
.voice-btn { color: #5d6e87; background: var(--panel-2); font-size: 9px; }
.voice-btn.listening { color: #d33b4b; background: #ffe8eb; animation: pulse 1s infinite; }
.send-btn { color: #fff; background: linear-gradient(145deg, #1a74eb, #0d59c6); box-shadow: 0 6px 16px rgba(18,103,232,.2); }
.send-btn.stop { background: #df4e5b; }
.send-btn:disabled { opacity: .42; cursor: not-allowed; box-shadow: none; }
@keyframes pulse { 50% { transform: scale(.91); } }
.composer-note { max-width: 900px; margin: 5px auto 0; display: flex; justify-content: space-between; color: var(--muted-2); font-size: 7px; }

.drawer-backdrop, .modal-backdrop { position: fixed; inset: 0; z-index: 80; background: rgba(4, 12, 28, .46); backdrop-filter: blur(2px); }
.settings-drawer {
  position: fixed; inset: 0 0 0 auto; z-index: 90; width: min(390px, 92vw); display: flex; flex-direction: column;
  background: var(--panel); box-shadow: -20px 0 50px rgba(4, 18, 41, .2); transform: translateX(105%); transition: transform .23s ease;
}
.settings-drawer.open { transform: translateX(0); }
.settings-drawer > header, .prompt-modal > header { min-height: 70px; padding: 15px 18px; display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.settings-drawer header p, .prompt-modal header p { margin: 0 0 3px; color: var(--blue); font-size: 8px; font-weight: 800; letter-spacing: .14em; }
.settings-drawer header h2, .prompt-modal header h2 { margin: 0; font-size: 16px; }
.settings-drawer header button, .prompt-modal header button { margin-left: auto; width: 32px; height: 32px; border: 0; border-radius: 9px; background: var(--panel-2); font-size: 20px; }
.settings-content { flex: 1; overflow-y: auto; padding: 15px 18px 24px; }
.settings-content section { margin-bottom: 19px; }
.settings-content h3 { margin: 0 0 9px; color: var(--muted); font-size: 10px; letter-spacing: .08em; }
.settings-content label { min-height: 43px; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); font-size: 11px; }
.settings-content select { min-width: 132px; height: 31px; padding: 0 7px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); font-size: 10px; }
.settings-content input[type="range"] { width: 118px; accent-color: var(--blue); }
.settings-content label > span#fontScaleValue { min-width: 35px; margin-left: -8px; color: var(--muted); font-size: 9px; }
.toggle-line span b, .toggle-line span small { display: block; }
.toggle-line span small { margin-top: 2px; color: var(--muted); font-size: 8px; }
.toggle-line input { width: 34px; height: 18px; accent-color: var(--blue); }
.settings-action {
  width: 100%; min-height: 54px; margin-bottom: 7px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 11px;
  display: flex; align-items: center; gap: 10px; color: var(--text); background: var(--panel-2); text-align: left; text-decoration: none;
}
.settings-action span { flex: 1; }
.settings-action b, .settings-action small { display: block; }
.settings-action b { font-size: 11px; }
.settings-action small { margin-top: 3px; color: var(--muted); font-size: 8px; }
.settings-action em { color: var(--muted); font-style: normal; }
.settings-action.primary { color: #fff; background: linear-gradient(145deg, #176ee4, #0e55ba); border-color: transparent; }
.settings-action.primary small, .settings-action.primary em { color: #cde0fb; }
.settings-action.danger b { color: var(--red); }

.modal-backdrop { display: grid; place-items: center; padding: 20px; }
.prompt-modal { width: min(760px, 96vw); max-height: min(680px, 90vh); border-radius: 17px; overflow: hidden; background: var(--panel); box-shadow: 0 25px 70px rgba(3, 15, 36, .28); }
.template-grid { max-height: calc(90vh - 70px); overflow-y: auto; padding: 14px; display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 8px; }
.template-card { min-height: 72px; padding: 11px; border: 1px solid var(--line); border-radius: 11px; color: var(--text); background: var(--panel-2); text-align: left; }
.template-card:hover { border-color: #9ec2ef; transform: translateY(-1px); }
.template-card b { display: block; margin-bottom: 5px; font-size: 11px; }
.template-card span { color: var(--muted); font-size: 9px; line-height: 1.5; }

body[data-density="comfortable"] { --sidebar-w: 248px; --topbar-h: 66px; }
body[data-density="comfortable"] .mode { min-height: 38px; padding-top: 8px; padding-bottom: 8px; }
body[data-density="comfortable"] .message-row { margin-bottom: 21px; }
body[data-density="comfortable"] .bubble { padding: 13px 15px; line-height: 1.75; }

@media (max-width: 900px) {
  .sidebar { transform: translateX(-105%); transition: transform .23s ease; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: block; }
  .main-panel { width: 100%; margin-left: 0; }
  .menu-btn { display: block; }
  .chat-area, .composer-wrap { padding-left: 13px; padding-right: 13px; }
  .provider-box select { min-width: 130px; max-width: 160px; }
}
@media (max-width: 620px) {
  .topbar { padding: 0 10px; }
  .mode-heading span { display: none; }
  .provider-box { max-width: 150px; }
  .provider-box select { min-width: 108px; max-width: 112px; }
  .top-actions { gap: 4px; }
  .top-icon { width: 32px; height: 32px; }
  .quick-grid { grid-template-columns: 1fr; }
  .quick-grid button { min-height: 65px; }
  .message-body { max-width: 88%; }
  .connection-banner { justify-content: space-between; gap: 8px; padding-left: 11px; padding-right: 11px; }
  .connection-banner div { display: block; }
  .connection-banner span { display: block; margin-top: 2px; }
  .composer-note span:first-child { display: none; }
  .composer-note { justify-content: center; }
  .template-grid { grid-template-columns: 1fr; }
}
@media (max-height: 700px) and (min-width: 901px) {
  .nav-group { margin-bottom: 8px; }
  .mode { min-height: 30px; padding-top: 4px; padding-bottom: 4px; }
  .mode i { height: 20px; }
}
