/*
 * Design tokens shared with IDBac-KB-Server (idbac.org) so the two sites read as one
 * product. Colours lifted from IDBac-KB-Server/assets/styles.css; keep them in sync.
 *
 * Layout is a fixed top bar over a collapsible sidebar plus a scrolling content column,
 * mirroring the Streamlit app's sidebar so the navigation stays familiar.
 */
:root {
  --idbac-blue: #156082;
  --idbac-blue-hover: #1a7ca1;
  --idbac-blue-soft: #e8f1f5;
  --idbac-grey: #3a3a3a;
  --idbac-border: #dfe3e6;
  --idbac-border-strong: #6f6f6f;
  --idbac-box: #f0f0f0;
  --idbac-accent: #d88000;
  --idbac-ink: #1f2933;
  --idbac-muted: #6b7680;

  --topbar-height: 56px;
  --sidebar-width: 264px;
  /* Left gutter holding the sidebar toggle, reserved in both sidebar states */
  --nav-gutter: 52px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: #fff;
  color: var(--idbac-ink);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { color: var(--idbac-ink); font-weight: 600; }
h3 { font-size: 1.4rem; margin-bottom: .35rem; }

/* ---- top bar ---------------------------------------------------------------- */

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  background: #fff;
  border-bottom: 1px solid var(--idbac-border);
  z-index: 30;
}

.topbar-brand img { height: 34px; display: block; }
.topbar-spacer { flex: 1; }
.topbar .btn { border-radius: 1px; }

/* Hamburger drawn in CSS so there is no icon-font dependency.
   Sits under the top bar, in the shell's left gutter, so the brand keeps the corner. */
.nav-toggle {
  position: fixed;
  top: calc(var(--topbar-height) + 12px);
  left: 7px;
  z-index: 31;
  width: 38px;
  height: 34px;
  padding: 8px 7px;
  background: #fff;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 2px;
  cursor: pointer;
}

.nav-toggle:hover { background: var(--idbac-box); border-color: var(--idbac-border); }
.nav-toggle span {
  display: block;
  height: 2px;
  background: var(--idbac-grey);
  border-radius: 2px;
  transition: transform .18s ease, opacity .18s ease;
}

/* Collapsed state morphs the bars into a chevron so the control reads as a toggle */
body.nav-collapsed .nav-toggle span:nth-child(1) { transform: translateY(3px) rotate(0); }
body.nav-collapsed .nav-toggle span:nth-child(2) { opacity: .45; }

/* ---- shell ------------------------------------------------------------------ */

.shell {
  display: flex;
  padding-top: var(--topbar-height);
  padding-left: var(--nav-gutter);
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  background: #fafbfc;
  border-right: 1px solid var(--idbac-border);
  padding: 18px 14px 40px;
  position: sticky;
  top: var(--topbar-height);
  height: calc(100vh - var(--topbar-height));
  overflow-y: auto;
  transition: flex-basis .2s ease, width .2s ease, padding .2s ease;
}

/* Collapsed to zero width rather than slid out under a negative margin: the shell keeps a
   left gutter for the toggle, so a margin of -(sidebar width) stops one gutter short of
   the viewport edge and leaves a strip of sidebar content showing beside the button. */
body.nav-collapsed .sidebar {
  flex-basis: 0;
  width: 0;
  min-width: 0;
  padding-left: 0;
  padding-right: 0;
  border-right-width: 0;
  overflow: hidden;
}

.sidebar-section { padding-bottom: 14px; border-bottom: 1px solid var(--idbac-border); }

.sidebar-label {
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--idbac-muted);
  margin-bottom: 6px;
}

.task-meta {
  font-size: .78rem;
  color: var(--idbac-muted);
  margin-top: 8px;
  line-height: 1.45;
  word-break: break-word;
}

.sidebar-nav { margin-top: 16px; display: flex; flex-direction: column; }

.sidebar-nav .nav-item {
  display: block;
  padding: 8px 10px;
  margin-bottom: 2px;
  border-radius: 2px;
  border-left: 3px solid transparent;
  color: var(--idbac-ink);
  text-decoration: none;
  font-size: .9rem;
  line-height: 1.3;
}

