/* =====================================================================
   INTERFACE — design tokens
   A light structural-biology console: paper-white ground, cyan/amber
   duotone for receptor/ligand, plex mono for residue data, plex sans
   for chrome.
   ===================================================================== */

:root {
  --bg: #f4f6f8;
  --bg-panel: #ffffff;
  --bg-panel-2: #f7f9fb;
  --bg-raised: #eef1f5;
  --border: #d7dee5;
  --border-soft: #e4e9ee;

  --text: #1f2933;
  --text-muted: #64748b;
  --text-faint: #9aa5b1;

  --receptor: #1f8fc2;
  --receptor-dim: #d3edf8;
  --ligand: #d97f1f;
  --ligand-dim: #fbe6cd;

  --accent: #1f9b7f;
  --accent-dim: #d7f3ea;
  --danger: #d64545;

  --hbond: #1f8fc2;
  --salt: #d64545;
  --hydrophobic: #5c9a4b;
  --pipi: #9a5bc9;
  --cationpi: #d97f1f;
  --vdw: #7c8894;
  --disulfide: #c99a1a;

  --font-ui: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-data: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;

  --radius-sm: 3px;
  --radius-md: 6px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

/* Stable desktop base size.  Keep the desktop UI at the same visual scale
   across 11", 14", 15" and large desktop displays.  Responsive rules below
   adjust available widths/spacing rather than shrinking the whole interface. */
html {
  font-size: 15px;
}

/* Large screens get more room, not smaller controls. */
@media (min-width: 1600px) {
  html {
    font-size: 15px;
  }
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 1rem;
  font-weight: 600;
  -webkit-font-smoothing: antialiased;
}

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

button,
select,
input {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

::selection {
  background: var(--accent-dim);
}

/* subtle background texture: faint grid, evokes a schematic/instrument console */
body {
  background-image:
    linear-gradient(rgba(15, 23, 32, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(15, 23, 32, 0.035) 1px, transparent 1px);
  background-size: 28px 28px;
}

/* ===================== TOP BAR ===================== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 10px 20px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: nowrap;
  min-width: 0;
}

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

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

.brand-title {
  font-family: var(--font-data);
  font-weight: 800;
  font-size: 1.3333rem;
  letter-spacing: 0.14em;
  color: var(--text);
}

.brand-sub {
  font-size: 0.9333rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}

/* ===================== LAB LOGO SLOT ===================== */
.lab-logo-slot {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 66px;
  height: 66px;
  flex-shrink: 0;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-faint);
  overflow: hidden;
  margin-right: 4px;
}

.lab-logo-slot img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.lab-logo-slot .lab-logo-placeholder {
  font-family: var(--font-data);
  font-size: 0.7333rem;
  text-align: center;
  line-height: 1.3;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.topbar-controls {
  display: flex;
  align-items: flex-end;
  gap: 18px;
  flex-wrap: nowrap;
  min-width: 0;
}

.ctrl-label {
  display: block;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.file-upload-btn {
  display: inline-flex;
  align-items: center;
  height: 34px;
  width: 220px;
  /* fixed so the control doesn't grow/shrink with the filename */
  flex: 0 0 220px;
  padding: 0 14px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius-md);
  border-color: var(--text-faint);
  background: var(--bg-panel-2);
  color: var(--text);
  font-size: 0.9333rem;
  cursor: pointer;
  transition: border-color .15s ease, color .15s ease;
  white-space: nowrap;
  align-self: flex-end;
  justify-content: center;
}

.file-upload-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

#upload-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
  min-width: 0;
}

.chain-select-group {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.swap-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  margin-bottom: 1px;
  transition: color .15s ease, border-color .15s ease;
}

.swap-icon:hover {
  color: var(--accent);
  border-color: var(--accent);
}

select,
.cutoff-group input,
#residue-search {
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: 6px 8px;
  height: 34px;
  font-family: var(--font-data);
  font-size: 0.9667rem;
}

select {
  min-width: 130px;
}

select#receptor-select {
  border-left: 3px solid var(--receptor);
}

