/* ============================================================
   EONSR HKD Chatbot — Dark Theme
   Color palette from tools/dashboard.html
   ============================================================ */

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #252830;
  --border: #333640;
  --text: #e0e0e6;
  --text2: #8b8fa3;
  --accent: #4f8cff;
  --accent2: #6c5ce7;
  --green: #2ecc71;
  --red: #e74c3c;
  --orange: #f39c12;
  --font: system-ui, -apple-system, sans-serif;
  --mono: 'SF Mono', Monaco, Consolas, monospace;
  --header-h: 48px;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
}

/* ---- Header ---- */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.header h1 {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red);
  transition: background 0.3s;
}

.status-dot.ok {
  background: var(--green);
}

.status-label {
  font-size: 12px;
  color: var(--text2);
  font-family: var(--mono);
}

/* ---- Split Layout ---- */
.split {
  display: flex;
  height: calc(100vh - var(--header-h));
  flex-direction: row;
}

/* ---- Sidebar Panel ---- */
.sidebar-panel {
  width: 260px;
  background-color: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width 0.3s;
}

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

.btn-new-chat {
  width: 100%;
  background-color: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 500;
  border-radius: 6px;
  padding: 10px;
}

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

.session-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.session-item {
  padding: 10px 12px;
  border-radius: 6px;
  background-color: transparent;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: relative;
  border: 1px solid transparent;
}

.session-item:hover {
  background-color: var(--surface2);
}

.session-item.active {
  background-color: var(--surface2);
  border-color: var(--border);
}

.session-title {
  font-weight: 500;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-right: 24px;
}

.session-date {
  font-size: 11px;
  color: var(--text2);
}

.btn-delete-session {
  position: absolute;
  right: 8px;
  top: 10px;
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  opacity: 0;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.session-item:hover .btn-delete-session {
  opacity: 1;
}

.btn-delete-session:hover {
  color: var(--red);
  background-color: rgba(231, 76, 60, 0.15);
}

/* ---- Chat Panel ---- */
.chat-panel {
  width: 50%;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  min-width: 320px;
  transition: width 0.3s;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

/* Scrollbar */
.messages::-webkit-scrollbar {
  width: 6px;
}

.messages::-webkit-scrollbar-track {
  background: transparent;
}

.messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ---- Message Bubbles ---- */
.msg {
  max-width: 90%;
  animation: fadeIn 0.2s ease-out;
}

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

.msg.user {
  align-self: flex-end;
}

.msg.bot {
  align-self: flex-start;
}

.msg-content {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.65;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.msg.user .msg-content {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg.bot .msg-content {
  background: var(--surface2);
  border-bottom-left-radius: 4px;
}

.msg.error .msg-content {
  background: rgba(231, 76, 60, 0.15);
  border: 1px solid var(--red);
  color: var(--red);
}

/* ---- Citations ---- */
.citations {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.citation-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 16px;
  font-size: 12px;
  font-family: var(--mono);
  color: var(--accent);
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}

.citation-chip:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  transform: translateY(-1px);
}

.citation-chip .chip-icon {
  font-size: 11px;
}

/* ---- Web References ---- */
.web-references {
  margin-top: 10px;
}

.web-refs-label {
  font-size: 11px;
  color: var(--text2);
  font-family: var(--mono);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.web-refs-label span {
  letter-spacing: 0.2px;
}

.web-refs-hint {
  font-size: 12px;
  color: var(--text2);
  margin-bottom: 8px;
  line-height: 1.45;
}

.web-refs-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.web-ref-chip {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 12px;
  color: var(--text);
  text-decoration: none;
  transition: all 0.2s;
  overflow: hidden;
}

.web-ref-chip:hover {
  border-color: var(--orange);
  background: rgba(243, 156, 18, 0.08);
  color: var(--orange);
}

.web-ref-chip .ref-icon {
  flex-shrink: 0;
  font-size: 12px;
  margin-top: 1px;
}

.web-ref-chip .ref-main {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.web-ref-chip .ref-title {
  font-weight: 500;
  line-height: 1.35;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.web-ref-chip .ref-snippet {
  color: var(--text2);
  font-size: 11px;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.web-ref-chip .ref-domain {
  flex-shrink: 0;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text2);
  opacity: 0.9;
  margin-top: 2px;
}



/* ---- Message Metadata ---- */
.msg-meta {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text2);
  font-family: var(--mono);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.cache-badge {
  display: inline-block;
  background: rgba(46, 204, 113, 0.15);
  color: var(--green);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
}

/* ---- Typing Indicator ---- */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
}

.typing-indicator span {
  width: 8px;
  height: 8px;
  background: var(--text2);
  border-radius: 50%;
  animation: bounce 1.4s infinite both;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.16s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.32s; }

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

/* ---- Input Bar ---- */
.input-bar {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  background: var(--surface);
}

.input-bar textarea {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-family: var(--font);
  resize: none;
  height: 44px;
  max-height: 120px;
  outline: none;
  transition: border-color 0.2s;
}

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

.input-bar textarea::placeholder {
  color: var(--text2);
}

/* ---- Buttons ---- */
.btn {
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
}

.btn-send {
  padding: 10px 20px;
  background: var(--accent);
  color: #fff;
  flex-shrink: 0;
}

.btn-send:hover {
  background: #3d7aee;
}

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

.btn-small {
  padding: 4px 10px;
  background: var(--surface2);
  color: var(--text2);
  border: 1px solid var(--border);
  font-size: 12px;
}

.btn-small:hover {
  background: var(--border);
  color: var(--text);
}

/* ---- PDF Panel ---- */
.pdf-panel {
  width: 50%;
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: width 0.3s;
}

.pdf-panel.collapsed {
  width: 0;
  min-width: 0;
  overflow: hidden;
}

.pdf-panel.collapsed + .chat-panel,
.chat-panel.expanded {
  width: 100%;
}

.pdf-toolbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 12px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.pdf-title {
  font-size: 13px;
  color: var(--text2);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pdf-panel iframe {
  flex: 1;
  width: 100%;
  border: none;
  background: var(--bg);
}

/* ---- Responsive: Mobile ---- */
@media (max-width: 768px) {
  .header h1 {
    font-size: 13px;
  }

  .split {
    flex-direction: column;
  }

  .sidebar-panel {
    width: 100% !important;
    height: 15vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .chat-panel {
    width: 100% !important;
    height: 55vh;
    min-width: unset;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .pdf-panel {
    width: 100% !important;
    height: 45vh;
  }

  .pdf-panel.collapsed {
    height: 0;
  }

  .msg {
    max-width: 95%;
  }

  .pdf-toolbar {
    height: 32px;
  }

  #pdfToggle {
    display: none;
  }
}
