/* ============================================================================ */
/* Variables                                                                    */
/* ============================================================================ */

:root {
  --bg-primary:    #f6f8fa;
  --bg-sidebar:    #f1f3f5;
  --bg-input:      #ffffff;
  --bg-user-msg:   #eef4ff;
  --bg-hover:      #e8efff;
  --bg-active:     #dbe4ff;
  --bg-modal:      #ffffff;
  --bg-btn:        #2d6cdf;
  --bg-btn-hover:  #1f4fb2;

  --text-primary:  #222222;
  --text-muted:    #555555;
  --text-btn:      #ffffff;

  --border:        #e0e4e8;
  --ring-color:    #2d6cdf;
  --ring-warn:     #a66b00;
  --ring-danger:   #b33434;

  --radius:        8px;
  --sidebar-width: 260px;
  --input-max:     860px;
}

/* ============================================================================ */
/* Dark theme                                                                    */
/* ============================================================================ */

[data-theme="dark"] {
  --bg-primary:    #212121;
  --bg-sidebar:    #171717;
  --bg-input:      #2f2f2f;
  --bg-user-msg:   #2f2f2f;
  --bg-hover:      #2a2a2a;
  --bg-active:     #3a3a3a;
  --bg-modal:      #2f2f2f;
  --bg-btn:        #2d6cdf;
  --bg-btn-hover:  #1f4fb2;

  --text-primary:  #ececec;
  --text-muted:    #ececec;
  --text-btn:      #ffffff;

  --border:        #383838;
  --ring-color:    #4d8af0;
  --ring-warn:     #cc8800;
  --ring-danger:   #e05555;
}

