/* ── Variables ── */
:root {
  --primary:       #2A2A35;
  --accent:        #C4684A;
  --bg:            #FAF7F2;
  --neutral:       #8A8580;
  --border:        #E8E4DF;
  --white:         #FFFFFF;
  --danger:        #C0392B;
  --success:       #27AE60;
  --warning:       #E67E22;

  --font-display:  'Fraunces', Georgia, serif;
  --font-body:     'DM Sans', system-ui, sans-serif;
  --font-mono:     'JetBrains Mono', 'Menlo', monospace;

  --sidebar-width: 260px;
  --radius:        10px;
  --radius-sm:     6px;
  --shadow:        0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.04);
  --shadow-lg:     0 8px 32px rgba(0,0,0,0.12);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.65;
  color: var(--primary);
  background: var(--bg);
  height: 100%;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--primary);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  position: relative;
  z-index: 50;
}

.sidebar-header {
  padding: 20px 16px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.logo-mark {
  color: var(--accent);
  font-size: 1.1rem;
}

.logo-text {
  font-family: var(--font-display);
  font-size: 1.15rem;
  color: var(--white);
  letter-spacing: 0.01em;
}

.new-chat-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.85);
  font-family: var(--font-body);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.new-chat-btn:hover {
  background: rgba(255,255,255,0.14);
  border-color: rgba(255,255,255,0.2);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

.nav-section {
  margin-bottom: 8px;
}

.nav-section-label {
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.35);
  padding: 8px 10px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.65);
  font-size: 0.88rem;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  text-decoration: none;
  margin-bottom: 1px;
}
.nav-item:hover {
  background: rgba(255,255,255,0.08);
  color: rgba(255,255,255,0.9);
  text-decoration: none;
}
.nav-item.active {
  background: rgba(196,104,74,0.15);
  color: var(--white);
  border-left: 2px solid var(--accent);
  padding-left: 8px;
}
.nav-item svg { flex-shrink: 0; opacity: 0.8; }
.nav-item.active svg { opacity: 1; }

.conversation-list {
  margin-top: 4px;
  border-top: 1px solid rgba(255,255,255,0.06);
  padding-top: 4px;
}

.conv-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 10px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.55);
  font-family: var(--font-body);
  font-size: 0.82rem;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.12s, color 0.12s;
  margin-bottom: 1px;
}
.conv-item:hover {
  background: rgba(255,255,255,0.07);
  color: rgba(255,255,255,0.8);
}

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--white);
  font-size: 0.8rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-details { min-width: 0; }
.user-name {
  font-size: 0.82rem;
  color: rgba(255,255,255,0.85);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-role {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.4);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.logout-link {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.35);
  text-decoration: none;
  flex-shrink: 0;
  transition: color 0.15s;
}
.logout-link:hover { color: rgba(255,255,255,0.7); text-decoration: none; }

/* ── Mobile sidebar ── */
.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 200;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--primary);
  border: none;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  color: var(--white);
  box-shadow: var(--shadow);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 40;
  backdrop-filter: blur(2px);
}

/* ── Main content ── */
.main-content {
  flex: 1;
  min-width: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

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

.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  flex: 1;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 40px 0 20px;
  scroll-behavior: smooth;
}

.chat-messages-inner {
  max-width: 780px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.chat-welcome {
  max-width: 780px;
  margin: 60px auto 0;
  padding: 0 24px;
  text-align: center;
}

.welcome-icon {
  font-size: 2rem;
  color: var(--accent);
  margin-bottom: 16px;
  display: block;
}

.chat-welcome h1 {
  font-family: var(--font-display);
  font-size: 1.9rem;
  font-weight: 400;
  color: var(--primary);
  margin-bottom: 8px;
}

.chat-welcome p {
  color: var(--neutral);
  font-size: 1rem;
}

/* ── Chat messages ── */
.chat-msg {
  display: flex;
  flex-direction: column;
}

.chat-msg-user {
  align-items: flex-end;
}

.chat-msg-assistant {
  align-items: flex-start;
}

.msg-bubble-user {
  background: var(--accent);
  color: var(--white);
  padding: 10px 16px;
  border-radius: 18px 18px 4px 18px;
  max-width: 62%;
  font-size: 0.93rem;
  line-height: 1.55;
  word-wrap: break-word;
}

.msg-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 4px 18px 18px 18px;
  padding: 16px 20px;
  max-width: 100%;
  box-shadow: var(--shadow);
  font-size: 0.93rem;
  line-height: 1.7;
}

.msg-meta {
  font-size: 0.72rem;
  color: var(--neutral);
  margin-top: 6px;
  padding: 0 4px;
}

