/* ============================================
   Agent — Coding Assistant UI
   RetroEarthy palette · JetBrains Mono + Syne
   ============================================ */

:root {
  --bg-base:       #0A1E28;
  --bg-surface:    #0f2535;
  --bg-elevated:   #152d3d;
  --bg-input:      #0d2130;
  --accent:        #F07000;
  --accent-dim:    #b85500;
  --accent-glow:   rgba(240, 112, 0, 0.15);
  --accent-subtle: rgba(240, 112, 0, 0.08);
  --text-primary:  #e8dcc8;
  --text-secondary:#8fa4b0;
  --text-muted:    #4a6070;
  --border:        rgba(240, 112, 0, 0.12);
  --border-strong: rgba(240, 112, 0, 0.25);
  --user-bubble:   #1a3040;
  --scrollbar:     #1e3545;
  --radius:        10px;
  --font-ui:       'Syne', sans-serif;
  --font-mono:     'JetBrains Mono', monospace;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg-base);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ---- Layout ---- */
#app {
  display: grid;
  grid-template-columns: 240px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ---- Sidebar ---- */
#sidebar {
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
}

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

.logo-icon {
  font-size: 20px;
  color: var(--accent);
  line-height: 1;
  filter: drop-shadow(0 0 6px var(--accent));
}

.logo-text {
  font-family: var(--font-ui);
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

#new-chat-btn {
  background: var(--accent-subtle);
  border: 1px solid var(--border-strong);
  color: var(--accent);
  border-radius: 6px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
#new-chat-btn:hover { background: var(--accent-glow); border-color: var(--accent); }

.model-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 12px 16px 4px;
  padding: 7px 10px;
  background: var(--accent-subtle);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 11px;
  color: var(--accent);
  font-family: var(--font-mono);
}

.model-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
  animation: pulse 2s infinite;
  flex-shrink: 0;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.sidebar-section-label {
  font-size: 10px;
  font-family: var(--font-ui);
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 14px 16px 6px;
}

#history-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
}

.history-item {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.12s, color 0.12s;
  font-family: var(--font-mono);
  margin-bottom: 1px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.history-item::before {
  content: '›';
  color: var(--text-muted);
  font-size: 14px;
  flex-shrink: 0;
}
.history-item:hover { background: var(--bg-elevated); color: var(--text-primary); }
.history-item.active {
  background: var(--accent-subtle);
  color: var(--accent);
  border: 1px solid var(--border);
}
.history-item.active::before { color: var(--accent); }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.settings-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-size: 12px;
  cursor: pointer;
  padding: 4px 0;
  transition: color 0.15s;
}
.settings-btn:hover { color: var(--accent); }

/* ---- Main ---- */
#main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

#chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 32px 0;
  scroll-behavior: smooth;
}

/* ---- Welcome Screen ---- */
#welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 140px);
  text-align: center;
  padding: 40px;
  animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.welcome-glyph {
  font-size: 56px;
  color: var(--accent);
  filter: drop-shadow(0 0 20px rgba(240,112,0,0.4));
  margin-bottom: 16px;
  animation: floatGlyph 4s ease-in-out infinite;
}

@keyframes floatGlyph {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-8px); }
}

#welcome-screen h1 {
  font-family: var(--font-ui);
  font-size: 48px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.welcome-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 40px;
  font-family: var(--font-mono);
}

.starter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  max-width: 540px;
  width: 100%;
}

.starter-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: left;
  cursor: pointer;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.4;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}
.starter-card:hover {
  background: var(--bg-elevated);
  border-color: var(--border-strong);
  color: var(--text-primary);
  transform: translateY(-1px);
}
.starter-icon { font-size: 16px; flex-shrink: 0; }

/* ---- Messages ---- */
#messages {
  display: flex;
  flex-direction: column;
  gap: 0;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  padding: 0 24px;
}

