*,
::backdrop,
::file-selector-button,
:after,
:before {
  border: 0 solid;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font: inherit;
}

:root {
  /* Brand tokens — override per project */
  --color-primary: #059669;
  --color-on-primary: #fff;
  --color-secondary: #eee;
  --color-success: #16a34a;
  --color-danger: #dc2626;

  /* System tokens — keep consistent */
  --color-text: #000;
  --color-muted: #666;
  --color-muted-light: #ccc;
  --color-border: #ccc;
  --color-divider: #e5e5e5;
  --color-success-bg: #dcfce7;
  --color-success-text: #166534;
  --color-warning-bg: #fef9c3;
  --color-warning-text: #854d0e;
  --color-error-bg: #fee2e2;
  --color-error-text: #991b1b;
  --radius: 0.75rem;
  --radius-lg: 1rem;
}

html {
  font-family: sans-serif;
  line-height: 1.5;
  color: var(--color-text);
  accent-color: var(--color-primary);
}

body {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 2rem;
  padding: 1rem;
}

/* Fluid variant — full width, no centered max-width cap */
body.fluid {
  max-width: none;
}

a {
  color: inherit;
  text-decoration: none;
}

/* Restore semantic defaults wiped by the `font: inherit` reset */
b,
strong {
  font-weight: bold;
}
em,
i {
  font-style: italic;
}

/* Images/video: block kills the inline baseline gap; responsive + aspect-ratio kept.
   (Deliberately NOT svg — our inline <x-ico> icons must stay inline.) */
img,
video {
  display: block;
  max-width: 100%;
  height: auto;
  vertical-align: middle;
}

svg {
  flex-shrink: 0;
  vertical-align: middle;
}

.section-title a > svg {
  vertical-align: calc(0.5cap - 13px);
}

h1,
.h1 {
  font-size: 2.25rem;
  font-weight: bold;
  line-height: 1.1;
  text-wrap: balance;
  overflow-wrap: break-word;
}
h2,
.h2 {
  font-size: 1.5rem;
  font-weight: bold;
  line-height: 1.2;
  text-wrap: balance;
}
h3,
.h3 {
  font-size: 1.25rem;
  font-weight: bold;
  line-height: 1.3;
}
h4,
.h4 {
  font-size: 1rem;
  font-weight: bold;
}

main {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 1rem;

  &.top {
    align-items: flex-start;

    & > svg {
      margin-top: calc((1lh - 1em) / 2);
    }
  }
}

section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.article {
  display: flex;
  flex-direction: column;
  gap: 1rem;

  & ul,
  & ol {
    padding-left: 1.5rem;
  }
}

/* Header & Footer */

.header {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.site-name {
  font-size: 1.5rem;
  font-weight: 900;
  width: fit-content;

  /* Logo variant — when the site name is an <img> instead of text.
     Flex + block image removes the baseline/line-height gap that the
     1.5rem text line-box otherwise adds around an inline image. */
  &.logo {
    display: inline-flex;
    align-items: center;
    line-height: 0;

    & img {
      display: block;
      max-height: 40px;
      width: auto;
    }
  }
}

.footer {
  display: flex;
  flex-direction: column;
  gap: 1rem;

  &.text-center {
    align-items: center;
  }
}

.search-bar {
  display: flex;
  align-items: center;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: #fff;

  & input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    padding: 0.5rem 0 0.5rem 0.75rem;
    font: inherit;
    min-width: 0;
  }

  & .plain-button {
    padding: 0.5rem;
    flex-shrink: 0;
    color: var(--color-muted);
  }
}

