/* Styles for the reusable components in templates/components/. One block per component. */

/* ---------- Icon ---------- */

.icon {
  flex-shrink: 0;
  width: var(--icon-size, 1.125rem);
  height: var(--icon-size, 1.125rem);
  stroke: currentColor;
  fill: none;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon--sm { --icon-size: 1rem; }
.icon--lg { --icon-size: 1.5rem; }
.icon--xl { --icon-size: 2rem; }

/* ---------- Navbar ---------- */

.navbar {
  position: sticky;
  top: 0;
  z-index: var(--z-navbar);
  background: var(--color-surface-translucent);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: var(--border);
}

/* Hidden while scrolling down on pages with <body data-navbar-autohide>. */
html[data-navbar-hidden] {
  --navbar-offset: 0px;
}

html[data-navbar-hidden] .navbar {
  transform: translateY(-100%);
}

.navbar__inner {
  display: flex;
  align-items: center;
  gap: var(--space-6);
  height: var(--navbar-height);
}

.navbar__brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: var(--weight-semibold);
  font-size: var(--text-lg);
  letter-spacing: var(--tracking-tight);
  color: var(--color-text);
  text-decoration: none;
}

.navbar__brand:hover {
  color: var(--color-text);
}

.navbar__logo {
  width: 1.5rem;
  height: 1.5rem;
  color: var(--color-accent);
}

.navbar__links {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  list-style: none;
  padding: 0;
}

.navbar__link {
  display: inline-flex;
  align-items: center;
  height: var(--control-height-sm);
  padding-inline: var(--space-3);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  text-decoration: none;
  transition: color var(--duration-fast), background var(--duration-fast);
}

.navbar__link:hover {
  color: var(--color-text);
  background: var(--color-bg-subtle);
}

.navbar__link[aria-current="page"] {
  color: var(--color-text);
  background: var(--color-bg-muted);
}

.navbar__end {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-left: auto;
}

/* Language switch and light/dark toggle (navbar preferences(), theme.js). */
.preferences {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.language-switch {
  display: inline-flex;
  padding: 2px;
  border: var(--border);
  border-radius: var(--radius-full);
}

.language-switch__option {
  min-width: 2rem;
  padding: 2px var(--space-2);
  border: 0;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--color-text-muted);
  font: inherit;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background var(--duration-fast), color var(--duration-fast);
}

.language-switch__option:hover {
  color: var(--color-text);
}

.language-switch__option[aria-pressed="true"] {
  background: var(--color-bg-muted);
  color: var(--color-text);
}

.language-switch__option:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* The toggle shows the icon of the theme it switches to. */
.theme-toggle__sun {
  display: none;
}

:root[data-theme="dark"] .theme-toggle__sun {
  display: inline-block;
}

:root[data-theme="dark"] .theme-toggle__moon {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle__sun {
    display: inline-block;
  }

  :root:not([data-theme="light"]) .theme-toggle__moon {
    display: none;
  }
}

.navbar__status {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
  text-decoration: none;
  padding: var(--space-1) var(--space-2);
  border: var(--border);
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.navbar__status--warning {
  color: var(--color-warning);
  border-color: var(--color-warning-border);
  background: var(--color-warning-bg);
}

.navbar__status--danger {
  color: var(--color-danger);
  border-color: var(--color-danger-border);
  background: var(--color-danger-bg);
}

.navbar .navbar__toggle {
  display: none;
}

/* User menu (details/summary dropdown, works without JS) */

.user-menu {
  position: relative;
}

.user-menu__trigger {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: var(--control-height-sm);
  padding: 0 var(--space-2) 0 var(--space-1);
  border-radius: var(--radius-full);
  list-style: none;
  cursor: pointer;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.user-menu__trigger::-webkit-details-marker {
  display: none;
}

.user-menu__trigger:hover {
  background: var(--color-bg-subtle);
}

.avatar {
  display: inline-grid;
  place-items: center;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: var(--radius-full);
  background: var(--color-accent-subtle);
  color: var(--color-accent);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  flex-shrink: 0;
}

.avatar--lg {
  width: 2.5rem;
  height: 2.5rem;
  font-size: var(--text-sm);
}

.avatar--muted {
  background: var(--color-bg-muted);
  color: var(--color-text-muted);
}

.user-menu__panel {
  position: absolute;
  right: 0;
  top: calc(100% + var(--space-2));
  z-index: var(--z-dropdown);
  min-width: 15rem;
  padding: var(--space-2);
  background: var(--color-surface);
  border: var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-overlay);
}

.user-menu__header {
  padding: var(--space-2) var(--space-3) var(--space-3);
  border-bottom: var(--border);
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
}

.user-menu__item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-radius: var(--radius-md);
  background: none;
  color: var(--color-text);
  font-size: var(--text-sm);
  text-align: left;
  text-decoration: none;
}

.user-menu__item:hover {
  background: var(--color-bg-subtle);
  color: var(--color-text);
}

@media (max-width: 48rem) {
  .navbar .navbar__toggle {
    display: inline-flex;
  }

  .navbar__nav {
    display: none;
    position: absolute;
    inset: var(--navbar-height) 0 auto 0;
    padding: var(--space-3) var(--gutter) var(--space-4);
    background: var(--color-bg);
    border-bottom: var(--border);
  }

  .navbar[data-open] .navbar__nav {
    display: block;
  }

  .navbar__links {
    flex-direction: column;
    align-items: stretch;
  }

  .navbar__link {
    height: var(--control-height);
  }

  .user-menu__name {
    display: none;
  }
}

/* Phones: keep brand, status, avatar and menu button on one line. */
@media (max-width: 30rem) {
  .navbar__inner {
    gap: var(--space-3);
  }

  .navbar__end {
    gap: var(--space-2);
  }

  .navbar__status .icon,
  .user-menu__trigger .icon--chevron {
    display: none;
  }
}

/* ---------- Footer ---------- */

.footer {
  margin-top: auto;
  border-top: var(--border);
  background: var(--color-bg-subtle);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.footer__inner {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-4) var(--space-8);
  padding-block: var(--space-8);
}

.footer__links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-5);
  list-style: none;
  padding: 0;
}

.footer__links a {
  color: var(--color-text-muted);
  text-decoration: none;
}

.footer__links a:hover {
  color: var(--color-text);
  text-decoration: underline;
}

.footer__notice {
  flex-basis: 100%;
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
}

/* ---------- Button ---------- */

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

.btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  pointer-events: none;
}

.btn--primary {
  background: var(--color-accent);
  color: var(--color-text-inverse);
}

.btn--primary:hover {
  background: var(--color-accent-hover);
  color: var(--color-text-inverse);
}

.btn--primary:active {
  background: var(--color-accent-active);
}

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

.btn--secondary:hover {
  background: var(--color-bg-subtle);
  color: var(--color-text);
}

.btn--ghost {
  background: transparent;
  color: var(--color-text-muted);
}

.btn--ghost:hover {
  background: var(--color-bg-subtle);
  color: var(--color-text);
}

.btn--danger {
  background: var(--color-danger);
  color: var(--color-text-inverse);
}

.btn--danger:hover {
  background: var(--color-danger-hover);
  color: var(--color-text-inverse);
}

.btn--sm {
  height: var(--control-height-sm);
  padding-inline: var(--space-3);
  font-size: var(--text-xs);
}

.btn--lg {
  height: var(--control-height-lg);
  padding-inline: var(--space-6);
  font-size: var(--text-base);
}

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

.btn--icon {
  width: var(--control-height);
  padding: 0;
}

.btn--icon.btn--sm {
  width: var(--control-height-sm);
}

