/* =========================
   AUTH SCREEN
   ========================= */
#auth-screen {
  position: fixed; inset: 0;
  background: #0f1115;
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
#auth-screen.hidden { display: none; }

#auth-box {
  background: #1a1d23;
  border: 1px solid #2d3139;
  border-radius: 10px;
  padding: 32px;
  width: 320px;
  display: flex; flex-direction: column; gap: 12px;
}
#auth-box h2  { margin: 0 0 4px; font-size: 18px; color: #f3f4f6; }
#auth-box input {
  padding: 9px 12px;
  border: 1px solid #374151;
  border-radius: 6px;
  background: #111317;
  color: #f3f4f6;
  font-size: 14px;
}
#auth-box button {
  padding: 9px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 14px;
}
#auth-submit { background: #2563eb; color: #fff; }
#auth-submit:hover { background: #1d4ed8; }
#auth-toggle  { background: transparent; color: #6b7280; }
#auth-toggle:hover  { color: #9ca3af; }
#auth-error { font-size: 13px; color: #ef4444; min-height: 16px; }

/* =========================
   WELCOME MODAL
   ========================= */
#welcome-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 999;
}
#welcome-modal.hidden { display: none; }
#welcome-box {
  background: #1a1d23;
  border: 1px solid #2d3139;
  border-radius: 10px;
  padding: 32px;
  width: 320px;
  display: flex; flex-direction: column; gap: 12px;
}
#welcome-box h2 { margin: 0 0 2px; font-size: 18px; color: #f3f4f6; }
#welcome-box p  { margin: 0; font-size: 13px; color: #6b7280; }
#welcome-box input {
  padding: 9px 12px;
  border: 1px solid #374151;
  border-radius: 6px;
  background: #111317;
  color: #f3f4f6;
  font-size: 14px;
}
#welcome-box input:focus { outline: none; border-color: #2563eb; }
#welcome-submit {
  padding: 9px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  background: #2563eb;
  color: #fff;
}
#welcome-submit:hover:not(:disabled) { background: #1d4ed8; }
#welcome-submit:disabled { opacity: 0.6; cursor: not-allowed; }
#welcome-error { font-size: 13px; color: #ef4444; min-height: 16px; }

.user-bar-logout {
  font-size: 12px; padding: 3px 8px;
  background: transparent; border: 1px solid #374151;
  border-radius: 4px; color: #9ca3af; cursor: pointer;
}
.user-bar-logout:hover { color: #f3f4f6; border-color: #6b7280; }

body {
  margin: 0;
  font-family: Arial, sans-serif;
  background: #0f1115;
  color: #eee;
}

/* =========================
   LAYOUT
========================= */

#container {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

#container.hidden { display: none; }

/* =========================
   SIDEBAR
========================= */

#sidebar {
  width: 220px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: #0c0e12;
  border-right: 1px solid #1f2937;
  overflow: hidden;
}

.sidebar-controls {
  padding: 12px 10px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-bottom: 1px solid #1f2937;
  flex-shrink: 0;
}

.sidebar-controls select {
  width: 100%;
  padding: 5px 7px;
  background: #161a22;
  color: #e2e8f0;
  border: 1px solid #2a2f3a;
  border-radius: 5px;
  font-size: 12px;
  cursor: pointer;
  margin-top: 0;
}

.sidebar-controls select:focus {
  outline: none;
  border-color: #3b82f6;
}

#sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 6px 4px;
  overflow-y: auto;
  gap: 1px;
}

.nav-group {
  display: flex;
  flex-direction: column;
  padding-top: 6px;
}

.nav-group + .nav-group {
  border-top: 1px solid #1a1f28;
  margin-top: 4px;
}

.nav-label {
  padding: 4px 12px 2px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #374151;
  user-select: none;
}

#sidebar-nav button {
  text-align: left;
  width: 100%;
  padding: 8px 12px;
  background: transparent;
  border: none;
  border-radius: 5px;
  color: #6b7280;
  font-size: 13px;
  cursor: pointer;
  margin: 0;
  transition: background 0.1s, color 0.1s;
}

#sidebar-nav button:hover {
  background: #161a22;
  color: #e2e8f0;
}

#sidebar-nav button.active {
  background: #1e3a5f;
  color: #93c5fd;
  border-left: 2px solid #3b82f6;
  padding-left: 10px;
}

#sidebar-footer {
  padding: 10px;
  border-top: 1px solid #1f2937;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#user-bar-email {
  display: block;
  font-size: 11px;
  color: #4b5563;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-footer-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* =========================
   CHAT COLUMN
========================= */

#chat-col {
  width: 420px;
  min-width: 250px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#resizer {
  width: 6px;
  cursor: col-resize;
  background: #1f2937;
  flex-shrink: 0;
  transition: background 0.15s;
}