.input-group {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;

  & input,
  & select,
  & .select {
    flex: 1;
    border: none;
    border-radius: 0;
    outline: none;
    background-color: transparent;
    padding: 0.5rem 0.75rem;
    font: inherit;
    min-width: 0;
  }

  & .plain-button {
    padding: 0.5rem;
    flex-shrink: 0;
  }

  & > * + input,
  & > * + select,
  & > * + .select,
  & > * + .plain-button {
    border-left: 1px solid var(--color-border);
  }

  & .input-addon {
    display: flex;
    align-items: center;
    padding: 0.5rem 0.75rem;
    white-space: nowrap;
  }

  & > * + .input-addon {
    border-left: 1px solid var(--color-border);
  }

  & .auto {
    flex: none;
    width: auto;
  }
}

/* Inputs */

.input {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;

  &:focus-visible {
    border-color: var(--color-primary);
    outline: none;
  }
}

.input-filled {
  background: var(--color-secondary);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;

  &:focus-visible {
    outline: none;
  }
}

.input-white {
  background: white;
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;

  &:focus-visible {
    outline: none;
  }
}

.textarea {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  resize: vertical;

  &:focus-visible {
    border-color: var(--color-primary);
    outline: none;
  }
}

.select {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.5rem 2.5rem 0.5rem 0.75rem;
  background: white
    url("data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 20 20' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M5.21983 8.22015C5.36045 8.0797 5.55108 8.00081 5.74983 8.00081C5.94858 8.00081 6.1392 8.0797 6.27983 8.22015L9.99983 11.9402L13.7198 8.22015C13.7885 8.14647 13.8713 8.08736 13.9633 8.04637C14.0553 8.00538 14.1546 7.98334 14.2553 7.98156C14.356 7.97979 14.456 7.99831 14.5494 8.03603C14.6428 8.07375 14.7276 8.1299 14.7989 8.20112C14.8701 8.27233 14.9262 8.35717 14.964 8.45056C15.0017 8.54394 15.0202 8.64397 15.0184 8.74468C15.0166 8.84538 14.9946 8.94469 14.9536 9.03669C14.9126 9.12869 14.8535 9.21149 14.7798 9.28015L10.5298 13.5302C10.3892 13.6706 10.1986 13.7495 9.99983 13.7495C9.80108 13.7495 9.61045 13.6706 9.46983 13.5302L5.21983 9.28015C5.07938 9.13953 5.00049 8.9489 5.00049 8.75015C5.00049 8.5514 5.07938 8.36078 5.21983 8.22015Z' fill='%23000'/%3E%3C/svg%3E")
    no-repeat right 0.75rem center;
  appearance: none;

  &:focus-visible {
    border-color: var(--color-primary);
    outline: none;
  }
}

/* Borderless select variants — mirror .input-filled / .input-white.
   Use .select-filled on white surfaces, .select-white on gray surfaces (cards, heroes). */
.select-filled {
  border: none;
  border-radius: var(--radius);
  padding: 0.5rem 2.5rem 0.5rem 0.75rem;
  background: var(--color-secondary)
    url("data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 20 20' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M5.21983 8.22015C5.36045 8.0797 5.55108 8.00081 5.74983 8.00081C5.94858 8.00081 6.1392 8.0797 6.27983 8.22015L9.99983 11.9402L13.7198 8.22015C13.7885 8.14647 13.8713 8.08736 13.9633 8.04637C14.0553 8.00538 14.1546 7.98334 14.2553 7.98156C14.356 7.97979 14.456 7.99831 14.5494 8.03603C14.6428 8.07375 14.7276 8.1299 14.7989 8.20112C14.8701 8.27233 14.9262 8.35717 14.964 8.45056C15.0017 8.54394 15.0202 8.64397 15.0184 8.74468C15.0166 8.84538 14.9946 8.94469 14.9536 9.03669C14.9126 9.12869 14.8535 9.21149 14.7798 9.28015L10.5298 13.5302C10.3892 13.6706 10.1986 13.7495 9.99983 13.7495C9.80108 13.7495 9.61045 13.6706 9.46983 13.5302L5.21983 9.28015C5.07938 9.13953 5.00049 8.9489 5.00049 8.75015C5.00049 8.5514 5.07938 8.36078 5.21983 8.22015Z' fill='%23000'/%3E%3C/svg%3E")
    no-repeat right 0.75rem center;
  appearance: none;

  &:focus-visible {
    outline: none;
  }
}

