/* MAP2 - the microRNAs Analysis Portal (modernised)
 * Custom palette and layout, designed on top of Bootstrap 5.
 */

:root {
  --map-primary: #8b0000;
  --map-primary-dark: #5e0000;
  --map-accent: #f25c54;
  --map-bg: #f6f4ef;
  --map-card: #ffffff;
  --map-border: #e4e0d8;
  --map-text: #2b2a26;
  --map-muted: #6c7079;
  --map-success: #2e7d54;
  --map-warning: #c7891d;
  --map-info: #2a6f97;
  --map-shadow: 0 6px 20px rgba(20, 16, 0, 0.06);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

/* Reserve space for the vertical scrollbar even on pages that don't
   need one. Without ``scrollbar-gutter: stable``, the topbar (sticky)
   and the body content end up measured against slightly different
   widths whenever Chrome/Firefox lazily add or remove the bar, which
   makes the centred header/footer look shifted relative to the body
   below. */
html {
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  font-family: "Inter", "Helvetica Neue", Arial, sans-serif;
  background: var(--map-bg);
  color: var(--map-text);
  line-height: 1.55;
  font-size: 15px;
}

a {
  color: var(--map-primary);
  text-decoration: none;
}
a:hover {
  color: var(--map-primary-dark);
  text-decoration: underline;
}

/* ---------- Top bar ---------- */
.map-topbar {
  background: var(--map-card);
  border-bottom: 1px solid var(--map-border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.map-topbar .map-topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  padding: 0.85rem 1.5rem;
  max-width: 1320px;
  margin: 0 auto;
}
.map-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--map-primary);
}
.map-brand img {
  height: 64px;
  width: auto;
}
.map-footer-mirnat {
  display: none;  /* logo hidden — corporate text alone in the footer */
}
.map-footer a {
  color: var(--map-primary);
  text-decoration: none;
}
.map-footer a:hover { text-decoration: underline; }
.map-brand small {
  display: block;
  color: var(--map-muted);
  font-weight: 400;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.map-nav {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
}
.map-nav a {
  color: var(--map-text);
  font-weight: 500;
  padding: 0.35rem 0.5rem;
  border-radius: 0.35rem;
  transition: background 0.15s ease;
}
.map-nav a:hover {
  background: var(--map-bg);
  text-decoration: none;
}
.map-nav a.active {
  background: var(--map-primary);
  color: #fff;
}

/* ---------- Layout ---------- */
.map-shell {
  max-width: 1320px;
  margin: 0 auto;
  padding: 1.75rem 1.5rem 4rem;
}

.map-hero {
  background: linear-gradient(135deg, #1c1c1c, #4a0000);
  color: #fff;
  border-radius: 1rem;
  padding: 3rem 2.5rem;
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 2rem;
  align-items: center;
  box-shadow: var(--map-shadow);
}
.map-hero h1 {
  font-size: 2.4rem;
  margin: 0 0 0.85rem;
  letter-spacing: -0.01em;
}
.map-hero p {
  color: #e9d9d9;
  margin-bottom: 1.25rem;
}
.map-hero .map-hero-cta {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.map-hero .btn-light {
  background: #fff;
  color: var(--map-primary);
  font-weight: 600;
  border: 0;
}
.map-hero .btn-outline-light {
  border-color: #fff;
  color: #fff;
}
.map-hero-stats {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 0.85rem;
  padding: 1.4rem 1.6rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem 1.5rem;
}
.map-hero-stats .stat {
  display: flex;
  flex-direction: column;
}
.map-hero-stats .stat .v {
  font-size: 1.7rem;
  font-weight: 700;
}
.map-hero-stats .stat .l {
  color: #f3c2c2;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
}

/* ---------- Cards / sections ---------- */
.map-card {
  background: var(--map-card);
  border: 1px solid var(--map-border);
  border-radius: 0.85rem;
  padding: 1.4rem 1.5rem;
  box-shadow: var(--map-shadow);
  margin-bottom: 1.4rem;
}
.map-card h2 {
  font-size: 1.25rem;
  margin-top: 0;
  margin-bottom: 0.85rem;
  color: var(--map-primary);
  font-weight: 700;
}
.map-card h3 {
  font-size: 1.05rem;
  margin: 1.2rem 0 0.5rem;
  color: var(--map-primary-dark);
}
.map-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}
.map-section-title h2 {
  margin: 0;
  font-size: 1.4rem;
  color: var(--map-primary);
}

/* ---------- Explore layout ---------- */
.explore-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1.4rem;
}
@media (max-width: 992px) {
  .explore-grid {
    grid-template-columns: 1fr;
  }
}

.filters-card label {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--map-muted);
  margin-top: 0.85rem;
  margin-bottom: 0.25rem;
  display: block;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.filters-card .form-control,
.filters-card .select-multi {
  border-radius: 0.5rem;
  border: 1px solid var(--map-border);
}
.filters-card .filter-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

.btn-map {
  background: var(--map-primary);
  color: #fff;
  font-weight: 600;
  border: 0;
  border-radius: 0.5rem;
  padding: 0.55rem 1.1rem;
  transition: background 0.15s ease;
}
.btn-map:hover {
  background: var(--map-primary-dark);
  color: #fff;
}
.btn-ghost {
  background: transparent;
  color: var(--map-primary);
  border: 1px solid var(--map-primary);
  border-radius: 0.5rem;
  padding: 0.55rem 1.1rem;
  font-weight: 600;
}
.btn-ghost:hover {
  background: var(--map-primary);
  color: #fff;
}

/* multi-select via choices.js */
.choices__inner {
  border-radius: 0.5rem !important;
  border-color: var(--map-border) !important;
  background: #fff !important;
  min-height: 36px;
  padding-top: 4px;
  padding-bottom: 4px;
}
.choices__list--multiple .choices__item {
  background: var(--map-primary) !important;
  border-color: var(--map-primary-dark) !important;
  border-radius: 4px !important;
}

/* ---------- Tables ---------- */
.papers-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.papers-table thead th {
  text-align: left;
  background: #faf7f0;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--map-border);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--map-muted);
  cursor: pointer;
  user-select: none;
}
.papers-table thead th .sort-indicator {
  font-size: 0.7rem;
  margin-left: 4px;
  color: var(--map-primary);
}
.papers-table tbody td {
  padding: 0.75rem 0.9rem;
  vertical-align: top;
  border-bottom: 1px solid var(--map-border);
}
.papers-table tbody tr:hover {
  background: #fbf6f4;
}
.papers-table .pmid-link {
  font-family: "JetBrains Mono", "Consolas", monospace;
  font-weight: 600;
}
.papers-table .badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 0.35rem;
}
.badge-analysis {
  background: #f1e6dc;
  color: var(--map-primary-dark);
  font-size: 0.7rem;
  padding: 0.18rem 0.5rem;
  border-radius: 0.35rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.no-data {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--map-muted);
  font-style: italic;
}