.message {
  padding: 20px 0;
  border-bottom: 1px solid var(--border);
  animation: msgIn 0.25s ease;
}
.message:last-child { border-bottom: none; }

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
  font-family: var(--font-ui);
  font-weight: 700;
}

.msg-avatar.user {
  background: var(--user-bubble);
  color: var(--accent);
  border: 1px solid var(--border-strong);
}

.msg-avatar.assistant {
  background: var(--accent-subtle);
  color: var(--accent);
  border: 1px solid var(--border-strong);
  font-size: 15px;
}

.msg-role {
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.msg-body {
  padding-left: 38px;
  color: var(--text-primary);
  line-height: 1.75;
}

/* Markdown inside messages */
.msg-body p { margin-bottom: 12px; }
.msg-body p:last-child { margin-bottom: 0; }
.msg-body strong { color: var(--accent); font-weight: 600; }
.msg-body em { color: var(--text-secondary); font-style: italic; }
.msg-body a { color: var(--accent); text-decoration: underline; }

.msg-body ul, .msg-body ol {
  padding-left: 20px;
  margin-bottom: 12px;
}
.msg-body li { margin-bottom: 4px; }

.msg-body h1, .msg-body h2, .msg-body h3 {
  font-family: var(--font-ui);
  color: var(--text-primary);
  margin: 20px 0 8px;
}
.msg-body h1 { font-size: 20px; }
.msg-body h2 { font-size: 17px; }
.msg-body h3 { font-size: 14px; }

/* Code blocks */
.msg-body pre {
  background: #060f14;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  overflow-x: auto;
  margin: 14px 0;
  position: relative;
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.code-lang { color: var(--accent); font-weight: 500; }

.copy-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 10px;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.copy-btn:hover { border-color: var(--accent); color: var(--accent); }
.copy-btn.copied { color: #4ade80; border-color: #4ade80; }

.msg-body pre code {
  display: block;
  padding: 14px;
  font-size: 13px;
  line-height: 1.6;
  background: none !important;
  font-family: var(--font-mono);
}

/* Inline code */
.msg-body code:not(pre code) {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 12.5px;
  color: #f4b86a;
  font-family: var(--font-mono);
}

/* Attached file chips in message */
.msg-files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
  padding-left: 38px;
}

.msg-file-chip {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 3px 9px;
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  display: flex;
  align-items: center;
  gap: 5px;
}

/* Thinking / streaming indicator */
.typing-indicator {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 8px 0;
}
.typing-indicator span {
  width: 7px;
  height: 7px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
  opacity: 0.7;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40%           { transform: translateY(-6px); }
}

/* ---- Input Area ---- */
#input-area {
  padding: 16px 24px 20px;
  background: linear-gradient(to top, var(--bg-base) 80%, transparent);
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  position: relative;
}

#input-wrapper {
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
#input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#file-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  padding: 3px 8px;
  font-size: 11.5px;
  color: var(--accent);
  font-family: var(--font-mono);
}

.chip-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  padding: 0;
  line-height: 1;
  transition: color 0.12s;
}
.chip-remove:hover { color: #f87171; }

#prompt-input {
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.6;
  resize: none;
  width: 100%;
  min-height: 24px;
  max-height: 200px;
  overflow-y: auto;
}
#prompt-input::placeholder { color: var(--text-muted); }

#input-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

#attach-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 6px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
#attach-btn:hover { border-color: var(--accent); color: var(--accent); }
#file-input { display: none; }

#send-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  border-radius: 7px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
#send-btn:hover:not(:disabled) { background: #e06500; transform: scale(1.05); }
#send-btn:disabled { background: var(--text-muted); cursor: not-allowed; opacity: 0.4; }

.input-hint {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 8px;
  font-family: var(--font-mono);
}
.input-hint strong { color: var(--text-secondary); }
#status-text { color: var(--accent); }
#status-text.offline { color: #f87171; }

