/* ===== kGPT Global Styles ===== */
:root {
  --bg: #0b0d12;
  --surface: #161821;
  --surface2: #1f2231;
  --border: #2a2d3d;
  --accent: #6366f1; /* Indigo */
  --accent-hover: #4f46e5;
  --accent2: #10b981; /* Emerald */
  --text: #f3f4f6;
  --text-muted: #9ca3af;
  --danger: #ef4444;
  --success: #10b981;
  --warning: #f59e0b;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 20px rgba(0,0,0,0.3);
  --chat-bubble-user: #6366f1;
  --chat-bubble-assistant: #1f2231;
}

body.light-theme {
  --bg: #f9fafb;
  --surface: #ffffff;
  --surface2: #f3f4f6;
  --border: #e5e7eb;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent2: #059669;
  --text: #111827;
  --text-muted: #6b7280;
  --danger: #dc2626;
  --success: #059669;
  --warning: #d97706;
  --shadow: 0 4px 20px rgba(0,0,0,0.05);
  --chat-bubble-user: #4f46e5;
  --chat-bubble-assistant: #ffffff;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 20px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500; cursor: pointer;
  border: none; transition: all 0.2s; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.85; }
.btn-icon { padding: 8px; border-radius: var(--radius-sm); background: var(--surface2); border: 1px solid var(--border); color: var(--text); cursor: pointer; transition: all 0.2s; }
.btn-icon:hover { background: var(--border); }
.btn-sm { padding: 6px 14px; font-size: 13px; }

/* ===== Inputs ===== */
input, textarea, select {
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 14px; font-size: 14px; width: 100%;
  transition: border-color 0.2s; outline: none; font-family: inherit;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
input::placeholder, textarea::placeholder { color: var(--text-muted); }

/* ===== Auth Pages ===== */
.auth-page {
  min-height: 100vh; display: flex; align-items: center;
  justify-content: center; padding: 20px;
  background: radial-gradient(ellipse at 50% 0%, rgba(108,99,255,0.15) 0%, transparent 60%), var(--bg);
}

.auth-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 40px; width: 100%; max-width: 420px;
  box-shadow: var(--shadow);
}

.auth-logo {
  text-align: center; margin-bottom: 32px;
}
.auth-logo h1 { font-size: 32px; font-weight: 700; color: var(--accent); }
.auth-logo p { color: var(--text-muted); font-size: 14px; margin-top: 4px; }

.auth-tabs {
  display: flex; margin-bottom: 28px;
  background: var(--surface2); border-radius: var(--radius-sm);
  padding: 4px;
}
.auth-tab {
  flex: 1; padding: 8px; text-align: center; cursor: pointer;
  border-radius: 6px; font-size: 14px; font-weight: 500;
  color: var(--text-muted); transition: all 0.2s;
}
.auth-tab.active { background: var(--accent); color: #fff; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
.form-group input { display: block; }

.auth-error {
  background: rgba(255,79,106,0.1); border: 1px solid rgba(255,79,106,0.3);
  color: var(--danger); padding: 10px 14px; border-radius: var(--radius-sm);
  font-size: 13px; margin-bottom: 16px; display: none;
}
.auth-error.show { display: block; }

/* ===== Main App Layout ===== */
.app-layout {
  display: grid; grid-template-columns: 260px 1fr;
  height: 100vh; overflow: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px; overflow-y: auto;
  width: 260px;
}

.new-chat-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: 14px; cursor: pointer; transition: all 0.15s;
  color: var(--text); background: var(--surface2); border: 1px solid var(--border);
  text-align: left; font-family: inherit; margin-bottom: 12px;
}
.new-chat-btn:hover { background: var(--border); }
.new-chat-btn .icon { font-size: 18px; }

.sidebar-bottom {
  margin-top: auto; padding: 0;
}
.user-info {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--surface2); margin-bottom: 8px;
}
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); display: flex; align-items: center;
  justify-content: center; font-size: 14px; font-weight: 600; flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 500; }
.user-email { font-size: 11px; color: var(--text-muted); }

/* ===== Chat Area ===== */
.chat-area {
  display: flex; flex-direction: column; overflow: hidden;
}

.chat-header {
  padding: 16px 24px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  background: var(--surface); flex-shrink: 0;
}
.chat-header-left h2 { font-size: 18px; font-weight: 600; color: var(--accent); }
.chat-header-actions { display: flex; gap: 8px; }

.theme-toggle-btn-header {
  padding: 8px; border-radius: var(--radius-sm); background: var(--surface2);
  border: 1px solid var(--border); color: var(--text); cursor: pointer;
  transition: all 0.2s; font-size: 18px;
}
.theme-toggle-btn-header:hover { background: var(--border); }

