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

:root {
  --color-primary: #000;
  --color-on-primary: #fff;
  --color-secondary: #eee;
  --color-muted: #666;
  --color-border: #ccc;
  --color-danger: #dc2626;
  --color-success: #16a34a;
  --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;
  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;
}

h1,
.h1 {
  font-size: 2.25rem;
  font-weight: bold;
  line-height: 1.1;
  text-wrap: balance;
}
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 {
  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;
    }
  }
}

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

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

  & .input,
  & .input-filled,
  & .input-white {
    flex: 1;
  }
}

/* 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 2rem 0.5rem 0.75rem;
  background: white
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%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 2rem 0.5rem 0.75rem;
  background: var(--color-secondary)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%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 2rem 0.5rem 0.75rem;
  background: white
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%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-primary);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    line-height: 1.5;
    margin-right: 0.75rem;
  }
}

/* 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-primary);
}
.outline-button {
  background: transparent;
  color: var(--color-primary);
  border: 1px solid var(--color-border);
}
.ghost-button {
  background: transparent;
  color: var(--color-primary);
}
.danger-button {
  background: var(--color-danger);
  color: var(--color-on-primary);
}

.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;
  }

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

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

.plain-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--color-primary);
  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: var(--color-primary);
  }

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

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

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

.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-primary);
        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-primary);
        color: var(--color-on-primary);
        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-primary);
      }
    }
  }

  /* 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: 2px solid transparent;
  cursor: pointer;

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

  &.active {
    color: var(--color-primary);
    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;
}

.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: var(--color-primary);
  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;

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

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

/* Alerts */

.alert {
  border-radius: var(--radius);
  padding: 0.75rem 1rem;

  &.info {
    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);
  }
  &.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 {
    border-bottom: none;
  }

  & th {
    font-weight: bold;
  }

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

/* 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;
    }
  }

  &.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-primary);
  color: var(--color-on-primary);
  font-weight: bold;
}

/* 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;
  }
}

/* Hero */

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

/* Utilities */

.text-muted {
  color: var(--color-muted);
}
.text-small {
  font-size: 0.875rem;
}
.text-center {
  text-align: center;
}
.text-right {
  text-align: right;
}
.text-success {
  color: var(--color-success);
}
.text-danger {
  color: var(--color-danger);
}
.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;
  }
}
.col {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.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;
}

.container-md {
  max-width: 32rem;
  width: 100%;
  margin: 0 auto;
}

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

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