:root {
  --ncbi-blue: #205493;
  --ncbi-blue-dark: #112e51;
  --ncbi-light: #f5f7fb;
  --ncbi-border: #c8d0da;
  --ncbi-text: #1f2937;
  --ncbi-muted: #5b6472;
  --ncbi-accent: #0071bc;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Helvetica Neue", "Segoe UI", Arial, sans-serif;
  color: var(--ncbi-text);
}

.ncbi-bg {
  min-height: 100vh;
  background: linear-gradient(180deg, #e9eef6 0%, #f8fafc 100%);
}

.ncbi-topbar {
  background: var(--ncbi-blue-dark);
  color: #fff;
  font-size: 0.9rem;
  padding: 10px 16px;
  border-radius: 8px 8px 0 0;
}

.login-wrapper {
  max-width: 520px;
  margin: 70px auto;
  border: 1px solid var(--ncbi-border);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.08);
}

.login-card {
  padding: 28px;
}

.page-title {
  margin: 0;
  font-size: 1.6rem;
  color: var(--ncbi-blue-dark);
}

.muted {
  color: var(--ncbi-muted);
}

.error-msg {
  margin: 12px 0;
  padding: 10px;
  border: 1px solid #f5c2c7;
  background: #f8d7da;
  color: #842029;
  border-radius: 6px;
}

.form-grid {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

label {
  font-weight: 600;
}

input {
  padding: 10px;
  border: 1px solid var(--ncbi-border);
  border-radius: 6px;
  font-size: 1rem;
}

.ncbi-btn {
  margin-top: 8px;
  background: var(--ncbi-blue);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 10px 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}

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

.ncbi-btn.ghost {
  margin-top: 0;
  background: #f1f5fb;
  color: var(--ncbi-blue-dark);
  border: 1px solid #c2d0e2;
}

.ncbi-btn.ghost:hover {
  background: #e5edf8;
}

.small {
  padding: 6px 10px;
  font-size: 0.9rem;
}

.ncbi-header {
  background: #fff;
  border-bottom: 2px solid var(--ncbi-blue);
  padding: 20px 28px;
}

.brand-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
}

.ncbi-tag {
  font-size: 0.82rem;
  color: var(--ncbi-accent);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.account-row {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--ncbi-muted);
}

.subline {
  margin-top: 6px;
  color: var(--ncbi-muted);
}

.panel-container {
  max-width: 1040px;
  margin: 22px auto;
  background: #fff;
  border: 1px solid var(--ncbi-border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.06);
}

.tab-nav {
  display: flex;
  gap: 1px;
  background: #d9e2ef;
  overflow-x: auto;
}

.tab-btn {
  flex: 1;
  min-width: 180px;
  border: none;
  background: #edf2f8;
  padding: 12px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ncbi-blue-dark);
  cursor: pointer;
}

.tab-btn.active {
  background: #fff;
  border-bottom: 3px solid var(--ncbi-accent);
}

.tab-panel {
  display: none;
  padding: 22px;
}

.tab-panel.active {
  display: block;
}

.sub-title {
  margin: 16px 0 8px;
  color: var(--ncbi-blue-dark);
  font-size: 1rem;
}

.code-block {
  margin: 14px 0;
  padding: 14px;
  border: 1px solid var(--ncbi-border);
  border-radius: 8px;
  background: var(--ncbi-light);
  overflow: auto;
}

.phylo-toolbar {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.tree-toolbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.tree-toolbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.tree-switch {
  display: inline-flex;
  border: 1px solid var(--ncbi-border);
  border-radius: 8px;
  overflow: hidden;
}

.tree-switch-btn {
  border: none;
  background: #eff3f9;
  color: var(--ncbi-blue-dark);
  padding: 8px 14px;
  cursor: pointer;
  font-weight: 600;
}

.tree-switch-btn + .tree-switch-btn {
  border-left: 1px solid var(--ncbi-border);
}

.tree-switch-btn.active {
  background: #d9e6f6;
}

.tree-current {
  font-size: 0.92rem;
  color: var(--ncbi-muted);
}

.reroot-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.86rem;
  color: var(--ncbi-muted);
  user-select: none;
}

.reroot-toggle input {
  width: 16px;
  height: 16px;
  margin: 0;
}

.length-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.86rem;
  color: var(--ncbi-muted);
}

.length-control input[type='range'] {
  width: 130px;
  padding: 0;
  border: none;
}

