/*
 * The Board - shared components. Uses only the tokens from theme.css.
 * Sections: base, layout, buttons, containers, forms, data, overlays, widgets, utilities, motion,
 * and (last) the style guide page.
 */

/* ================================================================== Base */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--tb-bg);
  color: var(--tb-text);
  font-family: var(--tb-font);
  font-size: 1rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body.tb-modal-open {
  overflow: hidden;
}

h1, h2, h3, h4 {
  margin: 0 0 var(--tb-space-3);
  line-height: 1.2;
  font-weight: 800;
  letter-spacing: -0.01em;
}

p {
  margin: 0 0 var(--tb-space-3);
}

a {
  color: var(--tb-primary);
  text-underline-offset: 0.2em;
}

a:hover {
  color: var(--tb-primary-hover);
}

img,
svg {
  max-width: 100%;
}

hr {
  border: 0;
  border-top: 1px solid var(--tb-border);
  margin: var(--tb-space-5) 0;
}

code,
kbd {
  font-family: var(--tb-font-mono);
  font-size: 0.9em;
  background: var(--tb-surface-2);
  border-radius: 6px;
  padding: 0.1em 0.4em;
}

[hidden] {
  display: none !important;
}

::selection {
  background: var(--tb-primary);
  color: var(--tb-primary-contrast);
}

/* Stops iOS double-tap zoom on controls that are tapped repeatedly (steppers, swatches, buttons). */
button,
a,
select,
summary,
label,
[role="button"],
[role="radio"],
[role="spinbutton"],
[role="tab"],
.tb-btn,
.tb-swatch,
.tb-stepper,
.tb-stepper__btn,
.tb-tabs > * {
  touch-action: manipulation;
}

/* Keyboard focus: a clear ring everywhere, never removed without a replacement. */
:focus-visible {
  outline: 3px solid var(--tb-focus);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

/* ================================================================== Layout */

.tb-app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.tb-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--tb-space-2) var(--tb-space-4);
  min-height: var(--tb-header-height);
  padding: var(--tb-space-2) var(--tb-space-4);
  background: var(--tb-surface);
  border-bottom: 1px solid var(--tb-border);
  box-shadow: 0 1px 0 var(--tb-border), 0 6px 16px -12px rgba(0, 0, 0, 0.25);
}

.tb-brand {
  display: inline-flex;
  align-items: center;
  gap: var(--tb-space-2);
  min-height: var(--tb-target);
  color: var(--tb-text);
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  text-decoration: none;
}

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

.tb-brand img,
.tb-brand svg {
  width: 2.25rem;
  height: 2.25rem;
  flex: none;
}

.tb-nav {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  gap: var(--tb-space-1);
  min-width: 0;
}

.tb-nav ul {
  display: contents;
  list-style: none;
  margin: 0;
  padding: 0;
}

.tb-nav li {
  display: contents;
}

.tb-nav a {
  display: inline-flex;
  align-items: center;
  min-height: var(--tb-target);
  padding: 0 var(--tb-space-4);
  border-radius: 999px;
  color: var(--tb-text);
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s var(--tb-ease);
}

.tb-nav a:hover {
  background: var(--tb-surface-2);
  color: var(--tb-text);
}

.tb-nav a.is-active,
.tb-nav a[aria-current="page"] {
  background: var(--tb-primary);
  color: var(--tb-primary-contrast);
}

/* Right-hand header controls sit together at the end. */
.tb-theme-toggle {
  margin-inline-start: auto;
}

.tb-nav + .tb-theme-toggle {
  margin-inline-start: 0;
}

.tb-theme-toggle__icon {
  display: inline-flex;
  width: 1.4rem;
  height: 1.4rem;
}

.tb-theme-toggle__icon svg {
  width: 100%;
  height: 100%;
}

.tb-user-menu {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--tb-space-2);
}

.tb-user-menu form {
  margin: 0;
}

.tb-user-menu__name {
  font-weight: 700;
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Role switcher: a segmented control, only for people who hold more than one role. Each segment is a submit
   button, so it works without JavaScript and every segment is reachable with Tab. */
.tb-role-switch {
  display: flex;
  align-items: center;
  gap: var(--tb-space-2);
  min-width: 0;
  max-width: 100%;
}

.tb-role-switch__label {
  font-weight: 700;
  white-space: nowrap;
}

.tb-role-switch__group {
  display: inline-flex;
  min-width: 0;
  padding: 2px;
  border: 1.5px solid var(--tb-border-strong);
  border-radius: 999px;
  background: var(--tb-surface-2);
}

.tb-role-switch__option {
  min-width: 0;
  min-height: 2.25rem;
  padding: 0 var(--tb-space-3);
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--tb-text);
  font: inherit;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: background-color 0.15s var(--tb-ease);
}