/* Explicit dark overrides — don't rely on the variable chain for key text */
[data-theme="dark"] .conv-item          { color: #ececec; }
[data-theme="dark"] .conv-item:hover    { color: #ffffff; }
[data-theme="dark"] .conv-item.active   { color: #ffffff; }
[data-theme="dark"] .conv-group-label   { color: #888888; }
[data-theme="dark"] .new-chat-btn       { color: #ececec; }
[data-theme="dark"] .sidebar-link-btn   { color: #ececec; }
[data-theme="dark"] .sidebar-nav-link   { color: #ececec; }
[data-theme="dark"] .sidebar-brand-name { color: #ececec; }
[data-theme="dark"] .user-menu-name     { color: #ececec; }
[data-theme="dark"] .user-menu-token-label { color: #888888; }
[data-theme="dark"] .user-menu-email    { color: #aaaaaa; }

/* ============================================================================ */
/* Reset                                                                         */
/* ============================================================================ */

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               Helvetica, Arial, sans-serif;
  font-size: 15px;
  background: var(--bg-primary);
  color: var(--text-primary);
}

.hidden { display: none !important; }

button { cursor: pointer; border: none; background: none; color: inherit; font: inherit; }
textarea, input { font: inherit; color: inherit; background: none; border: none; outline: none; resize: none; }
a { color: inherit; }
ul { list-style: none; }

/* ============================================================================ */
/* App shell — sidebar + main                                                   */
/* ============================================================================ */

#app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ============================================================================ */
/* Sidebar                                                                       */
/* ============================================================================ */

#sidebar {
  display: flex;
  flex-direction: column;
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

/* Sidebar brand row */

#sidebar-brand {
  display: flex;
  align-items: center;
  padding: 10px 10px 8px;
  flex-shrink: 0;
  gap: 4px;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

/* Badge: white bg + dark icon in light; dark bg + white icon in dark */
.sidebar-brand-icon-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--bg-sidebar);
  flex-shrink: 0;
}

.sidebar-brand-icon {
  color: #1a1a1a;
}

[data-theme="dark"] .sidebar-brand-icon-wrap { background: #1a1a1a; }
[data-theme="dark"] .sidebar-brand-icon       { color: #ffffff; }

.sidebar-brand-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: var(--radius);
  color: var(--text-muted);
  flex-shrink: 0;
  transition: background 0.15s;
}
.sidebar-icon-btn:hover { background: var(--bg-hover); }

/* Collapsed avatar — bottom-left of main, desktop only */

.user-avatar-collapsed {
  display: none;
  position: absolute;
  bottom: 14px;
  left: 8px;
  width: 36px;
  height: 36px;
  padding: 0;
  z-index: 5;
}
.user-avatar-collapsed:hover .user-menu-avatar { opacity: 0.85; }

/* Popup anchored to the collapsed avatar via fixed positioning */
#user-menu-popup.popup-anchored-collapsed {
  position: fixed !important;
  bottom: 60px;
  left: 10px;
  top: auto !important;
  width: 240px;
}

/* Collapsed-sidebar controls — open + new-chat, desktop only */

.sidebar-collapsed-controls {
  display: none;
  position: absolute;
  top: 12px;
  left: 12px;
  flex-direction: column;
  gap: 2px;
  z-index: 5;
}

#sidebar-header {
  padding: 12px 10px 10px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
}

.new-chat-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.93rem;
  font-weight: 500;
  transition: background 0.15s;
}
.new-chat-btn:hover { background: var(--bg-hover); }
.new-chat-btn svg { flex-shrink: 0; }

.sidebar-link-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 400;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.sidebar-link-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.sidebar-link-btn svg { flex-shrink: 0; }
.sidebar-link-btn--yt { color: #dc2626; }
.sidebar-link-btn--yt:hover { color: #b91c1c; }

#sidebar-links {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 4px;
}

.sidebar-nav-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.88rem;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  overflow: hidden;
}
.sidebar-nav-link svg { flex-shrink: 0; }
.sidebar-nav-link span { overflow: hidden; text-overflow: ellipsis; }
.sidebar-nav-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.links-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.link-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg-primary);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.link-card:focus-within {
  border-color: var(--ring-color);
  box-shadow: 0 0 0 3px rgba(45,108,223,0.08);
}

.link-card-icon {
  flex-shrink: 0;
  color: var(--text-muted);
  margin-top: 2px;
}

.link-card-fields {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
}
.link-card-fields input {
  width: 100%;
  border: none;
  background: transparent;
  padding: 0;
  font-size: 0.88rem;
  color: var(--text-primary);
  outline: none;
}
.link-card-fields .link-label-input {
  font-weight: 500;
  font-size: 0.9rem;
}
.link-card-fields .link-url-input {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.link-remove-btn {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}
.link-remove-btn:hover {
  background: #fee2e2;
  color: #dc2626;
}

.link-add-card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 10px;
  border: 1.5px dashed var(--border);
  border-radius: 10px;
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-bottom: 16px;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.link-add-card:hover {
  border-color: var(--ring-color);
  color: var(--ring-color);
  background: #eef4ff;
}
.sidebar-link-btn--li { color: #0a66c2; }
.sidebar-link-btn--li:hover { color: #004182; }
.sidebar-link-btn--build { color: #16a34a; }
.sidebar-link-btn--build:hover { color: #15803d; }

/* Conversation list */

#conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 6px;
}

#conv-list::-webkit-scrollbar { width: 4px; }
#conv-list::-webkit-scrollbar-track { background: transparent; }
#conv-list::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 4px; }

.conv-group-label {
  padding: 8px 8px 4px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-muted);
  transition: background 0.12s, color 0.12s;
  gap: 6px;
}
.conv-item:hover  { background: var(--bg-hover); color: var(--text-primary); }
.conv-item.active {
  background: var(--bg-active);
  color: var(--text-primary);
  border-left: 3px solid var(--ring-color);
  padding-left: 7px;
}

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

.conv-delete-btn {
  flex-shrink: 0;
  opacity: 0;
  padding: 2px 4px;
  border-radius: 4px;
  color: var(--text-muted);
  transition: opacity 0.1s, color 0.1s;
}
.conv-item:hover .conv-delete-btn { opacity: 1; }
.conv-delete-btn:hover { color: var(--ring-danger); }

/* Sidebar footer */

#sidebar-footer {
  flex-shrink: 0;
  padding: 8px 10px;
  border-top: 1px solid var(--border);
}

/* User menu — trigger + popup */

#user-menu-container {
  position: relative;
}

.user-menu-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 8px;
  border-radius: var(--radius);
  text-align: left;
  transition: background 0.12s;
}
.user-menu-trigger:hover { background: var(--bg-hover); }

/* Token ring wraps the avatar circle */
.user-avatar-wrap {
  position: relative;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
}

.user-avatar-ring-svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* Keep class names — JS references these to animate the ring */
.token-ring-bg  { fill: none; stroke: var(--border); stroke-width: 2.5; }
.token-ring-arc {
  fill: none;
  stroke: var(--ring-color);
  stroke-width: 2.5;
  stroke-linecap: round;
  transition: stroke-dasharray 0.4s ease, stroke 0.4s ease;
}

/* Avatar initial centered inside the ring */
.user-menu-avatar {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--bg-btn);
  color: var(--text-btn);
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Two-line label area: name above, token usage below */
.user-menu-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  gap: 1px;
}

.user-menu-name {
  font-size: 0.88rem;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu-token-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu-chevron {
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform 0.15s;
}
.user-menu-trigger.open .user-menu-chevron { transform: rotate(180deg); }

.user-menu-popup {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0,0,0,0.12);
  z-index: 200;
  overflow: hidden;
}

.user-menu-email-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 14px 9px;
}

.user-menu-popup-avatar {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--bg-btn);
  color: var(--text-btn);
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-menu-email {
  font-size: 0.78rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu-divider {
  height: 1px;
  background: var(--border);
  margin: 3px 0;
}

.user-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 14px;
  font-size: 0.88rem;
  color: var(--text-primary);
  text-decoration: none;
  transition: background 0.12s;
}
.user-menu-item:hover { background: var(--bg-hover); }

.user-menu-item--danger { color: var(--ring-danger); }
.user-menu-item--danger:hover { background: rgba(176, 52, 52, 0.1); }

/* Help submenu — inline expansion */
.user-menu-item--expandable {
  justify-content: flex-start;
}

.user-menu-expand-chevron {
  margin-left: auto;
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform 0.15s;
}
.user-menu-item--expandable.open .user-menu-expand-chevron {
  transform: rotate(90deg);
}

.user-menu-submenu {
  padding: 2px 0 4px;
}

.user-menu-subitem {
  display: block;
  padding: 7px 14px 7px 38px;
  font-size: 0.84rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: background 0.12s, color 0.12s;
}
.user-menu-subitem:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Sign-out confirmation modal */

.modal-content--centered { text-align: center; }

.signout-modal-desc { margin-top: 6px; }

.modal-actions--stack {
  flex-direction: column;
  gap: 8px;
}

.btn-signout-confirm {
  width: 100%;
  padding: 12px;
  background: #1a1a1a;
  color: #ffffff;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 500;
  transition: background 0.12s;
}
.btn-signout-confirm:hover { background: #333333; }

.modal-actions--stack .btn-secondary {
  width: 100%;
  padding: 12px;
  text-align: center;
}

/* Settings dialog */

.settings-dialog {
  display: flex;
  width: 860px;
  height: 520px;
  background: var(--bg-modal);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
}

.settings-nav {
  width: 210px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.settings-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  color: var(--text-muted);
  transition: background 0.12s, color 0.12s;
  margin-bottom: 10px;
  flex-shrink: 0;
}
.settings-close-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.settings-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  color: var(--text-primary);
  text-align: left;
  transition: background 0.12s;
}
.settings-nav-item:hover   { background: var(--bg-hover); }
.settings-nav-item.active  { background: var(--bg-active); font-weight: 500; }
.settings-nav-item svg     { flex-shrink: 0; color: var(--text-muted); }
.settings-nav-item.active svg { color: var(--ring-color); }

.settings-body {
  flex: 1;
  padding: 28px 32px;
  overflow-y: auto;
}

.settings-panel-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 22px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 15px 0;
  border-bottom: 1px solid var(--border);
}
.settings-row:last-child { border-bottom: none; }
.settings-row--col {
  flex-direction: column;
  align-items: flex-start;
  gap: 14px;
}

.settings-row-label {
  font-size: 0.9rem;
  color: var(--text-primary);
}
.settings-row-value {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Theme picker */

.theme-picker {
  display: flex;
  gap: 10px;
  width: 100%;
}

.theme-option {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 8px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.85rem;
  color: var(--text-muted);
  transition: border-color 0.15s, color 0.15s;
}
.theme-option:hover {
  border-color: var(--ring-color);
  color: var(--text-primary);
}
.theme-option.active {
  border-color: var(--ring-color);
  color: var(--ring-color);
  font-weight: 600;
}

.theme-swatch {
  width: 48px;
  height: 32px;
  border-radius: 5px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.theme-swatch--light  { background: #f6f8fa; }
.theme-swatch--dark   { background: #1c1c1e; }
.theme-swatch--system { background: linear-gradient(to right, #f6f8fa 50%, #1c1c1e 50%); }

/* ============================================================================ */
/* Main chat area                                                                */
/* ============================================================================ */

#chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ---- Empty state ---- */

#empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  gap: 16px;
}

.empty-logo-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

.empty-logo {
  font-size: 1.73rem;
  font-weight: 700;
  color: var(--text-primary);
}

.shuffle-btn {
  background: none;
  border: none;
  padding: 4px;
  color: var(--text-muted);
  opacity: 0.4;
  cursor: pointer;
  border-radius: 4px;
  line-height: 0;
  transition: opacity 0.15s;
}
.shuffle-btn:hover {
  opacity: 1;
}

.empty-tagline {
  font-size: 1rem;
  color: var(--text-muted);
  text-align: center;
  max-width: 420px;
}

.starter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  max-width: 540px;
  width: 100%;
  margin-top: 8px;
}

.starter-btn {
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: left;
  line-height: 1.4;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.starter-btn:hover {
  background: var(--bg-active);
  color: var(--text-primary);
  border-color: #a8c0f0;
}

/* ---- Chat log ---- */

#chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 24px 0 12px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

#chat-log::-webkit-scrollbar { width: 4px; }
#chat-log::-webkit-scrollbar-track { background: transparent; }
#chat-log::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); border-radius: 4px; }

/* ---- Message rows ---- */

.msg-row {
  display: flex;
  padding: 6px 32px;
  gap: 12px;
  width: 100%;
}

.msg-row--user {
  justify-content: flex-end;
}

.msg-row--assistant {
  justify-content: flex-start;
}

.msg-bubble {
  max-width: 100%;
  line-height: 1.65;
  font-size: 1rem;
}

.msg-row--user .msg-bubble {
  background: var(--bg-user-msg);
  border-radius: 18px 18px 4px 18px;
  padding: 10px 16px;
  color: var(--text-primary);
}

.msg-row--assistant .msg-bubble {
  color: var(--text-primary);
  padding: 4px 0;
}

/* Thinking dots */
.thinking-dots span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  margin: 0 2px;
  animation: dot-bounce 1.2s infinite ease-in-out;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dot-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40%            { transform: translateY(-6px); opacity: 1; }
}

.cancel-query-btn {
  display: block;
  margin-top: 10px;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 0;
  background: none;
  border: none;
  cursor: pointer;
}
.cancel-query-btn:hover { color: var(--ring-danger); }

/* Markdown rendering inside assistant bubbles */
.msg-markdown h1, .msg-markdown h2, .msg-markdown h3 {
  font-weight: 600;
  margin: 12px 0 4px;
  line-height: 1.3;
}
.msg-markdown h1 { font-size: 1.15rem; }
.msg-markdown h2 { font-size: 1.05rem; }
.msg-markdown h3 { font-size: 0.95rem; }
.msg-markdown p  { margin: 6px 0; }
.msg-markdown ul, .msg-markdown ol { padding-left: 20px; margin: 6px 0; }
.msg-markdown li { margin: 3px 0; }
.msg-markdown a  { color: var(--ring-color); text-decoration: underline; }
.msg-markdown a:hover { opacity: 0.8; }
.mc-ask-link { cursor: pointer; }
.mc-ask-link::before { content: "▶ "; font-size: 0.7em; opacity: 0.6; }

.mc-drill-link {
  display: inline-flex;
  align-items: center;
  margin-left: 8px;
  vertical-align: middle;
  color: var(--text-muted);
  opacity: 0.35;
  text-decoration: none;
  transition: opacity 0.12s, color 0.12s;
}
.mc-drill-link:hover { opacity: 1; color: var(--accent); }

.msg-markdown li {
  padding: 3px 0;
}
.msg-markdown li .source-summarize {
  margin-left: 6px;
}
.msg-markdown code {
  background: rgba(0,0,0,0.06);
  border-radius: 3px;
  padding: 1px 5px;
  font-family: monospace;
  font-size: 0.9em;
}
.msg-markdown pre {
  background: rgba(0,0,0,0.04);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 14px;
  overflow-x: auto;
  margin: 8px 0;
}
.msg-markdown pre code { background: none; padding: 0; }
.msg-markdown strong { font-weight: 600; }
.msg-markdown blockquote {
  border-left: 3px solid var(--border);
  padding-left: 12px;
  color: var(--text-muted);
  margin: 6px 0;
}

/* Sources section */
.sources-section {
  margin-top: 10px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.sources-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 4px 0;
  color: var(--text-muted);
  font-size: 0.9rem;
  transition: color 0.12s;
}
.sources-toggle:hover { color: var(--text-primary); }
.sources-toggle svg { transition: transform 0.2s; }
.sources-toggle.open svg { transform: rotate(90deg); }

.sources-list {
  display: none;
  flex-direction: column;
  gap: 4px;
  padding: 6px 0 2px 18px;
}
.sources-list.visible { display: flex; }

.source-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.83rem;
  transition: color 0.12s;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.source-link:hover { color: var(--text-primary); text-decoration: underline; }
.source-link--no-url { cursor: default; }
.source-link--no-url:hover { color: var(--text-muted); text-decoration: none; }

.source-row {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
.source-row .source-link {
  flex: 0 1 auto;
  min-width: 0;
}
.source-summarize {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  color: var(--text-muted);
  text-decoration: none;
  opacity: 0.45;
  transition: opacity 0.12s, color 0.12s;
}
.source-summarize:hover {
  opacity: 1;
  color: var(--accent);
  text-decoration: none;
}

/* ---- Input bar ---- */

#input-bar {
  flex-shrink: 0;
  padding: 12px 24px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

#input-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: var(--input-max);
  background: var(--bg-input);
  border: 1px solid #e0e0e0;
  border-radius: 28px;
  padding: 12px 12px 12px 20px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  transition: border-color 0.15s, box-shadow 0.15s;
}
#input-wrapper:focus-within {
  border-color: #c0c0c0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

#chat-input {
  flex: 1;
  max-height: 200px;
  overflow-y: auto;
  line-height: 1.5;
  font-size: 1rem;
  color: var(--text-primary);
}
#chat-input::placeholder { color: var(--text-muted); }

#btn-send {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-btn);
  color: var(--text-btn);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, opacity 0.15s;
}
#btn-send:hover    { background: var(--bg-btn-hover); }
#btn-send:disabled { opacity: 0.3; cursor: not-allowed; }

.input-error {
  font-size: 0.9rem;
  color: var(--ring-danger);
  max-width: var(--input-max);
  width: 100%;
  padding: 0 4px;
}

/* ============================================================================ */
/* Modals                                                                        */
/* ============================================================================ */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

/* Confirm and alert modals must sit above the settings dialog (z-index 100) */
#confirm-modal,
#alert-modal {
  z-index: 200;
}

.modal-content {
  background: var(--bg-modal);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 32px;
  width: 100%;
}

.modal-content--sm {
  max-width: 400px;
}

.modal-content--md {
  max-width: 520px;
}

.modal-content--lg {
  max-width: 740px;
}

/* -------------------------------------------------------------------------- */
/* Sample corpus card grid                                                      */
/* -------------------------------------------------------------------------- */

.sample-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
  padding: 2px 2px 4px;
  margin-top: 4px;
}

.sample-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  padding: 10px 12px;
  background: var(--bg-primary);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  width: 100%;
  min-height: 76px;
}

.sample-card:hover {
  border-color: var(--ring-primary, #6366f1);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring-primary, #6366f1) 12%, transparent);
}

.sample-card--selected {
  border-color: var(--ring-primary, #6366f1);
  background: color-mix(in srgb, var(--ring-primary, #6366f1) 8%, var(--bg-primary));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ring-primary, #6366f1) 18%, transparent);
}

.sample-card--none {
  border-style: dashed;
  border-color: var(--border);
  color: var(--text-muted);
}

.sample-card--none.sample-card--selected {
  border-style: solid;
}

.sample-card-category {
  font-size: 0.7em;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  line-height: 1.6;
}

.sample-card-name {
  font-size: 0.86em;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.sample-card-desc {
  font-size: 0.76em;
  color: var(--text-muted);
  line-height: 1.4;
}

.field-required { color: #c0392b; font-weight: 600; margin-left: 2px; }
.field-optional { color: var(--text-muted); font-size: 0.82rem; font-weight: 400; }
.field-error    { font-size: 0.82rem; color: #c0392b; margin-top: 2px; }
.field-note     { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }

/* Style file inputs to match other field-row inputs */
.field-row input[type="file"] {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 0.9rem;
  cursor: pointer;
}

.modal-message {
  color: var(--text-muted);
  margin: 8px 0 20px;
  font-size: 0.93rem;
  line-height: 1.5;
  word-break: normal;
  overflow-wrap: break-word;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

.modal-actions button {
  padding: 9px 20px;
  border-radius: var(--radius);
  font-size: 0.93rem;
  font-weight: 500;
  background: var(--bg-btn);
  color: var(--text-btn);
  transition: background 0.15s;
}
.modal-actions button:hover { background: var(--bg-btn-hover); }
.modal-actions .btn-secondary {
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.modal-actions .btn-secondary:hover { background: var(--bg-active); }

/* Sign-in modal — static, no animations */

#sign-in-modal {
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.modal-content--auth {
  display: flex;
  border-radius: 18px;
  overflow: hidden;
  width: 980px;
  max-width: 96vw;
  min-height: 540px;
  background: var(--bg-modal);
  box-shadow: 0 32px 96px rgba(0,0,0,0.45), 0 4px 24px rgba(0,0,0,0.2);
}

.auth-form-panel {
  flex: 1;
  padding: 60px 52px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 20px;
  background: #f8f9fc;
}

.auth-form-panel h2 {
  font-size: 1.55rem;
  font-weight: 700;
  margin: 0 0 2px;
  color: #0f172a;
  letter-spacing: -0.3px;
}

.auth-form-desc {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin: 0 0 12px;
}

.auth-form-actions button {
  width: 100%;
  padding: 14px 20px;
  border-radius: 9px;
  background: linear-gradient(135deg, #2563eb 0%, #4f38c9 100%);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.025em;
  box-shadow: 0 4px 18px rgba(37, 99, 235, 0.42);
  transition: transform 0.15s ease, box-shadow 0.15s ease, filter 0.15s ease;
}
.auth-form-actions button:hover {
  filter: brightness(1.08);
  box-shadow: 0 8px 28px rgba(37, 99, 235, 0.58);
  transform: translateY(-2px);
}

.auth-preview-panel {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, #1c3f85 0%, #2150a0 50%, #2d6cdf 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px 48px;
  color: white;
}

/* Floating orbs — pure CSS, no images */
.auth-preview-panel::before {
  content: "";
  position: absolute;
  width: 380px;
  height: 380px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.5) 0%, transparent 68%);
  top: -110px;
  right: -90px;
  pointer-events: none;
}

.auth-preview-panel::after {
  content: "";
  position: absolute;
  width: 280px;
  height: 280px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(59, 130, 246, 0.4) 0%, transparent 68%);
  bottom: -70px;
  left: -50px;
  pointer-events: none;
}

.auth-preview-inner {
  position: relative;
  z-index: 1;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.auth-logo-mark {
  margin-bottom: 4px;
  filter: drop-shadow(0 2px 12px rgba(99,102,241,0.6));
}

.auth-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid rgba(255, 255, 255, 0.4);
  flex-shrink: 0;
}

.auth-preview-logo {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: #fff;
  line-height: 1.15;
}

.auth-preview-tagline {
  font-size: 0.9rem;
  opacity: 0.8;
  line-height: 1.6;
  margin: 0 0 4px;
}

.auth-preview-features {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-preview-features li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.85rem;
  opacity: 0.88;
  line-height: 1.4;
}

.auth-preview-features svg {
  flex-shrink: 0;
  margin-top: 1px;
  color: #93c5fd;
}

/* Numbered onboarding steps on the sign-in panel (replaces the check icons) */
.auth-preview-features .auth-step-num {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-preview-clouds {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  padding-top: 8px;
}

.cloud-provider-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  opacity: 0.8;
}

.cloud-provider-icon svg {
  width: 56px;
  height: 56px;
}

.cloud-provider-icon span {
  font-size: 0.67rem;
  font-weight: 700;
  color: rgba(255,255,255,0.85);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* ============================================================================ */
/* Mobile responsive                                                             */
/* ============================================================================ */

#mobile-topbar {
  display: none;
}

#sidebar-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  color: var(--text-muted);
  flex-shrink: 0;
}
#sidebar-toggle:hover { background: var(--bg-hover); }

@media (min-width: 641px) {
  html, body    { font-size: 16.5px; }
  .msg-row      { padding: 6px 100px; }
  /* align starter grid with the input bar's max-width */
  .starter-grid { max-width: var(--input-max); }

  /* Sidebar slide-collapse on desktop */
  #sidebar {
    transition: width 0.22s ease, min-width 0.22s ease;
  }
  #app-shell.sidebar-collapsed #sidebar {
    width: 0;
    min-width: 0;
  }

  /* chat-main needs relative positioning for the open button */
  #chat-main { position: relative; }

  /* Show open+new-chat controls only when collapsed */
  #app-shell.sidebar-collapsed .sidebar-collapsed-controls {
    display: flex;
  }

  /* Show collapsed avatar only when collapsed */
  #app-shell.sidebar-collapsed .user-avatar-collapsed {
    display: flex;
  }
}

@media (max-width: 640px) {

  /* Hide sidebar by default on mobile — shown when toggled */
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }

  #sidebar.open {
    transform: translateX(0);
  }

  /* Hamburger toggle visible on mobile */
  #sidebar-toggle {
    display: flex;
  }

  /* Mobile top bar above chat */
  #chat-main {
    position: relative;
  }

  #mobile-topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }

  #mobile-topbar-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
  }

  /* Allow empty state and chat log to scroll on mobile */
  #chat-main {
    overflow-y: auto;
  }

  #empty-state {
    overflow-y: auto;
    justify-content: flex-start;
    padding-top: 32px;
  }

  /* Tighter chat padding on mobile */
  .msg-row {
    padding: 4px 12px;
  }

  #input-bar {
    padding: 8px 12px 14px;
  }

  /* Override hardcoded font sizes in sidebar */
  .conv-item {
    font-size: 1.33rem;
    padding: 12px 14px;
  }

  .conv-group-label {
    font-size: 1.07rem;
  }

  .new-chat-btn {
    font-size: 1.33rem;
    padding: 14px 16px;
  }

  .user-menu-trigger {
    font-size: 1.05rem;
  }

  .user-menu-token-label {
    font-size: 0.85rem;
  }

  /* 1.5x font sizes for readability on small screens */
  html, body {
    font-size: 15px;
  }

  .msg-bubble {
    font-size: 1.47rem;
  }

  #chat-input {
    font-size: 1.47rem;
  }

  .empty-logo {
    font-size: 2.6rem;
  }

  .empty-tagline {
    font-size: 1.47rem;
  }

  .starter-btn {
    font-size: 1.33rem;
    padding: 14px 16px;
  }

  /* Stack login modal vertically — hide gradient panel */
  .modal-content--auth {
    flex-direction: column;
    width: 95vw;
  }

  .auth-preview-panel {
    display: none;
  }

  .auth-form-panel {
    padding: 40px 28px;
  }

  /* Starter grid single column on mobile */
  .starter-grid {
    grid-template-columns: 1fr;
    max-width: 100%;
  }

  /* Dim overlay when sidebar is open */
  #sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 49;
  }

  #sidebar-overlay.visible {
    display: block;
  }
}