select#ligand-select {
  border-left: 3px solid var(--ligand);
}

select:disabled,
.file-upload-btn input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.cutoff-group {
  display: flex;
  flex-direction: column;
}

.cutoff-group>div,
.cutoff-group {
  position: relative;
}

#cutoff-input {
  width: 76px;
}

.cutoff-group .unit {
  position: absolute;
  right: 10px;
  bottom: 9px;
  font-size: 0.8667rem;
  color: var(--text-muted);
  pointer-events: none;
}

.primary-btn {
  height: 34px;
  padding: 0 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.9667rem;
  letter-spacing: 0.02em;
  transition: background .15s ease, transform .05s ease;
}

.primary-btn:hover:not(:disabled) {
  background: rgba(31, 155, 127, 0.20);
}

.primary-btn:active:not(:disabled) {
  transform: translateY(1px);
}

.primary-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  border-color: var(--border);
  background: transparent;
  color: var(--text-muted);
}

.status-banner {
  padding: 8px 20px;
  font-size: 0.9333rem;
  font-family: var(--font-data);
  border-bottom: 1px solid var(--border);
}

.status-banner.error {
  background: rgba(214, 69, 69, 0.08);
  color: var(--danger);
}

.status-banner.info {
  background: rgba(31, 143, 194, 0.08);
  color: var(--receptor);
}

.status-banner.success {
  background: rgba(31, 155, 127, 0.08);
  color: var(--accent);
}

.status-banner.hidden {
  display: none;
}

/* ===================== HELP / CONTACT MODAL ===================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 32, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal-overlay.hidden {
  display: none;
}

.modal-panel {
  width: 100%;
  max-width: 560px;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 12px 32px rgba(15, 23, 32, 0.22);
  overflow: hidden;
}

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

.modal-header h2 {
  margin: 0;
  font-size: 0.9333rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
}

.help-section {
  margin-bottom: 18px;
}

.help-section:last-child {
  margin-bottom: 0;
}

.help-section h3 {
  margin: 0 0 8px 0;
  font-size: 0.7333rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 600;
}

.help-section p {
  margin: 0 0 6px 0;
  font-size: 0.8333rem;
  line-height: 1.6;
  color: var(--text);
}

.help-section ul {
  margin: 0;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.help-section li {
  font-size: 0.8333rem;
  line-height: 1.55;
  color: var(--text);
}

.help-section code {
  font-family: var(--font-data);
  font-size: 0.7667rem;
  background: var(--bg-raised);
  padding: 1px 5px;
  border-radius: 3px;
}

.help-section a {
  color: var(--accent);
  font-weight: 600;
}


/* ===================== STABLE TOP BAR =====================
   Keep the desktop header on a single fixed-height row. Dynamic text,
   uploaded filenames, status messages, and control state changes must
   never cause the header controls to wrap onto a second row. */
@media (min-width: 761px) {
  .topbar {
    flex-wrap: nowrap;
    min-width: 0;
    overflow: hidden;
  }

  .brand {
    flex: 0 0 auto;
    min-width: 0;
  }

  .topbar-controls {
    /* Keep the brand anchored at the far left and the toolbar grouped
       at the far right on every non-mobile display. */
    flex: 0 1 auto;
    margin-left: auto;
    min-width: 0;
    flex-wrap: nowrap;
    justify-content: flex-end;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }

  .topbar-controls::-webkit-scrollbar {
    display: none;
  }

  .topbar-controls>* {
    flex: 0 0 auto;
  }

  /* Keep Analyze visible at the right edge when the toolbar is wider than the viewport. */
  .topbar-controls #analyze-btn {
    position: sticky;
    right: 0;
    z-index: 2;
  }
}

/* ===================== MAIN BODY ===================== */
.main-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* ---- sidebar ---- */
.sidebar {
  width: 280px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--bg-panel);
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.pdb-fetch-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.pdb-fetch-row .file-upload-btn {
  width: auto;
  min-width: 0;
  flex: 1 1 auto;
  height: 34px;
  padding: 0 10px;
  justify-content: center;
  align-self: center;
}

