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

:root {
  --primary: #0ea5e9;
  --primary-dark: #0284c7;
  --primary-light: #e0f2fe;
  --accent: #3b82f6;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --bg: #f0f9ff;
  --surface: #ffffff;
  --border: #e0f2fe;
  --border-soft: #f1f5f9;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --shadow-sm: 0 1px 3px rgba(14,165,233,0.07), 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 4px 12px rgba(14,165,233,0.1), 0 1px 3px rgba(0,0,0,0.06);
  --shadow-lg: 0 12px 32px rgba(14,165,233,0.15), 0 4px 8px rgba(0,0,0,0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --header-h: 60px;
  --chat-w: 380px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

/* ===== USER CHIP & AVATAR ===== */
.user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: #6366f1;
  color: white;
  font-size: 0.72rem;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  border: 2px solid rgba(255,255,255,0.25);
  font-family: var(--font);
  transition: box-shadow 0.15s, transform 0.1s;
  flex-shrink: 0;
}
.user-avatar:hover { box-shadow: 0 0 0 3px rgba(99,102,241,0.25); transform: scale(1.04); }

.user-chip { display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; color: white; font-weight: 700; font-family: var(--font); flex-shrink: 0; }
.user-chip--xs { width: 22px; height: 22px; font-size: 0.6rem; }
.user-chip--sm { width: 32px; height: 32px; font-size: 0.72rem; }
.user-chip--md { width: 40px; height: 40px; font-size: 0.85rem; }
.user-chip--lg { width: 48px; height: 48px; font-size: 1rem; }

/* Role badges */
.role-badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 10px; font-size: 0.68rem; font-weight: 700; white-space: nowrap; }
.role-badge--admin { background: #ede9fe; color: #5b21b6; }
.role-badge--user  { background: #f1f5f9; color: #475569; }
[data-theme="dark"] .role-badge--admin { background: rgba(139,92,246,0.2); color: #a78bfa; }
[data-theme="dark"] .role-badge--user  { background: rgba(100,116,139,0.2); color: #94a3b8; }

/* ===== USER PANEL ===== */
.user-panel-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,0.45);
  backdrop-filter: blur(2px);
  z-index: 500;
  display: flex; justify-content: flex-end;
  animation: fadeIn 0.15s ease;
}
.user-panel-overlay.hidden { display: none; }
.user-panel {
  width: 380px; max-width: 100vw;
  background: var(--surface);
  display: flex; flex-direction: column;
  box-shadow: -8px 0 32px rgba(0,0,0,0.15);
  animation: slideInRight 0.22s cubic-bezier(.22,.68,0,1.1);
}
.user-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.user-panel-title { font-size: 1rem; font-weight: 700; color: var(--text-primary); }
.user-panel-close {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border: none; background: transparent;
  color: var(--text-muted); border-radius: 8px; cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.user-panel-close:hover { background: var(--bg); color: var(--text-primary); }
.user-panel-body { flex: 1; overflow-y: auto; padding-bottom: 20px; }

.up-section { padding: 16px 20px 0; }
.up-section + .up-section { border-top: 1px solid var(--border-soft); margin-top: 12px; padding-top: 16px; }
.up-label { font-size: 0.67rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 10px; }

/* Current session row */
.up-current {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg); border-radius: 10px; padding: 10px 12px;
  border: 1px solid var(--border);
}
.up-current-info { flex: 1; min-width: 0; }
.up-current-name { font-size: 0.85rem; font-weight: 700; color: var(--text-primary); }
.up-switch-btn {
  padding: 5px 12px; border: 1.5px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text-secondary);
  font-size: 0.72rem; font-weight: 600; font-family: var(--font);
  cursor: pointer; white-space: nowrap; flex-shrink: 0;
  transition: all 0.12s;
}
.up-switch-btn:hover { border-color: var(--primary); color: var(--primary-dark); }

/* User list rows */
.up-user-list { display: flex; flex-direction: column; gap: 2px; }
.up-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 8px;
  transition: background 0.1s;
}
.up-row:hover { background: var(--bg); }
.up-row-info { flex: 1; min-width: 0; }
.up-row-name { font-size: 0.82rem; font-weight: 600; color: var(--text-primary); }
.up-row-email { font-size: 0.7rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.up-you { font-size: 0.65rem; font-weight: 600; color: var(--text-muted); margin-left: 4px; }

.up-role-sel {
  padding: 4px 6px; border: 1.5px solid var(--border); border-radius: 7px;
  font-size: 0.72rem; font-weight: 600; font-family: var(--font);
  background: var(--surface); color: var(--text-primary); cursor: pointer;
  flex-shrink: 0; transition: border-color 0.12s;
}
.up-role-sel:disabled { opacity: 0.5; cursor: not-allowed; }
.up-role-sel:focus { outline: none; border-color: var(--primary); }

.up-manage-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 9px; border: 1.5px solid var(--border); border-radius: 7px;
  background: var(--surface); color: var(--text-secondary);
  font-size: 0.7rem; font-weight: 600; font-family: var(--font);
  cursor: pointer; white-space: nowrap; flex-shrink: 0;
  transition: all 0.12s;
}
.up-manage-btn:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary-dark); }

.icon-btn {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--border); border-radius: 7px;
  background: transparent; color: var(--text-muted);
  cursor: pointer; flex-shrink: 0; transition: all 0.12s;
}
.up-del-btn:hover { background: #fee2e2; border-color: #fca5a5; color: #dc2626; }
[data-theme="dark"] .up-del-btn:hover { background: rgba(239,68,68,0.15); border-color: rgba(239,68,68,0.3); color: #f87171; }

/* Session meta + logout */
.up-session-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 8px;
}
.up-logout-btn {
  display: flex; align-items: center; gap: 7px;
  width: 100%; padding: 9px 12px;
  border: 1.5px solid var(--border); border-radius: 8px;
  background: transparent; color: var(--text-secondary);
  font-size: 0.82rem; font-weight: 600; font-family: var(--font);
  cursor: pointer; transition: all 0.12s;
}
.up-logout-btn:hover {
  border-color: #fca5a5; color: #dc2626; background: #fee2e2;
}
[data-theme="dark"] .up-logout-btn:hover {
  border-color: rgba(239,68,68,0.3); color: #f87171; background: rgba(239,68,68,0.12);
}

/* Add user form */
.up-add-user-btn {
  display: flex; align-items: center; gap: 6px;
  width: 100%; padding: 9px 12px;
  border: 1.5px dashed var(--border); border-radius: 8px;
  background: transparent; color: var(--text-muted);
  font-size: 0.8rem; font-weight: 600; font-family: var(--font);
  cursor: pointer; transition: all 0.12s; margin-top: 4px;
}
.up-add-user-btn:hover { border-color: var(--primary); color: var(--primary-dark); background: var(--primary-light); }
.up-add-form { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.up-add-input {
  padding: 7px 10px; border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 0.82rem; font-family: var(--font);
  background: var(--bg); color: var(--text-primary); outline: none;
  transition: border-color 0.15s;
}
.up-add-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14,165,233,0.1); }
.up-add-actions { display: flex; gap: 6px; }
.up-save-btn { padding: 6px 16px; font-size: 0.78rem; }
.up-cancel-btn { padding: 6px 12px; font-size: 0.78rem; }

