/* =========================================================
   BG BAU — Corporate UI Theme
   ========================================================= */

:root {
  --bg: #f5f6f8;
  --bg-sidebar: #f2f4f7;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --bg-hover: #dfe3ea;
  --bg-message-user: #e2e6ec;
  --bg-message-assistant: #e8ecf3;
  --border: #bfc5ce;
  --border-focus: #004b93;
  --text: #333333;
  --text-muted: #555555;
  --text-dim: #444444;
  --accent: #004b93;
  --accent-dim: rgba(0, 75, 147, 0.1);
  --accent-amber: #e6930a;
  --accent-red: #d93025;
  --accent-blue: #004b93;
  --font-mono: "Source Sans 3", Arial, sans-serif;
  --font-sans: "Source Sans 3", Arial, sans-serif;
  --sidebar-width: 240px;
  --topbar-height: 48px;
  --divider-inset: 12px; /* uniform side margin for all horizontal dividers (matches the sidebar padding) */
  --pagination-padding-top: 26px;    /* pagination footer: mirrors composer so the divider and button-centers align */
  --pagination-padding-bottom: 44px;
  --radius: 6px;
  --transition: 150ms ease;
}

/* ------------------------------------------------------------------ Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  opacity: 0;
}
body.ready {
  opacity: 1;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; color: #003366; }
button { cursor: pointer; font-family: inherit; font-size: 13px; }

/* ------------------------------------------------------------------ Layout */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ------------------------------------------------------------------ Sidebar */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  overflow-y: auto;
  gap: 4px;
  transition: transform var(--transition);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 4px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}
