/* =========================================================
   Consumer Council RAG — Design System
   Brand: Hong Kong Consumer Council
   Primary: #00703C (HKCC Green), Surface: light neutrals
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+HK:wght@400;500;600;700&family=Noto+Sans:wght@400;500;600;700&display=swap');

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

:root {
  --color-primary: #00703C;
  --color-primary-hover: #005C31;
  --color-primary-light: #e6f4ed;
  --color-primary-muted: #b8dcc8;

  --color-bg: #f7f7f5;
  --color-surface: #ffffff;
  --color-surface-raised: #fafaf8;
  --color-border: #e2e0dc;
  --color-border-light: #eeece8;

  --color-text: #1a1a18;
  --color-text-secondary: #4a4a46;
  --color-muted: #7c7c76;

  --color-user-bubble: #00703C;
  --color-user-text: #ffffff;
  --color-agent-bubble: #f0f0ec;
  --color-agent-text: #1a1a18;

  --color-success: #00703C;
  --color-error: #c4352a;
  --color-warning: #b86e00;

  --radius: 10px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.06), 0 0 1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.08), 0 0 1px rgba(0, 0, 0, 0.04);

  --font: 'Noto Sans', 'Noto Sans HK', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Consolas', monospace;

  --header-height: 52px;
  --sidebar-width: 272px;
  --content-max-width: 960px;

  --sidebar-bg: #f2f2f0;
  --sidebar-border: #e4e3df;
  --sidebar-text: #1a1a18;
  --sidebar-muted: #8a8a84;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ---- Header ---- */

.site-header {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  height: var(--header-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  z-index: 100;
  transition: left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.site-header.sidebar-collapsed {
  left: 0;
}

.header-inner {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}

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

.sidebar-toggle-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-muted);
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-toggle-btn:hover {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.header-nav {
  margin-left: auto;
  display: flex;
  gap: 4px;
}

.nav-link {
  text-decoration: none;
  color: var(--color-muted);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.nav-link svg {
  flex-shrink: 0;
}

.nav-link:hover {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.nav-link.active {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

/* ---- Sidebar (light gray) ---- */

.chat-sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.2s;
  z-index: 110;
}

.chat-sidebar.collapsed {
  width: 0;
  opacity: 0;
  border-right: none;
}

/* Sidebar top: logo + collapse button */
.sidebar-brand {
  padding: 20px 12px;
  border-bottom: 1px solid var(--sidebar-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: 6px;
}

.sidebar-brand-logo {
  height: 28px;
  width: auto;
  min-width: 0;
  object-fit: contain;
}

.sidebar-collapse-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--sidebar-muted);
  padding: 5px;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-collapse-btn:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--sidebar-text);
}

/* Sidebar section label */
.sidebar-header {
  padding: 12px 16px 4px;
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--sidebar-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Full-width New Chat button */
.btn-new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 6px 12px 8px;
  padding: 8px 12px;
  background: var(--color-primary);
  color: var(--sidebar-text);
  border: 1px var(--color-primary-light);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--color-surface);
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  flex-shrink: 0;
}

.btn-new-chat svg {
  flex-shrink: 0;
  stroke: currentColor;
  fill: none;
}

.btn-new-chat:hover {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
  color: var(--color-surface);
}

/* Session list */
.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px;
}

.session-list::-webkit-scrollbar {
  width: 4px;
}

.session-list::-webkit-scrollbar-track {
  background: transparent;
}

.session-list::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
  border-radius: 2px;
}

.session-item {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s;
  margin-bottom: 1px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
}

.session-item:hover {
  background: rgba(0, 0, 0, 0.05);
}

.session-item.active {
  background: var(--color-primary-light);
  box-shadow: 0 0 0 1px var(--color-primary-muted);
}

.session-item-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.session-item-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--sidebar-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  line-height: 1.35;
}

.session-item.active .session-item-title {
  color: var(--color-primary);
  font-weight: 600;
}

.session-item-time {
  font-size: 10px;
  color: var(--sidebar-muted);
  line-height: 1.3;
}

