:root {
  --bg: #0f0f13;
  --bg-card: #1a1a24;
  --bg-hover: #24243a;
  --bg-input: #14141e;
  --border: #2a2a3e;
  --text: #e8e8f0;
  --text-muted: #8888a8;
  --accent: #7c5cfc;
  --accent-hover: #9478ff;
  --accent-glow: rgba(124, 92, 252, 0.25);
  --success: #4ade80;
  --error: #f87171;
  --gold: #fbbf24;
  --sidebar-w: 320px;
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'SF Mono', 'Consolas', monospace;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

#app { height: 100vh; }

/* ── Screens ── */
.screen { display: none; height: 100%; }
.screen.active { display: flex; }

/* ── Login ── */
#login-screen {
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f0f13 0%, #1a1028 50%, #0f0f13 100%);
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 48px 40px;
  width: 420px;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 24px 48px rgba(0,0,0,0.4);
}

.logo-icon { font-size: 56px; display: block; margin-bottom: 12px; }
.logo h1 { font-size: 28px; font-weight: 700; margin-bottom: 4px; letter-spacing: -0.5px; }
.brand-accent { color: var(--gold); font-size: 1.2em; font-weight: 700; }
.subtitle { color: var(--text-muted); font-size: 14px; margin-bottom: 32px; }

.login-card label {
  display: block;
  text-align: left;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.login-card input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
  margin-bottom: 20px;
}

.login-card input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ── Buttons ── */
.btn {
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: white;
}

.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }

.btn-send {
  background: var(--accent);
  color: white;
  padding: 10px 20px;
  font-size: 14px;
}
.btn-send:hover { background: var(--accent-hover); }

.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}
.btn-icon:hover { background: var(--bg-hover); border-color: var(--accent); }

.btn-sm {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-sm:hover { color: var(--text); border-color: var(--text-muted); }

.error { color: var(--error); font-size: 13px; margin-top: 8px; }
.hidden { display: none !important; }

/* ── Main layout ── */
#main-screen { display: none; }
#main-screen.active { display: flex; }

/* ── Sidebar ── */
#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.logo-icon-sm { font-size: 24px; }
.sidebar-title { font-weight: 600; font-size: 15px; flex: 1; }

.sidebar-section {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-section h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.templates { display: flex; flex-direction: column; gap: 6px; }

.template-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s;
}

.template-btn:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  transform: translateX(3px);
}

#sidebar select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  outline: none;
  cursor: pointer;
}

#sidebar select:focus { border-color: var(--accent); }

.sidebar-footer {
  margin-top: auto;
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ── Status indicator ── */
.status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--error);
}

.status.connected .status-dot { background: var(--success); }
.status.connecting .status-dot { background: var(--gold); animation: pulse 1s infinite; }

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

/* ── Chat area ── */
#chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  scroll-behavior: smooth;
}

/* ── Welcome ── */
.welcome-message {
  max-width: 640px;
  margin: 60px auto 0;
  text-align: center;
}

.welcome-message h2 {
  font-size: 28px;
  margin-bottom: 8px;
}

.welcome-message > p {
  color: var(--text-muted);
  margin-bottom: 24px;
  font-size: 15px;
}

.welcome-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}

.welcome-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
  cursor: pointer;
  transition: all 0.2s;
}

.welcome-card:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
  transform: translateY(-2px);
}

.welcome-card span { font-size: 28px; display: block; margin-bottom: 8px; }
.welcome-card p { font-size: 13px; color: var(--text-muted); }

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

/* ── Messages ── */
.message {
  max-width: 780px;
  margin: 0 auto 20px;
  animation: fadeIn 0.3s ease;
}

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

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

.message-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.message.user .message-avatar { background: var(--accent); }
.message.assistant .message-avatar { background: var(--gold); }

.message-sender {
  font-size: 13px;
  font-weight: 600;
}

.message-content {
  padding: 16px 20px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.7;
}

.message.user .message-content {
  background: var(--accent);
  background: linear-gradient(135deg, var(--accent), #6341e0);
  color: white;
  border-bottom-right-radius: 4px;
  margin-left: 36px;
}

.message.assistant .message-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  margin-left: 36px;
}

