:root {
  --navy: #0a1628;
  --navy-light: #162033;
  --navy-hover: #1e2d45;
  --amber: #D87B42;
  --amber-hover: #c46a35;
  --bg: #f7f7f8;
  --white: #ffffff;
  --text: #1a1a1a;
  --text-secondary: #6b7280;
  --text-sidebar: #94a3b8;
  --text-sidebar-active: #e2e8f0;
  --border: #e5e7eb;
  --sidebar-width: 280px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  height: 100vh;
  overflow: hidden;
  color: var(--text);
}

/* ── Layout ── */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  height: 100vh;
}

/* ── Sidebar ── */
#sidebar {
  background: var(--navy);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.logo {
  color: var(--white);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

#new-chat-btn {
  background: var(--amber);
  color: white;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
#new-chat-btn:hover { background: var(--amber-hover); }
#new-chat-btn svg { width: 16px; height: 16px; }

/* Chat list */
#chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.chat-group-label {
  color: var(--text-sidebar);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 12px 8px 4px;
}

.chat-item {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-sidebar);
  font-size: 13px;
  transition: background 0.1s;
  gap: 8px;
}
.chat-item:hover {
  background: var(--navy-hover);
  color: var(--text-sidebar-active);
}
.chat-item.active {
  background: var(--navy-light);
  color: var(--text-sidebar-active);
}

.chat-item-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-item-delete {
  opacity: 0;
  background: none;
  border: none;
  color: var(--text-sidebar);
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  display: flex;
  transition: opacity 0.1s;
}
.chat-item:hover .chat-item-delete { opacity: 1; }
.chat-item-delete:hover { color: #ef4444; }
.chat-item-delete svg { width: 14px; height: 14px; }

/* Sidebar footer */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

#bug-btn {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: var(--text-sidebar);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s;
}
#bug-btn:hover {
  background: var(--navy-hover);
  color: var(--text-sidebar-active);
  border-color: rgba(255, 255, 255, 0.2);
}
#bug-btn svg { width: 16px; height: 16px; }

/* ── Main area ── */
#main {
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
  background: var(--bg);
}

#menu-btn {
  display: none;
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 10;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}
#menu-btn svg { width: 18px; height: 18px; color: var(--text); }

/* ── Messages ── */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
  display: flex;
  flex-direction: column;
}

.messages-inner {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

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

.message-role {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}

.message-content {
  line-height: 1.6;
  font-size: 14px;
}

.message.user .message-content {
  background: var(--navy);
  color: var(--white);
  padding: 12px 16px;
  border-radius: 12px;
  border-bottom-right-radius: 4px;
  align-self: flex-start;
  max-width: 85%;
}

.message.assistant .message-content {
  color: var(--text);
}

/* Markdown inside assistant messages */
.message.assistant .message-content h1,
.message.assistant .message-content h2,
.message.assistant .message-content h3 {
  margin: 16px 0 8px;
  font-size: 15px;
  font-weight: 600;
}
.message.assistant .message-content h1:first-child,
.message.assistant .message-content h2:first-child,
.message.assistant .message-content h3:first-child { margin-top: 0; }

.message.assistant .message-content p { margin: 0 0 12px; }
.message.assistant .message-content p:last-child { margin-bottom: 0; }

.message.assistant .message-content ul,
.message.assistant .message-content ol {
  margin: 0 0 12px;
  padding-left: 24px;
}
.message.assistant .message-content li { margin: 4px 0; }

.message.assistant .message-content code {
  background: #f0f0f0;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
}

.message.assistant .message-content pre {
  background: #1e1e1e;
  color: #d4d4d4;
  padding: 12px 16px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0 12px;
}
.message.assistant .message-content pre code {
  background: none;
  padding: 0;
  color: inherit;
}

.message.assistant .message-content strong { font-weight: 600; }

.message.assistant .message-content table {
  border-collapse: collapse;
  margin: 8px 0 12px;
  font-size: 13px;
  width: 100%;
}
.message.assistant .message-content th,
.message.assistant .message-content td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
.message.assistant .message-content th {
  background: #f3f4f6;
  font-weight: 600;
}

/* Streaming cursor */
.message.streaming .message-content::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 16px;
  background: var(--amber);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 0.8s infinite;
}

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

/* ── Empty state ── */
#empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  color: var(--text-secondary);
}

.empty-icon {
  width: 64px;
  height: 64px;
  background: var(--navy);
  color: var(--amber);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}
.empty-icon svg { width: 32px; height: 32px; }

#empty-state h2 {
  font-size: 20px;
  color: var(--text);
  margin-bottom: 8px;
}
#empty-state p { font-size: 14px; margin-bottom: 24px; }

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 500px;
}

.suggestion {
  background: var(--white);
  border: 1px solid var(--border);
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
}
.suggestion:hover {
  border-color: var(--amber);
  color: var(--amber);
}

/* ── Input area ── */
#input-area {
  padding: 16px 24px 24px;
  background: var(--bg);
}

.input-wrapper {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 8px 8px 16px;
  transition: border-color 0.15s;
}
.input-wrapper:focus-within { border-color: var(--amber); }

#message-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.5;
  resize: none;
  max-height: 200px;
  background: transparent;
  color: var(--text);
}

#send-btn {
  background: var(--amber);
  color: white;
  border: none;
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
#send-btn:hover { background: var(--amber-hover); }
#send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
#send-btn svg { width: 16px; height: 16px; }

/* ── Modal ── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal.hidden { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.modal-content {
  position: relative;
  background: var(--white);
  border-radius: 16px;
  padding: 24px;
  width: 90%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.modal-content h2 { font-size: 18px; font-weight: 600; }

#bug-description {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  outline: none;
  color: var(--text);
}
#bug-description:focus { border-color: var(--amber); }

.file-upload { display: flex; flex-direction: column; gap: 4px; }
.file-upload label { font-size: 13px; color: var(--text-secondary); }

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }

.btn-primary {
  background: var(--amber);
  color: white;
  border: none;
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
}
.btn-primary:hover { background: var(--amber-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: none;
  border: 1px solid var(--border);
  padding: 8px 20px;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
}
.btn-secondary:hover { background: #f3f4f6; }

/* ── Auth error ── */
#auth-error {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
#auth-error.hidden { display: none; }

.auth-error-content { text-align: center; color: var(--text-secondary); }
.auth-error-content h2 { font-size: 20px; color: var(--text); margin-bottom: 8px; }

/* ── Scrollbar ── */
#chat-list::-webkit-scrollbar,
#messages::-webkit-scrollbar { width: 6px; }

#chat-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}
#messages::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 3px;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy);
  color: white;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 300;
  animation: toast-in 0.2s ease, toast-out 0.3s ease 2.7s forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes toast-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* ── Mobile overlay ── */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 40;
}
.sidebar-overlay.hidden { display: none; }

/* ── Responsive ── */
@media (max-width: 768px) {
  #app { grid-template-columns: 1fr; }

  #sidebar {
    position: fixed;
    left: 0;
    top: 0;
    width: var(--sidebar-width);
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  #sidebar.open { transform: translateX(0); }

  #menu-btn { display: flex; }

  .messages-inner { padding: 0 16px; }
  #input-area { padding: 12px 16px 16px; }
}
