/* The account and admin pages (src/content/account/, src/content/admin/).
   Their forms reuse application-form.css (.af, .ff, .af-section, .af-error);
   this adds what those pages have beyond a form: the admin bar, tables,
   status labels, dialogs and file diffs. The dialogs also carry .af-wrap,
   for the form field styles it scopes. */

.app-narrow {
  max-width: 32rem;
}

/* Admin pages are tables more than text: give them the full content width
   rather than page.njk's reading column. */
.prose:has(> #admin-bar) {
  max-width: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.app-notice {
  background: var(--color-surface-alt);
  border-left: 4px solid var(--color-navy);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  margin: 0 0 var(--space-3);
}

.app-notice--error {
  border-left-color: #b42318;
  background: #fef3f2;
}

.app-notice--ok {
  border-left-color: #067647;
  background: #ecfdf3;
}

.app-notice > :last-child {
  margin-bottom: 0;
}

.app-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}

/* The site's .btn sets display, which would otherwise beat [hidden]. */
.app-actions [hidden] {
  display: none;
}

.link-button {
  background: none;
  border: 0;
  padding: 0;
  color: inherit;
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

/* ---------- Admin bar: who's signed in, and the admin pages' navigation */

.app-bar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--color-border);
  padding-bottom: var(--space-2);
  margin-bottom: var(--space-4);
  font-size: var(--step--1);
}

.app-bar nav {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
}

.app-bar nav a[aria-current="page"] {
  font-weight: 700;
  text-decoration: none;
}

/* ---------- Tables */

.app-table-wrap {
  overflow-x: auto;
  margin: 0 0 var(--space-4);
}

.app-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--step--1);
}

.app-table th,
.app-table td {
  text-align: left;
  vertical-align: top;
  padding: 0.5rem 0.6rem;
  border-bottom: 1px solid var(--color-border);
}

.app-table th {
  color: var(--color-ink-soft);
  font-weight: 600;
  white-space: nowrap;
}

.app-table tbody tr:hover {
  background: var(--color-surface);
}

.app-table .app-muted,
.app-muted {
  color: var(--color-ink-soft);
}

.app-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  margin-bottom: var(--space-3);
}

.app-toolbar input,
.app-toolbar select {
  font: inherit;
  font-size: var(--step--1);
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.app-toolbar input[type="search"] {
  flex: 1 1 14rem;
}

/* ---------- Status labels */

.pill {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  margin: 0 0.25rem 0.25rem 0;
  border-radius: 999px;
  background: var(--color-surface-alt);
  color: var(--color-ink);
  font-size: 0.8em;
  white-space: nowrap;
}

.pill--ok {
  background: #ecfdf3;
  color: #067647;
}

.pill--warn {
  background: #fffaeb;
  color: #93370d;
}

.pill--bad {
  background: #fef3f2;
  color: #b42318;
}

/* ---------- Dialogs */

.app-dialog {
  width: min(40rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  border: 0;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: var(--space-4);
}

.app-dialog::backdrop {
  background: rgba(0, 20, 50, 0.45);
}

.app-dialog h2 {
  margin-top: 0;
}

.app-roles {
  display: grid;
  gap: var(--space-2);
  margin: 0 0 var(--space-3);
}

.app-role {
  display: grid;
  grid-template-columns: minmax(8rem, 1fr) 2fr;
  gap: var(--space-2);
  align-items: start;
  padding: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.app-role-extra {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  font-size: var(--step--1);
}

.app-role-extra label {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.app-role-extra input {
  font: inherit;
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.app-dialog textarea {
  width: 100%;
  min-height: 10rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: var(--step--1);
}

/* ---------- Publishing */

.app-status {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.35rem var(--space-3);
  margin: 0 0 var(--space-4);
}

.app-status dt {
  font-weight: 600;
}

.app-status dd {
  margin: 0;
}

.app-status + .app-actions {
  margin-bottom: var(--space-5);
}

.diff {
  margin: var(--space-2) 0 var(--space-3);
  padding: var(--space-2);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  line-height: 1.45;
  overflow-x: auto;
  white-space: pre;
}

.diff-add {
  background: #e6ffec;
}

.diff-del {
  background: #ffebe9;
}

.diff-hunk {
  color: var(--color-navy);
}

.app-log {
  max-height: 20rem;
  overflow: auto;
}

/* ---------- Page and tile editors (admin/pages/, js/md-editor.js) */

.app-settings {
  margin: 0 0 var(--space-4);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.app-settings summary {
  cursor: pointer;
  font-weight: 600;
  margin-bottom: var(--space-2);
}

.app-picture {
  margin: var(--space-3) 0;
}

.app-link-row.grid {
  grid-template-columns: 1fr 1.4fr auto;
  align-items: start;
}

.app-tile-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-2);
}

.app-tile-head h3 {
  margin: 0;
}

/* Markdown box with its toolbar, and the live preview beside it on wide screens */
.md-editor {
  display: grid;
  gap: var(--space-3);
}

@media (min-width: 1100px) {
  .md-editor {
    grid-template-columns: 1fr 1fr;
  }
}

.md-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding: 0.3rem;
  border: 1px solid var(--color-border);
  border-bottom: 0;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: var(--color-surface);
}

.md-toolbar button {
  font: inherit;
  font-size: var(--step--1);
  padding: 0.2rem 0.55rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-white);
  cursor: pointer;
}

.md-toolbar button:hover,
.md-toolbar button:focus-visible {
  border-color: var(--color-navy);
}

.md-box {
  display: block;
  width: 100%;
  min-height: 12rem;
  padding: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  line-height: 1.5;
  resize: vertical;
}

.md-edit .md-box {
  height: 70vh;
}

.md-preview {
  width: 100%;
  height: calc(70vh + 2.2rem);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-white);
}

/* Template tags in the preview (they can't be rendered in the browser) */
.md-chip {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border: 1px dashed var(--color-navy);
  border-radius: var(--radius-sm);
  background: var(--color-surface-alt);
  color: var(--color-navy);
  font-size: 0.85em;
  font-weight: 600;
}

.md-chip--button {
  border-style: solid;
}

.md-chip--code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 400;
}

/* Save button and what happened, kept in view at the bottom of the screen */
.app-savebar {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
  margin-top: var(--space-3);
  padding: var(--space-2) 0;
  background: var(--color-white);
  border-top: 1px solid var(--color-border);
}

.app-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.2rem;
  margin: 0 0 var(--space-3);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}

.app-categories legend {
  padding: 0 0.3rem;
  font-weight: 600;
  font-size: var(--step--1);
}

.app-categories label {
  display: flex;
  gap: 0.4rem;
  align-items: center;
}