#resizer:hover,
#resizer.active {
  background: #3b82f6;
}

#right {
  flex: 1;
  min-width: 280px;
  display: flex;
  flex-direction: column;
  border-left: 1px solid #1f2937;
  overflow: hidden;
}

/* =========================
   CHAT (LEFT)
========================= */

#chat-header {
  display: none;
}

#chat-headerbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid #1f2937;
  background: #0c0e12;
  flex-shrink: 0;
}

#chat-headerbar #profile {
  flex: 1;
  min-width: 0;
  padding: 5px 7px;
  background: #161a22;
  color: #e2e8f0;
  border: 1px solid #2a2f3a;
  border-radius: 5px;
  font-size: 12px;
  cursor: pointer;
  margin-top: 0;
}

#chat-headerbar #profile:focus {
  outline: none;
  border-color: #3b82f6;
}

#chat, #mai-chat {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
}

#chat::before, #mai-chat::before {
  content: '';
  flex: 1;
}

.chat-empty {
  margin: auto;
  color: #4b5563;
  font-size: 13px;
  text-align: center;
}

.chat-history-hint {
  text-align: center;
  font-size: 11px;
  color: #4b5563;
  padding: 6px 0 10px;
}

.ctrl-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.ctrl-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #6b7280;
}

/* =========================
   INPUT AREA
========================= */

#input-area {
  flex-shrink: 0;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 8px 12px 12px;
  border-top: 1px solid #1f2937;
}

#input-area textarea#message {
  flex: 1;
  height: 72px;
  min-height: 72px;
  background: #1a1d23;
  color: #eee;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  resize: none;
  padding: 8px 10px;
  font-size: 14px;
  box-sizing: border-box;
  line-height: 1.4;
  font-family: inherit;
}

#input-area textarea#message:focus {
  outline: none;
  border-color: #3b82f6;
}

#send-btn {
  height: 72px;
  width: 60px;
  background: #1e3a5f;
  color: #93c5fd;
  border: 1px solid #1e3a5f;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  margin-top: 0;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

#send-btn:hover {
  background: #2563eb;
  color: #fff;
  border-color: #2563eb;
}

#send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* =========================
   RIGHT PANEL
========================= */

.user-bar-admin {
  font-size: 11px;
  padding: 3px 8px;
  background: #161c2a;
  color: #8ab4f8;
  border: 1px solid #2d3a5a;
  border-radius: 4px;
  cursor: pointer;
  letter-spacing: 0.02em;
  margin-top: 0;
}

.user-bar-admin:hover {
  background: #1e2a42;
  color: #93c5fd;
  border-color: #3b5a9a;
}

#panelContent {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* =========================
   SECTION (panel pages)
========================= */

.section {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px;
  min-height: 0;
  max-width: 100%;
}

/* sections that scroll their own content */
.section.scrollable {
  overflow-y: auto;
}

.section h2 {
  flex-shrink: 0;
  margin-bottom: 10px;
}

/* =========================
   INPUTS / BUTTONS
========================= */

select, button {
  margin-top: 5px;
  background: #2a2f38;
  color: #eee;
  border: none;
  padding: 6px;
  cursor: pointer;
}

button {
  padding: 8px 12px;
  border-radius: 6px;
}

button:hover {
  background: #3a404c;
}

button.primary {
  background: #2b6cb0;
}

button.primary:hover {
  background: #3b7dd8;
}

/* =========================
   FORM HELPERS
========================= */

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

.form-group {
  display: flex;
  flex-direction: column;
  margin-bottom: 12px;
}

.form-group input,
.form-group textarea,
.row input,
.row select {
  flex: 1;
  padding: 8px;
  background: #1a1d23;
  border: 1px solid #444;
  color: #eee;
  border-radius: 6px;
}

/* panel textareas: taller default, user-resizable */
.form-group textarea {
  flex: none;           /* override flex:1 from combined rule — lets resize drag work */
  width: 100%;
  box-sizing: border-box;
  min-height: 200px;
  max-height: 60vh;
  resize: vertical;
}

#panelButtons {
  padding: 10px;
  border-bottom: 1px solid #333;
}

/* =========================
   CHAT MESSAGES
========================= */

.msg {
  display: flex;
  margin: 10px 0;
}

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

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

.bubble {
  padding: 12px 16px;
  border-radius: 16px;
  max-width: 70%;
  font-size: 14px;
  line-height: 1.4;
}

.bubble.user {
  background: #1e3a5f;
  color: #e5e7eb;
}

.bubble.assistant {
  background: #1f2937;
  color: #e5e7eb;
}