.tb-role-switch__option:hover {
  background: var(--tb-surface);
}

.tb-role-switch__option.is-active,
.tb-role-switch__option[aria-pressed="true"] {
  background: var(--tb-primary);
  color: var(--tb-primary-contrast);
}

.tb-role-switch__option:focus-visible {
  outline: 3px solid var(--tb-focus);
  outline-offset: 1px;
}

/* With the role switcher the controls no longer fit beside the nav on a laptop, and the header would wrap
   mid-row. Use the two-row layout of narrow screens (brand and controls first, nav below) up to a wider
   breakpoint instead. */
@media (max-width: 100rem) {
  .tb-header:has(.tb-role-switch) .tb-brand {
    order: 1;
    margin-inline-end: auto;
  }

  .tb-header:has(.tb-role-switch) .tb-user-menu {
    order: 3;
  }

  .tb-header:has(.tb-role-switch) .tb-nav {
    order: 4;
    flex: 1 1 100%;
    overflow-x: auto;
    padding-bottom: var(--tb-space-1);
    scrollbar-width: thin;
  }
}

/* Click-to-open variant: <button aria-expanded aria-controls> or <details>/<summary>. */
.tb-user-menu__toggle,
.tb-user-menu > summary {
  display: inline-flex;
  align-items: center;
  gap: var(--tb-space-2);
  min-height: var(--tb-target);
  padding: 0 var(--tb-space-2) 0 var(--tb-space-1);
  border: 1.5px solid var(--tb-border);
  border-radius: 999px;
  background: var(--tb-surface);
  color: var(--tb-text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}

.tb-user-menu > summary::-webkit-details-marker {
  display: none;
}

.tb-user-menu__toggle:hover,
.tb-user-menu > summary:hover {
  background: var(--tb-surface-2);
}

details.tb-user-menu {
  display: block;
}

.tb-user-menu__panel {
  position: absolute;
  inset-inline-end: 0;
  top: calc(100% + var(--tb-space-2));
  z-index: 40;
  min-width: 14rem;
  display: flex;
  flex-direction: column;
  gap: var(--tb-space-2);
  padding: var(--tb-space-3);
  background: var(--tb-surface);
  border: 1px solid var(--tb-border);
  border-radius: var(--tb-radius);
  box-shadow: var(--tb-shadow);
}

.tb-main {
  flex: 1 1 auto;
  width: 100%;
  max-width: 72rem;
  margin: 0 auto;
  padding: var(--tb-space-5) var(--tb-space-4) var(--tb-space-6);
}

.tb-main--wide {
  max-width: none;
}

.tb-page-title {
  margin: 0 0 var(--tb-space-4);
  font-size: clamp(1.6rem, 1.2rem + 1.6vw, 2.25rem);
  font-weight: 800;
}

.tb-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--tb-space-3);
  margin-bottom: var(--tb-space-4);
}

.tb-toolbar > .tb-grow {
  flex: 1 1 auto;
}

.tb-stack {
  display: flex;
  flex-direction: column;
  gap: var(--tb-space-4);
}

.tb-stack--tight {
  gap: var(--tb-space-2);
}

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

/* Below laptop width the header would otherwise wrap mid-row: keep brand and controls on the first line
   and give the nav its own line. */
@media (max-width: 64rem) {
  .tb-header {
    padding-inline: var(--tb-space-3);
    gap: var(--tb-space-1) var(--tb-space-3);
  }

  /* Without JS: brand and controls stay on the first line, the nav drops to its own
     line and scrolls sideways when it does not fit. */
  .tb-brand {
    order: 1;
    margin-inline-end: auto;
  }

  .tb-theme-toggle {
    order: 2;
    margin-inline-start: 0;
  }

  .tb-user-menu {
    order: 3;
  }

  .tb-nav {
    order: 4;
    flex: 1 1 100%;
    overflow-x: auto;
    padding-bottom: var(--tb-space-1);
    scrollbar-width: thin;
  }

  .tb-user-menu__name,
  .tb-user-name {
    display: none;
  }

  /* Let the menu wrap instead of pushing the page sideways. */
  .tb-user-menu {
    flex-wrap: wrap;
    justify-content: flex-end;
    min-width: 0;
  }

  /* The group label drops out of sight, and the segments tighten so "Ouer | Administrateur" fits at 320px. */
  .tb-role-switch__label {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
  }

  .tb-role-switch__option {
    padding: 0 var(--tb-space-2);
    font-size: 0.9rem;
  }

  .tb-main {
    padding-inline: var(--tb-space-3);
  }
}