.chat-messages-container {
  flex: 1;
  overflow-y: auto;
  display: flex;
  justify-content: center;
  width: 100%;
}

.chat-messages {
  width: 100%;
  max-width: 800px;
  padding: 40px 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.message {
  display: flex;
  gap: 12px;
  width: 100%;
  animation: fadeIn 0.2s ease;
}
.message.user { flex-direction: row-reverse; align-self: flex-end; }
.message.assistant { align-self: flex-start; }

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

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
.message.user .message-avatar { background: var(--accent); }
.message.assistant .message-avatar { background: var(--surface2); border: 1px solid var(--border); }

.message-content {
  background: var(--chat-bubble-assistant);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 14px;
  max-width: calc(100% - 48px);
  line-height: 1.7;
  color: var(--text);
}
.message.user .message-content {
  background: var(--chat-bubble-user);
  border-color: var(--chat-bubble-user);
  color: #ffffff !important;
}

.message-content pre {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px; overflow-x: auto;
  margin: 8px 0; font-size: 13px;
}
.message-content code:not(pre code) {
  background: var(--bg); padding: 2px 6px;
  border-radius: 4px; font-size: 12px;
}
.message-time { font-size: 11px; color: var(--text-muted); margin-top: 6px; }

.typing-indicator {
  display: flex; gap: 4px; align-items: center; padding: 4px 0;
}
.typing-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted);
  animation: typing 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); } 30% { opacity: 1; transform: scale(1); } }

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-muted);
  width: 100%;
}
.empty-state .big-icon { font-size: 56px; opacity: 0.4; }
.empty-state h3 { font-size: 22px; color: var(--text); font-weight: 700; }
.empty-state p { font-size: 14px; text-align: center; max-width: 460px; color: var(--text-muted); line-height: 1.5; }

/* ===== Chat Input ===== */
.chat-input-area {
  padding: 16px 24px; border-top: 1px solid var(--border);
  background: var(--surface); flex-shrink: 0;
}
.input-row {
  display: flex; gap: 10px; align-items: center;
}
.input-wrapper {
  flex: 1; position: relative;
}
.input-wrapper textarea {
  resize: none; max-height: 160px; padding-right: 12px;
  border-radius: var(--radius); line-height: 1.6;
}

.send-btn {
  width: 44px; height: 44px; border-radius: var(--radius-sm);
  background: var(--accent); border: none; color: #fff;
  font-size: 18px; cursor: pointer; transition: all 0.2s;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.send-btn:hover { background: var(--accent-hover); transform: scale(1.05); }
.send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.input-hints {
  display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap;
}
.hint-chip {
  font-size: 11px; padding: 3px 10px; border-radius: 20px;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text-muted); cursor: pointer; transition: all 0.15s;
}
.hint-chip:hover { border-color: var(--accent); color: var(--accent); }

/* ===== Toast ===== */
.toast-container {
  position: fixed; bottom: 24px; right: 24px;
  display: flex; flex-direction: column; gap: 8px; z-index: 1000;
}
.toast {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 16px;
  font-size: 13px; box-shadow: var(--shadow);
  animation: slideIn 0.2s ease; max-width: 300px;
  display: flex; align-items: center; gap: 8px;
}
.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }
.toast.warning { border-color: var(--warning); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

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

/* ===== Suggestions Grid ===== */
.suggestions-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 760px;
  margin-top: 32px;
}
.suggestion-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.suggestion-card:hover {
  background: var(--surface2);
  border-color: var(--accent);
  transform: translateY(-2px);
}
.suggestion-icon {
  font-size: 20px;
  margin-bottom: 4px;
}
.suggestion-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
}
.suggestion-text {
  font-size: 12px;
  color: var(--text-muted);
}

@media (max-width: 600px) {
  .suggestions-grid {
    grid-template-columns: 1fr;
  }
}

/* ===== Centered Input Area ===== */
.input-container-centered {
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.input-disclaimer {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 4px;
}

/* ===== Tool Badges in Assistant Messages ===== */
.tool-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--accent);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}


/* ===== Phase 1 polish: markdown, code blocks, message actions ===== */
.message-body { display: flex; flex-direction: column; min-width: 0; max-width: calc(100% - 48px); }
.message.user .message-body { align-items: flex-end; }