.bubble.user .history-label     { color: #93c5fd; }
.bubble.assistant .history-label { color: #86efac; }

.typing-indicator {
  color: #6b7280;
  font-style: italic;
  animation: typing-pulse 1.4s ease-in-out infinite;
}

@keyframes typing-pulse {
  0%, 100% { opacity: 0.35; }
  50%       { opacity: 1;    }
}

/* =========================
   SCROLLBAR
========================= */

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-thumb {
  background: #444;
  border-radius: 3px;
}

::-webkit-scrollbar-track {
  background: #111;
}

/* =========================
   HISTORY
========================= */

.history-item {
  padding: 10px 14px;
  border-radius: 10px;
  max-width: 80%;
  margin-bottom: 10px;
}

.history-item.user {
  background: #1e3a5f;
  align-self: flex-end;
}

.history-item.assistant {
  background: #1f2937;
  align-self: flex-start;
}

/* meta row: label · time · delete */
.history-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.history-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.history-item.user .history-label {
  color: #93c5fd;
}

.history-item.assistant .history-label {
  color: #86efac;
}

.history-time {
  font-size: 10px;
  color: rgba(255,255,255,0.3);
  margin-right: auto;
}

.history-meta .danger {
  opacity: 0;
  transition: opacity 0.15s;
  font-size: 13px;
  padding: 0;
}

.history-item:hover .history-meta .danger {
  opacity: 0.6;
}

.history-item:hover .history-meta .danger:hover {
  opacity: 1;
}

.history-content {
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  color: #e5e7eb;
}

/* =========================
   MEMORY UI
========================= */

.memory-block {
  margin-bottom: 28px;
  overflow: visible;
}

.memory-block h3 {
  margin-bottom: 12px;
  color: #8ab4f8;
}

.memory-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  background: #161a22;
  border: 1px solid #2a2f3a;
  border-radius: 10px;
  padding: 6px 10px;
  transition: all 0.2s ease;
}

.memory-item:hover {
  border-color: #3b82f6;
  background: #1c2230;
}

.mem-text {
  flex: 1;
  background: transparent;
  border: none;
  color: #e5e7eb;
  font-size: 14px;
  padding: 2px 0;
}

.mem-text:focus {
  outline: none;
}

.mem-score {
  width: 60px;
  text-align: center;
  background: #1e293b;
  border: none;
  color: #93c5fd;
  font-size: 13px;
  padding: 2px;
}

.btn-danger {
  background: transparent;
  border: 1px solid #7f1d1d;
  color: #f87171;
  padding: 4px 10px;
  border-radius: 5px;
  font-size: 12px;
  cursor: pointer;
  opacity: 0.75;
  transition: opacity 0.15s, background 0.15s;
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.1);
  opacity: 1;
}

.key-status {
  font-size: 11px;
  margin-left: 6px;
  font-weight: normal;
}

.key-connected { color: #4ade80; }
.key-missing   { color: #6b7280; }

.danger {
  background: transparent;
  border: none;
  color: #ef4444;
  font-size: 16px;
  cursor: pointer;
  opacity: 0.6;
  transition: all 0.2s ease;
}

.danger:hover {
  opacity: 1;
  transform: scale(1.1);
}

.empty {
  color: #666;
  font-size: 13px;
  padding: 8px 0;
}

/* =========================
   ADMIN PAGE — SHELL
========================= */

.admin-shell {
  display: flex;
  height: 100%;
  overflow: hidden;
}

.admin-nav {
  width: 148px;
  flex-shrink: 0;
  background: #0e1117;
  border-right: 1px solid #1f2937;
  display: flex;
  flex-direction: column;
  padding: 16px 0;
  gap: 2px;
}

.admin-nav-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #4b5563;
  padding: 0 16px 12px;
  border-bottom: 1px solid #1f2937;
  margin-bottom: 6px;
}

.admin-nav-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: #6b7280;
  font-size: 13px;
  padding: 8px 16px;
  cursor: pointer;
  border-radius: 0;
  transition: background 0.12s, color 0.12s;
}

.admin-nav-item:hover {
  background: #161a22;
  color: #d1d5db;
}

.admin-nav-item.active {
  background: #1a2235;
  color: #8ab4f8;
  font-weight: 600;
  border-right: 2px solid #3b82f6;
}

.admin-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.admin-page-title {
  font-size: 16px;
  font-weight: 600;
  color: #e5e7eb;
  margin: 0 0 20px;
}

/* Users page */
.admin-search {
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 12px;
  background: #0e1117;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  color: #e5e7eb;
  font-size: 13px;
  padding: 7px 10px;
}

.admin-search:focus {
  outline: none;
  border-color: #3b82f6;
}

.admin-user-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 4px;
  border-bottom: 1px solid #1f2937;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.1s;
}

.admin-user-row:hover {
  background: #161a22;
}

.admin-user-email {
  flex: 1;
  font-size: 13px;
  color: #d1d5db;
}

.admin-user-role {
  font-size: 11px;
  color: #4b5563;
  padding: 2px 7px;
  border-radius: 10px;
  background: #1f2937;
}