.select-white {
  border: none;
  border-radius: var(--radius);
  padding: 0.5rem 2.5rem 0.5rem 0.75rem;
  background: white
    url("data:image/svg+xml,%3Csvg width='20' height='20' viewBox='0 0 20 20' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill-rule='evenodd' clip-rule='evenodd' d='M5.21983 8.22015C5.36045 8.0797 5.55108 8.00081 5.74983 8.00081C5.94858 8.00081 6.1392 8.0797 6.27983 8.22015L9.99983 11.9402L13.7198 8.22015C13.7885 8.14647 13.8713 8.08736 13.9633 8.04637C14.0553 8.00538 14.1546 7.98334 14.2553 7.98156C14.356 7.97979 14.456 7.99831 14.5494 8.03603C14.6428 8.07375 14.7276 8.1299 14.7989 8.20112C14.8701 8.27233 14.9262 8.35717 14.964 8.45056C15.0017 8.54394 15.0202 8.64397 15.0184 8.74468C15.0166 8.84538 14.9946 8.94469 14.9536 9.03669C14.9126 9.12869 14.8535 9.21149 14.7798 9.28015L10.5298 13.5302C10.3892 13.6706 10.1986 13.7495 9.99983 13.7495C9.80108 13.7495 9.61045 13.6706 9.46983 13.5302L5.21983 9.28015C5.07938 9.13953 5.00049 8.9489 5.00049 8.75015C5.00049 8.5514 5.07938 8.36078 5.21983 8.22015Z' fill='%23000'/%3E%3C/svg%3E")
    no-repeat right 0.75rem center;
  appearance: none;

  &:focus-visible {
    outline: none;
  }
}

.color-input {
  width: 3rem;
  height: 2rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.25rem;
  cursor: pointer;
}

.range {
  cursor: pointer;
}

.file-input {
  cursor: pointer;

  &::file-selector-button {
    background: var(--color-secondary);
    color: var(--color-text);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    line-height: 1.5;
    margin-right: 0.75rem;
  }
}

/* Upload card — dropzone-style file input with instant client-side preview.
   Structure: .upload-card > input[hidden] + label.upload-card-trigger + .upload-card-preview.
   JS toggles trigger/preview visibility and fills the <img> via URL.createObjectURL(). */
.upload-card {
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;

  &.has-file {
    border-style: solid;
  }

  & input[type="file"] {
    display: none;
  }
}

.upload-card-trigger {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: 8rem;
  padding: 1.5rem;
  cursor: pointer;
  text-align: center;
  color: var(--color-text);

  &[hidden] {
    display: none;
  }

  &:hover {
    color: var(--color-primary);
  }

  & svg {
    width: 1.5rem;
    height: 1.5rem;
  }
}

.upload-card-preview {
  position: relative;

  & img {
    display: block;
    width: 100%;
    max-height: 12rem;
    object-fit: contain;
    background: var(--color-secondary);

    &[hidden] {
      display: none;
    }
  }

  & .upload-card-file {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;

    &[hidden] {
      display: none;
    }

    & svg {
      width: 1.5rem;
      height: 1.5rem;
      flex-shrink: 0;
      color: var(--color-muted);
    }
  }

  & .icon-button {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
  }
}

/* Upload card — multiple files variant. Files accumulate in a list above the (always-visible)
   trigger; each row has its own remove button. JS keeps a File[] array (native <input multiple>
   replaces on every pick) and rebuilds input.files via DataTransfer so the accumulated set — not
   just the latest pick — is what submits with the form. */
.upload-card-list {
  display: flex;
  flex-direction: column;

  &:empty {
    display: none;
  }
}

