/* ===== CSS VARIABLES ===== */
:root {
  --bg: #0f1117;
  --surface: #161b2e;
  --surface-2: #1e2340;
  --surface-3: #252b45;
  --border: #2a3050;
  --border-light: #363c5e;
  --text: #e8eaf6;
  --text-muted: #7b82a8;
  --text-dim: #4a5080;
  --accent: #2563EB;
  --accent-dim: rgba(37, 99, 235, 0.15);
  --accent-hover: #1D4ED8;
  --accent-text: #fff;
  --danger: #e05c6c;
  --danger-dim: rgba(224, 92, 108, 0.12);

  /* Pillar colors */
  --faith: #a78bfa;
  --faith-dim: rgba(167, 139, 250, 0.15);
  --family: #6ee7b7;
  --family-dim: rgba(110, 231, 183, 0.14);
  --fitness: #fb923c;
  --fitness-dim: rgba(251, 146, 60, 0.14);
  --fortune: #fbbf24;
  --fortune-dim: rgba(251, 191, 36, 0.14);
  --fun: #38bdf8;
  --fun-dim: rgba(56, 189, 248, 0.14);

  --header-height: 54px;
  --bottom-bar-height: 64px;
  --radius: 10px;
  --radius-sm: 6px;
  --radius-pill: 100px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ===== LAYOUT ===== */
.layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ===== TOP HEADER ===== */
.top-header {
  height: var(--header-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.app-logo {
  display: flex;
  align-items: baseline;
  gap: 3px;
}

.logo-mark {
  font-size: 20px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.5px;
}

.logo-label {
  font-size: 20px;
  font-weight: 300;
  color: var(--text);
  letter-spacing: 3px;
}

.header-brand .tagline {
  font-size: 10px;
  color: var(--text-dim);
  letter-spacing: 0.8px;
  text-transform: uppercase;
  border-left: 1px solid var(--border);
  padding-left: 10px;
  margin-left: 4px;
  line-height: 1;
  align-self: center;
}

/* ===== TOP NAV ===== */
.top-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 16px;
  border-radius: var(--radius-pill);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s;
  font-family: var(--font);
  white-space: nowrap;
}

.nav-item:hover {
  color: var(--text);
  background: var(--surface-2);
}

.nav-item.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

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

.nav-logout {
  text-decoration: none;
  color: var(--text-muted);
  opacity: 0.75;
}

.nav-logout:hover {
  color: #f87171;
  background: rgba(239, 68, 68, 0.08);
  opacity: 1;
}

/* ===== MAIN CONTENT ===== */
.content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  position: relative;
}

.panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== CHAT TOP BAR ===== */
.chat-topbar {
  height: 48px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px 0 24px;
  flex-shrink: 0;
  background: var(--bg);
}

.topbar-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.3px;
}

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  letter-spacing: 0.2px;
  font-family: var(--font);
}

.new-chat-btn:hover { background: var(--accent-hover); }
.new-chat-btn:active { transform: scale(0.97); }

/* ===== WELCOME STATE ===== */
.welcome-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 32px 24px;
  gap: 28px;
  max-width: 800px;
  margin: 0 auto;
  width: 100%;
}

.welcome-header { text-align: center; }

.welcome-title {
  font-size: 26px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.5px;
  margin-bottom: 6px;
}

.welcome-title span { color: var(--accent); }

.welcome-sub {
  font-size: 14px;
  color: var(--text-muted);
  max-width: 420px;
  line-height: 1.6;
}

.welcome-cards {
  display: flex;
  gap: 14px;
  width: 100%;
  max-width: 640px;
}

.welcome-card {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.welcome-card-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.welcome-card-icon {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--accent-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.welcome-card ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.welcome-card li {
  font-size: 12.5px;
  color: var(--text-muted);
  display: flex;
  align-items: flex-start;
  gap: 7px;
  line-height: 1.5;
}

.welcome-card li::before {
  content: "✓";
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 1px;
}

.suggestion-chips {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
  max-width: 640px;
}

.chip {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 12.5px;
  color: var(--text-muted);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  line-height: 1.4;
  font-family: var(--font);
}

.chip:hover {
  border-color: var(--accent);
  color: var(--text);
  background: var(--accent-dim);
}

/* ===== MESSAGES ===== */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  align-self: center;
  box-sizing: border-box;
}

.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.message {
  display: flex;
  gap: 10px;
  max-width: 82%;
}

.message-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.message-assistant {
  align-self: flex-start;
}

/* 5F avatar circle for assistant */
.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 9px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  align-self: flex-end;
  letter-spacing: -0.2px;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.65;
}

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

.message-assistant .message-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 3px;
}

/* Markdown inside AI bubbles */
.message-assistant .message-bubble p { margin-bottom: 10px; }
.message-assistant .message-bubble p:last-child { margin-bottom: 0; }

.message-assistant .message-bubble h1,
.message-assistant .message-bubble h2,
.message-assistant .message-bubble h3 {
  font-size: 15px;
  font-weight: 700;
  margin: 14px 0 6px;
  color: var(--text);
}

.message-assistant .message-bubble strong { color: var(--accent); font-weight: 600; }
.message-assistant .message-bubble em { color: var(--text-muted); font-style: italic; }