/* ── Markdown in assistant messages ── */
.message.assistant .message-content h1,
.message.assistant .message-content h2,
.message.assistant .message-content h3 {
  margin: 20px 0 10px;
  color: var(--gold);
}

.message.assistant .message-content h1 { font-size: 22px; }
.message.assistant .message-content h2 { font-size: 18px; }
.message.assistant .message-content h3 { font-size: 16px; }

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

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

.message.assistant .message-content li { margin-bottom: 4px; }

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

.message.assistant .message-content code {
  background: var(--bg);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}

.message.assistant .message-content pre {
  background: var(--bg);
  padding: 16px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin: 12px 0;
}

.message.assistant .message-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 16px;
  color: var(--text-muted);
  margin: 12px 0;
}

/* ── Copy button ── */
.message-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  margin-left: 36px;
  opacity: 0;
  transition: opacity 0.2s;
}
.message:hover .message-actions { opacity: 1; }

.copy-btn {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}
.copy-btn:hover { color: var(--text); border-color: var(--accent); }

/* ── Input area ── */
#chat-input-area {
  padding: 16px 24px 24px;
  max-width: 828px;
  margin: 0 auto;
  width: 100%;
}

#typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 0;
  font-size: 13px;
  color: var(--text-muted);
}

#typing-indicator .dot {
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out;
}

#typing-indicator .dot:nth-child(1) { animation-delay: -0.32s; }
#typing-indicator .dot:nth-child(2) { animation-delay: -0.16s; }

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

#chat-form {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  transition: border-color 0.2s;
}

#chat-form:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#chat-input {
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  resize: none;
  outline: none;
  min-height: 24px;
  max-height: 200px;
}

#chat-input::placeholder { color: var(--text-muted); }

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

#char-count {
  font-size: 12px;
  color: var(--text-muted);
  margin-right: auto;
}

/* ── Mobile ── */
@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    height: 100%;
    z-index: 100;
    transition: left 0.3s ease;
    width: 280px;
  }

  #sidebar.open { left: 0; }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
    display: none;
  }

  .sidebar-overlay.open { display: block; }

  .welcome-grid { grid-template-columns: 1fr; }

  #chat-input-area { padding: 12px 12px 16px; }
}

/* ── Sidebar form fields ── */
.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
}

.field-label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
  margin-top: 10px;
}

.field-label:first-child { margin-top: 0; }

.sidebar-input {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  outline: none;
}

.sidebar-input:focus { border-color: var(--accent); }

.sidebar-textarea {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  line-height: 1.5;
  resize: vertical;
  outline: none;
}

.sidebar-textarea:focus { border-color: var(--accent); }

.btn-block { width: 100%; }

.translate-btns {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.translate-btns .btn-sm { flex: 1; text-align: center; }

.translate-result {
  margin-top: 8px;
  padding: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 1.5;
  max-height: 150px;
  overflow-y: auto;
  cursor: pointer;
}

.translate-result:hover { border-color: var(--accent); }
.translate-result .copy-hint { color: var(--text-muted); font-size: 10px; display: block; margin-top: 4px; }

.success {
  color: var(--success);
  font-size: 12px;
  margin-top: 6px;
  text-align: center;
}

/* ── Upload zone ── */
.upload-zone {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.upload-content {
  text-align: center;
  max-width: 520px;
  width: 100%;
}

.upload-icon {
  font-size: 64px;
  margin-bottom: 16px;
}

.upload-content h2 {
  font-size: 22px;
  margin-bottom: 8px;
}

.upload-content > p {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 24px;
}

.upload-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 12px;
}

.upload-zone.drag-over {
  background: var(--accent-glow);
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
}

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 24px 0;
  color: var(--text-muted);
  font-size: 12px;
}

.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

.paste-area {
  width: 100%;
  padding: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.6;
  resize: vertical;
  outline: none;
}

.paste-area:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

/* ── Review area ── */
.review-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}

.review-file-info {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
}

.file-icon { font-size: 20px; }

