/* Suppress all transitions on initial load to prevent sidebar/theme flash */
.no-transitions,
.no-transitions *,
.no-transitions *::before,
.no-transitions *::after {
  transition: none !important;
}

:root {
  color-scheme: light;
  --navy: #002b5c;
  --navy-dark: #001a3a;
  --navy-light: #003d7a;
  --teal: #00a3af;
  --teal-hover: #008a94;
  --teal-light: #e6f7f8;
  --white: #ffffff;
  --off-white: #f7f8fa;
  --light-gray: #e8ecf1;
  --medium-gray: #8c95a6;
  --dark-gray: #3a3f47;
  --success: #2e7d32;
  --warning: #f57c00;
  --error: #c62828;
  --citation: #6b4c9a;
  --text-inverse: #ffffff;
  --sidebar-text: #f7fbff;
  --app-background: radial-gradient(circle at top right, #dceefe 0%, #f7f8fa 42%, #eef4fb 100%);
  --sidebar-background: linear-gradient(180deg, #002b5c 0%, #001a3a 100%);
  --sidebar-control-border: rgba(255, 255, 255, 0.35);
  --sidebar-control-bg: rgba(255, 255, 255, 0.12);
  --sidebar-control-hover: rgba(255, 255, 255, 0.25);
  --sidebar-hover: rgba(255, 255, 255, 0.08);
  --sidebar-divider: rgba(255, 255, 255, 0.14);
  --sidebar-muted: #bad2f4;
  --avatar-bg: rgba(255, 255, 255, 0.15);
  --logo-ink: #001a3a;
  --card-shadow: 0 1px 3px rgba(0, 43, 92, 0.08), 0 4px 12px rgba(0, 43, 92, 0.04);
  --surface-raised: #fbfcff;
  --secondary-border: #bfd0e7;
  --secondary-hover: #f5f8fd;
  --drop-zone-border: #c7d5e8;
  --drop-zone-bg: linear-gradient(180deg, #fafcff, #f4f8fd);
  --progress-surface: #fbfcff;
  --warning-surface: #fff8e1;
  --warning-text: #e65100;
  --table-header-bg: #002b5c;
  --table-header-text: #ffffff;
  --modal-backdrop: rgba(0, 0, 0, 0.78);
  --modal-close-bg: rgba(0, 0, 0, 0.5);
  --modal-close-bg-hover: rgba(0, 0, 0, 0.75);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  /* Text — 87% alpha for body, brighter for headings */
  --navy: rgba(255, 255, 255, 0.92);
  --navy-dark: rgba(255, 255, 255, 0.62);
  --navy-light: rgba(140, 170, 220, 0.18);
  /* Teal — slightly desaturated, brighter to pop on dark surfaces */
  --teal: #4dd8c0;
  --teal-hover: #3cc4ad;
  --teal-light: rgba(77, 216, 192, 0.12);
  /* Surfaces — warm charcoal base, NOT pure navy */
  --white: #131518;
  --off-white: #181b20;
  --light-gray: #2a2d35;
  --medium-gray: #8e939e;
  --dark-gray: #d8dae0;
  --success: #4caf50;
  --warning: #ffb74d;
  --error: #ef5350;
  --citation: #c9a8ff;
  --text-inverse: rgba(255, 255, 255, 0.92);
  /* Sidebar — deeper but still warm-leaning */
  --sidebar-text: rgba(255, 255, 255, 0.88);
  --app-background: #111316;
  --sidebar-background: linear-gradient(180deg, #141720 0%, #0e1015 100%);
  --sidebar-control-border: rgba(255, 255, 255, 0.1);
  --sidebar-control-bg: rgba(255, 255, 255, 0.05);
  --sidebar-control-hover: rgba(255, 255, 255, 0.12);
  --sidebar-hover: rgba(255, 255, 255, 0.07);
  --sidebar-divider: rgba(255, 255, 255, 0.08);
  --sidebar-muted: rgba(255, 255, 255, 0.45);
  --avatar-bg: rgba(255, 255, 255, 0.08);
  --logo-ink: #0e1015;
  /* Cards — clearly elevated above background */
  --card-shadow: 0 1px 3px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.25);
  --surface-raised: #1c1f25;
  --secondary-border: #2e3140;
  --secondary-hover: #22252d;
  --drop-zone-border: #3a3e4a;
  --drop-zone-bg: linear-gradient(180deg, #1a1d23, #1e2128);
  --progress-surface: #1a1d23;
  --warning-surface: rgba(255, 183, 77, 0.1);
  --warning-text: #ffcc80;
  --table-header-bg: #1a1d24;
  --table-header-text: rgba(255, 255, 255, 0.88);
  --modal-backdrop: rgba(0, 0, 0, 0.75);
  --modal-close-bg: rgba(0, 0, 0, 0.5);
  --modal-close-bg-hover: rgba(0, 0, 0, 0.7);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "DM Sans", "Segoe UI", sans-serif;
  background: var(--app-background);
  color: var(--dark-gray);
  overflow-x: hidden;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width, 260px) 1fr;
  min-height: 100vh;
  transition: grid-template-columns 0.25s ease;
}

.app-shell.sidebar-collapsed {
  --sidebar-width: 68px;
}

.app-shell > .content {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar-background);
  color: var(--sidebar-text);
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width, 260px);
  height: 100%;
  min-height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 0.25s ease;
  z-index: 100;
}

.sidebar-collapsed .sidebar {
  width: 68px;
  padding: 16px 8px;
}

/* Sidebar controls */
.sidebar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1.5px solid var(--sidebar-control-border);
  border-radius: 8px;
  background: var(--sidebar-control-bg);
  color: var(--sidebar-text);
  cursor: pointer;
  padding: 7px;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.sidebar-toggle:hover {
  background: var(--sidebar-control-hover);
  border-color: var(--sidebar-control-hover);
  transform: translateY(-1px);
}

.sidebar-toggle:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(85, 215, 203, 0.22);
}