/* ============================================================================ */
/* Corpus picker (input bar)                                                     */
/* ============================================================================ */

#corpus-picker-row {
  display: flex;
  align-items: center;
  padding: 6px 4px 0;
}

.corpus-picker-select {
  appearance: none;
  -webkit-appearance: none;
  background: transparent
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E")
    no-repeat right 6px center;
  border: none;
  outline: none;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-primary);
  padding: 3px 24px 3px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.12s;
}
.corpus-picker-select:hover { background-color: var(--bg-hover); }
.corpus-picker-select:focus { background-color: var(--bg-hover); }

.model-selector-select {
  appearance: none;
  -webkit-appearance: none;
  flex-shrink: 0;
  background: var(--bg-hover)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E")
    no-repeat right 8px center;
  border: none;
  outline: none;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  padding: 5px 24px 5px 10px;
  border-radius: 16px;
  cursor: pointer;
  transition: background-color 0.12s, color 0.12s;
}
.model-selector-select:hover { background-color: var(--border-color); color: var(--text-primary); }
.model-selector-select:focus { outline: none; }

/* ============================================================================ */
/* Corpora management panel                                                      */
/* ============================================================================ */

#corpora-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary);
}

.corpora-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-input);
  min-height: 52px;
}

.corpora-toolbar-left {
  display: flex;
  align-items: stretch;
  height: 100%;
}

