/* FASTA Viewer — visual language aligned with protein.tacular.dev */

:root {
  --bg: #f6f7fb;
  --bg-elev: #ffffff;
  --fg: #0f172a;
  --fg-soft: #334155;
  --muted: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --accent: #4f46e5;
  --accent-2: #7c3aed;
  --accent-soft: #eef2ff;
  --row-hover: #f1f5f9;
  --row-active: #e0e7ff;

  --aa-hydrophobic: #f0f9ff;
  --aa-polar: #f0fdf4;
  --aa-acidic: #fef2f2;
  --aa-basic: #eff6ff;
  --aa-special: #fefce8;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 6px 16px rgba(15, 23, 42, 0.07);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.10);
  --gradient: linear-gradient(135deg, #4f46e5 0%, #7c3aed 55%, #ec4899 100%);

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", "Courier New", monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 22px;
  position: sticky;
  top: 0;
  background: var(--gradient);
  color: white;
  z-index: 10;
  box-shadow: var(--shadow);
}
.topbar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 10px;
}
.topbar h1::before {
  content: "";
  display: inline-block;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 30%, rgba(255,255,255,0.95), rgba(255,255,255,0.55) 35%, rgba(255,255,255,0) 70%),
    conic-gradient(from 200deg, #fcd34d, #f472b6, #60a5fa, #34d399, #fcd34d);
  box-shadow: 0 0 0 2px rgba(255,255,255,0.18), inset 0 0 6px rgba(0,0,0,0.25);
}
.status {
  color: rgba(255, 255, 255, 0.88);
  font-size: 13px;
  flex: 1;
  font-variant-numeric: tabular-nums;
}

.file-btn { cursor: pointer; }
.file-btn input { display: none; }

/* Small "Change file" pill that sits in the topbar after a FASTA is loaded. */
.topbar-file-btn {
  display: inline-flex;
  align-items: center;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.18);
  color: white;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid rgba(255, 255, 255, 0.28);
  backdrop-filter: blur(4px);
  transition: background 0.15s, transform 0.08s;
}
.topbar-file-btn:hover { background: rgba(255, 255, 255, 0.28); }
.topbar-file-btn:active { transform: translateY(1px); }

/* Large primary button below the example fixtures on first load. */
.file-btn-large {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 22px auto 0;
  padding: 14px 28px;
  background: var(--gradient);
  color: white;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
  box-shadow: 0 8px 20px rgba(79, 70, 229, 0.30);
  transition: filter 0.15s, transform 0.08s, box-shadow 0.15s;
}
.file-btn-large:hover {
  filter: brightness(1.06);
  box-shadow: 0 12px 28px rgba(79, 70, 229, 0.40);
}
.file-btn-large:active { transform: translateY(1px); }

/* ---------- Dropzone (initial empty state) ---------- */
.dropzone {
  margin: 40px auto;
  max-width: 900px;
  padding: 36px 28px;
  border: 2px dashed var(--border-strong);
  border-radius: 14px;
  background: var(--bg-elev);
  text-align: center;
  color: var(--muted);
  box-shadow: var(--shadow-lg);
}
.dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}
.dropzone code {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 1px 6px;
  border-radius: 4px;
  font-family: var(--mono);
}
.dropzone-or {
  margin-top: 22px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  font-weight: 600;
}

.sample-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 8px;
  margin: 12px auto 0;
  max-width: 900px;
  text-align: left;
}
.sample-btn {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s, transform 0.08s;
}
.sample-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}
.sample-name { display: block; font-weight: 700; color: var(--fg); }
.sample-desc { display: block; font-size: 12px; color: var(--muted); margin-top: 3px; }

/* ---------- App layout (sidebar + detail) ---------- */
main#app {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: calc(100vh - 53px);
}

.sidebar {
  border-right: 1px solid var(--border);
  background: var(--bg-elev);
  padding: 14px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  box-shadow: var(--shadow-sm);
}
.sidebar input[type="search"] {
  width: 100%;
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  background: white;
  color: var(--fg);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.sidebar input[type="search"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}
.search-row { display: flex; gap: 6px; align-items: stretch; }
.search-row input[type="search"] { flex: 1; min-width: 0; font-family: var(--mono); }
.search-row select {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  font-size: 12px;
  padding: 5px 8px;
  max-width: 9em;
  color: var(--fg);
}
.search-hint {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.4;
  margin-top: -2px;
}
.search-hint.error { color: #b91c1c; }

.search-action-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.search-action-row .btn { padding: 7px 14px; }
.search-action-row .btn.primary { flex: 1; justify-content: center; }
.search-action-row .btn.primary.pending {
  /* Visual cue that the query in the box hasn't been applied yet. */
  box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.35), 0 4px 12px rgba(79, 70, 229, 0.25);
  animation: pendingPulse 1.6s ease-in-out infinite;
}
@keyframes pendingPulse {
  0%, 100% { filter: brightness(1); }
  50%      { filter: brightness(1.1); }
}
.spinner.spinner-on-dark {
  border-color: rgba(255, 255, 255, 0.35);
  border-top-color: white;
  margin-left: 8px;
  margin-right: 0;
  width: 13px;
  height: 13px;
}


.select-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}
.select-row label { display: flex; align-items: center; gap: 6px; }
.select-row select {
  flex: 1;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 12px;
  background: white;
  font-family: inherit;
  text-transform: none;
  letter-spacing: normal;
  font-weight: 500;
  color: var(--fg);
}
.match-count {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.file-info {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-size: 12px;
}
.file-info summary {
  padding: 7px 11px;
  cursor: pointer;
  font-weight: 600;
  color: var(--fg);
  list-style: revert;
}
.file-info[open] summary { border-bottom: 1px solid var(--border); }
#file-info-content {
  padding: 9px 11px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
}
.stat-row { display: flex; justify-content: space-between; gap: 8px; }
.stat-row .k { color: var(--muted); }
.stat-row .v { font-weight: 600; font-variant-numeric: tabular-nums; color: var(--fg); }