.admin-user-role.admin {
  color: #8ab4f8;
  background: #1a2235;
}

/* =========================
   ADMIN PAGE — CARDS
========================= */

.admin-card {
  background: #161a22;
  border: 1px solid #2a2f3a;
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 16px;
}

.admin-card h3 {
  margin: 0 0 16px 0;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #8ab4f8;
  border-bottom: 1px solid #2a2f3a;
  padding-bottom: 10px;
}

.admin-desc {
  font-size: 12px;
  color: #4b5563;
  margin: -6px 0 16px;
  line-height: 1.5;
}

.admin-desc-danger {
  color: #7f3535;
}

/* Providers inline row */
.admin-providers {
  margin-top: 6px;
  padding-top: 12px;
  border-top: 1px solid #2a2f3a;
}

.admin-providers-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #6b7280;
  margin-bottom: 10px;
}

.admin-provider-row {
  display: flex;
  gap: 22px;
  flex-wrap: wrap;
}

.admin-provider-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: #9ca3af;
  cursor: pointer;
  user-select: none;
}

.admin-provider-item input[type="checkbox"] {
  width: 14px;
  height: 14px;
  margin: 0;
  cursor: pointer;
  accent-color: #3b82f6;
  flex-shrink: 0;
}

/* Providers vertical list */
.admin-provider-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.admin-provider-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13px;
  color: #9ca3af;
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
}

.admin-provider-list-item:hover {
  background: #1a1f2b;
  color: #e2e8f0;
}

.admin-provider-list-item input[type="checkbox"] {
  width: 14px;
  height: 14px;
  margin: 0;
  cursor: pointer;
  accent-color: #3b82f6;
  flex-shrink: 0;
}

/* Routing (provider chain) rows */
.admin-chain-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.provider-chain-row {
  background: #0d1117 !important;
  border: 1px solid #2a2f3a !important;
  border-radius: 7px !important;
  padding: 8px 10px !important;
  margin-bottom: 0 !important;
}

/* Usable tokens display */
.admin-usable-tokens {
  font-size: 13px;
  color: #6b7280;
  margin: 8px 0 12px;
}

/* Collapsible Advanced card */
.admin-card-collapsible {
  padding: 0;
  overflow: hidden;
}

.admin-collapsible-toggle {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  background: transparent;
  border: none;
  border-bottom: 1px solid #2a2f3a;
  color: #8ab4f8;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
  margin: 0;
  border-radius: 0;
}

.admin-collapsible-toggle:hover {
  background: rgba(139, 180, 248, 0.04);
  color: #93c5fd;
}

.admin-collapsible-arrow {
  font-size: 10px;
  color: #4b5563;
}

#admin-advanced-body {
  padding: 16px 20px 4px;
}

/* Memory Rules field (vertical layout, explicit sizing) */
.admin-rules-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.admin-rules-label {
  font-size: 13px;
  color: #9ca3af;
  line-height: 1.4;
}

.admin-rules-textarea {
  display: block;
  width: 100%;
  box-sizing: border-box;
  min-height: 120px;
  max-height: 300px;
  padding: 8px 10px;
  background: #1a1d23;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  color: #eee;
  font-size: 12px;
  font-family: "Courier New", monospace;
  resize: vertical;
  line-height: 1.5;
}

.admin-rules-textarea:focus {
  outline: none;
  border-color: #3b82f6;
}

/* Inline collapsible subsection within a card */
.admin-sub-collapsible {
  margin-top: 14px;
  padding-top: 2px;
  border-top: 1px solid #2a2f3a;
}

.admin-sub-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 8px 0;
  background: transparent;
  border: none;
  color: #6b7280;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  margin: 0;
  text-align: left;
}

.admin-sub-toggle:hover {
  color: #9ca3af;
  background: transparent;
}

/* Usage Summary Card */
.admin-card-usage-summary {
  padding: 0;
}

.usage-summary-details {
  width: 100%;
}

