/*
 * SMILES viewer: the tool's own layout (Phase 17, parcel V5a). Loaded by no page yet (the lab only).
 * Colours are inherited from the page's theme (no colour is set here, so both themes follow the sheets
 * that load beside it); the panel's own look comes from mathpix-chemistry.css. V5b says whether any rule
 * must move to light.css and dark.css.
 *
 * Layout: one column at every width by default, in the same DOM order as MathPix mode. From 60rem the
 * drawing and the identifiers sit side by side. Text that can wrap is start-aligned, never centred.
 */

.smiles-viewer {
  max-width: none;
  text-align: start;
}

/* V8: the mark is centred on the word, not hung from its baseline. */
.smiles-viewer-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

/* Alpha mark: words in a ring, so it does not rely on colour. */
.smiles-viewer-alpha {
  font-size: 0.55em;
  font-weight: 600;
  padding: 0.1em 0.6em;
  border: 0.1rem solid currentColor;
  border-radius: 0.4rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* V9: lifts tools.html's page-wide `form { max-width: 750px; }` for this tool's two forms only. */
.smiles-viewer .smiles-viewer-form,
.smiles-viewer .smiles-viewer-result {
  max-width: none;
}

.smiles-viewer-form {
  margin-block: 1.2rem;
}

.smiles-viewer-label {
  display: block;
  font-weight: 600;
  margin-block-end: 0.4rem;
}

.smiles-viewer-input-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
  align-items: stretch;
}

.smiles-viewer-input {
  flex: 1 1 18rem;
  min-width: 0;
  min-height: 2.75rem;
  padding: 0.4rem 0.8rem;
  font-family: monospace;
  font-size: 1.6rem;
}

.smiles-viewer-buttons {
  display: flex;
  gap: 0.8rem;
}

/* V8: main.css gives every button margin: 0.5rem 0.3rem 0.5rem 0, which pushed these two below the input. */
.smiles-viewer-buttons .chemistry-action-btn {
  min-height: 2.75rem;
  min-width: 4.5rem;
  margin: 0;
}

.smiles-viewer-help,
.smiles-viewer-message {
  margin-block: 0.6rem 0;
  text-align: start;
  overflow-wrap: anywhere;
}

/* A message that has to be read: a bar on the start edge and bold type, so colour is not the signal. */
.smiles-viewer-message {
  font-weight: 700;
  padding-inline-start: 0.8rem;
  border-inline-start: 0.4rem solid currentColor;
}

.smiles-viewer-message[hidden],
.smiles-viewer-result[hidden] {
  display: none;
}

/* The result: a single column (DOM order is MathPix's order). */
.smiles-viewer-result {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.2rem;
  margin-block-start: 1.6rem;
}

.smiles-viewer-result > * {
  min-width: 0;
}

/* Long SMILES and InChI strings wrap inside the column (start-aligned) rather than scrolling sideways. */
.smiles-viewer-result .chemistry-value,
.smiles-viewer-result .chemistry-code,
.smiles-viewer-result p {
  overflow-wrap: anywhere;
  text-align: start;
}

.smiles-viewer-result .chemistry-structure svg,
.smiles-viewer-result .chemistry-svg {
  max-width: 100%;
  height: auto;
}

/* The buttons stack to full width on a narrow screen and wrap side by side on a wide one. */
.smiles-viewer-result .chemistry-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.8rem;
}

.smiles-viewer-result .chemistry-actions .chemistry-action-btn,
.smiles-viewer-report .chemistry-action-btn {
  min-height: 2.75rem;
  text-align: start;
}

@media (max-width: 40rem) {
  .smiles-viewer-result .chemistry-actions {
    flex-direction: column;
  }

  .smiles-viewer-result .chemistry-actions .chemistry-action-btn,
  .smiles-viewer-report .chemistry-action-btn,
  .smiles-viewer-buttons {
    width: 100%;
  }

  .smiles-viewer-buttons .chemistry-action-btn {
    flex: 1 1 0;
  }
}

/* Wide: the drawing and the style controls on the start side, the identifiers and actions beside them. */
/* V8: two columns in DOM order (multi-column, not grid). Column 1 holds the drawing and the style controls;
   a forced break before the identifiers starts column 2 (identifiers, descriptions, action buttons); the
   report button spans both. The DOM is unchanged, so the Tab order runs down column 1, then column 2. */
@media (min-width: 60rem) {
  .smiles-viewer-result {
    display: block;
    columns: 2;
    column-gap: 2.4rem;
    column-fill: balance;
  }

  .smiles-viewer-result > * {
    break-inside: avoid;
    margin-block-end: 1.2rem;
  }

  .smiles-viewer-result > .chemistry-identifiers {
    break-before: column;
  }

  .smiles-viewer-result > .smiles-viewer-report {
    column-span: all;
  }

  /* A readable line in the description text, wherever the column is wide. */
  .smiles-viewer-result .chemistry-structural-desc p,
  .smiles-viewer-result .chemistry-comprehensive-desc p {
    max-width: 75ch;
  }
}
