/*
 * Reusable interface components.
 */

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

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 36px;
  padding: var(--space-2) var(--space-4);
  border: var(--border-width) solid transparent;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--duration-fast) var(--easing),
    border-color var(--duration-fast) var(--easing),
    color var(--duration-fast) var(--easing);
}

.button--primary {
  background: var(--accent);
  color: var(--text-on-accent);
}

.button--primary:hover:not(:disabled) {
  background: var(--accent-hover);
  color: var(--text-on-accent);
}

.button--secondary {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--text-primary);
}

.button--secondary:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.button--quiet {
  color: var(--text-secondary);
  padding-inline: var(--space-2);
}

.button--quiet:hover:not(:disabled) {
  background: var(--surface-sunken);
  color: var(--text-primary);
}

.button:disabled {
  opacity: 0.55;
}

.button--block {
  width: 100%;
}

/* ------------------------------------------------------------- icon button */

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  border: var(--border-width) solid transparent;
  transition: background var(--duration-fast) var(--easing),
    color var(--duration-fast) var(--easing);
}

.icon-button:hover {
  background: var(--surface-sunken);
  color: var(--text-primary);
}

.icon-button svg {
  width: 17px;
  height: 17px;
  stroke: currentcolor;
  fill: none;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* --------------------------------------------------------------- surfaces */

.card {
  background: var(--surface);
  border: var(--border-width) solid var(--line);
  border-radius: var(--radius-md);
}

.card--padded {
  padding: var(--space-5);
}

.panel {
  border: var(--border-width) solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  overflow: hidden;
}

.panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: var(--border-width) solid var(--line);
  background: var(--surface-sunken);
}

.panel__title {
  font-family: var(--font-interface);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.02em;
}

/* ---------------------------------------------------------------- badges */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  border-radius: var(--radius-xs);
  border: var(--border-width) solid var(--line);
  background: var(--surface-sunken);
  color: var(--text-secondary);
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge--accent {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
}

.badge--positive {
  background: var(--positive-soft);
  border-color: color-mix(in oklab, var(--positive) 35%, transparent);
  color: var(--positive);
}

.badge--caution {
  background: var(--caution-soft);
  border-color: color-mix(in oklab, var(--caution) 35%, transparent);
  color: var(--caution);
}

.badge--critical {
  background: var(--critical-soft);
  border-color: color-mix(in oklab, var(--critical) 35%, transparent);
  color: var(--critical);
}

.badge--info {
  background: var(--info-soft);
  border-color: color-mix(in oklab, var(--info) 35%, transparent);
  color: var(--info);
}

.badge--lock::before {
  content: "";
  width: 9px;
  height: 9px;
  border: 1.4px solid currentcolor;
  border-radius: 1px;
  border-bottom-width: 4px;
  box-sizing: border-box;
}

/* --------------------------------------------------------------- avatars */

/*
 * Avatars are generated locally from the member's initials and a stored hue
 * bucket. No image is uploaded, fetched or hosted, so there is no upload
 * surface, no remote request and no image-processing attack surface.
 */
.avatar {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.02em;
  user-select: none;
  border: var(--border-width) solid color-mix(in oklab, currentcolor 22%, transparent);
}

.avatar--sm { width: 24px; height: 24px; font-size: var(--text-2xs); }
.avatar--lg { width: 48px; height: 48px; font-size: var(--text-md); }