#pdb-id-input {
  width: 96px;
  height: 34px;
  box-sizing: border-box;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#pdb-id-input::placeholder {
  text-transform: none;
  letter-spacing: normal;
  color: var(--text-faint);
  text-align: center;
}

.pdb-fetch-row .chip-btn {
  flex: none;
  height: 34px;
  padding: 0 14px;
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.pdb-fetch-row .chip-btn:hover {
  background: rgba(31, 155, 127, 0.20);
}

.pdb-fetch-row .chip-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.panel-title-row .panel-title {
  margin: 0;
}

.panel-title-row .icon-btn {
  width: 22px;
  height: 22px;
  font-size: 0.8667rem;
}

.panel {
  background: var(--bg-panel-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  padding: 12px;
  box-shadow: 0 1px 2px rgba(31, 41, 51, 0.04);
}

.panel-title {
  margin: 0 0 10px 0;
  font-size: 0.8333rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-muted);
  font-weight: 700;
}

.type-toggles {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.type-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .12s ease;
  user-select: none;
}

.type-toggle:hover {
  background: var(--bg-raised);
}

.type-toggle input {
  accent-color: var(--accent);
}

.type-toggle .swatch {
  width: 18px;
  height: 0;
  border-top-width: 3px;
  border-top-style: solid;
  flex-shrink: 0;
}

.type-toggle .tt-label {
  font-size: 0.9333rem;
  flex: 1;
}

.type-toggle .tt-count {
  font-family: var(--font-data);
  font-size: 0.8667rem;
  color: var(--text-muted);
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 8px;
}

.type-toggle.disabled-type .tt-label {
  color: var(--text-faint);
}

.toggle-row-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

.chip-btn {
  flex: 1;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.8667rem;
  padding: 6px 4px;
  transition: color .12s ease, border-color .12s ease;
}

.chip-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}

.filter-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.radio-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.9333rem;
  cursor: pointer;
}

.radio-row input {
  accent-color: var(--accent);
}

#residue-search {
  width: 100%;
}

.search-results {
  margin-top: 8px;
  max-height: 150px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.search-hit {
  font-family: var(--font-data);
  font-size: 0.9rem;
  padding: 5px 7px;
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 6px;
}

.search-hit:hover {
  outline: 1px solid var(--accent);
}

.search-hit .side-tag {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.legend-body {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.legend-line {
  width: 22px;
  height: 0;
  border-top-width: 2.5px;
  flex-shrink: 0;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

.summary-body {
  font-size: 0.9333rem;
  color: var(--text-muted);
  line-height: 1.7;
}

.summary-body .stat-row {
  display: flex;
  justify-content: space-between;
}

.summary-body .stat-row b {
  color: var(--text);
  font-family: var(--font-data);
  font-weight: 700;
}

.muted-note {
  color: var(--text-faint);
  font-size: 0.9rem;
  line-height: 1.5;
  margin: 0;
}

/* ===================== MODE TABS ===================== */
.mode-tabs {
  display: flex;
  align-self: flex-end;
  gap: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  height: 34px;
}

.mode-tab {
  background: var(--bg-panel-2);
  color: var(--text-muted);
  border: none;
  padding: 0 12px;
  font-size: 0.9rem;
  font-family: var(--font-data);
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}

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

.mode-tab.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 700;
}

.hidden {
  display: none !important;
}

/* ===================== APPEARANCE PANEL ===================== */
.color-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.color-swatch-label {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 0.9333rem;
  cursor: pointer;
}

.color-swatch-label input[type="color"] {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: none;
  cursor: pointer;
  flex-shrink: 0;
}

/* ===================== RECENT UPLOADS ===================== */
.uploads-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
}

.upload-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--bg-raised);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 7px 8px;
}

.upload-row.active-upload {
  border-color: var(--accent);
}

.upload-row-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}