/* Quiet destructive action inside lists; the confirm dialog carries the emphasis. */
.btn--ghost.btn--danger-text {
  color: var(--color-danger);
}

.btn--ghost.btn--danger-text:hover {
  background: var(--color-danger-bg);
  color: var(--color-danger-hover);
}

/* ---------- Form fields ---------- */

.form {
  display: grid;
  gap: var(--space-5);
}

.form-row {
  display: grid;
  align-items: start;
  gap: var(--space-5);
  grid-template-columns: repeat(auto-fit, minmax(min(12rem, 100%), 1fr));
}

.field {
  display: grid;
  align-content: start;
  gap: var(--space-2);
  min-width: 0;
}

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

.field__optional {
  font-weight: var(--weight-regular);
  color: var(--color-text-subtle);
}

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

.field__error {
  display: flex;
  align-items: flex-start;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--color-danger);
}

.input,
.select,
.textarea {
  width: 100%;
  min-height: var(--control-height);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface);
  border: var(--border-width) solid var(--color-border-strong);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}

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

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

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: var(--focus-ring);
}

.textarea {
  min-height: 6rem;
  resize: vertical;
  line-height: var(--leading-normal);
}

.select {
  appearance: none;
  padding-right: var(--space-8);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23545c6b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  background-size: 1rem;
}

.field--invalid .input,
.field--invalid .select,
.field--invalid .textarea {
  border-color: var(--color-danger);
}

.field--invalid .input:focus,
.field--invalid .select:focus,
.field--invalid .textarea:focus {
  box-shadow: 0 0 0 3px var(--color-danger-ring);
}

.input[type="file"] {
  padding: var(--space-2);
  cursor: pointer;
}

.input[type="file"]::file-selector-button {
  margin-right: var(--space-3);
  padding: var(--space-1) var(--space-3);
  border: var(--border-width) solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-bg-subtle);
  font-size: var(--text-xs);
  cursor: pointer;
}

.password-field {
  position: relative;
}

.password-field .input {
  padding-right: var(--space-12);
}

.password-field__toggle {
  position: absolute;
  top: 50%;
  right: var(--space-1);
  transform: translateY(-50%);
}

.checkbox {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  font-size: var(--text-sm);
  cursor: pointer;
}

.checkbox__input {
  flex-shrink: 0;
  width: 1.125rem;
  height: 1.125rem;
  margin-top: 0.15em;
  accent-color: var(--color-accent);
  cursor: pointer;
}

/* Radio group (forms.html radio_group): one bordered option per choice. */
.radio-group {
  display: grid;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  border: 0;
}

.radio-option {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color var(--duration-fast), background var(--duration-fast);
}

.radio-option:hover {
  border-color: var(--color-border-strong);
}

.radio-option:has(.radio-option__input:checked) {
  border-color: var(--color-accent-border);
  background: var(--color-accent-subtle);
}

.radio-option__input {
  flex-shrink: 0;
  width: 1.125rem;
  height: 1.125rem;
  margin-top: 0.15em;
  accent-color: var(--color-accent);
  cursor: pointer;
}

.radio-option__text {
  display: grid;
  gap: var(--space-1);
}

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

.radio-option__hint {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* ---------- Alert ---------- */

.alert {
  display: flex;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: var(--border-width) solid var(--alert-border);
  border-radius: var(--radius-md);
  background: var(--alert-bg);
  color: var(--color-text);
  font-size: var(--text-sm);
}

.alert__icon {
  color: var(--alert-fg);
  margin-top: 0.15em;
}

.alert__body {
  flex: 1;
  min-width: 0;
}

.alert__title {
  font-weight: var(--weight-semibold);
  color: var(--alert-fg);
}

.alert__body > * + * {
  margin-top: var(--space-1);
}

.alert--info { --alert-fg: var(--color-info); --alert-bg: var(--color-info-bg); --alert-border: var(--color-info-border); }
.alert--success { --alert-fg: var(--color-success); --alert-bg: var(--color-success-bg); --alert-border: var(--color-success-border); }
.alert--warning { --alert-fg: var(--color-warning); --alert-bg: var(--color-warning-bg); --alert-border: var(--color-warning-border); }
.alert--error { --alert-fg: var(--color-danger); --alert-bg: var(--color-danger-bg); --alert-border: var(--color-danger-border); }

/* ---------- Toast ---------- */

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

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
  background: var(--color-surface);
  border: var(--border);
  border-left: 3px solid var(--toast-accent, var(--color-info));
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-overlay);
  font-size: var(--text-sm);
  pointer-events: auto;
  animation: toast-in var(--duration-base) var(--ease-out);
}

.toast__icon {
  color: var(--toast-accent, var(--color-info));
  margin-top: 0.1em;
}

.toast__message {
  flex: 1;
}

.toast--success { --toast-accent: var(--color-success); }
.toast--warning { --toast-accent: var(--color-warning); }
.toast--error { --toast-accent: var(--color-danger); }

.toast[data-leaving] {
  opacity: 0;
  transform: translateY(4px);
  transition: opacity var(--duration-base), transform var(--duration-base);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* ---------- Modal ---------- */

.modal {
  /* Centered in the viewport. The global margin reset in base.css removes the
     browser's default `margin: auto` for dialogs, so restore it here. */
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(32rem, calc(100vw - 2 * var(--space-4)));
  height: fit-content;
  max-height: calc(100vh - 2 * var(--space-8));
  padding: 0;
  border: var(--border);
  border-radius: var(--radius-xl);
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-overlay);
}

.modal::backdrop {
  background: var(--color-overlay);
}

.modal[open] {
  animation: modal-in var(--duration-base) var(--ease-out);
}

.modal__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-6) 0;
}

.modal__title {
  font-size: var(--text-lg);
}

.modal__body {
  padding: var(--space-3) var(--space-6) var(--space-6);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
}

.modal__footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: var(--border);
  background: var(--color-bg-subtle);
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}

/* ---------- Card ---------- */

.card {
  background: var(--color-surface);
  border: var(--border);
  border-radius: var(--radius-lg);
}

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-5) var(--space-6) 0;
}

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

.card__body {
  padding: var(--space-5) var(--space-6);
}

.card__footer {
  padding: var(--space-4) var(--space-6);
  border-top: var(--border);
}

.card--muted {
  background: var(--color-bg-subtle);
}

.card--highlight {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 1px var(--color-accent);
}

/* Definition list used in cards (account details etc.) */

.meta-list {
  display: grid;
  grid-template-columns: minmax(8rem, max-content) 1fr;
  gap: var(--space-2) var(--space-6);
  font-size: var(--text-sm);
}

.meta-list dt {
  color: var(--color-text-muted);
}

.meta-list dd {
  margin: 0;
}

/* ---------- Badge ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  height: 1.375rem;
  padding-inline: var(--space-2);
  border: var(--border-width) solid var(--badge-border, var(--color-border));
  border-radius: var(--radius-sm);
  background: var(--badge-bg, var(--color-bg-subtle));
  color: var(--badge-fg, var(--color-text-muted));
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  white-space: nowrap;
}

.badge--accent { --badge-fg: var(--color-accent); --badge-bg: var(--color-accent-subtle); --badge-border: var(--color-accent-border); }
.badge--success { --badge-fg: var(--color-success); --badge-bg: var(--color-success-bg); --badge-border: var(--color-success-border); }
.badge--warning { --badge-fg: var(--color-warning); --badge-bg: var(--color-warning-bg); --badge-border: var(--color-warning-border); }
.badge--danger { --badge-fg: var(--color-danger); --badge-bg: var(--color-danger-bg); --badge-border: var(--color-danger-border); }
.badge--outline { --badge-bg: transparent; }

/* Court badges: one tone per court level */
.badge--court-constitutional { --badge-fg: var(--color-court-constitutional); --badge-bg: var(--color-court-constitutional-bg); --badge-border: var(--color-court-constitutional-border); }
.badge--court-federal { --badge-fg: var(--color-accent); --badge-bg: var(--color-accent-subtle); --badge-border: var(--color-accent-border); }
.badge--court-fiscal { --badge-fg: var(--color-court-fiscal); --badge-bg: var(--color-court-fiscal-bg); --badge-border: var(--color-court-fiscal-border); }
.badge--court-european { --badge-fg: var(--color-court-european); --badge-bg: var(--color-court-european-bg); --badge-border: var(--color-court-european-border); }

