:root {
  --primary: #006EB7;
  --sidebar-w: 208px;
  --topbar-h: 80px;
}

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

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: #fff;
  color: #1e293b;
  overflow: hidden;
}

/* ── Sidebar ── */

.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: #fff;
  border-right: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  z-index: 20;
}

.sidebar-brand {
  padding: 24px 20px;
}

.sidebar-brand a {
  display: block;
  text-decoration: none;
}

.sidebar-wordmark {
  height: 28px;
  width: auto;
  display: block;
}

.sidebar-divider {
  height: 1px;
  background: #e2e8f0;
}

.sidebar-nav {
  flex: 1;
  padding: 20px 16px;
}

.sidebar-section-title {
  padding: 0 12px 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  border-radius: 10px;
  border: 1px solid rgba(0, 110, 183, 0.25);
  color: var(--primary);
  background: #fff;
  transition: all 0.15s;
  margin-bottom: 8px;
}

.sidebar-link:hover {
  background: #f1f5f9;
  border-color: var(--primary);
}

.sidebar-link-active {
  background: #e2e8f0;
  border-color: var(--primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.sidebar-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* ── History list ── */

.history-list {
  overflow-y: auto;
  max-height: calc(100vh - 480px);
}

.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  color: #475569;
  text-decoration: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  margin-bottom: 2px;
  border: 1px solid transparent;
}

.history-item:hover {
  background: #f1f5f9;
  color: var(--primary);
}

.history-item-active {
  background: #e2e8f0;
  color: var(--primary);
  border-color: rgba(0, 110, 183, 0.2);
  font-weight: 600;
}

.history-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-delete {
  opacity: 0;
  width: 16px;
  height: 16px;
  color: #94a3b8;
  flex-shrink: 0;
  cursor: pointer;
  transition: all 0.15s;
}

.history-item:hover .history-delete {
  opacity: 1;
}

.history-delete:hover {
  color: #ef4444;
}

.history-empty {
  padding: 8px 12px;
  font-size: 12px;
  color: #94a3b8;
  font-style: italic;
}

.history-list::-webkit-scrollbar { width: 4px; }
.history-list::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 2px;
}

/* ── Footer ── */

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid #e2e8f0;
}

.sidebar-back {
  display: block;
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  color: #64748b;
  border-radius: 10px;
  transition: all 0.15s;
}

.sidebar-back:hover {
  background: #f1f5f9;
  color: var(--primary);
}

/* ── Topbar / Header ── */

.topbar {
  position: relative;
  height: var(--topbar-h);
  border-bottom: 1px solid #e2e8f0;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.topbar-title {
  font-size: 28px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--primary);
}

.demo-badge {
  position: absolute;
  top: 50%;
  right: 24px;
  transform: translateY(-50%);
  background: #f59e0b;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 4px 12px;
  border-radius: 6px;
}

.topbar-line {
  width: 128px;
  height: 3px;
  border-radius: 99px;
  background: rgba(0, 110, 183, 0.8);
}

/* ── Main area ── */

.main-area {
  position: fixed;
  top: 0; left: var(--sidebar-w);
  right: 0; bottom: 0;
  display: flex;
  flex-direction: column;
}

.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px 24px 20px;
  min-height: 0;
}

/* ── Chat window ── */

.chat-window {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Chat messages ── */

.chat-line {
  display: flex;
  max-width: 75%;
}

.chat-line.user {
  align-self: flex-end;
}

.chat-line.assistant {
  align-self: flex-start;
}

.bubble {
  padding: 12px 18px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.55;
  word-wrap: break-word;
}

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

.assistant-bubble {
  background: #f1f5f9;
  color: #1e293b;
  border: 1px solid #e2e8f0;
  border-bottom-left-radius: 4px;
}

/* ── Prompt bar ── */

.prompt-bar {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 12px 0 0;
  flex-shrink: 0;
}

#prompt {
  flex: 1;
  resize: none;
  padding: 12px 16px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: #fff;
  color: #1e293b;
  min-height: 48px;
  max-height: 120px;
  transition: border-color 0.15s;
}