.session-delete-btn {
  display: none;
  background: none;
  border: none;
  color: var(--sidebar-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 0 3px;
  flex-shrink: 0;
  transition: color 0.15s;
  margin-top: 1px;
}

.session-item:hover .session-delete-btn {
  display: block;
}

.session-delete-btn:hover {
  color: var(--color-error);
}

/* Sidebar footer */
.sidebar-footer {
  padding: 16px 16px;
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.sidebar-footer-text {
  font-size: 10px;
  color: var(--sidebar-muted);
  letter-spacing: 0.02em;
}

.sidebar-footer-logo {
  height: 16px;
  width: auto;
  opacity: 0.8;
  transition: opacity 0.15s;
}

.sidebar-footer-logo:hover {
  opacity: 0.85;
}

/* ---- Shared button ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
  white-space: nowrap;
}

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

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}

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

/* ---- Chat layout ---- */

.chat-layout {
  display: flex;
  height: 100vh;
  padding-left: var(--sidebar-width);
  transition: padding-left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-layout.sidebar-collapsed {
  padding-left: 0;
}

.chat-main {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  height: 100%;
  padding-top: var(--header-height);
}

/* ---- Messages area ---- */

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message {
  display: flex;
  flex-direction: column;
  max-width: min(80%, var(--content-max-width));
  gap: 4px;
  animation: messageIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  margin-left: auto;
  margin-right: auto;
  width: 100%;
  max-width: var(--content-max-width);
}

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

.message.user {
  align-items: flex-end;
}

.message.agent {
  align-items: flex-start;
}

.message.user .message-bubble {
  max-width: 75%;
}

.message.agent .message-bubble {
  max-width: 90%;
}

.message-role {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-muted);
}

.message-bubble {
  padding: 24px 32px;
  border-radius: var(--radius-lg);
  line-height: 1.6;
  word-break: break-word;
}

.message.user .message-bubble {
  background: var(--color-user-bubble);
  color: var(--color-user-text);
  border-bottom-right-radius: 4px;
  padding: 16px 24px;
}

.message.agent .message-bubble {
  background: var(--color-agent-bubble);
  color: var(--color-agent-text);
}

/* Markdown in agent bubbles */
.message.agent .message-bubble p { margin: 0 0 0.6em; }
.message.agent .message-bubble p:last-child { margin-bottom: 0; }
.message.agent .message-bubble h1,
.message.agent .message-bubble h2,
.message.agent .message-bubble h3,
.message.agent .message-bubble h4 {
  margin: 1em 0 0.4em;
  font-weight: 700;
  line-height: 1.3;
}
.message.agent .message-bubble h1:first-child,
.message.agent .message-bubble h2:first-child,
.message.agent .message-bubble h3:first-child { margin-top: 0; }
.message.agent .message-bubble h1 { font-size: 1.25em; }
.message.agent .message-bubble h2 { font-size: 1.15em; }
.message.agent .message-bubble h3 { font-size: 1.05em; }

.message.agent .message-bubble ul,
.message.agent .message-bubble ol {
  margin: 0.4em 0 0.6em;
  padding-left: 1.4em;
}
.message.agent .message-bubble li { margin-bottom: 0.2em; }

.message.agent .message-bubble code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: rgba(0, 0, 0, 0.06);
  padding: 2px 5px;
  border-radius: 3px;
}

.message.agent .message-bubble pre {
  margin: 0.6em 0;
  padding: 12px 14px;
  background: #1a1a18;
  color: #e8e6e0;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-size: 13px;
  line-height: 1.5;
}

.message.agent .message-bubble pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

.message.agent .message-bubble blockquote {
  border-left: 3px solid var(--color-primary);
  padding: 4px 0 4px 12px;
  margin: 0.5em 0;
  color: var(--color-text-secondary);
}

.message.agent .message-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.6em 0;
  font-size: 0.92em;
}

.message.agent .message-bubble th,
.message.agent .message-bubble td {
  border: 1px solid var(--color-border);
  padding: 6px 10px;
  text-align: left;
}

.message.agent .message-bubble th {
  background: rgba(0, 0, 0, 0.04);
  font-weight: 600;
}

.message.agent .message-bubble tbody tr {
  background: #ffffff;
}

.message.agent .message-bubble a {
  color: var(--color-primary);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.message.agent .message-bubble a:hover {
  color: var(--color-primary-hover);
}

.message.agent .message-bubble hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 0.8em 0;
}

/* ---- Streaming / loading states ---- */

.loading-bubble {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 14px 16px;
}

.loading-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-primary);
  animation: dotPulse 1.4s infinite ease-in-out;
}

.loading-dot:nth-child(2) { animation-delay: 0.15s; }
.loading-dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes dotPulse {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.3; }
  40% { transform: scale(1); opacity: 1; }
}

.streaming-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0 4px;
  font-size: 12px;
  color: var(--color-primary);
  font-weight: 500;
  animation: fadeInUp 0.3s ease;
}

.streaming-indicator .streaming-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-primary);
  animation: streamPulse 1.5s infinite ease-in-out;
}

.streaming-indicator .streaming-label {
  animation: textShimmer 2s infinite;
}

@keyframes streamPulse {
  0%, 100% { opacity: 0.3; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.2); }
}

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

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

.streaming-cursor::after {
  content: '';
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--color-primary);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: cursorBlink 0.8s infinite;
}

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

.event-log-streaming {
  position: relative;
  overflow: hidden;
}