/* ---------- Progress bar ---------- */

.progress {
  display: grid;
  gap: var(--space-2);
}

.progress__header {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  font-size: var(--text-sm);
}

.progress__value {
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

.progress__bar {
  width: 100%;
  height: 0.5rem;
  appearance: none;
  border: 0;
  border-radius: var(--radius-full);
  background: var(--color-bg-muted);
  overflow: hidden;
  color: var(--progress-fill, var(--color-accent));
}

.progress__bar::-webkit-progress-bar {
  background: var(--color-bg-muted);
  border-radius: var(--radius-full);
}

.progress__bar::-webkit-progress-value {
  background: var(--progress-fill, var(--color-accent));
  border-radius: var(--radius-full);
}

.progress__bar::-moz-progress-bar {
  background: var(--progress-fill, var(--color-accent));
  border-radius: var(--radius-full);
}

.progress--warning { --progress-fill: var(--color-warning); }
.progress--danger { --progress-fill: var(--color-danger); }

/* ---------- Search bar and filters ---------- */

.search-bar {
  display: flex;
  gap: var(--space-2);
}

.search-bar__field {
  position: relative;
  flex: 1;
  min-width: 0;
}

.search-bar__icon {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-subtle);
  pointer-events: none;
}

.search-bar .input {
  height: var(--control-height-lg);
  padding-left: var(--space-10);
  font-size: var(--text-base);
}

.search-bar .btn {
  height: var(--control-height-lg);
}

.filter-panel {
  margin-top: var(--space-4);
  border: var(--border);
  border-radius: var(--radius-lg);
  background: var(--color-bg-subtle);
}

.filter-panel__summary {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  list-style: none;
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
}

.filter-panel__summary::-webkit-details-marker {
  display: none;
}

.filter-panel__summary .icon {
  transition: transform var(--duration-fast);
}

.filter-panel[open] .filter-panel__summary .icon--chevron {
  transform: rotate(180deg);
}

.filter-panel__body {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(min(11rem, 100%), 1fr));
  padding: 0 var(--space-4) var(--space-4);
}

.filter-panel__actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}

/* ---------- Result list ---------- */

.result-list {
  list-style: none;
  padding: 0;
  border-top: var(--border);
}

.result-item {
  padding-block: var(--space-5);
  border-bottom: var(--border);
}

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

.result-item__file {
  font-variant-numeric: tabular-nums;
  font-weight: var(--weight-medium);
  color: var(--color-text);
}

.result-item__title {
  margin-top: var(--space-2);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
}

.result-item__title a {
  color: var(--color-text);
  text-decoration: none;
}

.result-item__title a:hover {
  color: var(--color-accent);
  text-decoration: underline;
}

.result-item__snippet {
  margin-top: var(--space-2);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  max-width: var(--measure);
}

