/*
  The Manage page (/manage/). Only that page loads this file. Its own classes
  start with "m-".

  The page keeps the theme's colours, type and corner shapes, read from the
  variables each theme file sets. But it always draws thin, soft lines, whatever
  the theme's own lines are like, so the lists and forms stay calm in every
  theme. The only colours named here are the ones that must not follow the
  theme: the dimming behind a popup, shadows, white on the red delete button,
  and the little pictures of each theme in the theme picker.

  The article preview popup shows a story with the story page's own markup and
  styles. The few sizes each theme changes for it are at the end of that
  theme's file, under ".m-preview".
*/

:root {
  --m-line: color-mix(in srgb, var(--ink) 14%, transparent);
  --m-line-strong: color-mix(in srgb, var(--ink) 48%, transparent);
  --m-fill: color-mix(in srgb, var(--ink) 6%, transparent);
}

/* The page fills in after signing in. A full-height page keeps the footer from jumping when it does. */
.manage-main {
  min-height: 100vh;
  padding: clamp(2rem, 5vw, 3.5rem) var(--gutter) clamp(3rem, 6vw, 5rem);
}

.wrap-form {
  max-width: 52rem;
  margin-inline: auto;
}

/* The page behind an open popup does not scroll. */
html:has(.m-dialog[open]) {
  overflow: hidden;
}

.m-title {
  font-size: 1.75rem;
  line-height: 1.2;
}

.m-sub {
  margin-top: 0.3rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.m-hint {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.45;
}

.m-hint-split {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0 1rem;
}

/* Buttons */
.m-btn {
  position: relative;
  display: inline-flex;
  flex: none;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.5rem;
  border: 1px solid var(--m-line-strong);
  border-radius: var(--btn-radius);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  padding: 0 1rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
}

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

.m-btn:disabled {
  opacity: 0.55;
  pointer-events: none;
}

/* A button-styled label around a file input: show the keyboard focus that is on the input inside. */
.m-btn:has(input:focus-visible) {
  outline: var(--paint) solid var(--accent);
  outline-offset: 3px;
}

.m-btn-primary {
  border-color: var(--btn-solid-bg);
  background: var(--btn-solid-bg);
  color: var(--btn-solid-ink);
}

.m-btn-primary:hover {
  border-color: var(--btn-hover-bg);
  background: var(--btn-hover-bg);
  color: var(--btn-hover-ink);
}

.m-btn-danger {
  border-color: var(--stop);
  background: var(--stop);
  color: #fff;
}

.m-btn-danger:hover {
  border-color: var(--stop);
  filter: brightness(0.92);
}

.m-btn-quiet {
  border-color: transparent;
  background: transparent;
  color: var(--ink-soft);
  padding: 0 0.75rem;
}

.m-btn-quiet:hover {
  border-color: transparent;
  background: var(--m-fill);
  color: var(--ink);
}

.m-btn-quiet.m-btn-delete:hover {
  color: var(--stop);
}

.m-btn-sm {
  min-height: 2.1rem;
  padding: 0 0.7rem;
  font-size: 0.85rem;
}

.m-icon-btn {
  display: grid;
  flex: none;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border: 0;
  border-radius: var(--btn-radius);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0;
  font: inherit;
  font-size: 1.5rem;
  line-height: 1;
}

.m-icon-btn:hover {
  background: var(--m-fill);
  color: var(--ink);
}

.m-button-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.m-button-row-end {
  justify-content: flex-end;
}

/* Forms. Fields stay together at the top when the form's box is taller than they are, as in a
   popup that fills a phone screen. */
.m-form {
  display: grid;
  align-content: start;
  gap: 1.25rem;
}

.m-field {
  display: grid;
  gap: 0.4rem;
  min-width: 0;
}

.m-label {
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.4;
}

.m-optional {
  margin-left: 0.3rem;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 400;
}

.m-label-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem 1rem;
}

.m-input {
  width: 100%;
  min-height: 2.75rem;
  border: 1px solid var(--m-line-strong);
  border-radius: var(--field-radius);
  background: var(--page);
  color: var(--ink);
  padding: 0.6rem 0.8rem;
  font: inherit;
  font-size: 1rem;
  line-height: 1.4;
}

/* One-line fields and lists share one height, so two side by side line up. */
input.m-input,
select.m-input {
  height: 2.75rem;
}

/* Sentences that will be read on the site are typed in the typeface they are read in. */
textarea.m-input {
  display: block;
  resize: vertical;
  font-family: var(--font-read);
  font-size: 1.0625rem;
  line-height: 1.55;
}

.m-input-body {
  min-height: 14rem;
}

/* Example text keeps the full "muted" colour, which is dark enough to read on every theme. */
.m-input::placeholder {
  color: var(--muted);
  opacity: 1;
}

