/* ============================
   MTDB Website — Styles
   Scientific Editorial Aesthetic
   ============================ */

:root {
  /* Color Palette */
  --ink: #0f1729;
  --ink-light: #1e2a45;
  --ink-muted: #3a4a6b;
  --paper: #f7f3ec;
  --paper-warm: #ede6d8;
  --paper-cool: #f0f2f5;
  --amber: #c4913b;
  --amber-light: #e8cda0;
  --amber-dim: #a07830;
  --teal: #2d8f8f;
  --teal-light: #d0ecec;
  --coral: #c45c3b;
  --coral-light: #f0d5cc;
  --text: #2a2a2a;
  --text-secondary: #6b7280;
  --border: #d6d0c4;
  --border-light: #e8e2d6;
  --white: #ffffff;
  --positive-color: #2d8f8f;
  --negative-color: #c45c3b;

  /* Typography */
  --font-display: 'Instrument Serif', Georgia, serif;
  --font-body: 'IBM Plex Sans', -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Consolas', monospace;

  /* Spacing */
  --header-h: 72px;
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ---- Header ---- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--ink);
  border-bottom: 3px solid var(--amber);
  height: var(--header-h);
}

.header-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 0 32px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-mark svg {
  width: 40px;
  height: 40px;
}

.logo-text h1 {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 400;
  color: var(--white);
  letter-spacing: 2px;
  line-height: 1;
}

.logo-subtitle {
  font-size: 11px;
  color: var(--amber-light);
  letter-spacing: 0.5px;
  font-weight: 300;
  margin-top: 2px;
}

.header-stats {
  display: flex;
  gap: 16px;
}

.stat-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 18px;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
}

.stat-num {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 500;
  color: var(--amber);
  line-height: 1.2;
}

.stat-label {
  font-size: 10px;
  color: rgba(255,255,255,0.5);
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ---- Main Content ---- */
.main-content {
  max-width: 1360px;
  margin: 0 auto;
  padding: 32px;
  min-height: calc(100vh - var(--header-h) - 60px);
}

/* ---- Search Section ---- */
.search-section {
  margin-bottom: 24px;
}

.search-box {
  position: relative;
  max-width: 640px;
}

.search-icon {
  position: absolute;
  left: 16px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--ink-muted);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 14px 44px 14px 44px;
  font-family: var(--font-body);
  font-size: 15px;
  border: 2px solid var(--border);
  border-radius: 8px;
  background: var(--white);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

.search-box input:focus {
  border-color: var(--amber);
}

.search-box input::placeholder {
  color: var(--text-secondary);
  font-weight: 300;
}

.search-clear {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  font-size: 22px;
  color: var(--text-secondary);
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}

.filter-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.filter-btn {
  padding: 6px 16px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--white);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.filter-btn:hover {
  border-color: var(--amber);
  color: var(--amber-dim);
}

.filter-btn.active {
  background: var(--ink);
  color: var(--white);
  border-color: var(--ink);
}

/* ---- Results Info ---- */
.results-info {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  font-weight: 300;
}

/* ---- Compound Table ---- */
.table-wrap {
  background: var(--white);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  overflow: hidden;
}

.compound-table {
  width: 100%;
  border-collapse: collapse;
}

.compound-table thead {
  background: var(--paper-cool);
  border-bottom: 2px solid var(--border);
}

.compound-table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--ink-muted);
}

.compound-table td {
  padding: 14px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

.compound-table tbody tr {
  cursor: pointer;
  transition: background 0.15s;
}

.compound-table tbody tr:hover {
  background: var(--paper-warm);
}

.compound-table tbody tr:last-child td {
  border-bottom: none;
}

.col-id { width: 130px; }
.col-formula { width: 160px; }
.col-hmdb { width: 140px; }
.col-spectra { width: 90px; text-align: center; }

.cell-id {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink);
}

.cell-name {
  font-weight: 500;
  color: var(--text);
}

.cell-formula {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--ink-muted);
}

.cell-hmdb {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--teal);
}

.spectra-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-mono);
}

.spectra-badge.has {
  background: var(--teal-light);
  color: var(--teal);
}

.spectra-badge.none {
  background: var(--paper-cool);
  color: var(--text-secondary);
}

.iso-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--coral);
  background: var(--coral-light);
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 8px;
  vertical-align: middle;
  letter-spacing: 0.5px;
}

/* ---- Pagination ---- */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 4px;
  margin-top: 24px;
}

.page-btn {
  min-width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--white);
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
}

.page-btn:hover {
  border-color: var(--amber);
  color: var(--amber-dim);
}

.page-btn.active {
  background: var(--ink);
  color: var(--white);
  border-color: var(--ink);
}

.page-btn.disabled {
  opacity: 0.3;
  pointer-events: none;
}

.page-ellipsis {
  width: 36px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
}

/* ---- Detail View ---- */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  color: var(--ink-muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  margin-bottom: 20px;
  transition: all 0.2s;
}