.message-assistant .message-bubble ul,
.message-assistant .message-bubble ol {
  padding-left: 20px;
  margin-bottom: 10px;
}

.message-assistant .message-bubble li { margin-bottom: 4px; }

.message-assistant .message-bubble blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  margin: 10px 0;
  color: var(--text-muted);
  font-style: italic;
}

.message-assistant .message-bubble code {
  background: var(--surface-3);
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12.5px;
  font-family: "SF Mono", "Fira Code", monospace;
  color: var(--accent);
}

.message-assistant .message-bubble pre {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  overflow-x: auto;
  margin: 10px 0;
}

.message-assistant .message-bubble pre code {
  background: none;
  padding: 0;
  color: var(--text);
}

.message-assistant .message-bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

/* ===== LOADING DOTS ===== */
.loading-indicator { align-self: flex-start; }
.loading-indicator .message-bubble { padding: 14px 18px; }

.dots { display: flex; gap: 5px; align-items: center; }

.dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: dot-pulse 1.4s ease-in-out infinite;
}

.dots span:nth-child(1) { animation-delay: 0s; }
.dots span:nth-child(2) { animation-delay: 0.2s; }
.dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-pulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1); }
}

/* ===== THINKING INDICATOR ===== */
.thinking-indicator {
  display: none;
  align-items: center;
  gap: 6px;
  margin: 6px 16px 4px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(148, 163, 184, 0.35);
  color: #e5e7eb;
  font-size: 11px;
  width: fit-content;
}

.thinking-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #60a5fa;
  opacity: 0.3;
  animation: thinking-bounce 1.2s infinite ease-in-out;
  flex-shrink: 0;
}
.thinking-dot:nth-child(2) { animation-delay: 0.15s; }
.thinking-dot:nth-child(3) { animation-delay: 0.3s; }

.thinking-text {
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 500;
  font-size: 10px;
  color: #9ca3af;
}

@keyframes thinking-bounce {
  0%, 80%, 100% { transform: scale(0.8); opacity: 0.3; }
  40% { transform: scale(1); opacity: 1; }
}

/* ===== REASONING PILL + DROPDOWN ===== */
.message-reasoning {
  margin-top: 8px;
}

.reasoning-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px 3px 7px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(15, 23, 42, 0.92);
  cursor: pointer;
  font-size: 11px;
  font-family: var(--font);
  color: #9ca3af;
  transition: background 0.12s, border-color 0.12s;
}

.reasoning-toggle:hover:not(:disabled) {
  background: rgba(30, 35, 64, 0.98);
  border-color: rgba(148, 163, 184, 0.55);
}

.reasoning-toggle:disabled {
  cursor: default;
  opacity: 0.7;
}

.reasoning-label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 9px;
  font-weight: 700;
  color: #c4c8d4;
  flex-shrink: 0;
}

.reasoning-text {
  color: #9ca3af;
  font-size: 11px;
}

.reasoning-caret {
  font-size: 10px;
  color: #9ca3af;
  margin-left: 1px;
  transition: transform 0.15s;
}

.reasoning-dropdown {
  display: none;
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.97);
  border: 1px solid rgba(42, 48, 80, 0.9);
  max-width: 520px;
}

.reasoning-dropdown.open {
  display: block;
}

.reasoning-step {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 5px 0;
  font-size: 11px;
  color: #e5e7eb;
}

.reasoning-step + .reasoning-step {
  border-top: 1px solid rgba(42, 48, 80, 0.7);
}

.reasoning-step-icon {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: rgba(30, 35, 64, 1);
  border: 1px solid rgba(55, 65, 81, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: #9ca3af;
  flex-shrink: 0;
  margin-top: 1px;
}

.reasoning-step-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.reasoning-step-title {
  font-weight: 600;
  font-size: 11px;
  color: #e5e7eb;
}

.reasoning-step-detail {
  font-size: 10.5px;
  color: #6b7280;
  line-height: 1.4;
}

/* ===== INPUT AREA ===== */
.input-area {
  padding: 12px 24px 18px;
  background: var(--bg);
  flex-shrink: 0;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  align-self: center;
  box-sizing: border-box;
}

.attachment-preview-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

.attachment-preview-bar.hidden {
  display: none;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px 3px 7px;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.12);
  border: 1px solid rgba(37, 99, 235, 0.35);
  font-size: 11px;
  color: #93c5fd;
  max-width: 220px;
}

.attachment-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-chip-remove {
  flex-shrink: 0;
  background: none;
  border: none;
  color: #93c5fd;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0;
  opacity: 0.7;
}

.attachment-chip-remove:hover { opacity: 1; }

.chat-attach-btn {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.12s, background 0.12s, border-color 0.12s;
}

.chat-attach-btn:hover {
  color: var(--text);
  background: var(--surface-raised);
  border-color: rgba(148, 163, 184, 0.5);
}

.chat-attach-btn.has-attachments {
  color: #93c5fd;
  border-color: rgba(37, 99, 235, 0.45);
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 10px 14px;
  transition: border-color 0.15s;
}

.input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.08);
}

#chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  max-height: 160px;
  overflow-y: auto;
  padding: 2px 0;
}

#chat-input::placeholder { color: var(--text-dim); }

.send-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s, transform 0.1s;
}