.logo-icon { display: flex; align-items: center; }
.logo-icon img { height: 32px; width: auto; }
.logo-text { font-family: var(--font-sans); font-size: 13px; font-weight: 700; color: var(--accent); letter-spacing: 0.05em; }

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  background: var(--bg-card);
  border-radius: var(--radius);
  margin-bottom: 8px;
}
.user-dot { width: 7px; height: 7px; border-radius: 50%; background: #28a745; flex-shrink: 0; }
.user-label { font-family: var(--font-sans); font-size: 12px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-new-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 9px;
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  background: rgba(0, 75, 147, 0.06);
  font-family: var(--font-sans);
  text-decoration: none;
  transition: all var(--transition);
}
.sidebar-new-btn:hover,
a.sidebar-new-btn:hover {
  background: var(--accent);
  color: #ffffff !important;
  text-decoration: none !important;
  box-shadow: 0 2px 8px rgba(0,75,147,0.2);
}

.sidebar-section { margin-bottom: 16px; overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.sidebar-section-title {
  font-family: var(--font-sans);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  padding: 4px 8px;
  margin-bottom: 4px;
  position: sticky;
  top: 0;
  background: var(--bg-sidebar);
  z-index: 1;
}

.conv-list { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.conv-item .conv-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border-radius: var(--radius);
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 12px;
  text-align: left;
  transition: background var(--transition), color var(--transition);
}
.conv-item .conv-btn:hover { background: var(--accent); color: #fff; box-shadow: 0 2px 8px rgba(0,75,147,0.2); }
.conv-item.active .conv-btn { background: var(--bg-hover); color: var(--accent); }
.conv-icon { font-size: 11px; flex-shrink: 0; opacity: 0.5; }
.conv-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-empty { font-size: 12px; color: var(--text-muted); padding: 4px 8px; font-style: italic; }

.conv-load-more { display: flex; justify-content: center; padding: 8px 0; }
.conv-load-more[hidden] { display: none; }
.conv-load-spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: conv-spin 0.6s linear infinite;
}
@keyframes conv-spin { to { transform: rotate(360deg); } }

/* Model switcher */
.model-switcher { display: flex; gap: 4px; padding: 0 4px; }
.model-form { display: flex; gap: 4px; width: 100%; }
.model-btn {
  flex: 1;
  padding: 7px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
}
.model-btn:hover { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 2px 8px rgba(0,75,147,0.2); }
.model-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

/* Sidebar actions */
.sidebar-actions { margin-top: auto; display: flex; flex-direction: column; gap: 3px; padding-top: 12px; border-top: 1px solid var(--border); }
.sidebar-action-btn {
  font-size: 12px !important;
  padding: 7px 10px !important;
  color: var(--text) !important;
  justify-content: flex-start !important;
  font-family: var(--font-sans) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius) !important;
  background: var(--bg-card) !important;
  transition: all 0.15s ease !important;
}
.sidebar-action-btn:hover { color: #fff !important; border-color: var(--accent) !important; background: var(--accent) !important; box-shadow: 0 2px 8px rgba(0,75,147,0.2) !important; }
.logout-btn:hover { color: #fff !important; border-color: var(--accent-red) !important; background: var(--accent-red) !important; box-shadow: 0 2px 8px rgba(217,48,37,0.2) !important; }

/* ------------------------------------------------------------------ Top bar */
.topbar {
  display: flex;
  height: var(--topbar-height);
  background: var(--bg-sidebar);
  border-bottom: 1px solid transparent; /* keep box height; grey line drawn inset below */
  position: relative;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}
/* Inset central-column dividers (do not touch the side edges) */
.topbar::after,
.input-area::after {
  content: "";
  position: absolute;
  left: var(--divider-inset);
  right: var(--divider-inset);
  height: 1px;
  background: var(--border);
  pointer-events: none;
}
.topbar::after { bottom: 0; }
.input-area::after { top: 0; }
.sidebar-toggle { background: none; border: none; color: var(--text-dim); font-size: 18px; padding: 4px 8px; display: none; }
.sidebar-toggle:hover { color: var(--text); }
.topbar-title { font-family: var(--font-sans); font-size: 14px; font-weight: 600; color: var(--text); }
.topbar-model { margin-left: auto; font-family: var(--font-mono); font-size: 10px; color: var(--accent); background: var(--accent-dim); padding: 2px 8px; border-radius: 99px; }

/* ------------------------------------------------------------------ Chat main */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ------------------------------------------------------------------ Messages */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0;
  scroll-behavior: auto;
}
.messages-area::-webkit-scrollbar { width: 4px; }
.messages-area::-webkit-scrollbar-track { background: transparent; }
.messages-area::-webkit-scrollbar-thumb { background: #c0c4cc; border-radius: 2px; }

.welcome-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 60%;
  min-height: 200px;
  gap: 16px;
  padding: 32px;
  text-align: center;
}
.welcome-icon { font-size: 36px; color: var(--accent); }
.welcome-text {
  font-size: 14px;
  color: var(--text);
  max-width: 400px;
  line-height: 1.8;
  white-space: pre-line;
}

.message {
  max-width: 780px;
  margin: 0 auto 4px;
  padding: 12px 24px;
  border-radius: var(--radius);
  box-shadow: none;
}

.message-user { background: var(--bg-message-user); border-left: 2px solid var(--accent-blue); }
.message-assistant { background: var(--bg-message-assistant); border-left: 2px solid var(--border); }
.message-assistant.streaming-message { border-left-color: var(--accent); }

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-family: var(--font-mono);
  font-size: 11px;
}
.message-role { color: var(--accent); font-weight: 600; font-size: 14px; display: flex; align-items: center; }
.message-user .message-role { color: #333333; }
.message-label { color: var(--text); font-size: 12px; font-weight: 500; }
.message-model-tag {
  margin-left: auto;
  font-size: 10px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(0,75,147,0.08);
  border: 1px solid rgba(0,75,147,0.2);
  padding: 2px 8px;
  border-radius: 99px;
}

.message-content {
  font-size: 14px;
  line-height: 1.75;
  color: var(--text);
  word-break: break-word;
  font-family: var(--font-sans);
}

/* Code blocks */
.message-content code {
  font-family: "JetBrains Mono", "Fira Code", "Consolas", monospace;
  font-size: 12px;
  background: #f0f3f7;
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 3px;
  color: #c7254e;
}
.message-content pre {
  background: #1e1e2e;
  border: 1px solid #2a2a3a;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin: 8px 0;
  overflow-x: auto;
}
.message-content pre code {
  font-family: "JetBrains Mono", "Fira Code", "Consolas", monospace;
  background: none;
  border: none;
  padding: 0;
  color: #e0e0e0;
}

/* Markdown: headings */
.message-content h1 { font-size: 1.4em; font-weight: 600; margin: 16px 0 8px; }
.message-content h2 { font-size: 1.2em; font-weight: 600; margin: 14px 0 6px; }
.message-content h3 { font-size: 1.05em; font-weight: 600; margin: 12px 0 4px; }
.message-content h1:first-child,
.message-content h2:first-child,
.message-content h3:first-child { margin-top: 0; }

/* Markdown: paragraphs */
.message-content p { margin: 0 0 8px; }
.message-content p:last-child { margin-bottom: 0; }

/* Markdown: lists */
.message-content ul,
.message-content ol { padding-left: 20px; margin: 4px 0 8px; }
.message-content li { margin: 2px 0; }
.message-content li + li { margin-top: 2px; }
.message-content ul { list-style: disc; }
.message-content ol { list-style: decimal; }

/* Markdown: blockquotes */
.message-content blockquote {
  border-left: 3px solid var(--accent);
  padding: 4px 12px;
  margin: 8px 0;
  color: var(--text-dim);
  background: var(--bg-card);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.message-content blockquote p { margin: 0; }

/* Markdown: tables (zebra-stripe) */
.message-content table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin: 8px 0;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.message-content th {
  background: #f0f3f7;
  color: var(--text-dim);
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.message-content td {
  padding: 8px 14px;
  border-bottom: 1px solid #e8ecf1;
}
.message-content tr:last-child td { border-bottom: none; }
.message-content tbody tr:nth-child(even) { background: #f7f8fa; }
.message-content tbody tr:hover { background: #e8ecf1; }

/* Markdown: links */
.message-content a { color: var(--accent); text-decoration: underline; }
.message-content a:hover { color: var(--accent-blue); }

/* Markdown: horizontal rules */
.message-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

/* Markdown: emphasis */
.message-content strong { font-weight: 600; }
.message-content em { font-style: italic; }

/* Thinking panel */
.thinking-panel {
  margin-bottom: 10px;
  background: rgba(0, 75, 147, 0.05);
  border: 1px solid rgba(0, 75, 147, 0.2);
  border-radius: var(--radius);
  overflow: hidden;
}
.thinking-summary {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: #004b93;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.thinking-summary::-webkit-details-marker { display: none; }
.thinking-summary::marker { display: none; }
.thinking-pulse {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #004b93;
  flex-shrink: 0;
  animation: thinking-blink 1s infinite;
}
.thinking-panel[open] .thinking-pulse { animation: none; background: #003366; }
@keyframes thinking-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.2; }
}
.thinking-content {
  font-family: "JetBrains Mono", "Fira Code", "Consolas", monospace;
  font-size: 11px;
  color: #4a6fa5;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  padding: 10px 14px;
  margin: 0;
  border-top: 1px solid rgba(0, 75, 147, 0.15);
  max-height: 260px;
  overflow-y: auto;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  padding: 2px 0;
}
.typing-indicator span {
  width: 6px;
  height: 6px;
  background: #004b93;
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.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: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* Feedback */
.message-feedback {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.feedback-form { display: flex; gap: 4px; }
.feedback-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 12px;
  transition: all var(--transition);
}
.feedback-btn:hover { border-color: var(--accent); color: var(--accent); }
.active-like { border-color: var(--accent) !important; color: var(--accent) !important; background: var(--accent-dim) !important; }
.active-dislike { border-color: var(--accent-red) !important; color: var(--accent-red) !important; }

/* ------------------------------------------------------------------ Input area */
.input-area {
  padding: 12px 24px 8px;
  border-top: 1px solid transparent; /* keep box geometry; grey line drawn inset on top */
  position: relative;
  background: var(--bg);
}
.chat-form { max-width: 780px; margin: 0 auto; }
.input-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  transition: border-color var(--transition);
}
.input-wrapper:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(0,75,147,0.1); }
.message-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  outline: none;
  max-height: 200px;
  overflow-y: auto;
}
.message-input::placeholder { color: var(--text-muted); }
.send-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  font-size: 14px;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--transition);
}
.send-btn:hover { background: #003366; }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.attach-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  padding: 2px 4px;
  display: flex;
  align-items: center;
  transition: color var(--transition);
  cursor: pointer;
}
.attach-btn:hover { color: var(--accent); }
.image-preview-row {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 780px;
  margin: 0 auto 6px;
  padding: 6px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.image-preview-thumb {
  height: 56px;
  width: auto;
  max-width: 120px;
  border-radius: 4px;
  object-fit: cover;
  border: 1px solid var(--border);
}
.image-remove-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--radius);
  transition: color var(--transition);
}
.image-remove-btn:hover { color: var(--accent-red); }
.message-image {
  max-width: 320px;
  max-height: 240px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 8px;
  display: block;
}
.input-hint { font-size: 10px; color: var(--text-muted); font-family: var(--font-sans); text-align: right; margin-top: 6px; padding-right: 14px; }
.spin { animation: spin 1s linear infinite; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ Login page */
.login-container {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  overflow-y: auto;
}
.login-card {
  width: 340px;
  max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.login-header { text-align: center; }
.login-logo { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 6px; }
.login-subtitle { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); letter-spacing: 0.1em; text-transform: uppercase; }
.login-form { display: flex; flex-direction: column; gap: 16px; align-items: center; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-family: var(--font-mono); font-size: 11px; color: var(--text-dim); letter-spacing: 0.05em; }
.form-input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  padding: 10px 12px;
  outline: none;
  transition: border-color var(--transition);
}
.form-input:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--text-muted); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition);
  cursor: pointer;
  gap: 6px;
}
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.btn-primary:hover { background: #003366; border-color: #003366; }
.btn-ghost { background: transparent; color: var(--text-dim); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-full { width: 100%; }

/* Alert */
.alert { padding: 10px 14px; border-radius: var(--radius); font-size: 13px; }
.alert-error { background: rgba(217,48,37,0.08); border: 1px solid rgba(217,48,37,0.3); color: #d93025; }

/* Lang switcher in login */
.lang-switcher { display: flex; justify-content: center; gap: 6px; }
.lang-form { display: flex; gap: 6px; }
.lang-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius);
  padding: 4px 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  cursor: pointer;
  transition: all var(--transition);
}
.lang-btn.active, .lang-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Divider between login methods */
.login-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.login-divider::before,
.login-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ------------------------------------------------------------------ Responsive */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    transform: translateX(-100%);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: block; }
  .message { padding: 12px 16px; }
  .input-area { padding: 10px 16px 12px; }
}

