/* Engram WebUI — Premium Modern Dashboard */

/* ===== Design Tokens ===== */
:root, [data-theme="dark"] {
  --bg-canvas: #0a0b0f;
  --bg-primary: #12141a;
  --bg-secondary: #1a1d25;
  --bg-card: rgba(26,29,37,.85);
  --bg-hover: rgba(255,255,255,.04);
  --border: rgba(255,255,255,.06);
  --border-hover: rgba(255,255,255,.12);
  --text-primary: #e4e5e7;
  --text-secondary: #8b8d93;
  --text-muted: #555860;
  --accent: #ff9830;
  --accent-hover: #ffad5c;
  --accent-dim: rgba(255,152,48,.12);
  --success: #22c55e;
  --error: #ef4444;
  --info: #3b82f6;
  --warning: #f59e0b;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --font: 'Inter', -apple-system, system-ui, sans-serif;
  --mono: 'SF Mono', 'Cascadia Code', 'JetBrains Mono', monospace;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow: 0 1px 3px rgba(0,0,0,.3), 0 4px 12px rgba(0,0,0,.15);
  --shadow-lg: 0 4px 16px rgba(0,0,0,.4), 0 8px 32px rgba(0,0,0,.2);
  --glass-bg: rgba(26,29,37,.75);
  --glass-blur: blur(12px);
  --toast-success-bg: rgba(34,197,94,.12); --toast-success-border: rgba(34,197,94,.25);
  --toast-error-bg: rgba(239,68,68,.12); --toast-error-border: rgba(239,68,68,.25);
  --toast-info-bg: rgba(59,130,246,.12); --toast-info-border: rgba(59,130,246,.25);
  --row-hover: rgba(255,152,48,.04);
  --modal-overlay: rgba(0,0,0,.7);
  --sidebar-width: 240px;
  --sidebar-collapsed: 64px;
  --topbar-height: 56px;
}

/* Light theme */
[data-theme="light"] {
  --bg-canvas: #f0f2f5;
  --bg-primary: #ffffff;
  --bg-secondary: #f5f6f8;
  --bg-card: rgba(255,255,255,.9);
  --bg-hover: rgba(0,0,0,.03);
  --border: rgba(0,0,0,.08);
  --border-hover: rgba(0,0,0,.14);
  --text-primary: #1a1c20;
  --text-secondary: #5a5e64;
  --text-muted: #8a8e94;
  --accent: #e07800;
  --accent-hover: #c06800;
  --accent-dim: rgba(224,120,0,.10);
  --success: #16a34a;
  --error: #dc2626;
  --info: #2563eb;
  --warning: #d97706;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.04);
  --shadow-lg: 0 4px 16px rgba(0,0,0,.1), 0 8px 32px rgba(0,0,0,.06);
  --glass-bg: rgba(255,255,255,.8);
  --toast-success-bg: rgba(34,197,94,.08); --toast-success-border: rgba(34,197,94,.2);
  --toast-error-bg: rgba(239,68,68,.08); --toast-error-border: rgba(239,68,68,.2);
  --toast-info-bg: rgba(59,130,246,.08); --toast-info-border: rgba(59,130,246,.2);
  --row-hover: rgba(224,120,0,.04);
  --modal-overlay: rgba(0,0,0,.4);
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg-canvas); color: var(--text-primary); font-family: var(--font); font-size: 14px; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

/* ===== App Layout: Sidebar + Content ===== */
#app { display: flex; height: 100vh; overflow: hidden; }

/* --- Sidebar --- */
#sidebar {
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-primary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width .25s cubic-bezier(.4,0,.2,1);
  z-index: 100;
  overflow: hidden;
}
#sidebar.collapsed { width: var(--sidebar-collapsed); }