/* ================================================================== Buttons */

.tb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--tb-space-2);
  min-height: var(--tb-target);
  min-width: var(--tb-target);
  padding: 0 var(--tb-space-4);
  border: 1.5px solid var(--tb-border-strong);
  border-radius: 999px;
  background: var(--tb-surface);
  color: var(--tb-text);
  font: inherit;
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s var(--tb-ease), transform 0.1s var(--tb-ease),
    box-shadow 0.15s var(--tb-ease);
}

.tb-btn:hover {
  background: var(--tb-surface-2);
  color: var(--tb-text);
}

.tb-btn:active {
  transform: translateY(1px);
}

.tb-btn[disabled],
.tb-btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.tb-btn--primary {
  background: var(--tb-primary);
  border-color: var(--tb-primary);
  color: var(--tb-primary-contrast);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12);
}

.tb-btn--primary:hover {
  background: var(--tb-primary-hover);
  border-color: var(--tb-primary-hover);
  color: var(--tb-primary-contrast);
}

.tb-btn--danger {
  background: var(--tb-danger);
  border-color: var(--tb-danger);
  color: var(--tb-danger-contrast);
}

.tb-btn--danger:hover {
  background: var(--tb-danger);
  color: var(--tb-danger-contrast);
  filter: brightness(0.92);
}

.tb-btn--ghost {
  background: transparent;
  border-color: transparent;
}

.tb-btn--ghost:hover {
  background: var(--tb-surface-2);
}

.tb-btn--lg {
  min-height: 3.5rem;
  padding: 0 var(--tb-space-5);
  font-size: 1.15rem;
}

.tb-btn--sm {
  position: relative;
  min-height: 2.25rem;
  min-width: 2.25rem;
  padding: 0 var(--tb-space-3);
  font-size: 0.9rem;
}

/* Keep a 44px touch area even on the small variant. */
.tb-btn--sm::after {
  content: "";
  position: absolute;
  inset: -0.25rem;
}

.tb-btn--icon {
  padding: 0;
  width: var(--tb-target);
  border-radius: 50%;
  font-size: 1.25rem;
}

.tb-btn--icon.tb-btn--lg {
  width: 3.5rem;
}

.tb-btn--icon.tb-btn--sm {
  width: 2.25rem;
}

/* ================================================================== Containers */

.tb-card {
  background: var(--tb-surface);
  border: 1px solid var(--tb-border);
  border-radius: var(--tb-radius-lg);
  box-shadow: var(--tb-shadow);
  padding: var(--tb-space-5);
}

.tb-card__title {
  margin: 0 0 var(--tb-space-3);
  font-size: 1.2rem;
  font-weight: 800;
}

.tb-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--tb-space-2);
  padding: var(--tb-space-6) var(--tb-space-4);
  border: 2px dashed var(--tb-border);
  border-radius: var(--tb-radius-lg);
  color: var(--tb-text-muted);
  text-align: center;
}

.tb-empty > :last-child {
  margin-bottom: 0;
}

.tb-alert {
  --tb-alert-colour: var(--tb-info);
  display: flex;
  align-items: flex-start;
  gap: var(--tb-space-3);
  padding: var(--tb-space-3) var(--tb-space-4);
  border: 1px solid var(--tb-alert-colour);
  border-inline-start-width: 6px;
  border-radius: var(--tb-radius);
  background: color-mix(in srgb, var(--tb-alert-colour) 12%, var(--tb-surface));
  color: var(--tb-text);
}

.tb-alert::before {
  content: "i";
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  margin-top: 0.1rem;
  border-radius: 50%;
  background: var(--tb-alert-colour);
  color: var(--tb-surface);
  font-size: 0.9rem;
  font-weight: 800;
}

.tb-alert > :last-child {
  margin-bottom: 0;
}