.upload-row-name {
  font-size: 0.9rem;
  font-family: var(--font-data);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-row-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.upload-row-actions {
  display: flex;
  gap: 5px;
  margin-top: 4px;
}

.upload-row-actions button {
  flex: 1;
  font-size: 0.8rem;
  padding: 4px 2px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-panel-2);
  color: var(--text-muted);
}

.upload-row-actions button:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.upload-row-actions button.danger:hover {
  color: var(--danger);
  border-color: var(--danger);
}

/* ===================== CENTER COLUMN / VIEWER GRID ===================== */
.center-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.viewer-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-width: 0;
  min-height: 0;
}

.viewer-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-right: 1px solid var(--border);
}

.viewer-pane:last-child {
  border-right: none;
}

.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  flex-shrink: 0;
}

.pane-title {
  font-size: 0.8667rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 700;
}

.pane-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pane-divider {
  width: 1px;
  height: 16px;
  background: var(--border);
  margin: 0 4px;
}

.icon-btn {
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-panel-2);
  color: var(--text-muted);
  font-size: 1rem;
  transition: color .12s ease, border-color .12s ease;
}

.icon-btn.text-icon {
  width: auto;
  padding: 0 8px;
  font-family: var(--font-data);
  font-size: 0.8333rem;
  letter-spacing: 0.03em;
}

.icon-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.pane-body {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}

.viewer3d-container {
  position: absolute;
  inset: 0;
}

.diagram-scroll {
  position: absolute;
  inset: 0;
  overflow: auto;
}

#diagram-svg {
  display: block;
}

.placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 0.9333rem;
  text-align: center;
  padding: 20px;
}

.placeholder.hidden {
  display: none;
}

.distance-readout {
  position: absolute;
  bottom: 12px;
  left: 12px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-family: var(--font-data);
  font-size: 0.9rem;
  line-height: 1.6;
  max-width: 280px;
}

.distance-readout.hidden {
  display: none;
}

.distance-readout .dr-title {
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 2px;
}

/* ===================== FLOATING HELP BUTTON ===================== */
.floating-help-btn {
  position: fixed;
  right: 22px;
  bottom: 22px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 1.0667rem;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(15, 23, 32, 0.18);
  z-index: 50;
  transition: color .15s ease, border-color .15s ease, transform .12s ease, box-shadow .15s ease;
}

.floating-help-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 8px 22px rgba(15, 23, 32, 0.24);
  transform: translateY(-1px);
}

.floating-help-btn:active {
  transform: translateY(0);
}

.pane-body {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
}

.viewer3d-container {
  position: absolute;
  inset: 0;
}

.diagram-scroll {
  position: absolute;
  inset: 0;
  overflow: auto;
}

#diagram-svg {
  display: block;
}

.placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 0.8rem;
  text-align: center;
  padding: 20px;
}

.placeholder.hidden {
  display: none;
}

.distance-readout {
  position: absolute;
  bottom: 12px;
  left: 12px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-family: var(--font-data);
  font-size: 0.7667rem;
  line-height: 1.6;
  max-width: 280px;
}

.distance-readout.hidden {
  display: none;
}

.distance-readout .dr-title {
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 2px;
}

/* ===================== 2D DIAGRAM SVG ELEMENTS ===================== */
/* (base rules; most styling for generated nodes/edges is inline via app.js
   so exported SVGs remain fully self-contained) */
.res-chip {
  cursor: grab;
  touch-action: none;
}

.res-chip:active,
.res-chip.dragging {
  cursor: grabbing;
}

.res-chip:hover .res-chip-bg {
  stroke: var(--accent) !important;
  stroke-width: 2px;
}

.res-chip.highlighted .res-chip-bg {
  stroke: #1f2933 !important;
  stroke-width: 2.2px;
}

.res-chip.dimmed {
  opacity: 0.22;
}

/* the ligand hub is clickable (for selection) but not draggable */
.res-chip.lig-hub,
.res-chip.lig-hub-chem {
  cursor: pointer;
  touch-action: auto;
}

