/**
 * Kit Steward — app chrome on the WB Design System (0.9.2).
 *
 * Same visual language as Business Developer and the assistant, the other DS
 * consumers: page = background-default; raised chrome = surface-*; hairlines
 * only where they separate rows. Only DS tokens (--wb-*) for colour, type,
 * spacing, radius and elevation. This file never declares a --wb-* token.
 *
 * The --ks-* variables below are layout sizes the DS has no token for; each is
 * a `DS candidate` in docs/design-system.md. Patterns meant for reuse (the
 * future «Informes» section included): .page-header, .card, .table-wrap/.table,
 * .cell-actions, .chip, .notice, .field, .form-stack, .auth.
 */

:root {
  --ks-sidebar-width: 15rem; /* DS candidate: sidebar width */
  --ks-auth-width: 26rem; /* DS candidate: auth card width */
  --ks-qr-size: 13.75rem; /* DS candidate: QR / media frame size */
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--wb-color-background-default);
}

html {
  color-scheme: light;
}

html[data-theme='dark'] {
  color-scheme: dark;
}

body {
  font-family: var(--wb-font-family-body);
  font-size: var(--wb-font-size-body-md);
  line-height: var(--wb-line-height-body-md);
  font-weight: var(--wb-font-weight-body);
  color: var(--wb-color-text-default);
}

a {
  color: var(--wb-color-text-default);
  text-decoration: underline;
  text-underline-offset: var(--wb-spacing-inline-xs);
}

h1,
h2,
h3,
p,
ul,
ol,
dl,
dd,
fieldset {
  margin: 0;
}

code,
.mono {
  font-family: var(--wb-font-family-numbers);
  font-size: var(--wb-font-size-body-sm);
  overflow-wrap: anywhere;
}

/* Keyboard focus: the text colour keeps >= 3:1 on every surface (the DS yellow
   ring does not on light grays). Same choice as Business Developer. */
:where(a, button, input, select, textarea, summary, [tabindex]):focus-visible {
  outline: var(--wb-border-width-medium) solid var(--wb-color-text-default);
  outline-offset: var(--wb-border-width-medium);
}

.visually-hidden {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  inset-inline-start: var(--wb-spacing-inset-sm);
  inset-block-start: calc(var(--wb-spacing-inset-xl) * -2);
  z-index: 60;
  padding: var(--wb-spacing-inset-sm) var(--wb-spacing-inset-md);
  background: var(--wb-color-surface-default);
  border-radius: var(--wb-border-radius-component);
}

.skip-link:focus {
  inset-block-start: var(--wb-spacing-inset-sm);
}

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

/* —— App shell (data-wb-slot="app-shell") —— */
.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  min-height: 100dvh;
}

.app-shell__nav {
  display: flex;
  flex-direction: column;
  gap: var(--wb-spacing-stack-md);
  padding: var(--wb-spacing-inset-md);
  background: var(--wb-color-surface-default);
}

.app-shell__brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--wb-spacing-inline-sm);
}

.app-shell__brand-copy {
  display: flex;
  flex-direction: column;
  gap: var(--wb-spacing-stack-xs);
  min-width: 0;
}

.app-shell__brand-name {
  color: var(--wb-color-text-default);
  text-decoration: none;
}

.app-shell__menu-toggle {
  display: inline-flex;
}

.app-shell__nav-body {
  display: none;
  flex-direction: column;
  gap: var(--wb-spacing-stack-md);
}

.app-shell[data-nav='open'] .app-shell__nav-body {
  display: flex;
}

/* Without JS the menu stays open so the links are always reachable. */
html:not([data-js]) .app-shell__nav-body {
  display: flex;
}

html:not([data-js]) .app-shell__menu-toggle {
  display: none;
}

.app-shell__nav-group {
  display: flex;
  flex-direction: column;
  gap: var(--wb-spacing-stack-xs);
}

.app-shell__nav-label {
  padding-inline: var(--wb-spacing-inset-sm);
  color: var(--wb-color-text-secondary);
}

.app-shell__menu {
  display: flex;
  flex-direction: column;
  gap: var(--wb-spacing-stack-xs);
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--wb-spacing-inline-sm);
  min-block-size: var(--wb-button-size-min-height-sm);
  padding: var(--wb-spacing-inset-xs) var(--wb-spacing-inset-sm);
  border-radius: var(--wb-button-border-radius);
  border-inline-start: var(--wb-border-width-strong) solid transparent;
  color: var(--wb-color-text-default);
  text-decoration: none;
}