/* ------------------------------------------------------------------ Feedback modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  opacity: 0; pointer-events: none;
  transition: opacity var(--transition);
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(420px, 92vw);
  padding: 24px;
  display: flex; flex-direction: column; gap: 16px;
  transform: translateY(10px);
  transition: transform var(--transition);
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-header { display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-family: var(--font-sans); font-size: 13px; font-weight: 600; color: var(--accent); }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 20px; cursor: pointer; padding: 0 4px; line-height: 1; }
.modal-close:hover { color: var(--text); }
.modal-body { display: flex; flex-direction: column; gap: 8px; }
.modal-textarea {
  width: 100%; resize: vertical; min-height: 80px;
  background: var(--bg-input); border: 1px solid var(--border);
  color: var(--text); font-family: var(--font-sans); font-size: 13px;
  padding: 10px 12px; border-radius: var(--radius); outline: none;
  transition: border-color var(--transition);
}
.modal-textarea:focus { border-color: var(--accent); }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; }

/* ------------------------------------------------------------------ HITL interrupt cards */
.hitl-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-amber);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 10px auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 780px;
  width: calc(100% - 48px);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}
.hitl-card--resolved { opacity: 0.55; }
.hitl-card-header {
  font-family: var(--font-sans);
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.01em;
}
/* Choice variant */
.hitl-choices { display: flex; flex-direction: column; gap: 6px; }
.hitl-choice-btn {
  align-self: flex-start;
  text-align: left;
  white-space: normal;
  padding: 8px 14px;
  line-height: 1.4;
}
.hitl-freetext-input {
  box-sizing: border-box;
  width: 100%;
  resize: none;
  height: 38px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 13px;
  font-style: italic;
  padding: 6px 10px;
  border-radius: var(--radius);
  outline: none;
  transition: border-color var(--transition);
}
.hitl-freetext-input:focus { border-color: var(--accent); }