.send-btn:hover { opacity: 0.9; transform: scale(1.05); }
.send-btn:active { transform: scale(0.95); }
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }

/* ===== KNOWLEDGE PANEL ===== */
#panel-knowledge {
  overflow-y: auto;
}

.knowledge-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 28px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.knowledge-header-text h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
}

.panel-subtitle {
  font-size: 13px;
  color: var(--text-muted);
}

.upload-header-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 18px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, transform 0.1s;
  font-family: var(--font);
  flex-shrink: 0;
}

.upload-header-btn:hover { background: var(--accent-hover); }
.upload-header-btn:active { transform: scale(0.97); }

/* ===== AUTHORITY KEY CARD ===== */
.authority-card {
  margin: 16px 28px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  flex-shrink: 0;
}

.authority-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}

.authority-card-header:hover {
  background: var(--surface-2);
}

.authority-card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  flex-shrink: 0;
}

.authority-card-title svg {
  color: var(--accent);
  flex-shrink: 0;
}

.authority-card-meta {
  font-size: 11.5px;
  color: var(--text-dim);
  flex: 1;
}

.authority-chevron {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  transition: transform 0.2s, color 0.15s;
  flex-shrink: 0;
}

.authority-chevron.rotated svg {
  transform: rotate(180deg);
}

.authority-card-body {
  border-top: 1px solid var(--border);
  padding: 0 0 12px;
}

.authority-loading {
  padding: 16px 20px;
  font-size: 13px;
  color: var(--text-dim);
}

.authority-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.authority-table th {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.7px;
  padding: 10px 16px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.authority-table td {
  padding: 10px 16px;
  border-bottom: 1px solid rgba(42, 48, 80, 0.5);
  vertical-align: middle;
}

.authority-table tr:last-child td {
  border-bottom: none;
}

.authority-table tr:hover td {
  background: rgba(255,255,255,0.02);
}

.ath-col-priority { width: 72px; }
.ath-col-type { width: 160px; }
.ath-col-desc { }
.ath-col-actions { width: 140px; text-align: right; white-space: nowrap; }

.ath-priority-badge {
  display: inline-block;
  padding: 2px 9px;
  background: var(--accent-dim);
  color: var(--accent);
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.ath-type-name {
  font-weight: 600;
  color: var(--text);
  margin-right: 6px;
}

.ath-core-badge {
  display: inline-block;
  padding: 1px 7px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  color: var(--text-dim);
  letter-spacing: 0.3px;
}

.ath-desc-text {
  color: var(--text-muted);
  line-height: 1.5;
  font-size: 12.5px;
}

.ath-edit-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  font-family: var(--font);
}

.ath-edit-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

.ath-delete-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  margin-left: 4px;
}

.ath-delete-btn:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-dim);
}

.ath-save-btn {
  padding: 5px 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  font-family: var(--font);
}

.ath-save-btn:hover { opacity: 0.88; }

.ath-cancel-btn {
  padding: 5px 12px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  font-family: var(--font);
  margin-left: 4px;
}

.ath-cancel-btn:hover { border-color: var(--border-light); color: var(--text); }

.ath-status {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-left: 8px;
}

.ath-status.error { color: var(--danger); }

.ath-inline-input {
  background: var(--surface-2);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  padding: 4px 8px;
  font-family: var(--font);
  outline: none;
  width: 100%;
  box-sizing: border-box;
}

.ath-inline-textarea {
  background: var(--surface-2);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12.5px;
  padding: 5px 8px;
  font-family: var(--font);
  outline: none;
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
  min-height: 48px;
  line-height: 1.5;
}

.authority-note {
  padding: 8px 16px 4px;
  font-size: 11.5px;
  color: var(--text-dim);
  line-height: 1.5;
  border-top: 1px solid rgba(42, 48, 80, 0.5);
  margin-top: 4px;
}

.authority-add-section {
  padding: 10px 16px 0;
}

.authority-add-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: transparent;
  border: 1px dashed var(--border-light);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  font-family: var(--font);
}

.authority-add-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

.authority-add-form {
  margin: 10px 16px 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}

.authority-add-fields {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.ath-add-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 120px;
}

.ath-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ath-input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  padding: 5px 9px;
  font-family: var(--font);
  outline: none;
  width: 100%;
  box-sizing: border-box;
  transition: border-color 0.15s;
}

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

.ath-add-actions {
  display: flex;
  align-items: center;
}

/* Sources area */
.sources-area {
  padding: 20px 28px 28px;
}

/* Empty state */
.sources-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 32px;
  text-align: center;
  gap: 12px;
}

.sources-empty-icon {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}

.sources-empty-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.sources-empty-sub {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
  max-width: 280px;
}

.sources-empty-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-pill);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.15s;
  font-family: var(--font);
}

.sources-empty-btn:hover { background: var(--accent-hover); }

/* Card grid */
.sources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.source-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  transition: transform 0.18s, box-shadow 0.18s, border-color 0.15s;
  position: relative;
}

.source-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.28);
  border-color: var(--border-light);
}

.source-card-body { flex: 1; min-width: 0; }

.source-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 5px;
  flex-wrap: wrap;
}

.source-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-pillars { display: flex; flex-wrap: wrap; gap: 5px; }