.tb-alert--info {
  --tb-alert-colour: var(--tb-info);
}

.tb-alert--success {
  --tb-alert-colour: var(--tb-success);
}

.tb-alert--success::before {
  content: "\2713";
}

.tb-alert--warning {
  --tb-alert-colour: var(--tb-warning);
}

.tb-alert--warning::before {
  content: "!";
}

.tb-alert--danger {
  --tb-alert-colour: var(--tb-danger);
}

.tb-alert--danger::before {
  content: "\00D7";
  font-size: 1.1rem;
}

/* ================================================================== Forms */

.tb-field {
  display: flex;
  flex-direction: column;
  gap: var(--tb-space-1);
  margin-bottom: var(--tb-space-4);
}

.tb-label {
  font-weight: 700;
}

.tb-input,
.tb-select,
.tb-textarea {
  width: 100%;
  min-height: var(--tb-target);
  padding: var(--tb-space-2) var(--tb-space-3);
  border: 1.5px solid var(--tb-border-strong);
  border-radius: var(--tb-radius-sm);
  background: var(--tb-surface);
  color: var(--tb-text);
  font: inherit;
  transition: border-color 0.15s var(--tb-ease), box-shadow 0.15s var(--tb-ease);
}

.tb-input::placeholder,
.tb-textarea::placeholder {
  color: var(--tb-text-muted);
  opacity: 1;
}

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

.tb-input:focus,
.tb-select:focus,
.tb-textarea:focus {
  outline: none;
  border-color: var(--tb-focus);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--tb-focus) 35%, transparent);
}

.tb-input:disabled,
.tb-select:disabled,
.tb-textarea:disabled {
  background: var(--tb-surface-2);
  color: var(--tb-text-muted);
  cursor: not-allowed;
}

.tb-textarea {
  min-height: 6rem;
  resize: vertical;
}

.tb-select {
  appearance: none;
  padding-inline-end: 2.5rem;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 1.3rem) 50%, calc(100% - 0.95rem) 50%;
  background-size: 0.35rem 0.35rem, 0.35rem 0.35rem;
  background-repeat: no-repeat;
}

.tb-field__hint {
  margin: 0;
  color: var(--tb-text-muted);
  font-size: 0.9rem;
}

.tb-field__error {
  margin: 0;
  color: var(--tb-danger);
  font-size: 0.9rem;
  font-weight: 700;
}

.tb-field__error::before {
  content: "\26A0\00A0";
}

.tb-field__error:empty {
  display: none;
}

.tb-field.has-error .tb-input,
.tb-field.has-error .tb-select,
.tb-field.has-error .tb-textarea {
  border-color: var(--tb-danger);
  border-width: 2px;
}

.tb-field.has-error .tb-label {
  color: var(--tb-danger);
}

.tb-form-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--tb-space-3);
  margin-top: var(--tb-space-5);
}

input[type="checkbox"],
input[type="radio"] {
  width: 1.4rem;
  height: 1.4rem;
  accent-color: var(--tb-primary);
}

.tb-check {
  display: inline-flex;
  align-items: center;
  gap: var(--tb-space-2);
  min-height: var(--tb-target);
  font-weight: 600;
  cursor: pointer;
}

/* ================================================================== Data */

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

.tb-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--tb-surface);
}

.tb-table th,
.tb-table td {
  padding: var(--tb-space-3) var(--tb-space-4);
  text-align: start;
  vertical-align: middle;
  border-bottom: 1px solid var(--tb-border);
}