.upload-card-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border-bottom: 1px solid var(--color-border);

  & img {
    width: 3rem;
    height: 3rem;
    object-fit: cover;
    border-radius: var(--radius);
    flex-shrink: 0;
  }

  & .upload-card-item-icon {
    width: 3rem;
    height: 3rem;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-secondary);
    border-radius: var(--radius);

    & svg {
      width: 1.5rem;
      height: 1.5rem;
      color: var(--color-muted);
    }
  }

  & span {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* Forms */

.form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.fieldset {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.legend {
  font-weight: bold;
  padding: 0 0.5rem;
}

.radio-label,
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
}

/* Buttons */

.primary-button,
.secondary-button,
.outline-button,
.ghost-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.5rem;
  border-radius: var(--radius);
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  line-height: 1.5;
  text-decoration: none;

  &:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }
}

.primary-button {
  background: var(--color-primary);
  color: var(--color-on-primary);
}
.secondary-button {
  background: var(--color-secondary);
  color: var(--color-text);
}
.outline-button {
  background: transparent;
  color: var(--color-text);
  border: 1px solid var(--color-border);
}
.ghost-button {
  background: transparent;
  color: var(--color-text);
}
.danger-button {
  background: var(--color-danger);
  color: var(--color-on-primary);
}

.primary-button.full,
.secondary-button.full,
.outline-button.full,
.ghost-button.full,
.danger-button.full {
  width: 100%;
  justify-content: center;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;

  & svg {
    width: 1.5rem;
    height: 1.5rem;
  }

  & span { display: none; }

  @media (min-width: 640px) {
    &:has(span) {
      width: auto;
      padding-inline: 0.5rem 0.75rem;
      gap: 0.5rem;

      & span { display: inline; }
    }
  }

  &.primary {
    background: var(--color-primary);
    color: var(--color-on-primary);
  }
  &.secondary {
    background: var(--color-secondary);
    color: var(--color-text);
  }
  &.outline {
    background: transparent;
    color: var(--color-text);
    border: 1px solid var(--color-border);
  }
  &.ghost {
    background: transparent;
    color: var(--color-text);
  }
  &.success {
    background: var(--color-success);
    color: #fff;
  }

  &:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }
}

.plain-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--color-text);
  cursor: pointer;

  & svg {
    width: 1.5rem;
    height: 1.5rem;
  }

  &:disabled {
    opacity: 0.5;
    cursor: not-allowed;
  }
}

.button-group {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Navigation */

.nav {
  display: flex;
  column-gap: 1rem;
  row-gap: 0.5rem;
  flex-wrap: wrap;

  & a {
    color: inherit;
  }

  &.bold a {
    font-weight: bold;
  }

  &.center {
    justify-content: center;
  }

  &.chips {
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 0.5rem;

    & a {
      flex-shrink: 0;
      display: inline-flex;
      align-items: center;
      gap: 0.5rem;
      padding: 0.5rem 1rem;
      border-radius: var(--radius);
      border: 1px solid var(--color-border);
      white-space: nowrap;
    }
  }
}

.nav-vertical {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;

  & a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.5rem 0;
    color: inherit;
    text-decoration: none;

    & > div {
      display: flex;
      align-items: center;
      gap: 0.5rem;
    }
  }

  &.divided {
    gap: 0;

    & a + a {
      border-top: 1px solid var(--color-divider);
      padding-top: 0.5rem;
    }
  }

  &.separated {
    gap: 0.5rem;

    & a {
      padding: 0.5rem 1rem;
      background: var(--color-secondary);
      border-radius: var(--radius-lg);
    }
  }
}

.nav-vertical a svg {
  flex-shrink: 0;
  color: var(--color-muted-light);
}

