/*
 * .SYNOPSIS
 * chrome.css - the web part's own UI (toolbar, theme switcher, editor, version
 * panel). Themed from the same variables as the content so the frame never
 * fights the markdown it wraps.
 *
 * .USAGE
 *   Loaded in this order by MarkstrataWebPart.ts, because later rules
 *   override earlier ones:
 *
 *     base, typography, code, syntax, callouts, tables-lists, extras,
 *     chrome, the three themes, modifiers, print
 *
 * .NOTES
 * Since:     0.0.6
 * Ships in:  the web part bundle
 * Requires:  nothing else in this project
 */

.strata-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 0;
  border-bottom: 1px solid var(--strata-border);
  margin-bottom: 12px;
  font-size: 0.8125em;
  color: var(--strata-text-muted);
}

/*
 * Kept in view while the document scrolls under it, where the author asked
 * for that.
 *
 * It sticks to --strata-chrome-offset rather than to zero, because on a
 * SharePoint page the top of the window already belongs to the suite bar and
 * the command bar: stuck at zero the toolbar comes to rest behind them, which
 * is a toolbar nobody can reach rather than one always in reach.
 * ScrollOffset measures that and publishes it.
 *
 * The background is not decoration. A sticky element with none is a strip of
 * text with the document sliding through it.
 */
.strata-root[data-strata-toolbar='sticky'] .strata-toolbar {
  position: sticky;
  top: var(--strata-chrome-offset, 0px);
  /* Above the sticky table headers, which are 1, and the pinned meta line,
     which is 2 and sticks to the other end. */
  z-index: 3;
  background-color: var(--strata-bg);
}

/*
 * And the contents sidebar comes down to meet it.
 *
 * The sidebar sticks 16px from the top of the window, which was right when
 * nothing of ours was up there. Left alone it would scroll up behind a sticky
 * toolbar. Scoped to this mode rather than fixed everywhere, so a web part
 * that has not asked for a sticky toolbar keeps the layout it has.
 */
.strata-root[data-strata-toolbar='sticky'] .strata-toc-sidebar {
  top: var(--strata-scroll-offset, 16px);
}

.strata-toolbar-spacer {
  flex: 1 1 auto;
}

/*
 * The actions sit together at the end of the bar with one border around the
 * group, so the eye reads a single control rather than three loose buttons of
 * whatever width their words happened to need.
 */
.strata-toolbar-actions {
  display: inline-flex;
  align-items: center;
  margin-left: auto;
  border: 1px solid var(--strata-border);
  border-radius: var(--strata-radius-sm);
  overflow: hidden;
}

.strata-toolbar-actions .strata-btn {
  border: 0;
  border-radius: 0;
  background-color: transparent;
}

.strata-toolbar-actions .strata-btn + .strata-btn {
  border-left: 1px solid var(--strata-border);
}

/*
 * The colour-mode toggle, drawn as one shape that travels between a sun and a
 * moon. Three parts move together: the disc grows, the mask circle slides over
 * it to bite out a crescent, and the beams turn and fade. The beams leave the
 * 24-unit box at their tips, so the icon may not clip.
 *
 * Every transform is measured from the middle of its own shape, which is what
 * fill-box gives; the default for SVG is the user-space origin, where a scale
 * would throw the disc up and to the left instead of growing it in place.
 */
.strata-mode-toggle .strata-icon {
  overflow: visible;
}

.strata-theme-disc,
.strata-theme-beams {
  transform-box: fill-box;
  transform-origin: center;
}

/* A light page is a sun. The icon says which mode the page is in, so it turns
   with the page rather than against it when the reader switches. */
.strata-theme-disc {
  transform: scale(0.85);
  transition: transform 0.5s cubic-bezier(0.25, 0, 0.3, 1);
}

.strata-theme-bite {
  transform: translateX(0);
  transition: transform 0.5s cubic-bezier(0, 0, 0, 1);
}

.strata-theme-beams {
  opacity: 1;
  transform: rotate(0deg) scale(1);
  transition: transform 0.5s cubic-bezier(0.5, 1.25, 0.75, 1.25), opacity 0.35s ease;
}

/* A dark page is a moon: the beams draw in, the disc swells, and the bite
   slides across it. */
.strata-mode-toggle--dark .strata-theme-disc {
  transform: scale(1.2);
}

.strata-mode-toggle--dark .strata-theme-bite {
  transform: translateX(-9px);
  /* It starts across only once the beams are on their way in, so the crescent
     is never drawn with rays still coming off it. */
  transition-delay: 0.1s;
}