/* Actions column: edit + delete buttons stacked/side-by-side */
.source-card-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

/* Edit button — mirrors delete-btn but uses accent color on hover */
.edit-btn {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.edit-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(99, 102, 241, 0.08);
}

/* ===== SOURCE CARD EDIT MODE ===== */
.source-card-editing {
  align-items: stretch;
  flex-direction: column;
}

.source-edit-form { width: 100%; display: flex; flex-direction: column; gap: 10px; }

.sc-field { display: flex; flex-direction: column; gap: 4px; }

.sc-row { display: flex; gap: 10px; align-items: flex-start; }

.sc-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sc-input, .sc-select, .sc-textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  padding: 6px 10px;
  width: 100%;
  box-sizing: border-box;
  font-family: inherit;
  transition: border-color 0.15s;
}

.sc-input:focus, .sc-select:focus, .sc-textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.sc-textarea { resize: vertical; min-height: 52px; }

/* Pillar checkboxes inside edit form */
.sc-pillars { display: flex; flex-wrap: wrap; gap: 6px 12px; }

.sc-pillar-check {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.sc-pillar-check input { accent-color: var(--accent); cursor: pointer; }

/* Status line inside edit form */
.sc-edit-status {
  font-size: 12px;
  min-height: 16px;
  color: var(--text-muted);
}
.sc-edit-status.error { color: var(--danger); }

/* Save / Cancel action row */
.sc-actions { display: flex; gap: 8px; }

.sc-save-btn {
  padding: 6px 18px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.sc-save-btn:hover:not(:disabled) { opacity: 0.88; }
.sc-save-btn:disabled { opacity: 0.5; cursor: default; }

.sc-cancel-btn {
  padding: 6px 14px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.sc-cancel-btn:hover { border-color: var(--border-light); color: var(--text); }

.file-type-badge {
  display: inline-block;
  padding: 1px 7px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.delete-btn {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.delete-btn:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-dim);
}

.loading-sources {
  text-align: center;
  color: var(--text-dim);
  padding: 48px 0;
  font-size: 13px;
}

/* ===== BADGES ===== */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

.badge-faith   { background: var(--faith-dim);   color: var(--faith); }
.badge-family  { background: var(--family-dim);  color: var(--family); }
.badge-fitness { background: var(--fitness-dim); color: var(--fitness); }
.badge-fortune { background: var(--fortune-dim); color: var(--fortune); }
.badge-fun     { background: var(--fun-dim);     color: var(--fun); }

/* Source type authority badge shown on knowledge cards */
.source-type-badge {
  background: rgba(99, 102, 241, 0.12);
  color: #818cf8;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 3px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

/* Priority indicator (P1/P2/P3) shown next to source type badge */
.source-priority-label {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-dim);
  letter-spacing: 0.3px;
  padding: 2px 5px;
  border: 1px solid var(--border);
  border-radius: 3px;
  margin-left: 4px;
}

/* ===== UPLOAD MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(2px);
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: 14px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5);
}

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

.modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.modal-close-btn {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s;
}

.modal-close-btn:hover { color: var(--text); border-color: var(--border-light); }

.modal-body {
  padding: 18px 22px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px 18px;
  border-top: 1px solid var(--border);
  gap: 12px;
  flex-shrink: 0;
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.modal-cancel-btn {
  padding: 8px 16px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  font-family: var(--font);
}

.modal-cancel-btn:hover { color: var(--text); border-color: var(--border-light); }

/* ===== FORM STYLES ===== */
.form-group { margin-bottom: 16px; }

.form-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.form-label {
  display: block;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 8px;
}

.form-hint {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 10px;
  margin-top: -4px;
}

.required { color: var(--accent); }

.file-input-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.file-input { display: none; }

.file-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.file-label:hover {
  border-color: var(--accent);
  background: var(--surface-3);
}

.file-hint { font-size: 11px; color: var(--text-dim); }

/* Pill pillar chips */
.pillar-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.pillar-chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  font-family: var(--font);
}

.pillar-chip-btn:hover {
  border-color: var(--pillar-color, var(--accent));
  color: var(--pillar-color, var(--accent));
}

.pillar-chip-btn.active {
  border-color: var(--pillar-color, var(--accent));
  background: color-mix(in srgb, var(--pillar-color, var(--accent)) 14%, transparent);
  color: var(--pillar-color, var(--accent));
  font-weight: 600;
}

.text-input, .notes-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text);
  font-family: var(--font);
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s;
}

.text-input::placeholder,
.notes-input::placeholder { color: var(--text-dim); }

.text-input:focus,
.notes-input:focus { border-color: var(--accent); }

.notes-input { resize: vertical; min-height: 60px; }

/* ===== UPLOAD BUTTON ===== */
.upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 20px;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  font-family: var(--font);
}

.upload-btn:hover { background: var(--accent-hover); }
.upload-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.upload-status { font-size: 13px; color: var(--text-muted); }
.upload-status.error { color: var(--danger); }
.upload-status.success { color: var(--family); }

/* ===== PROFILE PANEL ===== */
#panel-profile {
  overflow-y: auto;
}

.profile-content {
  max-width: 720px;
  margin: 0 auto;
  padding: 28px 24px 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
}

.profile-user-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 18px;
}