.result-item__norms {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.norm-chip {
  white-space: nowrap;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  padding: 0.1rem var(--space-2);
  background: var(--color-bg-subtle);
  border-radius: var(--radius-sm);
}

/* ---------- Pagination ---------- */

.pagination {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  margin-top: var(--space-8);
  list-style: none;
  padding: 0;
}

.pagination__link {
  display: inline-grid;
  place-items: center;
  min-width: var(--control-height-sm);
  height: var(--control-height-sm);
  padding-inline: var(--space-2);
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
  text-decoration: none;
}

.pagination__link:hover {
  background: var(--color-bg-subtle);
  color: var(--color-text);
}

.pagination__link[aria-current="page"] {
  background: var(--color-text);
  color: var(--color-text-inverse);
}

.pagination__link[aria-disabled="true"] {
  opacity: 0.4;
  pointer-events: none;
}

.pagination__gap {
  color: var(--color-text-subtle);
  padding-inline: var(--space-1);
}

/* ---------- Source citation ---------- */

.citation-list {
  display: grid;
  gap: var(--space-2);
  list-style: none;
  padding: 0;
}

.citation {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: var(--border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  text-decoration: none;
  transition: border-color var(--duration-fast), background var(--duration-fast);
}

a.citation:hover {
  border-color: var(--color-accent-border);
  background: var(--color-accent-subtle);
  color: var(--color-text);
}

.citation__index {
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: var(--radius-sm);
  background: var(--color-bg-muted);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
}

.citation__body {
  min-width: 0;
  font-size: var(--text-sm);
}

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

.citation__title {
  color: var(--color-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.citation-marker {
  display: inline-grid;
  place-items: center;
  min-width: 1.15rem;
  height: 1.15rem;
  padding-inline: 0.2rem;
  margin-inline: 0.1rem;
  border-radius: var(--radius-sm);
  background: var(--color-accent-subtle);
  color: var(--color-accent);
  font-size: 0.7rem;
  font-weight: var(--weight-semibold);
  vertical-align: 0.15em;
  text-decoration: none;
}

/* ---------- Research progress and steps ---------- */

.research-progress {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: var(--border);
  border-radius: var(--radius-md);
  background: var(--color-bg-subtle);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.research-progress__label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.research-steps {
  border-top: var(--border);
  font-size: var(--text-sm);
}

.research-steps__summary {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding-block: var(--space-3);
  list-style: none;
  cursor: pointer;
  color: var(--color-text-muted);
  font-weight: var(--weight-medium);
}

.research-steps__summary::-webkit-details-marker {
  display: none;
}

.research-steps[open] .icon--chevron {
  transform: rotate(180deg);
}

.research-steps__list {
  display: grid;
  gap: var(--space-2);
  padding: 0 0 var(--space-3);
  list-style: none;
  counter-reset: step;
}

.research-steps__item {
  display: flex;
  gap: var(--space-3);
  color: var(--color-text-muted);
}

.research-steps__item::before {
  counter-increment: step;
  content: counter(step);
  flex-shrink: 0;
  width: 1.25rem;
  color: var(--color-text-subtle);
  font-variant-numeric: tabular-nums;
}

.research-steps__count {
  margin-left: auto;
  color: var(--color-text-subtle);
  white-space: nowrap;
}

/* The model's thinking: collapsed; live while the answer is written. */
.thinking {
  font-size: var(--text-sm);
}

.thinking__summary {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding-block: var(--space-1);
  list-style: none;
  cursor: pointer;
  color: var(--color-text-muted);
  font-weight: var(--weight-medium);
}

.thinking__summary::-webkit-details-marker {
  display: none;
}

.thinking__summary:hover {
  color: var(--color-text);
}

.thinking[open] .icon--chevron {
  transform: rotate(180deg);
}

.thinking__pulse {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--color-accent);
}

/* Thinking has ended (the answer text arrives): the pulse stops. */
.thinking--live[data-done] .thinking__pulse {
  background: var(--color-text-subtle);
}

.thinking__text {
  max-height: 18rem;
  margin-top: var(--space-2);
  padding: var(--space-3) var(--space-4);
  overflow-y: auto;
  overscroll-behavior: contain;
  border-left: 2px solid var(--color-border-strong);
  color: var(--color-text-muted);
  line-height: var(--leading-relaxed);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* The answer while it is written (plain text; the formatted answer replaces it). */
.chat-draft {
  white-space: pre-wrap;
}

.web-sources {
  display: grid;
  gap: var(--space-2);
  padding: 0;
  list-style: none;
}

.web-source {
  display: grid;
  gap: 0.125rem;
  padding: var(--space-2) var(--space-3);
  border: var(--border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  font-size: var(--text-sm);
  text-decoration: none;
  transition: border-color var(--duration-fast), background var(--duration-fast);
}

.web-source:hover {
  border-color: var(--color-accent-border);
  background: var(--color-accent-subtle);
  color: var(--color-text);
}

.web-source__title {
  font-weight: var(--weight-medium);
  overflow-wrap: anywhere;
}

.web-source__host {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
}

.web-sources__note {
  margin-top: var(--space-2);
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
}

/* ---------- Empty state ---------- */

.empty-state {
  display: grid;
  justify-items: center;
  gap: var(--space-3);
  padding: var(--space-12) var(--space-6);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-lg);
  text-align: center;
}

.empty-state__icon {
  color: var(--color-text-subtle);
}

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

.empty-state__text {
  max-width: 28rem;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* ---------- Loading indicator ---------- */

.spinner {
  flex-shrink: 0;
  width: var(--spinner-size, 1rem);
  height: var(--spinner-size, 1rem);
  border: 2px solid var(--color-border-strong);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.spinner--lg {
  --spinner-size: 1.75rem;
}

.loading {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.loading--block {
  display: flex;
  justify-content: center;
  padding: var(--space-10);
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 2s;
  }
}

/* ---------- Sample data label ---------- */

.sample-label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--color-warning);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
}

/* ---------- Landing page ---------- */

.hero {
  padding-block: var(--space-24) var(--space-16);
}

.hero__eyebrow {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-accent);
}

.hero__title {
  max-width: 44rem;
  font-size: var(--text-4xl);
  line-height: 1.1;
}

.hero__lead {
  max-width: 38rem;
  margin-top: var(--space-5);
  font-size: var(--text-lg);
  color: var(--color-text-muted);
}

.hero__actions {
  margin-top: var(--space-8);
}

.feature {
  display: grid;
  gap: var(--space-2);
  align-content: start;
}

.feature__icon {
  display: inline-grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  margin-bottom: var(--space-2);
  border: var(--border);
  border-radius: var(--radius-md);
  color: var(--color-accent);
}

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

.feature__text {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.landing-features {
  padding-block: var(--space-12) var(--space-20);
  border-top: var(--border);
}

/* ---------- Auth pages ---------- */

.auth-page {
  display: grid;
  justify-items: center;
  gap: var(--space-5);
  padding: var(--space-16) var(--gutter) var(--space-20);
}

.auth-card {
  display: grid;
  gap: var(--space-6);
  width: 100%;
  max-width: var(--container-narrow);
  padding: var(--space-8);
  background: var(--color-surface);
  border: var(--border);
  border-radius: var(--radius-xl);
}

.auth-card__header {
  display: grid;
  gap: var(--space-2);
}

.auth-card__title {
  font-size: var(--text-2xl);
}

.auth-card__lead {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.auth-card__icon {
  display: inline-grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  border-radius: var(--radius-full);
  background: var(--color-accent-subtle);
  color: var(--color-accent);
}

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

.auth-card__email {
  color: var(--color-text);
  font-weight: var(--weight-semibold);
  overflow-wrap: anywhere;
}

.auth-page__switch {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

@media (max-width: 30rem) {
  .auth-page {
    padding-top: var(--space-8);
  }

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

/* ---------- Settings ---------- */

.settings-current {
  margin-bottom: var(--space-5);
}

/* ---------- Plans ---------- */

.plan-grid {
  display: grid;
  gap: var(--space-5);
  grid-template-columns: repeat(auto-fit, minmax(min(15rem, 100%), 1fr));
  align-items: stretch;
}

.plan-card {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: var(--space-5);
  padding: var(--space-6);
  background: var(--color-surface);
  border: var(--border);
  border-radius: var(--radius-lg);
}

.plan-card--current {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 1px var(--color-accent);
}

.plan-card__header {
  display: grid;
  gap: var(--space-2);
}

.plan-card__title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.plan-card__name {
  font-size: var(--text-lg);
}

.plan-card__description {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.plan-card__price {
  display: grid;
  gap: var(--space-1);
}

.plan-card__amount {
  font-size: var(--text-2xl);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
  font-variant-numeric: tabular-nums;
}

.plan-card__interval {
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
}

.plan-card__features {
  display: grid;
  align-content: start;
  gap: var(--space-3);
  padding: var(--space-5) 0 0;
  margin: 0;
  border-top: var(--border);
  list-style: none;
  font-size: var(--text-sm);
}

.plan-feature {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
}

.plan-feature .icon {
  margin-top: 0.15rem;
  color: var(--color-success);
}

.plan-feature--excluded {
  color: var(--color-text-subtle);
}

.plan-feature--excluded .icon {
  color: var(--color-text-subtle);
}

/* ---------- Account: subscription and usage ---------- */

.subscription-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

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

.subscription-head__name {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
}

.subscription-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-4);
  padding-inline: var(--space-1);
}

.meter-grid {
  display: grid;
  gap: var(--space-6);
  grid-template-columns: repeat(auto-fit, minmax(min(14rem, 100%), 1fr));
}

.meter {
  display: grid;
  align-content: start;
  gap: var(--space-2);
}

.meter__hint,
.card-note {
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
}

.card-note {
  margin-top: var(--space-4);
}

.form-row--postal {
  grid-template-columns: minmax(6rem, 8rem) 1fr;
}

.form-row--invite {
  grid-template-columns: repeat(auto-fit, minmax(min(11rem, 100%), 1fr));
}

@media (min-width: 40rem) {
  .form-row--invite {
    grid-template-columns: 1fr 12rem;
  }
}

/* ---------- Team ---------- */

.member-list {
  display: grid;
  margin: 0;
  padding: 0;
  list-style: none;
}

.member-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  padding-block: var(--space-4);
}

.member-row + .member-row {
  border-top: var(--border);
}

.member-row:first-child {
  padding-top: 0;
}

.member-row:last-child {
  padding-bottom: 0;
}

.member-row__info {
  min-width: 0;
}

.member-row__name {
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  overflow-wrap: anywhere;
}

.member-row__detail {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  overflow-wrap: anywhere;
}

.member-row__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-1);
}

.member-row__actions:empty {
  display: none;
}

@media (max-width: 40rem) {
  .member-row {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .member-row__actions {
    grid-column: 2 / -1;
    justify-content: flex-start;
    margin-left: calc(-1 * var(--space-3));
  }
}

/* ---------- Error page ---------- */

.error-page {
  display: grid;
  justify-items: start;
  gap: var(--space-4);
  padding-block: var(--space-24);
}

.error-page__code {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-accent);
  font-variant-numeric: tabular-nums;
}

/* ---------- Component preview (debug only) ---------- */

.preview-section {
  padding-block: var(--space-8);
  border-top: var(--border);
}

.preview-section__title {
  margin-bottom: var(--space-5);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--color-text-subtle);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ---------- Case law: norm chips, results header, decision page ---------- */

.norm-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  list-style: none;
  padding: 0;
}

.norm-chip--link {
  color: var(--color-text-muted);
  text-decoration: none;
  border: var(--border-width) solid transparent;
  transition:
    color var(--duration-fast) var(--ease-out),
    background-color var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out);
}

.norm-chip--link:hover {
  color: var(--color-accent);
  background: var(--color-accent-subtle);
  border-color: var(--color-accent-border);
}

.result-item__section {
  font-weight: var(--weight-medium);
  color: var(--color-text);
}

.filter-panel .field__optional {
  display: none;
}

.results-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2) var(--space-4);
  margin-bottom: var(--space-3);
}