/* Confirm variant */
.hitl-confirm-content {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.hitl-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

/* Batch choice variant */
.hitl-card--batch {
  border-left-color: var(--accent-blue);
}
.hitl-batch-progress {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text-muted);
  text-align: center;
  font-weight: 500;
}
.hitl-batch-progress-text {
  color: var(--accent);
}
.hitl-row-card-container {
  min-height: 200px;
}
.hitl-row-card {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.hitl-row-header {
  font-size: 14px;
  color: var(--text);
  line-height: 1.4;
}
.hitl-row-explanation {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  font-style: italic;
}
.hitl-row-issue-types {
  font-size: 12px;
  color: var(--accent-amber);
  font-weight: 500;
}
.hitl-row-decided {
  background: rgba(52, 211, 153, 0.1);
  border: 1px solid rgba(52, 211, 153, 0.3);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 13px;
  color: var(--text);
}
.hitl-row-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.hitl-choice-btn--selected {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  background: var(--accent);
  color: #fff;
}
.hitl-row-freetext {
  display: flex;
  align-items: center;
  gap: 6px;
}
.hitl-row-freetext .hitl-freetext-input {
  flex: 1;
}
.hitl-freetext-submit-btn {
  white-space: nowrap;
}
.hitl-row-nav {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 4px;
}
.hitl-nav-btn {
  font-size: 12px;
  padding: 6px 12px;
}
.hitl-submit-all-btn {
  align-self: center;
  min-width: 180px;
}

/* Summary view (all rows decided) */
.hitl-row-summary { display: flex; flex-direction: column; gap: 8px; }
.hitl-row-summary-heading { font-size: 14px; font-weight: 600; color: var(--text); }
.hitl-summary-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.hitl-summary-row { border-bottom: 1px solid var(--border); }
.hitl-summary-row:hover { background: rgba(0, 75, 147, 0.04); }
.hitl-summary-cell-row { padding: 6px 8px; font-weight: 500; color: var(--text-muted); white-space: nowrap; width: 60px; }
.hitl-summary-cell-decision { padding: 6px 8px; color: var(--text); }
.hitl-summary-cell-edit { padding: 6px 8px; text-align: right; color: var(--text-muted); width: 24px; font-size: 14px; }

/* Diagnosis table overview (HITL batch card) */
.hitl-diagnosis-table-wrap {
  margin-bottom: 12px;
  overflow-x: auto;
}
.hitl-diagnosis-table-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 6px;
}
.hitl-diagnosis-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  line-height: 1.4;
}
.hitl-diagnosis-table th {
  text-align: left;
  padding: 5px 8px;
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}
.hitl-diagnosis-table td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hitl-diagnosis-table tr:last-child td { border-bottom: none; }
.hitl-diagnosis-row--problem {
  background: rgba(245, 158, 11, 0.08);
  font-weight: 500;
}
.hitl-diagnosis-row--problem td:first-child {
  border-left: 3px solid var(--accent-amber);
}
.hitl-diagnosis-cell--highlight {
  background: rgba(245, 158, 11, 0.18);
  font-weight: 700;
}

