@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Manrope:wght@500;600;700&display=swap');

:root {
  color-scheme: dark;
  --bg: #0a0c11;
  --sidebar: #0f1219;
  --panel: #121620;
  --panel-strong: #191e2a;
  --panel-soft: #151923;
  --line: rgba(255, 255, 255, 0.085);
  --line-strong: rgba(255, 255, 255, 0.15);
  --text: #f4f5f7;
  --muted: #969dac;
  --muted-strong: #b9bfca;
  --accent: #7c5cff;
  --accent-2: #9b87ff;
  --accent-soft: rgba(124, 92, 255, 0.14);
  --success: #55d69e;
  --warning: #f1b85b;
  --danger: #ff707b;
  --shadow: 0 26px 90px rgba(0, 0, 0, 0.45);
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f7f7fa;
  --sidebar: #efeff4;
  --panel: #ffffff;
  --panel-strong: #f4f3f8;
  --panel-soft: #f8f7fb;
  --line: rgba(16, 19, 28, 0.09);
  --line-strong: rgba(16, 19, 28, 0.17);
  --text: #171923;
  --muted: #6e7380;
  --muted-strong: #515663;
  --accent-soft: rgba(124, 92, 255, 0.1);
  --shadow: 0 26px 80px rgba(24, 20, 44, 0.15);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "DM Sans", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea { font: inherit; }
button { color: inherit; }

.hidden { display: none !important; }
.mobile-only { display: none; }

.app-shell {
  display: grid;
  grid-template-columns: 286px minmax(0, 1fr);
  min-height: 100dvh;
}

.sidebar {
  display: flex;
  min-width: 0;
  flex-direction: column;
  padding: 18px 14px;
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  z-index: 30;
}

.sidebar-head { display: flex; align-items: center; gap: 12px; padding: 4px 8px 18px; }
.brand-mark, .login-logo {
  display: grid;
  place-items: center;
  width: 37px;
  height: 37px;
  flex: 0 0 auto;
  border-radius: 12px;
  background: linear-gradient(145deg, var(--accent-2), #5d3df1);
  color: white;
  font-family: Manrope, sans-serif;
  font-weight: 800;
  box-shadow: 0 9px 28px rgba(124, 92, 255, 0.3);
}

.brand-copy { display: flex; min-width: 0; flex-direction: column; }
.brand-copy strong { font-family: Manrope, sans-serif; font-size: 14px; }
.brand-copy span { color: var(--muted); font-size: 11px; }

.new-chat-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 11px 14px;
  border: 1px solid rgba(124, 92, 255, .28);
  border-radius: 12px;
  background: var(--accent-soft);
  color: #a996ff;
  font-weight: 700;
  cursor: pointer;
  transition: .18s ease;
}

.new-chat-button:hover { transform: translateY(-1px); background: rgba(124, 92, 255, .2); }

.sidebar-search, .model-search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 13px 0 8px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--muted);
  background: rgba(255, 255, 255, .025);
}

.sidebar-search input, .model-search input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  font-size: 13px;
}

.conversation-list { flex: 1; overflow-y: auto; padding: 5px 0; scrollbar-width: thin; }
.conversation-item { position: relative; margin: 3px 0; }
.conversation-item > button:first-child {
  width: 100%;
  overflow: hidden;
  padding: 10px 34px 10px 11px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted-strong);
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.conversation-item.active > button:first-child { background: var(--panel-strong); color: var(--text); }
.conversation-item:hover > button:first-child { background: var(--panel-strong); }
.conversation-delete {
  position: absolute;
  top: 7px;
  right: 6px;
  width: 27px;
  height: 27px;
  border: 0;
  border-radius: 7px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  opacity: 0;
}
.conversation-item:hover .conversation-delete { opacity: 1; }
.conversation-delete:hover { color: var(--danger); background: rgba(255, 112, 123, .1); }