.nav-item:hover {
  background: var(--wb-button-color-background-ghost-hover);
}

.nav-item[aria-current='page'] {
  background: var(--wb-color-surface-subtle);
  border-inline-start-color: var(--wb-color-text-default);
  font-weight: var(--wb-font-weight-emphasis);
}

.app-shell__footer {
  display: flex;
  flex-direction: column;
  gap: var(--wb-spacing-stack-sm);
  padding-block-start: var(--wb-spacing-inset-md);
  border-block-start: var(--wb-border-width-default) solid var(--wb-color-border-on-surface-subtle);
}

.app-shell__user {
  display: flex;
  align-items: center;
  gap: var(--wb-spacing-inline-sm);
  min-width: 0;
  padding-inline: var(--wb-spacing-inset-sm);
  overflow-wrap: anywhere;
}

.app-shell__footer-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--wb-spacing-inline-xs);
}

.app-shell__footer-actions form {
  margin: 0;
}

.app-shell__main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: var(--wb-spacing-inset-md);
}

@media (min-width: 768px) {
  .app-shell {
    grid-template-columns: var(--ks-sidebar-width) minmax(0, 1fr);
    grid-template-rows: 1fr;
  }

  .app-shell__nav {
    position: sticky;
    inset-block-start: 0;
    block-size: 100dvh;
    overflow-y: auto;
  }

  .app-shell__menu-toggle {
    display: none;
  }

  .app-shell__nav-body {
    display: flex;
    flex: 1;
  }

  .app-shell__footer {
    margin-block-start: auto;
  }

  .app-shell__main {
    padding: var(--wb-spacing-inset-lg);
  }
}

@media (min-width: 1024px) {
  .app-shell__main {
    padding: var(--wb-spacing-inset-xl);
  }
}

/* —— Page —— */
.page {
  display: flex;
  flex-direction: column;
  gap: var(--wb-spacing-stack-lg);
  width: 100%;
  min-width: 0;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--wb-spacing-stack-sm) var(--wb-spacing-inline-md);
}

.page-header__title {
  display: flex;
  flex-direction: column;
  gap: var(--wb-spacing-stack-xs);
  min-width: 0;
}

.page-header__lede {
  color: var(--wb-color-text-secondary);
  max-inline-size: 70ch;
}

.page-header__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--wb-spacing-inline-sm);
}

/* Section index: in-page links to each card. */
.toc {
  display: flex;
  flex-wrap: wrap;
  gap: var(--wb-spacing-inline-xs);
  list-style: none;
  margin: 0;
  padding: 0;
}

.toc a {
  display: inline-flex;
  align-items: center;
  min-block-size: var(--wb-button-size-min-height-xs);
  padding: var(--wb-spacing-inset-xs) var(--wb-spacing-inset-sm);
  border-radius: var(--wb-border-radius-tag);
  background: var(--wb-color-surface-default);
  text-decoration: none;
  white-space: nowrap;
}

.toc a:hover {
  background: var(--wb-color-surface-subtle);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--wb-spacing-stack-lg);
  min-width: 0;
}

/* Two columns from 1024px: a narrow form beside a wide list. */
.split {
  display: grid;
  gap: var(--wb-spacing-inline-lg);
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
}

@media (min-width: 1024px) {
  .split {
    grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
  }
}

/* —— Card (DS candidate: wb-card) —— */
.card {
  display: flex;
  flex-direction: column;
  gap: var(--wb-spacing-stack-md);
  padding: var(--wb-spacing-inset-md) var(--wb-spacing-inset-lg) var(--wb-spacing-inset-lg);
  background: var(--wb-color-surface-default);
  border-radius: var(--wb-border-radius-card);
  box-shadow: var(--wb-elevation-sm);
  min-width: 0;
  scroll-margin-block-start: var(--wb-spacing-inset-lg);
}

.card__header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--wb-spacing-stack-xs) var(--wb-spacing-inline-sm);
}

.card__title-block {
  display: flex;
  flex-direction: column;
  gap: var(--wb-spacing-stack-xs);
  min-width: 0;
}

.card__title {
  display: flex;
  align-items: center;
  gap: var(--wb-spacing-inline-sm);
}

.card__lede {
  color: var(--wb-color-text-secondary);
  max-inline-size: 80ch;
}

