:root {
  --neutral-50: 0 0% 97%;
  --neutral-100: 0 0% 95%;
  --neutral-200: 0 0% 87%;
  --neutral-300: 0 0% 62%;
  --neutral-400: 0 0% 52%;
  --neutral-500: 0 0% 39%;
  --neutral-600: 0 0% 28%;
  --neutral-700: 0 0% 21%;
  --neutral-800: 0 0% 16%;
  --neutral-900: 0 0% 13%;
  --neutral-950: 0 0% 8%;
  --neutral-1000: 0 0% 2%;
  --black: 0 0% 2%;
  --white: 0 0% 99%;
  --sidebar-w: 240px;
  --sidebar-cw: 56px;
  --accent: #6C3CE1;
}

html.light {
  color-scheme: light;
  --surface-base: #5f25cd17;
  --surface-l1: hsl(var(--neutral-50));
  --surface-l2: hsl(var(--neutral-100));
  --fg-primary: hsl(var(--neutral-1000));
  --fg-secondary: hsl(var(--neutral-500));
  --fg-tertiary: hsl(var(--neutral-400));
  --fg-invert: hsl(var(--white));
  --border-l1: hsl(var(--black) / 6%);
  --border-l2: hsl(var(--black) / 10%);
  --border-l3: hsl(var(--black) / 15%);
  --hover: hsl(var(--black) / 4%);
  --active: hsl(var(--black) / 7%);
  --input-bg: #fff;
  --input-border: hsl(var(--neutral-200) / 60%);
  --input-focus: hsl(var(--neutral-400) / 40%);
  --popover-bg: #fff;
  --scrollbar: hsl(var(--black) / 10%);
}

html.dark {
  color-scheme: dark;
  --surface-base: #0d0d0d;
  --surface-l1: #141415;
  --surface-l2: #1c1d1f;
  --fg-primary: hsl(var(--white));
  --fg-secondary: hsl(var(--neutral-300));
  --fg-tertiary: hsl(var(--neutral-400));
  --fg-invert: hsl(var(--neutral-1000));
  --border-l1: hsl(var(--white) / 7%);
  --border-l2: hsl(var(--white) / 10%);
  --border-l3: hsl(var(--white) / 16%);
  --hover: hsl(var(--white) / 6%);
  --active: hsl(var(--white) / 10%);
  --input-bg: #171718;
  --input-border: hsl(var(--white) / 8%);
  --input-focus: hsl(var(--white) / 14%);
  --popover-bg: #2a2b2e;
  --scrollbar: hsl(var(--white) / 10%);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--surface-base);
  color: var(--fg-primary);
  transition: background 0.3s, color 0.3s;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; border: none; background: none; cursor: pointer; color: inherit; }

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 0; }

/* Canvas */
#starsCanvas { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }

/* Layout */
.app-wrapper { display: flex; height: 100vh; width: 100%; position: relative; z-index: 1; }

/* ====== SIDEBAR ====== */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--surface-base);
  border-right: 1px solid var(--border-l1);
  transition: width 0.25s cubic-bezier(.4,0,.2,1), min-width 0.25s cubic-bezier(.4,0,.2,1);
  z-index: 40;
  overflow: hidden;
}
.sidebar.collapsed {
  width: var(--sidebar-cw);
  min-width: var(--sidebar-cw);
}

.light .sidebar {
    background: #fff;
}
/* Hide text in collapsed */
.sidebar.collapsed .sidebar-label,
.sidebar.collapsed .sidebar-history,
.sidebar.collapsed .sidebar-collapse-btn {
  opacity: 0;
  pointer-events: none;
  width: 0;
  overflow: hidden;
  white-space: nowrap;
}
.sidebar.collapsed .sidebar-item { gap: 0px; }
.sidebar.collapsed .sidebar-bottom { border-top: none; }

.sidebar-header {
  height: 52px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  flex-shrink: 0;
  justify-content: space-between;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  padding: 2px;
  border-radius: 0;
  flex-shrink: 0;
  transition: opacity 0.15s;
}
.sidebar-logo:hover { opacity: 0.8; }
.sidebar-logo-img { border-radius: 0; }

.sidebar-collapse-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 0;
  color: var(--fg-tertiary);
  transition: all 0.15s;
  flex-shrink: 0;
}
.sidebar-collapse-btn:hover { background: var(--hover); color: var(--fg-primary); }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 6px 8px;
  flex-shrink: 0;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  border-radius: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--fg-secondary);
  transition: all 0.12s;
  cursor: pointer;
  width: 100%;
  text-align: left;
  white-space: nowrap;
}
.sidebar-item:hover { background: var(--hover); color: var(--fg-primary); }
.sidebar-item.active { background: var(--active); color: var(--fg-primary); }

.sidebar-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.sidebar-label {
  transition: opacity 0.2s;
}

.sidebar-history {
  flex: 1;
  overflow-y: auto;
  padding: 6px 10px;
  transition: opacity 0.2s;
}