.sidebar-toggle svg {
  width: 100%;
  height: 100%;
}

/* Hide toggle hamburger when collapsed — logo handles expand */
.sidebar-collapsed .sidebar-header .sidebar-toggle {
  display: none;
}

/* Overlay for tablet when sidebar open */
.sidebar-overlay {
  display: none;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  min-height: 44px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-collapsed .sidebar-header {
  flex-direction: column;
  justify-content: center;
  gap: 10px;
}

.sidebar-collapsed .sidebar-header .brand-text {
  display: none;
}

.sidebar-collapsed .brand {
  justify-content: center;
}

.logo-mark {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-weight: 700;
  background: linear-gradient(145deg, var(--teal), #0ad6c4);
  color: var(--logo-ink);
  position: relative;
}

.logo-mark .logo-text {
  transition: opacity 0.15s;
}

.logo-mark .logo-expand {
  display: none;
}

/* When collapsed: logo becomes clickable expand trigger */
.sidebar-collapsed .logo-mark {
  cursor: pointer;
  transition: background 0.2s;
}

.sidebar-collapsed .logo-mark .logo-expand {
  display: none;
  position: absolute;
  width: 22px;
  height: 22px;
  color: var(--logo-ink);
}

.sidebar-collapsed .logo-mark:hover .logo-text {
  opacity: 0;
}

.sidebar-collapsed .logo-mark:hover .logo-expand {
  display: block;
}

.sidebar-collapsed .logo-mark:hover {
  background: linear-gradient(145deg, #00c4b0, #0ad6c4);
}

.brand-text {
  overflow: hidden;
  white-space: nowrap;
  opacity: 1;
  transition: opacity 0.2s ease;
}

.sidebar-collapsed .brand-text {
  opacity: 0;
  width: 0;
}

.brand h1 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
}

.brand p {
  margin: 2px 0 0;
  font-size: 0.78rem;
  color: var(--sidebar-muted);
}

.nav { display: grid; gap: 4px; }

.nav-icon {
  width: 20px;
  height: 20px;
  min-width: 20px;
  opacity: 0.75;
  transition: opacity 0.15s;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  text-align: left;
  border: 0;
  border-left: 3px solid transparent;
  background: transparent;
  color: var(--sidebar-text);
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  transition: background 0.15s;
}

.nav-label {
  overflow: hidden;
  opacity: 1;
  transition: opacity 0.2s ease;
}

.sidebar-collapsed .nav-label {
  display: none;
}

.sidebar-collapsed .nav-item {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-left: 0;
  border-radius: 10px;
  width: 44px;
  height: 44px;
  margin: 0 auto;
  gap: 0;
}

.sidebar-collapsed .nav-item .nav-icon {
  opacity: 0.85;
}

.sidebar-collapsed .nav-item.active {
  border-left: 0;
  background: var(--navy-light);
  box-shadow: 0 0 0 2px var(--teal);
}

.sidebar-collapsed .nav-item.active .nav-icon {
  opacity: 1;
}

.nav-item:hover { background: var(--sidebar-hover); }
.nav-item:hover .nav-icon { opacity: 1; }

.nav-item.active {
  background: var(--navy-light);
  border-left-color: var(--teal);
}

.nav-item.active .nav-icon { opacity: 1; }

.sidebar-footer {
  margin-top: auto;
  flex-shrink: 0;
  display: flex;
  gap: 10px;
  align-items: center;
  padding-top: 16px;
  border-top: 1px solid var(--sidebar-divider);
  overflow: hidden;
}

.sidebar-collapsed .sidebar-footer > div:not(.avatar):not(.theme-fab) {
  display: none;
}

.sidebar-collapsed .sidebar-footer .theme-fab {
  display: none;
}

.sidebar-collapsed .sidebar-footer {
  justify-content: center;
}

.avatar {
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  background: var(--avatar-bg);
  font-size: 0.8rem;
  font-weight: 700;
}

.user-name { margin: 0; font-size: 0.85rem; white-space: nowrap; }
.version { margin: 0; color: var(--sidebar-muted); font-size: 0.75rem; white-space: nowrap; }

.content {
  position: relative;
  padding: clamp(14px, 2vw, 32px);
  width: 100%;
  max-width: none;
  min-width: 0;
}

.theme-fab {
  position: static;
  margin-left: auto;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.08);
  color: #f4f8ff;
  box-shadow: none;
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease;
  opacity: 0.7;
}

.theme-fab:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
}