/* A card whose body is a table: the table reaches the card edges. */
.card--table {
  padding: 0;
  gap: 0;
  overflow: hidden;
}

.card--table > .card__header {
  padding: var(--wb-spacing-inset-md) var(--wb-spacing-inset-lg);
}

/* —— Table (DS candidate: wb-table) —— */
.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th {
  padding: var(--wb-spacing-inset-sm) var(--wb-spacing-inset-md);
  text-align: start;
  white-space: nowrap;
  color: var(--wb-color-text-secondary);
  font-weight: var(--wb-font-weight-emphasis);
  background: var(--wb-color-surface-muted);
  border-block-end: var(--wb-border-width-default) solid var(--wb-color-border-on-surface-subtle);
}

.table td {
  padding: var(--wb-spacing-inset-sm) var(--wb-spacing-inset-md);
  vertical-align: middle;
  background: var(--wb-color-surface-subtle);
  border-block-end: var(--wb-border-width-default) solid var(--wb-color-border-on-surface-subtle);
}

.table tbody tr:last-child td {
  border-block-end: none;
}

.table th:first-child,
.table td:first-child {
  padding-inline-start: var(--wb-spacing-inset-lg);
}

.table th:last-child,
.table td:last-child {
  padding-inline-end: var(--wb-spacing-inset-lg);
}

.table .num {
  text-align: end;
  white-space: nowrap;
}

.table td.num {
  font-family: var(--wb-font-family-numbers);
  font-size: var(--wb-font-size-body-sm);
}

/* The first column names the row (a slug, a user): keep it on one line. */
.table td:first-child {
  white-space: nowrap;
}

/* Identifiers (paths, versions, programs) never break mid-word in a table:
   the table scrolls sideways instead. */
.table .mono,
.table code {
  white-space: nowrap;
  overflow-wrap: normal;
}

.table td.empty {
  color: var(--wb-color-text-secondary);
  background: var(--wb-color-surface-default);
  text-align: center;
  padding-block: var(--wb-spacing-inset-lg);
}

.table .cell-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--wb-spacing-inline-xs);
}

.table .cell-actions form {
  margin: 0;
}

/* —— Chip (DS candidate: wb-badge) —— */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--wb-spacing-inline-xs);
  padding: var(--wb-spacing-inset-xs) var(--wb-spacing-inset-sm);
  border-radius: var(--wb-border-radius-tag);
  background: var(--wb-color-surface-muted);
  color: var(--wb-color-text-default);
  font-size: var(--wb-font-size-body-sm);
  line-height: var(--wb-line-height-body-sm);
  white-space: nowrap;
}

.chip__count {
  font-family: var(--wb-font-family-numbers);
  color: var(--wb-color-text-secondary);
}

.chip__dot {
  display: inline-block;
  inline-size: var(--wb-spacing-inset-sm);
  block-size: var(--wb-spacing-inset-sm);
  border-radius: var(--wb-border-radius-pill);
  flex-shrink: 0;
  background: var(--wb-color-text-muted);
}

.chip--success .chip__dot {
  background: var(--wb-color-feedback-success);
}

.chip--warning .chip__dot {
  background: var(--wb-color-feedback-warning);
}

.chip--error .chip__dot {
  background: var(--wb-color-feedback-error);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--wb-spacing-inline-xs);
  list-style: none;
  margin: 0;
  padding: 0;
}

/* —— Notice (DS candidate: wb-alert) —— */
.notice {
  display: flex;
  align-items: flex-start;
  gap: var(--wb-spacing-inline-sm);
  padding: var(--wb-spacing-inset-md);
  background: var(--wb-color-surface-default);
  border-radius: var(--wb-border-radius-component);
  border-inline-start: var(--wb-border-width-strong) solid var(--wb-color-text-muted);
  box-shadow: var(--wb-elevation-sm);
}

.notice--error {
  border-inline-start-color: var(--wb-color-feedback-error);
}

.notice--warning {
  border-inline-start-color: var(--wb-color-feedback-warning);
}

.notice--success {
  border-inline-start-color: var(--wb-color-feedback-success);
}

.notice > wb-icon {
  flex-shrink: 0;
}

.notice__body {
  display: flex;
  flex-direction: column;
  gap: var(--wb-spacing-stack-xs);
  min-width: 0;
  overflow-wrap: anywhere;
}