.m-input:focus-visible {
  border-color: var(--ink);
  outline-offset: 0;
}

.m-grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1.25rem 1rem;
  align-items: start;
}

.m-field-narrow {
  max-width: calc(50% - 0.5rem);
}

.m-field-error,
.m-form-error {
  color: var(--stop);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.4;
}

.m-alert {
  border-left: 3px solid var(--btn-solid-bg);
  border-radius: var(--field-radius);
  background: var(--m-fill);
  padding: 0.7rem 0.9rem;
  font-size: 0.9rem;
  line-height: 1.45;
}

.m-alert.is-error {
  border-left-color: var(--stop);
  background: color-mix(in srgb, var(--stop) 9%, transparent);
}

.m-alert-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 1rem;
  margin-top: 1.25rem;
}

/* File pickers: a dashed area that also accepts a dragged file. The real input is inside it. */
.m-drop {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 0.2rem;
  border: 1px dashed var(--m-line-strong);
  border-radius: var(--field-radius);
  background: var(--page);
  cursor: pointer;
  padding: 1.25rem 1rem;
  text-align: center;
}

.m-drop:hover,
.m-drop.is-dragover {
  border-color: var(--ink);
  border-style: solid;
}

.m-drop:has(input:focus-visible) {
  outline: var(--paint) solid var(--accent);
  outline-offset: 3px;
}

.m-drop-main {
  max-width: 100%;
  overflow-wrap: anywhere;
  font-size: 0.95rem;
  font-weight: 600;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

.m-drop.has-file .m-drop-main {
  text-decoration: none;
}

.m-drop-hint {
  color: var(--muted);
  font-size: 0.85rem;
}

.m-photo,
.m-portrait {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.m-photo-img,
.m-portrait-img {
  flex: none;
  border-radius: var(--field-radius);
  background: var(--m-fill);
  object-fit: cover;
}

.m-photo-img {
  width: 10rem;
  aspect-ratio: 3 / 2;
}

.m-portrait-img {
  width: 5.5rem;
  height: 5.5rem;
}

.m-photo.is-busy .m-photo-img {
  opacity: 0.45;
}

.m-photo-side,
.m-portrait-side {
  display: grid;
  gap: 0.5rem;
  min-width: 0;
}

.m-attach-name {
  color: var(--muted);
  font-size: 0.9rem;
  overflow-wrap: anywhere;
}

.m-attach-name.has-file {
  color: var(--ink);
  font-weight: 500;
}

/* "More options" in the article popup */
.m-more {
  border-top: 1px solid var(--m-line);
  padding-top: 1.1rem;
}

.m-more > summary {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: fit-content;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  list-style: none;
}

.m-more > summary::-webkit-details-marker {
  display: none;
}

.m-more > summary::before {
  content: '';
  width: 0.42rem;
  height: 0.42rem;
  margin-left: 0.15rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
}

.m-more[open] > summary::before {
  transform: translateY(-0.12rem) rotate(45deg);
}

.m-more-body {
  padding-top: 1.25rem;
}

/* Page header, tabs and lists */
.m-gate {
  display: grid;
  justify-items: start;
  gap: 1rem;
  padding: 1.5rem 0;
  color: var(--muted);
}

.m-login {
  max-width: 23rem;
  margin: 2rem auto 0;
}

.m-login .m-form {
  margin-top: 1.75rem;
}

.m-login .m-btn {
  min-height: 2.75rem;
}

.m-login-back {
  margin-top: 1.5rem;
  font-size: 0.9rem;
}

.m-login-back a {
  color: var(--muted);
  text-decoration: none;
}

.m-login-back a:hover {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.m-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem 1rem;
}

/* Quiet buttons have invisible padding; pull them out so their text lines up with the edges. */
.m-head-actions {
  display: flex;
  gap: 0.25rem;
  margin: 0 -0.75rem;
}

.m-tabs {
  display: flex;
  gap: 1.75rem;
  margin: 1.75rem 0 1.5rem;
  overflow-x: auto;
  box-shadow: inset 0 -1px 0 var(--m-line);
  scrollbar-width: none;
}

.m-tabs::-webkit-scrollbar {
  display: none;
}

.m-tabs button {
  flex: none;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--muted);
  cursor: pointer;
  padding: 0.65rem 0;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
}

.m-tabs button:hover {
  color: var(--ink);
}

.m-tabs button[aria-selected='true'] {
  border-bottom-color: var(--btn-solid-bg);
  color: var(--ink);
}

.m-tabs button:focus-visible {
  outline-offset: -2px;
}

.m-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-bottom: 1rem;
}

.m-count {
  color: var(--muted);
  font-size: 0.95rem;
}

.m-list {
  margin: 0;
  border: 1px solid var(--m-line);
  border-radius: var(--box-radius);
  background: var(--panel);
  padding: 0;
  list-style: none;
}