#review-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ── Report styling ── */
.report-pass { color: var(--success); }
.report-fail { color: var(--error); }
.report-warn { color: var(--gold); }

/* ── Modals ── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(4px);
}

.modal.hidden { display: none; }

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 500px;
  max-width: 90vw;
  max-height: 80vh;
  overflow-y: auto;
  animation: fadeIn 0.2s ease;
}

.modal-content.modal-wide { width: 650px; }

.modal-content h2 {
  font-size: 18px;
  margin-bottom: 8px;
}

.modal-content h3 {
  font-size: 14px;
  color: var(--text-muted);
}

.modal-hint {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.modal-content textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.6;
  padding: 12px;
  resize: vertical;
  outline: none;
}

.modal-content textarea:focus {
  border-color: var(--accent);
}

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

/* ── Admin users table ── */
.admin-user-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.admin-user-row .user-name { flex: 1; font-weight: 600; }
.admin-user-row .user-role {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--bg-hover);
  color: var(--text-muted);
}
.admin-user-row .user-role.admin { background: var(--accent); color: white; }

.admin-user-row .btn-sm { padding: 4px 8px; font-size: 11px; }

.admin-form {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.admin-form input, .admin-form select {
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  flex: 1;
  min-width: 100px;
}

.admin-form input:focus, .admin-form select:focus {
  border-color: var(--accent);
}

.admin-form .btn { padding: 8px 16px; font-size: 13px; white-space: nowrap; }

/* ── Feature toggles ── */
.feature-toggles {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  cursor: pointer;
  padding: 4px 0;
}

.toggle-row input[type="checkbox"] {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  cursor: pointer;
}

/* ── Review actions ── */
.review-actions {
  display: flex;
  gap: 6px;
}

/* ── History list ── */
.history-item {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s;
}

.history-item:hover {
  border-color: var(--accent);
  background: var(--bg-hover);
}

.history-item .history-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.history-item .history-name {
  font-weight: 600;
  font-size: 13px;
}

.history-item .history-score {
  font-size: 12px;
  color: var(--gold);
}

.history-item .history-actions {
  margin-top: 6px;
  display: flex;
  gap: 6px;
}

/* ── Watcher list ── */
.watcher-item {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.watcher-item .watcher-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.watcher-item .watcher-name { font-weight: 600; font-size: 13px; }
.watcher-item .watcher-url { font-size: 11px; color: var(--text-muted); word-break: break-all; }
.watcher-item .watcher-result {
  margin-top: 8px;
  font-size: 12px;
  line-height: 1.5;
  padding: 8px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  max-height: 200px;
  overflow-y: auto;
}
.watcher-item .watcher-checked { font-size: 10px; color: var(--text-muted); }

/* ── Research results ── */
.research-item {
  padding: 10px;
  border-bottom: 1px solid var(--border);
}

.research-item:last-child { border-bottom: none; }

.research-item a {
  color: var(--accent);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
}

.research-item a:hover { text-decoration: underline; }
.research-item .research-snippet { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ── Integrations ── */
.integration-item {
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}

.integration-item h3 {
  font-size: 14px;
  margin-bottom: 8px;
  color: var(--text);
}

/* ── Slack messages ── */
.slack-msg {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  line-height: 1.5;
}

.slack-msg:last-child { border-bottom: none; }

.slack-msg-header {
  display: flex;
  gap: 8px;
  align-items: baseline;
  margin-bottom: 4px;
}

.slack-msg-user {
  font-weight: 600;
  font-size: 12px;
  color: var(--accent);
}

.slack-msg-time {
  font-size: 10px;
  color: var(--text-muted);
}

.slack-msg-text {
  color: var(--text);
}

/* ── Google Drive files ── */
.gdrive-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.2s;
}

.gdrive-file:hover { background: var(--bg-hover); }

.gdrive-file-icon { font-size: 20px; }
.gdrive-file-name { flex: 1; font-size: 13px; font-weight: 500; }
.gdrive-file-meta { font-size: 11px; color: var(--text-muted); }
.gdrive-file-btn { font-size: 12px; }

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