/* ================================================================
   File Browser Panel
   ================================================================ */
.file-browser-panel {
  position: relative;
  width: 12.5rem; /* 200px */
  min-width: 100px;
  max-width: 600px;
  background: var(--bg-sidebar);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.file-browser-panel.collapsed {
  width: 0 !important;
  min-width: 0 !important;
  padding: 0 !important;
  overflow: hidden;
  border-left: none;
}

.browser-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-height);
  padding: 0 12px;
  position: relative;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  flex-shrink: 0;
  gap: 8px;
}

/* Inset dividers (do not touch the side edges), matching the left panel and the
   pagination. Drawn as pseudo-elements so the content keeps its own padding. */
.browser-header::after,
.browser-search::after {
  content: "";
  position: absolute;
  left: var(--divider-inset);
  right: var(--divider-inset);
  bottom: 0;
  height: 1px;
  background: var(--border);
  pointer-events: none;
}

.browser-toggle {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: var(--radius);
  transition: color var(--transition), background var(--transition), border-color var(--transition);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  line-height: 1;
}

.browser-toggle:hover {
  color: var(--accent-red);
  background: var(--bg-sidebar);
  border-color: var(--accent-red);
}

.browser-open-btn {
  display: none;
  width: 36px;
  height: 36px;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  align-self: center;
  margin: 0 12px;
  transition: color var(--transition), background var(--transition);
}
.browser-open-btn:hover {
  color: var(--text);
  background: var(--bg-hover);
}
.file-browser-panel.collapsed ~ .browser-open-btn {
  display: flex;
  align-items: center;
  justify-content: center;
}

.browser-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 12px 0; /* horizontal 12px keeps the pagination divider at --divider-inset */
  display: flex;
  flex-direction: column;
}