/* ── Markdown inside assistant cards ── */
.msg-card h1, .msg-card h2, .msg-card h3, .msg-card h4 {
  font-family: var(--font-display);
  font-weight: 500;
  color: var(--primary);
  margin-top: 1.2em;
  margin-bottom: 0.4em;
}
.msg-card h1 { font-size: 1.25rem; }
.msg-card h2 { font-size: 1.1rem; }
.msg-card h3 { font-size: 1rem; }
.msg-card h1:first-child, .msg-card h2:first-child, .msg-card h3:first-child { margin-top: 0; }

.msg-card p { margin-bottom: 0.75em; }
.msg-card p:last-child { margin-bottom: 0; }

.msg-card ul, .msg-card ol {
  padding-left: 1.4em;
  margin-bottom: 0.75em;
}
.msg-card li { margin-bottom: 0.2em; }
.msg-card li:last-child { margin-bottom: 0; }

.msg-card table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75em 0;
  font-size: 0.88rem;
}
.msg-card table th {
  background: var(--primary);
  color: var(--white);
  padding: 7px 12px;
  text-align: left;
  font-weight: 500;
}
.msg-card table td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
}
.msg-card table tr:last-child td { border-bottom: none; }
.msg-card table tr:nth-child(even) td { background: rgba(250,247,242,0.6); }

.msg-card pre {
  background: #1e1e2e;
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 0.75em 0;
  position: relative;
}
.msg-card pre code {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: #cdd6f4;
  background: none;
  padding: 0;
  border-radius: 0;
}
.msg-card code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: rgba(42,42,53,0.08);
  color: var(--primary);
  padding: 2px 5px;
  border-radius: 4px;
}

.msg-card blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 14px;
  color: var(--neutral);
  margin: 0.75em 0;
  font-style: italic;
}

.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(255,255,255,0.1);
  border: none;
  border-radius: 4px;
  color: rgba(255,255,255,0.6);
  font-size: 0.72rem;
  font-family: var(--font-body);
  padding: 3px 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.copy-btn:hover { background: rgba(255,255,255,0.2); color: var(--white); }

/* ── Citations ── */
.citation {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 17px;
  height: 17px;
  background: var(--accent);
  color: var(--white);
  border-radius: 50%;
  font-size: 0.65rem;
  font-weight: 600;
  cursor: pointer;
  vertical-align: super;
  margin: 0 1px;
  position: relative;
  text-decoration: none;
  transition: background 0.15s;
}
.citation:hover { background: var(--primary); }

.citation-tooltip {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary);
  color: var(--white);
  font-size: 0.75rem;
  font-family: var(--font-body);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  max-width: 280px;
  white-space: normal;
  z-index: 100;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
  line-height: 1.4;
}
.citation:hover .citation-tooltip { display: block; }
.citation-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--primary);
}

/* ── Thinking indicator ── */
.thinking {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 10px 16px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 4px 18px 18px 18px;
  width: fit-content;
}
.thinking span {
  width: 7px;
  height: 7px;
  background: var(--accent);
  border-radius: 50%;
  animation: thinkBounce 1.2s infinite;
  display: block;
}
.thinking span:nth-child(2) { animation-delay: 0.2s; }
.thinking span:nth-child(3) { animation-delay: 0.4s; }

@keyframes thinkBounce {
  0%, 80%, 100% { transform: scale(0.75); opacity: 0.5; }
  40% { transform: scale(1.1); opacity: 1; }
}

/* ── Tool call indicator ── */
.tool-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--neutral);
  padding: 5px 0;
}
.tool-indicator svg { color: var(--accent); }

/* ── Chat input area ── */
.chat-input-area {
  padding: 12px 24px 20px;
  background: var(--bg);
  flex-shrink: 0;
  max-width: 780px;
  width: 100%;
  margin: 0 auto;
  position: relative;
}

.chat-input-wrapper {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.chat-input-wrapper:focus-within {
  border-color: rgba(196,104,74,0.4);
  box-shadow: 0 2px 8px rgba(196,104,74,0.1);
}

.web-search-toggle {
  padding: 8px 14px 4px;
  border-bottom: 1px solid var(--border);
}

.toggle-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--neutral);
  user-select: none;
}

.toggle-switch {
  width: 30px;
  height: 16px;
  background: var(--border);
  border-radius: 8px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}
.toggle-switch::after {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--white);
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.toggle-label input[type=checkbox] { display: none; }
.toggle-label input:checked + .toggle-switch { background: var(--accent); }
.toggle-label input:checked + .toggle-switch::after { transform: translateX(14px); }
.toggle-text { color: var(--neutral); }

.input-row {
  display: flex;
  align-items: flex-end;
  padding: 8px 12px 10px;
  gap: 8px;
}

#chatInput {
  flex: 1;
  border: none;
  outline: none;
  font-family: var(--font-body);
  font-size: 0.93rem;
  line-height: 1.55;
  color: var(--primary);
  background: transparent;
  resize: none;
  max-height: 180px;
  overflow-y: auto;
}
#chatInput::placeholder { color: var(--neutral); }