.toolbar-tabs {
  display: flex;
  align-items: stretch;
  gap: 0;
}

.toolbar-tab {
  padding: 0 18px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  height: 52px;
  transition: color 0.12s, border-color 0.12s;
}
.toolbar-tab:hover  { color: var(--text-primary); }
.toolbar-tab.active {
  color: var(--bg-btn);
  border-bottom-color: var(--bg-btn);
}
.toolbar-tab:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

.corpora-toolbar-actions {
  display: flex;
  gap: 8px;
}

.corpora-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ---- Corpus card list ---- */

.corpora-list-col {
  width: 240px;
  min-width: 200px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 10px 8px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
}

.corpora-list--locked {
  opacity: 0.45;
  pointer-events: none;
  user-select: none;
}

.corpus-card {
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  margin-bottom: 4px;
  border: 1px solid transparent;
  transition: background 0.12s, border-color 0.12s;
}
.corpus-card:hover  { background: var(--bg-hover); }
.corpus-card.active {
  background: var(--bg-active);
  border-color: #a8c0f0;
}

.corpus-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.corpus-card-name {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.corpus-card-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 3px;
}

/* ---- Status pills ---- */

.corpus-status-pill {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
  white-space: nowrap;
  flex-shrink: 0;
}
.status-ready           { background: #dcfce7; color: #166534; }
.status-building        { background: #fef9c3; color: #713f12; }
.status-pending         { background: #f1f3f5; color: #555; }
.status-pending-changes { background: #fff3e0; color: #b45309; }
.status-error           { background: #fee2e2; color: #991b1b; }

/* ---- Corpus detail pane ---- */

.corpora-detail-col {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  display: flex;
  flex-direction: column;
}

#corpora-detail {
  display: flex;
  flex-direction: column;
  flex: 1;
}
/* During build: dim Sources/CORPUS.md tabs only — Log tab + Cancel Build stay live */
#corpora-detail.detail-building .corpus-inner-tab[data-tab="sources"],
#corpora-detail.detail-building .corpus-inner-tab[data-tab="corpus-md"] {
  opacity: 0.4;
  pointer-events: none;
  user-select: none;
}
/* Disabled action buttons in header get the standard muted look */
#corpora-detail.detail-building .corpus-detail-header .btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.corpus-detail-header {
  padding: 20px 28px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-input);
}

.corpus-detail-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.corpus-detail-title-row h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

.corpus-detail-desc {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin: 0 0 12px;
  min-height: 1.2em;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Pencil button — only visible on hover of the desc row */
.corpus-desc-edit-btn {
  opacity: 0;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  padding: 2px 4px;
  border-radius: 4px;
  color: var(--text-muted);
  transition: opacity 0.15s, color 0.15s, background 0.15s;
}
.corpus-detail-desc:hover .corpus-desc-edit-btn { opacity: 1; }
.corpus-desc-edit-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

/* Inline edit state */
.corpus-detail-desc.desc-editing {
  align-items: center;
  gap: 6px;
}
.corpus-desc-input {
  flex: 1;
  min-width: 0;
  font-size: 0.88rem;
  color: var(--text-primary);
  border: 1.5px solid var(--ring-color);
  border-radius: 5px;
  padding: 3px 8px;
  background: var(--bg-input);
  outline: none;
}
.desc-action-btn {
  flex-shrink: 0;
  padding: 3px 10px;
  font-size: 0.82rem;
}

.corpus-detail-actions {
  display: flex;
  gap: 8px;
}

/* ---- Corpus contents list ---- */

.corpus-contents {
  flex: 1;
  overflow-y: auto;
  padding: 14px 20px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Toolbar — filter + bulk action */
.contents-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 2px;
}
.contents-filter {
  flex: 1;
  padding: 7px 12px;
  font-size: 0.88rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s;
}
.contents-filter:focus { border-color: var(--ring-color); }
.bulk-delete-btn {
  flex-shrink: 0;
  padding: 7px 14px;
  font-size: 0.85rem;
  font-weight: 500;
  border-radius: var(--radius);
  background: #fef2f2;
  color: #b91c1c;
  border: 1.5px solid #fca5a5;
  transition: background 0.15s;
}
.bulk-delete-btn:hover { background: #fee2e2; }

/* Group sections */
.source-group {
  display: flex;
  flex-direction: column;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.source-group-header {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  background: var(--bg-input);
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}
.source-group-header:hover { background: var(--bg-hover); }
.source-group-chevron { flex-shrink: 0; color: var(--text-muted); }
.source-group-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
}
.source-group-count {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-left: 2px;
  flex: 1;
}
.source-group-select-all {
  display: flex;
  align-items: center;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}
.source-group-select-all:hover { background: var(--bg-hover); }
.source-group-body {
  display: flex;
  flex-direction: column;
}

/* Checkbox on each row */
.content-row-cb-label {
  display: flex;
  align-items: center;
  cursor: pointer;
  flex-shrink: 0;
  padding: 2px;
}

.contents-empty {
  font-size: 0.9rem;
  color: var(--text-muted);
  padding: 16px 0;
}

.content-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
  padding: 6px 12px;
  gap: 8px;
  transition: background 0.12s;
}
.content-row:hover { background: var(--bg-hover); }

.content-row-main {
  display: flex;
  align-items: center;
  gap: 10px;
  overflow: hidden;
  flex: 1;
}

.content-type-badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
  flex-shrink: 0;
}
.type-github     { background: #e8f0fe; color: #1a56db; }
.type-youtube    { background: #fde8e8; color: #c81e1e; }
.type-qa         { background: #ecfdf5; color: #065f46; }
.type-url        { background: #e0f2fe; color: #0369a1; }
.type-document   { background: #f3e8ff; color: #7e3af2; }
.type-fileupload { background: #fff7ed; color: #c2410c; }

.content-name {
  font-size: 0.9rem;
  color: var(--text-primary);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

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

.content-edit-btn {
  font-size: 0.82rem;
  padding: 4px 12px;
}

/* ---- Source modal ---- */

.modal-content--source {
  width: 700px;
  max-width: 95vw;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Step 1 — source type card picker */

.source-type-picker {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 2px;
}

.source-type-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg-primary);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.source-type-card:hover {
  border-color: var(--ring-color);
  background: #eef4ff;
  box-shadow: 0 2px 8px rgba(45, 108, 223, 0.12);
}

.source-type-card-icon {
  font-size: 1.8rem;
  line-height: 1;
}

.source-type-card-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary);
}

.source-type-card-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.field-label-with-help {
  display: flex;
  align-items: center;
  gap: 6px;
}

.field-help-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px solid var(--text-muted);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
  transition: border-color 0.12s, color 0.12s;
}
.field-help-btn:hover {
  border-color: var(--bg-btn);
  color: var(--bg-btn);
}

.field-help-text {
  background: #f0f4ff;
  border: 1px solid #c7d7f7;
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 0.84rem;
  line-height: 1.55;
  color: #1e3a6e;
}
.field-help-text ol {
  margin: 8px 0 8px 18px;
  padding: 0;
}
.field-help-text li { margin-bottom: 4px; }
.field-help-text code {
  background: #dde8fa;
  padding: 1px 5px;
  border-radius: 4px;
  font-family: monospace;
  font-size: 0.82rem;
}
.field-help-link {
  display: inline-block;
  margin-top: 8px;
  color: var(--bg-btn);
  text-decoration: none;
  font-size: 0.83rem;
  font-weight: 500;
}
.field-help-link:hover { text-decoration: underline; }

.field-url-preview {
  font-size: 0.78rem;
  font-family: monospace;
  color: var(--text-muted);
  opacity: 0.7;
  margin-top: -4px;
  margin-bottom: 2px;
  min-height: 1em;
  display: flex;
  flex-direction: column;
  gap: 2px;
  word-break: break-all;
}

.source-modal-fields {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---- Shared field rows ---- */

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

/* Space consecutive field rows when there is no flex-gap wrapper */
.field-row + .field-row { margin-top: 14px; }

.field-row--inline {
  flex-direction: row;
  align-items: flex-start;
  gap: 8px;
}
.field-row--inline input[type="checkbox"] {
  margin-top: 2px;
  flex-shrink: 0;
  width: auto;
  border: none;
  background: none;
}
.field-row--inline label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  color: var(--text-primary);
  font-size: 0.88rem;
  font-weight: 400;
  cursor: pointer;
}

.field-row label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
}

.field-row input,
.field-row textarea {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: 0.9rem;
  color: var(--text-primary);
  transition: border-color 0.15s;
}
.field-row input:focus,
.field-row textarea:focus {
  border-color: #a8c0f0;
  outline: none;
}
.field-row textarea {
  resize: vertical;
  min-height: 100px;
  line-height: 1.5;
}

.cfg-badge {
  font-size: 0.75rem;
  font-weight: 600;
  color: #166534;
  background: #dcfce7;
  border-radius: 6px;
  padding: 1px 6px;
  margin-left: 4px;
}

/* ---- Buttons ---- */

.btn-primary {
  padding: 8px 18px;
  border-radius: var(--radius);
  background: var(--bg-btn);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--bg-btn-hover); }
.btn-primary:disabled, .btn-secondary:disabled, .btn-ghost:disabled, .btn-danger:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-secondary {
  padding: 8px 18px;
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border);
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s;
}
.btn-secondary:hover { background: var(--bg-active); }

.btn-danger {
  padding: 8px 18px;
  border-radius: var(--radius);
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fca5a5;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s;
}
.btn-danger:hover { background: #fee2e2; }

.btn-icon-danger {
  color: var(--text-muted);
  padding: 3px 7px;
  border-radius: 4px;
  font-size: 0.85rem;
  flex-shrink: 0;
  transition: color 0.12s;
}
.btn-icon-danger:hover { color: var(--ring-danger); }

.sidebar-link-btn.active {
  background: var(--bg-active);
  color: var(--text-primary);
}

/* ---- Build log panel ---- */

.build-log-panel {
  margin: 16px 28px 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  flex-shrink: 0;
}

.build-log-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-input);
  border-bottom: 1px solid var(--border);
}

.build-log-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.build-log-badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
}
.build-log-badge.running { background: #fef9c3; color: #713f12; }
.build-log-badge.done    { background: #dcfce7; color: #166534; }
.build-log-badge.failed  { background: #fef2f2; color: #b91c1c; }

.build-log-controls {
  margin-left: auto;
  display: flex;
  gap: 4px;
}
.build-log-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--text-secondary);
  line-height: 1.4;
}
.build-log-btn:hover { background: var(--hover-bg); color: var(--text-primary); }
.build-log-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}
.build-log-body {
  background: #1a1a2e;
  color: #c8d3f0;
  font-family: "Consolas", "Fira Mono", "Menlo", monospace;
  font-size: 0.78rem;
  line-height: 1.5;
  padding: 12px 16px;
  min-height: 180px;
  max-height: 320px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.log-line {
  min-height: 1.5em;
}

/* ============================================================================ */
/* Login page branding editor                                                    */
/* ============================================================================ */

.branding-view-container {
  flex: 1;
  overflow-y: auto;
  padding: 32px 40px;
  width: 75%;
  margin: 0 auto;
}

.corpus-appearance-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 16px 0 8px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

.appearance-section-title {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.branding-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  align-items: start;
}

@media (max-width: 860px) {
  .branding-panels { grid-template-columns: 1fr; }
}

.branding-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
}

