:root {
  --bg: #050607;
  --panel: #0f1115;
  --border: #2a2f38;

  --text: #d1d5db;
  --text-strong: #e5e7eb;
  --muted: #9ca3af;

  --accent: #16d3ff;
  --accent-2: #0ea5e9;

  --user-bubble: #1b1d22;
  --ai-bubble: #0d2028;

  --danger: #ef4444;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, Arial, sans-serif;
}

body {
  min-height: 100vh;
}

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

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.error {
  color: var(--danger) !important;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  border-right: 1px solid var(--border);
  background: #090a0d;
  padding: 14px;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.sidebar-top {
  margin-bottom: 14px;
  flex-shrink: 0;
}

.sidebar-section + .sidebar-section {
  margin-top: 18px;
}

.sidebar-heading {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.conversation-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 180px;
  overflow-y: auto;
  padding-right: 4px;
}

.nav-item,
.conversation-item {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  transition: border-color 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.nav-item:hover,
.conversation-item:hover,
.conversation-item.active {
  color: var(--text-strong);
  border-color: var(--accent);
  background: rgba(22, 211, 255, 0.08);
}

.conversation-item-empty {
  opacity: 0.75;
}

.conversation-item-title {
  font-weight: 600;
  font-size: 13px;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-item-summary {
  display: none;
}

/* Main */
.main-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
}

/* Header */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(8, 9, 12, 0.95);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-logo {
  width: 34px;
  height: 34px;
  object-fit: contain;
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text-strong);
}

.brand-subtitle {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.2;
}

.topbar-controls {
  display: flex;
  align-items: center;
  gap: 14px;
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.control-group-threshold {
  min-width: 300px;
}

.control-label {
  font-size: 11px;
  color: var(--muted);
}

.control-input {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
}

.threshold-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.threshold-row input[type="range"] {
  width: 160px;
}

.threshold-value {
  min-width: 42px;
  text-align: right;
  font-weight: 700;
  font-size: 13px;
  color: var(--text-strong);
}

.auth-box {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.user-display {
  font-size: 13px;
  color: var(--text);
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
}

/* Auth buttons */
.auth-btn {
  min-width: 82px;
  height: 36px;
  padding: 0 14px;
  border-radius: 10px;
  font-weight: 600;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.auth-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(22, 211, 255, 0.12);
}

.auth-btn:active {
  transform: translateY(0);
}

#logoutBtn {
  background: #111827;
  border: 1px solid #334155;
  color: var(--text-strong);
}

#logoutBtn:hover {
  border-color: var(--accent);
}

/* Chat */
.chat-window {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  min-height: 0;
}

.empty-state {
  max-width: 700px;
  min-height: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: var(--muted);
  text-align: center;
}

.empty-state-logo {
  width: 180px;
  height: auto;
  margin-bottom: 20px;
  object-fit: contain;
}

.empty-state h1 {
  margin: 0 0 10px;
  color: var(--text-strong);
  font-size: 40px;
  font-weight: 700;
}

.message-row {
  display: flex;
  flex-direction: column;
  margin-bottom: 18px;
}

.message-row.user {
  align-items: flex-end;
}

.message-row.ai {
  align-items: flex-start;
}

.message-bubble {
  max-width: min(820px, 78%);
  border-radius: 18px;
  padding: 16px 18px;
  line-height: 1.65;
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
}

.message-row.user .message-bubble {
  background: var(--user-bubble);
  border: 1px solid #30343c;
  color: #d8dee6;
}

.message-row.ai .message-bubble {
  background: var(--ai-bubble);
  border: 1px solid #173848;
  color: #d1d5db;
}

.message-meta {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  max-width: min(820px, 78%);
}

/* Markdown/code inside message bubbles */
.message-bubble p {
  margin: 0 0 12px;
}

.message-bubble p:last-child {
  margin-bottom: 0;
}

.message-bubble ul,
.message-bubble ol {
  margin: 8px 0 12px 20px;
  padding: 0;
}

.message-bubble li {
  margin-bottom: 6px;
}

.message-bubble h1,
.message-bubble h2,
.message-bubble h3,
.message-bubble h4 {
  margin: 16px 0 10px;
  line-height: 1.25;
  color: var(--text-strong);
}

.message-bubble h1:first-child,
.message-bubble h2:first-child,
.message-bubble h3:first-child,
.message-bubble h4:first-child {
  margin-top: 0;
}

.message-bubble code {
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 13px;
  color: #a7f3d0;
}

.message-bubble p code,
.message-bubble li code {
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 6px;
  border-radius: 6px;
}

.message-bubble pre {
  margin: 0;
  overflow-x: auto;
  padding: 16px;
  background: #020617;
  border: 0;
  border-radius: 0;
}

.message-bubble pre code {
  display: block;
  background: transparent;
  padding: 0;
  border-radius: 0;
  color: #cbd5e1;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 13px;
  line-height: 1.6;
}

/* Code blocks with toolbar */
.code-block-wrap {
  margin: 12px 0;
  border: 1px solid #1f2a44;
  border-radius: 12px;
  overflow: hidden;
  background: #020617;
}

.code-toolbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  padding: 8px 10px;
  background: #0f172a;
  border-bottom: 1px solid #1f2a44;
}