/* User switch dropdown */
.up-switch-dd {
  position: relative; margin-top: 8px;
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow-lg);
  padding: 4px; overflow: hidden;
}
.up-switch-opt {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 7px 10px; border-radius: 7px;
  border: none; background: transparent; cursor: pointer;
  font-family: var(--font); transition: background 0.1s;
}
.up-switch-opt:hover { background: var(--bg); }
.up-switch-opt.active { background: var(--primary-light); }
.up-switch-name { flex: 1; font-size: 0.82rem; font-weight: 600; color: var(--text-primary); text-align: left; }

/* ===== IMPERSONATION BANNER ===== */
.impersonate-banner { background: #f59e0b; border-bottom: 1px solid #d97706; padding: 0 20px; }
.impersonate-banner.hidden { display: none; }
[data-theme="dark"] .impersonate-banner { background: rgba(245,158,11,0.18); border-bottom-color: rgba(245,158,11,0.4); }
.imp-banner-inner { display: flex; align-items: center; gap: 8px; height: 38px; }
.imp-banner-text { flex: 1; font-size: 0.78rem; color: #451a03; font-weight: 500; }
[data-theme="dark"] .imp-banner-text { color: #fcd34d; }
.imp-banner-exit {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 7px;
  border: 1px solid rgba(0,0,0,0.2); background: rgba(0,0,0,0.1);
  color: #451a03; font-size: 0.73rem; font-weight: 600;
  font-family: var(--font); cursor: pointer; transition: all 0.12s;
}
.imp-banner-exit:hover { background: rgba(0,0,0,0.2); }
[data-theme="dark"] .imp-banner-exit { background: rgba(245,158,11,0.15); border-color: rgba(245,158,11,0.4); color: #fcd34d; }
[data-theme="dark"] .imp-banner-exit:hover { background: rgba(245,158,11,0.25); }

/* ===== VIEWING-AS BANNER ===== */
.viewing-as-banner {
  background: linear-gradient(135deg, #ede9fe, #dbeafe);
  border-bottom: 1px solid #c4b5fd;
  padding: 0 20px;
}
.viewing-as-banner.hidden { display: none; }
[data-theme="dark"] .viewing-as-banner {
  background: rgba(139,92,246,0.12);
  border-bottom-color: rgba(139,92,246,0.3);
}
.vab-inner {
  display: flex; align-items: center; gap: 8px;
  height: 38px;
}
.vab-text { flex: 1; font-size: 0.78rem; color: #4c1d95; }
[data-theme="dark"] .vab-text { color: #c4b5fd; }
.vab-exit {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 7px;
  border: 1.5px solid #c4b5fd; background: rgba(255,255,255,0.6);
  color: #5b21b6; font-size: 0.72rem; font-weight: 700;
  font-family: var(--font); cursor: pointer; transition: all 0.12s;
}
.vab-exit:hover { background: white; }
[data-theme="dark"] .vab-exit { background: rgba(139,92,246,0.15); border-color: rgba(139,92,246,0.4); color: #a78bfa; }
[data-theme="dark"] .vab-exit:hover { background: rgba(139,92,246,0.25); }

/* ===== VIEWS DROPDOWN BAR ===== */
.views-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: 42px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.vdb-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
}
.vdb-selector-wrap {
  position: relative;
}
.vdb-selector {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  background: var(--bg);
  color: var(--text-primary);
  font-size: 0.82rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.12s;
  white-space: nowrap;
}
.vdb-selector:hover {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary-dark);
}
.vdb-selector svg:first-child { color: var(--text-muted); flex-shrink: 0; }
.vdb-name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.vdb-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: 0.68rem;
  font-weight: 700;
}
.vdb-chevron { color: var(--text-muted); flex-shrink: 0; transition: transform 0.15s; }
.vdb-selector:has(+ .vdb-dropdown:not(.hidden)) .vdb-chevron { transform: rotate(180deg); }

.vdb-dropdown {
  position: absolute;
  top: calc(100% + 5px);
  left: 0;
  min-width: 220px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 4px;
  z-index: 300;
  animation: fadeIn 0.1s ease;
}
.vdb-dropdown.hidden { display: none; }
.vdb-opt {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 7px 10px;
  border: none;
  border-radius: 7px;
  background: transparent;
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.1s;
  gap: 8px;
}
.vdb-opt:hover { background: var(--bg); }
.vdb-opt.active { background: var(--primary-light); }
.vdb-opt-name {
  flex: 1;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
  text-align: left;
}
.vdb-opt-count {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--border-soft);
  padding: 1px 6px;
  border-radius: 8px;
}
.vdb-opt.active .vdb-opt-count { background: rgba(14,165,233,0.15); color: var(--primary-dark); }

.vdb-manage-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  padding: 4px 10px;
  border-radius: 7px;
  transition: all 0.12s;
  margin-left: auto;
}
.vdb-manage-link:hover {
  color: var(--primary-dark);
  background: var(--primary-light);
}

/* ===== VIEWS BAR (legacy tab styles kept for reference) ===== */
.views-bar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  position: sticky;
  top: var(--header-h);
  z-index: 90;
}
.views-bar-inner {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 44px;
}
.view-tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
}
.view-tabs::-webkit-scrollbar { display: none; }

.view-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  border: 1.5px solid transparent;
  transition: background 0.12s, border-color 0.12s;
  position: relative;
  user-select: none;
}
.view-tab:hover { background: var(--bg); border-color: var(--border); }
.view-tab.active {
  background: var(--primary-light);
  border-color: var(--primary);
}
.view-tab-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  outline: none;
  min-width: 4px;
}
.view-tab.active .view-tab-name { color: var(--primary-dark); }
.view-tab-name.editing {
  border-bottom: 1.5px solid var(--primary);
  color: var(--text-primary);
  min-width: 60px;
}
.view-tab-count {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1px 6px;
  line-height: 1.4;
}
.view-tab.active .view-tab-count {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.view-tab-menu-btn {
  opacity: 0;
  width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center;
  border: none; background: transparent;
  color: var(--text-muted); border-radius: 5px; cursor: pointer;
  transition: opacity 0.1s, background 0.1s, color 0.1s;
  flex-shrink: 0;
}
.view-tab:hover .view-tab-menu-btn,
.view-tab.active .view-tab-menu-btn { opacity: 1; }
.view-tab-menu-btn:hover { background: var(--border); color: var(--text-primary); }

.view-add-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.12s;
}
.view-add-btn:hover {
  border-color: var(--primary);
  color: var(--primary-dark);
  background: var(--primary-light);
}