/* Sidebar brand */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 16px 18px;
  height: var(--topbar-height);
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand .brand-icon { color: var(--accent); flex-shrink: 0; display: flex; align-items: center; }
.sidebar-brand .brand-text {
  font-size: 17px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  letter-spacing: -.02em;
  opacity: 1;
  transition: opacity .2s ease;
}
#sidebar.collapsed .brand-text { opacity: 0; pointer-events: none; width: 0; overflow: hidden; }
#sidebar.collapsed .brand-icon { display: none; }
#sidebar.collapsed .sidebar-brand { justify-content: center; padding: 16px 8px; gap: 0; }
#sidebar.collapsed .sidebar-toggle { margin: 0 auto; }

/* Sidebar navigation */
#sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: all .2s ease;
  position: relative;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.nav-item:hover { color: var(--text-primary); background: var(--bg-hover); }
.nav-item.active {
  color: var(--accent);
  background: var(--accent-dim);
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}
.nav-item .nav-icon { width: 20px; height: 20px; flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.nav-item .nav-label { opacity: 1; transition: opacity .2s ease; }
#sidebar.collapsed .nav-label { opacity: 0; pointer-events: none; width: 0; overflow: hidden; }
#sidebar.collapsed .nav-item { justify-content: center; padding: 10px; gap: 0; }
#sidebar.collapsed .nav-item.active::before { left: 0; }

/* Sidebar footer */
.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* Sidebar footer collapsed */
#sidebar.collapsed .sidebar-footer .nav-item { justify-content: center; padding: 10px; gap: 0; }
#sidebar.collapsed .sidebar-footer .nav-label { opacity: 0; pointer-events: none; width: 0; overflow: hidden; }

/* Sidebar toggle button */
.sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all .2s ease;
  flex-shrink: 0;
}
.sidebar-toggle:hover { color: var(--text-primary); border-color: var(--border-hover); background: var(--bg-hover); }

/* --- Main area --- */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
}

/* --- Topbar --- */
#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  height: var(--topbar-height);
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
/* Mobile hamburger in topbar */
.mobile-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
}
.mobile-menu-btn:hover { color: var(--text-primary); border-color: var(--border-hover); }

/* Search bar — command palette style */
#search-global {
  margin-left: auto;
  padding: 8px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-primary);
  font-size: 13px;
  width: 280px;
  outline: none;
  transition: all .2s ease;
}
#search-global:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); width: 340px; }
#search-global::placeholder { color: var(--text-muted); }

/* Topbar action buttons */
.topbar-actions { display: flex; align-items: center; gap: 6px; }

/* --- Content area --- */
#content { flex: 1; overflow-y: auto; padding: 24px; }

/* ===== Cards ===== */
.card {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  transition: all .2s ease;
}
.card:hover { border-color: var(--border-hover); }
.card h3 {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 16px;
  font-weight: 600;
  letter-spacing: .01em;
}

/* ===== Stat Cards — Hero treatment ===== */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat-card {
  text-align: center;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  transition: all .25s cubic-bezier(.4,0,.2,1);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.stat-card .stat-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}
.stat-card .value {
  font-size: 36px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0,0,0,.15);
}
.stat-card .label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 8px;
  font-weight: 500;
  letter-spacing: .02em;
}

/* Stat card gradient variants */
.stat-card--memories { background: linear-gradient(135deg, rgba(255,152,48,.12) 0%, rgba(255,152,48,.03) 100%); }
.stat-card--memories .stat-icon { background: rgba(255,152,48,.15); color: var(--accent); }
.stat-card--nodes { background: linear-gradient(135deg, rgba(59,130,246,.12) 0%, rgba(59,130,246,.03) 100%); }
.stat-card--nodes .stat-icon { background: rgba(59,130,246,.15); color: var(--info); }
.stat-card--edges { background: linear-gradient(135deg, rgba(168,85,247,.12) 0%, rgba(168,85,247,.03) 100%); }
.stat-card--edges .stat-icon { background: rgba(168,85,247,.15); color: #a855f7; }
.stat-card--health { background: linear-gradient(135deg, rgba(34,197,94,.12) 0%, rgba(34,197,94,.03) 100%); }
.stat-card--health .stat-icon { background: rgba(34,197,94,.15); color: var(--success); }

/* ===== Tables — Modern data grid ===== */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: auto; }
th {
  text-align: left;
  padding: 12px 14px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: .02em;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 2;
}
td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--text-primary);
}
tr:nth-child(even) td { background: rgba(255,255,255,.01); }
[data-theme="light"] tr:nth-child(even) td { background: rgba(0,0,0,.015); }
tr { transition: all .15s ease; }
tr:hover td {
  background: var(--row-hover);
  border-left-color: transparent;
}