.usage-summary-collapsed {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 500;
  color: #e2e8f0;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.usage-summary-collapsed::-webkit-details-marker { display: none; }

.usage-summary-collapsed::after {
  content: "▶";
  margin-left: auto;
  font-size: 10px;
  color: #6b7280;
  transition: transform 0.15s;
}

.usage-summary-details[open] .usage-summary-collapsed::after {
  transform: rotate(90deg);
}

.usage-summary-body {
  padding: 0 16px 14px;
  border-top: 1px solid #2a2f3a;
}

.usage-breakdown {
  padding-top: 12px;
}

.usage-breakdown-period {
  font-size: 11px;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.usage-breakdown-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: #9ca3af;
  padding: 2px 0;
}

.usage-breakdown-row span:first-child {
  color: #d1d5db;
}

.usage-breakdown-indent {
  padding-left: 16px;
  font-size: 12px;
}

.usage-breakdown-indent span:first-child {
  color: #6b7280;
}

/* Danger Zone */
.admin-card-danger {
  border-color: #5a1d1d;
  background: #0e0808;
}

.admin-card-danger h3 {
  color: #f87171;
  border-bottom-color: #5a1d1d;
}

.btn-danger-action {
  background: transparent;
  border: 1px solid #7f1d1d;
  color: #f87171;
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  margin-top: 0;
}

.btn-danger-action:hover {
  background: rgba(239, 68, 68, 0.1);
  color: #fca5a5;
  border-color: #991b1b;
}

.field {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.field:last-child {
  margin-bottom: 0;
}

.field label {
  width: 160px;
  flex-shrink: 0;
  font-size: 13px;
  color: #9ca3af;
  padding-top: 8px;
  line-height: 1.4;
}

.label-hint {
  color: #4b5563;
  font-size: 11px;
}

.label-deprecated {
  color: #f59e0b;
  font-size: 11px;
  font-style: italic;
}

.field-hint {
  font-size: 11px;
  color: #6b7280;
  margin: 2px 0 0;
}

/* Hint indented to sit under the input column (past the 160px label + 12px gap) */
.settings-hint {
  margin-left: 172px;
  margin-top: -6px;
  margin-bottom: 12px;
}

/* Select inside .field rows */
.field select {
  flex: 1;
  padding: 7px 10px;
  background: #1a1d23;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  color: #eee;
  font-size: 13px;
  cursor: pointer;
}

.field select:focus {
  outline: none;
  border-color: #3b82f6;
}

/* AI Lab bot pair columns in Settings */
.settings-bot-pair {
  display: flex;
  gap: 20px;
}

.settings-bot-col {
  flex: 1;
  min-width: 0;
}

.settings-bot-col .mai-bot-header {
  margin-bottom: 8px;
}

.settings-bot-col label {
  display: block;
  font-size: 11px;
  color: #6b7280;
  margin-bottom: 4px;
}

.settings-bot-col select {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  background: #1a1d23;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  color: #eee;
  font-size: 12px;
  cursor: pointer;
}

.settings-bot-col select:focus {
  outline: none;
  border-color: #3b82f6;
}

/* Primary CHAT card accent */
.settings-card-primary {
  border-color: #1e3a5f;
}

.settings-card-primary h3 {
  color: #93c5fd;
}

/* Divider between field groups within a card */
.settings-divider {
  border: none;
  border-top: 1px solid #2a2f3a;
  margin: 16px 0;
}

/* Usage summary block inside CHAT section */
.settings-usage-summary {
  background: #0d1117;
  border: 1px solid #2a2f3a;
  border-radius: 8px;
  padding: 10px 14px;
  margin-top: 8px;
  margin-left: 172px;
}

.settings-usage-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 0;
}

.settings-usage-label {
  font-size: 12px;
  color: #6b7280;
  min-width: 48px;
}

.settings-usage-value {
  font-size: 12px;
  color: #9ca3af;
  font-variant-numeric: tabular-nums;
}

/* Advanced collapsed section */
.settings-advanced-toggle {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 500;
  color: #6b7280;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.settings-advanced-toggle::-webkit-details-marker { display: none; }

.settings-advanced-toggle::after {
  content: "▶";
  margin-left: auto;
  font-size: 10px;
  transition: transform 0.15s;
}

.admin-card-collapsible details[open] .settings-advanced-toggle::after {
  transform: rotate(90deg);
}

.settings-advanced-body {
  padding: 12px 16px 14px;
  border-top: 1px solid #2a2f3a;
}

.token-badge {
  font-size: 11px;
  color: #6b7280;
  padding: 2px 8px 6px;
  cursor: default;
  user-select: none;
}

.tooltip-wrap {
  position: relative;
  display: inline-block;
  margin-left: 4px;
  color: #4b5563;
  font-size: 11px;
  cursor: help;
  vertical-align: middle;
}

.tooltip-wrap:hover {
  color: #6b7280;
}

.tooltip-wrap .tooltip-text {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  width: 230px;
  background: #0f1115;
  border: 1px solid #374151;
  color: #9ca3af;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
  text-transform: none;
  letter-spacing: normal;
  padding: 7px 10px;
  border-radius: 6px;
  white-space: normal;
  pointer-events: none;
  z-index: 200;
  transition: opacity 0.15s;
}

.tooltip-wrap:hover .tooltip-text {
  visibility: visible;
  opacity: 1;
}

.field input[type="text"],
.field input[type="number"] {
  flex: 1;
  padding: 7px 10px;
  background: #1a1d23;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  color: #eee;
  font-size: 13px;
}

.field input[type="text"]:focus,
.field input[type="number"]:focus {
  outline: none;
  border-color: #3b82f6;
}

.field input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin-top: 9px;
  cursor: pointer;
  accent-color: #3b82f6;
  flex-shrink: 0;
}

.field textarea {
  flex: 1;
  padding: 8px 10px;
  background: #1a1d23;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  color: #eee;
  font-size: 12px;
  font-family: "Courier New", monospace;
  min-height: 100px;
  max-height: 300px;
  resize: vertical;
  line-height: 1.5;
}

.field textarea:focus {
  outline: none;
  border-color: #3b82f6;
}

/* =========================
   TOAST
========================= */

#toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  color: #e5e7eb;
  background: #1f2937;
  border: 1px solid #374151;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  opacity: 0;
  transform: translateX(12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: auto;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(0);
}

.toast.toast-success { border-left: 3px solid #22c55e; }
.toast.toast-error   { border-left: 3px solid #ef4444; }
.toast.toast-info    { border-left: 3px solid #3b82f6; }

/* =========================
   CHAT ERROR NOTIFICATION
========================= */

.msg-error {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  margin: 6px 12px;
  background: #2d1f1f;
  border: 1px solid #7f1d1d;
  border-left: 3px solid #ef4444;
  border-radius: 6px;
  font-size: 13px;
  color: #fca5a5;
  flex-wrap: wrap;
}

.msg-error-text { flex: 1; }

.msg-error-action {
  background: transparent;
  border: 1px solid #ef4444;
  color: #fca5a5;
  border-radius: 4px;
  padding: 2px 10px;
  font-size: 12px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.msg-error-action:hover {
  background: #7f1d1d;
  color: #fff;
}

/* token usage */
#usageBox {
  font-size: 13px;
  color: #9ca3af;
  line-height: 2;
}

#usageBox b {
  color: #e2e8f0;
}

#usageBox hr {
  border: none;
  border-top: 1px solid #2a2f3a;
  margin: 6px 0;
}

.bar {
  background: #1a1d23;
  border-radius: 4px;
  height: 6px;
  margin: 8px 0 4px;
  overflow: hidden;
}

.bar-inner {
  height: 100%;
  background: #3b82f6;
  border-radius: 4px;
  transition: width 0.4s ease;
}

.cost {
  font-size: 12px;
  color: #4b5563;
  margin-top: 6px;
}

/* =========================
   MULTI-AI PAGE
========================= */

.mai-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* ── Settings panel (collapsible) ── */

.mai-settings-panel {
  flex-shrink: 0;
}

.mai-settings-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: #0c0e12;
  border: none;
  border-bottom: 1px solid #1f2937;
  color: #94a3b8;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  text-align: left;
}

.mai-settings-toggle:hover {
  background: #131720;
  color: #e2e8f0;
}

/* ── Control area ── */

.mai-controls {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid #1f2937;
  background: #0c0e12;
}

/* ── Bot cards row ── */

.mai-bots-row {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid #1f2937;
}

.bot-card {
  flex: 1;
  min-width: 0;
  background: #0a0c10;
  border: 1px solid #1f2937;
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bot-card-a { border-color: #1e3252; }
.bot-card-b { border-color: #12302a; }

.bot-card-header {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 2px;
}

.bot-field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bot-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.bot-field-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #4b5563;
}

.bot-field-sep {
  margin-top: 2px;
  padding-top: 9px;
  border-top: 1px solid #1f2937;
}

.bot-card select {
  background: #1a1f28;
  color: #d1d5db;
  border: 1px solid #2a3040;
  border-radius: 5px;
  padding: 5px 8px;
  font-size: 12px;
  cursor: pointer;
  width: 100%;
  box-sizing: border-box;
}

.bot-card select:focus {
  outline: none;
  border-color: #3b82f6;
}

/* ── Global controls bar (Rounds / Mode / Context) ── */

.mai-global-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 9px 14px;
}

.mai-ctrl-group {
  display: flex;
  align-items: center;
  gap: 7px;
}

.mai-ctrl-group-stacked {
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
}

.mai-ctrl-label-row {
  display: flex;
  align-items: center;
  gap: 3px;
}

.mai-ctrl-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #4b5563;
  flex-shrink: 0;
}

.mai-ctrl-btns {
  display: flex;
  gap: 4px;
}

.mai-ctrl-divider {
  width: 1px;
  height: 18px;
  background: #1f2937;
  flex-shrink: 0;
}

.mai-ctrl-input {
  width: 52px;
  padding: 4px 7px;
  background: #2a2f38;
  border: 1px solid #374151;
  border-radius: 5px;
  color: #eee;
  font-size: 12px;
  text-align: center;
}

/* ── Keep legacy classes (used in settings.js) ── */

.mai-bot-section {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.mai-bot-header {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.mai-color-a { color: #93c5fd; }
.mai-color-b { color: #86efac; }

.mai-bot-row {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.mai-bot-row select {
  background: #2a2f38;
  color: #eee;
  border: 1px solid #374151;
  border-radius: 5px;
  padding: 5px 8px;
  font-size: 12px;
  cursor: pointer;
  width: 175px;
}

.mai-rounds-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.mai-rounds-group label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #6b7280;
}

.mai-rounds-group input {
  width: 58px;
  padding: 5px 8px;
  background: #2a2f38;
  border: 1px solid #374151;
  border-radius: 5px;
  color: #eee;
  font-size: 12px;
}

.mai-instruction-row {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid #1f2937;
}

.mai-instruction-row input[type="text"] {
  flex: 1;
  padding: 5px 10px;
  background: #2a2f38;
  border: 1px solid #374151;
  border-radius: 5px;
  color: #eee;
  font-size: 12px;
}

.mai-instruction-row input[type="text"]::placeholder {
  color: #4b5563;
}

/* ── Session bar ── */

.mai-session-bar {
  flex-shrink: 0;
  padding: 5px 16px;
  font-size: 11px;
  color: #4b5563;
  border-bottom: 1px solid #161a22;
  background: #0a0c10;
  letter-spacing: 0.02em;
}

/* ── Chat area ── */

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

.mai-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #4b5563;
  font-size: 13px;
  padding: 24px 0;
}

/* ── Message rows ── */

.mai-msg {
  display: flex;
  flex-direction: column;
  max-width: 72%;
  margin-bottom: 10px;
}

.mai-msg-a {
  align-self: flex-start;
}

.mai-msg-b {
  align-self: flex-end;
  align-items: flex-end;
}

.mai-msg-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
  padding: 0 4px;
}

.mai-msg-a .mai-msg-label { color: #93c5fd; }
.mai-msg-b .mai-msg-label { color: #86efac; }

/* ── Bubbles ── */

.mai-bubble {
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  color: #e5e7eb;
  border-radius: 14px;
}

.mai-msg-a .mai-bubble {
  background: #152238;
  border-bottom-left-radius: 4px;
}

.mai-msg-b .mai-bubble {
  background: #112419;
  border-bottom-right-radius: 4px;
}

.mai-mode-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  font-size: 12px;
  color: #94a3b8;
}

.mai-mode-btn {
  background: #2a2f38;
  border: 1px solid #374151;
  color: #94a3b8;
  padding: 3px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}

.mai-mode-btn.mai-mode-active {
  background: #1e40af;
  border-color: #3b82f6;
  color: #fff;
}

.mai-input-area {
  flex-shrink: 0;
  padding: 8px 16px 12px;
  border-top: 1px solid #1f2937;
  background: #0c0e12;
}

.mai-status {
  font-size: 12px;
  color: #94a3b8;
  margin-bottom: 6px;
  min-height: 18px;
}

.mai-input-row {
  display: flex;
  gap: 6px;
}

.mai-input-row input[type="text"] {
  flex: 1;
  background: #1a1f28;
  border: 1px solid #374151;
  color: #e2e8f0;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13px;
}

.mai-input-row input[type="text"]:disabled { opacity: 0.4; }

.mai-input-row input[type="text"]::placeholder { color: #4b5563; }

.mai-input-row button {
  background: #1e40af;
  border: none;
  color: #fff;
  padding: 7px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

.mai-input-row button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.mai-msg-user { align-self: center; }

.mai-msg-user .mai-msg-label { color: #fbbf24; }

.mai-msg-user .mai-bubble {
  background: #2d2000;
  border-color: #78350f;
}

/* ── Sessions panel (fills remaining height) ── */

.mai-sessions-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ── Inline Sessions panel ── */

.mai-sessions-header {
  display: flex;
  align-items: center;
  background: #0c0e12;
  border-bottom: 1px solid #1f2937;
}

.mai-sessions-toggle-btn {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  cursor: pointer;
  text-align: left;
}

.mai-sessions-toggle-btn:hover {
  color: #e2e8f0;
}

.mai-session-count {
  font-size: 11px;
  color: #4b5563;
  font-weight: 400;
}

.mai-sessions-deleteall {
  background: transparent;
  border: none;
  color: #4b5563;
  font-size: 11px;
  padding: 8px 14px;
  cursor: pointer;
  flex-shrink: 0;
  white-space: nowrap;
}

.mai-sessions-deleteall:hover {
  color: #f87171;
}

.mai-sessions-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  background: #0a0c10;
}

.mai-sessions-empty {
  color: #6b7280;
  font-size: 12px;
  padding: 10px 16px;
  margin: 0;
}

/* Session cards */

.mai-session-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid #111520;
  cursor: pointer;
  transition: background 0.1s;
}

.mai-session-card:hover {
  background: #0f1420;
}

.mai-session-card:last-child {
  border-bottom: none;
}

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

.mai-session-card-ts {
  font-size: 12px;
  color: #94a3b8;
  margin-bottom: 2px;
}

.mai-session-card-preview {
  font-size: 11px;
  color: #6b7280;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mai-session-card.active {
  background: #0d1625;
  border-left: 2px solid #3b82f6;
}

.mai-session-card.active .mai-session-card-ts {
  color: #93c5fd;
}

.mai-session-card-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.mai-session-card-actions button {
  background: #1e3a5f;
  border: 1px solid #2d5a8e;
  color: #93c5fd;
  padding: 3px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  flex-shrink: 0;
}

.mai-session-card-actions button:hover {
  background: #1e40af;
}

.mai-session-card-actions button.danger {
  background: transparent;
  border-color: transparent;
  color: #6b7280;
  padding: 3px 6px;
}

.mai-session-card-actions button.danger:hover {
  color: #f87171;
}

/* =========================
   CHAT TOPBAR
========================= */

#topbar-gear {
  display: flex;
  align-items: center;
  gap: 5px;
  background: transparent;
  border: 1px solid #374151;
  color: #9ca3af;
  font-size: 14px;
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  margin: 0;
  line-height: 1;
  flex-shrink: 0;
}

#topbar-gear:hover {
  color: #e2e8f0;
  border-color: #6b7280;
  background: #161a22;
}

#topbar-controls {
  display: none;
  flex-shrink: 0;
}

body.topbar-sheet-open #topbar-controls {
  display: grid;
  grid-template-columns: 120px 1fr;
  row-gap: 12px;
  column-gap: 12px;
  align-items: center;
  padding: 14px;
  border-bottom: 1px solid #1f2937;
  background: #0c0e12;
}

.topbar-provider-model {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 120px 1fr;
  row-gap: 10px;
  column-gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid #2a2f3a;
  border-radius: 6px;
  background: #111317;
}

.topbar-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #6b7280;
  white-space: nowrap;
}