.m-row {
  display: flex;
  align-items: center;
  gap: 0.5rem 1rem;
  border-top: 1px solid var(--m-line);
  padding: 0.9rem 1.1rem;
}

.m-row:first-child {
  border-top: 0;
}

.m-row-main {
  flex: 1 1 auto;
  min-width: 0;
}

.m-row-title {
  display: block;
  max-width: 100%;
  border: 0;
  background: none;
  color: var(--ink);
  padding: 0;
  font: inherit;
  font-size: 1.02rem;
  font-weight: 600;
  line-height: 1.35;
  text-align: left;
}

button.m-row-title {
  cursor: pointer;
}

button.m-row-title:hover {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
}

.m-row-meta {
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.85rem;
  overflow-wrap: anywhere;
}

.m-row-actions {
  display: flex;
  flex: none;
  gap: 0.1rem;
  margin-right: -0.4rem;
}

.m-empty {
  padding: 2.5rem 1.25rem;
  color: var(--muted);
  text-align: center;
}

/* Profile and settings */
.m-panel {
  border: 1px solid var(--m-line);
  border-radius: var(--box-radius);
  background: var(--panel);
  padding: 1.5rem;
}

.m-panel + .m-panel {
  margin-top: 1.5rem;
}

.m-help {
  margin-top: 2.5rem;
}

.m-help-list {
  display: grid;
  gap: 0.5rem;
  margin-top: 1rem;
  font-size: 0.95rem;
}

.m-help-list div {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
}

.m-help-list dt {
  min-width: 4rem;
  color: var(--muted);
  font-weight: 600;
}

.m-help-list dd {
  margin: 0;
}

.m-help-list a {
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.m-group {
  display: grid;
  gap: 1.25rem;
}

.m-group + .m-group {
  border-top: 1px solid var(--m-line);
  padding-top: 1.5rem;
}

.m-group-title {
  font-size: 1.15rem;
  line-height: 1.3;
}

.m-group-title + .m-hint {
  margin-top: 0.3rem;
}

.m-facts {
  display: grid;
  gap: 0.6rem;
}

.m-facts:empty {
  display: none;
}

.m-fact {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr) minmax(0, 1.2fr) auto;
  gap: 0.5rem;
  align-items: center;
}

/* Stays at the bottom of the window while the profile form is on screen. */
.m-savebar {
  position: sticky;
  bottom: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem 1rem;
  margin: 0 -1.5rem -1.5rem;
  border-top: 1px solid var(--m-line);
  border-radius: 0 0 var(--box-radius) var(--box-radius);
  background: var(--panel);
  padding: 0.9rem 1.5rem;
}

.m-savebar .m-form-error {
  flex: 1 1 14rem;
}

.m-savebar-note {
  color: var(--muted);
  font-size: 0.9rem;
}

/* Theme picker in Settings. The little pictures use each theme's own colours, whatever theme is showing. */
.theme-options {
  display: grid;
  gap: 0.6rem;
}

.theme-option {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  border: 1px solid var(--m-line-strong);
  border-radius: var(--field-radius);
  background: var(--page);
  padding: 0.75rem 0.9rem;
}

.theme-option:hover {
  border-color: var(--ink);
}

.theme-option:has(input:checked) {
  border-color: var(--btn-solid-bg);
  box-shadow: inset 0 0 0 1px var(--btn-solid-bg);
}

.theme-choice {
  display: flex;
  flex: 1 1 16rem;
  align-items: center;
  gap: 1rem;
  min-width: 0;
  cursor: pointer;
}

.theme-choice input {
  flex: none;
  width: 1.25rem;
  height: 1.25rem;
  margin: 0;
  accent-color: var(--btn-solid-bg);
}

/* The Preview link keeps to the right edge, also when a narrow screen moves it to its own line. */
.theme-option > .m-btn {
  margin-left: auto;
}

.theme-swatch {
  flex: none;
  width: 5.5rem;
  height: 3.6rem;
  border-radius: 3px;
  box-shadow: 0 0 0 1px var(--m-line);
}