.code-copy-btn {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid #334155;
  background: #111827;
  color: #d1d5db;
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  box-shadow: none;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}

.code-copy-btn:hover {
  background: #0ea5e9;
  border-color: #0ea5e9;
  color: #ffffff;
}

.code-copy-btn:active {
  transform: translateY(1px);
}

/* Composer */
.composer {
  border-top: 1px solid var(--border);
  padding: 12px 18px;
  background: #090a0d;
  flex-shrink: 0;
}

.composer-input {
  width: 100%;
  resize: vertical;
  min-height: 72px;
  background: #06080b;
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 14px;
  padding: 14px;
  outline: none;
}

.composer-input::placeholder {
  color: #7f8794;
}

.composer-input:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
}

.composer-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  gap: 16px;
}

.status-text {
  font-size: 13px;
  color: var(--muted);
}

/* Buttons */
.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text-strong);
  border-radius: 12px;
  padding: 12px 18px;
  font-weight: 600;
}

.btn:hover {
  border-color: var(--accent);
}

.btn-primary {
  background: linear-gradient(135deg, #0891b2, #0f766e);
  border: 1px solid #22d3ee;
  color: #ffffff;
}

.btn-primary:hover {
  border-color: #67e8f9;
  box-shadow: 0 10px 24px rgba(34, 211, 238, 0.18);
}

.btn-full {
  width: 100%;
}

/* Login modal */
#loginModal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.72);
  z-index: 9999;
}

#loginModal.hidden {
  display: none !important;
}

.login-card {
  width: 100%;
  max-width: 460px;
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 18px;
  padding: 24px;
  box-sizing: border-box;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}

.login-card h2 {
  margin: 0 0 18px;
  color: var(--text-strong);
  font-size: 28px;
}

.login-form-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-form-row input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid #334155;
  background: #111827;
  color: var(--text);
  font-size: 15px;
  box-sizing: border-box;
}

.login-actions {
  display: flex;
  gap: 12px;
  margin-top: 18px;
  flex-wrap: wrap;
}

.login-actions button {
  padding: 12px 18px;
  border-radius: 12px;
  border: 1px solid #334155;
  background: #111827;
  color: var(--text-strong);
  cursor: pointer;
}

.login-actions button.primary {
  background: #0369a1;
  border-color: #0284c7;
}

#loginStatus {
  min-height: 20px;
  margin-top: 12px;
  font-size: 14px;
  color: #cbd5e1;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .topbar-controls {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .control-group-threshold {
    min-width: 0;
  }

  .message-bubble,
  .message-meta {
    max-width: 100%;
  }

  .composer-actions {
    flex-direction: column;
    align-items: stretch;
  }

}


::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: #475569;
}

/* Additional Project Inputs textarea scrollbar */

textarea {
  scrollbar-width: thin;
  scrollbar-color: #2dd4bf #020617;
}