/* ===== Badges ===== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .02em;
}
.type-fact { background: rgba(34,197,94,.12); color: var(--success); }
.type-preference { background: rgba(59,130,246,.12); color: var(--info); }
.type-decision { background: rgba(245,158,11,.12); color: var(--warning); }
.type-error { background: rgba(239,68,68,.12); color: var(--error); }
.type-todo { background: rgba(168,85,247,.12); color: #a855f7; }
.type-context { background: rgba(139,141,147,.12); color: var(--text-secondary); }
.type-workflow { background: rgba(59,130,246,.12); color: var(--info); }

/* Source tabs (Chrome-style) */
.source-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}
.source-tab {
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all .15s ease;
  border-radius: 6px 6px 0 0;
}
.source-tab:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.source-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: rgba(255,140,50,.06);
}

/* Source badges */
.source-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .03em;
  color: var(--src-color, var(--text-muted));
  background: color-mix(in srgb, var(--src-color, var(--text-muted)) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--src-color, var(--text-muted)) 20%, transparent);
}

/* Tier badges */
.tier-full { color: var(--success); }
.tier-standard { color: #a3e635; }
.tier-basic { color: var(--warning); }
.tier-readonly { color: var(--error); }

/* ===== Pills ===== */
.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 11px;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  margin: 2px 3px;
  border: 1px solid var(--border);
  transition: all .15s ease;
}