/* pager */
.pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 0;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.pager .info {
  color: var(--map-muted);
  font-size: 0.88rem;
}
.pager .ctrls {
  display: flex;
  gap: 0.3rem;
  align-items: center;
}
.pager button {
  background: #fff;
  border: 1px solid var(--map-border);
  border-radius: 0.4rem;
  padding: 0.35rem 0.7rem;
  cursor: pointer;
  font-weight: 600;
  color: var(--map-text);
}
.pager button[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}
.pager button.active {
  background: var(--map-primary);
  color: #fff;
  border-color: var(--map-primary);
}
.pager select {
  border-radius: 0.4rem;
  border: 1px solid var(--map-border);
  padding: 0.3rem 0.55rem;
  background: #fff;
}

/* ---------- Stats page ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 1.2rem;
}
.stat-card {
  background: var(--map-card);
  border-radius: 0.85rem;
  padding: 1.1rem 1.2rem;
  border: 1px solid var(--map-border);
  box-shadow: var(--map-shadow);
}
.stat-card h3 {
  color: var(--map-primary);
  margin: 0 0 0.65rem;
  font-size: 1.05rem;
}

/* ---------- Details page ---------- */
.detail-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.4rem;
}
@media (max-width: 992px) {
  .detail-grid {
    grid-template-columns: 1fr;
  }
}
.detail-meta {
  list-style: none;
  padding: 0;
  margin: 0;
}
.detail-meta li {
  padding: 0.5rem 0;
  border-bottom: 1px dashed var(--map-border);
  font-size: 0.92rem;
}
.detail-meta li strong {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--map-muted);
  margin-bottom: 0.2rem;
}
.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}
.tag {
  background: #f3eee5;
  border-radius: 0.35rem;
  padding: 0.2rem 0.55rem;
  font-size: 0.78rem;
  color: var(--map-primary-dark);
}

