:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --row-hover: #f3f4f6;
  --row-active: #dbeafe;
  --mod-unimod: #1f77b4;
  --mod-psimod: #9467bd;
  --mod-other: #2ca02c;
  --mod-mixed: #374151;
  --variant: #d62728;
  --variant-complex: #ff7f0e;
  --processed: #6366f1;
  --disulfide: #d97706;
  --proteoform: #7c3aed;
  --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, "Segoe UI", Roboto, sans-serif;
  color: var(--fg);
  background: var(--bg);
  font-size: 14px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.topbar h1 { margin: 0; font-size: 16px; font-weight: 600; }
.status { color: var(--muted); font-size: 13px; flex: 1; }

.file-btn {
  display: inline-block;
  padding: 6px 12px;
  background: var(--accent);
  color: white;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.file-btn input { display: none; }
.file-btn:hover { filter: brightness(1.05); }

.dropzone {
  margin: 40px auto;
  max-width: 900px;
  padding: 40px 20px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  text-align: center;
  color: var(--muted);
}
.dropzone.dragover { border-color: var(--accent); background: #eff6ff; }
.dropzone code { background: #f3f4f6; padding: 2px 6px; border-radius: 4px; }
.dropzone-or { margin-top: 22px; font-size: 13px; color: var(--muted); }

.sample-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 8px;
  margin: 8px auto 0;
  max-width: 900px;
  text-align: left;
}
.sample-btn {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: white;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
}
.sample-btn:hover { border-color: var(--accent); background: #f9fafb; }
.sample-name { display: block; font-weight: 600; color: var(--fg); }
.sample-desc { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }

main#app {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: calc(100vh - 49px);
}

.sidebar {
  border-right: 1px solid var(--border);
  padding: 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}
.sidebar input[type="search"] {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}
.filters { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.filters label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.match-count { color: var(--muted); font-size: 12px; }

.file-info {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #f9fafb;
  font-size: 12px;
}
.file-info summary {
  padding: 6px 10px;
  cursor: pointer;
  font-weight: 500;
  color: var(--fg);
  list-style: revert;
}
.file-info[open] summary { border-bottom: 1px solid var(--border); }
#file-info-content {
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 240px;
  overflow-y: auto;
}
#file-info-content .peff-version {
  font-weight: 600;
  color: var(--accent);
  font-size: 11px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
#file-info-content .comment {
  color: var(--muted);
  font-style: italic;
  font-size: 11px;
}
#file-info-content .db {
  border-top: 1px solid var(--border);
  padding-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
#file-info-content .db:first-of-type {
  border-top: none;
  padding-top: 0;
}
#file-info-content .db .meta { color: var(--muted); font-size: 11px; }
#file-info-content .flags { margin-top: 2px; display: flex; flex-wrap: wrap; gap: 3px; }
#file-info-content .flag {
  background: #e0e7ff;
  color: #3730a3;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
}
#file-info-content .tagdefs {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.protein-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; min-height: 0; }
.protein-list li {
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  border: 1px solid transparent;
}
.protein-list li:hover { background: var(--row-hover); }
.protein-list li.active { background: var(--row-active); border-color: #93c5fd; }
.protein-list .acc { font-weight: 600; }
.protein-list .meta { color: var(--muted); font-size: 12px; }
.protein-list .badges { display: inline-flex; gap: 4px; margin-left: 6px; }
.protein-list .badge {
  display: inline-block;
  width: 7px; height: 7px; border-radius: 50%;
}
.badge.mod { background: var(--mod-unimod); }
.badge.var { background: var(--variant); }
.badge.proc { background: var(--processed); }
.badge.ds { background: var(--disulfide); }
.badge.pf { background: var(--proteoform); }

.detail { padding: 16px 20px; overflow-y: auto; min-height: 0; }

.header-card { margin-bottom: 12px; }
.header-card h2 { margin: 0 0 4px; font-size: 18px; }
.header-card .pname { font-weight: 500; }
.header-card .gname { color: var(--muted); font-size: 13px; }
.header-card .comment { color: var(--muted); font-size: 12px; font-style: italic; margin-top: 4px; }
.header-card .decoy-flag { display: inline-block; background: #fee2e2; color: #991b1b; padding: 1px 8px; border-radius: 3px; font-size: 11px; margin-left: 6px; }
.header-card .metrics { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; }
.metric { border: 1px solid var(--border); border-radius: 6px; padding: 4px 10px; font-size: 12px; }
.metric .label { color: var(--muted); display: block; }
.metric .value { font-weight: 600; font-size: 14px; }

.tabs { display: flex; gap: 4px; margin: 8px 0 0; border-bottom: 1px solid var(--border); }
.tab {
  border: none; background: none; padding: 8px 14px; cursor: pointer;
  font-size: 13px; color: var(--muted); border-bottom: 2px solid transparent;
}
.tab:hover { color: var(--fg); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.sequence-area {
  margin-top: 14px;
  padding: 8px 0;
  overflow-x: auto;
}
.seq-group {
  font-family: var(--mono);
  font-size: 14px;
  margin-bottom: 14px;
}
.seq-line,
.track {
  display: grid;
  grid-template-columns: 5ch repeat(60, 1ch);
}
.seq-line {
  line-height: 1.7em;
  align-items: center;
}
.seq-pos {
  grid-column: 1;
  text-align: right;
  padding-right: 0.5ch;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  user-select: none;
}
.aa { text-align: center; }
.aa.tick { border-right: 1px dotted #d1d5db; }
.aa.flash {
  animation: flashpulse 1.6s ease-out;
  border-radius: 3px;
}
@keyframes flashpulse {
  0%   { background: var(--accent); color: white; }
  60%  { background: var(--accent); color: white; }
  100% { background: transparent; color: inherit; }
}

.track {
  line-height: 1em;
  height: 1.35em;
  align-items: center;
  margin-top: 1px;
}
.track-pos { grid-column: 1; }

.mod-mark {
  height: 1.15em;
  line-height: 1.15em;
  border-radius: 2px;
  cursor: help;
  color: white;
  font-size: 9px;
  font-weight: 700;
  text-align: center;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.mod-mark.mod-mixed { outline: 1px solid #111827; outline-offset: -1px; }

.var-cell {
  background: var(--variant);
  color: white;
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  height: 1.15em;
  line-height: 1.15em;
  border-radius: 2px;
  cursor: help;
}

.bar {
  font-size: 10px;
  line-height: 1.25em;
  height: 1.25em;
  border-radius: 3px;
  padding: 0 4px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  cursor: help;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.var-bar { background: #fed7aa; color: #7c2d12; }
.proc-bar { background: #c7d2fe; color: #3730a3; }
.ds-bar { background: #fde68a; color: #78350f; border-top: 1px solid #d97706; border-bottom: 1px solid #d97706; height: 1em; }
.pf-bar { background: #ddd6fe; color: #4c1d95; }
.bar-open-left { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.bar-open-right { border-top-right-radius: 0; border-bottom-right-radius: 0; }

.legend {
  display: flex; flex-wrap: wrap; gap: 6px 14px;
  font-size: 12px; color: var(--muted);
  padding: 6px 0 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.legend-square { display: inline-block; width: 12px; height: 12px; border-radius: 2px; }
.legend-square.mixed { background: var(--mod-mixed); outline: 1px solid #111827; outline-offset: -1px; }
.legend-var { display: inline-block; width: 14px; height: 14px; background: var(--variant); color: white; text-align: center; font-size: 10px; line-height: 14px; border-radius: 2px; }
.legend-bar { display: inline-block; padding: 1px 6px; font-size: 10px; border-radius: 2px; }

table.data {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
table.data th, table.data td {
  text-align: left; padding: 4px 8px;
  border-bottom: 1px solid var(--border);
}
table.data th { color: var(--muted); font-weight: 500; font-size: 12px; }
table.data tr:hover td { background: var(--row-hover); }
table.data tr[data-pos] { cursor: pointer; }
table.data tr[data-pos]:hover td { background: var(--row-active); }

.empty { color: var(--muted); font-style: italic; padding: 8px 0; }
.raw-json {
  background: #f9fafb; border: 1px solid var(--border); border-radius: 6px;
  padding: 10px; font-family: var(--mono); font-size: 12px;
  white-space: pre-wrap; word-break: break-word;
  max-height: 60vh; overflow: auto;
}

h3.section-title-sm { margin: 14px 0 6px; font-size: 13px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.5px; }