/* ===== Buttons ===== */
.btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all .2s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { background: var(--bg-hover); border-color: var(--border-hover); }
.btn-primary {
  background: linear-gradient(135deg, #ff9830 0%, #ff7a00 100%);
  border-color: transparent;
  color: #000;
  font-weight: 600;
}
.btn-primary:hover {
  background: linear-gradient(135deg, #ffad5c 0%, #ff9830 100%);
  border-color: transparent;
  box-shadow: 0 2px 8px rgba(255,152,48,.3);
}
.btn-danger { border-color: rgba(239,68,68,.3); color: var(--error); }
.btn-danger:hover { background: var(--error); border-color: var(--error); color: #fff; }
.btn-success { border-color: rgba(34,197,94,.3); color: var(--success); }
.btn-success:hover { background: var(--success); color: #000; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  font-size: 14px;
  opacity: .5;
  transition: all .2s ease;
  color: var(--text-primary);
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
}
.btn-icon:hover { opacity: 1; background: var(--bg-hover); }

/* ===== Progress bars ===== */
.bar-wrap { width: 64px; height: 6px; background: var(--bg-primary); border-radius: 3px; overflow: hidden; display: inline-block; vertical-align: middle; }
.bar-fill { height: 100%; border-radius: 3px; transition: width .3s ease; }
.bar-confidence .bar-fill { background: linear-gradient(90deg, var(--info), #60a5fa); }
.bar-priority .bar-fill { background: linear-gradient(90deg, var(--accent), #ffb040); }

/* ===== Modals ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--modal-overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modal-bg-in .2s ease;
}
@keyframes modal-bg-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  min-width: 440px;
  max-width: 620px;
  max-height: 82vh;
  overflow-y: auto;
  padding-bottom: 20px;
  box-shadow: var(--shadow-lg);
  animation: modal-slide-up .25s cubic-bezier(.4,0,.2,1);
}
@keyframes modal-slide-up {
  from { opacity: 0; transform: translateY(16px) scale(.98); }
  to { opacity: 1; transform: none; }
}
.modal h2 {
  font-size: 17px;
  color: var(--text-primary);
  font-weight: 600;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  margin: 0;
  position: relative;
}
.modal h2::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 24px;
  right: 24px;
  height: 1px;
  background: linear-gradient(90deg, var(--accent), transparent);
}
.modal .modal-body, .modal .memory-detail, .modal .form-group:first-of-type { padding-top: 0; }
.modal > *:not(h2):not(.modal-actions) { padding-left: 24px; padding-right: 24px; }
.modal > .form-group:first-of-type { margin-top: 20px; }
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  margin-top: 12px;
}

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 600;
  letter-spacing: .02em;
}
input, select, textarea {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 9px 12px;
  font-size: 13px;
  font-family: var(--font);
  width: 100%;
  outline: none;
  transition: all .2s ease;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
textarea { resize: vertical; min-height: 80px; font-family: var(--mono); }
select {
  cursor: pointer;
  padding-right: 28px !important;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23999'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

/* ===== Pagination ===== */
.pagination { display: flex; align-items: center; gap: 8px; margin-top: 16px; justify-content: center; }
.pagination .page-info { color: var(--text-secondary); font-size: 13px; }

/* ===== Toast ===== */
#toast-container { position: fixed; top: 16px; right: 16px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  animation: toast-in .3s cubic-bezier(.4,0,.2,1);
  min-width: 260px;
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  box-shadow: var(--shadow);
}
.toast-success { background: var(--toast-success-bg); color: var(--success); border: 1px solid var(--toast-success-border); }
.toast-error { background: var(--toast-error-bg); color: var(--error); border: 1px solid var(--toast-error-border); }
.toast-info { background: var(--toast-info-bg); color: var(--info); border: 1px solid var(--toast-info-border); }
@keyframes toast-in { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: none; } }

/* ===== Spinner ===== */
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .6s linear infinite; }
.btn .spinner, .btn-primary .spinner { border-color: rgba(255,255,255,.3); border-top-color: #fff; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 48px; color: var(--text-secondary); }

/* ===== Tab content visibility ===== */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ===== Graph container ===== */
#graph-vis { width: 100%; height: calc(100vh - 200px); min-height: 400px; }
.graph-toolbar { display: flex; gap: 8px; margin-bottom: 12px; align-items: center; }

/* ===== Think tab ===== */
.think-layout { display: grid; grid-template-columns: 1fr 280px; gap: 20px; }
.think-results { margin-top: 20px; }
.think-answer {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  color: var(--text-primary);
  font-size: 14px;
}
.query-history { max-height: 420px; overflow-y: auto; }
.query-item {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
  transition: all .15s ease;
  border-radius: var(--radius-sm);
  margin-bottom: 2px;
}
.query-item:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  #sidebar { position: fixed; left: -260px; transition: left .25s cubic-bezier(.4,0,.2,1), width .25s cubic-bezier(.4,0,.2,1); width: var(--sidebar-width) !important; z-index: 200; }
  #sidebar.mobile-open { left: 0; }
  .mobile-menu-btn { display: flex; }
  .mobile-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 150; display: none; }
  .mobile-overlay.active { display: block; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .think-layout { grid-template-columns: 1fr; }
  #search-global { width: 160px; }
  #search-global:focus { width: 200px; }
  .modal { min-width: unset; width: 92vw; }
  #content { padding: 16px; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  #search-global { width: 120px; }
}

/* ===== Checkbox ===== */
.checkbox-row { display: flex; align-items: center; gap: 8px; }
input[type="checkbox"] { width: auto; accent-color: var(--accent); }

/* ===== JSON viewer ===== */
.json-view {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
  color: var(--text-primary);
}

/* ===== Truncated text ===== */
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; display: inline-block; }
.truncate-wide { max-width: 350px; }
.truncate-multiline { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; max-width: 420px; white-space: pre-wrap; word-break: break-word; }

/* ===== Memory detail ===== */
.memory-detail { padding: 20px 24px; }
.memory-detail .field { margin-bottom: 14px; }
.memory-detail .field-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; font-weight: 600; letter-spacing: .04em; }
.memory-detail .field-value { margin-top: 4px; color: var(--text-primary); }

/* ===== Bulk select ===== */
.bulk-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}

/* ===== Entities overflow ===== */
.entities-list { display: flex; flex-wrap: wrap; gap: 4px; }
.entities-list.collapsed { max-height: 28px; overflow: hidden; }
.entities-toggle { color: var(--accent); cursor: pointer; font-size: 12px; margin-top: 4px; }
.entities-toggle:hover { text-decoration: underline; }

/* ===== Login Page ===== */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-canvas);
}
.login-card {
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.login-logo { margin-bottom: 12px; color: var(--accent); }
.login-logo svg { width: 48px; height: 48px; }
.login-card h2 { margin-bottom: 6px; color: var(--text-primary); font-size: 22px; }
.login-subtitle { color: var(--text-secondary); font-size: 14px; margin-bottom: 28px; }
.login-card .form-group { text-align: left; margin-bottom: 20px; }
.login-card input { padding: 11px 14px; font-size: 14px; }
.btn-block { width: 100%; padding: 11px; font-size: 14px; justify-content: center; }
.login-hint { margin-top: 20px; font-size: 12px; color: var(--text-muted); }

/* ===== Topbar buttons ===== */
.btn-theme, .btn-logout {
  padding: 8px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all .2s ease;
}
.btn-theme:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-dim); }
.btn-theme svg, .btn-logout svg { width: 18px; height: 18px; }
.btn-logout:hover { color: var(--error); border-color: rgba(239,68,68,.3); background: rgba(239,68,68,.08); }