.results-header__title {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
}

.results-header__mode {
  font-size: var(--text-sm);
  color: var(--color-text-subtle);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  margin-bottom: var(--space-6);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-decoration: none;
}

.back-link:hover {
  color: var(--color-accent);
}

.decision-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  gap: var(--space-12);
  align-items: start;
}

/* The aside spans the whole article, so the sticky contents stay in view while scrolling. */
.decision-layout__aside {
  align-self: stretch;
}

.decision-layout__sticky {
  position: sticky;
  top: calc(var(--navbar-offset) + var(--space-6));
  display: grid;
  gap: var(--space-6);
  /* Decisions with many sections: the sidebar scrolls on its own instead of being cut off. */
  max-height: calc(100vh - var(--navbar-offset) - var(--space-12));
  overflow-y: auto;
  /* Room for focus rings, which the scroll area would otherwise clip. */
  padding: var(--space-1);
  margin: calc(-1 * var(--space-1));
}

/* The grid gap spaces the back link; it keeps its own width instead of stretching. */
.decision-layout__sticky .back-link {
  justify-self: start;
  margin-bottom: 0;
}

.decision {
  max-width: var(--measure);
}

.decision__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.decision__file {
  font-weight: var(--weight-medium);
  color: var(--color-text);
  font-variant-numeric: tabular-nums;
}

.decision__title {
  margin-top: var(--space-3);
  font-size: var(--text-3xl);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
}

.decision__header + * {
  margin-top: var(--space-6);
}

.decision__facts {
  margin-top: var(--space-6);
  padding: var(--space-5);
  border: var(--border);
  border-radius: var(--radius-lg);
  background: var(--color-bg-subtle);
}

.decision__body {
  margin-top: var(--space-10);
}

.decision__section {
  scroll-margin-top: calc(var(--navbar-height) + var(--space-6));
}

.decision__section + .decision__section {
  margin-top: var(--space-10);
}

.decision__heading {
  font-size: var(--text-xl);
  margin-bottom: var(--space-4);
}

.decision__text,
.decision__tenor {
  line-height: var(--leading-relaxed);
}

.decision__text > p + p,
.decision__tenor > p + p {
  margin-top: var(--space-4);
}

.decision__tenor {
  padding-left: var(--space-4);
  border-left: 3px solid var(--color-accent-border);
}

.decision__headnotes {
  display: grid;
  gap: var(--space-4);
  padding-left: var(--space-5);
  line-height: var(--leading-relaxed);
  font-weight: var(--weight-medium);
}

.decision__headnotes--single {
  list-style: none;
  padding-left: 0;
}

.decision__section .norm-chips {
  margin-top: var(--space-3);
}

/* Table of contents */

.toc__title {
  margin-bottom: var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-subtle);
}

.toc__list {
  list-style: none;
  padding: 0;
  border-left: var(--border);
}

.toc__link {
  display: block;
  margin-left: calc(-1 * var(--border-width));
  padding: var(--space-1) var(--space-3);
  border-left: 2px solid transparent;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  text-decoration: none;
  transition:
    color var(--duration-fast) var(--ease-out),
    border-color var(--duration-base) var(--ease-out);
}

.toc__link:hover {
  color: var(--color-text);
}

.toc__link[aria-current="true"] {
  color: var(--color-accent);
  border-left-color: var(--color-accent);
  font-weight: var(--weight-medium);
}

@media (max-width: 900px) {
  .decision-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-6);
  }

  .decision-layout__sticky {
    position: static;
    max-height: none;
    overflow-y: visible;
  }

  .decision-layout__aside .toc {
    display: none;
  }

  .decision__title {
    font-size: var(--text-2xl);
  }
}

.related-results .result-item__title {
  font-weight: var(--weight-medium);
}

.related-results .result-list {
  border-top-style: dashed;
}

/* ---------- Docking search bar (search-dock.js) ---------- */

.search-dock {
  scroll-margin-top: calc(var(--navbar-height) + var(--space-4));
}

/* Keeps the original height while the form is docked, so nothing jumps. */
.search-dock[data-docked] {
  min-height: var(--dock-height);
}

.search-dock__filter {
  display: none;
}

/* Full-width bar; the padding lines the content up with the page column. */
.search-dock[data-docked] > .search-bar {
  position: fixed;
  top: var(--navbar-offset);
  left: 0;
  right: 0;
  z-index: calc(var(--z-navbar) - 1);
  padding: var(--space-3) max(var(--gutter), calc((100% - var(--container-medium)) / 2));
  background: var(--color-surface-translucent);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: var(--border);
  box-shadow: var(--shadow-raised);
}

.search-dock[data-docked] .search-bar .input,
.search-dock[data-docked] .search-bar .btn {
  height: var(--control-height);
}

.search-dock[data-docked] .search-dock__filter {
  display: inline-flex;
}

.search-dock__count {
  display: inline-grid;
  place-items: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding-inline: var(--space-1);
  border-radius: var(--radius-full);
  background: var(--color-accent);
  color: var(--color-text-inverse);
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
}

@media (max-width: 640px) {
  .search-dock__filter-label {
    display: none;
  }
}

/* ---------- Assistant chat ---------- */

/* App layout (<body data-app-shell>): navbar and chat fill the viewport (no
   page footer) and the page does not scroll; the history list and the
   conversation scroll on their own. The
   chat column is centered on the page: on wide screens the scroll area keeps
   the history's width free on its right. */
body[data-app-shell] {
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

body[data-app-shell] .site-main {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-layout {
  --chat-history-width: calc(var(--sidebar-width) + 2 * var(--gutter));
  --chat-pad-right: calc(var(--chat-history-width) + var(--gutter));
  display: grid;
  grid-template-columns: var(--chat-history-width) minmax(0, 1fr);
  flex: 1;
  min-height: 0;
}

/* With the preview panel open, it takes the right column; the chat is centered
   in the space between history and preview. */
.chat-layout[data-preview-open] {
  --chat-pad-right: var(--gutter);
  grid-template-columns: var(--chat-history-width) minmax(0, 1fr) var(--chat-preview-width);
}

.chat-layout {
  --chat-preview-width: clamp(26rem, 40vw, 56rem);
}

.chat-layout__history {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  min-height: 0;
  padding: var(--space-6) var(--gutter) var(--space-4);
  border-right: var(--border);
  background: var(--color-bg-subtle);
}

/* Drag handle on the history's right border (shown by chat.js). */
.chat-resizer {
  position: absolute;
  top: 0;
  right: -0.3125rem;
  bottom: 0;
  z-index: 1;
  width: 0.625rem;
  cursor: col-resize;
  touch-action: none;
}

.chat-resizer--start {
  right: auto;
  left: -0.3125rem;
}

.chat-resizer::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 50%;
  width: 2px;
  transform: translateX(-50%);
  background: transparent;
  transition: background var(--duration-fast);
}

.chat-resizer:hover::after,
.chat-resizer[data-dragging]::after {
  background: var(--color-accent);
}

.chat-resizer:focus-visible {
  outline: none;
}

.chat-resizer:focus-visible::after {
  background: var(--color-accent);
  box-shadow: var(--focus-ring);
}

/* No text selection and a steady cursor while dragging. */
html[data-resizing],
html[data-resizing] * {
  cursor: col-resize !important;
  user-select: none;
}

.chat-layout__history > .chat-history {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.chat-layout__main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.chat-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--space-8) var(--chat-pad-right) var(--space-4) var(--gutter);
}