.profile-avatar {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 2px solid var(--accent);
  color: var(--accent);
  font-size: 20px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}

.user-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-user-info { flex: 1; min-width: 0; }

.profile-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-email {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  background: var(--accent-dim);
  color: var(--accent);
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.profile-section-title {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1.4px;
  padding-left: 2px;
  margin-bottom: 8px;
}

.profile-pillars-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

.profile-pillar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
}

.profile-pillar-num {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-dim);
  width: 16px;
  flex-shrink: 0;
}

.profile-pillar-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.profile-pillar-name {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.profile-pillar-divider {
  height: 1px;
  background: var(--border);
  margin-left: 52px;
}

.profile-logout-btn {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 12px 24px;
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(224, 92, 108, 0.35);
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s;
  align-self: flex-start;
}

.profile-logout-btn:hover {
  background: var(--danger-dim);
  border-color: var(--danger);
}

/* ===== MOBILE BOTTOM BAR ===== */
.bottom-bar { display: none; }

/* ===== LOGIN WALL ===== */
.login-wall {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
  background: radial-gradient(ellipse at 60% 0%, #0c1f4e 0%, #0f1117 55%),
              linear-gradient(180deg, #0d1b38 0%, #0f1117 100%);
  overflow-y: auto;
  padding: 40px 24px;
}

.login-hero {
  width: 100%;
  max-width: 760px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.login-logo {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-bottom: 6px;
}

.login-logo .logo-mark {
  font-size: 52px;
  font-weight: 900;
  color: var(--accent);
  letter-spacing: -2px;
}

.login-logo .logo-label {
  font-size: 36px;
  font-weight: 200;
  color: var(--text);
  letter-spacing: 6px;
  margin-bottom: 4px;
}

.login-tagline {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 28px;
}

.login-headline {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.25;
  letter-spacing: -0.5px;
  margin-bottom: 14px;
  max-width: 600px;
}

.login-headline em {
  font-style: normal;
  background: linear-gradient(90deg, #3b82f6 0%, #2563EB 50%, #60a5fa 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-oneliner {
  font-size: 15px;
  color: var(--text-muted);
  line-height: 1.65;
  max-width: 520px;
  margin-bottom: 32px;
}

.login-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 14px 36px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-pill);
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  letter-spacing: 0.2px;
  margin-bottom: 48px;
}

.login-btn:hover { background: var(--accent-hover); }
.login-btn:active { transform: scale(0.97); }

.login-cards {
  display: flex;
  gap: 14px;
  width: 100%;
}

.login-card {
  flex: 1;
  background: rgba(22, 27, 46, 0.7);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 20px;
  text-align: left;
  backdrop-filter: blur(8px);
}

.login-card-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.login-card-icon {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  background: var(--accent-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--accent);
}

.login-card ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.login-card li {
  font-size: 12.5px;
  color: var(--text-muted);
  display: flex;
  align-items: flex-start;
  gap: 8px;
  line-height: 1.45;
}

.login-card li::before {
  content: "✓";
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 1px;
}

.btn-google {
  background: #ffffff;
  color: #3c4043;
  border: 1px solid #dadce0;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,0.18);
}

.btn-google:hover {
  background: #f8f8f8;
  box-shadow: 0 2px 6px rgba(0,0,0,0.22);
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ===== MOBILE — bottom nav ≤ 600px ===== */
@media (max-width: 600px) {
  .top-header {
    padding: 0 14px;
  }

  .top-nav {
    display: none;
  }

  .header-brand .tagline {
    display: none;
  }

  .bottom-bar {
    display: flex;
    align-items: stretch;
    height: calc(var(--bottom-bar-height) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 50;
  }

  /* Push content above fixed bottom bar + fixed input area */
  .content {
    padding-bottom: calc(var(--bottom-bar-height) + env(safe-area-inset-bottom, 0px));
  }

  .bottom-bar-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.15s;
    font-family: var(--font);
    padding: 8px 4px;
  }

  .bottom-bar-item.active {
    color: var(--accent);
  }

  .bottom-bar-item span {
    font-size: 10px;
    letter-spacing: 0.2px;
  }

  /* Chat panel on mobile */
  .chat-topbar {
    padding: 0 14px;
  }

  /* Always hide the desktop expand/collapse chevron on mobile —
     mobile drawer uses mobile-history-btn instead */
  .sidebar-expand-btn {
    display: none !important;
  }

  .welcome-state {
    /* Override flex-centering so chips don't get pushed behind the fixed input */
    display: block;
    padding: 24px 16px 0;
  }

  .welcome-header {
    text-align: center;
    margin-bottom: 20px;
  }

  .welcome-cards {
    flex-direction: column;
    margin-bottom: 20px;
  }

  .suggestion-chips {
    grid-template-columns: 1fr;
    margin-bottom: 0;
  }

  .messages {
    padding: 16px;
  }

  /* Fix input above bottom nav, with safe-area clearance */
  .input-area {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(var(--bottom-bar-height) + env(safe-area-inset-bottom, 0px));
    z-index: 25;
    padding: 10px 16px 14px;
    background: var(--bg);
    border-top: 1px solid var(--border);
    max-width: 100%;
    box-sizing: border-box;
  }

  /* Textarea bigger tap target on mobile */
  #chat-input {
    font-size: 16px; /* prevents iOS zoom-on-focus */
    min-height: 28px;
  }

  .input-wrapper {
    padding: 12px 14px;
  }

  .send-btn {
    width: 40px;
    height: 40px;
    border-radius: 20px;
  }

  /* Messages need room for fixed input (~80px) + gap */
  .messages {
    padding-bottom: 100px;
  }

  /* Welcome state: enough bottom padding to clear fixed input + nav */
  .welcome-state {
    padding-bottom: 140px;
  }

  /* Knowledge on mobile */
  .knowledge-header {
    padding: 14px 16px 12px;
    flex-wrap: wrap;
  }

  .sources-area {
    padding: 14px 16px 80px;
  }

  .sources-grid {
    grid-template-columns: 1fr;
  }

  /* Profile on mobile */
  .profile-content {
    padding: 16px 16px 80px;
  }

  /* Login on mobile */
  .login-cards {
    flex-direction: column;
  }

  .login-headline { font-size: 22px; }

  /* Modal on mobile */
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .modal-box {
    border-radius: 16px 16px 0 0;
    max-height: 90vh;
  }
}

/* ===== CHAT SIDEBAR ===== */
#panel-chat {
  flex-direction: row;
}

.chat-sidebar {
  width: 240px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  overflow: hidden;
  transition: width 0.2s ease;
}

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

.sidebar-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-new-btn {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  font-family: var(--font);
  justify-content: center;
}

.sidebar-new-btn:hover { background: var(--accent-hover); }

.sidebar-toggle-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s;
}

.sidebar-toggle-btn:hover { color: var(--text); border-color: var(--border-light); }

.sidebar-expand-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-right: 8px;
  transition: color 0.15s, border-color 0.15s;
}