/* Views dropdown menu */
.view-dropdown {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 4px;
  min-width: 160px;
  animation: fadeIn 0.1s ease;
}
.view-dd-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 500;
  font-family: var(--font);
  border-radius: 7px;
  cursor: pointer;
  text-align: left;
  transition: background 0.1s, color 0.1s;
}
.view-dd-item:hover { background: var(--bg); color: var(--text-primary); }
.view-dd-item--danger { color: #ef4444; }
.view-dd-item--danger:hover { background: #fee2e2; color: #dc2626; }
.view-dd-item--danger:disabled,
.view-dd-item--danger[disabled] { opacity: 0.4; cursor: not-allowed; pointer-events: none; }
.view-dd-sep { height: 1px; background: var(--border); margin: 3px 4px; }

/* New view creation form (popup) */
.view-new-form {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  padding: 8px 10px;
  animation: fadeIn 0.12s ease;
}
.view-new-input {
  padding: 6px 10px;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  font-size: 0.82rem;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  width: 180px;
  outline: none;
  transition: border-color 0.15s;
}
.view-new-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14,165,233,0.1); }
.view-new-create {
  padding: 6px 14px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 7px;
  font-size: 0.78rem;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.12s;
  white-space: nowrap;
}
.view-new-create:hover { background: var(--primary-dark); }
.view-new-cancel {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  border-radius: 7px; cursor: pointer;
  transition: all 0.12s;
}
.view-new-cancel:hover { background: #fee2e2; border-color: #fca5a5; color: #dc2626; }

/* Dark mode overrides */
[data-theme="dark"] .view-dd-item--danger:hover { background: rgba(239,68,68,0.15); color: #f87171; }
[data-theme="dark"] .view-new-cancel:hover { background: rgba(239,68,68,0.15); border-color: rgba(239,68,68,0.3); color: #f87171; }

/* ===== DONE MODAL ===== */
.done-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,0.55);
  backdrop-filter: blur(3px);
  z-index: 600;
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 0.12s ease;
}
.done-overlay.hidden { display: none; }
.done-modal {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  width: 480px; max-width: calc(100vw - 32px);
  display: flex; flex-direction: column;
  animation: scaleIn 0.18s cubic-bezier(.22,.68,0,1.1);
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.94); }
  to   { opacity: 1; transform: scale(1); }
}
.done-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.done-modal-title { font-size: 1rem; font-weight: 700; color: var(--text-primary); }
.done-close {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border: none; background: transparent;
  color: var(--text-muted); border-radius: 8px; cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.done-close:hover { background: var(--bg); color: var(--text-primary); }
.done-alert-preview { padding: 14px 20px 0; }
.done-alert-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 12px; border-radius: 8px;
  border: 1.5px solid transparent;
  font-size: 0.8rem; width: 100%;
}
.done-alert-pill.done-sev--critical { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.done-alert-pill.done-sev--warning  { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.done-alert-pill.done-sev--info     { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
[data-theme="dark"] .done-alert-pill.done-sev--critical { background: rgba(239,68,68,0.1);  border-color: rgba(239,68,68,0.25);  color: #fca5a5; }
[data-theme="dark"] .done-alert-pill.done-sev--warning  { background: rgba(245,158,11,0.1); border-color: rgba(245,158,11,0.25); color: #fcd34d; }
[data-theme="dark"] .done-alert-pill.done-sev--info     { background: rgba(59,130,246,0.1); border-color: rgba(59,130,246,0.25); color: #93c5fd; }
.done-sev-dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.done-sev-label { font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; flex-shrink: 0; }
.done-alert-title-text { flex: 1; font-weight: 500; }
.done-modal-body { padding: 14px 20px 0; display: flex; flex-direction: column; gap: 6px; }
.done-field-label { font-size: 0.78rem; font-weight: 700; color: var(--text-secondary); }
.done-textarea {
  width: 100%; padding: 10px 12px;
  border: 1.5px solid var(--border); border-radius: 10px;
  font-size: 0.85rem; font-family: var(--font); line-height: 1.5;
  background: var(--bg); color: var(--text-primary);
  resize: vertical; min-height: 90px; outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.done-textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14,165,233,0.1); }
.done-char-hint { font-size: 0.7rem; color: var(--text-muted); }
.done-char-hint.ok { color: #10b981; }
.done-modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 16px 20px 18px;
  border-top: 1px solid var(--border); margin-top: 14px;
}
.done-modal-footer .btn { display: inline-flex; align-items: center; gap: 6px; }
.done-modal-footer .btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ===== ACTION LOG PANEL ===== */
.alog-badge {
  position: absolute; top: 4px; right: 4px;
  background: #ef4444; color: white;
  font-size: 0.6rem; font-weight: 700;
  min-width: 15px; height: 15px;
  border-radius: 8px; padding: 0 3px;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.alog-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,0.4);
  backdrop-filter: blur(2px);
  z-index: 500;
  display: flex; justify-content: flex-end;
  animation: fadeIn 0.15s ease;
}
.alog-overlay.hidden { display: none; }
.alog-panel {
  width: 440px; max-width: 100vw;
  background: var(--surface);
  display: flex; flex-direction: column;
  box-shadow: -8px 0 32px rgba(0,0,0,0.15);
  animation: slideInRight 0.22s cubic-bezier(.22,.68,0,1.1);
}
.alog-panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.alog-panel-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 1rem; font-weight: 700; color: var(--text-primary);
}
.alog-close {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border: none; background: transparent;
  color: var(--text-muted); border-radius: 8px; cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.alog-close:hover { background: var(--bg); color: var(--text-primary); }
.alog-tabs {
  display: flex; gap: 4px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.alog-tab {
  padding: 5px 14px; border-radius: 8px;
  border: 1.5px solid transparent;
  background: transparent; color: var(--text-muted);
  font-size: 0.78rem; font-weight: 600; font-family: var(--font);
  cursor: pointer; transition: all 0.12s;
}
.alog-tab:hover { color: var(--text-secondary); background: var(--bg); }
.alog-tab.active { background: var(--primary-light); border-color: rgba(14,165,233,0.25); color: var(--primary-dark); }
.alog-body { flex: 1; overflow-y: auto; padding: 8px 0 20px; }
.alog-empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 200px; color: var(--text-muted); font-size: 0.82rem; text-align: center;
  padding: 32px;
}
.alog-date-group { padding: 0 20px; }
.alog-date-label {
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.5px; color: var(--text-muted);
  padding: 12px 0 6px;
  position: sticky; top: 0; background: var(--surface);
  z-index: 1;
}
.alog-entry {
  display: flex; gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-soft);
}
.alog-entry:last-child { border-bottom: none; }
.alog-entry-avatar { flex-shrink: 0; padding-top: 2px; }
.alog-entry-body { flex: 1; min-width: 0; }
.alog-entry-top {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  margin-bottom: 4px;
}
.alog-entry-who { font-size: 0.82rem; font-weight: 700; color: var(--text-primary); }
.alog-action-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 10px;
  font-size: 0.68rem; font-weight: 700;
}
.alog-action--completed { background: #d1fae5; color: #065f46; }
.alog-action--snoozed   { background: #fef3c7; color: #92400e; }
[data-theme="dark"] .alog-action--completed { background: rgba(16,185,129,0.15); color: #6ee7b7; }
[data-theme="dark"] .alog-action--snoozed   { background: rgba(245,158,11,0.15); color: #fcd34d; }
.alog-entry-time { font-size: 0.7rem; color: var(--text-muted); margin-left: auto; white-space: nowrap; }
.alog-alert-ref {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.78rem; color: var(--text-secondary);
  margin-bottom: 4px;
}
.alog-sev-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.alog-sev--critical { color: #dc2626; }
.alog-sev--warning  { color: #d97706; }
.alog-sev--info     { color: #2563eb; }
[data-theme="dark"] .alog-sev--critical { color: #f87171; }
[data-theme="dark"] .alog-sev--warning  { color: #fbbf24; }
[data-theme="dark"] .alog-sev--info     { color: #93c5fd; }
.alog-explanation {
  margin: 4px 0 0;
  padding: 6px 10px;
  border-left: 3px solid var(--border);
  font-size: 0.78rem; color: var(--text-secondary);
  font-style: italic; line-height: 1.45;
  border-radius: 0 6px 6px 0;
  background: var(--bg);
}

/* ===== DARK MODE ===== */
[data-theme="dark"] .header {
  background: rgba(30,41,59,0.95);
}

[data-theme="dark"] {
  --bg:            #0f172a;
  --surface:       #1e293b;
  --border:        #334155;
  --border-soft:   #243147;
  --text-primary:  #f1f5f9;
  --text-secondary:#94a3b8;
  --text-muted:    #64748b;
  --primary-light: rgba(56,189,248,0.12);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.5);
  --shadow:    0 4px 12px rgba(0,0,0,0.55), 0 1px 3px rgba(0,0,0,0.4);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.65), 0 4px 8px rgba(0,0,0,0.45);
}

/* Trend badges */
[data-theme="dark"] .kpi-trend.up      { background: rgba(16,185,129,0.15); color: #34d399; }
[data-theme="dark"] .kpi-trend.down    { background: rgba(239,68,68,0.15);  color: #f87171; }
[data-theme="dark"] .kpi-trend.neutral { background: rgba(100,116,139,0.2); color: #94a3b8; }

/* Alert cards */
[data-theme="dark"] .alert-card--critical { background: rgba(239,68,68,0.06); }
[data-theme="dark"] .alert-card--warning  { background: rgba(245,158,11,0.06); }
[data-theme="dark"] .alert-card--info     { background: rgba(59,130,246,0.06); }
[data-theme="dark"] .alert-card--critical .alert-icon { background: rgba(239,68,68,0.15);  color: #f87171; }
[data-theme="dark"] .alert-card--warning  .alert-icon { background: rgba(245,158,11,0.15); color: #fbbf24; }
[data-theme="dark"] .alert-card--info     .alert-icon { background: rgba(59,130,246,0.15); color: #60a5fa; }

/* Investigate status badges */
[data-theme="dark"] .inv-status--success { background: rgba(16,185,129,0.15);  color: #34d399; }
[data-theme="dark"] .inv-status--error   { background: rgba(239,68,68,0.15);   color: #f87171; }
[data-theme="dark"] .inv-status--warning { background: rgba(245,158,11,0.15);  color: #fbbf24; }
[data-theme="dark"] .inv-status--active  { background: rgba(59,130,246,0.15);  color: #60a5fa; }
[data-theme="dark"] .inv-status--info    { background: rgba(16,185,129,0.1);   color: #6ee7b7; }
[data-theme="dark"] .inv-status--neutral { background: rgba(100,116,139,0.15); color: #94a3b8; }

/* Investigate pct / rating cells */
[data-theme="dark"] .inv-cell-pct.up     { color: #34d399; }
[data-theme="dark"] .inv-cell-pct.down   { color: #f87171; }
[data-theme="dark"] .inv-cell-rating.high { color: #fbbf24; }
[data-theme="dark"] .inv-cell-rating.mid  { color: #64748b; }
[data-theme="dark"] .inv-cell-rating.low  { color: #f87171; }

/* Config panel badge */
[data-theme="dark"] .inv-cfg-badge--chart { background: rgba(245,158,11,0.15); color: #fbbf24; border-color: rgba(245,158,11,0.3); }

/* Chart grid lines (SVG) */
[data-theme="dark"] .chart-grid-line { stroke: #1e3a5f; }

/* Dark-mode toggle icon visibility */
.dark-icon { transition: opacity 0.2s, transform 0.2s; }
.dark-icon--moon { display: block; }
.dark-icon--sun  { display: none; }
[data-theme="dark"] .dark-icon--moon { display: none; }
[data-theme="dark"] .dark-icon--sun  { display: block; }

html { font-size: 15px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ===== HEADER ===== */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-h);
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
}

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

.brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 2px 8px rgba(14,165,233,0.35);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.brand-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.brand-sub {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.header-center {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
}

.company-select-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.select-icon {
  position: absolute;
  left: 10px;
  color: var(--text-muted);
  pointer-events: none;
}

.company-select {
  padding: 6px 12px 6px 30px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-primary);
  font-size: 0.875rem;
  font-weight: 500;
  font-family: var(--font);
  cursor: pointer;
  outline: none;
  min-width: 220px;
  transition: border-color 0.2s;
}

.company-select:focus { border-color: var(--primary); }

.user-impersonate-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.user-impersonate-select { min-width: 180px; }

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

.header-btn {
  position: relative;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.header-btn:hover { background: var(--primary-light); color: var(--primary-dark); }

.notif-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 16px;
  height: 16px;
  background: var(--danger);
  color: white;
  border-radius: 50%;
  font-size: 0.6rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid white;
}

.user-avatar {
  width: 34px;
  height: 34px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
}

/* ===== MAIN CONTENT ===== */
.main-content {
  flex: 1;
  padding: 24px 20px 40px;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
  transition: padding-right 0.3s ease;
}

.main-content.chat-open {
  padding-right: calc(var(--chat-w) + 24px);
}

/* ===== COLLAPSIBLE SECTION HEADERS ===== */
.collapsible-wrap {
  margin-bottom: 24px;
}

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

.collapsible-title {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-primary);
}

.collapsible-toggle {
  margin-left: auto;
  background: none;
  border: none;
  font-size: 0.75rem;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font);
  padding: 3px 8px;
  border-radius: 5px;
  transition: background 0.15s;
}

.collapsible-toggle:hover {
  background: var(--border-soft);
  color: var(--text-primary);
}

/* ===== KPI SECTION ===== */
.kpi-section {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 16px;
}

.kpi-section.collapsed { display: none; }

/* ===== KPI CARD ===== */
.kpi-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-soft);
  padding: 0;
  overflow: hidden;
  transition: box-shadow 0.2s, transform 0.2s;
  cursor: default;
  position: relative;
}

.kpi-card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.kpi-card-accent {
  height: 3px;
  width: 100%;
}

.kpi-card-body {
  padding: 14px 16px 0;
}

.kpi-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 8px;
}

.kpi-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.kpi-actions {
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}

.kpi-card:hover .kpi-actions { opacity: 1; }

.kpi-icon-btn {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 5px;
  cursor: pointer;
  padding: 0;
  transition: background 0.15s, color 0.15s;
}

.kpi-icon-btn:hover { background: var(--primary-light); color: var(--primary-dark); }

.kpi-value {
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
  line-height: 1.1;
  margin-bottom: 5px;
}

.kpi-trend {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 20px;
  margin-bottom: 10px;
}

.kpi-trend.up { background: #d1fae5; color: #065f46; }
.kpi-trend.down { background: #fee2e2; color: #991b1b; }
.kpi-trend.neutral { background: #f1f5f9; color: var(--text-secondary); }

.kpi-trend svg { flex-shrink: 0; }

.kpi-compare {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-left: 4px;
  font-weight: 400;
}

.kpi-sparkline {
  width: 100%;
  height: 52px;
  display: block;
}

.kpi-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px 12px;
  border-top: 1px solid var(--border-soft);
  margin-top: 2px;
}

.kpi-demo-badge {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--border-soft);
  border-radius: 4px;
  padding: 2px 6px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.kpi-live-badge {
  font-size: 0.65rem;
  font-weight: 600;
  color: #065f46;
  background: #d1fae5;
  border-radius: 4px;
  padding: 2px 6px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

@media (prefers-color-scheme: dark) {
  .kpi-live-badge { color: #6ee7b7; background: #064e3b; }
}
:root[data-theme="dark"] .kpi-live-badge { color: #6ee7b7; background: #064e3b; }
:root[data-theme="light"] .kpi-live-badge { color: #065f46; background: #d1fae5; }

.kpi-type-tag {
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--border-soft);
  border-radius: 4px;
  padding: 2px 5px;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

/* Wide chart cards (line / bar) */
.kpi-card--wide {
  grid-column: span 3;
}

/* Half-width bar-list cards */
.kpi-card--bar-list {
  grid-column: span 3;
}
.kpi-card-body--bar-list {
  padding-bottom: 6px;
}
.kpi-bar-list-svg {
  display: block;
  width: 100%;
  overflow: visible;
  margin-top: 8px;
}

/* Half-width multi-line cards */
.kpi-card--multi-line {
  grid-column: span 3;
}
.kpi-card-body--multi-line {
  padding-bottom: 4px;
}
.kpi-multi-line-svg {
  display: block;
  width: 100%;
  height: 88px;
  margin-top: 6px;
  overflow: visible;
}

/* Clickable chart-type cards */
.kpi-card--chart {
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.kpi-card--chart:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.13);
}

.kpi-card-body--wide {
  padding-bottom: 4px;
}

.kpi-wide-layout {
  display: flex;
  align-items: stretch;
  gap: 12px;
  padding: 4px 16px 0;
}

.kpi-wide-stats {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  min-width: 110px;
  flex-shrink: 0;
  padding-bottom: 8px;
}

.kpi-value--wide {
  font-size: 1.65rem;
}

.kpi-wide-chart {
  flex: 1;
  height: 160px;
  min-width: 0;
  display: block;
  overflow: visible;
}

.range-select {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-secondary);
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: var(--font);
  padding: 0;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  background-image: 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='%2394a3b8' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0 center;
  padding-right: 14px;
}

.range-select:focus { color: var(--primary); }

/* ===== CHARTS SECTION ===== */
.charts-section {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: auto auto auto;
  gap: 16px;
}

.charts-section.collapsed { display: none; }

.chart-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-soft);
  padding: 18px 20px 16px;
  transition: box-shadow 0.2s;
  overflow: hidden;
}

.chart-card:hover { box-shadow: var(--shadow); }

.chart-card--wide {
  grid-column: 1 / -1;
}

.chart-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}

.chart-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.chart-insight {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
}

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

.chart-controls .range-select {
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 22px 4px 8px;
  font-size: 0.75rem;
  background-image: 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='%2394a3b8' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
}

.ask-btn {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}

.ask-btn:hover {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary-dark);
}

.chart-body {
  width: 100%;
}

.chart-body svg { display: block; }

/* ===== NEEDS ATTENTION ===== */
.alerts-section {
  margin-bottom: 20px;
}

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

.alerts-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.alerts-count-badge {
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 700;
}

.alerts-count-badge.has-critical { background: #fee2e2; color: #991b1b; }
.alerts-count-badge.has-warning  { background: #fef3c7; color: #92400e; }
.alerts-count-badge.has-info     { background: #dbeafe; color: #1e40af; }

.alerts-toggle {
  margin-left: auto;
  background: none;
  border: none;
  font-size: 0.75rem;
  color: var(--text-muted);
  cursor: pointer;
  font-family: var(--font);
  padding: 3px 8px;
  border-radius: 5px;
  transition: background 0.15s;
}
.alerts-toggle:hover { background: var(--border-soft); color: var(--text-secondary); }

.alerts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
  transition: all 0.25s;
}

.alerts-grid.collapsed { display: none; }

.alert-card {
  background: var(--surface);
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow 0.2s, transform 0.2s;
  animation: alertIn 0.25s ease;
}

@keyframes alertIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.alert-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }

.alert-card--critical { border-left: 4px solid #ef4444; }
.alert-card--warning  { border-left: 4px solid #f59e0b; }
.alert-card--info     { border-left: 4px solid #3b82f6; }

.alert-card-header {
  display: flex;
  align-items: flex-start;
  padding: 12px 14px 8px;
  gap: 10px;
}

.alert-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.alert-card--critical .alert-icon { background: #fee2e2; color: #dc2626; }
.alert-card--warning  .alert-icon { background: #fef3c7; color: #d97706; }
.alert-card--info     .alert-icon { background: #dbeafe; color: #2563eb; }

.alert-meta { flex: 1; min-width: 0; }

.alert-severity {
  font-size: 0.63rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 2px;
}

.alert-card--critical .alert-severity { color: #dc2626; }
.alert-card--warning  .alert-severity { color: #d97706; }
.alert-card--info     .alert-severity { color: #2563eb; }

.alert-title {
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}

.alert-detail {
  padding: 0 14px 8px;
  font-size: 0.77rem;
  color: var(--text-secondary);
  line-height: 1.45;
}

.alert-badges {
  display: flex;
  gap: 6px;
  padding: 0 14px 10px;
}

.alert-badge {
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 700;
}

.alert-badge--value   { background: #f1f5f9; color: var(--text-primary); }
.alert-badge--vs      { background: #f8fafc; color: var(--text-muted); border: 1px solid var(--border); }

[data-theme="dark"] .alert-badge--value { background: rgba(255,255,255,0.08); color: var(--text-primary); }
[data-theme="dark"] .alert-badge--vs    { background: transparent; color: var(--text-muted); border-color: var(--border); }

.alert-footer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 14px 12px;
  border-top: 1px solid var(--border-soft);
}

.alert-action-hint {
  font-size: 0.71rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin: 0;
}

.alert-footer-btns {
  display: flex;
  align-items: center;
  gap: 5px;
  justify-content: flex-end;
}

/* Shared base for all three action buttons */
.alert-ask-btn,
.alert-complete-btn,
.alert-snooze-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 9px;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.15s;
  white-space: nowrap;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
}

.alert-ask-btn:hover     { background: var(--primary-light); color: var(--primary-dark); border-color: rgba(14,165,233,0.4); }
.alert-complete-btn:hover { background: #d1fae5; color: #065f46; border-color: #6ee7b7; }
.alert-snooze-btn:hover   { background: #fef3c7; color: #92400e; border-color: #fcd34d; }

.alert-snooze-btn .chevron {
  opacity: 0.6;
  transition: transform 0.15s;
}

/* Snooze dropdown */
.snooze-wrap {
  position: relative;
}

.snooze-dropdown {
  position: absolute;
  bottom: calc(100% + 5px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: var(--shadow-lg);
  min-width: 152px;
  z-index: 50;
  overflow: hidden;
  display: none;
  flex-direction: column;
}

.snooze-dropdown.open {
  display: flex;
  animation: snoozeIn 0.14s cubic-bezier(0.4, 0, 0.2, 1);
}

.snooze-wrap:has(.snooze-dropdown.open) .alert-snooze-btn .chevron {
  transform: rotate(180deg);
}

@keyframes snoozeIn {
  from { opacity: 0; transform: translateY(6px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.snooze-option {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
  font-family: var(--font);
  text-align: left;
  transition: background 0.1s, color 0.1s;
}

.snooze-option:last-child { border-bottom: none; }

.snooze-option:hover {
  background: #fef3c7;
  color: #92400e;
}

.alerts-clear {
  text-align: center;
  padding: 14px;
  background: var(--surface);
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  font-size: 0.82rem;
  color: var(--text-muted);
  display: none;
}

.alerts-clear.visible { display: block; }

/* ===== (modal styles removed — config is a separate page) ===== */

.modal {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border-soft);
}

.modal-header h2 {
  font-size: 1.05rem;
  font-weight: 700;
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.15s;
}

.modal-close:hover { background: var(--bg); }

.modal-body {
  padding: 16px 24px;
  overflow-y: auto;
  flex: 1;
}

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

.metric-config-list { display: flex; flex-direction: column; gap: 8px; }

.metric-config-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 9px;
  padding: 10px 14px;
  cursor: grab;
  transition: border-color 0.15s, box-shadow 0.15s;
  user-select: none;
}

.metric-config-item:active { cursor: grabbing; }
.metric-config-item.dragging { opacity: 0.5; box-shadow: var(--shadow); }
.metric-config-item.drag-over { border-color: var(--primary); background: var(--primary-light); }

.drag-handle {
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 2px;
}

.drag-handle span {
  display: block;
  width: 16px;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
}

.metric-config-info {
  flex: 1;
}

.metric-config-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
}

.metric-config-range {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
}

.metric-config-range label {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.config-range-select {
  font-size: 0.72rem;
  padding: 2px 18px 2px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: white;
  color: var(--text-secondary);
  font-family: var(--font);
  cursor: pointer;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  background-image: 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='%2394a3b8' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 4px center;
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

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

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #cbd5e1;
  border-radius: 22px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-switch input:checked + .toggle-slider { background: var(--primary); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(18px); }

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border-soft);
}

.btn {
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  border: none;
  transition: all 0.15s;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--text-secondary); border: 1.5px solid var(--border); }
.btn-ghost:hover { background: var(--bg); }

/* ===== CHAT PANEL ===== */
.chat-panel {
  position: fixed;
  right: 0;
  top: var(--header-h);
  width: var(--chat-w);
  height: calc(100vh - var(--header-h));
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 24px rgba(14,165,233,0.1);
  display: flex;
  flex-direction: column;
  z-index: 90;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-panel.open { transform: translateX(0); }

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-soft);
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
}

.chat-header-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 0.9rem;
}

.chat-close {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: rgba(255,255,255,0.15);
  color: white;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.chat-close:hover { background: rgba(255,255,255,0.25); }

.chat-context-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg);
  min-height: 0;
}

.chat-context-bar:empty { display: none; }

.context-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px 3px 8px;
  background: var(--primary-light);
  color: var(--primary-dark);
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  border: 1px solid rgba(14,165,233,0.25);
}

.context-chip-remove {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  color: var(--primary-dark);
  opacity: 0.6;
  display: flex;
  align-items: center;
  font-size: 0.9rem;
  line-height: 1;
}

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

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}

.chat-message {
  display: flex;
  flex-direction: column;
  gap: 3px;
  animation: msgIn 0.2s ease;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-message.user { align-items: flex-end; }
.chat-message.ai { align-items: flex-start; }

.message-bubble {
  max-width: 85%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 0.83rem;
  line-height: 1.55;
}

.chat-message.user .message-bubble {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  border-bottom-right-radius: 4px;
}

.chat-message.ai .message-bubble {
  background: var(--bg);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.message-time {
  font-size: 0.65rem;
  color: var(--text-muted);
  padding: 0 4px;
}

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  width: fit-content;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typingBounce 1.2s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

.chat-footer {
  border-top: 1px solid var(--border-soft);
  padding: 10px 12px 12px;
}

.chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 8px;
}

.suggestion-chip {
  padding: 4px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 0.72rem;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.15s;
}

.suggestion-chip:hover {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary-dark);
}

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

.chat-input {
  flex: 1;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  font-size: 0.83rem;
  font-family: var(--font);
  color: var(--text-primary);
  resize: none;
  outline: none;
  line-height: 1.4;
  transition: border-color 0.15s;
  max-height: 100px;
  overflow-y: auto;
}

.chat-input:focus { border-color: var(--primary); background: white; }
.chat-input::placeholder { color: var(--text-muted); }

.chat-send-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 9px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}

.chat-send-btn:hover { background: var(--primary-dark); }
.chat-send-btn:active { transform: scale(0.95); }
.chat-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== CHAT FAB ===== */
.chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 89;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  border: none;
  border-radius: 50px;
  box-shadow: 0 4px 16px rgba(14,165,233,0.4);
  cursor: pointer;
  font-family: var(--font);
  font-weight: 600;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.chat-fab:hover {
  box-shadow: 0 6px 24px rgba(14,165,233,0.5);
  transform: translateY(-1px);
}

.chat-fab.hidden { display: none; }

.fab-text { white-space: nowrap; }

/* ===== D3 STYLES ===== */
.tick line, .tick text { font-family: var(--font); }
.axis-label { font-family: var(--font); font-size: 11px; fill: var(--text-muted); }
.tooltip-box {
  position: absolute;
  background: rgba(15,23,42,0.88);
  color: white;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.75rem;
  pointer-events: none;
  white-space: nowrap;
  z-index: 300;
  backdrop-filter: blur(4px);
  transform: translate(-50%, -110%);
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

/* ===== INVESTIGATE MODAL ===== */
.investigate-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.55);
  backdrop-filter: blur(3px);
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.15s ease;
}
.investigate-overlay.hidden { display: none; }

.investigate-modal {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.22);
  width: 100%;
  max-width: 920px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: investSlideUp 0.22s cubic-bezier(.22,.68,0,1.2);
}
@keyframes investSlideUp {
  from { transform: translateY(18px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* Header */
.investigate-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.invest-hdr-left { flex: 1; min-width: 0; }
.invest-metric-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}
.invest-summary {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}
.invest-hdr-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.invest-range-sel {
  padding: 6px 10px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.78rem;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  cursor: pointer;
  transition: border-color 0.15s;
}
.invest-range-sel:focus { outline: none; border-color: var(--primary); }
.invest-ask-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  background: var(--primary-light);
  color: var(--primary-dark);
  border: 1.5px solid rgba(14,165,233,0.3);
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: all 0.15s;
  white-space: nowrap;
}
.invest-ask-btn:hover { background: var(--primary); color: white; border-color: var(--primary); }
.investigate-close {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border: none; background: transparent;
  color: var(--text-muted); border-radius: 8px; cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.investigate-close:hover { background: var(--bg); color: var(--text-primary); }

/* Tabs */
.invest-tabs {
  display: flex;
  padding: 0 20px;
  border-bottom: 2px solid var(--border);
  flex-shrink: 0;
}
.invest-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-bottom: 2.5px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  font-family: var(--font);
  transition: color 0.15s, border-color 0.15s;
}
.invest-tab:hover { color: var(--text-primary); }
.invest-tab.active {
  color: var(--primary-dark);
  font-weight: 700;
  border-bottom-color: var(--primary);
}

/* Panels */
.invest-body { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.invest-panel { flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.invest-panel.hidden { display: none; }

/* Viz */
.invest-chart-wrap {
  flex: 1;
  padding: 16px 20px;
  position: relative;
  overflow: hidden;
  min-height: 300px;
}
.invest-tooltip { position: absolute; pointer-events: none; z-index: 10; }

/* Data toolbar */
.invest-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px 6px;
  flex-shrink: 0;
}
.invest-search-wrap { position: relative; flex: 1; max-width: 340px; }
.invest-search-icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); pointer-events: none;
}
.invest-search {
  width: 100%; box-sizing: border-box;
  padding: 7px 10px 7px 32px;
  border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 0.82rem; font-family: var(--font);
  background: var(--bg); color: var(--text-primary);
  transition: border-color 0.15s;
}
.invest-search:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14,165,233,0.1); }
.invest-row-count {
  font-size: 0.72rem; color: var(--text-muted); font-weight: 600;
  white-space: nowrap; margin-left: auto;
}

/* Filter chips */
.invest-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  padding: 4px 20px 10px;
  flex-shrink: 0;
}
.inv-filter-group { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.inv-filter-label {
  font-size: 0.67rem; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.4px; white-space: nowrap;
}
.inv-filter-chip {
  padding: 3px 10px;
  border: 1.5px solid var(--border); border-radius: 12px;
  font-size: 0.71rem; font-weight: 500; color: var(--text-secondary);
  background: var(--surface); cursor: pointer; font-family: var(--font);
  white-space: nowrap; transition: all 0.12s;
}
.inv-filter-chip:hover { border-color: var(--primary); color: var(--primary-dark); background: var(--primary-light); }
.inv-filter-chip.active {
  background: var(--primary-light); border-color: var(--primary);
  color: var(--primary-dark); font-weight: 700;
}

/* Table */
.invest-table-wrap {
  flex: 1;
  overflow: auto;
  border-top: 1px solid var(--border-soft);
}
.invest-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.inv-th {
  position: sticky; top: 0;
  background: var(--bg); padding: 9px 13px;
  text-align: left; font-size: 0.68rem; font-weight: 700;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px;
  border-bottom: 2px solid var(--border); white-space: nowrap; user-select: none; z-index: 1;
}
.inv-th.sortable { cursor: pointer; }
.inv-th.sortable:hover { color: var(--primary-dark); background: var(--primary-light); }
.inv-th.sorted { color: var(--primary-dark); }
.inv-row:hover { background: var(--bg); }
.inv-row:not(:last-child) .inv-td { border-bottom: 1px solid var(--border-soft); }
.inv-td {
  padding: 8px 13px; color: var(--text-secondary);
  vertical-align: middle; max-width: 220px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.inv-cell-num { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text-primary); }
.inv-cell-pct { font-weight: 700; }
.inv-cell-pct.up   { color: #059669; }
.inv-cell-pct.down { color: #dc2626; }
.inv-cell-rating      { font-size: 0.78rem; letter-spacing: 1px; }
.inv-cell-rating.high { color: #d97706; }
.inv-cell-rating.mid  { color: #94a3b8; }
.inv-cell-rating.low  { color: #ef4444; }
.inv-cell-empty { color: var(--text-muted); }
.inv-empty-row { text-align: center; padding: 40px; color: var(--text-muted); font-style: italic; }
.inv-tag {
  display: inline-block; padding: 2px 8px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  font-size: 0.7rem; font-weight: 600; color: var(--text-secondary); white-space: nowrap;
}
.inv-status {
  display: inline-block; padding: 2px 8px; border-radius: 10px;
  font-size: 0.7rem; font-weight: 700; white-space: nowrap;
}
.inv-status--success { background: #d1fae5; color: #065f46; }
.inv-status--error   { background: #fee2e2; color: #991b1b; }
.inv-status--warning { background: #fef3c7; color: #92400e; }
.inv-status--active  { background: #dbeafe; color: #1e40af; }
.inv-status--info    { background: #f0fdf4; color: #166534; }
.inv-status--neutral { background: #f1f5f9; color: #475569; }

/* ===== INVEST CONFIGURE PANEL ===== */
.invest-config-body {
  display: flex; flex-direction: column; height: 100%;
  overflow-y: auto;
}
.invest-config-head {
  padding: 20px 24px 12px;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.invest-config-title { font-size: 0.95rem; font-weight: 700; color: var(--text-primary); }
.invest-config-sub   { font-size: 0.75rem; color: var(--text-muted); margin-top: 3px; }

.invest-config-fields {
  flex: 1;
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
}
.invest-config-field {
  padding: 16px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color 0.15s;
}
.invest-config-field:focus-within { border-color: var(--primary); }

.invest-config-field-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.invest-config-label {
  font-size: 0.82rem; font-weight: 700; color: var(--text-primary);
  cursor: default;
}
.inv-cfg-badges { display: flex; gap: 5px; flex-shrink: 0; }
.inv-cfg-badge {
  padding: 2px 8px; border-radius: 10px; font-size: 0.65rem; font-weight: 700;
  white-space: nowrap;
}
.inv-cfg-badge--chart { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }

.invest-config-desc {
  font-size: 0.72rem; color: var(--text-muted); line-height: 1.5;
}
.invest-config-input-wrap {
  display: flex; align-items: center; gap: 0;
  border: 1.5px solid var(--border); border-radius: 8px; overflow: hidden;
  background: var(--surface);
  transition: border-color 0.15s;
  max-width: 240px;
}
.invest-config-input-wrap:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14,165,233,0.1); }
.inv-input-affix {
  padding: 7px 10px;
  background: var(--bg); border: none;
  font-size: 0.82rem; font-weight: 600; color: var(--text-muted);
  user-select: none; flex-shrink: 0;
}
.inv-input-pre { border-right: 1px solid var(--border); }
.inv-input-suf { border-left:  1px solid var(--border); }
.inv-config-input {
  flex: 1; padding: 7px 10px;
  border: none; outline: none;
  font-size: 0.88rem; font-weight: 600; font-family: var(--font);
  color: var(--text-primary); background: transparent;
  min-width: 0;
}
/* hide number spinners */
.inv-config-input::-webkit-outer-spin-button,
.inv-config-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.inv-config-input[type=number] { -moz-appearance: textfield; }

.invest-config-footer {
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  padding: 14px 24px;
  border-top: 1px solid var(--border-soft);
  flex-shrink: 0;
}
.inv-cfg-reset {
  padding: 7px 14px; border: 1.5px solid var(--border); border-radius: 8px;
  background: transparent; color: var(--text-muted); font-size: 0.78rem; font-weight: 600;
  font-family: var(--font); cursor: pointer; transition: all 0.15s;
}
.inv-cfg-reset:hover { border-color: var(--text-secondary); color: var(--text-primary); }
.inv-cfg-save {
  padding: 7px 18px; border: none; border-radius: 8px;
  background: var(--primary); color: white;
  font-size: 0.78rem; font-weight: 700; font-family: var(--font);
  cursor: pointer; transition: background 0.15s;
}
.inv-cfg-save:hover  { background: var(--primary-dark); }
.inv-cfg-save.saved  { background: #059669; }

/* ===== EMPTY STATE ===== */
.kpi-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
  :root { --chat-w: 340px; }
  .kpi-section { grid-template-columns: repeat(6, 1fr); }
  .charts-section { grid-template-columns: 1fr; }
  .chart-card--wide { grid-column: 1; }
}

@media (max-width: 768px) {
  :root { --header-h: 56px; }

  .header { padding: 0 12px; }
  .brand-sub { display: none; }
  .header-center { display: none; }

  .main-content { padding: 14px 12px 80px; }
  .main-content.chat-open { padding-right: 12px; }

  .kpi-section { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .kpi-card--wide { grid-column: span 2; }
  .kpi-card--bar-list { grid-column: span 2; }
  .kpi-card--multi-line { grid-column: span 2; }
  .charts-section { gap: 10px; }

  .chat-panel {
    width: 100%;
    top: var(--header-h);
    height: calc(100vh - var(--header-h));
  }

  .chat-fab { bottom: 16px; right: 16px; }
  .fab-text { display: none; }
  .chat-fab { padding: 14px; border-radius: 50%; }

  .modal { max-height: 90vh; margin: 0 8px; }
  .investigate-overlay { padding: 0; align-items: flex-end; }
  .investigate-modal { max-height: 92vh; border-radius: 16px 16px 0 0; }
  .invest-ask-btn span { display: none; }
  .invest-hdr-right { gap: 6px; }
}

@media (max-width: 400px) {
  .kpi-section { grid-template-columns: repeat(2, 1fr); }
  .kpi-card--wide { grid-column: span 2; }
  .kpi-value { font-size: 1.4rem; }
  .kpi-wide-layout { flex-direction: column; }
  .kpi-wide-chart { height: 120px; }
}

/* ── Chart Modal ─────────────────────────────────────────────── */
.chart-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.52);
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(3px);
}

.chart-modal-overlay[hidden] {
  display: none;
}

.chart-modal {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  padding: 28px;
  width: min(92vw, 820px);
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: 0 24px 72px rgba(0, 0, 0, 0.28);
}

.chart-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 18px;
}

.chart-modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 6px;
  line-height: 1.2;
}

.chart-modal-type-tag {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--border-soft);
  border-radius: 4px;
  padding: 2px 7px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.chart-modal-close {
  background: none;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 1rem;
  line-height: 1;
  padding: 5px 10px;
  flex-shrink: 0;
  margin-left: 16px;
  transition: background 0.1s, color 0.1s;
}

.chart-modal-close:hover {
  background: var(--border-soft);
  color: var(--text-primary);
}

.chart-modal-stat {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 20px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border-soft);
}

.chart-modal-value {
  font-size: 2.3rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}

.chart-modal-period-toggle {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
}

.period-toggle-btn {
  padding: 4px 14px;
  font-size: 0.78rem;
  font-weight: 500;
  border-radius: 20px;
  border: 1px solid var(--border-soft);
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.period-toggle-btn:hover:not(:disabled) {
  background: var(--border-soft);
  color: var(--text-primary);
}

.period-toggle-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.period-toggle-btn:disabled {
  opacity: 0.5;
  cursor: default;
}

.chart-modal-chart-wrap {
  position: relative;
}

.chart-modal-svg {
  width: 100%;
  height: 320px;
  display: block;
}

.chart-modal-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.8rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.16);
  white-space: nowrap;
  z-index: 10;
}

.chart-modal-tooltip-date {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 7px;
}

.chart-modal-tooltip-row {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.chart-modal-tooltip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.chart-modal-tooltip-val {
  margin-left: auto;
  font-weight: 600;
  color: var(--text-primary);
  padding-left: 16px;
}

/* chart modal header actions (data btn + close) */
.chart-modal-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}


/* ── Data Table Modal ─────────────────────────────────────────── */
.dt-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 1100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 36px 16px;
  overflow-y: auto;
}
.dt-modal-overlay[hidden] { display: none; }

.dt-modal {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  width: 100%;
  max-width: 1100px;
  min-height: 300px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  overflow: hidden;
}

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

.dt-modal-title-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.dt-modal-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.dt-row-count {
  font-size: 0.72rem;
  color: var(--text-secondary);
  font-weight: 500;
}

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

.dt-col-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  background: var(--surface-alt, var(--border-soft));
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.dt-col-toggle-btn:hover {
  background: var(--accent, #0ea5e9);
  color: #fff;
  border-color: transparent;
}

.dt-modal-close {
  background: none;
  border: none;
  font-size: 1.1rem;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
}
.dt-modal-close:hover { background: var(--border-soft); }

.dt-col-picker { position: relative; }

.dt-col-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 230px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.18);
  z-index: 200;
  overflow: hidden;
}
.dt-col-dropdown[hidden] { display: none; }

.dt-col-search-wrap {
  padding: 8px;
  border-bottom: 1px solid var(--border-soft);
}
.dt-col-search {
  width: 100%;
  box-sizing: border-box;
  padding: 5px 9px;
  font-size: 0.78rem;
  background: var(--surface-alt, rgba(0,0,0,0.04));
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  color: var(--text-primary);
  outline: none;
}
.dt-col-search:focus { border-color: var(--accent, #0ea5e9); }

.dt-col-list {
  max-height: 260px;
  overflow-y: auto;
  padding: 4px 0;
}

.dt-col-check {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
}
.dt-col-check:hover { background: var(--surface-alt, rgba(0,0,0,0.04)); }
.dt-col-check[hidden] { display: none; }
.dt-col-check input { accent-color: var(--accent, #0ea5e9); cursor: pointer; flex-shrink: 0; }

.dt-col-footer {
  display: flex;
  gap: 6px;
  padding: 6px 8px;
  border-top: 1px solid var(--border-soft);
}
.dt-col-foot-btn {
  flex: 1;
  padding: 4px 0;
  font-size: 0.72rem;
  background: none;
  border: 1px solid var(--border-soft);
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.dt-col-foot-btn:hover { background: var(--accent, #0ea5e9); color: #fff; border-color: var(--accent, #0ea5e9); }

.dt-table-wrap {
  overflow: auto;
  flex: 1;
}

.dt-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.dt-th {
  padding: 8px 12px;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-secondary);
  white-space: nowrap;
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 1;
  user-select: none;
}
.dt-th:hover { color: var(--text-primary); }
.dt-th--active { color: var(--accent, #0ea5e9); }

.dt-filter-row td { background: var(--surface); position: sticky; top: 32px; z-index: 1; }
.dt-filter-cell { padding: 4px 6px; border-bottom: 1px solid var(--border-soft); }
.dt-filter-input {
  width: 100%;
  min-width: 60px;
  padding: 3px 7px;
  background: var(--surface-alt, rgba(0,0,0,0.04));
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  font-size: 0.72rem;
  color: var(--text-primary);
  outline: none;
}
.dt-filter-input:focus { border-color: var(--accent, #0ea5e9); }

.dt-td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border-soft);
  color: var(--text-primary);
  vertical-align: top;
  white-space: nowrap;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dt-row-alt td { background: rgba(0,0,0,0.02); }

.dt-link {
  color: var(--accent, #0ea5e9);
  text-decoration: none;
  font-weight: 500;
}
.dt-link:hover { text-decoration: underline; }

.dt-loading, .dt-error, .dt-empty {
  padding: 32px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.85rem;
}
.dt-error { color: #ef4444; }

.dt-pagination {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 16px;
  border-top: 1px solid var(--border-soft);
  flex-wrap: wrap;
}
.dt-page-info {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-right: 8px;
}
.dt-page-btn {
  padding: 4px 10px;
  background: var(--surface-alt, var(--border-soft));
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  font-size: 0.75rem;
  color: var(--text-secondary);
  cursor: pointer;
  min-width: 32px;
  text-align: center;
  transition: background 0.12s, color 0.12s;
}
.dt-page-btn:hover:not([disabled]) { background: var(--accent, #0ea5e9); color: #fff; border-color: transparent; }
.dt-page-btn--active { background: var(--accent, #0ea5e9); color: #fff; border-color: transparent; font-weight: 700; }
.dt-page-btn--disabled { opacity: 0.35; cursor: default; }