.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--color-border);
  overflow-x: auto;

  /* Fit all tabs in one row -- no scroll; equal width, center, truncate with ellipsis */
  &.fit {
    overflow: hidden;

    & .tab {
      flex: 1;
      min-width: 0;
      text-align: center;
      overflow: hidden;
      text-overflow: ellipsis;
    }
  }

  /* Fit + wrap -- equal segments stay in one row, labels wrap to multiple lines */
  &.wrap {
    overflow: hidden;

    & .tab {
      flex: 1;
      min-width: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      text-align: center;
      white-space: normal;
      overflow-wrap: anywhere;
    }
  }

  /* iOS-style segmented control — pills in a rounded track.
     Wrapper radius is one step larger than the segment radius. */
  &.segmented {
    border-bottom: none;
    background: var(--color-secondary);
    border-radius: var(--radius-lg);
    padding: 0.25rem;
    gap: 0.25rem;

    & .tab {
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: center;
      text-align: center;
      padding: 0.5rem 0.75rem;
      border-bottom: none;
      border-radius: var(--radius);

      &.active {
        background: var(--color-on-primary);
        color: var(--color-text);
        border-bottom: none;
      }
    }

    /* fit: equal-width tabs with ellipsis truncation */
    &.fit {
      & .tab {
        display: block;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        line-height: 1.5;
      }
    }
  }

  /* Pills — each tab a rounded pill; active is a filled primary pill */
  &.pills {
    border-bottom: none;
    gap: 0.5rem;

    & .tab {
      border-bottom: none;
      border-radius: var(--radius);

      &.active {
        background: var(--color-secondary);
        color: var(--color-text);
        border-bottom: none;
      }
    }
  }

  /* Boxed — enclosed folder tabs; active tab merges with the panel below */
  &.boxed {
    gap: 0.25rem;

    & .tab {
      border: 1px solid transparent;
      border-bottom: none;
      border-radius: var(--radius) var(--radius) 0 0;
      margin-bottom: -1px;

      &.active {
        border-color: var(--color-border);
        background: var(--color-on-primary);
        color: var(--color-text);
      }
    }
  }

  /* Bottom nav — equal-width, icon stacked above label, centered */
  &.bottom-nav {
    border-bottom: none;

    & .tab {
      flex: 1;
      border-bottom: none;
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 0.25rem;
      text-align: center;
      font-size: 0.625rem;

      &.active {
        color: var(--color-primary);
        font-weight: normal;
      }
    }
  }

  /* Ghost — no underline; active is just bold + colour */
  &.ghost {
    border-bottom: none;

    & .tab {
      border-bottom: none;
    }
  }
}

.tab {
  white-space: nowrap;
  padding: 0.5rem 0.75rem;
  color: var(--color-muted);
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  cursor: pointer;

  & svg {
    width: 1.5rem;
    height: 1.5rem;
    vertical-align: middle;
  }

  &.active {
    color: var(--color-text);
    font-weight: bold;
    border-bottom-color: var(--color-primary);
  }
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;

  & a {
    color: var(--color-muted);
  }
}

.breadcrumb-separator {
  color: var(--color-border);
}

.chip-group {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.chip {
  color: var(--color-muted);
}

/* Cards */

.card {
  border-radius: var(--radius-lg);
  padding: 1rem;
  background: var(--color-secondary);
  display: flex;
  flex-direction: column;
  gap: 1rem;

  &.row {
    flex-direction: row;
    align-items: flex-start;
  }

  &.white {
    background: #fff;
  }

  &.ghost {
    background: transparent;
    padding: 0;
    border-radius: 0;
  }
}

.card-footer {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
}

/* Pagination */

.pagination {
  display: flex;
  align-items: center;
  gap: 0.5rem;

  &.center {
    justify-content: center;
  }
  &.end {
    align-self: flex-end;
  }
}

.pagination-item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.5rem;
  height: 2.5rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  text-decoration: none;
  color: inherit;
  cursor: pointer;

  &.active {
    background: var(--color-primary);
    color: white;
  }
}

.pagination-dots {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.5rem;
  height: 2.5rem;
  color: var(--color-muted);
}

.pagination-info {
  padding-inline: 0.25rem;
}

/* Disclosure */