.sidebar-expand-btn:hover { color: var(--text); border-color: var(--border-light); }

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

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s;
  border: 1px solid transparent;
}

.sidebar-item:hover { background: var(--surface-2); }

.sidebar-item.active {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.sidebar-item-title {
  flex: 1;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-item.active .sidebar-item-title { color: var(--accent); }

.sidebar-item-date {
  font-size: 10.5px;
  color: var(--text-dim);
  flex-shrink: 0;
}

.sidebar-item-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.12s;
}

.sidebar-item:hover .sidebar-item-actions,
.sidebar-item.pinned .pin-btn {
  opacity: 1;
}

.sidebar-item.pinned .sidebar-item-actions {
  opacity: 1;
}

.sidebar-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-dim);
  transition: color 0.12s, background 0.12s;
  line-height: 1;
}

.sidebar-action-btn:hover {
  background: var(--surface-3, rgba(255,255,255,0.08));
  color: var(--text);
}

.sidebar-action-btn.delete-btn:hover {
  color: #f87171;
  background: rgba(239, 68, 68, 0.12);
}

.sidebar-item.pinned .pin-btn {
  color: var(--accent);
}

.sidebar-empty {
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  padding: 24px 8px;
  line-height: 1.6;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

/* Desktop: hide mobile-only close button */
.sidebar-mobile-close { display: none; }

/* Mobile sidebar as slide-in drawer */
@media (max-width: 600px) {
  .chat-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: calc(var(--bottom-bar-height) + env(safe-area-inset-bottom, 0px));
    z-index: 200;
    width: 80vw;
    max-width: 300px;
    background: var(--surface);
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    border-right: 1px solid var(--border-light);
    padding-top: env(safe-area-inset-top, 0px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  .chat-sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 6px 0 32px rgba(0, 0, 0, 0.6);
  }

  /* Desktop collapse button hidden on mobile; show X close instead */
  .sidebar-toggle-btn { display: none; }
  .sidebar-mobile-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
  }
  .sidebar-mobile-close:hover { color: var(--text); border-color: var(--border-light); }

  .mobile-drawer-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 199;
    -webkit-tap-highlight-color: transparent;
  }

  .mobile-drawer-backdrop.visible {
    display: block;
  }

  .mobile-history-btn {
    display: inline-flex;
  }

  #panel-chat { flex-direction: column; }

  /* Make chat-main scrollable so welcome + chips can scroll */
  .chat-main {
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
  }

  /* Suggestion chips: full width, no extra padding needed (handled above) */
  .suggestion-chips {
    width: 100%;
  }
}

@media (min-width: 601px) {
  .mobile-history-btn { display: none; }
  .mobile-drawer-backdrop { display: none !important; }
}

.mobile-history-btn {
  display: none;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}

.mobile-history-btn:hover {
  color: var(--text);
  border-color: var(--border-light);
}

/* ===== ADMIN MODAL ===== */
.admin-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  font-family: var(--font);
}

.admin-link:hover { color: var(--accent); border-color: var(--accent); }
.admin-link.admin-active { color: var(--accent); border-color: var(--accent); background: var(--accent-dim); }

.admin-secret-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}

.admin-secret-input:focus { border-color: var(--accent); }

.admin-login-btn {
  width: 100%;
  padding: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  font-family: var(--font);
  margin-top: 10px;
}

.admin-login-btn:hover { background: var(--accent-hover); }

.admin-error {
  color: var(--danger);
  font-size: 12.5px;
  margin-top: 8px;
  text-align: center;
}