.browser-resize-handle {
  position: absolute;
  left: 0;
  top: 0;
  width: 4px;
  height: 100%;
  cursor: col-resize;
  background: transparent;
  transition: background var(--transition);
  z-index: 1;
}
.browser-resize-handle:hover,
.browser-resize-handle:active {
  background: var(--accent);
}

/* ================================================================
   File Preview Panel
   ================================================================ */
.file-preview-panel {
  position: relative;
  width: 0;
  min-width: 0;
  max-width: 0;
  background: var(--bg-sidebar);
  border-left: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  transition: width 0.2s ease, min-width 0.2s ease, max-width 0.2s ease;
  pointer-events: none;
}

.file-preview-panel.open {
  width: 28.125rem; /* 450px */
  min-width: 250px;
  max-width: 900px;
  pointer-events: auto;
  border-left: 1px solid var(--border);
}

.resize-handle {
  position: absolute;
  left: 0;
  top: 0;
  width: 4px;
  height: 100%;
  cursor: col-resize;
  background: transparent;
  z-index: 1;
  transition: background var(--transition);
}

.resize-handle:hover,
.resize-handle:active {
  background: var(--accent);
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  flex-shrink: 0;
  gap: 8px;
}

.preview-filename {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.preview-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: var(--radius);
  transition: color var(--transition), background var(--transition);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  line-height: 1;
}

.preview-close:hover {
  color: var(--accent-red);
  background: var(--bg-hover);
}

.preview-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px;
}

/* ================================================================
   Chat-main flex update (shrinks when panels open)
   ================================================================ */
.chat-main {
  flex: 1;
  min-width: 0;
}

/* ================================================================
   Mobile breakpoint
   ================================================================ */
@media (max-width: 768px) {
  /* Mobile toggle button */
  .mobile-browser-toggle { display: inline-flex !important; }

  /* File Browser — fixed overlay */
  .file-browser-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 80vw !important;
    max-width: 320px;
    height: 100vh;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .file-browser-panel.collapsed { width: 80vw !important; }
  .file-browser-panel.browser-open {
    display: flex;
    transform: translateX(0);
    border-left: none;
    border-right: 1px solid var(--border);
  }

  /* File Preview — bottom sheet */
  .file-preview-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100% !important;
    min-width: 0;
    max-width: none;
    height: 0;
    border-left: none;
    border-top: 1px solid var(--border);
    transition: height 0.2s ease;
  }
  .file-preview-panel.open {
    width: 100% !important;
    min-width: 0;
    max-width: none;
    height: 50vh;
    border-radius: var(--radius) var(--radius) 0 0;
  }
  .resize-handle { display: none !important; }

  /* File ref cards */
  .file-ref-card { padding: 6px 10px; }
  .file-ref-name { font-size: 0.8rem; }
  .file-ref-summary { font-size: 0.72rem; }
}

/* ------------------------------------------------------------------ File Browser Search */
.browser-search {
  padding: 6px var(--divider-inset);
  position: relative;
  flex-shrink: 0;
}
.browser-search-input {
  width: 100%;
  padding: 5px 8px;
  font-size: 0.8rem;
  font-family: var(--font-mono);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color var(--transition);
}
.browser-search-input::placeholder { color: var(--text-muted); opacity: 0.7; }
.browser-search-input:focus { border-color: var(--accent); }

/* ------------------------------------------------------------------ File Browser Header Actions */
.browser-header-actions { display: flex; align-items: center; gap: 4px; }
.browser-refresh-btn {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  flex-shrink: 0;
  transition: color var(--transition), background var(--transition), border-color var(--transition);
}
.browser-refresh-btn:hover { color: var(--accent); background: var(--bg-sidebar); border-color: var(--accent); }