.send-btn {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--white);
  flex-shrink: 0;
  transition: background 0.15s;
}
.send-btn:hover:not(:disabled) { background: var(--accent); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.input-hint {
  text-align: center;
  font-size: 0.73rem;
  color: var(--neutral);
  margin-top: 8px;
  opacity: 0.7;
}

/* ── Login page ── */
.login-page .layout { justify-content: center; align-items: center; background: var(--bg); }
.login-page .main-content { display: flex; align-items: center; justify-content: center; }

.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 100vh;
}

.login-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 44px 40px;
  width: 380px;
  box-shadow: var(--shadow-lg);
}

.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 6px;
}
.login-logo .logo-mark { color: var(--accent); font-size: 1.4rem; }
.login-logo .logo-text { font-family: var(--font-display); font-size: 1.5rem; color: var(--primary); }

.login-tagline {
  text-align: center;
  font-size: 0.83rem;
  color: var(--neutral);
  margin-bottom: 28px;
}

/* ── Page inner (non-chat pages) ── */
.page-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 40px 32px;
  width: 100%;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-header h1 {
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 400;
  color: var(--primary);
  line-height: 1.2;
}

.page-subtitle {
  font-size: 0.88rem;
  color: var(--neutral);
  margin-top: 4px;
}

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

.section-block { margin-bottom: 32px; }
.section-block h2 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 400;
  color: var(--primary);
  margin-bottom: 14px;
}

/* ── Card panel ── */
.card-panel {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.table-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  justify-content: flex-end;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 500;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(0.97); }

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

.btn-accent   { background: var(--accent); color: var(--white); }
.btn-accent:hover:not(:disabled)   { background: #b55a3e; }

.btn-ghost {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) { background: var(--bg); }

.btn-full { width: 100%; }

.btn-icon {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--neutral);
  transition: background 0.15s, color 0.15s;
}
.btn-icon:hover { background: var(--bg); color: var(--primary); }

.btn-danger-icon:hover { background: rgba(192,57,43,0.08); color: var(--danger); border-color: rgba(192,57,43,0.3); }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--primary);
  margin-bottom: 5px;
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--primary);
  background: var(--white);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(196,104,74,0.1);
}

.role-select {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.82rem;
  color: var(--primary);
  background: var(--white);
  cursor: pointer;
  outline: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238A8580'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  padding-right: 24px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.88rem;
}

.form-msg {
  font-size: 0.82rem;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  margin-top: 8px;
}
.form-msg.error { background: rgba(192,57,43,0.08); color: var(--danger); border: 1px solid rgba(192,57,43,0.2); }
.form-msg.success { background: rgba(39,174,96,0.08); color: var(--success); border: 1px solid rgba(39,174,96,0.2); }

/* ── Alerts ── */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 16px;
}
.alert-error { background: rgba(192,57,43,0.08); color: var(--danger); border: 1px solid rgba(192,57,43,0.2); }
.alert-success { background: rgba(39,174,96,0.08); color: var(--success); border: 1px solid rgba(39,174,96,0.2); }
.alert-info { background: rgba(42,42,53,0.06); color: var(--primary); border: 1px solid var(--border); }

/* ── Tables ── */
.table-scroll {
  overflow-x: auto;
  width: 100%;
  -webkit-overflow-scrolling: touch;
}
.table-scroll::-webkit-scrollbar { height: 6px; }
.table-scroll::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.2); border-radius: 3px; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
}
.data-table th {
  background: var(--primary);
  color: rgba(255,255,255,0.9);
  padding: 9px 14px;
  text-align: left;
  font-weight: 500;
  font-size: 0.8rem;
  white-space: nowrap;
}
.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--primary);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(250,247,242,0.8); }

.preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.preview-table th {
  background: var(--bg);
  color: var(--neutral);
  padding: 8px 12px;
  text-align: left;
  font-weight: 500;
  font-size: 0.78rem;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.preview-table th small { display: block; font-weight: 400; opacity: 0.7; font-size: 0.72rem; }
.preview-table td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--primary);
}
.preview-table tr:hover td { background: rgba(250,247,242,0.8); }

.mono-cell { font-family: var(--font-mono); font-size: 0.78rem; color: var(--neutral); }
.wrap-cell { white-space: normal; max-width: 280px; }

.action-cell { display: flex; gap: 4px; align-items: center; }