.branding-section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

.branding-hint {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin: 0;
}

.branding-save-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-top: 4px;
}

.branding-saved-msg {
  font-size: 0.88rem;
  color: #166534;
  font-weight: 500;
}

/* ============================================================================ */
/* Users management panel                                                        */
/* ============================================================================ */

.users-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}


.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.users-table thead th {
  text-align: left;
  padding: 8px 12px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1.5px solid var(--border);
}

.users-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.users-table tbody tr:hover { background: var(--bg-input); }

.users-table td {
  padding: 10px 12px;
  vertical-align: middle;
}

.users-email {
  color: var(--text-primary);
  font-weight: 500;
  word-break: break-all;
}

.users-date {
  color: var(--text-muted);
  white-space: nowrap;
}

.users-actions {
  white-space: nowrap;
  display: flex;
  gap: 6px;
  align-items: center;
}

.users-protected {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
}

/* Role badges */

.role-badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 10px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.role-owner {
  background: #ede9fe;
  color: #5b21b6;
}

.role-admin {
  background: #dbeafe;
  color: #1e40af;
}

.role-allowed {
  background: #dcfce7;
  color: #166534;
}

.role-denied {
  background: #fef2f2;
  color: #b91c1c;
}

/* ============================================================================ */
/* Corpus advanced actions (download / upload sources)                           */
/* ============================================================================ */