.sidebar-footer { padding-top: 8px; border-top: 1px solid var(--line); }
.sidebar-action {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted-strong);
  cursor: pointer;
}
.sidebar-action:hover { background: var(--panel-strong); color: var(--text); }
.danger-action:hover { color: var(--danger); }

.main-panel { position: relative; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; min-width: 0; height: 100dvh; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 68px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(16px);
  z-index: 10;
}
.topbar-actions { display: flex; gap: 6px; }
.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel-soft);
  color: var(--muted-strong);
  cursor: pointer;
}
.icon-button:hover { color: var(--text); border-color: var(--line-strong); }

.model-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 240px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--panel-soft);
  cursor: pointer;
}
.model-status { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 4px rgba(85, 214, 158, .11); }
.model-pill-copy { display: flex; min-width: 0; flex: 1; flex-direction: column; align-items: flex-start; }
.model-pill-copy strong { max-width: 185px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.model-pill-copy small { color: var(--muted); font-size: 10px; }
.chevron { color: var(--muted); }

.chat-view { overflow-y: auto; scroll-behavior: smooth; }
.empty-state {
  width: min(760px, calc(100% - 38px));
  margin: 0 auto;
  padding: clamp(50px, 11vh, 120px) 0 40px;
  text-align: center;
}
.hero-orb {
  position: relative;
  display: grid;
  place-items: center;
  width: 70px;
  height: 70px;
  margin: 0 auto 26px;
  border-radius: 24px;
  background: radial-gradient(circle at 30% 20%, #b9acff, #7655f7 58%, #4832be);
  box-shadow: 0 0 0 10px var(--accent-soft), 0 24px 80px rgba(124, 92, 255, .32);
  transform: rotate(8deg);
}
.hero-orb span { font-size: 30px; color: white; transform: rotate(-8deg); }
.eyebrow { margin: 0 0 10px; color: var(--accent-2); font-size: 10px; font-weight: 800; letter-spacing: .16em; }
.empty-state h1, .login-card h1 { margin: 0; font-family: Manrope, sans-serif; font-size: clamp(30px, 4vw, 46px); letter-spacing: -.04em; }
.empty-state > p:not(.eyebrow) { max-width: 490px; margin: 13px auto 30px; color: var(--muted); line-height: 1.6; }
.suggestion-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 11px; }
.suggestion {
  min-height: 100px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--panel-soft);
  text-align: left;
  cursor: pointer;
  transition: .18s ease;
}
.suggestion:hover { transform: translateY(-2px); border-color: rgba(124, 92, 255, .35); background: var(--accent-soft); }
.suggestion span { display: block; margin-bottom: 20px; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .12em; }
.suggestion strong { font-size: 13px; }