.strata-mode-toggle--dark .strata-theme-beams {
  opacity: 0;
  transform: rotate(-25deg) scale(0.6);
  transition-duration: 0.25s, 0.2s;
}

/* Asked for less movement: the icon still changes, it just does not travel. */
@media (prefers-reduced-motion: reduce) {
  .strata-theme-disc,
  .strata-theme-bite,
  .strata-theme-beams {
    transition: none;
  }
}

.strata-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--strata-border);
  border-radius: var(--strata-radius-sm);
  background-color: var(--strata-bg-elevated);
  color: var(--strata-text);
  font-family: inherit;
  font-size: inherit;
  line-height: 1.4;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.strata-btn:hover {
  background-color: var(--strata-bg-hover);
  border-color: var(--strata-border-strong);
}

.strata-btn[aria-pressed='true'],
.strata-btn.is-active {
  border-color: var(--strata-link);
  color: var(--strata-link);
}

.strata-btn[disabled] {
  opacity: 0.5;
  cursor: default;
}

.strata-btn-primary {
  border-color: var(--strata-link);
  background-color: var(--strata-link);
  color: var(--strata-on-accent);
}

.strata-btn-primary:hover {
  background-color: var(--strata-link-hover);
  border-color: var(--strata-link-hover);
}

.strata-select {
  padding: 4px 6px;
  border: 1px solid var(--strata-border);
  border-radius: var(--strata-radius-sm);
  background-color: var(--strata-bg-elevated);
  color: var(--strata-text);
  font-family: inherit;
  font-size: inherit;
}

.strata-switcher {
  display: flex;
  align-items: center;
  gap: 6px;
}

.strata-switcher label {
  color: var(--strata-text-faint);
}

.strata-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin-top: 16px;
  padding-top: 10px;
  border-top: 1px solid var(--strata-border);
  color: var(--strata-text-faint);
  font-size: 0.8125em;
}

/*
 * Tags a document gave itself in its frontmatter. Quiet on purpose: they label
 * the document, they are not navigation, and the footer they sit in is meant to
 * stay out of the way of the text above it.
 */
.strata-meta .strata-tag {
  padding: 1px 8px;
  border: 1px solid var(--strata-border);
  border-radius: 999px;
  background-color: var(--strata-bg-elevated);
  color: var(--strata-text-muted);
  font-size: 0.9em;
  line-height: 1.5;
}

/*
 * Pinned, the file name and modified date stay in view for the whole document
 * rather than only at the end of it. Sticky rather than fixed, so it belongs to
 * the web part: it rides the bottom of the window while the web part is on
 * screen and scrolls away with it, instead of sitting over the page.
 *
 * It needs its own background for that. Sticky leaves the element in the flow,
 * so without one the text it is passing over shows through.
 */
.strata-root[data-strata-meta='pinned'] .strata-meta {
  position: sticky;
  bottom: 0;
  z-index: 2;
  margin-top: 16px;
  padding-bottom: 10px;
  background-color: var(--strata-bg);
}

.strata-status {
  padding: 4px 8px;
  border-radius: var(--strata-radius-sm);
  background-color: var(--strata-bg-elevated);
  color: var(--strata-text-muted);
}

.strata-status[data-tone='error'] {
  background-color: rgba(var(--strata-color-red), 0.12);
  color: rgb(var(--strata-color-red));
}

.strata-status[data-tone='success'] {
  background-color: rgba(var(--strata-color-green), 0.12);
  color: rgb(var(--strata-color-green));
}

/*
 * The bar that appears over a document the reader followed a link to. It says
 * which one is open and offers the way back, and it sits above everything else
 * because it is the answer to "where am I".
 */
/*
 * No box. It was a bordered, filled bar when it held one sentence and a
 * button, which needed separating from the document under it. A trail does
 * not: it reads as the line above a page, the way breadcrumbs do everywhere
 * else, and a panel around it competes with the document for the eye.
 */
.strata-open-doc {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  font-size: 0.8125em;
  color: var(--strata-text-muted);
}

/*
 * In the toolbar it is a row of its own rather than another item on the end of
 * the controls: full width forces the wrap, and the toolbar's own padding and
 * rule close underneath it. The margin goes, because the toolbar already has
 * one and two of them read as a gap nobody asked for.
 */
.strata-toolbar > .strata-open-doc {
  flex: 0 0 100%;
  margin-bottom: 0;
}

/*
 * The trail the reader walked, as breadcrumbs. Wraps rather than scrolling or
 * collapsing: a crumb that is off the edge or behind an ellipsis is a way back
 * the reader cannot see, which is the thing this replaced a single Back button
 * to fix.
 */