.phylo-layout {
  margin-top: 14px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 14px;
}

.phylo-main {
  min-width: 0;
}

.tree-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-bottom: 10px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  color: var(--ncbi-muted);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.15);
}

.tree-canvas-wrap {
  border: 1px solid var(--ncbi-border);
  border-radius: 8px;
  overflow: auto;
  background: #fcfdff;
}

.phylo-tree-svg {
  display: block;
  width: auto;
  min-height: 320px;
}

.tree-branch {
  stroke: #8a95a6;
  stroke-width: 1.1;
  fill: none;
}

.tree-branch.is-selected {
  stroke: #d9480f;
  stroke-width: 2.2;
}

.tree-leaf-dot {
  stroke: #fff;
  stroke-width: 1;
}

.tree-label {
  font-size: 12px;
  dominant-baseline: middle;
  cursor: pointer;
}

.tree-label.is-muted {
  opacity: 0.25;
}

.tree-label.is-match {
  font-weight: 700;
}

.tree-label.is-selected {
  font-weight: 700;
  text-decoration: underline;
}

.tree-status {
  margin-top: 8px;
  font-size: 0.88rem;
}

.tree-nearest {
  margin-top: 8px;
  font-size: 0.86rem;
}

.tree-sidebar {
  border: 1px solid var(--ncbi-border);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdff;
  display: grid;
  gap: 8px;
  align-content: start;
}

.tree-sidebar label {
  font-size: 0.86rem;
  color: var(--ncbi-muted);
}

.tree-results {
  font-size: 0.84rem;
}

.sequence-list {
  border: 1px solid #dbe4f0;
  border-radius: 6px;
  background: #fff;
  max-height: 480px;
  overflow: auto;
}

.seq-item {
  width: 100%;
  border: none;
  border-bottom: 1px solid #edf2f8;
  background: transparent;
  text-align: left;
  padding: 8px 10px;
  cursor: pointer;
  display: grid;
  gap: 2px;
}

.seq-item:last-child {
  border-bottom: none;
}

.seq-item:hover {
  background: #f3f7fc;
}

.seq-item.is-selected {
  background: #dbe9f8;
}

.seq-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.seq-accession {
  font-size: 0.78rem;
  color: #64748b;
}

.seq-name {
  font-weight: 700;
  color: var(--ncbi-blue-dark);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seq-host,
.seq-strain {
  color: var(--ncbi-muted);
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-context-menu {
  position: fixed;
  z-index: 1000;
  min-width: 180px;
  border: 1px solid var(--ncbi-border);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.18);
  padding: 6px;
  display: none;
}

.tree-context-menu.open {
  display: block;
}

.tree-context-item {
  width: 100%;
  border: none;
  background: transparent;
  text-align: left;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--ncbi-blue-dark);
  font-size: 0.88rem;
}

.tree-context-item:hover {
  background: #eef4fc;
}

.msa-widget {
  margin-top: 12px;
}

.msa-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  align-items: end;
}

.msa-controls label {
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
  font-weight: 600;
}

.msa-controls input,
.msa-controls select {
  width: 100%;
  padding: 9px 10px;
}

.msa-filter-box {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid var(--ncbi-border);
  border-radius: 8px;
  background: #f7faff;
}

.msa-filter-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.msa-filter-actions {
  display: flex;
  gap: 8px;
}

.msa-species-list {
  max-height: 180px;
  overflow: auto;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 6px 12px;
}

.msa-species-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  font-weight: 500;
  min-width: 0;
}

.msa-species-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msa-summary {
  margin: 12px 0 6px;
}

.msa-viewer {
  font-family: "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.82rem;
  line-height: 1.35;
}

.msa-block {
  margin-bottom: 10px;
}

.msa-block-title {
  margin-bottom: 6px;
  color: var(--ncbi-blue-dark);
  font-weight: 700;
}

.msa-row {
  display: grid;
  grid-template-columns: minmax(170px, 240px) 1fr;
  gap: 8px;
  align-items: start;
  margin: 1px 0;
}

.msa-label {
  color: #334155;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.msa-seq {
  white-space: pre;
  color: #1f2937;
  letter-spacing: 0.02em;
}

.msa-token {
  border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.08);
}

.msa-ruler .msa-label {
  color: #475569;
  font-weight: 700;
}

.msa-ruler .msa-seq {
  color: #1d4ed8;
}