/* ---- Modal ---- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 14, 20, 0.8);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }

.modal-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 28px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.modal-header h2 {
  font-family: var(--font-ui);
  font-size: 20px;
  font-weight: 700;
}

#close-settings {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  transition: color 0.12s;
}
#close-settings:hover { color: var(--text-primary); }

.modal-box label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-ui);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 16px;
}

.modal-box input,
.modal-box select,
.modal-box textarea {
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  padding: 9px 12px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}
.modal-box input:focus,
.modal-box select:focus,
.modal-box textarea:focus { border-color: var(--accent); }
.modal-box select option { background: var(--bg-surface); }

#save-settings {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
  margin-top: 4px;
}
#save-settings:hover { background: #e06500; }

/* ---- Error / info banner ---- */
.banner {
  max-width: 800px;
  margin: 12px auto;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.banner.error {
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.25);
  color: #f87171;
}
.banner.info {
  background: var(--accent-subtle);
  border: 1px solid var(--border);
  color: var(--accent);
}

/* Responsive */
@media (max-width: 680px) {
  #app { grid-template-columns: 1fr; }
  #sidebar { display: none; }
  .starter-grid { grid-template-columns: 1fr; }
}

/* ===================== AUTH ===================== */
#auth-modal {
  position: fixed;
  inset: 0;
  background: var(--bg-base);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 24px;
}
#auth-modal.hidden { display: none; }

.auth-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 32px 80px rgba(0,0,0,0.6);
  animation: fadeIn 0.3s ease;
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.auth-tagline {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-bottom: 28px;
}

.auth-heading {
  font-family: var(--font-ui);
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.auth-input {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  box-sizing: border-box;
  display: block;
  width: 100%;
  background: var(--bg-elevated) !important;
  border: 1px solid var(--border-strong) !important;
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text-primary) !important;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  /* Kill browser autofill yellow */
  -webkit-box-shadow: 0 0 0px 1000px var(--bg-elevated) inset !important;
  -webkit-text-fill-color: var(--text-primary) !important;
}
.auth-input:focus {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 3px var(--accent-glow) !important;
  -webkit-box-shadow: 0 0 0px 1000px var(--bg-elevated) inset, 0 0 0 3px var(--accent-glow) !important;
}
.auth-input::placeholder { color: var(--text-muted); opacity: 1; }

.auth-btn {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  padding: 11px;
  color: #fff;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  width: 100%;
  transition: background 0.15s, transform 0.1s;
  margin-top: 4px;
}
.auth-btn:hover { background: #e06500; transform: translateY(-1px); }

.auth-error {
  font-size: 12px;
  color: #f87171;
  font-family: var(--font-mono);
  min-height: 16px;
  margin: -4px 0;
}

.auth-switch {
  font-size: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  text-align: center;
}

.auth-link {
  background: none;
  border: none;
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}
.auth-link:hover { color: #ff8c1a; }

/* ===================== USER ROW ===================== */
.user-row {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 10px;
  background: var(--accent-subtle);
  border: 1px solid var(--border);
  border-radius: 7px;
  margin-bottom: 8px;
}

.user-icon { font-size: 13px; }

.user-name {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 2px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}
.logout-btn:hover { color: #f87171; background: rgba(248,113,113,0.1); }

/* ===================== DELETE CHAT ===================== */
.history-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--text-secondary);
  transition: background 0.12s, color 0.12s;
  font-family: var(--font-mono);
  margin-bottom: 1px;
}
.history-item:hover { background: var(--bg-elevated); color: var(--text-primary); }
.history-item.active {
  background: var(--accent-subtle);
  color: var(--accent);
  border: 1px solid var(--border);
}

.history-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.history-delete {
  background: none;
  border: none;
  color: transparent;
  font-size: 11px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 3px;
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.12s, background 0.12s;
}
.history-item:hover .history-delete { color: var(--text-muted); }
.history-delete:hover { color: #f87171!important; background: rgba(248,113,113,0.1); }