.tb-table th {
  background: var(--tb-surface-2);
  color: var(--tb-text-muted);
  font-size: 0.85rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

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

.tb-table tbody tr:hover {
  background: color-mix(in srgb, var(--tb-primary) 6%, var(--tb-surface));
}

.tb-badge {
  --tb-badge-colour: var(--tb-info);
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.15rem 0.7rem;
  border: 1px solid var(--tb-badge-colour);
  border-radius: 999px;
  background: color-mix(in srgb, var(--tb-badge-colour) 14%, var(--tb-surface));
  color: var(--tb-text);
  font-size: 0.85rem;
  font-weight: 700;
  line-height: 1.5;
  white-space: nowrap;
}

.tb-badge::before {
  content: "";
  width: 0.55em;
  height: 0.55em;
  border-radius: 50%;
  background: var(--tb-badge-colour);
}

.tb-badge--success {
  --tb-badge-colour: var(--tb-success);
}

.tb-badge--warning {
  --tb-badge-colour: var(--tb-warning);
}

.tb-badge--danger {
  --tb-badge-colour: var(--tb-danger);
}

.tb-badge--muted {
  --tb-badge-colour: var(--tb-text-muted);
}

.tb-avatar {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background: var(--tb-primary-soft);
  border: 2px solid var(--tb-surface);
  box-shadow: 0 0 0 1px var(--tb-border);
  font-size: 1.4rem;
  line-height: 1;
  overflow: hidden;
  text-align: center;
}

.tb-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tb-avatar--lg {
  width: 4rem;
  height: 4rem;
  font-size: 2.2rem;
}

.tb-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: var(--tb-space-1);
  padding: var(--tb-space-1);
  border-radius: 999px;
  background: var(--tb-surface-2);
  width: fit-content;
  max-width: 100%;
}

.tb-tabs > button,
.tb-tabs > a,
.tb-tabs [role="tab"] {
  display: inline-flex;
  align-items: center;
  min-height: var(--tb-target);
  padding: 0 var(--tb-space-4);
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--tb-text);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.tb-tabs > button:hover,
.tb-tabs > a:hover,
.tb-tabs [role="tab"]:hover {
  background: color-mix(in srgb, var(--tb-text) 8%, transparent);
  color: var(--tb-text);
}

.tb-tabs .is-active,
.tb-tabs [aria-selected="true"],
.tb-tabs [aria-current="page"] {
  background: var(--tb-surface);
  box-shadow: var(--tb-shadow);
  color: var(--tb-text);
}

/* ================================================================== Overlays */

.tb-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--tb-space-4);
  background: var(--tb-overlay);
  animation: tb-fade-in 0.15s var(--tb-ease);
}

.tb-modal__dialog {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 34rem;
  max-height: calc(100vh - 2 * var(--tb-space-4));
  max-height: calc(100dvh - 2 * var(--tb-space-4));
  overflow: auto;
  padding: var(--tb-space-5);
  background: var(--tb-surface);
  color: var(--tb-text);
  border: 1px solid var(--tb-border);
  border-radius: var(--tb-radius-lg);
  box-shadow: var(--tb-shadow);
  animation: tb-pop-in 0.2s var(--tb-ease);
}

.tb-modal__dialog:focus {
  outline: none;
}

.tb-modal__title {
  margin: 0 0 var(--tb-space-3);
  font-size: 1.35rem;
}

.tb-modal__body {
  flex: 1 1 auto;
}

.tb-modal__body > :last-child {
  margin-bottom: 0;
}

.tb-modal__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--tb-space-3);
  margin-top: var(--tb-space-5);
}

.tb-toast-host {
  position: fixed;
  inset-inline: var(--tb-space-3);
  bottom: var(--tb-space-3);
  z-index: 120;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--tb-space-2);
  pointer-events: none;
}

.tb-toast {
  --tb-toast-colour: var(--tb-info);
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--tb-space-3);
  width: 100%;
  max-width: 28rem;
  padding: var(--tb-space-2) var(--tb-space-2) var(--tb-space-2) var(--tb-space-4);
  border: 1px solid var(--tb-border);
  border-inline-start: 6px solid var(--tb-toast-colour);
  border-radius: var(--tb-radius);
  background: var(--tb-surface);
  color: var(--tb-text);
  box-shadow: var(--tb-shadow);
  font-weight: 600;
  animation: tb-toast-in 0.25s var(--tb-ease);
}

.tb-toast.is-leaving {
  animation: tb-toast-out 0.2s var(--tb-ease) forwards;
}

.tb-toast__icon {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--tb-toast-colour);
  color: var(--tb-surface);
  font-size: 0.9rem;
  font-weight: 800;
}

.tb-toast__message {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}

.tb-toast--success {
  --tb-toast-colour: var(--tb-success);
}

.tb-toast--warning {
  --tb-toast-colour: var(--tb-warning);
}

.tb-toast--error {
  --tb-toast-colour: var(--tb-danger);
}

@media (min-width: 48rem) {
  .tb-toast-host {
    inset-inline-start: auto;
    inset-inline-end: var(--tb-space-4);
    bottom: var(--tb-space-4);
    align-items: flex-end;
  }
}