/* ---------- Analysis page ---------- */
.analysis-toolbar {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  align-items: end;
  margin-bottom: 1rem;
}
.analysis-toolbar .control {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 200px;
}
.analysis-toolbar .control label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--map-muted);
  font-weight: 600;
}
.analysis-tabs {
  display: flex;
  gap: 0.4rem;
  border-bottom: 1px solid var(--map-border);
  margin-bottom: 1rem;
}
.analysis-tabs button {
  background: transparent;
  border: 0;
  padding: 0.55rem 1rem;
  font-weight: 600;
  color: var(--map-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.analysis-tabs button.active {
  color: var(--map-primary);
  border-bottom-color: var(--map-primary);
}
.analysis-pane {
  min-height: 420px;
}
.placeholder {
  border: 2px dashed var(--map-border);
  border-radius: 0.75rem;
  padding: 2rem;
  color: var(--map-muted);
  text-align: center;
  background: #fbfaf6;
}

/* ---------- Footer ---------- */
.map-footer {
  border-top: 1px solid var(--map-border);
  color: var(--map-muted);
  font-size: 0.85rem;
  padding: 1rem 0;
  text-align: left;
  background: #fff;
}
/* Constrain the footer's inner content to the same max-width as
   .map-shell so the line of text starts under the page's content
   instead of hugging the viewport edge. The footer banner itself (with
   border-top) still spans the full viewport. */
.map-footer-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* ---------- COMPASS page (blue tones) ----------
   Scoped to ``body.compass-theme`` so the colour overrides only apply
   to the COMPASS landing + results pages. Everything else (layout,
   typography, cards, buttons, table styling) inherits from the main
   MAP² palette unchanged — only the primary colour family is
   re-targeted from dark red to deep blue. */
body.compass-theme {
  --map-primary:      #1d5a82;
  --map-primary-dark: #163f5e;
  --map-accent:       #4a90b8;
}
body.compass-theme .map-topbar {
  border-bottom-color: var(--map-primary);
}
body.compass-theme .map-hero {
  /* slightly cooler hero gradient than the default warm-black-to-red */
  background: linear-gradient(135deg, #0d1d2c, #163f5e);
}
.compass-logo {
  max-width: 320px;
  width: 60%;
  height: auto;
  display: block;
  margin: 0.4rem auto 0.9rem;
}
@media (max-width: 600px) {
  .compass-logo { width: 80%; max-width: 240px; }
}

/* Break the COMPASS result plots out of the 1320px .map-shell so they
   span the full viewport width (with a small inset for breathing room).
   100vw vs 100% avoids the scrollbar-overflow trick failing on macOS;
   the inset keeps the plots visually attached to the card's edge. */
.compass-fullwidth {
  width: 100vw;
  position: relative;
  left: 50%;
  right: 50%;
  margin-left: -50vw;
  margin-right: -50vw;
  padding: 0 1.5rem;
  box-sizing: border-box;
}
.compass-fullwidth > div[id^="plot-"] {
  width: 100%;
}

/* ---------- Justified body copy ----------
   Long-form paragraphs and list items inside the main content area are
   justified, with automatic hyphenation enabled so the inter-word gaps
   stay reasonable on narrow viewports. The hero is exempted because
   its short subtitle would otherwise stretch into ugly gaps. */
.map-shell p,
.map-shell li {
  text-align: justify;
  text-justify: inter-word;
  hyphens: auto;
  -webkit-hyphens: auto;
  -ms-hyphens: auto;
}
.map-hero p,
.map-hero li,
.map-hero-cta,
.map-section-title,
.map-section-title p {
  text-align: left;
  hyphens: manual;
}

/* ---------- User-guide figures ----------
   Each <h2> section in templates/user-guide.html is followed by a
   <figure class="map-figure"> containing an SVG mockup from
   /MAP/static/images/userguide/. The image is constrained to the
   section width with a light border, soft shadow, and a muted-italic
   caption beneath. */
.map-figure {
  margin: 1.1rem 0 1.6rem;
  text-align: center;
}
.map-figure img {
  /* 90% of the section width so the user-guide figures sit slightly
     inset from the body text — easier to read at a glance and leaves
     room for the caption beneath. */
  max-width: 90%;
  height: auto;
  border: 1px solid var(--map-border);
  border-radius: 0.55rem;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
}
.map-figure figcaption {
  margin-top: 0.45rem;
  font-size: 0.83rem;
  color: var(--map-muted);
  font-style: italic;
}

/* ---------- Loader ---------- */
.map-spinner {
  display: inline-block;
  width: 28px;
  height: 28px;
  border: 3px solid #e7e1d8;
  border-top-color: var(--map-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

/* ---------- Utility ---------- */
.text-muted-soft {
  color: var(--map-muted);
}
.divider {
  height: 1px;
  background: var(--map-border);
  margin: 1.25rem 0;
}
.kbd {
  font-family: "JetBrains Mono", monospace;
  background: #f3eee5;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.85rem;
}
.notice {
  background: #fef7e6;
  border: 1px solid #f0d27d;
  color: #826512;
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  margin: 1rem 0;
}
.position-relative {
  position: relative;
}


/* ====================================================================== */
/* Mobile / narrow-viewport overrides                                     */
/* ====================================================================== */

/* Hamburger toggle — injected by app.js into the topbar. Hidden by
   default; the @media block below reveals it at narrow widths. */
.map-nav-toggle {
  display: none;
  border: 1px solid var(--map-border);
  background: #fff;
  border-radius: 0.5rem;
  width: 38px;
  height: 38px;
  cursor: pointer;
  padding: 0;
  align-items: center;
  justify-content: center;
}
.map-nav-toggle .bar {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--map-text);
  margin: 3px 0;
  border-radius: 1px;
}

/* Universal safety nets so a long unbreakable string or Bootstrap row
   negative margin doesn't push the page wider than the viewport. */
html, body {
  max-width: 100%;
  overflow-x: hidden;
}
.map-shell, .map-hero, .map-hero-stats, .map-card,
.explore-grid, .papers-table {
  max-width: 100%;
}
.map-hero > *, .map-hero-stats > *, .explore-grid > * { min-width: 0; }

@media (max-width: 860px) {
  /* --- Hero stacks vertically and the stat-grid collapses to one column */
  .map-hero {
    grid-template-columns: 1fr;
    padding: 1.25rem 1rem;
    border-radius: 0.6rem;
  }
  .map-hero h1 { font-size: 1.45rem; word-break: normal; overflow-wrap: anywhere; }
  .map-hero p  { font-size: 0.9rem; }
  .map-hero-stats {
    grid-template-columns: 1fr 1fr;
    padding: 0.85rem;
    gap: 0.6rem 0.8rem;
  }
  .map-hero-stats .stat .v { font-size: 1.35rem; }
  .map-hero-stats .stat .l { font-size: 0.75rem; }
  .map-hero .btn-light,
  .map-hero .btn-outline-light { font-size: 0.95rem; padding: 0.4rem 0.85rem; }

  /* --- Header: hide the inline nav, show the burger, stash the dropdown.
       Horizontal padding intentionally matches ``.map-shell`` and
       ``.map-footer-inner`` at this breakpoint so all three centre
       to the same gutter. */
  .map-topbar .map-topbar-inner {
    padding: 0.55rem 0.75rem;
    flex-wrap: wrap;
  }
  .map-brand img { height: 44px; }
  .map-nav-toggle { display: inline-flex; }
  .map-nav {
    display: none;
    flex-basis: 100%;
    flex-direction: column;
    gap: 0;
    border-top: 1px solid var(--map-border);
    margin-top: 0.55rem;
    padding-top: 0.35rem;
  }
  .map-nav.is-open { display: flex; }
  .map-nav a { padding: 0.6rem 0.4rem; }

  /* --- Main shell + cards: cosier paddings */
  .map-shell { padding: 0.85rem 0.75rem 2.5rem; }
  .map-card  { padding: 0.9rem 0.9rem; border-radius: 0.55rem; }

  /* --- Tables: keep readable + always-scrollable on overflow */
  .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .papers-table { font-size: 0.82rem; }
  .papers-table thead th,
  .papers-table tbody td {
    padding: 0.4rem 0.45rem;
    white-space: normal;
    word-break: break-word;
  }

  /* --- Section title can collapse to one column */
  .map-section-title {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.4rem;
  }
  .map-section-title h2 { font-size: 1.2rem; }
  .stat-card h3 { font-size: 0.95rem; }

  /* --- Footer reads on one column too at narrow widths.
       Horizontal padding matches .map-shell at this breakpoint so the
       footer line aligns with the body content above it. */
  .map-footer { font-size: 0.78rem; padding: 0.85rem 0; }
  .map-footer-inner { padding: 0 0.75rem; }
}

@media (max-width: 480px) {
  .map-hero          { padding: 1rem 0.85rem; }
  .map-hero h1       { font-size: 1.2rem; }
  .map-hero p        { font-size: 0.85rem; line-height: 1.45; }
  .map-hero-stats    { grid-template-columns: 1fr; padding: 0.75rem; gap: 0.4rem; }
  .map-hero-stats .stat .v { font-size: 1.2rem; }
  .map-hero .btn-light,
  .map-hero .btn-outline-light { width: 100%; }
  .map-hero .map-hero-cta { flex-direction: column; }
  .map-brand img     { height: 36px; }
  .map-shell         { padding: 0.7rem 0.55rem 2rem; }
  /* Keep header + footer aligned with .map-shell at this breakpoint
     (the inherited 860px rule uses 0.75rem, which would leave them
     sitting more inset than the body). */
  .map-topbar .map-topbar-inner { padding: 0.55rem 0.55rem; }
  .map-footer-inner             { padding: 0 0.55rem; }
  .map-card          { padding: 0.75rem 0.75rem; }
}