.theme-fab:focus-visible {
  outline: none;
  opacity: 1;
  box-shadow: 0 0 0 2px rgba(0, 163, 175, 0.3);
}

.theme-fab-icon {
  width: 18px;
  height: 18px;
}

.theme-fab-icon--sun,
.theme-fab-icon--moon {
  display: none;
}

:root[data-theme="light"] .theme-fab-icon--moon,
:root:not([data-theme]) .theme-fab-icon--moon {
  display: block;
}

:root[data-theme="dark"] .theme-fab {
  background: rgba(255, 255, 255, 0.08);
  color: #f4f8ff;
  border-color: rgba(255, 255, 255, 0.18);
  box-shadow: none;
}

:root[data-theme="dark"] .theme-fab-icon--sun {
  display: block;
}

body,
.card,
.drop-zone,
input,
select,
.btn-primary,
.btn-secondary,
.table-wrap,
.screenshot-panel,
.screenshot-thumb,
.screenshot-thumb-label,
.screenshot-modal-content,
th,
td {
  transition: background 0.22s ease, color 0.22s ease, border-color 0.22s ease, box-shadow 0.22s ease;
}

.view { display: none; animation: fadeIn 0.35s ease; }
.view.active { display: block; width: 100%; }

#view-new-research.active {
  display: block;
  width: 100%;
}

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

.card {
  background: var(--white);
  border: 1px solid var(--light-gray);
  border-radius: 12px;
  box-shadow: var(--card-shadow);
  padding: 24px;
}

.centered {
  width: min(100%, 860px);
  margin: 0 auto;
}

.centered.wide {
  width: min(100%, 1320px);
  max-width: none;
}

.title {
  margin: 0;
  font-family: "Playfair Display", Georgia, serif;
  font-size: 2rem;
  color: var(--navy);
}

.subtitle {
  margin: 8px 0 0;
  color: var(--medium-gray);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
  margin-top: 22px;
}

.form-grid label {
  display: grid;
  gap: 8px;
  font-size: 0.81rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--medium-gray);
  font-weight: 600;
}

.form-grid label:first-child,
.form-grid label:nth-child(2),
.btn-primary {
  grid-column: 1 / -1;
}

/* --- New Research search bar --- */
.search-bar {
  position: relative;
  margin-top: 22px;
}

.search-bar .search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  color: var(--medium-gray);
  pointer-events: none;
}

.search-bar .search-input {
  width: 100%;
  padding: 14px 16px 14px 44px;
  font-size: 1rem;
  border: 2px solid var(--light-gray);
  border-radius: 12px;
  background: var(--white);
  color: var(--dark-gray);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.search-bar .search-input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 4px rgba(0, 163, 175, 0.12);
  outline: none;
}

.search-bar .search-input::placeholder {
  color: var(--medium-gray);
  font-size: 0.9rem;
}

.search-bar .search-clear {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  border: none;
  background: var(--error);
  color: var(--text-inverse);
  border-radius: 50%;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.15s;
  padding: 0;
}

.search-bar .search-clear:hover {
  background: #a01e1e;
  transform: translateY(-50%) scale(1.1);
}

.search-bar:has(.search-clear:not(.hidden)) .search-input {
  padding-right: 48px;
}

.research-options-row {
  display: flex;
  align-items: center;
  gap: 24px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.research-options-row .inline-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--medium-gray);
  font-weight: 600;
  margin: 0;
}

