@layer components {
  /* Card */
  .card {
    background: var(--card); color: var(--card-foreground);
    border: 1px solid var(--border); border-radius: var(--radius-xl); box-shadow: var(--shadow-sm);
    display: flex; flex-direction: column; gap: 20px; padding: 24px;
  }
  .card-header { display: flex; flex-direction: column; gap: 6px; }
  .card-desc { color: var(--muted-foreground); }
  .card-footer {
    display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
    margin: 0 -24px -24px; padding: 14px 24px;
    border-top: 1px solid var(--border); background: var(--surface);
    border-radius: 0 0 var(--radius-xl) var(--radius-xl);
  }
  .card-footer .hint { flex: 1 1 240px; }
  .card--flush { padding: 0; gap: 0; overflow: hidden; }
  .card--flush > .card-header { padding: 20px 24px 16px; }
  .card--flush > .card-footer { margin: 0; }

  .auth-card { gap: 22px; padding: 28px; }
  .auth-card .card-header { text-align: center; align-items: center; }
  .auth-card .card-footer { margin: 0 -28px -28px; padding: 14px 28px; justify-content: center; }

  /* Buttons: outline by default, primary for the one main action. */
  .button {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 36px; padding: 0 16px; white-space: nowrap;
    font: inherit; font-size: 14px; font-weight: 500; line-height: 1; text-decoration: none;
    color: var(--foreground); background: var(--background);
    border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-xs);
    cursor: pointer; transition: background-color .15s, border-color .15s, box-shadow .15s;
  }
  .button:is(:hover, :active) { background: var(--accent); color: var(--accent-foreground); text-decoration: none; }
  .button:focus-visible { outline: none; border-color: var(--jx-accent); box-shadow: 0 0 0 3px var(--ring); }
  .button:disabled { opacity: .5; pointer-events: none; }
  .button svg { width: 16px; height: 16px; flex: none; }
  .button--primary { background: var(--primary); color: var(--primary-foreground); border-color: transparent; }
  .button--primary:is(:hover, :active) { background: color-mix(in oklch, var(--primary) 88%, black); color: var(--primary-foreground); }
  .button--ghost { background: transparent; border-color: transparent; box-shadow: none; }
  .button--danger { color: var(--jx-no); }
  .button--danger:is(:hover, :active) { background: var(--jx-no-soft); color: var(--jx-no); border-color: color-mix(in oklch, var(--jx-no) 35%, transparent); }
  .button--sm { height: 32px; padding: 0 12px; font-size: 13px; gap: 6px; }
  .button--icon { width: 32px; height: 32px; padding: 0; }
  .button--block { width: 100%; }
  form.button_to { display: inline-flex; margin: 0; }
  form.button_to:has(> .button--block) { display: flex; }
  .button-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

  /* Forms */
  .form { display: flex; flex-direction: column; gap: 16px; margin: 0; }
  .field { display: flex; flex-direction: column; gap: 8px; }
  .field-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
  .label { font-size: 14px; font-weight: 500; line-height: 1.2; }
  .field-row a { font-size: 13px; }
  .field-row a, .card-footer a:not(.button) { text-decoration: none; }
  .field-row a:hover, .card-footer a:not(.button):hover { text-decoration: underline; }
  .input {
    width: 100%; height: 36px; padding: 4px 12px;
    font: inherit; font-size: 14px; color: var(--foreground);
    background: transparent; border: 1px solid var(--input); border-radius: var(--radius-md); box-shadow: var(--shadow-xs);
    transition: border-color .15s, box-shadow .15s;
  }
  textarea.input { height: auto; min-height: 76px; padding: 8px 12px; line-height: 1.45; resize: vertical; }
  select.input { width: auto; min-width: 140px; padding-right: 28px; }
  .input::placeholder { color: var(--muted-foreground); }
  .input:focus-visible { outline: none; border-color: var(--jx-accent); box-shadow: 0 0 0 3px var(--ring); }
  .input[aria-invalid="true"] { border-color: var(--destructive); }
  .input--mono { font-family: var(--font-mono); font-size: 13px; }
  .hint { color: var(--muted-foreground); font-size: 13px; line-height: 1.45; }

  .check { display: flex; align-items: flex-start; gap: 10px; }
  .check input[type="checkbox"] { width: 16px; height: 16px; margin: 2px 0 0; flex: none; accent-color: var(--primary); }
  .check > div { display: flex; flex-direction: column; gap: 4px; }

  .form--inline { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0; }
  .form--inline select.input { height: 32px; min-width: 110px; font-size: 13px; }

  .divider { display: flex; align-items: center; gap: 12px; color: var(--muted-foreground); font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em; }
  .divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
  .separator { width: 100%; height: 1px; margin: 0; border: 0; background: var(--border); }

  /* Alerts (flash messages, form errors, notices) */
  .alert {
    display: flex; gap: 10px; align-items: flex-start;
    padding: 10px 14px; border: 1px solid var(--border); border-radius: var(--radius-lg);
    background: var(--card); font-size: 14px; line-height: 1.45;
  }
  .alert svg { width: 16px; height: 16px; flex: none; margin-top: 2px; }
  .alert ul { margin: 0; padding-left: 18px; }
  .alert--success { border-color: color-mix(in oklch, var(--jx-ok) 30%, transparent); background: var(--jx-ok-soft); }
  .alert--success svg { color: var(--jx-ok); }
  .alert--error { border-color: color-mix(in oklch, var(--jx-no) 35%, transparent); background: var(--jx-no-soft); }
  .alert--error svg { color: var(--jx-no); }
  .alert--info { background: var(--surface); color: var(--muted-foreground); }
  .flashes { display: flex; flex-direction: column; gap: 8px; }
  .app-main .flashes { max-width: 880px; margin: 0 auto 20px; }

  /* Badges */
  .badge {
    display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px;
    border-radius: 999px; font-size: 13px; font-weight: 500; line-height: 1.4; white-space: nowrap;
    background: var(--muted); color: var(--muted-foreground);
  }
  .badge--dot::before { content: ""; width: 6px; height: 6px; border-radius: 999px; background: currentColor; }
  .badge--active, .badge--enabled { background: var(--jx-ok-soft); color: var(--jx-ok); }
  .badge--invited, .badge--untested, .badge--wait { background: var(--jx-wait-soft); color: var(--jx-wait); }
  .badge--accent, .badge--tested { background: var(--jx-accent-soft); color: var(--jx-accent); }

  /* Tables */
  /* Positioned so the absolute visually-hidden labels inside are clipped by the scroller, not the page. */
  .table-wrap { position: relative; overflow-x: auto; }
  .table { width: 100%; border-collapse: collapse; font-size: 13px; }
  .table th {
    height: 40px; padding: 0 12px; text-align: left; white-space: nowrap;
    font-weight: 500; color: var(--muted-foreground); border-bottom: 1px solid var(--border);
  }
  .table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
  .table tbody tr:last-child td { border-bottom: 0; }
  .table tbody tr:hover { background: color-mix(in oklch, var(--muted) 50%, transparent); }
  .table th:first-child, .table td:first-child { padding-left: 24px; }
  .table th:last-child, .table td:last-child { padding-right: 24px; }
  .table .cell-actions { text-align: right; }
  .table .cell-actions > div { display: inline-flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; align-items: center; }
  .table .cell-strong { font-weight: 500; }
  .table .cell-mono { font-family: var(--font-mono); font-size: 13px; }
  .table .nowrap { white-space: nowrap; }
  .table .cell-ua { display: block; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .cell-stack { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }

  .person { display: flex; align-items: center; gap: 10px; min-width: 0; }
  .person > div { display: flex; flex-direction: column; min-width: 0; }
  .person .muted { font-size: 13px; }

  /* Definition list */
  .dl { display: grid; grid-template-columns: max-content 1fr; gap: 8px 24px; margin: 0; }
  .dl dt { color: var(--muted-foreground); }
  .dl dd { margin: 0; font-weight: 500; }

  /* Status line (SSO state) */
  .status { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
  .copy-box {
    padding: 10px 12px; border-radius: var(--radius-md); background: var(--surface); border: 1px dashed var(--border);
    font-family: var(--font-mono); font-size: 13px; word-break: break-all; user-select: all;
  }

  /* Empty-state panel on the home page */
  .empty {
    display: flex; flex-direction: column; align-items: flex-start; gap: 10px;
    padding: 28px; border: 1px dashed var(--border); border-radius: var(--radius-xl); background: var(--surface);
  }
  .empty svg { width: 22px; height: 22px; color: var(--muted-foreground); }

  @media (max-width: 767px) {
    .card:not(.card--flush) { padding: 20px; }
    .card--flush > .card-header { padding: 16px; }
    .card-footer { margin: 0 -20px -20px; padding: 12px 20px; }
    .auth-card { padding: 24px 20px; }
    .auth-card .card-footer { margin: 0 -20px -24px; padding: 12px 20px; }
    .dl { grid-template-columns: 1fr; gap: 2px; }
    .dl dd { margin-bottom: 8px; }
    .table th:first-child, .table td:first-child { padding-left: 16px; }
    .table th:last-child, .table td:last-child { padding-right: 16px; }

    /* Stacked rows on phones: one block per row, cells labelled by data-label when set. */
    .table--stack, .table--stack tbody { display: block; }
    .table--stack thead { display: none; }
    .table--stack tr { display: flex; flex-direction: column; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
    .table--stack tbody tr:last-child { border-bottom: 0; }
    .table--stack td, .table--stack td:first-child, .table--stack td:last-child { display: block; padding: 0; border: 0; white-space: normal; }
    .table--stack td[data-label]::before { content: attr(data-label); display: block; font-size: 13px; color: var(--muted-foreground); }
    /* A labelled cell with no value would show its label alone. */
    .table--stack td[data-label]:empty { display: none; }
    .table--stack .cell-actions { text-align: left; }
    .table--stack .cell-actions > div { justify-content: flex-start; }
    .table--stack .cell-actions:not(:has(form)) { display: none; }
    .table--stack .cell-ua { max-width: 100%; }
  }
}