.corpus-detail-advanced {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}

/* Ghost button — low-emphasis secondary action */
.btn-ghost {
  padding: 5px 12px;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.btn-ghost:hover {
  background: var(--bg-input);
  color: var(--text-primary);
}

/* Extra-small size variant */
.btn-xs {
  padding: 3px 9px;
  font-size: 0.78rem;
}

/* Hide file input while making its label click-activatable */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* label styled as btn-ghost works without cursor:pointer since label handles it */
label.btn-ghost { cursor: pointer; }

/* Small size variant for primary/secondary buttons */
.btn-sm {
  padding: 6px 14px;
  font-size: 0.85rem;
}

/* ============================================================================ */
/* Access mode toggle (inside Users tab)                                         */
/* ============================================================================ */

.users-access-mode {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  margin-bottom: 12px;
}

.users-access-mode-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.users-access-mode-toggle {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ============================================================================ */
/* Toggle switch — on/off slider used for boolean settings                       */
/* ============================================================================ */

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

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

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 24px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-track::after {
  content: "";
  position: absolute;
  left: 3px;
  top: 3px;
  width: 18px;
  height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle-switch input:checked + .toggle-track {
  background: #2563eb;
}

.toggle-switch input:checked + .toggle-track::after {
  transform: translateX(18px);
}

.toggle-switch input:disabled + .toggle-track {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================================================================ */
/* Pre-auth add-user form (inside Users tab)                                     */
/* ============================================================================ */

.users-add-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
}

.users-add-title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.users-add-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.users-add-input {
  flex: 1;
  min-width: 200px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
  font-size: 0.88rem;
  color: var(--text-primary);
}
.users-add-input:focus {
  border-color: #a8c0f0;
  outline: none;
}

.users-add-select {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
  font-size: 0.88rem;
  color: var(--text-primary);
  cursor: pointer;
}

/* Tag shown next to emails that are pre-authorized but haven't signed up yet */
.users-preauth-tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 8px;
  background: #fef9c3;
  color: #713f12;
  font-size: 0.72rem;
  font-weight: 600;
  margin-left: 6px;
  vertical-align: middle;
}

/* ============================================================================ */
/* Identity tab — IDP provider cards                                             */
/* ============================================================================ */

.idp-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  width: 100%;
  box-sizing: border-box;
}

.idp-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  overflow: hidden;
}

.idp-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-primary);
  gap: 12px;
}

.idp-card-title {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.idp-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--bg-hover);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  flex-shrink: 0;
}

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

.idp-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.78rem;
  font-weight: 600;
  white-space: nowrap;
}

.idp-badge--on {
  background: #dcfce7;
  color: #15803d;
}

.idp-badge--off {
  background: var(--bg-hover);
  color: var(--text-muted);
}

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

.idp-card--locked {
  opacity: 0.6;
  pointer-events: none;
  user-select: none;
}

/* Re-enable pointer events on the locked notice so text is readable */
.idp-locked-notice {
  pointer-events: auto;
  font-size: 13px;
  color: #92400e;
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 4px;
}

.idp-card-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Copy field — read-only URL with a Copy button */
.idp-copy-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.idp-copy-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

.idp-copy-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.idp-copy-input {
  flex: 1;
  font-size: 0.82rem;
  font-family: monospace;
  color: var(--text-primary);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 8px;
  cursor: text;
  min-width: 0;
}

/* Active provider rows (for SAML / OIDC multi-provider lists) */
.idp-active-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.idp-active-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
}

.idp-active-name {
  flex: 1;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
}