.research-options-row .inline-field input {
  width: 120px;
  padding: 7px 10px;
  font-size: 0.85rem;
  border-radius: 8px;
}

#single-form > .btn-primary {
  width: 100%;
  margin-top: 18px;
}

input, select {
  border: 1px solid var(--light-gray);
  border-radius: 8px;
  padding: 11px 12px;
  font-size: 0.94rem;
  font-family: inherit;
  color: var(--dark-gray);
  background: var(--white);
  outline: none;
}

input:focus, select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(0, 163, 175, 0.15);
}

.advanced-toggle {
  border: 0;
  background: transparent;
  color: var(--teal);
  justify-self: start;
  cursor: pointer;
  font-weight: 600;
  padding: 0;
}

.advanced-options {
  padding: 14px;
  border: 1px dashed var(--light-gray);
  border-radius: 10px;
  background: var(--surface-raised);
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.hidden { display: none !important; }

.advanced-options label {
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.92rem;
  color: var(--dark-gray);
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-primary, .btn-secondary {
  border: 0;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 0.94rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary {
  background: linear-gradient(135deg, var(--teal) 0%, #11beca 100%);
  color: var(--text-inverse);
}

.btn-primary:hover { background: linear-gradient(135deg, var(--teal-hover) 0%, #08aeb9 100%); }

.btn-primary:disabled,
.btn-secondary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-secondary {
  border: 1px solid var(--secondary-border);
  background: var(--white);
  color: var(--navy);
}

.btn-secondary:hover { background: var(--secondary-hover); }

.stepper { margin-top: 20px; display: grid; gap: 12px; }
.step {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--light-gray);
  border-radius: 10px;
}

.dot {
  width: 20px;
  height: 20px;
  border-radius: 999px;
  border: 2px solid var(--light-gray);
}

.step.done .dot { background: var(--teal); border-color: var(--teal); }
.step.active .dot { border-color: var(--teal); box-shadow: 0 0 0 4px rgba(0, 163, 175, 0.2); }

.badge {
  margin-left: auto;
  font-size: 0.69rem;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
  color: var(--text-inverse);
}

.badge.success { background: var(--success); }
.badge.warning { background: var(--warning); }
.badge.error { background: var(--error); }
.badge.info { background: var(--teal); }

.drop-zone {
  margin-top: 18px;
  border: 2px dashed var(--drop-zone-border);
  border-radius: 12px;
  min-height: 180px;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  background: var(--drop-zone-bg);
}

.drop-zone.dragover {
  border-color: var(--teal);
  background: var(--teal-light);
}

.drop-title { margin: 0; font-weight: 700; color: var(--navy); }
.drop-sub { margin: 8px 0 14px; color: var(--medium-gray); }
.template-downloads { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.template-label { font-size: 0.85rem; color: var(--medium-gray); }
.btn-sm { padding: 4px 12px; font-size: 0.8rem; }
.file-meta { margin-top: 12px; font-family: "JetBrains Mono", monospace; font-size: 0.83rem; }
.preview-wrap { margin-top: 16px; }
.caption { color: var(--medium-gray); }
.caption.error { color: var(--error); font-weight: 600; }
.batch-status-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 4px; }
.batch-status-bar .caption { margin: 0; }
.batch-status-bar .batch-progress { margin: 0; padding: 0; border: 0; background: none; text-align: right; }
.batch-progress { margin-top: 10px; padding: 10px 12px; border: 1px solid var(--light-gray); border-radius: 8px; background: var(--progress-surface); }
.reconnect-banner { margin-top: 10px; padding: 10px 12px; border: 1px solid var(--warning); border-radius: 8px; background: var(--warning-surface); color: var(--warning-text); font-size: 0.88rem; font-weight: 600; }

.toolbar {
  display: grid;
  grid-template-columns: 1fr auto auto auto auto auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.toolbar .btn-secondary {
  white-space: nowrap;
  font-size: 0.82rem;
  padding: 9px 14px;
}

.toolbar .btn-primary {
  grid-column: 1 / -1;
}

@media (max-width: 1200px) {
  .toolbar {
    grid-template-columns: 1fr auto auto;
  }
  .toolbar .btn-secondary,
  .toolbar .btn-primary {
    grid-column: auto;
  }
  .toolbar .btn-primary {
    grid-column: 1 / -1;
  }
}

#view-results .card,
#view-results .toolbar {
  width: 100%;
  max-width: none;
}

#view-results .table-wrap {
  max-height: calc(100vh - 250px);
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--light-gray);
  border-radius: 10px;
  max-height: 62vh;
}

table { width: 100%; border-collapse: collapse; min-width: 1200px; }
#preview-table { min-width: 0; }

th {
  background: var(--table-header-bg);
  color: var(--table-header-text);
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 11px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  text-align: left;
}

td {
  padding: 10px;
  border-top: 1px solid var(--light-gray);
  vertical-align: top;
  font-size: 0.9rem;
}

tr:nth-child(even) td { background: var(--off-white); }
tr:hover td { background: var(--teal-light); }

.citation {
  color: var(--citation);
  font-size: 0.7rem;
  cursor: help;
  margin-left: 2px;
}

a > .citation { cursor: pointer; }
a:has(> .citation) { text-decoration: none; color: inherit; }
a:has(> .citation):hover > .citation { text-decoration: underline; }

.settings-card .settings-grid {
  margin: 20px 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.settings-status {
  display: block;
  font-size: 0.78rem;
  margin-top: 4px;
  font-weight: 500;
}
.settings-status.status-ok { color: #2e7d32; }
.settings-status.status-warn { color: #e65100; }

.toast-host {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: grid;
  gap: 8px;
  z-index: 1000;
}

.toast {
  color: var(--white);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.86rem;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
}

.toast.success { background: var(--success); }
.toast.warning { background: var(--warning); }
.toast.error { background: var(--error); }

@media (max-width: 1120px) {
  .app-shell:not(.sidebar-collapsed) { --sidebar-width: 68px; }
  .app-shell:not(.sidebar-collapsed) .sidebar-header .sidebar-toggle { display: none; }
  .app-shell:not(.sidebar-collapsed) .brand-text { display: none; }
  .app-shell:not(.sidebar-collapsed) .nav-label { display: none; }
  .app-shell:not(.sidebar-collapsed) .nav-item {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border-left: 0;
    border-radius: 10px;
    width: 44px;
    height: 44px;
    margin: 0 auto;
    gap: 0;
  }
  .app-shell:not(.sidebar-collapsed) .nav-item.active {
    border-left: 0;
    box-shadow: 0 0 0 2px var(--teal);
  }
  .app-shell:not(.sidebar-collapsed) .sidebar-footer > div:not(.avatar) { display: none; }
  .app-shell:not(.sidebar-collapsed) .sidebar-footer { justify-content: center; }
  .app-shell:not(.sidebar-collapsed) .sidebar { width: 68px; padding: 16px 8px; }
  .app-shell:not(.sidebar-collapsed) .sidebar-header {
    flex-direction: column;
    justify-content: center;
    gap: 10px;
  }
  .app-shell:not(.sidebar-collapsed) .sidebar-header .brand-text { display: none; }
  .app-shell:not(.sidebar-collapsed) .brand { justify-content: center; }
}

/* Screenshot Panel */
.screenshot-panel {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--light-gray);
  border-radius: 12px;
  background: var(--surface-raised);
}

.screenshot-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.screenshot-panel-header h4 {
  margin: 0;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--navy);
}

.screenshot-panel-header .badge {
  font-size: 0.65rem;
}

.screenshot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
}

.screenshot-thumb {
  position: relative;
  border: 1px solid var(--light-gray);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  background: var(--white);
}

.screenshot-thumb:hover {
  transform: scale(1.03);
  box-shadow: 0 4px 16px rgba(0, 43, 92, 0.12);
}

.screenshot-thumb img {
  width: 100%;
  height: 110px;
  object-fit: cover;
  display: block;
}

.screenshot-thumb-label {
  padding: 6px 8px;
  font-size: 0.72rem;
  color: var(--dark-gray);
  background: var(--off-white);
  border-top: 1px solid var(--light-gray);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.screenshot-thumb-label .step-name {
  font-weight: 600;
  color: var(--navy);
}

.screenshot-thumb-label .step-time {
  color: var(--medium-gray);
  margin-left: 4px;
}

/* Batch inline screenshot thumbnail */
.batch-screenshot-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  vertical-align: middle;
}

.batch-screenshot-inline img {
  width: 40px;
  height: 28px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--light-gray);
  cursor: pointer;
}

.batch-screenshot-inline a {
  font-size: 0.78rem;
  color: var(--teal);
  text-decoration: none;
}

.batch-screenshot-inline a:hover {
  text-decoration: underline;
}

/* Screenshot Modal / Lightbox */
.screenshot-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: var(--modal-backdrop);
  display: grid;
  place-items: center;
  padding: 24px;
}

.screenshot-modal-content {
  position: relative;
  max-width: 92vw;
  max-height: 92vh;
  background: var(--white);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
}

.screenshot-modal-close {
  position: absolute;
  top: 8px;
  right: 12px;
  z-index: 10;
  background: var(--modal-close-bg);
  color: var(--white);
  border: 0;
  border-radius: 999px;
  width: 32px;
  height: 32px;
  font-size: 1.2rem;
  cursor: pointer;
  display: grid;
  place-items: center;
}

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

.screenshot-modal-content img {
  max-width: 90vw;
  max-height: 80vh;
  object-fit: contain;
}

.screenshot-modal-caption {
  padding: 12px 16px;
  font-size: 0.85rem;
  color: var(--dark-gray);
  background: var(--off-white);
  border-top: 1px solid var(--light-gray);
}

@media (min-width: 1600px) {
  .content {
    padding-inline: clamp(18px, 1.6vw, 36px);
  }

  .centered.wide {
    width: min(100%, 1700px);
  }

  .centered {
    width: min(100%, 960px);
  }

  .search-bar .search-input {
    font-size: 1.08rem;
    padding: 16px 52px 16px 48px;
  }

  .search-bar .search-icon {
    width: 22px;
    height: 22px;
    left: 16px;
  }
}

/* ===== Results Redesign ===== */

.results-view--accordion,
.results-view--card-grid,
.accordion-group,
.property-card,
.member-card-h,
.member-card-v,
.member-compact-item,
.slideout-panel,
.master-list,
.master-item,
.detail-pane,
.meta-chip,
.segmented-control,
.seg-btn,
.save-view-btn {
  transition: background 0.22s ease, color 0.22s ease, border-color 0.22s ease, box-shadow 0.22s ease;
}

/* -- Scrollable Results Area -- */
.results-container {
  margin-top: 8px;
}

.results-view--accordion,
.results-view--card-grid {
  max-height: calc(100vh - 280px);
  overflow-y: auto;
  border: 1px solid var(--light-gray);
  border-radius: 12px;
  background: var(--white);
}

.slideout-table-area .table-wrap {
  max-height: calc(100vh - 280px);
  overflow-y: auto;
}

#batch-results-grouped .results-view--accordion,
#batch-results-grouped .results-view--card-grid {
  max-height: calc(100vh - 320px);
}

