:root {
  --navy-1: #020b3a;
  --navy-2: #01052a;
  --navy-3: #06114f;
  --purple: #4318ff;
  --purple-2: #601cff;
  --text: #09114a;
  --text-soft: #5c689a;
  --line: #e8ebf4;
  --panel: #ffffff;
  --bg: #f8f9fe;
  --shadow: 0 12px 28px rgba(13, 19, 64, 0.04);
  --sidebar-w: 224px;
  --sidebar-collapsed: 92px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}
a { color: inherit; text-decoration: none; }
button, textarea { font: inherit; }
button { cursor: pointer; border: 0; background: transparent; }
textarea { resize: none; }
svg { fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; }

.ai-app { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
body.sidebar-collapsed .ai-app { grid-template-columns: var(--sidebar-collapsed) minmax(0, 1fr); }
.ai-sidebar {
  display: flex; flex-direction: column; justify-content: space-between; min-height: 100vh; padding: 16px 14px 18px;
  background: radial-gradient(circle at 22px 22px, rgba(96, 32, 255, 0.3), transparent 84px), linear-gradient(180deg, var(--navy-3) 0%, var(--navy-2) 54%, #000b33 100%);
  box-shadow: 18px 0 44px rgba(4, 11, 51, 0.16);
}
.sidebar-brand-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sidebar-brand { display: flex; align-items: center; gap: 12px; min-width: 0; padding: 8px 10px 18px; }
.sidebar-brand-icon {
  width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #3200ef 0%, #651dff 100%); box-shadow: 0 12px 24px rgba(68, 24, 255, 0.32); flex: 0 0 44px;
}
.sidebar-brand-icon svg { width: 24px; height: 24px; stroke-width: 2; }
.brand-copy strong { display: block; color: #fff; font-size: 18px; font-weight: 800; letter-spacing: -0.03em; }
.brand-copy small { display: block; margin-top: 2px; color: rgba(255,255,255,0.92); font-size: 10px; font-weight: 700; letter-spacing: 0.06em; }
.sidebar-toggle {
  width: 34px; height: 34px; flex: 0 0 34px; display: grid; place-items: center; color: rgba(255,255,255,0.86);
  border-radius: 10px; background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.06);
}
.sidebar-toggle svg { width: 18px; height: 18px; stroke-width: 2.2; transition: transform .2s ease; }
.ai-nav { padding-top: 10px; border-top: 1px solid rgba(255,255,255,0.08); }
.nav-item, .logout-link {
  height: 46px; display: flex; align-items: center; gap: 14px; padding: 0 12px; margin-bottom: 5px; border-radius: 10px;
  color: rgba(255,255,255,0.96); font-size: 14px; font-weight: 600; transition: background .2s ease, color .2s ease;
}
.nav-item:hover, .logout-link:hover { background: rgba(255,255,255,0.05); }
.nav-item.active { color: #fff; background: linear-gradient(135deg, #3500ee 0%, #5e1cff 100%); box-shadow: 0 14px 26px rgba(67, 14, 255, 0.26); }
.nav-icon { width: 28px; height: 28px; display: grid; place-items: center; flex: 0 0 28px; }
.nav-icon svg { width: 21px; height: 21px; stroke-width: 1.9; }
.nav-text { white-space: nowrap; }
.sidebar-mini-card {
  display: flex; align-items: center; gap: 12px; margin: 18px 4px 18px; padding: 16px; border-radius: 12px; color: #fff;
  background: linear-gradient(180deg, rgba(81, 20, 255, 0.24) 0%, rgba(63, 18, 180, 0.6) 100%); border: 1px solid rgba(255,255,255,0.08);
}
.sidebar-mini-card strong { display: block; font-size: 15px; font-weight: 800; }
.sidebar-mini-card p { margin: 4px 0 0; font-size: 13px; color: rgba(255,255,255,0.95); }
.mini-dot { width: 10px; height: 10px; border-radius: 999px; background: #27d264; box-shadow: 0 0 0 6px rgba(39,210,100,0.15); }
.logout-link { margin-top: 8px; }

.ai-main { min-width: 0; padding: 18px 20px; display: flex; flex-direction: column; gap: 18px; }
.ai-topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 8px 4px 2px;
}
.ai-topbar h1 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: -0.03em; }
.ai-topbar p { margin: 6px 0 0; font-size: 14px; color: var(--text-soft); }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.ghost-btn, .primary-btn {
  height: 44px; padding: 0 18px; border-radius: 12px; font-size: 14px; font-weight: 700;
}
.ghost-btn { border: 1px solid #dde2f0; background: #fff; color: #1a255f; }
.primary-btn { color: #fff; background: linear-gradient(135deg, #3500ee 0%, #5d1cff 100%); box-shadow: 0 14px 30px rgba(67, 14, 255, 0.18); }

.chat-shell {
  min-height: calc(100vh - 120px); display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 18px;
}
.chat-history-panel, .chat-panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow);
}
.chat-history-panel { padding: 18px; display: flex; flex-direction: column; }
.history-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.history-head h2 { margin: 0; font-size: 17px; font-weight: 800; }
.history-head button { color: #4d37ff; font-size: 13px; font-weight: 700; }
.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-item {
  width: 100%; padding: 14px 14px; text-align: left; border-radius: 14px; border: 1px solid #e7ebf5; background: #fff;
  transition: border-color .2s ease, background .2s ease, box-shadow .2s ease;
}
.history-item strong { display: block; font-size: 14px; font-weight: 700; color: #101b53; }
.history-item span { display: block; margin-top: 5px; font-size: 13px; line-height: 1.45; color: #6571a3; }
.history-item.active, .history-item:hover { border-color: #dcd7ff; background: linear-gradient(180deg, #faf9ff 0%, #f6f4ff 100%); box-shadow: 0 10px 24px rgba(67, 14, 255, 0.06); }

.chat-panel { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.chat-thread {
  flex: 1 1 auto; overflow: auto; padding: 26px 26px 10px;
}
.welcome-block { text-align: center; max-width: 760px; margin: 0 auto 26px; }
.welcome-mark {
  width: 62px; height: 62px; margin: 0 auto 18px; border-radius: 18px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #3500ee 0%, #5d1cff 100%); box-shadow: 0 18px 36px rgba(67, 14, 255, 0.22);
}
.welcome-mark svg { width: 28px; height: 28px; stroke-width: 2; }
.welcome-block h2 { margin: 0; font-size: 28px; font-weight: 800; letter-spacing: -0.03em; }
.welcome-block p { margin: 12px auto 0; max-width: 620px; color: #5d6999; font-size: 15px; line-height: 1.65; }

.suggestion-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; max-width: 860px; margin: 0 auto 26px;
}
.suggestion-card {
  min-height: 96px; padding: 16px 18px; text-align: left; border-radius: 16px; border: 1px solid #e8ebf4; background: #fff;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.suggestion-card:hover { transform: translateY(-1px); border-color: #dcd7ff; box-shadow: 0 12px 24px rgba(67, 14, 255, 0.08); }
.suggestion-card strong { display: block; font-size: 15px; font-weight: 700; color: #121d57; }
.suggestion-card span { display: block; margin-top: 8px; color: #6571a3; font-size: 13px; line-height: 1.5; }

.message {
  display: flex; align-items: flex-start; gap: 14px; max-width: 900px; margin: 0 auto 16px;
}
.avatar {
  width: 38px; height: 38px; flex: 0 0 38px; border-radius: 12px; display: grid; place-items: center; font-size: 13px; font-weight: 800;
}
.ai-avatar { color: #fff; background: linear-gradient(135deg, #3500ee 0%, #5d1cff 100%); }
.user-avatar { color: #14215d; background: #eef2ff; }
.bubble {
  flex: 1 1 auto; padding: 16px 18px; border-radius: 18px; border: 1px solid #e8ebf4; background: #fff;
}
.message.user .bubble { background: #fafbff; }
.message-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.message-head strong { font-size: 14px; font-weight: 800; }
.message-head span { font-size: 12px; color: #7380b2; }
.bubble p { margin: 0; font-size: 14px; line-height: 1.7; color: #27336f; }
.bubble ul { margin: 12px 0 0 18px; padding: 0; color: #27336f; }
.bubble li { margin-bottom: 8px; font-size: 14px; line-height: 1.6; }
.insight-list { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.insight-pill {
  display: inline-flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 42px; padding: 0 14px;
  border-radius: 999px; background: #f6f8ff; color: #23306a; font-size: 13px; font-weight: 700;
}
.insight-pill strong { color: #15a248; font-weight: 800; }
.insight-pill.danger strong { color: #ef1d33; }

.composer-wrap {
  border-top: 1px solid var(--line); background: linear-gradient(180deg, rgba(251,252,255,0.9) 0%, #fff 100%); padding: 18px 22px 20px;
}
.composer-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.composer-tools button {
  height: 34px; padding: 0 14px; border-radius: 999px; background: #f3f5fb; color: #2c3973; font-size: 13px; font-weight: 700;
}
.composer-box {
  min-height: 92px; display: grid; grid-template-columns: 46px minmax(0, 1fr) 52px; gap: 14px; align-items: end;
  padding: 14px; border-radius: 20px; border: 1px solid #dde2f0; background: #fff; box-shadow: 0 14px 28px rgba(13, 19, 64, 0.04);
}
.attach-btn, .send-btn {
  width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center;
}
.attach-btn { color: #2d3973; background: #f3f5fb; }
.send-btn { color: #fff; background: linear-gradient(135deg, #3500ee 0%, #5d1cff 100%); box-shadow: 0 12px 24px rgba(67, 14, 255, 0.22); }
.attach-btn svg, .send-btn svg { width: 20px; height: 20px; stroke-width: 2; }
.composer-box textarea {
  width: 100%; height: 62px; border: 0; outline: 0; background: transparent; color: #122059; font-size: 15px; line-height: 1.55; padding-top: 6px;
}
.composer-box textarea::placeholder { color: #7a86b6; }
.composer-note { margin: 10px 2px 0; color: #7a86b6; font-size: 12px; text-align: center; }

body.sidebar-collapsed .ai-sidebar { padding-left: 10px; padding-right: 10px; }
body.sidebar-collapsed .brand-copy,
body.sidebar-collapsed .nav-text,
body.sidebar-collapsed .sidebar-mini-card div,
body.sidebar-collapsed .logout-link .nav-text { display: none; }
body.sidebar-collapsed .sidebar-brand { justify-content: center; padding-right: 0; padding-left: 0; }
body.sidebar-collapsed .sidebar-brand-row { flex-direction: column; align-items: center; gap: 12px; }
body.sidebar-collapsed .sidebar-toggle svg { transform: rotate(180deg); }
body.sidebar-collapsed .nav-item,
body.sidebar-collapsed .logout-link,
body.sidebar-collapsed .sidebar-mini-card { justify-content: center; padding-left: 0; padding-right: 0; }
body.sidebar-collapsed .sidebar-mini-card { min-height: 48px; }

@media (max-width: 1320px) {
  .chat-shell { grid-template-columns: 250px minmax(0, 1fr); }
}
@media (max-width: 1120px) {
  .chat-shell { grid-template-columns: 1fr; }
  .chat-history-panel { order: 2; }
  .chat-panel { order: 1; }
}
@media (max-width: 980px) {
  .ai-app, body.sidebar-collapsed .ai-app { grid-template-columns: 1fr; }
  .ai-sidebar { min-height: auto; }
  .ai-main { padding: 16px; }
  .ai-topbar { flex-direction: column; align-items: stretch; }
  .topbar-actions { justify-content: stretch; }
  .ghost-btn, .primary-btn { flex: 1 1 auto; }
  .suggestion-grid { grid-template-columns: 1fr; }
  .composer-box { grid-template-columns: 44px minmax(0, 1fr) 44px; }
}