.interaction-edge {
  cursor: pointer;
}

.interaction-edge.dimmed {
  opacity: 0.08;
}

.interaction-edge.highlighted {
  opacity: 1;
  filter: drop-shadow(0 0 2px rgba(31, 41, 51, 0.35));
}

/* fullscreen panes */
.viewer-pane:fullscreen {
  background: var(--bg);
  padding: 0;
}

.viewer-pane:fullscreen .pane-body {
  flex: 1;
}

.viewer-pane:-webkit-full-screen {
  background: var(--bg);
}

.viewer-pane:-webkit-full-screen .pane-body {
  flex: 1;
}

/* ===================== INTERACTION TABLE DRAWER ===================== */
.table-drawer {
  position: relative;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  max-height: 46vh;
}

.table-drawer.collapsed .table-drawer-body {
  display: none;
}

.table-drawer.collapsed {
  max-height: none;
}

.table-drawer-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  padding-right: 190px;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.table-drawer-count {
  font-family: var(--font-data);
  font-size: 0.8667rem;
  color: var(--text-muted);
  background: var(--bg-raised);
  padding: 1px 7px;
  border-radius: 8px;
}

.table-export-actions {
  position: absolute;
  top: 4px;
  right: 14px;
  z-index: 2;
}

.drawer-spacer {
  flex: 1;
}

.drawer-chevron {
  color: var(--text-muted);
  font-size: 0.8667rem;
  transition: transform .15s ease;
}

.table-drawer.collapsed .drawer-chevron {
  transform: rotate(180deg);
}

.table-drawer-body {
  overflow: auto;
  min-height: 0;
}

.table-scroll {
  overflow: auto;
}

#interaction-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-data);
  font-size: 0.9rem;
}

#interaction-table thead th {
  position: sticky;
  top: 0;
  background: var(--bg-panel-2);
  color: var(--text-muted);
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  font-size: 0.8333rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#interaction-table thead th:hover {
  color: var(--accent);
}

#interaction-table thead th.sorted-asc::after {
  content: " \25B2";
  font-size: 0.7667rem;
}

#interaction-table thead th.sorted-desc::after {
  content: " \25BC";
  font-size: 0.7667rem;
}

#interaction-table tbody td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}

#interaction-table tbody td.detail-cell {
  white-space: normal;
  color: var(--text-muted);
  font-size: 0.8667rem;
}

#interaction-table tbody tr {
  cursor: pointer;
  transition: background .1s ease;
}

#interaction-table tbody tr:hover {
  background: var(--bg-raised);
}

#interaction-table tbody tr.row-selected {
  background: rgba(31, 155, 127, 0.12);
}

#interaction-table .type-pill {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 9px;
  font-size: 0.8rem;
  border: 1px solid currentColor;
}

.table-empty {
  padding: 14px !important;
  white-space: normal !important;
}

/* ===================== SCROLLBARS ===================== */
::-webkit-scrollbar {
  width: 9px;
  height: 9px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-faint);
}

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

/* ---- Narrow desktop (11" class / small laptop widths) ---- */
@media (min-width: 981px) and (max-width: 1199px) {
  .topbar {
    gap: 10px;
    padding: 8px 12px;
  }

  .topbar-controls {
    gap: 8px;
    flex: 1 1 auto;
    justify-content: flex-end;
  }

  .brand-title {
    font-size: 1.15rem;
  }

  .brand-sub {
    font-size: 0.8rem;
  }

  .lab-logo-slot {
    width: 54px;
    height: 54px;
    margin-right: 2px;
  }

  .file-upload-btn {
    width: 185px;
    flex-basis: 185px;
    padding: 0 10px;
  }

  .chain-select-group {
    gap: 5px;
  }

  select {
    min-width: 105px;
  }

  .swap-icon {
    width: 25px;
    height: 25px;
  }

  #cutoff-input {
    width: 68px;
  }

  .primary-btn {
    padding: 0 12px;
  }
}