#prompt:focus {
  outline: none;
  border-color: var(--primary);
}

.prompt-bar button {
  padding: 12px 24px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: var(--primary);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s;
  min-height: 48px;
  white-space: nowrap;
}

.prompt-bar button:hover {
  background: #005a96;
}

.chat-options {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  padding: 0 2px;
  flex-shrink: 0;
}

.model-info {
  font-size: 12px;
  color: #94a3b8;
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #64748b;
  cursor: pointer;
  user-select: none;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #cbd5e1;
  border-radius: 20px;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 2px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--primary);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(16px);
}

/* ── Scrollbar ── */

.chat-window::-webkit-scrollbar { width: 6px; }
.chat-window::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 3px;
}

/* ── Knowledge Page ── */

.knowledge-page {
  max-width: 700px;
  margin: 0 auto;
}

.knowledge-header h2 {
  font-size: 22px;
  font-weight: 600;
  color: #1e293b;
  margin-bottom: 6px;
}

.knowledge-header p {
  font-size: 14px;
  color: #64748b;
  line-height: 1.5;
  margin-bottom: 24px;
}

.knowledge-upload {
  border: 2px dashed #cbd5e1;
  border-radius: 16px;
  padding: 48px 32px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 24px;
}

.knowledge-upload:hover,
.knowledge-upload.drag-over {
  border-color: var(--primary);
  background: rgba(0, 110, 183, 0.04);
}

.upload-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  color: #94a3b8;
}

.upload-icon svg {
  width: 100%;
  height: 100%;
}

.upload-text {
  font-size: 14px;
  color: #64748b;
  line-height: 1.6;
}

.upload-text strong {
  font-size: 16px;
  color: #1e293b;
}

/* Progress */

.progress-section {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 20px 24px;
  margin-bottom: 24px;
}

.progress-title {
  font-size: 14px;
  font-weight: 600;
  color: #1e293b;
  margin-bottom: 12px;
}

.progress-bar-wrap {
  height: 8px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.progress-detail {
  font-size: 12px;
  color: #64748b;
}

/* Stats */

.knowledge-stats {
  margin-top: 8px;
}

.knowledge-stats h3 {
  font-size: 16px;
  font-weight: 600;
  color: #1e293b;
  margin-bottom: 16px;
}

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

.stat-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 20px;
  text-align: center;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: 13px;
  color: #64748b;
  margin-top: 4px;
}

.doc-list {
  margin-bottom: 16px;
}

.doc-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  font-size: 13px;
  color: #475569;
  border-bottom: 1px solid #f1f5f9;
}

.doc-info {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
}

.doc-info::before {
  content: '';
  width: 8px;
  height: 8px;
  background: var(--primary);
  border-radius: 50%;
  flex-shrink: 0;
}

.doc-delete {
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 500;
  color: #ef4444;
  background: none;
  border: 1px solid #fecaca;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}

.doc-delete:hover {
  background: #fef2f2;
  border-color: #ef4444;
}

.doc-delete:disabled {
  opacity: 0.5;
  cursor: default;
}

.btn-danger {
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 600;
  color: #ef4444;
  background: #fff;
  border: 1px solid #fecaca;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-danger:hover {
  background: #fef2f2;
  border-color: #ef4444;
}

/* ── Typing animation ── */

.typing-dots span {
  display: inline-block;
  font-size: 24px;
  color: var(--primary);
  animation: blink 1.4s infinite both;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes blink {
  0%, 80%, 100% { opacity: 0.2; }
  40% { opacity: 1; }
}

/* ── Responsive ── */

@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  .sidebar { display: none; }
  .topbar-title { font-size: 22px; }
  .content { padding: 12px 16px 16px; }
  .chat-line { max-width: 90%; }
  .bubble { font-size: 14px; }
}