.notice__title {
  font-weight: var(--wb-font-weight-emphasis);
}

/* A one-time secret: selectable at once, mono, on a subtle surface. */
.secret {
  display: block;
  padding: var(--wb-spacing-inset-sm) var(--wb-spacing-inset-md);
  border-radius: var(--wb-border-radius-component);
  background: var(--wb-color-surface-subtle);
  user-select: all;
}

/* —— Forms (DS candidate: wb-input, wb-label, wb-checkbox) —— */
.form-stack {
  display: flex;
  flex-direction: column;
  gap: var(--wb-spacing-stack-md);
  min-width: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--wb-spacing-stack-xs);
  min-width: 0;
}

.field__label {
  font-size: var(--wb-font-size-label-md);
  line-height: var(--wb-line-height-label-md);
  letter-spacing: var(--wb-letter-spacing-label);
  font-weight: var(--wb-font-weight-emphasis);
}

.field__hint {
  color: var(--wb-color-text-secondary);
  font-size: var(--wb-font-size-body-sm);
  line-height: var(--wb-line-height-body-sm);
}

.field__input {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-block-size: var(--wb-button-size-min-height-md);
  padding: var(--wb-spacing-inset-sm) var(--wb-spacing-inset-md);
  border: var(--wb-border-width-default) solid var(--wb-input-color-border-on-surface-default);
  border-radius: var(--wb-border-radius-component);
  background: var(--wb-input-color-background-on-surface-default);
  color: var(--wb-input-color-text-default);
  font-family: inherit;
  font-size: var(--wb-font-size-body-md);
  line-height: var(--wb-line-height-body-md);
}

.field__input::placeholder {
  color: var(--wb-input-color-text-placeholder);
}

.field__input:disabled {
  border-color: var(--wb-input-color-border-on-surface-disabled);
  background: var(--wb-input-color-background-on-surface-disabled);
  color: var(--wb-input-color-text-disabled);
  cursor: not-allowed;
}

/* Six-digit TOTP code: mono, large, centred. */
.field__input--code {
  min-block-size: var(--wb-button-size-min-height-lg);
  font-family: var(--wb-font-family-numbers);
  font-size: var(--wb-font-size-heading-md);
  line-height: var(--wb-line-height-heading-md);
  letter-spacing: var(--wb-spacing-inline-xs);
  text-align: center;
}

.field--check {
  flex-direction: row;
  align-items: center;
  gap: var(--wb-spacing-inline-sm);
}

.field--check input {
  margin: 0;
  inline-size: var(--wb-spacing-inset-md);
  block-size: var(--wb-spacing-inset-md);
  accent-color: var(--wb-color-text-default);
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--wb-spacing-inline-sm);
}

/* Full-width submit, as Bestard's auth gate: the host and its `trigger` part. */
.form-actions--block wb-button {
  display: block;
  flex: 1 1 100%;
  width: 100%;
}

.form-actions--block wb-button::part(trigger) {
  width: 100%;
  justify-content: center;
}

.form-actions form {
  margin: 0;
}

/* —— Auth gate (data-wb-slot="auth-gate") —— */
.auth {
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: var(--wb-spacing-inset-md);
}

.auth__theme {
  position: fixed;
  inset-block-start: var(--wb-spacing-inset-sm);
  inset-inline-end: var(--wb-spacing-inset-sm);
}

.auth__card {
  width: 100%;
  max-inline-size: var(--ks-auth-width);
}

.auth__brand {
  display: flex;
  align-items: center;
  gap: var(--wb-spacing-inline-sm);
  color: var(--wb-color-text-secondary);
}

.auth__qr {
  display: flex;
  justify-content: center;
}

/* The QR PNG is black on white: keep it on white in both themes so it scans. */
.auth__qr img {
  inline-size: var(--ks-qr-size);
  block-size: var(--ks-qr-size);
  padding: var(--wb-spacing-inset-xs);
  border-radius: var(--wb-border-radius-component);
  background: var(--wb-color-gray-50); /* primitive: fixed white in both themes */
  box-shadow: var(--wb-elevation-sm);
}

.auth__switch {
  display: flex;
  justify-content: center;
}

@media (min-width: 768px) {
  .auth__card {
    padding: var(--wb-spacing-inset-xl);
  }
}

/* The theme toggle needs JS: hide it when JS is off. */
html:not([data-js]) .theme-toggle {
  display: none;
}