/* ---- Standard laptop / 14-15" class ---- */
@media (min-width: 1200px) and (max-width: 1599px) {
  .topbar {
    gap: 16px;
    padding: 10px 18px;
  }

  .topbar-controls {
    gap: 14px;
  }
}

/* ---- Large desktop: preserve the same usable UI scale and arrangement ---- */
@media (min-width: 1600px) {
  .topbar {
    gap: 18px;
    padding: 10px 22px;
  }

  .topbar-controls {
    gap: 16px;
  }
}

/* ---- Tablet / narrow desktop: stack the 3D and 2D panes vertically,
   let the sidebar wrap its panels into a flexible row instead of one
   long column ---- */
@media (max-width: 980px) {
  .viewer-grid {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr 1fr;
  }

  .viewer-pane {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .main-body {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    max-height: 40vh;
  }

  .sidebar .panel {
    flex: 1 1 260px;
  }
}

/* ---- Small tablet / large phone (landscape) ---- */
@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
  }

  .topbar-controls {
    width: 100%;
    align-items: stretch;
  }

  .chain-select-group {
    flex: 1 1 auto;
  }

  select {
    min-width: 100px;
  }
}

/* Mobile-only upload control: keeps the original mobile arrangement without
   changing the existing file input or application logic. */
.mobile-local-upload-btn {
  display: none;
}

/* Mobile-only PDB controls. These proxy the existing desktop controls without
   changing app.js or its IDs, so the application logic remains untouched. */
.mobile-pdb-fetch {
  display: none;
}

.mobile-pdb-fetch-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.mobile-pdb-fetch-row input {
  flex: 1 1 auto;
  min-width: 0;
  height: 34px;
}

.mobile-pdb-fetch-row .chip-btn {
  height: 34px;
  flex: 0 0 auto;
}

.mobile-pdb-note {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 0.78rem;
  line-height: 1.45;
}

/* ---- Phone ---- */
@media (max-width: 560px) {

  html,
  body {
    height: auto;
    min-height: 100%;
  }

  #app {
    height: auto;
    min-height: 100vh;
  }

  body {
    overflow-x: hidden;
  }

  /* Mobile order: brand -> mode tabs -> divider -> upload -> PDB fetch ->
     receptor/ligand -> cutoff -> analyze. Existing application elements are
     retained; only their visual order is changed. */
  .topbar {
    position: relative;
    padding: 10px 12px;
    gap: 10px;
  }

  .brand {
    width: 100%;
    justify-content: center;
  }

  .lab-logo-slot {
    width: 44px;
    height: 44px;
  }

  .brand-title {
    font-size: 1rem;
  }

  .topbar-controls {
    width: 100%;
    gap: 10px;
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  .mode-tabs {
    order: 1;
    align-self: auto;
    width: 100%;
  }

  .mode-tab {
    flex: 1;
    padding: 0 6px;
  }

  .mobile-local-upload-btn {
    order: 2;
    display: flex;
    width: 100%;
    flex: 0 0 34px;
    justify-content: center;
    align-items: center;
    height: 34px;
    box-sizing: border-box;
    padding: 0 10px;
    margin-top: 2px;
    border-top: 1px solid var(--border);
  }

  .mobile-pdb-fetch {
    order: 3;
    display: block;
    width: 100%;
  }

  .sidebar #local-upload-panel,
  .sidebar #pdb-fetch-panel {
    display: none;
  }

  #pp-controls,
  #pl-controls {
    order: 4;
    width: 100%;
    flex-wrap: wrap;
    row-gap: 8px;
  }

  .chain-select-group label {
    flex: 1 1 42%;
  }

  select {
    width: 100%;
    min-width: 0;
  }

  .swap-icon {
    margin-bottom: 9px;
  }

  .cutoff-group {
    order: 5;
    width: 100%;
  }

  #cutoff-input {
    width: 100%;
  }

  #analyze-btn {
    order: 6;
    width: 100%;
  }

  .primary-btn {
    width: 100%;
  }

  /* sidebar: single column again, no fixed cap on height */
  .sidebar {
    flex-direction: column;
    flex-wrap: nowrap;
    max-height: none;
    overflow-y: visible;
  }

  .sidebar .panel {
    flex: 1 1 auto;
  }

  /* viewer panes: fixed practical heights instead of splitting an
     already-short viewport, so the page scrolls instead of clipping */
  .viewer-grid {
    grid-template-rows: auto auto;
  }

  .viewer-pane {
    min-height: 380px;
  }

  .pane-body {
    min-height: 320px;
  }

  .pane-header {
    flex-wrap: wrap;
    row-gap: 6px;
  }

  .pane-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
    row-gap: 4px;
  }

  .table-drawer {
    max-height: 56vh;
  }

  #interaction-table {
    font-size: 0.8333rem;
  }

  #interaction-table thead th,
  #interaction-table tbody td {
    padding: 6px 7px;
  }
}