.chat-dock {
  padding: 0 var(--chat-pad-right) 0 var(--gutter);
  border-top: var(--border);
}

.chat-column {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  width: 100%;
  max-width: var(--container-medium);
  margin-inline: auto;
}

.chat-legal {
  display: grid;
  gap: var(--space-1);
  padding-top: var(--space-3);
  border-top: var(--border);
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
}

.chat-legal__links {
  display: flex;
  gap: var(--space-4);
  padding: 0;
  list-style: none;
}

.chat-legal__links a {
  color: var(--color-text-muted);
  text-decoration: none;
}

.chat-legal__links a:hover {
  color: var(--color-text);
  text-decoration: underline;
}

/* Preview of a source or provision (an iframe of the page with ?vorschau=1). */
.source-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-left: var(--border);
  background: var(--color-bg);
}

.source-panel[hidden] {
  display: none;
}

.source-panel__header {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  min-height: var(--control-height-lg);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4);
  border-bottom: var(--border);
  background: var(--color-bg-subtle);
}

.source-panel__title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

.source-panel__body {
  position: relative;
  display: flex;
  flex: 1;
  min-height: 0;
}

.source-panel__frame {
  flex: 1;
  width: 100%;
  min-height: 0;
  border: 0;
  background: var(--color-bg);
}

/* Placeholder lines over the frame while the page loads (shimmer in motion.css). */
.source-panel__skeleton {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: none;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-6) var(--space-6);
  background: var(--color-bg);
}

.source-panel[data-loading] .source-panel__skeleton {
  display: flex;
}

.skeleton {
  display: block;
  height: 0.875rem;
  border-radius: var(--radius-sm);
  background: var(--color-bg-muted);
}

.skeleton--title {
  width: 70%;
  height: 1.75rem;
  margin-bottom: var(--space-1);
}

.skeleton--meta {
  width: 40%;
  margin-bottom: var(--space-4);
}

.skeleton--block {
  height: 7rem;
  margin-bottom: var(--space-4);
  border-radius: var(--radius-lg);
}

.skeleton--line:nth-child(odd) {
  width: 96%;
}

.skeleton--short {
  width: 55%;
}

/* The iframe would swallow pointer events while a border is dragged. */
html[data-resizing] .source-panel__frame {
  pointer-events: none;
}

.norm-link {
  text-decoration-style: dotted;
  text-underline-offset: 0.2em;
}

/* Thinking effort in the history sidebar. */
.reasoning-picker {
  display: grid;
  gap: var(--space-1);
  margin: 0;
  padding: 0 0 var(--space-4);
  border: 0;
  border-bottom: var(--border);
}

.reasoning-picker__title {
  margin-bottom: var(--space-2);
  padding: 0;
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-subtle);
}

.reasoning-option {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-2);
  border: var(--border-width) solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--duration-fast), border-color var(--duration-fast);
}

.reasoning-option:hover {
  background: var(--color-bg-muted);
}

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

.reasoning-option:has(:focus-visible) {
  box-shadow: var(--focus-ring);
}

.reasoning-option__input {
  flex-shrink: 0;
  margin-top: 0.2rem;
  accent-color: var(--color-accent);
}

.reasoning-option__body {
  display: grid;
  flex: 1;
  min-width: 0;
  gap: 0.125rem;
}

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

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

/* Not in the plan: visible, but greyed out. */
.reasoning-option--locked {
  cursor: not-allowed;
  opacity: 0.55;
}

.reasoning-option--locked:hover {
  background: none;
}

.reasoning-option--locked .icon {
  margin-top: 0.15rem;
  color: var(--color-text-subtle);
}

.reasoning-picker__upgrade {
  justify-self: start;
  margin-top: var(--space-1);
  padding-left: var(--space-2);
  font-size: var(--text-xs);
}

.chat-history__header {
  display: grid;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

.chat-history__title {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-subtle);
}

.chat-history__new {
  justify-self: start;
}

.chat-history__search {
  margin-bottom: var(--space-3);
}

.chat-history__search .input {
  height: var(--control-height-sm);
  min-height: var(--control-height-sm);
  padding-block: 0;
}

.chat-history__list {
  display: grid;
  align-content: start;
  gap: var(--space-1);
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  margin: 0 calc(-1 * var(--space-1));
  padding: var(--space-1);
  list-style: none;
}

.chat-history__snippet {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.chat-history__snippet mark {
  background: var(--color-highlight);
  color: inherit;
}

.chat-history__item {
  position: relative;
}

/* The delete button sits on the entry's right; visible on hover and focus. */
.chat-history__delete {
  position: absolute;
  top: var(--space-1);
  right: var(--space-1);
  opacity: 0;
  transition: opacity var(--duration-fast);
}

.chat-history__item:hover .chat-history__delete,
.chat-history__item:focus-within .chat-history__delete {
  opacity: 1;
}

@media (hover: none) {
  .chat-history__delete {
    opacity: 1;
  }
}

.chat-history__delete .btn:hover {
  color: var(--color-danger);
}

.chat-history__link {
  display: grid;
  gap: 0.125rem;
  padding: var(--space-2) calc(var(--control-height-sm) + var(--space-2)) var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--color-text);
  font-size: var(--text-sm);
  text-decoration: none;
  transition: background var(--duration-fast), color var(--duration-fast);
}

.chat-history__link:hover {
  background: var(--color-bg-muted);
  color: var(--color-text);
}

.chat-history__link[aria-current="page"] {
  background: var(--color-accent-subtle);
  color: var(--color-accent);
}

.chat-history__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: var(--weight-medium);
}

.chat-history__date {
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
}

.chat-history__empty {
  font-size: var(--text-sm);
  color: var(--color-text-subtle);
}

.chat-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
}

.chat-header__title {
  font-size: var(--text-xl);
  overflow-wrap: anywhere;
}

.chat-context {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border: var(--border);
  border-radius: var(--radius-md);
  background: var(--color-bg-subtle);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* minmax(0, 1fr): long unbroken lines (progress labels) must not widen the column. */
.chat-thread {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--space-6);
  flex: 1;
  align-content: start;
}

.chat-message--user {
  justify-self: end;
  max-width: 85%;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-lg);
  background: var(--color-bg-muted);
}

.chat-message__question {
  white-space: pre-line;
  overflow-wrap: anywhere;
}

/* Edit button next to a question: on hover or focus (always on touch screens). */
.chat-message--user {
  position: relative;
}

.chat-message--user .chat-message__edit {
  position: absolute; /* beside the bubble; .btn sets position for its ripple */
  top: 50%;
  right: calc(100% + var(--space-1));
  translate: 0 -50%;
  opacity: 0;
  transition: opacity var(--duration-fast);
}

.chat-message--user:hover .chat-message__edit,
.chat-message__edit:focus-visible {
  opacity: 1;
}

@media (hover: none) {
  .chat-message__edit {
    opacity: 1;
  }
}

/* A question being edited: the field takes the full width. */
.chat-message--editing {
  width: 100%;
  max-width: 100%;
}

.chat-edit {
  display: grid;
  gap: var(--space-2);
}