.disclosure {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;

  & summary {
    cursor: pointer;
    font-weight: bold;
    list-style: none;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;

    &::marker,
    &::-webkit-details-marker {
      display: none;
    }

    & svg {
      flex-shrink: 0;
      margin-left: auto;
      transition: transform 0.2s ease;
    }
  }

  &[open] summary {
    margin-bottom: 1rem;

    & svg {
      transform: rotate(45deg);
    }
  }
}

/* Alerts */

.alert {
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;

  &.info {
    background: var(--color-secondary);
    color: var(--color-text);
  }
  &.success {
    background: var(--color-success-bg);
    color: var(--color-success-text);
  }
  &.warning {
    background: var(--color-warning-bg);
    color: var(--color-warning-text);
  }
  &.error {
    background: var(--color-error-bg);
    color: var(--color-error-text);
  }
}

/* Badges */

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.5rem;
  padding: 0.125rem 0.5rem;
  font-size: 0.75rem;
  font-weight: bold;

  &.primary {
    background: var(--color-primary);
    color: var(--color-on-primary);
  }
  &.secondary {
    background: var(--color-secondary);
    color: var(--color-primary);
  }
  &.success {
    background: var(--color-success-bg);
    color: var(--color-success-text);
  }
  &.warning {
    background: var(--color-warning-bg);
    color: var(--color-warning-text);
  }
  &.danger {
    background: var(--color-error-bg);
    color: var(--color-error-text);
  }
}

/* Tables */

.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;

  & th,
  & td {
    border-bottom: 1px solid var(--color-border);
    border-right: 1px solid var(--color-border);
    padding: 0.5rem;
    text-align: left;
  }

  & th:last-child,
  & td:last-child {
    border-right: none;
  }

  & tbody tr:last-child td,
  & tbody tr:last-child th {
    border-bottom: none;
  }

  & th {
    font-weight: bold;
  }

  & .text-right {
    text-align: right;
  }
  & .text-center {
    text-align: center;
  }
  & .align-top {
    vertical-align: top;
  }
  & .fit {
    width: 1%;
    white-space: nowrap;
  }
  & .thumb-col {
    width: 8rem;
  }
}

/* Divider */

.divider {
  border: none;
  border-top: 1px solid var(--color-border);
}

/* Lists */

.list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-left: 1.5rem;
}

.list-none {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  list-style: none;
}

/* Description list — label/value metadata (<dl>). Wrap each pair in a <div>.
   Variants: .vertical (label above value), .horizontal (side by side),
   .between (side by side, value pushed to the end). */
.description-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;

  &.vertical > div {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
  }

  &.horizontal > div {
    display: flex;
    gap: 1rem;

    & dt {
      flex: 1;
      min-width: 0;
    }
    & dd {
      flex: 1;
      min-width: 0;
    }
  }

  &.columns {
    display: grid;
    gap: 1rem;

    & > div {
      display: flex;
      flex-direction: column;
      gap: 0.25rem;
    }

    &.col-2  { grid-template-columns: repeat(2,  1fr); }
    &.col-3  { grid-template-columns: repeat(3,  1fr); }
    &.col-4  { grid-template-columns: repeat(4,  1fr); }
    &.col-5  { grid-template-columns: repeat(5,  1fr); }
    &.col-6  { grid-template-columns: repeat(6,  1fr); }
    &.col-7  { grid-template-columns: repeat(7,  1fr); }
    &.col-8  { grid-template-columns: repeat(8,  1fr); }
    &.col-9  { grid-template-columns: repeat(9,  1fr); }
    &.col-10 { grid-template-columns: repeat(10, 1fr); }
    &.col-11 { grid-template-columns: repeat(11, 1fr); }
    &.col-12 { grid-template-columns: repeat(12, 1fr); }
  }

  &.between > div {
    display: flex;
    gap: 1rem;

    & dt {
      flex: 1;
      min-width: 0;
    }
    & dd {
      flex: 1;
      min-width: 0;
      text-align: right;
    }
  }
}