/* ===== Spinner animation for loader icon ===== */
.spinner-icon { animation: spin 1s linear infinite; }

/* ===== Table info & load more ===== */
.table-info { font-size: 12px; color: var(--text-secondary); margin-bottom: 10px; }
#dash-load-more { text-align: center; padding: 16px; }
.text-muted { color: var(--text-muted); }
.text-error { color: var(--error); }

/* ===== Graph legend ===== */
.graph-legend { margin-top: 16px; }
.graph-legend h4 { font-size: 12px; color: var(--text-secondary); margin-bottom: 10px; letter-spacing: 0.02em; font-weight: 600; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 12px; margin-bottom: 6px; color: var(--text-primary); }
.legend-item svg { flex-shrink: 0; }

/* ===== Section spacing for dashboard ===== */
.dash-actions { display: flex; gap: 12px; margin-bottom: 20px; }

/* ===== Markdown body ===== */
.markdown-body { line-height: 1.45; word-break: break-word; }
.markdown-body > :first-child { margin-top: 0; }
.markdown-body > :last-child { margin-bottom: 0; }
.markdown-body h1, .markdown-body h2, .markdown-body h3, .markdown-body h4 {
  margin: .6em 0 .2em; font-weight: 600; color: var(--text-primary);
}
.markdown-body h1 { font-size: 1.4em; } .markdown-body h2 { font-size: 1.2em; } .markdown-body h3 { font-size: 1.05em; }
.markdown-body p { margin: .15em 0; }
.markdown-body ul, .markdown-body ol { padding-left: 1.5em; margin: .15em 0; }
.markdown-body li { margin: .05em 0; }
.markdown-body li > p { margin: 0; }
.markdown-body p:empty { display: none; }
.markdown-body p + p { margin-top: .25em; }
.markdown-body code {
  background: var(--bg-secondary); padding: 2px 6px; border-radius: 4px;
  font-family: var(--mono); font-size: .9em;
}
.markdown-body pre {
  background: var(--bg-secondary); padding: 12px 16px; border-radius: var(--radius-sm);
  overflow-x: auto; margin: .75em 0;
}
.markdown-body pre code { background: none; padding: 0; }
.markdown-body blockquote {
  border-left: 3px solid var(--accent); padding-left: 12px; margin: .75em 0;
  color: var(--text-secondary); font-style: italic;
}
.markdown-body strong { color: var(--text-primary); font-weight: 600; }
.markdown-body a { color: var(--accent); text-decoration: none; }
.markdown-body a:hover { text-decoration: underline; }
.markdown-body hr { border: none; border-top: 1px solid var(--border); margin: 1em 0; }
.markdown-body table { border-collapse: collapse; width: 100%; margin: .75em 0; }
.markdown-body th, .markdown-body td {
  border: 1px solid var(--border); padding: 6px 10px; text-align: left;
}
.markdown-body th { background: var(--bg-secondary); font-weight: 600; }