/* A tooltip bubble you place yourself (position it relative to its trigger). */
.tb-tooltip {
  position: absolute;
  z-index: 60;
  max-width: 18rem;
  padding: var(--tb-space-2) var(--tb-space-3);
  border-radius: var(--tb-radius-sm);
  background: var(--tb-text);
  color: var(--tb-bg);
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.35;
  box-shadow: var(--tb-shadow);
  pointer-events: none;
}

/* CSS-only tooltip: <button data-tb-tooltip="Text">. Shown on hover and keyboard focus. */
[data-tb-tooltip] {
  position: relative;
}

[data-tb-tooltip]::after {
  content: attr(data-tb-tooltip);
  position: absolute;
  inset-inline-start: 50%;
  bottom: calc(100% + 0.5rem);
  z-index: 60;
  width: max-content;
  max-width: 16rem;
  padding: var(--tb-space-2) var(--tb-space-3);
  border-radius: var(--tb-radius-sm);
  background: var(--tb-text);
  color: var(--tb-bg);
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.35;
  text-align: center;
  white-space: normal;
  box-shadow: var(--tb-shadow);
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s var(--tb-ease);
}

[data-tb-tooltip]:hover::after,
[data-tb-tooltip]:focus-visible::after {
  opacity: 1;
}

@keyframes tb-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes tb-pop-in {
  from { opacity: 0; transform: translateY(0.75rem) scale(0.97); }
  to { opacity: 1; transform: none; }
}

@keyframes tb-toast-in {
  from { opacity: 0; transform: translateY(1rem); }
  to { opacity: 1; transform: none; }
}

@keyframes tb-toast-out {
  to { opacity: 0; transform: translateY(0.5rem); }
}

/* ================================================================== Widgets */

.tb-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: var(--tb-space-2);
}

.tb-swatches__group {
  display: contents;
}

.tb-swatch {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: var(--tb-target);
  height: var(--tb-target);
  padding: 0;
  border: 2px solid var(--tb-surface);
  border-radius: 50%;
  background: var(--tb-surface-2);
  box-shadow: 0 0 0 1px var(--tb-border-strong);
  cursor: pointer;
  font: inherit;
  font-size: 1.2rem;
  font-weight: 800;
  transition: transform 0.12s var(--tb-ease), box-shadow 0.12s var(--tb-ease);
}

.tb-swatch:hover {
  transform: scale(1.08);
}

.tb-swatch.is-selected {
  box-shadow: 0 0 0 3px var(--tb-text);
}

/* The tick takes the swatch's own text colour (set inline by the picker), so it is always readable. */
.tb-swatch.is-selected::after {
  content: "\2713";
  color: inherit;
}

.tb-swatch--custom {
  background: conic-gradient(var(--tb-danger), var(--tb-warning), var(--tb-success), var(--tb-info), var(--tb-primary), var(--tb-danger));
  color: var(--tb-text);
}

.tb-swatch--custom:focus-within {
  outline: 3px solid var(--tb-focus);
  outline-offset: 2px;
}

.tb-swatch--custom input[type="color"] {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  opacity: 0;
  cursor: pointer;
}

.tb-swatch--custom:not(.is-selected)::after {
  content: "+";
  display: inline-grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background: var(--tb-surface);
  color: var(--tb-text);
  font-size: 1.1rem;
  line-height: 1;
}

.tb-stepper {
  display: inline-flex;
  align-items: center;
  gap: var(--tb-space-2);
  padding: var(--tb-space-1);
  border: 1.5px solid var(--tb-border);
  border-radius: 999px;
  background: var(--tb-surface);
}

.tb-stepper__btn {
  display: inline-grid;
  place-items: center;
  width: 3.25rem;
  height: 3.25rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--tb-primary-soft);
  color: var(--tb-text);
  font: inherit;
  font-size: 1.75rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 0.15s var(--tb-ease), transform 0.1s var(--tb-ease);
}

.tb-stepper__btn:hover:not(:disabled) {
  background: var(--tb-primary);
  color: var(--tb-primary-contrast);
}

.tb-stepper__btn:active:not(:disabled) {
  transform: scale(0.94);
}