/* -- Toggle Controls -- */
.view-toggles {
  display: flex;
  gap: 24px;
  align-items: center;
  padding: 12px 24px;
  margin-bottom: 12px;
}

.toggle-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.toggle-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--medium-gray);
}

.save-view-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  border: 1px solid var(--light-gray);
  background: var(--white);
  color: var(--medium-gray);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
  transition: all 0.15s ease;
}

.save-view-btn:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.save-view-btn.saved {
  background: var(--teal);
  border-color: var(--teal);
  color: var(--text-inverse);
}

.save-view-btn.saved:hover {
  background: var(--teal-hover);
  border-color: var(--teal-hover);
}

.save-view-label {
  pointer-events: none;
}

.segmented-control {
  display: flex;
  background: var(--off-white);
  border: 1px solid var(--light-gray);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
}

.seg-btn {
  border: 0;
  background: transparent;
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--medium-gray);
  display: grid;
  place-items: center;
  transition: all 0.15s ease;
}

.seg-btn:hover { color: var(--navy); background: var(--white); }
.seg-btn.active {
  background: var(--white);
  color: var(--teal);
  box-shadow: 0 1px 3px rgba(0, 43, 92, 0.12);
}

/* -- Results Container -- */
/* results-container styles consolidated above */

.results-view { animation: fadeIn 0.35s ease; }