.avatar--h0  { background: #e7edf9; color: #2c4c86; }
.avatar--h1  { background: #e6f0f4; color: #245c6e; }
.avatar--h2  { background: #e4f1ec; color: #1f6350; }
.avatar--h3  { background: #e9f1e4; color: #3f6326; }
.avatar--h4  { background: #f2f0e0; color: #6a6021; }
.avatar--h5  { background: #f7ece0; color: #7d5220; }
.avatar--h6  { background: #f9e9e6; color: #8a3f31; }
.avatar--h7  { background: #f8e7ef; color: #86325c; }
.avatar--h8  { background: #f2e8f7; color: #63357e; }
.avatar--h9  { background: #eae9f8; color: #443a8a; }
.avatar--h10 { background: #e5ecf7; color: #2f4a7d; }
.avatar--h11 { background: #eceff1; color: #40474d; }

:root[data-theme="dark"] .avatar,
:root:not([data-theme="light"]) .avatar {
  border-color: color-mix(in oklab, currentcolor 30%, transparent);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .avatar--h0  { background: #1b2436; color: #9dbdf0; }
  :root:not([data-theme="light"]) .avatar--h1  { background: #16272e; color: #8ccbdd; }
  :root:not([data-theme="light"]) .avatar--h2  { background: #152a24; color: #85d3ba; }
  :root:not([data-theme="light"]) .avatar--h3  { background: #1c2a16; color: #a8cf8c; }
  :root:not([data-theme="light"]) .avatar--h4  { background: #2a2814; color: #d8cc82; }
  :root:not([data-theme="light"]) .avatar--h5  { background: #2e2114; color: #e0b389; }
  :root:not([data-theme="light"]) .avatar--h6  { background: #2f1d18; color: #eda595; }
  :root:not([data-theme="light"]) .avatar--h7  { background: #2d1a24; color: #e9a0c2; }
  :root:not([data-theme="light"]) .avatar--h8  { background: #271a2f; color: #cfa5e6; }
  :root:not([data-theme="light"]) .avatar--h9  { background: #1f1d34; color: #ada6f0; }
  :root:not([data-theme="light"]) .avatar--h10 { background: #1a2233; color: #a2bbe8; }
  :root:not([data-theme="light"]) .avatar--h11 { background: #212326; color: #b6bec5; }
}

:root[data-theme="dark"] .avatar--h0  { background: #1b2436; color: #9dbdf0; }
:root[data-theme="dark"] .avatar--h1  { background: #16272e; color: #8ccbdd; }
:root[data-theme="dark"] .avatar--h2  { background: #152a24; color: #85d3ba; }
:root[data-theme="dark"] .avatar--h3  { background: #1c2a16; color: #a8cf8c; }
:root[data-theme="dark"] .avatar--h4  { background: #2a2814; color: #d8cc82; }
:root[data-theme="dark"] .avatar--h5  { background: #2e2114; color: #e0b389; }
:root[data-theme="dark"] .avatar--h6  { background: #2f1d18; color: #eda595; }
:root[data-theme="dark"] .avatar--h7  { background: #2d1a24; color: #e9a0c2; }
:root[data-theme="dark"] .avatar--h8  { background: #271a2f; color: #cfa5e6; }
:root[data-theme="dark"] .avatar--h9  { background: #1f1d34; color: #ada6f0; }
:root[data-theme="dark"] .avatar--h10 { background: #1a2233; color: #a2bbe8; }
:root[data-theme="dark"] .avatar--h11 { background: #212326; color: #b6bec5; }

/* ----------------------------------------------------------------- forms */

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.field__label {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

.field__hint {
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.field__error {
  font-size: var(--text-xs);
  color: var(--critical);
}

.input,
.select,
.textarea {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  min-height: 36px;
  border: var(--border-width) solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-primary);
  font-size: var(--text-base);
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-muted);
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--accent-border);
}

.input[aria-invalid="true"],
.textarea[aria-invalid="true"] {
  border-color: var(--critical);
}

.textarea {
  min-height: 140px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
}

/* --------------------------------------------------------------- toolbar */

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

.segmented {
  display: inline-flex;
  padding: 2px;
  gap: 2px;
  border: var(--border-width) solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
}

.segmented__option {
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-xs);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
}

.segmented__option[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

/* ------------------------------------------------------------- messages */

.notice {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-4);
  border: var(--border-width) solid var(--line);
  border-left: 3px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.notice--info { border-left-color: var(--info); background: var(--info-soft); }
.notice--caution { border-left-color: var(--caution); background: var(--caution-soft); }
.notice--critical { border-left-color: var(--critical); background: var(--critical-soft); }
.notice--positive { border-left-color: var(--positive); background: var(--positive-soft); }

.notice__title {
  display: block;
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-12) var(--space-6);
  text-align: center;
  border: var(--border-width) dashed var(--line-strong);
  border-radius: var(--radius-md);
  color: var(--text-muted);
}

.empty-state__title {
  font-family: var(--font-reading);
  font-size: var(--text-lg);
  color: var(--text-primary);
}

.empty-state__body {
  max-width: 46ch;
  font-size: var(--text-sm);
}

/* -------------------------------------------------------------- skeleton */

.skeleton-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.skeleton {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: var(--surface-sunken);
}

.skeleton--row { height: 88px; }
.skeleton--line { height: 12px; }
.skeleton--title { height: 20px; width: 60%; }

@media (prefers-reduced-motion: no-preference) {
  .skeleton::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(
      90deg,
      transparent,
      color-mix(in oklab, var(--surface) 70%, transparent),
      transparent
    );
    animation: skeleton-sweep 1.4s var(--easing) infinite;
  }
}

@keyframes skeleton-sweep {
  to {
    transform: translateX(100%);
  }
}

/* ----------------------------------------------------------------- toast */

.toast-region {
  position: fixed;
  z-index: var(--z-toast);
  right: var(--space-4);
  bottom: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(360px, calc(100vw - (2 * var(--space-4))));
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: var(--border-width) solid var(--line-strong);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
}

.toast--critical { border-color: var(--critical); }
.toast--positive { border-color: var(--positive); }

.toast__body { flex: 1; }

/* ------------------------------------------------------------ pagination */

.pagination {
  display: flex;
  justify-content: center;
  gap: var(--space-3);
  margin-top: var(--space-6);
}

/* ------------------------------------------------------------- meta list */

.meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  color: var(--text-muted);
}

.meta-row__dot::before {
  content: "·";
  margin-right: var(--space-3);
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.tag-chip {
  display: inline-block;
  padding: 2px var(--space-2);
  border-radius: var(--radius-xs);
  border: var(--border-width) solid var(--line);
  background: var(--surface-sunken);
  color: var(--text-secondary);
  font-size: var(--text-2xs);
  text-decoration: none;
}

.tag-chip:hover {
  border-color: var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent);
}

/* ------------------------------------------------------------ form layout */

.form {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  max-width: 34rem;
}

.form__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
}

.form__aside {
  font-size: var(--text-sm);
  margin-top: calc(var(--space-2) * -1);
}

.form__footnote {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.form-notice {
  margin: 0;
}

/* The invalid state is carried by colour and by the message itself, never by
   colour alone, so it survives a monochrome display and colour blindness. */
.field--invalid .field__label {
  color: var(--critical);
}

.field__error:empty {
  display: none;
}

/* Prose fields are ordinary writing, not code, so they do not inherit the
   monospaced treatment the post composer uses. */
.textarea--prose {
  font-family: var(--font-reading);
  font-size: var(--text-base);
  min-height: 7rem;
}

/* ------------------------------------------------------------- composer */

/* The thread composer is a writing surface, not a settings dialog, so it is
   given the full column instead of the narrow form measure. */
.form--wide {
  max-width: 48rem;
}

/* A fieldset carrying a grid of choices. The reset is needed because the
   browser's default fieldset border and padding fight the field rhythm. */
.tag-option-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.tag-option {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  cursor: pointer;
}

.tag-option:has(:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

/* A tag that would exceed the cap is disabled rather than hidden, so the list
   does not reflow under the reader's cursor. */
.tag-option:has(:disabled) {
  opacity: 0.5;
  cursor: not-allowed;
}

.tag-option:focus-within {
  box-shadow: var(--focus-ring);
}

/* The reply composer sits inside the post tree and is indented with it, so it
   is visibly attached to the post it answers. */
.reply-composer {
  margin: var(--space-4) 0;
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
}

.reply-composer .form {
  max-width: none;
  gap: var(--space-3);
}

.reply-composer__label {
  margin: 0 0 var(--space-2);
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

/* A ladder of levels to choose from at registration. One option per row,
   because each carries a sentence and a narrow grid would break it badly. */
.level-picker {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
}

.level-option-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.level-option {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.level-option:has(:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.level-option:focus-within {
  box-shadow: var(--focus-ring);
}

.level-option__control {
  flex: none;
  margin-top: 0.2em;
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
}

.level-option__text {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.level-option__name {
  font-weight: var(--weight-semibold);
}

.level-option__summary {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

/* -------------------------------------------------------------- checkbox */

.checkbox {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
}

.checkbox__control {
  flex: none;
  /* Aligned to the first line of the label rather than the top of the block,
     which is where the eye expects it when the label wraps. */
  margin-top: 0.15em;
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
}

.checkbox__text {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.checkbox__label {
  font-size: var(--text-base);
}

/* ------------------------------------------------------------------ tabs */

/* Segmented, not tabbed.
 *
 * These were underlined tabs sitting on a horizontal rule: the row carried a
 * bottom border, each link carried a transparent one, and the selected link
 * coloured its own in and pulled itself a pixel down to overlap the row's. It
 * worked, and it was three rules and a negative margin conspiring to draw a
 * line — an idiom inherited from interfaces that had to look like folder tabs.
 *
 * A segmented row of chips says the same thing with one property, matches the
 * navigation above it, and does not break when a tab label wraps to a second
 * line, which the overlapping borders did.
 */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin: var(--space-6) 0 var(--space-6);
}

.tabs__link {
  padding: var(--space-2) var(--space-3);
  border: var(--border-width) solid transparent;
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-secondary);
  text-decoration: none;
  transition: background var(--duration-fast) var(--easing),
    color var(--duration-fast) var(--easing);
}

.tabs__link:hover {
  background: var(--surface-sunken);
  color: var(--text-primary);
}

.tabs__link[aria-current="page"] {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent-border);
}

/* --------------------------------------------------------- account chip */

.account-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--text-primary);
  text-decoration: none;
}

.account-chip:hover {
  background: var(--surface-sunken);
}

.account-chip__name {
  max-width: 12ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 47.99rem) {
  /* On a narrow header the avatar carries the identity on its own; the name
     would push the sign-out control off the row. */
  .account-chip__name {
    display: none;
  }
}