/* ===== Scrollbar styling ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.2); }
[data-theme="light"] ::-webkit-scrollbar-thumb { background: rgba(0,0,0,.12); }
[data-theme="light"] ::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,.2); }

/* ===== Settings Tab ===== */

/* Card spacing */
.settings-card { margin-bottom: 16px; }

/* Card header with actions */
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.card-header h3 { margin-bottom: 0; }
.card-header-actions { display: flex; gap: 8px; align-items: center; }

/* Model selector layout */
.model-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: end;
}
.model-selector .form-group { margin-bottom: 0; }
.model-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.model-test-result { font-size: 12px; }

/* Config status banner */
.cfg-status {
  display: none;
  margin-bottom: 12px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.5;
  border: 1px solid transparent;
}
.cfg-status--success {
  background: var(--toast-success-bg);
  border-color: var(--toast-success-border);
  color: var(--success);
}
.cfg-status--warning {
  background: rgba(245,158,11,.1);
  border-color: rgba(245,158,11,.25);
  color: var(--warning);
}
.cfg-status--error {
  background: var(--toast-error-bg);
  border-color: var(--toast-error-border);
  color: var(--error);
}

/* Config groups grid */
.config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 16px;
}

/* Individual config group card */
.config-group {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  transition: border-color .2s ease;
}
.config-group:hover { border-color: var(--border-hover); }
.config-group-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: .03em;
  text-transform: uppercase;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* Config field rows */
.config-fields { display: flex; flex-direction: column; gap: 10px; }
.config-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.config-field-label {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  min-width: 160px;
  width: 160px;
  flex-shrink: 0;
}
.config-field-input { flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; }
.config-field-input select,
.config-field-input input[type="text"],
.config-field-input input[type="number"] {
  width: 100%;
  padding: 6px 10px;
  font-size: 12px;
}
.config-field-input input[type="number"] { max-width: none; }

/* Config subsection divider (when a tab has multiple config sections) */
.config-subsection-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.config-subsection-label:first-child { margin-top: 0; padding-top: 0; border-top: none; }

/* Info hint badge */
.hint-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  font-size: 9px;
  font-weight: 700;
  font-style: italic;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 50%;
  margin-left: 4px;
  cursor: help;
  vertical-align: middle;
  flex-shrink: 0;
  transition: color 0.15s, border-color 0.15s;
}
.hint-badge:hover {
  color: var(--primary);
  border-color: var(--primary);
}

/* Restart required badge */
.badge-restart {
  display: inline-block;
  background: rgba(245,158,11,.15);
  color: var(--warning);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .02em;
  border: 1px solid rgba(245,158,11,.2);
  margin-left: 8px;
}

/* No-key warning */
.model-warning {
  font-size: 11px;
  color: var(--warning);
  margin-top: 4px;
}

/* Danger zone */
.danger-card { border-color: rgba(239,68,68,.2); }
.danger-card:hover { border-color: rgba(239,68,68,.35); }
.danger-card h3 { color: var(--error); }
.danger-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Inline restart button inside status banner */
.btn-restart-inline {
  margin-left: 8px;
  padding: 4px 12px;
  background: var(--warning);
  color: #000;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: all .2s ease;
}
.btn-restart-inline:hover { background: var(--accent-hover); }

/* Scheduler section empty state */
.empty-state {
  color: var(--text-muted);
  font-size: 13px;
  padding: 8px 0;
}

/* Settings responsive */
@media (max-width: 768px) {
  .model-selector { grid-template-columns: 1fr; }
  .config-grid { grid-template-columns: 1fr; }
  .config-field { flex-direction: column; align-items: flex-start; gap: 4px; }
  .config-field-input { width: 100%; }
  .config-field-input input[type="number"] { max-width: 100%; }
}