.sidebar-history-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--fg-tertiary);
  padding: 10px 10px 6px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.sidebar-history-item {
  display: block;
  padding: 7px 10px;
  border-radius: 0;
  font-size: 13px;
  color: var(--fg-tertiary);
  transition: all 0.12s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-history-item:hover { background: var(--hover); color: var(--fg-primary); }
.sidebar-history-item.active { color: var(--fg-primary); }

.sidebar-bottom {
  padding: 10px 8px;
  border-top: 1px solid var(--border-l1);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px;
  border-radius: 0;
  cursor: pointer;
  transition: background 0.12s;
}
.sidebar-user:hover { background: var(--hover); }

.sidebar-user-avatar {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sidebar-user-avatar img { border-radius: 0; }

/* ====== MAIN ====== */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
}

/* Top nav */
.top-nav {
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  flex-shrink: 0;
  z-index: 25;
}
.top-nav-left { display: flex; align-items: center; gap: 4px; }
.top-nav-center { flex: 1; }
.top-nav-right { display: flex; align-items: center; gap: 4px; }

.sidebar-open-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 0;
  color: var(--fg-secondary);
  transition: all 0.15s;
}
.sidebar-open-btn:hover { background: var(--hover); color: var(--fg-primary); }

/* Only show open btn when sidebar is collapsed */
.sidebar:not(.collapsed) ~ .main-area .sidebar-open-btn { opacity: 0; pointer-events: none; }

.nav-text-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 10px;
  border-radius: 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-primary);
  transition: background 0.15s;
}
.nav-text-btn:hover { background: var(--hover); }

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 0;
  color: var(--fg-secondary);
  transition: all 0.15s;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--hover); color: var(--fg-primary); }

.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: block; }
html.light .theme-toggle .icon-sun { display: block; }
html.light .theme-toggle .icon-moon { display: none; }

.center-logo-light { display: none; }
.center-logo-dark { display: block; }
html.light .center-logo-light { display: block; }
html.light .center-logo-dark { display: none; }

/* ====== CHAT CONTENT ====== */
.chat-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 0 16px 20px;
}

.chat-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  width: 100%;
  max-width: 900px;
}

.center-logo {
  display: flex;
  align-items: center;
  justify-content: center;
}
.center-logo img { max-height: 56px; width: auto; }

/* Model selector */
.model-selector {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: center;
}

.model-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 0;
  border: 1px solid var(--border-l2);
  background: var(--input-bg);
  color: var(--fg-secondary);
  cursor: pointer;
  transition: all 0.15s;
}
.model-btn:hover {
  background: var(--hover);
  color: var(--fg-primary);
  border-color: var(--border-l3);
}
.model-btn.active {
    color: var(--fg-primary);
    border-color: #5d25cd;
}
.light .model-btn.active {
    background: #fff;
}

.model-btn-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.model-btn-icon img { width: 20px; height: 20px; border-radius: 0; }

.model-btn-info { display: flex; flex-direction: column; line-height: 1.2;
    align-items: flex-start; }
.model-btn-name { font-size: 12px; font-weight: 600; }
.model-btn-version { font-size: 10px; color: var(--fg-tertiary); }

/* ====== CHAT INPUT (centered, in chat-center) ====== */
.chat-input-area {
  width: 100%;
  max-width: 900px;
}

.chat-input-box {
  background: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: 0;
  padding: 6px 8px 6px 18px;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.chat-input-box:focus-within {
  border-color: #5d25cd;
  box-shadow: 0 0 20px 10px rgb(87 35 190 / 10%);
}

.chat-input-editor {
  flex: 1;
  min-height: 24px;
  max-height: 160px;
  padding: 10px 0;
  font-size: 15px;
  line-height: 1.5;
  outline: none;
  overflow-y: auto;
  color: var(--fg-primary);
  word-break: break-word;
}
.chat-input-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--fg-tertiary);
  pointer-events: none;
}

.chat-input-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  padding-bottom: 4px;
}

.chat-input-attach,
.chat-input-voice {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 0;
  color: var(--fg-tertiary);
  transition: all 0.15s;
}
.chat-input-attach:hover,
.chat-input-voice:hover {
  background: var(--hover);
  color: var(--fg-primary);
}

.chat-input-send {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 0;
  background: var(--accent);
  color: #fff;
  transition: all 0.15s;
}
.chat-input-send:disabled { opacity: 0.25; cursor: default; }
.chat-input-send:not(:disabled):hover { opacity: 0.85; }

/* ====== MESSAGES ====== */
.messages-container {
  display: flex;
  flex-direction: column;
  gap: 24px;
  width: 100%;
  max-width: 900px;
  padding: 20px 0;
}

.message { display: flex; gap: 8px; width: 100%; }

/* User message: avatar on right, with background/border/padding */
.message.user-message {
  flex-direction: row-reverse;
}
.message.user-message .message-content {    
  padding: 12px 12px 18px 18px;
  background: var(--surface-l2);
  border: 1px solid var(--border-l2);
  max-width: 80%;
}

.message-avatar {
  width: 28px;
  height: 28px;
  border-radius: 0;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
}
.message-avatar.user { background: var(--border-l2); color: #fff; }
.message-avatar.assistant { color: var(--fg-primary); }

.message-content {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  line-height: 1.6;
  color: var(--fg-primary);
}

/* Model name label in AI messages */
.model-label {
  font-size: 11px;
  color: var(--fg-tertiary);
  margin-bottom: 2px;
  font-weight: 500;
    display: inline-block;
    padding: 6px 8px;
    background: var(--surface-l2);
}

/* ====== BOTTOM INPUT WRAPPER (chat mode) ====== */
.input-wrapper-bottom {
  flex-shrink: 0;
}
.input-wrapper-bottom .chat-input-area {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 16px 12px;
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0;
    transform: translateX(-100%);
    z-index: 50;
  }
  .sidebar:not(.collapsed) { transform: translateX(0); }
  .sidebar.collapsed { transform: translateX(-100%); }
  .sidebar-open-btn { opacity: 1 !important; pointer-events: auto !important; }
  .model-btn { padding: 7px 10px; gap: 6px; }
  .nav-text-btn span { display: none; }
}