.theme-swatch[data-swatch='street'] {
  background: linear-gradient(#232427 0 16%, #f7f5f0 16% 52%, #cda57a 52% 68%, #e7e4dd 68%);
}

.theme-swatch[data-swatch='syllabus'] {
  background:
    linear-gradient(90deg, #ffe566 0 46%, transparent 46%) 12% 30% / 100% 12% no-repeat,
    linear-gradient(#fff 0 52%, #131416 52% 54%, #fff 54% 70%, #e4e4e1 70% 72%, #fff 72% 86%, #e4e4e1 86% 88%, #fff 88%);
}

.theme-swatch[data-swatch='fall'] {
  background:
    radial-gradient(circle at 22% 34%, #a4471f 0 0.62rem, transparent 0.66rem),
    linear-gradient(#f7efe2 0 62%, #efe3cf 62%);
}

.theme-text {
  min-width: 0;
}

.theme-name {
  display: block;
  font-weight: 600;
}

.theme-desc {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.4;
}

/* Popups */
.m-dialog {
  width: min(46rem, calc(100vw - 2rem));
  max-width: none;
  max-height: calc(100vh - 2rem);
  max-height: calc(100dvh - 2rem);
  overflow: hidden;
  border: 1px solid var(--m-line);
  border-radius: var(--box-radius);
  background: var(--panel);
  color: var(--ink);
  padding: 0;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.28);
}

.m-dialog[open] {
  display: flex;
  flex-direction: column;
}

.m-dialog::backdrop {
  background: rgba(10, 10, 10, 0.5);
}

.m-dialog-narrow {
  width: min(34rem, calc(100vw - 2rem));
}

.m-dialog-confirm {
  width: min(26rem, calc(100vw - 2rem));
}

.m-dialog-form {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  margin: 0;
}

.m-dialog-head {
  display: flex;
  flex: none;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--m-line);
  padding: 0.85rem 1rem 0.85rem 1.5rem;
}

.m-dialog-title {
  font-size: 1.2rem;
  line-height: 1.3;
}

.m-dialog-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 1.5rem;
}

.m-dialog-foot {
  display: flex;
  flex: none;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.6rem;
  border-top: 1px solid var(--m-line);
  padding: 0.9rem 1.5rem;
}

.m-dialog-foot .m-form-error {
  flex: 1 1 14rem;
}

.m-foot-start {
  margin-right: auto;
  margin-left: -0.75rem;
}

.m-confirm {
  display: grid;
  gap: 0.75rem;
  padding: 1.5rem;
}

.m-confirm-message {
  color: var(--ink-soft);
  line-height: 1.5;
}

.m-confirm .m-button-row {
  margin-top: 0.5rem;
}

/* The article preview is the story page's own markup, drawn by the story page's own styles. It
   sits on the page colour and its bands run edge to edge. Each theme file ends with the few sizes
   it changes for a box this narrow. */
.m-dialog-body.m-preview {
  --gutter: 1.5rem;
  background: var(--page);
  padding: 0;
}

.m-toasts {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  z-index: 30;
  display: grid;
  justify-items: center;
  gap: 0.5rem;
  width: max-content;
  max-width: calc(100vw - 2rem);
  pointer-events: none;
  transform: translateX(-50%);
}

.m-toast {
  border-radius: var(--field-radius);
  background: var(--ink);
  color: var(--page);
  padding: 0.65rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  line-height: 1.4;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
}

@media (max-width: 680px) {
  .m-grid-2 {
    grid-template-columns: minmax(0, 1fr);
  }

  .m-field-narrow {
    max-width: none;
  }

  .m-fact {
    grid-template-columns: minmax(0, 1fr) auto;
    border-bottom: 1px solid var(--m-line);
    padding-bottom: 0.9rem;
  }

  .m-fact .m-input {
    grid-column: 1;
  }

  .m-fact .m-icon-btn {
    grid-row: 1;
    grid-column: 2;
  }

  .m-tabs {
    gap: 1.25rem;
  }

  .m-row {
    flex-wrap: wrap;
  }

  .m-row-main {
    flex-basis: 100%;
  }

  .m-row-actions {
    margin: 0 0 -0.35rem -0.7rem;
  }

  .m-photo {
    flex-wrap: wrap;
  }

  .m-panel {
    padding: 1.1rem;
  }

  .m-savebar {
    margin: 0 -1.1rem -1.1rem;
    padding: 0.8rem 1.1rem;
  }

  /* Popups fill the phone screen, except the small confirmation one. */
  .m-dialog:not(.m-dialog-confirm) {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  .m-dialog-head {
    padding-left: 1.1rem;
  }

  .m-dialog-body {
    padding: 1.1rem;
  }

  .m-dialog-body.m-preview {
    --gutter: 1.1rem;
  }

  .m-dialog-foot {
    padding: 0.8rem 1.1rem max(0.8rem, env(safe-area-inset-bottom, 0px));
  }
}

/* While this tab is trying a theme out, a notice bar sits along the bottom of the window.
   theme.js measures it, and these two keep clear of it. */
.is-previewing .m-savebar {
  bottom: var(--preview-bar-height);
}

.is-previewing .m-toasts {
  bottom: calc(var(--preview-bar-height) + 1.25rem);
}

/* Windows high-contrast mode: colour alone marks these two as chosen, so they get a colour it keeps. */
@media (forced-colors: active) {
  .m-tabs button[aria-selected='true'],
  .theme-option:has(input:checked) {
    border-color: Highlight;
  }
}