.tb-stepper__btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.tb-stepper__value {
  min-width: 5rem;
  padding: var(--tb-space-1) var(--tb-space-2);
  border-radius: var(--tb-radius-sm);
  font-size: 1.3rem;
  font-weight: 800;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.tb-spinner {
  display: inline-block;
  width: 1.75rem;
  height: 1.75rem;
  border: 3px solid var(--tb-border);
  border-top-color: var(--tb-primary);
  border-radius: 50%;
  animation: tb-spin 0.8s linear infinite;
  vertical-align: middle;
}

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

/* ================================================================== Utilities */

.tb-visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

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

/* ================================================================== Motion */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }

  /* A spinner that does not move says nothing, so it keeps turning, slowly. */
  .tb-spinner {
    animation: tb-spin 2.4s linear infinite !important;
  }

  .tb-btn:active,
  .tb-swatch:hover,
  .tb-stepper__btn:active:not(:disabled) {
    transform: none;
  }
}

/* ================================================================== Style guide page (/styleguide, dev only) */

.tb-sg-section {
  margin-bottom: var(--tb-space-6);
}

.tb-sg-section > h2 {
  font-size: 1.5rem;
  padding-bottom: var(--tb-space-2);
  border-bottom: 2px solid var(--tb-border);
}

.tb-sg-grid {
  display: grid;
  gap: var(--tb-space-3);
  grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
}

.tb-sg-token {
  overflow: hidden;
  border: 1px solid var(--tb-border);
  border-radius: var(--tb-radius);
  background: var(--tb-surface);
  font-size: 0.85rem;
}

.tb-sg-token__chip {
  display: block;
  height: 3.5rem;
  background:
    linear-gradient(var(--sg-c, transparent), var(--sg-c, transparent)),
    repeating-conic-gradient(var(--tb-surface-2) 0% 25%, var(--tb-surface) 0% 50%) 0 0 / 14px 14px;
  border-bottom: 1px solid var(--tb-border);
}

.tb-sg-token__chip--stripe {
  background: repeating-linear-gradient(45deg, var(--sg-a) 0 6px, var(--sg-b) 6px 12px);
}

.tb-sg-token__name {
  display: block;
  padding: var(--tb-space-2) var(--tb-space-3) 0;
  font-family: var(--tb-font-mono);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.tb-sg-token__use {
  display: block;
  padding: 0 var(--tb-space-3) var(--tb-space-2);
  color: var(--tb-text-muted);
}

.tb-sg-demo {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--tb-space-3);
  margin-bottom: var(--tb-space-4);
}

.tb-sg-palette {
  display: grid;
  gap: var(--tb-space-2);
  grid-template-columns: repeat(auto-fill, minmax(8.5rem, 1fr));
}

.tb-sg-chip {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: var(--tb-space-3);
  border-radius: var(--tb-radius);
  box-shadow: 0 0 0 1px var(--tb-border);
  font-weight: 800;
}

.tb-sg-chip small {
  font-family: var(--tb-font-mono);
  font-weight: 600;
  opacity: 0.9;
}

.tb-sg-out {
  min-height: 1.5rem;
  color: var(--tb-text-muted);
  font-family: var(--tb-font-mono);
  font-size: 0.9rem;
}

/* Mock week strip: the same shading rules the schedule grid uses. */
.tb-sg-week {
  display: grid;
  grid-template-columns: repeat(7, minmax(5.5rem, 1fr));
  gap: 0;
  overflow-x: auto;
  border: 1px solid var(--tb-grid-line-strong);
  border-radius: var(--tb-radius);
  background: var(--tb-surface);
}

.tb-sg-day {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-inline-start: 1px solid var(--tb-grid-line-strong);
}

.tb-sg-day:first-child {
  border-inline-start: 0;
}

.tb-sg-day__head {
  padding: var(--tb-space-2);
  border-bottom: 1px solid var(--tb-grid-line-strong);
  text-align: center;
  font-size: 0.85rem;
  line-height: 1.25;
}

.tb-sg-day__head strong {
  display: block;
  font-size: 1rem;
}

.tb-sg-day__head small {
  display: block;
  color: var(--tb-text-muted);
}

.tb-sg-seg {
  position: relative;
  display: grid;
  place-items: center;
  padding: var(--tb-space-1);
  border-bottom: 1px solid var(--tb-grid-line);
  color: var(--tb-text);
  font-size: 0.8rem;
  font-weight: 600;
  text-align: center;
}

.tb-sg-seg--school {
  min-height: 4.5rem;
  background: var(--tb-slot-school);
}