/* ---- Laptop / desktop polish ----
   Above the tablet breakpoint the two-pane layout is already active;
   these rules just tune proportions so the app doesn't feel oddly
   narrow-sidebar-vs-huge-panes on wide monitors, or cramped on
   short 1366x768-style laptop panels. ---- */

/* let the sidebar breathe a little on wider desktops instead of
   staying pinned at 280px all the way up to ultrawide */
@media (min-width: 981px) {
  .sidebar {
    width: 320px;
    flex: 0 0 320px;
  }
}

@media (min-width: 1600px) {
  .sidebar {
    width: 320px;
    flex-basis: 320px;
  }
}

/* extra padding/spacing once there's real room to spare */

/* short-height laptop screens (e.g. 1366x768): claw back vertical
   space from chrome so the 3D/2D panes and table drawer aren't
   squeezed into a sliver */
@media (max-height: 800px) and (min-width: 981px) {
  .topbar {
    padding: 8px 20px;
  }

  .sidebar {
    padding: 12px;
    gap: 10px;
  }

  .panel {
    padding: 10px;
  }

  .table-drawer {
    max-height: 34vh;
  }
}

/* keyboard focus visibility */
a:focus-visible,
button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}

/* Local file upload module - layout only */
.local-upload-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.local-upload-row .file-upload-btn {
  width: auto;
  min-width: 92px;
}

/* Final mobile layout correction: keep the mobile top controls in a single
   vertical flow. This is CSS-only and does not alter application logic. */
@media (max-width:560px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    width: 100%;
    overflow: visible;
  }

  .topbar .brand {
    position: relative;
    width: 100%;
    min-height: 44px;
    padding-right: 42px;
  }

  .topbar-controls {
    width: 100%;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .mode-tabs {
    order: 1;
    width: 100%;
    display: flex;
    margin-bottom: 2px;
  }

  .mode-tab {
    min-width: 0;
  }

  .mobile-local-upload-btn {
    order: 2;
    width: 100%;
    margin-top: 6px;
    border-top: 1px solid var(--border);
    padding-top: 10px;
  }

  .mobile-pdb-fetch {
    order: 3;
    width: 100%;
  }

  #pp-controls,
  #pl-controls {
    order: 4;
    width: 100%;
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
  }

  #pp-controls label,
  #pl-controls label {
    flex: 1 1 0;
    min-width: 0;
  }

  #pp-controls .swap-icon {
    flex: 0 0 28px;
  }

  .cutoff-group {
    order: 5;
    width: 100%;
  }

  #analyze-btn {
    order: 6;
    width: 100%;
    min-height: 34px;
  }

  /* The upload/PDB controls are now represented in the mobile top section;
     avoid duplicate desktop sidebar copies on phones. */
  .sidebar #local-upload-panel,
  .sidebar #pdb-fetch-panel {
    display: none;
  }

  .theme-toggle-btn {
    display: flex !important;
    position: fixed;
    top: 8px;
    right: 8px;
    bottom: auto;
    width: 34px;
    height: 34px;
    z-index: 9999;
  }
}