.sidebar-nav .nav-item:hover { background: var(--idbac-box); }

.sidebar-nav .nav-item.active {
  background: var(--idbac-blue-soft);
  border-left-color: var(--idbac-blue);
  color: var(--idbac-blue);
  font-weight: 600;
}

.sidebar-scrim { display: none; }

.content {
  flex: 1;
  min-width: 0;
  padding: 22px 28px 80px;
  max-width: 1600px;
}

/* On narrow screens the sidebar overlays the content instead of squeezing it */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: var(--nav-gutter);
    z-index: 25;
    box-shadow: 0 2px 12px rgba(0, 0, 0, .12);
  }
  .content { padding: 16px; }
  body:not(.nav-collapsed) .sidebar-scrim {
    display: block;
    position: fixed;
    inset: var(--topbar-height) 0 0 var(--nav-gutter);
    background: rgba(0, 0, 0, .25);
    z-index: 20;
  }
}

/* ---- buttons ---------------------------------------------------------------- */

.button-blue,
.btn-idbac {
  background-color: var(--idbac-blue);
  color: #fff;
  border: 1px solid var(--idbac-border-strong);
  border-radius: 1px;
}

.button-blue:hover,
.btn-idbac:hover { background-color: var(--idbac-blue-hover); color: #fff; }

.grey-box {
  background-color: var(--idbac-box);
  padding: 10px;
  border-radius: 1px;
  border: 1px solid var(--idbac-border-strong);
  margin-top: 5px;
}

/* ---- controls --------------------------------------------------------------- */

.idbac-expander {
  border: 1px solid var(--idbac-border);
  border-radius: 3px;
  margin-bottom: 10px;
  background: #fff;
}

.idbac-expander > summary {
  cursor: pointer;
  padding: 10px 14px;
  font-weight: 600;
  font-size: .92rem;
  background: #f7f9fa;
  list-style: none;
  border-radius: 3px;
  user-select: none;
}

.idbac-expander[open] > summary {
  border-bottom: 1px solid var(--idbac-border);
  border-radius: 3px 3px 0 0;
}

.idbac-expander > summary::-webkit-details-marker { display: none; }

.idbac-expander > summary::before {
  content: '\25B8';
  display: inline-block;
  margin-right: 8px;
  color: var(--idbac-muted);
  transition: transform .15s ease;
}

.idbac-expander[open] > summary::before { transform: rotate(90deg); }

/* Tinted headers for input-file problems. The Streamlit version highlighted these in
 * yellow, which is how a reader spots a task with warnings without opening anything. */
.idbac-expander--warn { border-color: #f2e2b8; }
.idbac-expander--warn > summary { background: #fff8e6; color: #7a5a00; }
.idbac-expander--warn[open] > summary { border-bottom-color: #f2e2b8; }

.idbac-expander--error { border-color: #f3c6c3; }
.idbac-expander--error > summary { background: #fdeceb; color: #8c2f26; }
.idbac-expander--error[open] > summary { border-bottom-color: #f3c6c3; }
.idbac-expander-body { padding: 16px 14px 6px; }

.control { margin-bottom: 16px; }

.control label {
  font-size: .86rem;
  font-weight: 500;
  display: block;
  margin-bottom: 5px;
}

.control .help { font-size: .78rem; color: var(--idbac-muted); margin-top: 4px; }

.control-value {
  font-variant-numeric: tabular-nums;
  color: var(--idbac-blue);
  font-weight: 600;
  margin-left: 6px;
}

/* ---- chip multi-select --------------------------------------------------------
 * A scrolling checkbox list cannot show what is currently selected without scrolling
 * back through it, which is the whole question when picking strains out of hundreds.
 */

.chips { position: relative; }

.chip-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  min-height: 38px;
  padding: 5px 6px;
  border: 1px solid #ced4da;
  border-radius: 3px;
  background: #fff;
}

.chip-box:focus-within {
  border-color: var(--idbac-blue);
  box-shadow: 0 0 0 .18rem rgba(21, 96, 130, .15);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  padding: 2px 4px 2px 9px;
  font-size: .8rem;
  line-height: 1.5;
  color: var(--idbac-blue);
  background: var(--idbac-blue-soft);
  border: 1px solid #bcd6e2;
  border-radius: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  font-size: 15px;
  line-height: 1;
  color: var(--idbac-blue);
  background: transparent;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  flex: 0 0 auto;
}

.chip-x:hover { background: rgba(21, 96, 130, .18); }

.chip-search {
  flex: 1 1 130px;
  min-width: 110px;
  border: 0;
  outline: 0;
  padding: 3px 2px;
  font-size: .86rem;
  background: transparent;
}

.chip-menu {
  position: absolute;
  z-index: 15;
  left: 0;
  right: 0;
  max-height: 230px;
  overflow-y: auto;
  margin-top: 3px;
  background: #fff;
  border: 1px solid var(--idbac-border);
  border-radius: 3px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .10);
}

.chip-option {
  display: block;
  width: 100%;
  text-align: left;
  padding: 7px 11px;
  font-size: .86rem;
  background: transparent;
  border: 0;
  cursor: pointer;
}

.chip-option:hover { background: var(--idbac-blue-soft); color: var(--idbac-blue); }

.chip-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 5px;
  font-size: .78rem;
}

.chip-count { color: var(--idbac-muted); }

.chip-link {
  padding: 0;
  background: none;
  border: 0;
  color: var(--idbac-blue);
  text-decoration: underline;
  cursor: pointer;
  font-size: .78rem;
}

.chip-link:hover { color: var(--idbac-blue-hover); }

/* ---- notices ---------------------------------------------------------------- */

.notice {
  border-radius: 3px;
  padding: 10px 14px;
  margin-bottom: 10px;
  border: 1px solid transparent;
  border-left-width: 4px;
  font-size: .9rem;
}

.notice-info { background: #eef5fa; border-color: #cfe0ec; border-left-color: var(--idbac-blue); }
.notice-warn { background: #fff8e6; border-color: #f2e2b8; border-left-color: var(--idbac-accent); }
.notice-error { background: #fdeceb; border-color: #f3c6c3; border-left-color: #c0392b; }
.notice-success { background: #eaf6ef; border-color: #c3e3d0; border-left-color: #2e7d52; }

.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 260px;
  flex-direction: column;
  gap: 14px;
  color: var(--idbac-muted);
}

.plot-host {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--idbac-border);
  border-radius: 3px;
  padding: 6px;
  margin-top: 14px;
  background: #fff;
}

/* ---- fullscreen plots -------------------------------------------------------- */

.plot-frame { position: relative; }

/* Covers the window rather than entering browser fullscreen, which is refused inside the
   cross-origin iframes GNPS2 embeds this app in. */
.plot-frame.is-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 100;
  margin: 0;
  padding: 8px;
  background: #fff;
  overflow: auto;
}

.plot-frame.is-fullscreen .plot-host {
  margin-top: 0;
  border: 0;
}

body.has-fullscreen-plot { overflow: hidden; }

.plot-fullscreen {
  position: absolute;
  top: 20px;
  right: 8px;
  z-index: 2;
  width: 30px;
  height: 30px;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Plotly's own modebar fades in on hover; this control sits beside it and matches. */
  opacity: .35;
  background: #fff;
  border: 1px solid transparent;
  border-radius: 2px;
  cursor: pointer;
  transition: opacity .15s ease;
}

.plot-frame:hover .plot-fullscreen,
.plot-fullscreen:focus-visible { opacity: 1; }
.plot-fullscreen:hover { opacity: 1; border-color: var(--idbac-border); }

.plot-frame.is-fullscreen .plot-fullscreen {
  position: fixed;
  top: 10px;
  right: 14px;
  opacity: 1;
  border-color: var(--idbac-border);
}

.plot-fullscreen svg {
  width: 100%;
  height: 100%;
  fill: none;
  stroke: var(--idbac-grey);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.download-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

code.share-link {
  display: block;
  word-break: break-all;
  background: var(--idbac-box);
  border: 1px solid var(--idbac-border);
  padding: 8px;
  font-size: .78rem;
  color: var(--idbac-grey);
  border-radius: 2px;
}

.table-responsive table { font-size: .86rem; }
.table-responsive thead th { font-size: .8rem; white-space: nowrap; }