.chat-edit__input {
  width: 100%;
  min-height: 4.5rem;
  max-height: 15rem;
  padding: var(--space-2);
  border: var(--border-width) solid var(--color-border-strong);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  font: inherit;
  line-height: var(--leading-normal);
  resize: vertical;
}

.chat-edit__input:focus {
  border-color: var(--color-accent);
  outline: none;
  box-shadow: var(--focus-ring);
}

.chat-edit__footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

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

.chat-edit__actions {
  display: flex;
  gap: var(--space-2);
}

.chat-message--assistant {
  display: grid;
  gap: var(--space-5);
  scroll-margin-top: var(--space-6);
}

.chat-message__label {
  margin-bottom: var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-subtle);
}

.chat-message .citation__title {
  white-space: normal;
}

.answer {
  display: grid;
  gap: var(--space-3);
  max-width: var(--measure);
  line-height: var(--leading-relaxed);
  overflow-wrap: anywhere;
}

.answer ul,
.answer ol {
  display: grid;
  gap: var(--space-2);
  padding-left: var(--space-6);
}

.answer__heading {
  font-weight: var(--weight-semibold);
  margin-top: var(--space-2);
}

.chat-live-steps {
  display: grid;
  gap: var(--space-1);
  padding: 0 0 0 var(--space-4);
  list-style: none;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* Planned research (ai/planning.py): the tasks, each with its agent's steps. */
.live-plan {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border: var(--border);
  border-radius: var(--radius-lg);
  background: var(--color-bg-subtle);
}

.live-plan__summary {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  list-style: none;
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
}

.live-plan__summary::-webkit-details-marker {
  display: none;
}

.live-plan__summary:hover {
  color: var(--color-text);
}

.live-plan[open] > .live-plan__summary .icon--chevron {
  transform: rotate(180deg);
}

/* All agents have finished (the writer is at work): the pulse stops. */
.live-plan[data-done] .thinking__pulse {
  background: var(--color-text-subtle);
}

.live-plan__tasks,
.research-plan__tasks {
  display: grid;
  gap: var(--space-3);
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: task;
}

.live-plan__task,
.research-plan__task {
  display: grid;
  gap: var(--space-1);
  counter-increment: task;
}

.live-plan__name,
.research-plan__title {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text);
}