/* ===== INSTRUCTIONS PANEL ===== */
#panel-instructions {
  overflow-y: auto;
}

.instructions-content {
  max-width: 760px;
  margin: 0 auto;
  padding: 28px 24px 48px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  width: 100%;
}

.instructions-section-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 10px;
}

.instructions-section-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 14px;
  margin-top: -4px;
}

.global-prompt-textarea {
  width: 100%;
  min-height: 240px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  font-family: "SF Mono", "Fira Code", monospace;
  line-height: 1.6;
  padding: 14px 16px;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
}

.global-prompt-textarea:focus { border-color: var(--accent); }

.instructions-save-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  font-family: var(--font);
  margin-top: 12px;
}

.instructions-save-btn:hover { background: var(--accent-hover); }
.instructions-save-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.guardrails-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.guardrail-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.guardrail-top {
  display: flex;
  align-items: center;
  gap: 10px;
}

.guardrail-title-input {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 10px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}

.guardrail-title-input:focus { border-color: var(--accent); }

.guardrail-toggle {
  position: relative;
  width: 36px;
  height: 20px;
  cursor: pointer;
  flex-shrink: 0;
}

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

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 20px;
  transition: background 0.15s;
}

.guardrail-toggle input:checked + .toggle-track { background: var(--accent); }

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s;
}

.guardrail-toggle input:checked ~ .toggle-thumb { transform: translateX(16px); }

.guardrail-text-input {
  width: 100%;
  min-height: 80px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13px;
  font-family: var(--font);
  line-height: 1.5;
  padding: 9px 10px;
  resize: vertical;
  outline: none;
  transition: border-color 0.15s;
}

.guardrail-text-input:focus { border-color: var(--accent); }

.guardrail-pillars {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.guardrail-pillar-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
  font-family: var(--font);
}

.guardrail-pillar-chip.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

.guardrail-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.guardrail-delete-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(224, 92, 108, 0.35);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  font-family: var(--font);
}

.guardrail-delete-btn:hover {
  background: var(--danger-dim);
  border-color: var(--danger);
}

.add-guardrail-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  background: transparent;
  color: var(--accent);
  border: 1px dashed var(--accent);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s;
  font-family: var(--font);
  align-self: flex-start;
}

.add-guardrail-btn:hover { background: var(--accent-dim); }

.instructions-status {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-left: 12px;
}

.instructions-status.success { color: var(--family); }
.instructions-status.error { color: var(--danger); }

/* ===== PROFILE ONBOARDING ===== */
.profile-onboarding {
  max-width: 720px;
  margin: 0 auto;
  padding: 28px 24px 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  width: 100%;
}

.profile-onboarding-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
}

.profile-onboarding-sub {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: -12px;
}

.profile-section-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.profile-section-card-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
}

.profile-pillar-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.profile-pillar-block-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.profile-text-input {
  width: 100%;
  padding: 9px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13.5px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}

.profile-text-input:focus { border-color: var(--accent); }

.profile-textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 13.5px;
  font-family: var(--font);
  line-height: 1.5;
  resize: vertical;
  min-height: 60px;
  outline: none;
  transition: border-color 0.15s;
}

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

.profile-save-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 11px 28px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  font-family: var(--font);
  align-self: flex-start;
}

.profile-save-btn:hover { background: var(--accent-hover); }
.profile-save-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.profile-edit-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 18px;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  font-family: var(--font);
}

.profile-edit-btn:hover { background: var(--accent-dim); }

.profile-read-pillar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.profile-read-pillar-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
}

.profile-read-row {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 6px;
  font-size: 13px;
}

.profile-read-label {
  color: var(--text-dim);
  font-weight: 600;
}

.profile-read-value {
  color: var(--text);
}

.profile-status {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-left: 12px;
}

.profile-status.success { color: var(--family); }
.profile-status.error { color: var(--danger); }

/* ===== BUSINESS PROFILE (Fortune) ===== */
.bp-card {
  border-color: color-mix(in srgb, var(--fortune) 25%, var(--border));
  margin: 0 0 16px;
}

.bp-read-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 2px;
}

.bp-read-row {
  display: grid;
  grid-template-columns: 148px 1fr;
  gap: 8px;
  font-size: 13px;
  align-items: baseline;
}

.bp-read-label {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.bp-read-value {
  color: var(--text);
  line-height: 1.5;
}

.bp-empty {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.6;
  padding: 6px 0 2px;
}

.bp-textarea {
  min-height: 56px;
}

/* ===== WORKFLOW BAR ===== */
#workflow-bar {
  margin-bottom: 6px;
}

.workflow-bar-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  transition: border-color 0.15s;
}

.workflow-bar-icon {
  color: var(--accent);
  flex-shrink: 0;
}

.workflow-select {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 12.5px;
  font-family: var(--font);
  cursor: pointer;
  min-width: 0;
  appearance: auto;
}

.workflow-select option,
.workflow-select optgroup {
  background: var(--surface);
  color: var(--text);
}

.workflow-active-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: var(--radius-pill);
  padding: 2px 10px 2px 10px;
  font-size: 12px;
  font-weight: 600;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 0;
}

.workflow-clear-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 14px;
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
  opacity: 0.7;
  transition: opacity 0.15s;
}