/* Blockquote */

.blockquote {
  border-left: 3px solid var(--color-primary);
  padding: 0.5rem 1rem;
  color: var(--color-muted);
}

/* Code */

.code {
  font-family: monospace;
  font-size: 1rem;
  background: var(--color-secondary);
  border-radius: 0.25rem;
  padding: 0.125rem 0.375rem;
}

.code-block {
  font-family: monospace;
  font-size: 1rem;
  background: var(--color-secondary);
  border-radius: var(--radius);
  padding: 1rem;
  overflow-x: auto;
  white-space: pre;
}

/* Empty State */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 2rem;
  text-align: center;
}

/* Avatar */

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  width: 2.5rem;
  height: 2.5rem;
  font-size: 1rem;

  & img {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  &.avatar-xs {
    width: 1.5rem;
    height: 1.5rem;
    font-size: 0.625rem;
  }
  &.avatar-sm {
    width: 2rem;
    height: 2rem;
    font-size: 0.75rem;
  }
  &.avatar-lg {
    width: 3.5rem;
    height: 3.5rem;
    font-size: 1.25rem;
  }
  &.avatar-xl {
    width: 5rem;
    height: 5rem;
    font-size: 1.75rem;
  }
}

.avatar-placeholder {
  background: var(--color-text);
  color: var(--color-on-primary);
  font-weight: bold;
}

/* Square thumbnail — table/list previews (documents, attachments). Not circular like .avatar.
   Apply directly to <img> (uses object-fit) or to a <span> placeholder (uses flex centering). */
.thumb {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3rem;
  height: 3rem;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
  overflow: hidden;
  background: var(--color-secondary);
  object-fit: cover;
  font-size: 0.625rem;
  font-weight: bold;
}

/* Full-width table image preview — fills the column (capped), no crop (preserves aspect ratio). */
.table-thumb {
  display: block;
  width: 100%;
  max-width: 8rem;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
}

/* Dropdown */

.dropdown {
  position: relative;
  display: inline-flex;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 0.25rem);
  left: 0;
  z-index: 100;
  min-width: 12rem;
  display: none;
  flex-direction: column;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  overflow: hidden;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.15s ease, transform 0.15s ease, display 0.15s allow-discrete;

  &.open {
    display: flex;
    opacity: 1;
    transform: translateY(0);
  }
}

@starting-style {
  .dropdown-menu.open {
    opacity: 0;
    transform: translateY(-4px);
  }
}

.dropdown.right .dropdown-menu {
  left: auto;
  right: 0;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  color: var(--color-text);
  text-decoration: none;
  background: transparent;
  cursor: pointer;
  text-align: left;

  &:hover,
  &:focus,
  &.active {
    background: var(--color-secondary);
    outline: none;
  }

  &.active {
    font-weight: 700;
  }

  & svg {
    width: 1.5rem;
    height: 1.5rem;
    flex-shrink: 0;
  }
}

.dropdown-menu.divided .dropdown-item + .dropdown-item {
  border-top: 1px solid var(--color-divider);
}

.dropdown-divider {
  border: none;
  border-top: 1px solid var(--color-divider);
  margin: 0;
}

.dropdown-header {
  padding: 0.5rem 0.75rem;
  font-weight: 700;
  pointer-events: none;
}

/* Modal */

.modal {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 28rem;
  width: calc(100% - 2rem);

  &[open] {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin: auto;
  }

  &::backdrop {
    background: rgba(0, 0, 0, 0.5);
  }

  & .modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  & .modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
  }
}