.strata-crumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.strata-crumb {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

/* On the separator rather than between the items, so a wrapped line does not
   begin with one. */
.strata-crumb + .strata-crumb::before {
  content: '\203A';
  color: var(--strata-text-muted);
  opacity: 0.7;
}

/*
 * A crumb is a button where the web part can open the document itself, and an
 * anchor where the crumb is another SharePoint page and crossing to it is a
 * navigation. They sit in one bar and have to read as one thing, so the rule
 * covers both: the anchor gives up its underline here and takes it back on
 * hover, which is what the buttons beside it already do.
 */
.strata-crumb-link {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: var(--strata-link);
  cursor: pointer;
  text-decoration: none;
}

.strata-crumb-link:hover,
.strata-crumb-link:focus-visible {
  text-decoration: underline;
}

/* Where the reader is. Not a button, so it carries the document's weight
   rather than a link's colour. */
.strata-crumb-here {
  font-weight: 600;
  color: var(--strata-text);
}

/* On paper the bar is chrome, and the document is the point. */
@media print {
  .strata-open-doc { display: none; }
}

/* ------------------------------------------------------------------ editor */

/*
 * The editor is one row of a fixed height with the panes stretched into it,
 * rather than two boxes each as tall as whatever is in it. Sized from the
 * content, the source stopped at 420px while the preview ran on beside it, so
 * the half of the split you type into was the half with an empty area under
 * it - and the two halves cannot be read across if they are not the same box.
 */
.strata-editor {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
  height: 70vh;
  min-height: 420px;
}

.strata-editor[data-layout='split'] {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

/*
 * Each pane is a label above a box, and the box takes the rest of the pane.
 * The label is outside the box in both, because it was outside the textarea
 * and inside the preview's border, which started the two panes at different
 * heights and put every line of the source a label's worth below its own
 * rendering.
 */
.strata-editor-pane,
.strata-preview-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  /* A flex item is floored at its content, and the preview's content is the
     whole document: without this the pane grows to fit it and drags the row
     it was given out of shape. */
  min-height: 0;
}

.strata-editor[data-layout='preview'] .strata-editor-pane,
.strata-editor[data-layout='edit'] .strata-preview-pane {
  display: none;
}

.strata-editor-input,
.strata-preview-box {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding: 12px 14px;
  border: 1px solid var(--strata-border);
  border-radius: var(--strata-radius-md);
}

.strata-editor-input {
  display: block;
  width: 100%;
  background-color: var(--strata-code-bg);
  color: var(--strata-code-text);
  font-family: var(--strata-font-mono);
  font-size: var(--strata-code-font-size);
  line-height: var(--strata-code-line-height);
  /* The pane decides how tall this is now, and a dragged corner would only
     put the two halves back out of step with each other. */
  resize: none;
  tab-size: 2;
}

.strata-editor-input:focus {
  outline: 2px solid var(--strata-link);
  outline-offset: -1px;
}

.strata-pane-label {
  margin-bottom: 6px;
  font-size: 0.75em;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--strata-text-faint);
}

/* A web part in a narrow column must drop the split view, or the editor and
   the Save button end up squeezed out of reach. Keyed on the web part's own
   width, with a viewport media query as the fallback. */
@container mdf (max-width: 720px) {
  .strata-editor[data-layout='split'] {
    grid-template-columns: 1fr;
    /* Stacked, the panes are read one after the other rather than across, so
       each takes a height of its own instead of halving one row between
       them. */
    height: auto;
  }

  .strata-editor[data-layout='split'] .strata-editor-pane,
  .strata-editor[data-layout='split'] .strata-preview-pane {
    height: 40vh;
  }
}

@supports not (container-type: inline-size) {
  @media (max-width: 900px) {
    .strata-editor[data-layout='split'] {
      grid-template-columns: 1fr;
      height: auto;
    }

    .strata-editor[data-layout='split'] .strata-editor-pane,
    .strata-editor[data-layout='split'] .strata-preview-pane {
      height: 40vh;
    }
  }
}

/* The toolbar wraps rather than clipping, so Save stays reachable however
   narrow the column is. */
.strata-toolbar > .strata-btn-primary {
  margin-left: auto;
}

/* ------------------------------------------------------------ version panel */

.strata-panel {
  margin-bottom: 12px;
  border: 1px solid var(--strata-border);
  border-radius: var(--strata-radius-md);
  background-color: var(--strata-bg-elevated);
  overflow: hidden;
}

.strata-panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--strata-border);
  font-weight: 600;
}

.strata-panel-body {
  max-height: 320px;
  overflow-y: auto;
  padding: 4px 0;
}

.strata-version {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--strata-border);
  font-size: 0.875em;
}