#topbar-controls select {
  width: 100%;
  box-sizing: border-box;
  background: #161a22;
  color: #e2e8f0;
  border: 1px solid #2a2f3a;
  border-radius: 5px;
  font-size: 12px;
  padding: 5px 7px;
  cursor: pointer;
  margin: 0;
}

#topbar-controls select:focus {
  outline: none;
  border-color: #3b82f6;
}

#topbar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 699;
}

@keyframes topbar-slide-up {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* =========================
   MOBILE / RESPONSIVE
========================= */

/* Hamburger — hidden on desktop */
#mobile-bar {
  display: none;
  align-items: center;
  height: 44px;
  padding: 0 12px;
  border-bottom: 1px solid #1f2937;
  background: #0c0e12;
  flex-shrink: 0;
}

#hamburger {
  background: transparent;
  border: none;
  color: #9ca3af;
  font-size: 20px;
  line-height: 1;
  padding: 4px 8px;
  margin: 0;
  border-radius: 4px;
  cursor: pointer;
}

#hamburger:hover {
  color: #e2e8f0;
  background: #161a22;
}

/* Overlay backdrop when sidebar is open */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 499;
}

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

/* Back bar — hidden on desktop */
#mobile-back-bar {
  display: none;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid #1f2937;
  background: #0c0e12;
  flex-shrink: 0;
}