/* ------------------------------------------------------------------ File Browser Tree */
.tree-list { list-style: none; padding: 0; margin: 4px 0; }
.tree-item { cursor: pointer; padding: 2px 8px; font-size: 0.85rem; }
.tree-item:hover { background: var(--bg-hover); }
.tree-item.active { background: var(--accent-dim); color: var(--accent); }
.tree-label { display: flex; align-items: center; gap: 4px; padding: 2px 0; }
.tree-icon { flex-shrink: 0; }
.tree-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-children { padding-left: 16px; }
.tree-spinner { text-align: center; padding: 20px; color: var(--accent); }
.tree-error { text-align: center; padding: 20px; color: #d93025; font-size: 0.85rem; }
.tree-empty { text-align: center; padding: 20px; color: #7a7a7a; font-size: 0.85rem; }

/* ------------------------------------------------------------------ File Browser Pagination */
.tree-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: var(--pagination-padding-top) 4px var(--pagination-padding-bottom);
  border-top: 1px solid var(--border);
  margin-top: auto; /* pin to the bottom of the panel */
  flex-shrink: 0;
}
.tree-page-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
  padding: 2px 8px;
  border-radius: 4px;
  transition: background var(--transition), color var(--transition);
}
.tree-page-btn:hover { background: var(--bg-hover); color: var(--accent); }
.tree-page-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); cursor: default; }
.tree-page-btn.disabled { opacity: 0.4; cursor: not-allowed; }
.tree-page-label { font-size: 0.8rem; color: var(--text-muted); }

/* ------------------------------------------------------------------ File Preview Code (light theme override) */
.preview-content pre {
  background: #f7f8fa;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 0;
}
.preview-content pre code.hljs {
  background: #f7f8fa;
  color: #333333;
}
.preview-content .hljs-attr { color: #005cc5; }
.preview-content .hljs-string { color: #22863a; }
.preview-content .hljs-number { color: #005cc5; }
.preview-content .hljs-literal { color: #005cc5; }
.preview-content .hljs-keyword { color: #d73a49; }
.preview-content .hljs-built_in { color: #e36209; }
.preview-content .hljs-comment { color: #6a737d; }
.preview-content .hljs-punctuation { color: #333333; }

/* ------------------------------------------------------------------ File Preview States */
.preview-loading { text-align: center; padding: 40px 20px; color: var(--accent); font-size: 0.9rem; }
.preview-error { text-align: center; padding: 40px 20px; color: #d93025; font-size: 0.85rem; }
.preview-metadata { padding: 20px; }
.meta-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 0.85rem; }
.meta-label { color: #7a7a7a; }
.meta-value { color: #4a4a4a; font-family: var(--font-sans); }
.preview-download-btn { display: inline-block; margin-top: 16px; padding: 8px 16px; background: var(--accent); color: #fff; border-radius: var(--radius); text-decoration: none; font-size: 0.85rem; font-weight: 600; }
.preview-download-btn:hover { opacity: 0.9; }
.preview-iframe {
  width: 100%;
  height: 100%;
  border: none;
  min-height: 400px;
}
.preview-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* ------------------------------------------------------------------ File Reference Cards in Chat */
.file-ref-cards { padding: 8px 16px; display: flex; flex-direction: column; gap: 6px; }
.file-ref-card { display: flex; gap: 10px; align-items: flex-start; background: var(--bg-card); border-left: 3px solid var(--accent); border-radius: var(--radius); padding: 8px 12px; cursor: pointer; transition: background 0.15s ease; }
.file-ref-card:hover { background: var(--bg-hover); }
.file-ref-icon { font-size: 1.3rem; flex-shrink: 0; padding-top: 2px; }
.file-ref-body { flex: 1; min-width: 0; }
.file-ref-name { font-size: 0.85rem; font-weight: 600; color: #4a4a4a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-ref-summary { font-size: 0.78rem; color: #7a7a7a; margin-top: 2px; display: -webkit-box; line-clamp: 2; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ------------------------------------------------------------------ Batch Confirm Details */
.hitl-confirm-details { margin-top: 10px; padding: 8px; background: #f8f9fa; border-radius: 4px; border: 1px solid #e0e0e0; }
.hitl-confirm-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
.hitl-confirm-table th { text-align: left; padding: 4px 8px; border-bottom: 1px solid #dee2e6; font-weight: 600; color: #495057; }
.hitl-confirm-table td { padding: 4px 8px; border-bottom: 1px solid #f0f0f0; }
.hitl-confirm-table tr:last-child td { border-bottom: none; }
.file-ref-meta { display: flex; gap: 12px; margin-top: 4px; }
.file-ref-type { font-size: 0.72rem; color: var(--accent); background: var(--accent-dim); padding: 1px 6px; border-radius: 3px; text-transform: uppercase; }
.file-ref-size { font-size: 0.72rem; color: #7a7a7a; }