.structure-toolbar {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid var(--ncbi-border);
  border-radius: 8px;
  background: #f7faff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.structure-toolbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.structure-select-list {
  margin-top: 10px;
  border: 1px solid var(--ncbi-border);
  border-radius: 8px;
  background: #fbfdff;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 8px 12px;
  max-height: 220px;
  overflow: auto;
}

.structure-select-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  color: #334155;
}

.structure-select-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.structure-viewer-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 12px;
}

.structure-card {
  border: 1px solid var(--ncbi-border);
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
}

.structure-card-head {
  padding: 8px 10px;
  border-bottom: 1px solid #e2e8f0;
  background: #f5f9ff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.structure-card-head-main {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.structure-card-title {
  font-weight: 700;
  color: var(--ncbi-blue-dark);
}

.structure-card-meta {
  color: #64748b;
  font-size: 0.8rem;
}

.structure-card-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.structure-drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  padding: 4px 8px;
  border: 1px dashed #94a3b8;
  border-radius: 6px;
  color: #475569;
  background: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: grab;
  user-select: none;
}

.structure-drag-handle:active {
  cursor: grabbing;
}

.structure-card.is-dragging {
  opacity: 0.55;
}

.structure-card.is-drag-over {
  outline: 2px dashed #1d4ed8;
  outline-offset: -2px;
}

.structure-opacity-row {
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid #e2e8f0;
}

.structure-opacity-row input[type='range'] {
  flex: 1;
  min-width: 120px;
  padding: 0;
  border: none;
}

.structure-opacity-value {
  width: 48px;
  text-align: right;
  color: #334155;
  font-size: 0.85rem;
}

.structure-viewer-wrap {
  height: 360px;
  background: #f8fbff;
}

.structure-viewer-canvas {
  width: 100%;
  height: 100%;
}

.structure-viewer-wrap:fullscreen {
  width: 100vw;
  height: 100vh;
  background: #ffffff;
}

.structure-viewer-wrap:fullscreen .structure-viewer-canvas {
  width: 100%;
  height: 100%;
}

.structure-alignment {
  max-height: 430px;
  overflow: auto;
}

.structure-align-block {
  margin-bottom: 12px;
}

.structure-align-title {
  margin-bottom: 6px;
  color: var(--ncbi-blue-dark);
  font-weight: 700;
}

.structure-align-row {
  display: grid;
  grid-template-columns: minmax(170px, 240px) 1fr;
  gap: 8px;
  align-items: start;
  margin: 2px 0;
}

.structure-align-label {
  color: #334155;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.structure-align-seq {
  white-space: pre;
  font-family: "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.8rem;
  line-height: 1.35;
  letter-spacing: 0.02em;
}

.structure-ruler .structure-align-seq {
  color: #1d4ed8;
}

.structure-aa-token {
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  min-width: 0;
  color: inherit;
  font: inherit;
  line-height: inherit;
  cursor: pointer;
  border-radius: 2px;
}

.structure-aa-token:hover {
  background: rgba(30, 64, 175, 0.14);
}

.structure-aa-token.is-active {
  background: rgba(239, 68, 68, 0.2);
  color: #991b1b;
}

.structure-gap-token {
  color: #94a3b8;
}

@media (max-width: 760px) {
  .brand-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .panel-container {
    margin: 12px;
  }

  .tab-btn {
    min-width: 150px;
    font-size: 0.88rem;
  }

  .phylo-layout {
    grid-template-columns: 1fr;
  }

  .tree-toolbar-right {
    width: 100%;
  }

  .length-control {
    width: 100%;
    justify-content: space-between;
  }

  .length-control input[type='range'] {
    width: 100%;
    max-width: 180px;
  }

  .sequence-list {
    max-height: 260px;
  }

  .msa-filter-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .msa-filter-actions {
    flex-wrap: wrap;
  }

  .msa-row {
    grid-template-columns: 1fr;
    gap: 2px;
    margin: 4px 0;
  }

  .msa-seq {
    overflow-x: auto;
  }

  .structure-toolbar {
    align-items: flex-start;
  }

  .structure-viewer-grid {
    grid-template-columns: 1fr;
  }

  .structure-viewer-wrap {
    height: 320px;
  }

  .structure-align-row {
    grid-template-columns: 1fr;
    gap: 2px;
    margin: 4px 0;
  }

  .structure-align-seq {
    overflow-x: auto;
  }
}
