/* Servitor — app.css
   Dark neutral theme, no external framework.
   Breakpoint: 768px (sidebar collapses to overlay drawer below).
*/

/* ── Reset & base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #1a1b1e;
  --bg-2:        #25262b;
  --bg-3:        #2c2d32;
  --bg-4:        #35363c;
  --border:      #3a3b40;
  --text:        #d4d4d8;
  --text-muted:  #71717a;
  --text-strong: #f4f4f5;
  --accent:      #6366f1;
  --accent-hover:#4f52d8;
  --bubble-user: #2d2f6b;
  --bubble-asst: #25262b;
  --danger:      #ef4444;
  --radius:      8px;
  --radius-lg:   12px;
  --sidebar-w:   280px;
  --header-h:    52px;
  --composer-h:  auto;
  --transition:  0.18s ease;
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
}

/* ── Utilities ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), opacity var(--transition);
  white-space: nowrap;
  text-decoration: none;
}

.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-outline {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-outline:hover:not(:disabled) { background: var(--bg-3); }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--bg-3); }

.btn-sm { min-height: 32px; padding: 0 10px; font-size: 13px; }

.btn-full { width: 100%; }

/* ── Login page ───────────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  overflow: auto;
  background: var(--bg);
}

.login-container {
  width: 100%;
  max-width: 380px;
  padding: 24px 16px;
}

.login-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
}

.login-header { text-align: center; margin-bottom: 28px; }

.login-title {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-strong);
  letter-spacing: -0.5px;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 4px;
}

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

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

.form-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.form-input {
  height: 42px;
  padding: 0 12px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-strong);
  font-size: 15px;
  outline: none;
  transition: border-color var(--transition);
}
.form-input:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--text-muted); }

.error-message {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius);
  padding: 10px 14px;
  color: #fca5a5;
  font-size: 14px;
}

/* ── Chat page shell ──────────────────────────────────────────── */
.chat-page { overflow: hidden; }

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── Header ───────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--header-h);
  padding: 0 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 100;
}

.app-title {
  font-weight: 700;
  font-size: 17px;
  color: var(--text-strong);
  letter-spacing: -0.3px;
  flex: 1;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

/* ── Hamburger ────────────────────────────────────────────────── */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius);
  flex-shrink: 0;
}
.hamburger:hover { background: var(--bg-3); }
.hamburger span {
  display: block;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
  transition: transform var(--transition), opacity var(--transition);
}

/* ── App body ─────────────────────────────────────────────────── */
.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  flex-shrink: 0;
  overflow: hidden;
}

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

.sidebar-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.conv-list-empty {
  padding: 24px 8px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.conv-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 100%;
  padding: 10px 12px;
  border: none;
  border-radius: var(--radius);
  background: none;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: background var(--transition);
  min-height: 48px;
  gap: 2px;
}
.conv-item:hover { background: var(--bg-3); }
.conv-item-active { background: var(--bg-4); }
.conv-item-active:hover { background: var(--bg-4); }

.conv-item-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.conv-item-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.conv-item-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  overflow: hidden;
}

.conv-agent-badge {
  background: rgba(99,102,241,0.15);
  border-radius: 4px;
  color: #a5b4fc;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 5px;
  white-space: nowrap;
  flex-shrink: 0;
}

.agent-filter-row {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.agent-filter-select {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12px;
  padding: 4px 8px;
}

.conv-agent-banner {
  background: rgba(99,102,241,0.1);
  border-bottom: 1px solid rgba(99,102,241,0.25);
  color: #a5b4fc;
  font-size: 12px;
  font-weight: 500;
  padding: 5px 20px;
  flex-shrink: 0;
}

/* ── Sidebar overlay (mobile) ─────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 150;
}
.overlay-visible { display: block; }

/* ── Main pane ────────────────────────────────────────────────── */
.main-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* ── Messages area ────────────────────────────────────────────── */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.welcome-screen,
.messages-loading,
.messages-empty,
.messages-error {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: var(--text-muted);
  font-size: 14px;
  text-align: center;
  padding: 40px 20px;
}

.messages-error { color: #fca5a5; }

/* ── Bubbles ──────────────────────────────────────────────────── */
.bubble-wrap {
  display: flex;
  max-width: 82%;
}

.bubble-wrap-user {
  align-self: flex-end;
  justify-content: flex-end;
}

.bubble-wrap-assistant {
  align-self: flex-start;
  justify-content: flex-start;
}

.bubble {
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.65;
  word-break: break-word;
}

.bubble-user {
  background: var(--bubble-user);
  color: #e0e0ff;
  border-bottom-right-radius: 4px;
}

.bubble-assistant {
  background: var(--bubble-asst);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.bubble-stub {
  background: rgba(234, 179, 8, 0.08);
  border-color: rgba(234, 179, 8, 0.25);
  color: #fbbf24;
  font-size: 13px;
  font-style: italic;
}

/* Markdown content inside bubbles */
.bubble p { margin-bottom: 0.6em; }
.bubble p:last-child { margin-bottom: 0; }
.bubble pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  overflow-x: auto;
  margin: 8px 0;
}
.bubble code {
  font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', Menlo, monospace;
  font-size: 13px;
}
.bubble p > code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}
.bubble ul, .bubble ol { padding-left: 20px; margin: 6px 0; }
.bubble blockquote {
  border-left: 3px solid var(--accent);
  margin: 8px 0;
  padding-left: 12px;
  color: var(--text-muted);
}
.bubble table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 13px; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 6px 10px; }
.bubble th { background: var(--bg-3); }
.bubble a { color: #818cf8; }
.bubble a:hover { color: var(--accent); }

/* ── Composer ─────────────────────────────────────────────────── */
.composer-wrapper {
  border-top: 1px solid var(--border);
  padding: 14px 16px;
  background: var(--bg-2);
  flex-shrink: 0;
}

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

.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

/* ── EasyMDE integration ──────────────────────────────────────── */
.EasyMDEContainer {
  display: flex;
  flex-direction: column;
}

.EasyMDEContainer .CodeMirror {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-strong);
  font-family: 'JetBrains Mono', 'Fira Code', Menlo, monospace;
  font-size: 14px;
  line-height: 1.6;
  min-height: 80px;
  max-height: 200px;
  padding: 4px 0;
}