#mobile-back {
  background: transparent;
  border: none;
  color: #6b7280;
  font-size: 13px;
  cursor: pointer;
  padding: 4px 0;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

#mobile-back:hover {
  color: #e2e8f0;
  background: transparent;
}

/* ── Media query ── */

@media (max-width: 768px) {
  /* Sidebar becomes a slide-in drawer */
  #sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 500;
    width: 260px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.6);
  }

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

  /* Chat column fills full width */
  #chat-col {
    width: 100% !important;
    min-width: 0;
    flex: 1;
  }

  /* Right panel becomes a full-screen overlay when active */
  #right {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 600;
    background: #0f1115;
    border-left: none;
    overflow-y: auto;
  }

  #right.mobile-open {
    display: flex;
    flex-direction: column;
  }

  /* Hide resizer */
  #resizer {
    display: none;
  }

  /* Show mobile-only elements */
  #mobile-bar {
    display: flex;
  }

  #mobile-back-bar {
    display: flex;
  }

  body.topbar-sheet-open #topbar-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    grid-template-columns: 1fr;
    row-gap: 10px;
    padding: 20px 16px 32px;
    background: #161a22;
    border-top: 1px solid #374151;
    border-bottom: none;
    border-radius: 14px 14px 0 0;
    z-index: 700;
    animation: topbar-slide-up 0.22s ease;
  }

  body.topbar-sheet-open #topbar-overlay {
    display: block;
  }

  .topbar-provider-model {
    grid-template-columns: 1fr;
  }

  #topbar-controls select {
    padding: 9px 10px;
    font-size: 14px;
  }
}