.messages { width: min(850px, calc(100% - 38px)); margin: 0 auto; padding: 34px 0 48px; }
.message { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 13px; margin-bottom: 28px; }
.message.user { grid-template-columns: minmax(0, 1fr); justify-items: end; }
.message-avatar { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 11px; background: var(--accent-soft); color: var(--accent-2); font-weight: 800; }
.message-content { min-width: 0; color: var(--text); font-size: 15px; line-height: 1.72; }
.message.user .message-content { max-width: min(660px, 88%); padding: 11px 15px; border-radius: 17px 17px 4px 17px; background: var(--panel-strong); }
.message-content p { margin: 0 0 12px; }
.message-content p:last-child { margin-bottom: 0; }
.message-content pre { position: relative; overflow-x: auto; margin: 14px 0; padding: 17px; border: 1px solid var(--line); border-radius: 13px; background: #080a0f; color: #d8dbe3; font: 13px/1.6 ui-monospace, SFMono-Regular, Consolas, monospace; }
[data-theme="light"] .message-content pre { background: #20232b; color: #f4f5f7; }
.message-content code:not(pre code) { padding: 2px 6px; border-radius: 5px; background: var(--panel-strong); color: var(--accent-2); font: .9em ui-monospace, monospace; }
.message-content a { color: var(--accent-2); }
.thinking { display: inline-flex; gap: 4px; padding: 9px 0; }
.thinking i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: pulse 1.1s infinite ease-in-out; }
.thinking i:nth-child(2) { animation-delay: .16s; }.thinking i:nth-child(3) { animation-delay: .32s; }
.provider-wait { display: block; margin-bottom: 10px; color: var(--muted); font-size: .92rem; line-height: 1.45; }
@keyframes pulse { 0%, 70%, 100% { opacity: .25; transform: translateY(0); } 35% { opacity: 1; transform: translateY(-3px); } }

.research-progress {
  width: min(620px, 100%);
  margin: 0 0 17px;
  padding: 14px;
  border: 1px solid rgba(124, 92, 255, .24);
  border-radius: 15px;
  background: linear-gradient(145deg, var(--accent-soft), var(--panel-soft) 62%);
}
.research-progress:last-child { margin-bottom: 0; }
.research-progress[data-stage="provider_retry"] { border-color: color-mix(in srgb, var(--warning) 48%, transparent); }
.research-progress[data-stage="completed"] { border-color: color-mix(in srgb, var(--success) 45%, transparent); }
.research-progress[data-stage="failed"] { border-color: color-mix(in srgb, var(--danger) 48%, transparent); }
.research-progress-header { display: grid; grid-template-columns: 13px minmax(0, 1fr); gap: 10px; align-items: start; }
.research-progress-indicator {
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border: 2px solid var(--accent-2);
  border-top-color: transparent;
  border-radius: 50%;
  animation: research-spin .9s linear infinite;
}
.research-progress[data-stage="provider_retry"] .research-progress-indicator { border-color: var(--warning); border-top-color: transparent; }
.research-progress[data-stage="completed"] .research-progress-indicator,
.research-progress[data-stage="failed"] .research-progress-indicator {
  border: 0;
  background: var(--success);
  animation: none;
}
.research-progress[data-stage="failed"] .research-progress-indicator { background: var(--danger); }
.research-progress-copy { display: flex; min-width: 0; flex-direction: column; }
.research-progress-copy strong { font-size: 13px; line-height: 1.35; }
.research-progress-copy small { margin-top: 3px; color: var(--muted-strong); font-size: 11px; line-height: 1.5; }
.research-progress-meter { height: 4px; overflow: hidden; margin: 13px 0; border-radius: 99px; background: var(--panel-strong); }
.research-progress-meter > span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .25s ease; }
.research-progress[data-stage="completed"] .research-progress-meter > span { background: var(--success); }
.research-progress[data-stage="failed"] .research-progress-meter > span { background: var(--danger); }
.research-progress-steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0; padding: 0; list-style: none; }
.research-progress-step { display: grid; grid-template-columns: 16px minmax(0, 1fr); gap: 6px; min-width: 0; color: var(--muted); }
.research-progress-marker { display: block; width: 13px; height: 13px; margin-top: 2px; border: 1px solid var(--line-strong); border-radius: 50%; color: var(--bg); font-size: 9px; font-weight: 900; line-height: 12px; text-align: center; }
.research-progress-step > span:last-child { display: flex; min-width: 0; flex-direction: column; }
.research-progress-step strong { color: inherit; font-size: 10px; line-height: 1.3; }
.research-progress-step small { margin-top: 2px; overflow: hidden; color: var(--muted); font-size: 9px; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
.research-progress-step.is-active { color: var(--accent-2); }
.research-progress-step.is-active .research-progress-marker { border: 3px solid var(--accent-2); box-shadow: 0 0 0 3px var(--accent-soft); }
.research-progress-step.is-complete { color: var(--success); }
.research-progress-step.is-complete .research-progress-marker { border-color: var(--success); background: var(--success); }
.research-progress-step.is-failed { color: var(--danger); }
.research-progress-step.is-failed .research-progress-marker { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(255, 112, 123, .1); }
@keyframes research-spin { to { transform: rotate(360deg); } }

.composer-wrap { padding: 12px 22px max(12px, env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 22%); }
.composer { width: min(850px, 100%); margin: 0 auto; padding: 11px; border: 1px solid var(--line-strong); border-radius: 19px; background: var(--panel); box-shadow: 0 14px 50px rgba(0,0,0,.18); }
.composer:focus-within { border-color: rgba(124, 92, 255, .5); box-shadow: 0 14px 50px rgba(0,0,0,.18), 0 0 0 3px var(--accent-soft); }
.composer textarea { display: block; width: 100%; max-height: 180px; resize: none; border: 0; outline: 0; padding: 2px 4px 12px; color: var(--text); background: transparent; line-height: 1.55; }
.composer textarea::placeholder { color: var(--muted); }
.composer-bottom { display: flex; align-items: center; justify-content: space-between; }
.composer-tools { display: flex; min-width: 0; align-items: center; gap: 4px; }
.composer-model { display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 70%; padding: 7px 9px; border: 0; border-radius: 9px; background: transparent; color: var(--muted-strong); cursor: pointer; }
.composer-model:hover { background: var(--panel-strong); color: var(--text); }
.composer-model span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.composer-model .model-status { width: 6px; height: 6px; }
.research-toggle { display: flex; align-items: center; gap: 6px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 9px; background: transparent; color: var(--muted); font-size: 11px; cursor: pointer; }
.research-toggle:hover { color: var(--text); background: var(--panel-strong); }
.research-toggle.active { border-color: var(--accent); background: linear-gradient(135deg, var(--accent), #5c3fe3); color: white; box-shadow: 0 5px 18px rgba(124, 92, 255, .3); }
.send-button { display: grid; place-items: center; width: 35px; height: 35px; border: 0; border-radius: 11px; background: var(--accent); color: white; font-weight: 900; cursor: pointer; }
.send-button:disabled { opacity: .35; cursor: not-allowed; }
.stop-button { background: var(--danger); font-size: 11px; }
.disclaimer { margin: 7px auto 0; color: var(--muted); text-align: center; font-size: 10px; }
.source-list { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 15px; padding-top: 12px; border-top: 1px solid var(--line); }
.source-link { display: inline-flex; max-width: 240px; align-items: center; gap: 5px; padding: 6px 9px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted-strong) !important; background: var(--panel-soft); font-size: 10px; text-decoration: none; }
.source-link:hover { border-color: rgba(124, 92, 255, .4); color: var(--accent-2) !important; }

.model-dialog { width: min(720px, calc(100% - 28px)); max-height: min(760px, calc(100dvh - 28px)); padding: 0; border: 1px solid var(--line-strong); border-radius: 20px; background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.model-dialog::backdrop { background: rgba(0, 0, 0, .66); backdrop-filter: blur(8px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 21px 22px 15px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; font-family: Manrope, sans-serif; font-size: 22px; }
.dialog-head .eyebrow { margin-bottom: 5px; }
.model-controls { padding: 8px 18px 12px; border-bottom: 1px solid var(--line); }
.model-search { margin: 6px 0 10px; padding: 11px 12px; background: var(--panel-soft); }
.filter-row { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 2px; }
.filter-chip { flex: 0 0 auto; padding: 7px 11px; border: 1px solid var(--line); border-radius: 999px; background: transparent; color: var(--muted); font-size: 11px; cursor: pointer; }
.filter-chip.active { border-color: rgba(124, 92, 255, .35); background: var(--accent-soft); color: var(--accent-2); }
.model-list { max-height: 520px; overflow-y: auto; padding: 10px; }
.model-card { display: grid; grid-template-columns: 38px minmax(0, 1fr) auto; gap: 12px; align-items: center; width: 100%; padding: 12px; border: 1px solid transparent; border-radius: 13px; background: transparent; text-align: left; cursor: pointer; }
.model-card:hover, .model-card.selected { border-color: var(--line); background: var(--panel-soft); }
.model-card.selected { border-color: rgba(124, 92, 255, .35); background: var(--accent-soft); }
.model-icon { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; background: var(--panel-strong); color: var(--accent-2); font-weight: 800; text-transform: uppercase; }
.model-copy { min-width: 0; }
.model-copy strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.model-copy small { display: block; margin-top: 3px; overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }
.model-tags { display: flex; justify-content: flex-end; gap: 5px; }
.tag { padding: 4px 7px; border-radius: 99px; background: var(--panel-strong); color: var(--muted); font-size: 9px; font-weight: 700; text-transform: uppercase; }
.tag.free { background: rgba(85, 214, 158, .12); color: var(--success); }

.login-screen { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at 50% 10%, rgba(124,92,255,.17), transparent 35%), var(--bg); z-index: 100; }
.login-card { width: min(410px, 100%); padding: 34px; border: 1px solid var(--line-strong); border-radius: 22px; background: var(--panel); box-shadow: var(--shadow); }
.login-logo { width: 48px; height: 48px; margin-bottom: 28px; font-size: 19px; }
.login-card h1 { font-size: 31px; }
.login-card > p:not(.eyebrow):not(.form-error) { margin: 8px 0 26px; color: var(--muted); }
.login-card label span { display: block; margin-bottom: 7px; color: var(--muted-strong); font-size: 12px; }
.login-card input { width: 100%; padding: 12px 13px; border: 1px solid var(--line-strong); border-radius: 11px; outline: 0; background: var(--panel-soft); color: var(--text); }
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-card button { width: 100%; margin-top: 14px; padding: 12px; border: 0; border-radius: 11px; background: var(--accent); color: white; font-weight: 800; cursor: pointer; }
.form-error { min-height: 18px; margin: 8px 0 0; color: var(--danger); font-size: 12px; }

.toast { position: fixed; right: 20px; bottom: 20px; max-width: min(380px, calc(100% - 40px)); padding: 11px 14px; border: 1px solid var(--line-strong); border-radius: 11px; background: var(--panel-strong); color: var(--text); box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); pointer-events: none; transition: .2s ease; z-index: 120; }
.toast.show { opacity: 1; transform: translateY(0); }
.sidebar-backdrop { display: none; }

@media (max-width: 760px) {
  .mobile-only { display: grid; }
  .app-shell { display: block; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(310px, 88vw); transform: translateX(-105%); box-shadow: var(--shadow); transition: transform .22s ease; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop { position: fixed; inset: 0; display: block; background: rgba(0,0,0,.56); opacity: 0; pointer-events: none; transition: opacity .22s ease; z-index: 25; }
  .sidebar-backdrop.open { opacity: 1; pointer-events: auto; }
  .sidebar-head .icon-button { margin-left: auto; }
  .topbar { height: 62px; padding: 0 12px; gap: 8px; }
  .model-pill { flex: 1; min-width: 0; max-width: 260px; }
  .model-pill-copy strong { max-width: 170px; }
  .empty-state { padding-top: 65px; }
  .suggestion-grid { grid-template-columns: 1fr; }
  .suggestion { min-height: auto; }
  .suggestion span { margin-bottom: 8px; }
  .messages { width: calc(100% - 26px); padding-top: 22px; }
  .message { gap: 9px; }
  .message.user .message-content { max-width: 92%; }
  .research-progress { padding: 12px; }
  .research-progress-steps { gap: 5px; }
  .research-progress-step { grid-template-columns: 13px minmax(0, 1fr); gap: 5px; }
  .research-progress-step small { white-space: normal; }
  .composer-wrap { padding-inline: 10px; }
  .research-toggle { justify-content: center; }
  .disclaimer { font-size: 9px; }
  .model-dialog { max-height: calc(100dvh - 14px); }
  .model-list { max-height: calc(100dvh - 225px); }
  .model-tags .tag:not(.free) { display: none; }
}

@media (max-width: 430px) {
  .topbar-actions { display: none; }
  .model-pill { max-width: none; }
  .login-card { padding: 27px 22px; }
}

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