/* Lightbox — full-screen image viewer. Native <dialog>: Escape closes automatically via showModal(), no JS needed. */
.lightbox {
  border: none;
  padding: 0;
  background: transparent;
  max-width: 100vw;
  max-height: 100vh;
  width: 100vw;
  height: 100vh;

  &[open] {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  &::backdrop {
    background: rgba(0, 0, 0, 0.9);
  }

  & img {
    display: block;
    max-width: 100vw;
    max-height: 100vh;
    width: auto;
    height: auto;
    object-fit: contain;
  }

  & .icon-button {
    position: fixed;
    top: 1rem;
    right: 1rem;
  }
}

/* Hero */

.hero {
  background: var(--color-primary);
  color: white;
  padding: 2rem;
  border-radius: var(--radius-lg);
  text-align: center;

  &.centered {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    background: white;
    color: var(--color-text);
  }
}

/* Utilities */

.text-muted {
  color: var(--color-muted);
}
.text-muted-light {
  color: var(--color-muted-light);
}
.text-small {
  font-size: 0.875rem;
}
.field-message {
  font-size: 0.75rem;
  color: var(--color-muted);

  &.danger {
    color: var(--color-danger);
  }
}
.text-center {
  text-align: center;
}
.text-right {
  text-align: right;
}
.text-success {
  color: var(--color-success);
}
.text-danger {
  color: var(--color-danger);
}
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.link {
  text-decoration: underline;
}
/* Row: horizontal flex. Default centered; compose alignment with modifiers.
   Cross-axis (vertical): .top .bottom — center is default.
   Main-axis (horizontal): .between .end .center. */
.row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;

  /* vertical -- align-items */
  &.top {
    align-items: flex-start;
  }
  &.middle {
    align-items: center;
  }
  &.bottom {
    align-items: flex-end;
  }

  /* horizontal -- justify-content */
  &.start {
    justify-content: flex-start;
  }
  &.center {
    justify-content: center;
  }
  &.end {
    justify-content: flex-end;
  }
  &.between {
    justify-content: space-between;
  }

  /* gap modifiers */
  &.none { gap: 0; }
  &.xs { gap: 0.25rem; }
  &.sm { gap: 0.5rem; }
  &.md { gap: 0.75rem; }

  &.nowrap { flex-wrap: nowrap; }
}
.col {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Grid */

.grid {
  display: grid;
  gap: 1rem;
}

@media (min-width: 48rem) {
  .grid.cols-2  { grid-template-columns: repeat(2,  1fr); }
  .grid.cols-3  { grid-template-columns: repeat(3,  1fr); }
  .grid.cols-4  { grid-template-columns: repeat(4,  1fr); }
  .grid.cols-5  { grid-template-columns: repeat(5,  1fr); }
  .grid.cols-6  { grid-template-columns: repeat(6,  1fr); }
  .grid.cols-7  { grid-template-columns: repeat(7,  1fr); }
  .grid.cols-8  { grid-template-columns: repeat(8,  1fr); }
  .grid.cols-9  { grid-template-columns: repeat(9,  1fr); }
  .grid.cols-10 { grid-template-columns: repeat(10, 1fr); }
  .grid.cols-11 { grid-template-columns: repeat(11, 1fr); }
  .grid.cols-12 { grid-template-columns: repeat(12, 1fr); }
}

@media (max-width: 48rem) {
  .grid.sm-cols-1 { grid-template-columns: 1fr; }
  .grid.sm-cols-2 { grid-template-columns: repeat(2, 1fr); }
  .grid.sm-cols-3 { grid-template-columns: repeat(3, 1fr); }
  .grid.sm-cols-4 { grid-template-columns: repeat(4, 1fr); }
}

.gap-0 { gap: 0; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }
.gap-5 { gap: 1.5rem; }
.gap-6 { gap: 2rem; }
.col-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  text-align: center;
}
.grow {
  flex: 1;
  min-width: 0;
}
.auto-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
}

/* Centered narrow containers — auth forms, single-column content */
.container-sm {
  max-width: 24rem;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.container-md {
  max-width: 32rem;
  width: 100%;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Two-column form grid — admin panels, settings forms */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;

  & .full {
    grid-column: 1 / -1;
  }
}