.back-btn svg {
  width: 16px;
  height: 16px;
}

.back-btn:hover {
  border-color: var(--ink);
  color: var(--ink);
}

.detail-header {
  margin-bottom: 28px;
}

.detail-name {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 400;
  color: var(--ink);
  line-height: 1.3;
  margin-bottom: 10px;
}

.detail-ids {
  display: flex;
  gap: 10px;
}

.id-badge {
  display: inline-block;
  padding: 4px 14px;
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  border-radius: 4px;
}

.id-badge.mtdb {
  background: var(--ink);
  color: var(--amber-light);
}

.id-badge.hmdb {
  background: var(--teal-light);
  color: var(--teal);
}

/* Detail Grid */
.detail-grid {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 24px;
  align-items: start;
}

/* Cards */
.card {
  background: var(--white);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 24px;
  margin-bottom: 20px;
}

.card-title {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 400;
  color: var(--ink);
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-light);
}

/* Structure Card */
.structure-container {
  width: 100%;
  min-height: 260px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--white);
  border-radius: 6px;
}

.structure-container svg {
  max-width: 100%;
  max-height: 280px;
}

.structure-loading {
  font-size: 13px;
  color: var(--text-secondary);
  font-style: italic;
}

/* Info Card */
.info-list {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 8px 12px;
}

.info-list dt {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding-top: 2px;
}

.info-list dd {
  font-size: 14px;
  color: var(--text);
  word-break: break-all;
}

.formula-text {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 15px;
  color: var(--ink);
}

.mono-text {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-muted);
}

.smiles-text {
  font-size: 11px;
  line-height: 1.5;
}

/* ---- Isomer Card ---- */
.isomer-card .card-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.isomer-count {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--coral);
  background: var(--coral-light);
  padding: 2px 8px;
  border-radius: 10px;
}

.isomer-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.isomer-item {
  padding: 12px 14px;
  background: var(--paper);
  border: 1px solid var(--border-light);
  border-radius: 8px;
  transition: border-color 0.2s;
}

.isomer-item:hover {
  border-color: var(--border);
}

.isomer-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.isomer-genus {
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
}

.isomer-rt {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-muted);
}

.isomer-rt span {
  color: var(--amber-dim);
  font-weight: 500;
}

.isomer-smiles {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-muted);
  word-break: break-all;
  line-height: 1.5;
  margin-bottom: 4px;
}

.isomer-msms-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 4px;
}

.isomer-msms-tag.available {
  background: var(--teal-light);
  color: var(--teal);
}

.isomer-msms-tag.unavailable {
  background: var(--paper-cool);
  color: var(--text-secondary);
}

/* Spectra Card */
.spectra-card {
  min-height: 400px;
}

.spectra-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.spectrum-tab {
  padding: 6px 16px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--white);
  cursor: pointer;
  transition: all 0.15s;
}

.spectrum-tab:hover {
  border-color: var(--amber);
}

.spectrum-tab.active {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--white);
}

.spectrum-tab .ion-mode {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}

.spectrum-tab .ion-mode.positive { background: var(--positive-color); }
.spectrum-tab .ion-mode.negative { background: var(--negative-color); }

.spectra-container {
  position: relative;
  width: 100%;
  min-height: 300px;
}

.no-spectra {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
  font-style: italic;
  font-size: 14px;
}

/* Peak Table */
.peak-table-wrap {
  margin-top: 20px;
  max-height: 300px;
  overflow-y: auto;
}

.peak-table-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.peak-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.peak-table th {
  text-align: left;
  padding: 6px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ink-muted);
  border-bottom: 2px solid var(--border);
  background: var(--paper-cool);
  position: sticky;
  top: 0;
}

.peak-table td {
  padding: 5px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  border-bottom: 1px solid var(--border-light);
}

.peak-table tr:hover td {
  background: var(--paper-warm);
}

.peak-rel-bar {
  display: inline-block;
  height: 10px;
  background: var(--amber);
  border-radius: 2px;
  vertical-align: middle;
  margin-right: 6px;
  opacity: 0.7;
}

/* ---- Footer ---- */
.site-footer {
  text-align: center;
  padding: 20px;
  font-size: 12px;
  color: var(--text-secondary);
  border-top: 1px solid var(--border-light);
}

/* ---- Loading Overlay ---- */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.4s;
}

.loading-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--amber);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay p {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 300;
}

/* ---- Responsive ---- */
@media (max-width: 960px) {
  .detail-grid {
    grid-template-columns: 1fr;
  }
  .header-stats { display: none; }
  .main-content { padding: 20px; }
}

@media (max-width: 640px) {
  .logo-text h1 { font-size: 22px; }
  .search-box input { font-size: 14px; padding: 12px 40px; }
  .compound-table th, .compound-table td { padding: 10px 10px; font-size: 13px; }
  .col-hmdb, .col-spectra { display: none; }
  .detail-name { font-size: 24px; }
}
