:root {
  color-scheme: dark;
  --bg: #0b0c10;
  --panel: #12141b;
  --panel-2: #1b1e28;
  --text: #f4f4fb;
  --muted: #969bad;
  --border: #282b38;
  --accent: #a78bfa;
  --accent-2: #70e1d1;
  --accent-text: #151020;
  --danger: #ff8e98;
  --radius: 15px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(ellipse at 60% -20%, #30225333, transparent 55%),
    var(--bg);
  color: var(--text);
  font: 15px/1.6 system-ui, -apple-system, "Segoe UI", sans-serif;
}

button, input, textarea, select { font: inherit; }
button, select { cursor: pointer; }
button:disabled { opacity: .55; cursor: not-allowed; }
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

#app { min-height: 100dvh; display: flex; }

.sidebar {
  width: 270px;
  flex: 0 0 270px;
  background: #101117;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  min-height: 100dvh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  font-weight: 800;
  font-size: 17px;
  letter-spacing: -.3px;
  padding: 0 5px 25px;
}

.brand-icon, .welcome-mark {
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #11121a;
  font-weight: 900;
  border-radius: 12px;
  width: 36px;
  height: 36px;
  box-shadow: 0 4px 25px #a78bfa22;
}

.brand-icon.large {
  width: 52px;
  height: 52px;
  font-size: 23px;
  margin: auto;
  border-radius: 17px;
}

.new-chat, .sidebar-action {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 11px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  text-align: left;
  transition: background .18s, border-color .18s;
}

.new-chat {
  background: linear-gradient(110deg, #a78bfa17, #70e1d108);
  border-color: #a78bfa45;
}

.new-chat:hover, .sidebar-action:hover, .history-item:hover {
  background: var(--panel-2);
}

.history-heading {
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 1.5px;
  padding: 25px 8px 9px;
}

.history { overflow: auto; flex: 1; min-height: 70px; }

.history-item {
  width: 100%;
  display: flex;
  gap: 7px;
  align-items: center;
  color: var(--text);
  background: transparent;
  border: 0;
  border-radius: 9px;
  padding: 9px 7px;
  text-align: left;
}

.history-item.active { background: var(--panel-2); }
.history-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.history-tools { display: flex; gap: 3px; }
.mini-btn {
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 4px 6px;
  border-radius: 6px;
}
.mini-btn:hover { color: var(--text); background: var(--border); }

.sidebar-bottom {
  display: grid;
  gap: 5px;
  padding-top: 13px;
  border-top: 1px solid var(--border);
  margin-top: 12px;
}

.sidebar-action { border: 0; font-size: 13px; }

.main {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.topbar {
  height: 62px;
  flex: 0 0 62px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 25px;
  border-bottom: 1px solid #282b383d;
  background: #0b0c10bb;
}

.topbar-title { font-weight: 700; letter-spacing: -.2px; }
.account-status {
  margin-left: auto;
  font-size: 12px;
  color: var(--muted);
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 20px;
}

.icon-btn {
  background: transparent;
  color: var(--text);
  border: 0;
  font-size: 20px;
  padding: 5px 8px;
}
.menu-btn, .mobile-close { display: none; }

.auth-panel {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 25px;
}

.auth-card {
  width: min(100%, 420px);
  background: linear-gradient(145deg, #171923, #11131a);
  border: 1px solid var(--border);
  padding: 32px;
  border-radius: 23px;
  text-align: center;
  box-shadow: 0 25px 80px #0003;
}

.auth-card h1 { font-size: 25px; margin: 17px 0 4px; }
.auth-card form {
  text-align: left;
  margin-top: 24px;
  display: grid;
  gap: 9px;
}
.auth-card label, .model-label {
  font-size: 12px;
  color: var(--muted);
}
.auth-card input, .auth-card textarea {
  width: 100%;
  padding: 12px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  margin-bottom: 8px;
  outline: none;
}
.auth-card input:focus, .auth-card textarea:focus,
.composer:focus-within { border-color: var(--accent); }

.primary-btn {
  background: linear-gradient(110deg, var(--accent), #c4b5fd);
  color: var(--accent-text);
  border: 0;
  border-radius: 10px;
  padding: 12px 16px;
  font-weight: 800;
}
.primary-btn:hover { filter: brightness(1.07); }
.full { width: 100%; }
.auth-switch { color: var(--muted); font-size: 13px; margin-bottom: 0; }
.text-btn {
  border: 0;
  background: transparent;
  color: var(--accent);
  padding: 5px;
}
.form-message {
  min-height: 20px;
  font-size: 13px;
  color: var(--danger);
  overflow-wrap: anywhere;
}

.chat-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.welcome {
  margin: auto;
  width: min(calc(100% - 32px), 760px);
  text-align: center;
  padding: 35px 0 20px;
}

.welcome-mark {
  width: 62px;
  height: 62px;
  border-radius: 20px;
  margin: 0 auto 18px;
  font-size: 28px;
}

.welcome h1 {
  font-size: clamp(27px, 4vw, 42px);
  letter-spacing: -1.4px;
  line-height: 1.2;
  margin: 8px 0 12px;
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  justify-content: center;
  margin-top: 28px;
}

.suggestion, .tool-btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  transition: border-color .18s, background .18s;
}

.suggestion:hover, .tool-btn:hover {
  border-color: var(--accent);
  background: #a78bfa0c;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 27px 20px 205px;
  scroll-behavior: smooth;
}

.message {
  width: min(100%, 820px);
  margin: 0 auto 25px;
  display: flex;
  gap: 13px;
}

.message-avatar {
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: var(--panel-2);
  font-size: 11px;
  font-weight: 800;
}

.message-body {
  min-width: 0;
  flex: 1;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  padding-top: 4px;
}

.message-role {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.message.error .message-body { color: var(--danger); }

.composer-wrap {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 18px 20px 10px;
  background: linear-gradient(transparent, var(--bg) 20%);
}

.composer-tools {
  width: min(100%, 820px);
  margin: 0 auto 8px;
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
}

.model-label { font-weight: 700; }
.model-selector {
  max-width: 200px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 10px;
}

.tool-btn { font-size: 12px; padding: 7px 10px; }

.composer {
  width: min(100%, 820px);
  margin: auto;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: #171923;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 10px;
  box-shadow: 0 12px 40px #0003;
}

.composer textarea {
  flex: 1;
  min-width: 0;
  resize: none;
  max-height: 180px;
  background: transparent;
  border: 0;
  outline: none;
  color: var(--text);
  padding: 8px;
}

.send-btn {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #11121a;
  font-size: 24px;
  font-weight: 800;
}

.composer-note {
  text-align: center;
  color: var(--muted);
  font-size: 10px;
  margin: 7px 0 0;
}

#imageResult img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 12px;
  margin-top: 14px;
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 90vw;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 15px;
  display: none;
  z-index: 30;
}
.toast.show { display: block; }

body.light {
  color-scheme: light;
  --bg: #f6f6fb;
  --panel: #fff;
  --panel-2: #eeeef6;
  --text: #20212a;
  --muted: #696b78;
  --border: #dedfe7;
  --accent: #7562e8;
  --accent-2: #5acabc;
  --accent-text: #fff;
  --danger: #ba2535;
}

body.light .sidebar,
body.light .topbar,
body.light .auth-card,
body.light .composer { background: var(--panel); }

@media (max-width: 760px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    transform: translateX(-102%);
    transition: transform .2s;
    box-shadow: 15px 0 50px #0004;
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .menu-btn, .mobile-close { display: inline-block; }
  .mobile-close { margin-left: auto; }
  .topbar { padding: 0 12px; }
  .auth-panel { padding: 14px; }
  .auth-card { padding: 24px 18px; }
  .messages { padding: 20px 12px 185px; }
  .composer-wrap { padding: 15px 10px 8px; }
  .suggestions { flex-direction: column; align-items: stretch; }
  .model-selector { max-width: 145px; }
}