.workflow-clear-btn:hover { opacity: 1; }

/* ===== MY WORKFLOWS (Profile) ===== */
.wf-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.wf-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  transition: opacity 0.2s;
}

.wf-editing {
  flex-direction: column;
  align-items: stretch;
}

.wf-info {
  flex: 1;
  min-width: 0;
}

.wf-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.wf-desc {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.wf-create-form {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-bottom: 12px;
}

/* ===== MEMORIES ===== */
.mem-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.mem-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  transition: opacity 0.2s;
}

.mem-body {
  flex: 1;
  min-width: 0;
}

.mem-content {
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
  word-break: break-word;
}

.mem-date {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
}

.mem-add-form {
  flex-direction: column;
  gap: 0;
  margin-bottom: 10px;
}

.mem-add-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: border-color 0.15s, color 0.15s;
}

.mem-add-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ===== GLOBAL WORKFLOWS (Admin) ===== */
.gwf-admin-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
  background: rgba(251, 191, 36, 0.14);
  border: 1px solid rgba(251, 191, 36, 0.3);
  color: #fbbf24;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  margin-left: 2px;
}

.gwf-inactive-tag {
  display: inline-flex;
  align-items: center;
  padding: 1px 7px;
  border-radius: var(--radius-pill);
  background: var(--danger-dim);
  border: 1px solid rgba(224, 92, 108, 0.25);
  color: var(--danger);
  font-size: 10px;
  font-weight: 600;
}

.gwf-pillar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
}

.gwf-pillar-tag {
  padding: 1px 7px;
  border-radius: var(--radius-pill);
  background: var(--accent-dim);
  border: 1px solid rgba(37, 99, 235, 0.2);
  color: var(--accent);
  font-size: 10px;
  font-weight: 500;
}

.gwf-pillar-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.gwf-pillar-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12.5px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.gwf-pillar-label input[type="checkbox"] {
  accent-color: var(--accent);
  width: 13px;
  height: 13px;
  cursor: pointer;
}

.gwf-active-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.gwf-active-label input[type="checkbox"] {
  accent-color: var(--accent);
  width: 13px;
  height: 13px;
  cursor: pointer;
}

/* ===== USER CONTEXT DOCS ===== */
.ctx-upload-form {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.ctx-upload-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ctx-choose-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  font-family: var(--font);
  transition: border-color 0.15s;
  flex-shrink: 0;
}

.ctx-choose-btn:hover { border-color: var(--accent); color: var(--accent); }

.ctx-upload-btn {
  display: inline-flex;
  align-items: center;
  padding: 8px 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.15s;
  white-space: nowrap;
}

.ctx-upload-btn:hover { background: var(--accent-hover); }
.ctx-upload-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.ctx-doc-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
}

.ctx-doc-item:last-child { margin-bottom: 0; }

.ctx-doc-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.ctx-doc-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ctx-doc-meta {
  font-size: 11.5px;
  color: var(--text-muted);
}

.ctx-doc-notes {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

.ctx-doc-delete {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ctx-doc-delete:hover {
  color: var(--danger, #ef4444);
  background: rgba(239, 68, 68, 0.08);
}

/* ===== LEGAL PAGES ===== */
.legal-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

.legal-container {
  flex: 1;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: 40px 24px 64px;
}

.legal-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 36px;
  transition: color 0.15s;
}
.legal-back:hover { color: var(--text); }

.legal-title {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.5px;
  margin-bottom: 8px;
  line-height: 1.2;
}

.legal-updated {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.legal-draft-notice {
  font-size: 12px;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 40px;
  line-height: 1.5;
}

.legal-body { display: flex; flex-direction: column; gap: 40px; }

.legal-section h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.legal-section h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin: 16px 0 8px;
}

.legal-section p {
  font-size: 14px;
  line-height: 1.75;
  color: var(--text);
  margin-bottom: 12px;
}
.legal-section p:last-child { margin-bottom: 0; }

.legal-section ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0;
}

.legal-section ul li {
  font-size: 14px;
  line-height: 1.65;
  color: var(--text);
  padding-left: 18px;
  position: relative;
}
.legal-section ul li::before {
  content: "–";
  position: absolute;
  left: 0;
  color: var(--text-dim);
}

.legal-section a {
  color: var(--accent);
  text-decoration: none;
}
.legal-section a:hover { text-decoration: underline; }

/* Legal footer */
.legal-footer {
  border-top: 1px solid var(--border);
  padding: 20px 24px;
  text-align: center;
  background: var(--surface);
}

.legal-footer-links {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.legal-footer-links a {
  font-size: 12px;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}
.legal-footer-links a:hover { color: var(--text); }
.legal-footer-links span { color: var(--text-dim); font-size: 12px; }

.legal-footer-copy {
  font-size: 11px;
  color: var(--text-dim);
}

/* Login wall footer */
.login-wall-footer {
  margin-top: 32px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 12px;
}

.login-wall-footer a {
  font-size: 11px;
  color: var(--text-dim);
  text-decoration: none;
  transition: color 0.15s;
}
.login-wall-footer a:hover { color: var(--text-muted); }
.login-wall-footer-sep { font-size: 11px; color: var(--text-dim); }
.login-wall-footer-copy {
  width: 100%;
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
}