.event-log-streaming::before {
  content: '';
  position: absolute;
  top: 0;
  width: 20vw;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--color-primary), transparent);
  animation: traceSlide 2s infinite linear;
}

@keyframes traceSlide {
  0% { left: -20vw; }
  100% { left: 100%; }
}

/* ---- Chat input bar ---- */

.chat-input-bar {
  padding: 12px 32px 20px;
  background: var(--color-bg);
}

.chat-input-inner {
  max-width: var(--content-max-width);
  width: 100%;
  margin: 0 auto;
}

.chat-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-input-wrap:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

.chat-textarea {
  flex: 1;
  resize: none;
  border: none;
  border-radius: var(--radius-lg);
  padding: 15px 48px 15px 12px;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text);
  background: transparent;
  outline: none;
  min-height: 44px;
  max-height: 160px;
  overflow-y: auto;
}

.chat-textarea::placeholder {
  color: var(--color-muted);
}

.btn-send {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  width: 34px;
  height: 34px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.btn-send:hover:not(:disabled) {
  background: var(--color-primary-hover);
}

.btn-send:active:not(:disabled) {
  transform: translateY(-50%) scale(0.93);
}

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

.btn-send svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---- Empty chat welcome state ---- */

.empty-chat-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}

.empty-chat-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 640px;
  width: 100%;
  gap: 12px;
}

.empty-chat-logo {
  height: 56px;
  width: auto;
  margin-bottom: 4px;
  opacity: 0.9;
}

.empty-chat-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -0.01em;
}

.empty-chat-subtitle {
  font-size: 13px;
  color: var(--color-muted);
  line-height: 1.5;
  max-width: 420px;
}

.empty-chat-input-wrap {
  width: 100%;
  margin-top: 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

.empty-chat-input-wrap .chat-input-wrap {
  width: 100%;
}

.empty-chat-doc-count {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: #7a7d72;
  background: #ecede9;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
}

.empty-chat-doc-count svg {
  flex-shrink: 0;
  opacity: 0.6;
}

/* ---- Upload page ---- */

.upload-layout {
  padding-left: var(--sidebar-width);
  transition: padding-left 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.upload-layout.sidebar-collapsed {
  padding-left: 0;
}

.upload-main {
  max-width: 760px;
  margin: 0 auto;
  padding: calc(var(--header-height) + 40px) 24px 48px;
  display: flex;
  flex-direction: column;
  gap: 48px;
}

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

.upload-section-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  background: var(--color-primary-light);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.upload-section-icon svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.section-heading {
  font-size: 20px;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -0.01em;
}

.section-desc {
  color: var(--color-text-secondary);
  margin-bottom: 20px;
  font-size: 14px;
  line-height: 1.5;
}

/* Drag-and-drop zone */
.drop-zone {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-lg);
  padding: 48px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  background: var(--color-surface);
  text-align: center;
}

.drop-zone:hover,
.drop-zone.drag-over {
  border-color: var(--color-primary);
  background: var(--color-primary-light);
}

.drop-zone-icon {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--color-primary-light);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, background 0.2s;
}

.drop-zone:hover .drop-zone-icon,
.drop-zone.drag-over .drop-zone-icon {
  transform: scale(1.08);
  background: var(--color-primary-muted);
}

.drop-zone-icon svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.drop-zone-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text);
}

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

.drop-zone-hint .browse-link {
  color: var(--color-primary);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}

.drop-zone-file-info {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--color-primary-light);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--color-primary);
}

.drop-zone-file-info svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.upload-actions {
  margin-top: 16px;
  display: flex;
  justify-content: center;
}

/* Progress bar */
.progress-bar-wrap {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.progress-bar {
  height: 4px;
  background: var(--color-border);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: 2px;
  animation: indeterminate 1.6s infinite ease-in-out;
  width: 35%;
}

@keyframes indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}