/* -- SOS Status Badge -- */
.sos-badge {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  color: var(--text-inverse);
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.sos-badge--active { background: var(--success); }
.sos-badge--warning { background: var(--warning); }
.sos-badge--error { background: var(--error); }
.sos-badge--unknown { background: var(--medium-gray); }

/* -- Member Count Pill -- */
.member-count-pill {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--medium-gray);
  color: var(--text-inverse);
  white-space: nowrap;
}

/* -- Accordion View -- */
.accordion-group {
  background: var(--white);
  border: 1px solid var(--light-gray);
  border-radius: 12px;
  margin-bottom: 10px;
  box-shadow: 0 1px 3px rgba(0, 43, 92, 0.06);
  overflow: hidden;
}

.accordion-header {
  display: grid;
  grid-template-columns: 24px 1.5fr 0.7fr 0.7fr 1.2fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 14px 18px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease;
}

.accordion-header:hover { background: var(--teal-light); }

.accordion-chevron {
  font-size: 0.85rem;
  color: var(--medium-gray);
  transition: transform 0.2s ease;
  display: grid;
  place-items: center;
}

.accordion-group.open .accordion-chevron { transform: rotate(90deg); }

.accordion-prop-name {
  font-weight: 700;
  color: var(--navy);
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.accordion-location {
  font-size: 0.85rem;
  color: var(--dark-gray);
}

.accordion-mgmt {
  font-size: 0.85rem;
  color: var(--dark-gray);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.accordion-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.25s ease-out;
}

.accordion-group.open .accordion-body {
  max-height: 10000px;
  transition: max-height 0.5s ease-in;
}

.accordion-inner {
  padding: 0 18px 18px;
  border-top: 1px solid var(--light-gray);
}

/* -- Metadata Chips -- */
.meta-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 0;
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  padding: 4px 10px;
  background: var(--off-white);
  border: 1px solid var(--light-gray);
  border-radius: 6px;
  color: var(--dark-gray);
}

