@layer theme {
  :root {
    --color-primary: hsl(214, 56%, 40%);
    --primary-wash: color-mix(in srgb, var(--color-primary) 10%, white);
    --text: #111827;
    --text-muted: #4b5563;
    --text-faint: #6b7280;
    --border: #e5e7eb;
    --border-strong: #d1d5db;
    --surface: #ffffff;
    --surface-muted: #f3f4f6;
    --page-background: #f8f9fb;
    --danger: hsl(4, 65%, 48%);

    /* translation states, the colours of the old app's labels */
    --state-green: hsl(145, 50%, 38%);
    --state-olive: hsl(66, 50%, 38%);
    --state-orange: hsl(28, 85%, 50%);
    --state-red: hsl(4, 70%, 52%);
  }

  body {
    background: var(--page-background);
    color: var(--text);
  }
}

@layer components {
  /* ---- Page frame ------------------------------------------------------- */

  .page {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 1.25rem;
  }

  .page--narrow {
    max-width: 56rem;
  }

  .page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
  }

  .page-header h1 {
    margin: 0;
    font-size: 1.75rem;
    line-height: 1.2;
  }

  .page-kicker {
    margin-bottom: 0.25rem;
    color: var(--text-faint);
    font-size: 0.9rem;
    font-weight: 600;
  }

  .page-kicker a {
    color: inherit;
  }

  .panel {
    display: grid;
    gap: 0.9rem;
    padding: 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
  }

  .panel[hidden] {
    display: none;
  }

  .panel--quiet {
    background: transparent;
  }

  .panel__title {
    margin: 0;
    font-size: 1.05rem;
  }

  .stacked-form {
    display: grid;
    gap: 1.25rem;
  }

  .field-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
    gap: 0 1rem;
  }

  .kinds {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.5rem;
    margin: 0;
    padding: 0;
    border: 0;
  }

  .kinds legend {
    width: 100%;
    margin-bottom: 0.4rem;
    padding: 0;
  }

  .input-narrow {
    max-width: 8rem;
  }

  .mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  }

  .muted {
    color: var(--text-faint);
  }

  .form-actions,
  .button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
  }

  .btn {
    gap: 0.4rem;
    text-decoration: none;
  }

  .btn:hover {
    text-decoration: none;
  }

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

  .btn-danger-outline {
    color: var(--danger);
    background: transparent;
    border-color: color-mix(in srgb, var(--danger) 45%, white);
  }

  .btn-danger-outline:hover {
    background: color-mix(in srgb, var(--danger) 8%, white);
  }

  .icon-button {
    display: inline-grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    color: var(--text-faint);
    border-radius: 50%;
    --icon-size: 1.15rem;
  }

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

  .icon-button--danger:hover {
    color: var(--danger);
    background: color-mix(in srgb, var(--danger) 10%, white);
  }

  .empty-state {
    margin: 0;
    padding: 2rem 1rem;
    color: var(--text-faint);
    text-align: center;
  }

  .plain-list {
    margin: 0;
    padding-left: 1.2rem;
  }

  /* ---- Text list ---------------------------------------------------------- */

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

  .list-toolbar form {
    flex: 1 1 16rem;
    max-width: 24rem;
  }

  .segmented {
    display: inline-flex;
    max-width: 100%;
    overflow-x: auto;
    padding: 0.2rem;
    background: var(--surface-muted);
    border-radius: 999px;
  }

  .segmented__item {
    padding: 0.35rem 0.9rem;
    color: var(--text-muted);
    font-size: 0.95rem;
    font-weight: 600;
    text-decoration: none;
    border-radius: 999px;
    white-space: nowrap;
  }

  .segmented__item:hover {
    color: var(--text);
    text-decoration: none;
  }

  .segmented__item.is-active {
    color: var(--text);
    background: var(--surface);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12);
  }

  .status-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 1.1rem;
    color: var(--text-faint);
    font-size: 0.85rem;
  }

  .status-legend__item {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
  }

  .status-legend .lang-chip {
    min-width: 0.85rem;
    height: 0.85rem;
    padding: 0;
  }

  .table-wrap {
    overflow-x: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
  }

  .data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
  }

  .data-table th {
    padding: 0.65rem 0.75rem;
    color: var(--text-faint);
    font-size: 0.8rem;
    font-weight: 700;
    text-align: left;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
    background: var(--surface-muted);
    border-bottom: 1px solid var(--border);
  }

  .data-table td {
    padding: 0.55rem 0.75rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--border);
  }

  .data-table tbody tr:last-child td {
    border-bottom: 0;
  }

  .data-table tbody tr:hover {
    background: color-mix(in srgb, var(--color-primary) 4%, white);
  }

  .data-table tbody tr:target {
    background: var(--primary-wash);
  }

  .data-table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
  }

  .nowrap {
    white-space: nowrap;
  }

  .texts-table__title a {
    color: var(--text);
    font-weight: 600;
  }

  .row-actions {
    width: 1%;
    text-align: right;
  }

  .row-actions form {
    display: inline;
  }

  .kind-badge {
    display: inline-block;
    margin: 0.1rem 0.2rem 0.1rem 0;
    padding: 0.1rem 0.5rem;
    font-size: 0.78rem;
    font-weight: 700;
    border-radius: 999px;
  }

  .kind-badge--book { color: hsl(214, 60%, 32%); background: hsl(214, 70%, 93%); }
  .kind-badge--lecture { color: hsl(180, 55%, 24%); background: hsl(180, 45%, 90%); }
  .kind-badge--article { color: hsl(30, 45%, 30%); background: hsl(30, 50%, 91%); }
  .kind-badge--compilation { color: hsl(268, 45%, 36%); background: hsl(268, 60%, 94%); }

  .lang-chips {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.3rem;
  }

  .data-table .lang-chips {
    flex-wrap: nowrap;
  }

  .lang-chip {
    display: inline-grid;
    place-items: center;
    min-width: 2.2rem;
    height: 1.7rem;
    padding: 0 0.4rem;
    font-size: 0.8rem;
    font-weight: 700;
    text-decoration: none;
    text-transform: uppercase;
    border: 1.5px solid transparent;
    border-radius: 999px;
  }

  .lang-chip:hover {
    text-decoration: none;
    filter: brightness(0.94);
  }

  .lang-chip--green { color: #fff; background: var(--state-green); }
  .lang-chip--olive { color: #fff; background: var(--state-olive); }
  .lang-chip--orange { color: #fff; background: var(--state-orange); }
  .lang-chip--red { color: var(--state-red); background: #fff; border-color: var(--state-red); }
  .lang-chip--white { color: var(--text-muted); background: #fff; border-color: var(--border-strong); }

  /* ---- Contained texts of a compilation ------------------------------- */

  .sortable-list {
    display: grid;
    gap: 0.35rem;
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .sortable-list__item {
    display: grid;
    grid-template-columns: auto auto 1fr auto;
    align-items: center;
    gap: 0.75rem;
    padding: 0.35rem 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
  }

  .sortable-list__item.is-dragging {
    opacity: 0.5;
    border-style: dashed;
  }

  .sortable-list__handle {
    display: inline-grid;
    color: var(--text-faint);
    cursor: grab;
    --icon-size: 1.2rem;
  }

  .sortable-list__date {
    color: var(--text-faint);
    font-size: 0.9rem;
    font-variant-numeric: tabular-nums;
  }

  .sortable-list__title {
    color: var(--text);
  }

  .add-contained-text__row {
    display: flex;
    gap: 0.5rem;
  }

  .add-contained-text__row input[type="text"] {
    flex: 1;
  }

  /* ---- Translation form ----------------------------------------------- */

  .page-header__aside {
    padding-bottom: 0.2rem;
  }

  .pdf-slot {
    display: grid;
    gap: 0.4rem;
    padding: 0.9rem 1rem;
    background: var(--page-background);
    border: 1px solid var(--border);
    border-radius: 8px;
  }

  .pdf-slot__head {
    display: flex;
    align-items: center;
    gap: 0.6rem;
  }

  .pdf-slot__number {
    display: inline-grid;
    place-items: center;
    width: 1.5rem;
    height: 1.5rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 700;
    background: var(--surface-muted);
    border-radius: 50%;
  }

  .pdf-slot__file {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-weight: 600;
  }

  .pdf-slot__empty {
    color: var(--text-faint);
  }

  .content-editor {
    min-height: 22rem;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.92rem;
    line-height: 1.55;
  }

  /* ---- Export ------------------------------------------------------------ */

  .export-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(19rem, 1fr));
    gap: 1rem;
  }

  .export-card {
    display: grid;
    align-content: start;
    gap: 0.9rem;
    padding: 1.1rem 1.2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
  }

  .export-card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
  }

  .export-card__header h2 {
    margin: 0;
    font-size: 1.05rem;
  }

  .lang-code {
    padding: 0.1rem 0.5rem;
    color: var(--color-primary);
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    background: var(--primary-wash);
    border-radius: 999px;
  }

  .export-card__facts {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.3rem 1rem;
    margin: 0;
    font-size: 0.92rem;
  }

  .export-card__facts dt {
    color: var(--text-faint);
  }

  .export-card__facts dd {
    margin: 0;
    font-variant-numeric: tabular-nums;
  }

  .zip-kind {
    margin-left: 0.35rem;
    padding: 0 0.35rem;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 700;
    border: 1px solid var(--border-strong);
    border-radius: 4px;
  }

  .export-card__download {
    justify-content: center;
  }

  .export-card__actions {
    display: grid;
    gap: 0.45rem;
  }

  .export-card__actions .btn {
    justify-content: center;
    width: 100%;
  }

  .export-progress {
    display: grid;
    gap: 0.4rem;
  }

  .export-progress__bar {
    height: 0.5rem;
    overflow: hidden;
    background: var(--surface-muted);
    border-radius: 999px;
  }

  .export-progress__bar span {
    display: block;
    height: 100%;
    min-width: 0.5rem;
    background: var(--color-primary);
    border-radius: inherit;
    transition: width 0.4s ease;
  }

  .export-progress__label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-muted);
    font-size: 0.9rem;
  }

  .export-error {
    display: flex;
    gap: 0.4rem;
    margin: 0;
    color: var(--danger);
    font-size: 0.9rem;
  }

  .export-card__publish summary {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-muted);
    font-size: 0.92rem;
    font-weight: 600;
    cursor: pointer;
  }

  .export-card__publish[open] summary {
    margin-bottom: 0.6rem;
  }

  .publish-form {
    display: flex;
    gap: 0.5rem;
  }

  .publish-form input {
    flex: 1;
  }

  .export-card__links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 1rem;
    padding-top: 0.8rem;
    font-size: 0.9rem;
    border-top: 1px solid var(--border);
  }

  .export-card__links a {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
  }

  /* ---- Minghui check --------------------------------------------------- */

  .check-list {
    display: grid;
    gap: 0.8rem;
    margin: 0;
    padding-left: 1.4rem;
  }

  .check-list__errors {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-left: 0.3rem;
  }

  .error-badge {
    padding: 0.05rem 0.45rem;
    color: var(--danger);
    font-size: 0.78rem;
    font-weight: 600;
    border: 1px solid color-mix(in srgb, var(--danger) 45%, white);
    border-radius: 4px;
  }

  .check-list__mh {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    margin-left: 0.4rem;
    font-size: 0.88rem;
  }

  .check-list__summary {
    margin-top: 0.25rem;
    color: var(--text-faint);
    font-size: 0.85rem;
  }

  @media (max-width: 640px) {
    .texts-table .col-kind,
    .texts-table .col-position {
      display: none;
    }

    .list-toolbar form {
      max-width: none;
    }
  }
}