.strata-version:last-child {
  border-bottom: 0;
}

.strata-version-label {
  min-width: 3.5em;
  font-family: var(--strata-font-mono);
  color: var(--strata-text-muted);
}

.strata-version-meta {
  flex: 1 1 auto;
  min-width: 0;
  color: var(--strata-text-muted);
}

.strata-version-current {
  padding: 1px 6px;
  border-radius: 999px;
  background-color: rgba(var(--strata-color-green), 0.15);
  color: rgb(var(--strata-color-green));
  font-size: 0.85em;
}

/*
 * How long the document takes to read, beside the theme control rather than
 * among the buttons: it describes the document, it is not something to do
 * to it.
 */
/*
 * One rule sizes and colours every icon in the bar. They are 24x24 outlines
 * inheriting currentColor, so a button's own colour carries into its icon and
 * no icon has to be told about the theme.
 */
.strata-icon {
  width: 1em;
  height: 1em;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  /* Optical: an outline on the same grid as text sits a shade high. */
  vertical-align: -0.12em;
}

/*
 * How long the document takes to read, as a quiet pill rather than loose grey
 * text. It is the one thing in the bar that is a fact about the document
 * rather than a control, so it is shaped differently from everything else.
 */
.strata-reading-time {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px 3px 7px;
  border-radius: 999px;
  background-color: var(--strata-bg-elevated);
  color: var(--strata-text-faint);
  font-size: 0.8125em;
  line-height: 1.5;
  white-space: nowrap;
}

.strata-reading-time .strata-icon {
  opacity: 0.85;
}

/*
 * Back to the top of the document.
 *
 * Fixed to the window, because the web part is a section of somebody's page
 * and the reader's screen is what the button needs to stay on. It is hidden
 * with the hidden attribute rather than by opacity, so it leaves the tab order
 * while it cannot do anything.
 */
.strata-to-top {
  position: fixed;
  bottom: 24px;
  z-index: 40;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--strata-border-strong);
  border-radius: 50%;
  background-color: var(--strata-bg-elevated);
  color: var(--strata-text-muted);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}

/*
 * The hidden attribute is display:none in the UA stylesheet, which a class
 * setting display:flex beats on specificity: without this the button ignored
 * being hidden and sat on screen from the moment the page loaded.
 */
.strata-to-top[hidden] {
  display: none;
}

.strata-to-top[data-strata-side='right'] { right: 24px; }
.strata-to-top[data-strata-side='left'] { left: 24px; }

.strata-to-top:hover {
  background-color: var(--strata-bg);
  color: var(--strata-text);
}

.strata-to-top:focus-visible {
  outline: 2px solid var(--strata-link);
  outline-offset: 2px;
}

/* A narrow screen has less room to spare beside the text. */
@media (max-width: 600px) {
  .strata-to-top { bottom: 16px; }
  .strata-to-top[data-strata-side='right'] { right: 12px; }
  .strata-to-top[data-strata-side='left'] { left: 12px; }
}

/* Neither belongs on paper. */
@media print {
  .strata-to-top { display: none; }
}


/*
 * In a narrow column the action labels go and the icons carry the buttons.
 * The label stays in the markup, so a screen reader still reads "Reload"
 * rather than announcing an unnamed button.
 */
@media (max-width: 560px) {
  .strata-toolbar-actions .strata-btn-label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .strata-toolbar-actions .strata-btn {
    padding: 6px 9px;
  }
}

/*
 * A web part nobody has pointed at a document yet.
 *
 * Outside the themed root on purpose: there is no document, so there is no
 * theme to sit inside, and this has to be legible on whatever the page or the
 * Teams tab is painted with. It follows the reader's colour scheme directly
 * rather than the web part's, for the same reason.
 */
.strata-unconfigured {
  max-width: 34em;
  margin: 24px auto;
  padding: 20px 22px;
  border: 1px dashed #8a8886;
  border-radius: 8px;
  background: #faf9f8;
  color: #323130;
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  text-align: center;
}

.strata-unconfigured-heading {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 600;
}

.strata-unconfigured-body { margin: 0; }

.strata-unconfigured-sample {
  margin-top: 14px;
  padding: 8px 16px;
  border: 1px solid #0E7C86;
  border-radius: 4px;
  background: #0E7C86;
  color: #ffffff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.strata-unconfigured-sample:hover { background: #0a626a; border-color: #0a626a; }
.strata-unconfigured-sample:focus-visible { outline: 2px solid #F0A442; outline-offset: 2px; }

@media (prefers-color-scheme: dark) {
  .strata-unconfigured {
    border-color: #605e5c;
    background: #201f1e;
    color: #f3f2f1;
  }
}