.tb-sg-seg--break {
  min-height: 2.25rem;
  background: repeating-linear-gradient(45deg, var(--tb-slot-break) 0 6px, var(--tb-slot-break-stripe) 6px 12px);
}

.tb-sg-seg--outside {
  min-height: 2.5rem;
  background: repeating-linear-gradient(-45deg, var(--tb-slot-outside) 0 5px, var(--tb-slot-outside-stripe) 5px 7px);
}

/* Whole-day tints are overlays so the area shading stays visible underneath. */
.tb-sg-day.is-holiday::after,
.tb-sg-day.is-out-of-term::after,
.tb-sg-day.is-today::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.tb-sg-day.is-holiday::after {
  background: var(--tb-day-holiday);
}

.tb-sg-day.is-out-of-term::after {
  background: var(--tb-day-out-of-term);
}

.tb-sg-day.is-today::after {
  background: var(--tb-today);
  box-shadow: inset 0 0 0 2px var(--tb-primary);
}

.tb-sg-block {
  display: grid;
  place-items: center;
  min-height: 3.5rem;
  margin: var(--tb-space-1);
  border-radius: var(--tb-radius-sm);
  font-size: 0.8rem;
  font-weight: 800;
}

.tb-sg-progress {
  height: 0.6rem;
  border-radius: 999px;
  background: var(--tb-surface-2);
  overflow: hidden;
}

.tb-sg-progress > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--tb-primary);
}

.tb-sg-legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--tb-space-3);
  margin-top: var(--tb-space-3);
  font-size: 0.9rem;
}

.tb-sg-state {
  display: inline-flex;
  align-items: center;
  gap: var(--tb-space-1);
  font-weight: 800;
}

.tb-sg-state--over {
  color: var(--tb-over);
}

.tb-sg-state--remaining {
  color: var(--tb-remaining);
}

.tb-sg-state--done {
  color: var(--tb-done);
}

.tb-sg-seg--fill {
  flex: 1 1 auto;
  min-height: 15rem;
}

.tb-sg-block {
  justify-self: stretch;
  align-self: stretch;
}

.tb-sg-type-xl {
  margin: 0;
  font-size: 2.25rem;
  font-weight: 800;
}

.tb-sg-type-lg {
  font-size: 1.35rem;
  font-weight: 700;
}

.tb-sg-space {
  display: inline-block;
  background: var(--tb-primary);
  border-radius: 3px;
}

.tb-sg-space--1 { width: var(--tb-space-1); height: var(--tb-space-1); }
.tb-sg-space--2 { width: var(--tb-space-2); height: var(--tb-space-2); }
.tb-sg-space--3 { width: var(--tb-space-3); height: var(--tb-space-3); }
.tb-sg-space--4 { width: var(--tb-space-4); height: var(--tb-space-4); }
.tb-sg-space--5 { width: var(--tb-space-5); height: var(--tb-space-5); }
.tb-sg-space--6 { width: var(--tb-space-6); height: var(--tb-space-6); }

.tb-sg-radii {
  margin-top: var(--tb-space-4);
}

.tb-sg-radius-sm {
  border-radius: var(--tb-radius-sm);
}

.tb-sg-radius {
  border-radius: var(--tb-radius);
}

.tb-sg-demo--spaced {
  margin-top: var(--tb-space-4);
}

.tb-sg-tooltip-static {
  position: static;
  display: inline-block;
}

/* ------------------------------------------------------------------ Layout helpers used on every page */

/* Skip link: hidden until it gets keyboard focus. */
.tb-skip-link {
  position: absolute;
  left: var(--tb-space-3);
  top: var(--tb-space-3);
  z-index: 1000;
  padding: var(--tb-space-2) var(--tb-space-4);
  border-radius: var(--tb-radius);
  background: var(--tb-primary);
  color: var(--tb-primary-contrast);
  transform: translateY(-300%);
}

.tb-skip-link:focus {
  transform: none;
  outline: 3px solid var(--tb-focus);
  outline-offset: 2px;
}

.tb-user-name {
  max-width: 14ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 600px) {
  .tb-user-name {
    display: none;
  }
}

/* ------------------------------------------------------------------ Footer (every page) */

.tb-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--tb-space-4);
  padding: var(--tb-space-4) var(--tb-space-4) var(--tb-space-5);
  font-size: 0.875rem;
}

.tb-footer a {
  color: var(--tb-text-muted);
}

.tb-footer a:hover {
  color: var(--tb-text);
}