/* Rendered markdown */
.md { word-wrap: break-word; overflow-wrap: anywhere; }
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 14px 0 8px; line-height: 1.3; font-weight: 600; }
.md h1 { font-size: 20px; }
.md h2 { font-size: 18px; }
.md h3 { font-size: 16px; }
.md h4 { font-size: 14px; }
.md p { margin: 8px 0; }
.md ul, .md ol { margin: 8px 0; padding-left: 22px; }
.md li { margin: 4px 0; }
.md a { color: var(--accent); text-decoration: underline; }
.md blockquote {
  margin: 8px 0; padding: 4px 12px;
  border-left: 3px solid var(--border); color: var(--text-muted);
}
.md hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

/* Markdown tables */
.md table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 13px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; vertical-align: top; }
.md thead th { background: var(--surface2); font-weight: 600; }
.md tbody tr:nth-child(even) { background: rgba(127, 127, 127, 0.06); }

/* Code blocks + copy button */
.message-content pre { position: relative; padding-top: 30px; }
.message-content pre code { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }
.code-copy-btn {
  position: absolute; top: 6px; right: 6px;
  font-size: 11px; padding: 3px 8px; border-radius: 6px;
  background: var(--surface2); color: var(--text-muted);
  border: 1px solid var(--border); cursor: pointer; opacity: 0; transition: opacity 0.15s;
}
.message-content pre:hover .code-copy-btn { opacity: 1; }
.code-copy-btn:hover { color: var(--text); }

/* Per-message action buttons */
.message-actions { display: flex; gap: 6px; margin-top: 8px; opacity: 0; transition: opacity 0.15s; }
.message:hover .message-actions { opacity: 1; }
.msg-action-btn {
  font-size: 12px; padding: 4px 10px; border-radius: 8px;
  background: transparent; color: var(--text-muted);
  border: 1px solid var(--border); cursor: pointer; font-family: inherit;
}
.msg-action-btn:hover { background: var(--surface2); color: var(--text); }

/* Lock the page to the viewport so only inner panels scroll (removes the outer scrollbar) */
html, body { height: 100vh; overflow: hidden; }

/* ===== Artifacts-style live preview ===== */
.code-preview-btn {
  position: absolute; top: 6px; right: 54px;
  font-size: 11px; padding: 3px 8px; border-radius: 6px;
  background: var(--accent); color: #fff;
  border: none; cursor: pointer; opacity: 0; transition: opacity 0.15s;
}
.message-content pre:hover .code-preview-btn { opacity: 1; }
.artifact-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 1000; display: none; }
.artifact-overlay.open { display: block; }
.artifact-panel {
  position: fixed; top: 0; right: 0; height: 100vh; width: min(760px, 94vw);
  background: var(--surface); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 1001;
  transform: translateX(100%); transition: transform 0.25s ease;
  box-shadow: -8px 0 30px rgba(0,0,0,0.35);
}
.artifact-panel.open { transform: translateX(0); }
.artifact-header { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.artifact-title { font-size: 14px; font-weight: 600; flex: 1; }
.artifact-tabs { display: flex; gap: 6px; }
.artifact-tab { padding: 5px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: transparent; color: var(--text-muted); cursor: pointer; font-size: 13px; font-family: inherit; }
.artifact-tab.active { background: var(--surface2); color: var(--text); }
.artifact-close { background: transparent; border: none; color: var(--text-muted); cursor: pointer; font-size: 20px; line-height: 1; padding: 0 4px; }
.artifact-close:hover { color: var(--text); }
.artifact-body { flex: 1; overflow: hidden; position: relative; }
.artifact-frame { width: 100%; height: 100%; border: none; background: #fff; }
.artifact-code { margin: 0; padding: 16px; height: 100%; overflow: auto; white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, Consolas, monospace; font-size: 13px; color: var(--text); }

/* ===== Input alignment ===== */
.input-wrapper textarea { min-height: 44px; box-sizing: border-box; padding-top: 11px; padding-bottom: 11px; }

/* ===== Conversation list (sidebar) ===== */
.conv-list { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; margin: 8px 0; }
.conv-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; border-radius: var(--radius-sm); cursor: pointer;
  color: var(--text-muted); border: 1px solid transparent; transition: all 0.15s;
}
.conv-item:hover { background: var(--surface2); color: var(--text); }
.conv-item.active { background: var(--surface2); color: var(--text); border-color: var(--border); }
.conv-title { flex: 1; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-del { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 12px; opacity: 0; padding: 0 2px; line-height: 1; }
.conv-item:hover .conv-del { opacity: 1; }
.conv-del:hover { color: var(--text); }

/* Inline conversation rename */
.conv-rename-input {
  flex: 1; min-width: 0; font-size: 13px; font-family: inherit;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--accent); border-radius: 6px; padding: 2px 6px; outline: none;
}