.meta-chip-label {
  font-weight: 600;
  color: var(--medium-gray);
}

.research-notes-line {
  font-size: 0.85rem;
  font-style: italic;
  color: var(--dark-gray);
  padding: 4px 0 8px;
  line-height: 1.5;
}

/* -- Member Cards: Horizontal (cards-h) -- */
.members-cards-h {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  padding-top: 12px;
}

.member-card-h {
  flex: 1 1 280px;
  max-width: 380px;
  background: var(--off-white);
  border: 1px solid var(--light-gray);
  border-radius: 10px;
  padding: 14px;
}

.member-card-h-header {
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--light-gray);
}

.member-card-h-name {
  font-weight: 700;
  font-size: 0.92rem;
  color: var(--navy);
}

.member-card-h-title {
  font-size: 0.8rem;
  color: var(--medium-gray);
  margin-top: 2px;
}

/* -- Member Cards: Sub-rows -- */
.members-sub-rows {
  padding-top: 12px;
}

.members-sub-rows table {
  width: 100%;
  border-collapse: collapse;
  min-width: 0;
}

.members-sub-rows th {
  background: var(--off-white);
  color: var(--navy);
  font-size: 0.72rem;
  padding: 8px 10px;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--light-gray);
  position: static;
}

.members-sub-rows td {
  padding: 8px 10px;
  font-size: 0.85rem;
  border-top: 1px solid var(--light-gray);
  vertical-align: top;
}

/* -- Member Cards: Vertical (cards-v) -- */
.members-cards-v {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 12px;
}

.member-card-v {
  background: var(--off-white);
  border: 1px solid var(--light-gray);
  border-radius: 10px;
  padding: 14px 18px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 24px;
}

.member-card-v-header {
  grid-column: 1 / -1;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--light-gray);
  margin-bottom: 4px;
}

/* -- Member Cards: Compact List -- */
.members-compact-list {
  padding-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.member-compact-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--off-white);
  border: 1px solid var(--light-gray);
  border-radius: 8px;
  font-size: 0.85rem;
  flex-wrap: wrap;
}

.member-compact-name {
  font-weight: 700;
  color: var(--navy);
  min-width: 140px;
}

.member-compact-title {
  color: var(--medium-gray);
  font-size: 0.8rem;
  min-width: 100px;
}

.member-compact-sep {
  color: var(--light-gray);
}

/* -- Contact Info -- */
.contact-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.83rem;
  padding: 3px 0;
  color: var(--dark-gray);
}

.contact-row svg {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  color: var(--medium-gray);
}

.contact-row a {
  color: var(--teal);
  text-decoration: none;
}

.contact-row a:hover { text-decoration: underline; }

.contact-row .copy-btn {
  opacity: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  color: var(--medium-gray);
  padding: 2px;
  font-size: 0.7rem;
  transition: opacity 0.15s;
}

.contact-row:hover .copy-btn { opacity: 1; }

/* -- Contact Icons inline (compact list) -- */
.contact-icons {
  display: flex;
  gap: 8px;
  align-items: center;
}

.contact-icon-link {
  color: var(--medium-gray);
  transition: color 0.15s;
  display: grid;
  place-items: center;
}

.contact-icon-link:hover { color: var(--teal); }

/* -- Citation Footer -- */
.citation-footer {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--light-gray);
  overflow: hidden;
  min-width: 0;
}

.citation-footer-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--medium-gray);
  margin-bottom: 6px;
}