.EasyMDEContainer .CodeMirror:focus-within {
  border-color: var(--accent);
}

.EasyMDEContainer .CodeMirror-scroll { min-height: 80px; }

.editor-toolbar {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 4px 6px;
}

.editor-toolbar button {
  color: var(--text-muted) !important;
  min-height: 28px;
  min-width: 28px;
}

.editor-toolbar button:hover,
.editor-toolbar button.active {
  background: var(--bg-3) !important;
  color: var(--text-strong) !important;
  border-color: var(--border) !important;
}

.editor-toolbar i.separator {
  border-left-color: var(--border) !important;
}

.EasyMDEContainer .CodeMirror { border-radius: 0 0 var(--radius) var(--radius); }

.editor-preview {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
}

/* CodeMirror cursor */
.CodeMirror-cursor { border-left-color: var(--text-strong) !important; }

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

/* ── Responsive (< 768px) ─────────────────────────────────────── */
@media (max-width: 767px) {
  .hamburger { display: flex; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform var(--transition);
    width: var(--sidebar-w);
  }

  .sidebar.sidebar-open {
    transform: translateX(0);
  }

  .header-username { display: none; }
}

@media (min-width: 768px) {
  .hamburger { display: none; }
}

/* ── Streaming / working indicator ───────────────────────────── */
.bubble-streaming {
  opacity: 0.9;
  border-left: 3px solid var(--accent);
  padding-left: 10px;
}

.working-indicator {
  display: inline-block;
  color: var(--text-muted);
  font-style: italic;
  animation: pulse 1.4s ease-in-out infinite;
}

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

.error-note {
  color: var(--danger);
  font-style: italic;
}

.error-note-agent {
  font-weight: 600;
}

.empty-response {
  color: var(--text-muted);
}

.poll-error-banner {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  border-radius: var(--radius);
  color: #fca5a5;
  font-size: 13px;
  padding: 8px 12px;
  margin: 0 16px 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.poll-error-dismiss {
  background: none;
  border: none;
  color: #fca5a5;
  cursor: pointer;
  font-size: 14px;
  margin-left: auto;
  padding: 0 4px;
  line-height: 1;
}

.admin-page {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.admin-container {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 16px;
}

.admin-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}

.admin-tab {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 15px;
  padding: 8px 16px;
  margin-bottom: -1px;
}

.admin-tab-active {
  border-bottom-color: var(--accent);
  color: var(--text);
  font-weight: 600;
}

.admin-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.admin-section-header h2 {
  margin: 0;
  font-size: 20px;
}

.admin-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
}

.admin-form h3 {
  margin: 0 0 16px;
  font-size: 16px;
}

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

.admin-empty {
  color: var(--text-muted);
  padding: 16px 0;
}

.admin-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
}

.admin-row-info {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  line-height: 1.5;
}

.admin-row-info code {
  background: var(--bg);
  border-radius: 4px;
  font-size: 12px;
  padding: 1px 5px;
}

.admin-row-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.badge-admin {
  background: rgba(99,102,241,0.2);
  border-radius: 4px;
  color: #a5b4fc;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  text-transform: uppercase;
}

.badge-disabled {
  background: rgba(239,68,68,0.15);
  border-radius: 4px;
  color: #fca5a5;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  text-transform: uppercase;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-width: 480px;
  padding: 24px;
  width: 100%;
}

.modal-box h3 {
  margin: 0 0 20px;
  font-size: 18px;
}

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.agent-checks {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}

.agent-check-label {
  align-items: center;
  cursor: pointer;
  display: flex;
  font-size: 14px;
  gap: 8px;
}

select.form-input {
  appearance: auto;
  background: var(--surface);
}