/* Add form section inside a card */
.idp-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.idp-form-title {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.idp-form-actions {
  display: flex;
  justify-content: flex-end;
  padding-top: 4px;
}

/* ============================================================================
   Plan tab — pricing grid
   ============================================================================ */

/* Token budget control section */

.plan-budget-section {
  max-width: 520px;
  margin: 0 auto 36px;
  padding: 22px 24px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg-modal);
}

.plan-budget-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.plan-budget-desc {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.plan-budget-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

.plan-budget-option {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
}

.plan-budget-option input[type="radio"] {
  margin-top: 3px;
  flex-shrink: 0;
  accent-color: var(--ring-color);
}

.plan-budget-option span {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.plan-budget-option strong {
  font-size: 0.9rem;
  color: var(--text-primary);
}

.plan-budget-option small {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.plan-budget-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.plan-budget-label {
  font-size: 0.88rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.plan-budget-input {
  width: 140px;
  padding: 6px 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 0.9rem;
}
.plan-budget-input:focus {
  outline: none;
  border-color: var(--ring-color);
}

.plan-budget-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.plan-budget-status {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.plan-budget-status--ok    { color: #16a34a; }
.plan-budget-status--error { color: var(--ring-danger); }

.users-period-btns {
  display: flex;
  gap: 6px;
}

.plan-budget-input[readonly] {
  opacity: 0.55;
  cursor: default;
  background: var(--bg-2);
}

.tokens-derived-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tokens-derived-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* ---- */

/* ============================================================================
   Trial banner
   ============================================================================ */

.trial-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--warn-bg, #fef3c7);
  border-bottom: 1px solid var(--warn-border, #f59e0b);
  font-size: 0.85rem;
  color: var(--warn-text, #92400e);
  position: sticky;
  top: 0;
  z-index: 10;
}

.trial-banner span {
  flex: 1;
}

.trial-banner-upgrade {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 0.8rem;
  cursor: pointer;
  white-space: nowrap;
}

.trial-banner-close {
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  font-size: 1rem;
  line-height: 1;
  padding: 0 4px;
  opacity: 0.7;
}

.trial-banner-close:hover { opacity: 1; }

/* ============================================================================
   Plan tab — trial notice
   ============================================================================ */

.plan-trial {
  margin: 8px auto 0;
  font-size: 0.85rem;
  max-width: 480px;
}

.plan-trial--ok      { color: var(--text-muted); }
.plan-trial--warn    { color: #d97706; }
.plan-trial--urgent  { color: #dc2626; font-weight: 600; }
.plan-trial--expired { color: #dc2626; font-weight: 600; }

/* ============================================================================
   Plan panel
   ============================================================================ */

.plan-panel {
  padding: 40px 0 60px;
}

.plan-header {
  text-align: center;
  margin-bottom: 28px;
}

.plan-title {
  margin: 0 0 8px;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
}

.plan-subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.plan-notice {
  display: flex;
  align-items: center;
  gap: 10px;
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  border-radius: 10px;
  padding: 14px 20px;
  margin-bottom: 36px;
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.5;
}

.plan-notice-icon {
  font-size: 1.1rem;
  color: var(--accent);
  flex-shrink: 0;
}

.plan-contact-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}
.plan-contact-link:hover {
  text-decoration: underline;
}

/* Grid — 4 columns, collapse gracefully */
.plan-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
}

/* Plan card */
.plan-card {
  display: flex;
  flex-direction: column;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.plan-card--current {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent),
              0 8px 24px rgba(0,0,0,0.18);
}

.plan-card--upcoming {
  opacity: 0.78;
}

.plan-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 32px rgba(0,0,0,0.22);
}

/* Coloured top band */
.plan-card-top {
  padding: 24px 20px 20px;
  text-align: center;
  position: relative;
}

.plan-accent--free     { background: linear-gradient(135deg, #16a34a, #15803d); }
.plan-accent--basic    { background: linear-gradient(135deg, #2563eb, #1d4ed8); }
.plan-accent--pro      { background: linear-gradient(135deg, #7c3aed, #6d28d9); }
.plan-accent--business { background: linear-gradient(135deg, #b45309, #92400e); }

.plan-card-badge {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: rgba(255,255,255,0.2);
  color: #fff;
  border-radius: 20px;
  padding: 3px 10px;
  margin-bottom: 12px;
}

.plan-card-name {
  font-size: 1.25rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 8px;
}

.plan-card-price {
  font-size: 2rem;
  font-weight: 800;
  color: #fff;
  line-height: 1;
}

.plan-card-period {
  font-size: 0.78rem;
  color: rgba(255,255,255,0.7);
  margin-top: 4px;
}

/* Card body — feature list + CTA */
.plan-card-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  padding: 20px;
  gap: 16px;
}

.plan-features {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.plan-feature-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
  gap: 8px;
}
.plan-feature-row:last-child {
  border-bottom: none;
}

.plan-feature-label {
  color: var(--text-muted);
  flex-shrink: 0;
}

.plan-feature-value {
  color: var(--text);
  font-weight: 500;
  text-align: right;
}

/* CTA buttons */
.plan-cta {
  text-align: center;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.plan-cta--active {
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
}

.plan-cta--disabled {
  background: var(--surface-alt, var(--border));
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* Free-tier downgrade is a cancellation, not a plan switch */
.plan-cta--cancel {
  background: transparent;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  font-style: italic;
  font-size: 0.8rem;
}

.plan-cta--switch {
  width: 100%;
  display: block;
  background: var(--bg-btn);
  color: #fff;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: 0.02em;
  text-align: center;
  transition: background 0.15s;
}

.plan-cta--switch:hover:not(:disabled) {
  background: var(--bg-btn-hover);
}

.plan-cta--switch:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================================================================
   Support tab — contact form
   ============================================================================ */

/* textarea inside a branding-form (support tab) */
.branding-form textarea {
  resize: vertical;
  font-family: inherit;
  font-size: 0.9rem;
}

.support-char-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: right;
  margin-top: 4px;
}

.support-char-count--warn {
  color: #f59e0b;
  font-weight: 600;
}

.support-form-actions {
  display: flex;
  justify-content: flex-end;
}

.support-feedback {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.88rem;
  line-height: 1.5;
}

.support-feedback.hidden {
  display: none;
}

.support-feedback--success {
  background: color-mix(in srgb, #16a34a 12%, transparent);
  border: 1px solid color-mix(in srgb, #16a34a 30%, transparent);
  color: #16a34a;
}

.support-feedback--error {
  background: color-mix(in srgb, #dc2626 10%, transparent);
  border: 1px solid color-mix(in srgb, #dc2626 30%, transparent);
  color: #dc2626;
}

.support-form-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin: 0;
}

.support-form-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.5;
}

/* Link row inside the Support Site branding-form card */
.support-site-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.support-site-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.support-site-text strong {
  font-size: 0.95rem;
  color: var(--text);
}

.support-site-text span {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.support-site-btn {
  white-space: nowrap;
  flex-shrink: 0;
  text-decoration: none;
}

/* Shown on Free tier in place of the email form */
.support-free-notice {
  font-size: 0.875rem;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
  line-height: 1.6;
}

/* ============================================================================ */
/* Corpus inner tabs (Sources | CORPUS.md)                                      */
/* ============================================================================ */

.corpus-inner-tabs {
  display: flex;
  gap: 2px;
  margin: 8px 0 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}

.corpus-inner-tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px 4px 0 0;
  transition: color 0.15s, border-color 0.15s;
}

.corpus-inner-tab:hover {
  color: var(--text);
}

.corpus-inner-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Log tab — build-log-body fills the tab body without the fixed panel height */
#corpus-contents-body .build-log-body {
  min-height: 260px;
  max-height: 480px;
}

/* Subtle copy/download/refresh toolbar above the log body */
.log-tab-toolbar {
  display: flex;
  gap: 4px;
  justify-content: flex-end;
  padding: 0 2px 6px;
}
.log-tab-toolbar .build-log-btn {
  font-size: 1rem;
  padding: 2px 7px;
  line-height: 1.4;
}

/* Dim the ↑ Sources upload label when its input is disabled */
#upload-sources-input:disabled + * ,
label:has(#upload-sources-input:disabled) {
  opacity: 0.4;
  pointer-events: none;
  cursor: not-allowed;
}

/* Build Corpus button in cancel state */
#btn-build-corpus.btn-cancel-state {
  background: #7f1d1d;
  color: #fca5a5;
  border-color: #991b1b;
}
#btn-build-corpus.btn-cancel-state:hover {
  background: #991b1b;
}

/* ============================================================================ */
/* CORPUS.md editor panel                                                        */
/* ============================================================================ */

.corpus-md-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 4px 0;
}

.corpus-md-textarea {
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
  min-height: 200px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-family: inherit;
  font-size: 0.88rem;
  color: var(--text);
  line-height: 1.6;
}

.corpus-md-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 20%, transparent);
}

.corpus-md-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ============================================================================ */
/* MCP Connector panel                                                           */
/* ============================================================================ */

.mcp-section {
  margin-top: 24px;
}

.mcp-section-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 10px;
}

.mcp-steps {
  margin: 0;
  padding-left: 20px;
  color: var(--text-muted);
  font-size: 0.875rem;
  line-height: 1.7;
}

.mcp-key-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  background: var(--surface);
}

.mcp-key-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  min-width: 0;
}

.mcp-key-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
}

.mcp-key-prefix {
  font-family: monospace;
  font-size: 0.82rem;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
}

.mcp-key-date {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.mcp-no-keys {
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 8px 0;
  margin: 0;
}

.mcp-generate-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.mcp-label-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.88rem;
  color: var(--text);
}

.mcp-label-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 20%, transparent);
}

.mcp-new-key-box {
  margin-top: 16px;
  padding: 14px 16px;
  background: color-mix(in srgb, #f59e0b 10%, transparent);
  border: 1px solid color-mix(in srgb, #f59e0b 40%, transparent);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mcp-new-key-box.hidden {
  display: none;
}

.mcp-new-key-warning {
  font-size: 0.85rem;
  color: #b45309;
  font-weight: 600;
  margin: 0;
}

.mcp-new-key-display {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.mcp-key-value {
  font-family: monospace;
  font-size: 0.82rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  word-break: break-all;
  color: var(--text);
}

.mcp-config-block {
  position: relative;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px 14px 14px;
}

.mcp-config-pre {
  margin: 0;
  font-family: monospace;
  font-size: 0.8rem;
  line-height: 1.6;
  color: var(--text);
  white-space: pre;
  overflow-x: auto;
}

.mcp-copy-config-btn {
  position: absolute;
  top: 8px;
  right: 8px;
}

.mcp-cred-grid {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 8px 12px;
  align-items: start;
}

.mcp-cred-field-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  padding-top: 8px;
}

/* ================================================================================
 * Settings panel
 * ================================================================================ */

.settings-panel {
  max-width: 820px;
  margin: 0 auto;
  padding: 24px 28px;
}

.settings-header {
  margin-bottom: 24px;
}

.settings-title {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 4px;
}

.settings-subtitle {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin: 0;
}

.settings-sections {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.settings-section {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
}

.settings-section-title {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0 0 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.settings-row {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.settings-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.settings-row:first-of-type {
  padding-top: 0;
}

.settings-row--stacked {
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
}

.settings-row-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.settings-row-label {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
}

.settings-row-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.settings-row-control {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.settings-select {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 0.875rem;
  color: var(--text-primary);
  min-width: 240px;
  cursor: pointer;
}

.settings-select:focus {
  border-color: #a8c0f0;
  outline: none;
}

.model-checkbox-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.model-checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
}

.model-checkbox-row--locked {
  opacity: 0.6;
  cursor: default;
}

.model-checkbox-row input[type="checkbox"] {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  cursor: inherit;
  accent-color: #2d6cdf;
}

.model-required-badge {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 5px;
}

.settings-input {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 0.875rem;
  color: var(--text-primary);
  width: 100px;
}

.settings-input:focus {
  border-color: #a8c0f0;
  outline: none;
}

.settings-textarea {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 0.875rem;
  color: var(--text-primary);
  font-family: inherit;
  line-height: 1.5;
  resize: vertical;
  width: 100%;
  box-sizing: border-box;
}

.settings-textarea:focus {
  border-color: #a8c0f0;
  outline: none;
}

.settings-row-actions {
  display: flex;
  justify-content: flex-end;
}

.settings-loading {
  padding: 48px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ============================================================================ */
/* Operator console shell — header + nav + content                              */
/* ============================================================================ */

#console-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

#console-header {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-shrink: 0;
  height: 56px;
  padding: 0 20px;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
}

.console-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-shrink: 0;
}

/* Badge: white bg + dark icon in light; dark bg + white icon in dark */
.console-brand-icon-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--bg-sidebar);
  flex-shrink: 0;
}
.console-brand-icon { color: #1a1a1a; }
[data-theme="dark"] .console-brand-icon-wrap { background: #1a1a1a; }
[data-theme="dark"] .console-brand-icon       { color: #ffffff; }

.console-brand-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
}
[data-theme="dark"] .console-brand-name { color: #ececec; }

/* GOD MODE badge — amber, persistent reminder of operator (god mode) access */
.god-mode-badge {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #7a3e00;
  background: #fde68a;
  border: 1px solid #f59e0b;
  border-radius: 6px;
  padding: 2px 8px;
  white-space: nowrap;
}
[data-theme="dark"] .god-mode-badge {
  color: #fde68a;
  background: rgba(245, 158, 11, 0.18);
  border-color: #b45309;
}

/* Primary nav — sits between the brand and the account menu */
#console-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.console-nav-item {
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: 0.92rem;
  font-weight: 500;
  color: var(--text-muted);
  transition: background 0.12s, color 0.12s;
}
.console-nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.console-nav-item.active {
  background: var(--bg-active);
  color: var(--text-primary);
}

/* Account menu sits at the right edge of the header */
#console-header #user-menu-container { flex-shrink: 0; width: 200px; }

/* Header-anchored avatar — no token ring in the control plane */
.user-menu-avatar--header {
  position: static;
  transform: none;
  width: 28px;
  height: 28px;
}

/* Header popup opens downward from the trigger */
.user-menu-popup--header {
  top: calc(100% + 6px);
  bottom: auto;
}

/* Theme picker shown inside the account menu submenu */
.theme-picker--menu { padding: 6px 12px 10px; gap: 6px; }
.theme-picker--menu .theme-option { padding: 8px 4px; font-size: 0.78rem; }
.theme-picker--menu .theme-swatch { width: 36px; height: 22px; }

/* ---- Main content panel ---- */

#console-main {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-primary);
}

.view-panel {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 32px;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

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

.view-title {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-primary);
}

/* Loading / empty / error placeholder text inside a view */
.tab-loading {
  font-size: 0.92rem;
  color: var(--text-muted);
  padding: 16px 0;
}

/* ---- Tenant table ---- */

.tenant-table tbody tr { cursor: pointer; }
.tenant-mono {
  font-family: "Consolas", "Fira Mono", "Menlo", monospace;
  font-size: 0.82rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* ---- Tenant detail ---- */

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0 32px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 20px;
  background: var(--bg-input);
}

@media (max-width: 640px) {
  .detail-grid { grid-template-columns: 1fr; }
}

.detail-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.detail-label {
  font-size: 0.74rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.detail-value {
  font-size: 0.9rem;
  color: var(--text-primary);
  word-break: break-all;
}

.detail-audit-title {
  margin: 28px 0 12px;
}