.progress-label {
  font-size: 13px;
  color: var(--color-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.progress-label .spinner-sm {
  width: 14px;
  height: 14px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Upload result */
.upload-result {
  margin-top: 16px;
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.6;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.upload-result.success {
  background: var(--color-primary-light);
  color: var(--color-primary);
  border: 1px solid var(--color-primary-muted);
}

.upload-result.error {
  background: #fef2f2;
  color: var(--color-error);
  border: 1px solid #fecaca;
}

.upload-result svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
  margin-top: 1px;
}

/* Documents list */
.docs-section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.docs-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.doc-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.doc-card:hover {
  border-color: var(--color-primary-muted);
  box-shadow: var(--shadow);
}

.doc-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.doc-filename {
  font-size: 14px;
  font-weight: 600;
  word-break: break-all;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
}

.doc-filename svg {
  width: 16px;
  height: 16px;
  stroke: var(--color-primary);
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

.btn-preview {
  background: var(--color-primary);
  color: var(--color-surface);
  font-size: 12px;
  padding: 8px 14px;
  border-radius: var(--radius-md);
  text-decoration: none;
  font-weight: 600;
  font-family: var(--font);
  flex-shrink: 0;
  border: none;
  cursor: pointer;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-preview:hover {
  background: var(--color-primary-hover);
}

.btn-preview svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.doc-meta {
  font-size: 12px;
  color: var(--color-muted);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.doc-topics {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 4px;
}

.topic-tag {
  background: #FBF2EE;
  color: #534839;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 500;
}

.loading-text {
  color: var(--color-muted);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.empty-text {
  color: var(--color-muted);
  font-size: 14px;
  font-style: italic;
}

/* ---- Event log (agent trace) ---- */

.event-log-container {
  margin-top: 8px;
  width: 100%;
}

.event-log-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-muted);
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font);
  padding: 4px 12px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  user-select: none;
}

.event-log-toggle:hover {
  background: var(--color-primary-light);
  color: var(--color-primary);
  border-color: var(--color-primary);
}

.event-log-toggle-icon {
  font-size: 9px;
  line-height: 1;
}

.event-log {
  margin-top: 6px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 12px;
}

.event-log[aria-hidden="true"] {
  display: none;
}

.event-item {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 5px;
  line-height: 1.4;
  padding: 3px 0;
  border-bottom: 1px solid var(--color-border-light);
  animation: eventFadeIn 0.3s ease;
}

@keyframes eventFadeIn {
  from { opacity: 0; transform: translateX(-4px); }
  to { opacity: 1; transform: translateX(0); }
}

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

.event-type-badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.badge-tool-call {
  background: #ede9fe;
  color: #6d28d9;
}

.badge-tool-response {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.badge-search {
  background: #fef3c7;
  color: #92400e;
}

.event-thinking {
  font-style: italic;
  color: var(--color-muted);
  padding-left: 4px;
}

.event-tool-name {
  font-weight: 600;
  color: var(--color-text);
}

.event-result-summary {
  color: var(--color-muted);
  word-break: break-word;
}

.event-args-toggle {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: 3px;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--color-muted);
  padding: 1px 5px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.event-args-toggle:hover {
  background: var(--color-primary-light);
  color: var(--color-primary);
}

.event-args {
  width: 100%;
  margin-top: 4px;
  padding: 6px 8px;
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--color-text);
  white-space: pre;
  overflow-x: auto;
  line-height: 1.5;
}

.event-args[aria-hidden="true"] {
  display: none;
}

.event-search-query {
  font-style: italic;
  color: var(--color-text);
}

.event-search-count {
  color: var(--color-muted);
}

.event-snippets {
  width: 100%;
  list-style: disc;
  padding-left: 18px;
  margin-top: 3px;
  color: var(--color-muted);
}

.event-snippets li {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* ---- Preview modal ---- */

.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-modal.hidden {
  display: none !important;
}

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

.preview-modal-content {
  position: relative;
  width: 92vw;
  height: 88vh;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1;
}

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

.preview-modal-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-modal-close {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--color-muted);
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  transition: color 0.15s;
}

.preview-modal-close:hover {
  color: var(--color-text);
}

.preview-modal-iframe {
  flex: 1;
  border: none;
  width: 100%;
}

/* ---- Source citation links ---- */

.source-link {
  color: var(--color-primary) !important;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  font-weight: 500;
  cursor: pointer;
}

.source-link:hover {
  color: var(--color-primary-hover) !important;
  text-decoration-thickness: 2px;
}

/* ---- Utilities ---- */

.hidden {
  display: none !important;
}

/* ---- Responsive ---- */

@media (max-width: 768px) {
  :root {
    --sidebar-width: 0px;
  }

  .chat-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 272px;
    z-index: 110;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.12);
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .chat-sidebar:not(.collapsed) {
    transform: translateX(0);
  }

  .chat-sidebar.collapsed {
    width: 272px;
    opacity: 1;
    transform: translateX(-100%);
  }

  .site-header {
    left: 0 !important;
  }

  .chat-layout {
    padding-left: 0 !important;
  }

  .upload-layout {
    padding-left: 0 !important;
  }

  .messages {
    padding: 20px 16px 12px;
  }

  .chat-input-bar {
    padding: 10px 16px 16px;
  }

  .message.user .message-bubble {
    max-width: 88%;
  }

  .message.agent .message-bubble {
    max-width: 95%;
  }

  .drop-zone {
    padding: 32px 20px;
  }
}

@media (max-width: 480px) {
  .btn {
    width: 100%;
  }

  .nav-link span {
    display: none;
  }
}