.protein-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 0; }
.protein-list li {
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  border: 1px solid transparent;
  transition: background 0.1s, border-color 0.15s;
}
.protein-list li:hover { background: var(--row-hover); }
.protein-list li.active {
  background: var(--row-active);
  border-color: var(--accent);
}
.protein-list .acc { font-weight: 700; font-family: var(--mono); font-size: 12px; color: var(--accent); }
.protein-list li.active .acc { color: var(--accent-2); }
.protein-list .meta { color: var(--muted); font-size: 12px; margin-top: 3px; }
.protein-list .len {
  float: right;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.protein-list .hit-badge {
  float: right;
  margin-right: 6px;
  background: #fde68a;
  color: #78350f;
  font-weight: 700;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
  line-height: 1.4;
}
.protein-list li.active .hit-badge {
  background: #f59e0b;
  color: #fff;
}

/* ---------- Pagination ---------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 4px 4px;
  margin-top: 8px;
  border-top: 1px solid var(--border);
}
.pagination .pg-btn {
  min-width: 32px;
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 600;
  font-family: var(--mono);
  line-height: 1;
}
.pagination .pg-btn[disabled] {
  opacity: 0.35;
  cursor: not-allowed;
}
.pagination .pg-info {
  flex: 1;
  text-align: center;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--fg-soft);
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.pagination .pg-of {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 600;
}

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border);
  background: white;
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  color: var(--fg-soft);
  font-weight: 500;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: border-color 0.15s, color 0.15s, background 0.15s, box-shadow 0.15s, transform 0.05s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--gradient);
  color: white;
  border-color: transparent;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.25);
  font-weight: 600;
}
.btn.primary:hover { filter: brightness(1.06); color: white; box-shadow: 0 6px 18px rgba(79, 70, 229, 0.35); }

/* ---------- Detail / header card ---------- */
.detail { padding: 18px 24px 40px; overflow-y: auto; min-height: 0; }

.header-card {
  margin-bottom: 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.header-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--gradient);
}
.header-card:empty { display: none; }
.header-card h2 {
  margin: 0 0 4px;
  font-size: 19px;
  font-family: var(--mono);
  font-weight: 700;
  letter-spacing: -0.01em;
}
.header-card .pname { font-weight: 500; color: var(--fg-soft); font-size: 14px; }
.header-card .gname { color: var(--muted); font-size: 13px; }
.header-card .desc { color: var(--muted); font-size: 12px; font-style: italic; margin-top: 4px; word-break: break-word; }
.header-card .raw-header {
  margin-top: 10px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  background: var(--bg);
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  word-break: break-all;
}
.header-card .metrics { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.metric {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 11px;
  font-size: 12px;
  background: var(--bg-elev);
  transition: border-color 0.15s, background 0.15s;
}
.metric:hover { border-color: var(--border-strong); background: var(--bg); }
.metric .label {
  color: var(--muted);
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}
.metric .value { font-weight: 600; font-size: 14px; word-break: break-word; color: var(--fg); }
.header-card .mass-line {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
}
.header-card .mass-line .v { color: var(--fg); font-weight: 600; }

.header-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-wrap: wrap;
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 2px;
  margin: 10px 0 0;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tab {
  border: none;
  background: none;
  padding: 10px 16px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  font-family: inherit;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
  border-radius: 6px 6px 0 0;
  white-space: nowrap;
}
.tab:hover { color: var(--fg); background: var(--row-hover); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

/* ---------- Sequence tab ---------- */
.sequence-toolbar {
  margin: 14px 0 8px;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  font-size: 12px;
}
.sequence-toolbar label { display: inline-flex; align-items: center; gap: 6px; }
.sequence-toolbar input[type="search"] {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12px;
  min-width: 240px;
  font-family: var(--mono);
  background: var(--bg-elev);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.sequence-toolbar input[type="search"]:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}
.sequence-toolbar .btn {
  padding: 6px 12px;
  font-size: 12px;
}

.sequence-area {
  margin-top: 6px;
  padding: 14px 14px 10px;
  overflow-x: auto;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow-sm);
}
.seq-group { font-family: var(--mono); font-size: 14px; margin-bottom: 14px; }
.seq-group:last-child { margin-bottom: 0; }
.seq-line {
  display: grid;
  grid-template-columns: 5ch repeat(60, 1ch) 6ch;
  line-height: 1.75em;
  align-items: center;
  width: fit-content;
  margin-inline: auto;
}
.seq-pos {
  text-align: right;
  padding-right: 0.5ch;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  user-select: none;
}
.seq-pos.end { text-align: left; padding-left: 0.5ch; padding-right: 0; }
.aa { text-align: center; transition: background 0.1s; }
.aa.colored.hydrophobic { background: var(--aa-hydrophobic); }
.aa.colored.polar { background: var(--aa-polar); }
.aa.colored.acidic { background: var(--aa-acidic); color: #991b1b; }
.aa.colored.basic { background: var(--aa-basic); color: #1e40af; }
.aa.colored.special { background: var(--aa-special); }
.aa.match {
  background: #fde68a;
  color: #78350f;
  font-weight: 700;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(180, 83, 9, 0.3);
}

/* ---------- Composition ---------- */
.composition-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
  margin-top: 14px;
}
.comp-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  background: var(--bg-elev);
  box-shadow: var(--shadow-sm);
}
.comp-card h4 {
  margin: 0 0 10px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  font-weight: 600;
}
.comp-bar-row {
  display: grid;
  grid-template-columns: 2.5ch 4ch 1fr 4ch;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  margin-bottom: 4px;
  font-family: var(--mono);
}
.comp-bar-row .aa-label { font-weight: 700; }
.comp-bar-row .pct, .comp-bar-row .count {
  color: var(--muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.comp-bar {
  height: 10px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.comp-bar > div {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 999px;
  transition: width 0.3s;
}
.comp-bar.hydrophobic > div { background: linear-gradient(90deg, #38bdf8, #2563eb); }
.comp-bar.polar > div { background: linear-gradient(90deg, #34d399, #059669); }
.comp-bar.acidic > div { background: linear-gradient(90deg, #fb7185, #be123c); }
.comp-bar.basic > div { background: linear-gradient(90deg, #818cf8, #4338ca); }
.comp-bar.special > div { background: linear-gradient(90deg, #fbbf24, #b45309); }

/* ---------- Spinner / empties ---------- */
.spinner {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-left: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.computing { color: var(--muted); font-style: italic; padding: 10px 0; }
.empty { color: var(--muted); font-style: italic; padding: 10px 0; }

/* ---------- Raw tab ---------- */
.raw-json {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 70vh;
  overflow: auto;
  box-shadow: var(--shadow-sm);
}

/* ---------- Generic legend chips ---------- */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  font-size: 12px;
  color: var(--muted);
  padding: 10px 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin: 4px 0 12px;
  align-items: center;
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-square {
  display: inline-block;
  width: 16px; height: 16px;
  border-radius: 3px;
  font-family: var(--mono);
  font-size: 11px;
  text-align: center;
  line-height: 16px;
  border: 1px solid var(--border);
}
.legend-square.hydrophobic { background: var(--aa-hydrophobic); }
.legend-square.polar { background: var(--aa-polar); }
.legend-square.acidic { background: var(--aa-acidic); color: #991b1b; }
.legend-square.basic { background: var(--aa-basic); color: #1e40af; }
.legend-square.special { background: var(--aa-special); }

/* ---------- Load overlay (FASTA parse) ---------- */
.load-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.load-card {
  background: var(--bg-elev);
  border-radius: 14px;
  padding: 24px 28px;
  width: min(420px, calc(100vw - 32px));
  text-align: center;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}
.load-spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-right-color: var(--accent-2);
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
.load-text {
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.4;
}
.load-subtle {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
  max-width: 100%;
  overflow-wrap: break-word;
}

/* ---------- Responsive ---------- */
@media (max-width: 880px) {
  main#app {
    grid-template-columns: 1fr;
    height: auto;
  }
  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .detail { padding-bottom: 60px; }
}
/* ---------- URL parameter help ---------- */
.url-help {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elev);
  font-size: 13px;
}
.url-help > summary {
  cursor: pointer;
  padding: 10px 14px;
  font-weight: 600;
  color: var(--fg-soft);
  list-style: revert;
}
.url-help[open] > summary { border-bottom: 1px solid var(--border); }
.url-help-body { padding: 12px 14px; color: var(--fg-soft); line-height: 1.5; }
.url-help-body > p { margin: 0 0 10px; }
.url-help-table { width: 100%; border-collapse: collapse; }
.url-help-table th, .url-help-table td {
  text-align: left;
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.url-help-table tr:last-child td { border-bottom: none; }
.url-help-table th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.url-help-table td:first-child { white-space: nowrap; }
.url-help code {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 1px 5px;
  border-radius: 4px;
  word-break: break-word;
}
.url-help-eg { margin: 10px 0 0; color: var(--muted); }