.citation-footer-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.citation-footer-item {
  font-size: 0.78rem;
  color: var(--dark-gray);
  display: flex;
  gap: 6px;
  align-items: baseline;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.citation-footer-item .cid {
  font-weight: 700;
  color: var(--citation);
  flex-shrink: 0;
}

.citation-footer-item span:not(.cid) {
  min-width: 0;
  overflow: hidden;
}

.citation-footer-item a,
.citation-footer-item a.citation-url {
  color: var(--teal);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
  min-width: 0;
  max-width: 100%;
}

.citation-footer-item a:hover { text-decoration: underline; }

/* -- Table + Slideout View -- */
.results-view--table-slideout {
  display: flex;
  gap: 0;
}

.results-view--table-slideout.hidden { display: none; }

.slideout-table-area {
  flex: 1;
  min-width: 0;
  transition: flex 0.25s ease;
}

.slideout-panel {
  width: 420px;
  flex-shrink: 0;
  background: var(--white);
  border: 1px solid var(--light-gray);
  border-radius: 0 12px 12px 0;
  box-shadow: -4px 0 16px rgba(0, 43, 92, 0.08);
  overflow-y: auto;
  max-height: calc(100vh - 250px);
  position: relative;
  animation: slideInRight 0.2s ease;
}

.slideout-panel.hidden { display: none; }

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

.slideout-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--off-white);
  border: 1px solid var(--light-gray);
  border-radius: 999px;
  width: 28px;
  height: 28px;
  font-size: 1.1rem;
  cursor: pointer;
  display: grid;
  place-items: center;
  color: var(--medium-gray);
  z-index: 2;
}

.slideout-close:hover { background: var(--teal-light); color: var(--navy); }

.slideout-content {
  padding: 20px;
}

.slideout-prop-name {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--navy);
  padding-right: 36px;
}

/* Summary table row highlight */
.results-view--table-slideout tr.selected td {
  background: var(--teal-light);
}

.results-view--table-slideout table {
  min-width: 600px;
}

/* -- Card Grid View -- */
.results-view--card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 14px;
}

.results-view--card-grid.hidden { display: none; }

.property-card {
  background: var(--white);
  border: 1px solid var(--light-gray);
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 1px 3px rgba(0, 43, 92, 0.06);
  transition: box-shadow 0.15s ease;
  cursor: default;
}

.property-card:hover {
  box-shadow: 0 4px 16px rgba(0, 43, 92, 0.1);
}

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

.property-card-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--navy);
}

.property-card-location {
  font-size: 0.82rem;
  color: var(--medium-gray);
  margin-top: 2px;
}

.property-card-mgmt {
  font-size: 0.82rem;
  color: var(--dark-gray);
  margin-top: 6px;
}

.property-card-divider {
  height: 1px;
  background: var(--light-gray);
  margin: 12px 0;
}

/* -- Master-Detail View -- */
.results-view--master-detail {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 0;
  border: 1px solid var(--light-gray);
  border-radius: 12px;
  overflow: hidden;
  background: var(--white);
  height: calc(100vh - 280px);
}

.results-view--master-detail.hidden { display: none; }

.master-list {
  border-right: 1px solid var(--light-gray);
  overflow-y: hidden;
  overflow-y: scroll;
  scrollbar-width: none;
  background: var(--off-white);
  overscroll-behavior: contain;
}

.master-list::-webkit-scrollbar { width: 0; }
.master-list:hover { scrollbar-width: thin; }
.master-list:hover::-webkit-scrollbar { width: 6px; }
.master-list:hover::-webkit-scrollbar-thumb { background: var(--light-gray); border-radius: 3px; }

.master-item {
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--light-gray);
  transition: background 0.15s ease;
}

.master-item:hover { background: var(--white); }
.master-item.selected { background: var(--teal-light); border-left: 3px solid var(--teal); }

.master-item-name {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--navy);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.master-item-sub {
  font-size: 0.78rem;
  color: var(--medium-gray);
  margin-top: 2px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.detail-pane {
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
  overscroll-behavior: contain;
}

.detail-pane-empty {
  display: grid;
  place-items: center;
  height: 100%;
  color: var(--medium-gray);
  font-size: 0.92rem;
}

/* -- Empty State -- */
.results-empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--medium-gray);
  font-size: 0.92rem;
}

/* New item flash when streaming data arrives */
.new-item-flash {
  animation: flashHighlight 2s ease;
}

@keyframes flashHighlight {
  0% { background: var(--teal-light); }
  100% { background: transparent; }
}

@media (max-width: 768px) {
  .app-shell { grid-template-columns: 1fr; }
  .app-shell > .content { grid-column: 1; }
  .sidebar { position: sticky; width: auto; height: auto; z-index: 10; }
  .nav { grid-template-columns: repeat(4, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
}