/* ── Status badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.73rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}
.badge-green   { background: rgba(39,174,96,0.12);  color: #1d8348; }
.badge-amber   { background: rgba(230,126,34,0.12); color: #d35400; }
.badge-red     { background: rgba(192,57,43,0.12);  color: var(--danger); }
.badge-blue    { background: rgba(41,128,185,0.12); color: #1a5276; }
.badge-neutral { background: rgba(138,133,128,0.12); color: var(--neutral); }

/* ── Stats cards ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow);
}
.stat-label {
  font-size: 0.73rem;
  color: var(--neutral);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 6px;
}
.stat-value {
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 400;
  color: var(--primary);
}

/* ── Explorer ── */
.explorer-layout {
  display: flex;
  gap: 20px;
  height: calc(100vh - 132px);
}

.explorer-panel {
  width: 240px;
  flex-shrink: 0;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.panel-title {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--neutral);
  margin-bottom: 10px;
}

.table-list { list-style: none; }
.table-list-item {
  display: flex;
  align-items: stretch;
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: 2px;
}

.table-btn {
  flex: 1;
  text-align: left;
  background: none;
  border: none;
  padding: 8px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: background 0.12s;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
}
.table-btn:hover { background: var(--bg); }
.table-btn.active { background: rgba(196,104,74,0.08); border-left: 2px solid var(--accent); }

.table-name { font-size: 0.84rem; font-weight: 500; color: var(--primary); }
.table-meta { font-size: 0.73rem; color: var(--neutral); }
.table-date { font-size: 0.68rem; color: var(--neutral); opacity: 0.7; }

.table-remove-btn {
  background: none;
  border: none;
  padding: 0 8px;
  cursor: pointer;
  color: var(--neutral);
  opacity: 0.4;
  transition: opacity 0.15s, color 0.15s;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.table-remove-btn:hover { opacity: 1; color: var(--danger); background: rgba(192,57,43,0.06); }

.preview-section {
  flex: 1;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  box-shadow: var(--shadow);
}

.preview-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
}
.preview-header h2 { font-size: 1rem; font-weight: 600; color: var(--primary); }
.preview-meta { font-size: 0.78rem; color: var(--neutral); margin-top: 2px; }

.preview-content { padding: 20px; }

.empty-state-large {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 60px 20px;
  color: var(--neutral);
  font-size: 0.88rem;
}

/* ── Add Data ── */
.upload-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

.upload-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
}

.upload-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.upload-card h2 { font-size: 0.95rem; font-weight: 600; color: var(--primary); }

.file-badge {
  font-size: 0.7rem;
  background: var(--bg);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
  font-weight: 500;
}

.drop-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 28px 20px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--neutral);
  margin-bottom: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.drop-area.drag-over { border-color: var(--accent); background: rgba(196,104,74,0.04); }
.drop-area p { margin: 0; }

.file-list { width: 100%; text-align: left; }
.file-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.78rem;
  padding: 3px 0;
  color: var(--primary);
}

.upload-result {
  font-size: 0.8rem;
  white-space: pre-wrap;
  color: var(--neutral);
  display: none;
}
.upload-result.visible { display: block; margin-top: 8px; }

.ingest-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 18px 0;
}
.ingest-hint { font-size: 0.83rem; color: var(--neutral); }
.ingest-result {
  width: 100%;
  font-size: 0.84rem;
  white-space: pre-wrap;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: none;
}
.ingest-result.visible { display: block; }

/* ── Modals ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 500;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}
.modal-overlay.open { display: flex; }

.modal-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 440px;
  max-width: calc(100vw - 40px);
  max-height: 90vh;
  overflow-y: auto;
  animation: modalIn 0.18s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(-8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1rem; font-weight: 600; color: var(--primary); }

.modal-close {
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 1.2rem;
  color: var(--neutral);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.modal-close:hover { background: var(--bg); color: var(--primary); }

.modal-body { padding: 20px 22px; }
.modal-footer {
  padding: 14px 22px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ── Utility ── */
.text-muted { color: var(--neutral); font-size: 0.85rem; }
.empty-state { color: var(--neutral); font-size: 0.85rem; padding: 16px 14px; }
.error-state { color: var(--danger); font-size: 0.85rem; }
.loading-state { color: var(--neutral); font-size: 0.85rem; padding: 20px; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay.open { display: block; }
  .mobile-menu-btn { display: flex; }

  .main-content { padding-top: 0; }
  .chat-container { padding-top: 52px; }

  .page-inner { padding: 20px 16px; padding-top: 64px; }

  .upload-grid { grid-template-columns: 1fr; }
  .explorer-layout { flex-direction: column; height: auto; }
  .explorer-panel { width: 100%; height: auto; max-height: 200px; }

  .stats-grid { grid-template-columns: 1fr 1fr; }
  .page-header { flex-direction: column; gap: 12px; }
  .header-actions { width: 100%; }

  .msg-bubble-user { max-width: 85%; }

  .chat-input-area { padding: 8px 12px 16px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .modal-card { width: calc(100vw - 24px); }
}