.live-plan__name::before,
.research-plan__title::before {
  content: counter(task);
  display: inline-grid;
  place-items: center;
  flex-shrink: 0;
  width: 1.25rem;
  height: 1.25rem;
  border-radius: var(--radius-full);
  background: var(--color-bg-muted);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.live-plan__task[data-state="done"] .live-plan__name::before {
  content: "\2713"; /* check mark */
  background: var(--color-success-bg);
  color: var(--color-success);
}

.live-plan__task[data-state="failed"] .live-plan__name::before {
  content: "!";
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.research-plan__tasks {
  margin-top: var(--space-3);
}

.chat-live-steps:empty {
  display: none;
}

.chat-live-steps__item {
  display: flex;
  gap: var(--space-3);
}

.chat-live-steps__item::before {
  content: "";
  flex-shrink: 0;
  width: 0.375rem;
  height: 0.375rem;
  margin-top: 0.55em;
  border-radius: 50%;
  background: var(--color-success);
}

.chat-live-steps__count {
  margin-left: auto;
  color: var(--color-text-subtle);
  white-space: nowrap;
}

.chat-intro {
  display: grid;
  justify-items: center;
  gap: var(--space-3);
  padding: var(--space-12) var(--space-4) var(--space-8);
  text-align: center;
}

.chat-intro__icon {
  display: inline-grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  border-radius: var(--radius-lg);
  background: var(--color-accent-subtle);
  color: var(--color-accent);
}

.chat-intro__title {
  font-size: var(--text-2xl);
}

.chat-intro__text {
  max-width: 32rem;
  color: var(--color-text-muted);
}

.chat-intro__examples {
  display: grid;
  gap: var(--space-2);
  width: 100%;
  max-width: 36rem;
  margin-top: var(--space-4);
  padding: 0;
  list-style: none;
}

.chat-example {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border: var(--border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: var(--text-sm);
  text-align: left;
  cursor: pointer;
  transition: border-color var(--duration-fast), background var(--duration-fast);
}

.chat-example:hover {
  border-color: var(--color-accent-border);
  background: var(--color-accent-subtle);
}

.chat-example:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.chat-composer {
  display: grid;
  gap: var(--space-2);
  padding-block: var(--space-3) var(--space-4);
  background: var(--color-bg);
}

.chat-composer__box {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  padding: var(--space-2);
  border: var(--border-width) solid var(--color-border-strong);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
  transition: border-color var(--duration-fast), box-shadow var(--duration-fast);
}

.chat-composer__box:focus-within {
  border-color: var(--color-accent);
  box-shadow: var(--focus-ring);
}

.chat-composer__input {
  flex: 1;
  min-height: var(--control-height);
  max-height: 15rem;
  padding: var(--space-2);
  border: 0;
  background: transparent;
  font: inherit;
  line-height: var(--leading-normal);
  resize: none;
}

.chat-composer__input:focus {
  outline: none;
}

.chat-composer__input:disabled {
  cursor: not-allowed;
}

.chat-composer__hint {
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
}

@media (max-width: 1280px) {
  .chat-layout,
  .chat-layout[data-preview-open] {
    --chat-pad-right: var(--gutter);
    grid-template-columns: var(--chat-history-width) minmax(0, 1fr);
  }

  /* No room for a third column: the preview lies over the chat. */
  .source-panel {
    position: fixed;
    top: var(--navbar-height);
    right: 0;
    bottom: 0;
    z-index: var(--z-dropdown);
    width: min(40rem, 100%);
    box-shadow: var(--shadow-overlay);
  }

  .source-panel .chat-resizer {
    display: none;
  }
}

/* Small screens: an ordinary scrolling page, the history below the chat. */
@media (max-width: 900px) {
  body[data-app-shell] {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .chat-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .chat-resizer {
    display: none;
  }

  .chat-layout__history {
    order: 2;
    border-right: 0;
    border-top: var(--border);
  }

  .chat-history__list {
    max-height: 20rem;
  }

  .chat-scroll {
    overflow: visible;
    padding-bottom: 0;
  }

  .chat-dock {
    position: sticky;
    bottom: 0;
    background: var(--color-bg);
  }
}

@media (max-width: 40rem) {
  .chat-message--user {
    max-width: calc(100% - 2.5rem); /* room for the edit button beside it */
  }

  .chat-composer__hint {
    display: none;
  }
}

/* Component preview: history and chat side by side in the page flow. */
.chat-preview {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  gap: var(--space-10);
  align-items: start;
}

.chat-preview__history {
  display: grid;
  gap: var(--space-4);
}

@media (max-width: 900px) {
  .chat-preview {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* ---------- Statute provision ---------- */

.statute {
  max-width: var(--measure);
}

.statute__law {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.statute__title {
  display: grid;
  gap: var(--space-1);
  margin-top: var(--space-2);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-tight);
}

.statute__citation {
  font-size: var(--text-3xl);
}

.statute__heading {
  font-size: var(--text-xl);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
}

.statute__structure {
  margin-top: var(--space-3);
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
}

.statute__text {
  display: grid;
  gap: var(--space-3);
  margin-top: var(--space-8);
  line-height: var(--leading-relaxed);
  overflow-wrap: anywhere;
}

.statute__block--absatz {
  scroll-margin-top: calc(var(--navbar-offset) + var(--space-6));
}

.statute__block--absatz:not(:first-child) {
  margin-top: var(--space-2);
}

.statute__block--item {
  padding-left: var(--space-6);
}

/* The Absatz a citation link points to. */
.statute__block:target {
  margin-inline: calc(-1 * var(--space-3));
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-highlight);
}

.statute__notes {
  margin-top: var(--space-8);
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

.statute__notes summary {
  cursor: pointer;
  font-weight: var(--weight-medium);
  color: var(--color-text);
}

.statute__notes p {
  margin-top: var(--space-2);
  white-space: pre-line;
}

.statute__source {
  margin-top: var(--space-6);
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
}

.statute__actions {
  margin-top: var(--space-6);
}

.statute__pager {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  margin-top: var(--space-10);
}

.statute__pager-link {
  display: grid;
  gap: var(--space-1);
  padding: var(--space-3) var(--space-4);
  border: var(--border);
  border-radius: var(--radius-md);
  color: var(--color-text);
  text-decoration: none;
  transition: border-color var(--duration-fast), background var(--duration-fast);
}

.statute__pager-link:hover {
  border-color: var(--color-accent-border);
  background: var(--color-accent-subtle);
  color: var(--color-text);
}

.statute__pager-link--next {
  grid-column: 2;
  text-align: right;
}

.statute__pager-label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-weight: var(--weight-semibold);
}

.statute__pager-link--next .statute__pager-label {
  justify-content: flex-end;
}

.statute__pager-heading {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* ---------- Preview mode (?vorschau=1, inside the assistant's preview panel) ---------- */

html[data-embedded] {
  --navbar-offset: 0px;
  scroll-padding-top: var(--space-4);
}

html[data-embedded] .page {
  padding-block: var(--space-6) var(--space-10);
}

/* The link whose page the assistant's preview panel shows. */
.chat-layout .citation[data-preview-active] {
  border-color: var(--color-accent);
  background: var(--color-accent-subtle);
}

.norm-link[data-preview-active] {
  background: var(--color-accent-subtle);
  border-radius: var(--radius-sm);
}

/* ---------- Admin panel (pages/admin, components/admin.html) ---------- */

.admin-header {
  align-items: flex-end;
}

.admin-header__eyebrow {
  margin-bottom: var(--space-1);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-subtle);
}

.admin-tabs {
  display: inline-flex;
  gap: var(--space-1);
  padding: var(--space-1);
  border: var(--border);
  border-radius: var(--radius-lg);
  background: var(--color-bg-subtle);
}

.admin-tabs__link {
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text-muted);
  text-decoration: none;
  transition: background var(--duration-fast), color var(--duration-fast);
}

.admin-tabs__link:hover {
  color: var(--color-text);
}

.admin-tabs__link[aria-current="page"] {
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: var(--shadow-sm);
}

.admin-filter {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-3);
}

.admin-filter .field {
  min-width: 11rem;
}

.admin-create__summary {
  padding: var(--space-4) var(--space-6);
  font-weight: var(--weight-semibold);
  cursor: pointer;
}

.admin-create__form {
  padding: 0 var(--space-6) var(--space-6);
}

.admin-badges {
  display: inline-flex;
  flex-wrap: wrap;
  gap: var(--space-1);
}

.admin-badges:empty {
  display: none;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr));
  gap: var(--space-3);
  margin-bottom: 0;
}

.stat {
  padding: var(--space-4);
  border: var(--border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}

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

.stat__value {
  margin: var(--space-1) 0 0;
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
}

.data-table-wrap {
  overflow-x: auto;
}

.data-table-wrap:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.data-table th,
.data-table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: var(--border);
  text-align: left;
  vertical-align: top;
}

.data-table thead th {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  color: var(--color-text-muted);
  white-space: nowrap;
}

.data-table tbody th {
  font-weight: var(--weight-medium);
}

.data-table tfoot th,
.data-table tfoot td {
  border-bottom: 0;
  font-weight: var(--weight-semibold);
}

.data-table .data-table__num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.data-table__hint {
  margin-left: 2px;
  color: var(--color-warning);
  cursor: help;
}

.data-table__row--muted {
  color: var(--color-text-subtle);
}

.usage-user__row th,
.usage-user__row td {
  background: var(--color-bg-subtle);
}

.usage-user__detail {
  display: block;
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  color: var(--color-text-muted);
}

.usage-user__model th {
  padding-left: var(--space-6);
  font-weight: var(--weight-regular);
}

.usage-model {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
}

.usage-provider {
  font-size: var(--text-xs);
  color: var(--color-text-subtle);
}

/* ---------- Onboarding tour (components/onboarding.html, js/onboarding.js) ---------- */

/* A modal dialog covering the viewport. The spotlight's large shadow darkens
   everything except the highlighted element; without one (data-centered) the
   dialog itself is the overlay and the card sits in the middle. */
.tour {
  position: fixed;
  inset: 0;
  width: 100%;
  max-width: none;
  height: 100%;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  background: transparent;
  color: var(--color-text);
}

.tour::backdrop {
  background: transparent;
}

.tour[data-centered] {
  background: var(--color-overlay);
}

.tour__spotlight {
  position: fixed;
  border-radius: var(--radius-lg);
  box-shadow: 0 0 0 200vmax var(--color-overlay);
  pointer-events: none;
}

.tour__card {
  position: fixed;
  width: min(22rem, calc(100vw - 2 * var(--space-4)));
  padding: var(--space-5);
  border: var(--border);
  border-radius: var(--radius-xl);
  background: var(--color-surface);
  box-shadow: var(--shadow-overlay);
}

.tour[data-centered] .tour__card {
  inset: 0;
  height: fit-content;
  margin: auto;
}

.tour__progress {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--color-text-subtle);
}

.tour__title {
  margin-top: var(--space-1);
  font-size: var(--text-lg);
}

.tour__title:focus {
  outline: none;
}

.tour__text {
  margin-top: var(--space-2);
  font-size: var(--text-sm);
  line-height: var(--leading-relaxed);
  color: var(--color-text-muted);
}

.tour__dots {
  display: flex;
  gap: var(--space-1);
  margin: var(--space-4) 0 0;
  padding: 0;
  list-style: none;
}

.tour__dot {
  width: var(--space-2);
  height: var(--space-2);
  border-radius: var(--radius-full);
  background: var(--color-border-strong);
}

.tour__dot[data-current] {
  background: var(--color-accent);
}

.tour__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.tour__nav {
  display: flex;
  gap: var(--space-2);
  margin-left: auto;
}

/* Narrow screens: the card at the bottom, the element stays visible above it. */
@media (max-width: 40rem) {
  .tour__card,
  .tour[data-centered] .tour__card {
    inset: auto var(--space-4) var(--space-4);
    width: auto;
    margin: 0;
  }
}

/* ---------- Invoice (components/invoice.html) ---------- */

.invoice {
  display: grid;
  gap: var(--space-6);
  padding: var(--space-8);
  border: var(--border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}

.invoice__head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: var(--space-6);
}

.invoice__meta {
  display: grid;
  grid-template-columns: auto auto;
  gap: var(--space-1) var(--space-4);
  margin: 0;
  font-size: var(--text-sm);
}

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

.invoice__meta dd {
  margin: 0;
}

.invoice__label {
  margin-bottom: var(--space-1);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.invoice__title {
  font-size: var(--text-xl);
}

.invoice__notes {
  display: grid;
  gap: var(--space-2);
  font-size: var(--text-sm);
}

.invoice__foot {
  padding-top: var(--space-4);
  border-top: var(--border);
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

.invoice-toolbar {
  margin-bottom: var(--space-4);
}

@media print {
  .navbar,
  .footer,
  .skip-link,
  .invoice-toolbar {
    display: none;
  }

  .invoice {
    border: 0;
    padding: 0;
  }
}
