/* ==========================================================================
   components.css — Reusable UI components
   Cards, buttons, forms, tables, badges, avatars, progress, tabs, modals,
   toasts, empty states, stat cards, chart cards, dropdowns, pagination.
   ========================================================================== */

/* ---- Cards ------------------------------------------------------------------ */
.card {
  --bs-card-bg: var(--tf-surface);
  --bs-card-border-color: var(--tf-border);
  --bs-card-border-radius: var(--tf-radius);
  --bs-card-inner-border-radius: calc(var(--tf-radius) - 1px);
  --bs-card-cap-bg: transparent;
  --bs-card-cap-padding-x: var(--tf-card-pad);
  --bs-card-cap-padding-y: 1rem;
  --bs-card-spacer-x: var(--tf-card-pad);
  --bs-card-spacer-y: var(--tf-card-pad);
  box-shadow: var(--tf-shadow-sm);
  min-width: 0;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--tf-border);
}
.card-header-title { margin: 0; font-size: var(--tf-fs-md); font-weight: 650; }
.card-header-sub { margin: 0.125rem 0 0; font-size: var(--tf-fs-sm); color: var(--tf-text-muted); }
.card-footer {
  background: transparent;
  border-top: 1px solid var(--tf-border);
  padding: 0.875rem var(--tf-card-pad);
}
.card-flush > .card-body { padding: 0; }
.card-link { transition: border-color var(--tf-dur), box-shadow var(--tf-dur), transform var(--tf-dur); }
.card-link:hover { border-color: var(--tf-border-strong); box-shadow: var(--tf-shadow-md); }

/* ---- Buttons ------------------------------------------------------------------ */
.btn {
  --bs-btn-font-size: var(--tf-fs-base);
  --bs-btn-font-weight: 550;
  --bs-btn-padding-x: 0.9375rem;
  --bs-btn-padding-y: 0.4375rem;
  --bs-btn-border-radius: var(--tf-radius-sm);
  --bs-btn-focus-box-shadow: var(--tf-focus-ring);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  min-height: var(--tf-control-h);
  line-height: 1.25;
  white-space: nowrap;
  transition: background var(--tf-dur) var(--tf-ease), border-color var(--tf-dur) var(--tf-ease),
    color var(--tf-dur) var(--tf-ease), box-shadow var(--tf-dur) var(--tf-ease);
}
.btn .icon { width: 1.0625rem; height: 1.0625rem; }
.btn-sm { --bs-btn-padding-x: 0.625rem; --bs-btn-padding-y: 0.25rem; --bs-btn-font-size: var(--tf-fs-sm); min-height: 2rem; }
.btn-lg { --bs-btn-padding-x: 1.25rem; --bs-btn-font-size: var(--tf-fs-md); min-height: 2.75rem; }

.btn-primary {
  --bs-btn-color: var(--tf-on-primary);
  --bs-btn-bg: var(--tf-primary);
  --bs-btn-border-color: var(--tf-primary);
  --bs-btn-hover-color: var(--tf-on-primary);
  --bs-btn-hover-bg: var(--tf-primary-hover);
  --bs-btn-hover-border-color: var(--tf-primary-hover);
  --bs-btn-active-color: var(--tf-on-primary);
  --bs-btn-active-bg: var(--tf-primary-active);
  --bs-btn-active-border-color: var(--tf-primary-active);
  --bs-btn-disabled-bg: var(--tf-primary);
  --bs-btn-disabled-border-color: var(--tf-primary);
  box-shadow: 0 1px 2px rgba(var(--tf-primary-rgb), 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
.btn-outline-secondary,
.btn-secondary {
  --bs-btn-color: var(--tf-text);
  --bs-btn-bg: var(--tf-surface);
  --bs-btn-border-color: var(--tf-border-strong);
  --bs-btn-hover-color: var(--tf-text);
  --bs-btn-hover-bg: var(--tf-surface-3);
  --bs-btn-hover-border-color: var(--tf-border-strong);
  --bs-btn-active-color: var(--tf-text);
  --bs-btn-active-bg: var(--tf-surface-3);
  --bs-btn-active-border-color: var(--tf-border-strong);
  --bs-btn-disabled-color: var(--tf-text-muted);
  --bs-btn-disabled-bg: var(--tf-surface);
  --bs-btn-disabled-border-color: var(--tf-border);
  box-shadow: var(--tf-shadow-sm);
}
.btn-soft {
  --bs-btn-color: var(--tf-primary-text);
  --bs-btn-bg: var(--tf-primary-soft);
  --bs-btn-border-color: transparent;
  --bs-btn-hover-color: var(--tf-primary-text);
  --bs-btn-hover-bg: var(--tf-primary-soft-hover);
  --bs-btn-hover-border-color: transparent;
  --bs-btn-active-color: var(--tf-primary-text);
  --bs-btn-active-bg: var(--tf-primary-soft-hover);
  --bs-btn-active-border-color: transparent;
}
.btn-ghost {
  --bs-btn-color: var(--tf-text-muted);
  --bs-btn-bg: transparent;
  --bs-btn-border-color: transparent;
  --bs-btn-hover-color: var(--tf-text);
  --bs-btn-hover-bg: var(--tf-surface-3);
  --bs-btn-hover-border-color: transparent;
  --bs-btn-active-color: var(--tf-text);
  --bs-btn-active-bg: var(--tf-surface-3);
  --bs-btn-active-border-color: transparent;
}
.btn-danger {
  --bs-btn-color: #fff;
  --bs-btn-bg: #dc2626;
  --bs-btn-border-color: #dc2626;
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: #b91c1c;
  --bs-btn-hover-border-color: #b91c1c;
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: #991b1b;
  --bs-btn-active-border-color: #991b1b;
}
.btn-outline-danger {
  --bs-btn-color: var(--tf-danger);
  --bs-btn-border-color: rgba(var(--tf-danger-rgb), 0.45);
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: #dc2626;
  --bs-btn-hover-border-color: #dc2626;
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: #b91c1c;
  --bs-btn-active-border-color: #b91c1c;
}
.btn-icon { padding: 0; width: var(--tf-control-h); }
.btn-icon.btn-sm { width: 2rem; }
.btn-close { --bs-btn-close-focus-shadow: var(--tf-focus-ring); }
[data-bs-theme="dark"] .btn-close { filter: invert(1) grayscale(100%) brightness(200%); }

/* ---- Forms -------------------------------------------------------------------- */
.form-label { font-size: var(--tf-fs-sm); font-weight: 600; color: var(--tf-text); margin-bottom: 0.375rem; }
.form-label .req { color: var(--tf-danger); margin-left: 0.125rem; }
.form-text { font-size: var(--tf-fs-xs); color: var(--tf-text-muted); }
.form-control,
.form-select {
  --bs-body-bg: var(--tf-surface);
  min-height: var(--tf-control-h);
  padding: 0.4375rem 0.75rem;
  font-size: var(--tf-fs-base);
  color: var(--tf-text);
  background-color: var(--tf-surface);
  border: 1px solid var(--tf-border-strong);
  border-radius: var(--tf-radius-sm);
  transition: border-color var(--tf-dur), box-shadow var(--tf-dur);
}
.form-control::placeholder { color: var(--tf-text-subtle); opacity: 1; }
.form-control:hover:not(:disabled):not(:focus),
.form-select:hover:not(:disabled):not(:focus) { border-color: var(--tf-text-subtle); }
.form-control:focus,
.form-select:focus {
  background-color: var(--tf-surface);
  color: var(--tf-text);
  border-color: var(--tf-primary);
  box-shadow: var(--tf-focus-ring);
}
.form-control:disabled, .form-select:disabled { background: var(--tf-surface-2); color: var(--tf-text-muted); }
textarea.form-control { min-height: 5.5rem; }
.form-control-sm, .form-select-sm { min-height: 2rem; font-size: var(--tf-fs-sm); padding: 0.25rem 0.625rem; }
.form-select {
  --bs-form-select-bg-img: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%238c94ad' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}
[data-bs-theme="dark"] .form-select {
  --bs-form-select-bg-img: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23a4acc4' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}
.form-control.is-invalid, .form-select.is-invalid { border-color: var(--tf-danger); background-image: none; }
.form-control.is-invalid:focus, .form-select.is-invalid:focus { box-shadow: 0 0 0 3px rgba(var(--tf-danger-rgb), 0.25); }
.form-control.is-valid, .form-select.is-valid { border-color: var(--tf-success); background-image: none; }
.invalid-feedback { font-size: var(--tf-fs-xs); color: var(--tf-danger); margin-top: 0.375rem; }
.valid-feedback { font-size: var(--tf-fs-xs); color: var(--tf-success); }

.form-check-input {
  --bs-form-check-bg: var(--tf-surface);
  border: 1px solid var(--tf-border-strong);
  width: 1.0625rem;
  height: 1.0625rem;
  margin-top: 0.1875rem;
}
.form-check-input:checked { background-color: var(--tf-primary); border-color: var(--tf-primary); }
.form-check-input:focus { border-color: var(--tf-primary); box-shadow: var(--tf-focus-ring); }
.form-switch .form-check-input { width: 2.125rem; height: 1.25rem; margin-top: 0.125rem; }
.form-check-label { cursor: pointer; }

.input-group-text {
  background: var(--tf-surface-2);
  border-color: var(--tf-border-strong);
  color: var(--tf-text-muted);
}

/* Segmented control (view switchers, ranges) */
.segmented {
  display: inline-flex;
  padding: 0.1875rem;
  gap: 0.125rem;
  background: var(--tf-surface-3);
  border-radius: var(--tf-radius-sm);
}
.segmented button {
  min-height: 1.875rem;
  padding: 0.25rem 0.75rem;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--tf-text-muted);
  font-size: var(--tf-fs-sm);
  font-weight: 550;
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  transition: background var(--tf-dur), color var(--tf-dur);
}
.segmented button:hover { color: var(--tf-text); }
.segmented button[aria-pressed="true"] {
  background: var(--tf-surface);
  color: var(--tf-text);
  box-shadow: var(--tf-shadow-sm);
}

/* ---- Badges / status pills / priority --------------------------------------------- */
.badge {
  --bs-badge-font-size: var(--tf-fs-xs);
  --bs-badge-font-weight: 600;
  --bs-badge-padding-x: 0.5rem;
  --bs-badge-padding-y: 0.25rem;
  --bs-badge-border-radius: var(--tf-radius-pill);
  letter-spacing: 0.005em;
}
.pill {
  --pill-c: var(--tf-text-muted);
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.1875rem 0.625rem 0.1875rem 0.5rem;
  border-radius: var(--tf-radius-pill);
  font-size: var(--tf-fs-xs);
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  color: var(--pill-c);
  background: color-mix(in srgb, var(--pill-c) 13%, transparent);
}
.pill::before {
  content: "";
  width: 0.4375rem;
  height: 0.4375rem;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.pill-backlog { --pill-c: var(--tf-status-backlog); }
.pill-todo { --pill-c: var(--tf-status-todo); }
.pill-progress { --pill-c: var(--tf-status-progress); }
.pill-review { --pill-c: var(--tf-status-review); }
.pill-done { --pill-c: var(--tf-status-done); }
.pill-blocked { --pill-c: var(--tf-status-blocked); }
.pill-hold { --pill-c: var(--tf-status-hold); }
.pill-success { --pill-c: var(--tf-success); }
.pill-warning { --pill-c: var(--tf-warning); }
.pill-danger { --pill-c: var(--tf-danger); }
.pill-info { --pill-c: var(--tf-info); }
.pill-primary { --pill-c: var(--tf-primary-text); }
.pill-plain::before { display: none; }

.priority {
  --pr-c: var(--tf-priority-low);
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-size: var(--tf-fs-sm);
  font-weight: 550;
  color: var(--tf-text);
  white-space: nowrap;
}
.priority .icon { color: var(--pr-c); width: 0.9375rem; height: 0.9375rem; }
.priority-low { --pr-c: var(--tf-priority-low); }
.priority-medium { --pr-c: var(--tf-priority-medium); }
.priority-high { --pr-c: var(--tf-priority-high); }
.priority-urgent { --pr-c: var(--tf-priority-urgent); }

.tag {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 5px;
  background: var(--tf-surface-3);
  color: var(--tf-text-muted);
  font-size: var(--tf-fs-xs);
  font-weight: 550;
}

/* ---- Avatars ---------------------------------------------------------------------- */
.avatar {
  --av-size: 2.25rem;
  position: relative;
  display: inline-grid;
  place-items: center;
  flex: none;
  width: var(--av-size);
  height: var(--av-size);
  border-radius: 50%;
  background: var(--av-bg, var(--tf-primary-soft));
  color: var(--av-fg, var(--tf-primary-text));
  font-size: calc(var(--av-size) * 0.38);
  font-weight: 650;
  letter-spacing: 0.01em;
  line-height: 1;
  user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.avatar-xs { --av-size: 1.5rem; }
.avatar-sm { --av-size: 1.875rem; }
.avatar-lg { --av-size: 3rem; }
.avatar-xl { --av-size: 5rem; }
.avatar[data-tone="1"] { --av-bg: rgba(79, 70, 229, 0.14); --av-fg: var(--tf-chart-1); }
.avatar[data-tone="2"] { --av-bg: rgba(8, 145, 178, 0.14); --av-fg: var(--tf-chart-2); }
.avatar[data-tone="3"] { --av-bg: rgba(22, 163, 74, 0.14); --av-fg: var(--tf-chart-3); }
.avatar[data-tone="4"] { --av-bg: rgba(217, 119, 6, 0.16); --av-fg: var(--tf-chart-4); }
.avatar[data-tone="5"] { --av-bg: rgba(219, 39, 119, 0.14); --av-fg: var(--tf-chart-5); }
.avatar[data-tone="6"] { --av-bg: rgba(124, 58, 237, 0.14); --av-fg: var(--tf-chart-6); }
[data-bs-theme="dark"] .avatar[data-tone] { --av-bg: color-mix(in srgb, var(--av-fg) 20%, transparent); }
.avatar-status::after {
  content: "";
  position: absolute;
  right: 0;
  bottom: 0;
  width: 28%;
  height: 28%;
  border-radius: 50%;
  background: var(--tf-text-subtle);
  border: 2px solid var(--tf-surface);
  box-sizing: content-box;
}
.avatar-status[data-presence="online"]::after { background: var(--tf-success); }
.avatar-status[data-presence="away"]::after { background: var(--tf-warning); }

.avatar-group { display: inline-flex; align-items: center; padding-left: calc(var(--av-size, 1.875rem) * 0.28); }
.avatar-group .avatar { margin-left: calc(var(--av-size) * -0.28); box-shadow: 0 0 0 2px var(--tf-surface); }
.avatar-group .avatar-xs { font-size: 0.5rem; margin-left: calc(var(--av-size) * -0.16); }
.avatar-group .avatar-more { --av-bg: var(--tf-surface-3); --av-fg: var(--tf-text-muted); }

/* ---- Progress ----------------------------------------------------------------------- */
.progress {
  --bs-progress-height: 0.375rem;
  --bs-progress-bg: var(--tf-surface-3);
  --bs-progress-bar-bg: var(--tf-primary);
  --bs-progress-border-radius: var(--tf-radius-pill);
}
.progress-lg { --bs-progress-height: 0.625rem; }
.progress-bar { border-radius: var(--tf-radius-pill); transition: width 400ms var(--tf-ease); }
.progress-bar.bg-success { background: var(--tf-success) !important; }
.progress-bar.bg-warning { background: var(--tf-warning) !important; }
.progress-bar.bg-danger { background: var(--tf-danger) !important; }
.progress-label { display: flex; justify-content: space-between; margin-bottom: 0.375rem; font-size: var(--tf-fs-sm); color: var(--tf-text-muted); }
.progress-label strong { color: var(--tf-text); font-weight: 600; }

/* ---- Tables -------------------------------------------------------------------------- */
.table {
  --bs-table-bg: transparent;
  --bs-table-color: var(--tf-text);
  --bs-table-border-color: var(--tf-border);
  --bs-table-hover-bg: var(--tf-surface-2);
  --bs-table-hover-color: var(--tf-text);
  --bs-table-striped-bg: var(--tf-surface-2);
  margin-bottom: 0;
  font-size: var(--tf-fs-base);
}
.table > :not(caption) > * > * {
  padding: var(--tf-cell-py) var(--tf-cell-px);
  vertical-align: middle;
  border-bottom-color: var(--tf-border);
}
.table thead th {
  background: var(--tf-surface-2);
  color: var(--tf-text-muted);
  font-size: var(--tf-fs-xs);
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
  border-bottom: 1px solid var(--tf-border);
}
.table tbody tr:last-child > * { border-bottom: 0; }
.table-responsive { border-radius: inherit; }
.card > .table-responsive:first-child thead th:first-child { border-top-left-radius: calc(var(--tf-radius) - 1px); }
.card > .table-responsive:first-child thead th:last-child { border-top-right-radius: calc(var(--tf-radius) - 1px); }
.table .cell-main { font-weight: 600; color: var(--tf-text); }
.table .cell-sub { font-size: var(--tf-fs-xs); color: var(--tf-text-muted); }
.th-sort {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
}
.th-sort:hover { color: var(--tf-text); }
.th-sort .icon { width: 0.8125rem; height: 0.8125rem; opacity: 0.45; }
th[aria-sort="ascending"] .th-sort,
th[aria-sort="descending"] .th-sort { color: var(--tf-text); }
th[aria-sort="ascending"] .th-sort .icon,
th[aria-sort="descending"] .th-sort .icon { opacity: 1; color: var(--tf-primary-text); }

.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.625rem;
  padding: 0.875rem var(--tf-card-pad);
  border-bottom: 1px solid var(--tf-border);
}
.table-toolbar .search-field { flex: 1 1 14rem; max-width: 22rem; }
.table-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem var(--tf-card-pad);
  border-top: 1px solid var(--tf-border);
  font-size: var(--tf-fs-sm);
  color: var(--tf-text-muted);
}

/* ---- Pagination ------------------------------------------------------------------------ */
.pagination {
  --bs-pagination-padding-x: 0.625rem;
  --bs-pagination-padding-y: 0.3125rem;
  --bs-pagination-font-size: var(--tf-fs-sm);
  --bs-pagination-color: var(--tf-text-muted);
  --bs-pagination-bg: transparent;
  --bs-pagination-border-color: transparent;
  --bs-pagination-hover-color: var(--tf-text);
  --bs-pagination-hover-bg: var(--tf-surface-3);
  --bs-pagination-hover-border-color: transparent;
  --bs-pagination-focus-color: var(--tf-text);
  --bs-pagination-focus-bg: var(--tf-surface-3);
  --bs-pagination-focus-box-shadow: var(--tf-focus-ring);
  --bs-pagination-active-bg: var(--tf-primary);
  --bs-pagination-active-border-color: var(--tf-primary);
  --bs-pagination-active-color: var(--tf-on-primary);
  --bs-pagination-disabled-color: var(--tf-text-subtle);
  --bs-pagination-disabled-bg: transparent;
  --bs-pagination-disabled-border-color: transparent;
  --bs-pagination-border-radius: var(--tf-radius-sm);
  gap: 0.25rem;
  margin: 0;
}
.pagination .page-link { border-radius: var(--tf-radius-sm); min-width: 2rem; text-align: center; font-weight: 550; }

/* ---- Tabs / nav pills -------------------------------------------------------------------- */
.nav-tabs-tf {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.25rem;
  overflow-x: auto;
  border-bottom: 1px solid var(--tf-border);
  scrollbar-width: none;
}
.nav-tabs-tf::-webkit-scrollbar { display: none; }
.nav-tabs-tf .nav-link {
  position: relative;
  padding: 0.625rem 0.875rem;
  border: 0;
  border-radius: var(--tf-radius-sm) var(--tf-radius-sm) 0 0;
  background: transparent;
  color: var(--tf-text-muted);
  font-weight: 550;
  white-space: nowrap;
}
.nav-tabs-tf .nav-link:hover { color: var(--tf-text); text-decoration: none; }
.nav-tabs-tf .nav-link.active { color: var(--tf-primary-text); background: transparent; }
.nav-tabs-tf .nav-link.active::after {
  content: "";
  position: absolute;
  left: 0.5rem; right: 0.5rem; bottom: -1px;
  height: 2px;
  background: var(--tf-primary);
  border-radius: 2px 2px 0 0;
}

/* ---- Dropdowns --------------------------------------------------------------------------- */
.dropdown-menu {
  --bs-dropdown-bg: var(--tf-surface);
  --bs-dropdown-color: var(--tf-text);
  --bs-dropdown-border-color: var(--tf-border);
  --bs-dropdown-border-radius: var(--tf-radius);
  --bs-dropdown-link-color: var(--tf-text);
  --bs-dropdown-link-hover-color: var(--tf-text);
  --bs-dropdown-link-hover-bg: var(--tf-surface-3);
  --bs-dropdown-link-active-color: var(--tf-primary-text);
  --bs-dropdown-link-active-bg: var(--tf-primary-soft);
  --bs-dropdown-divider-bg: var(--tf-border);
  --bs-dropdown-item-padding-y: 0.4375rem;
  --bs-dropdown-item-padding-x: 0.75rem;
  --bs-dropdown-padding-y: 0.375rem;
  --bs-dropdown-font-size: var(--tf-fs-base);
  box-shadow: var(--tf-shadow-md);
}
.dropdown-item { display: flex; align-items: center; gap: 0.625rem; border-radius: 6px; margin-inline: 0.375rem; width: auto; }
.dropdown-item .icon { color: var(--tf-text-subtle); }
.dropdown-item.text-danger .icon { color: inherit; }
.dropdown-header { font-size: var(--tf-fs-xs); }

/* ---- Modals / offcanvas -------------------------------------------------------------------- */
.modal {
  --bs-modal-bg: var(--tf-surface);
  --bs-modal-border-color: var(--tf-border);
  --bs-modal-border-radius: var(--tf-radius-lg);
  --bs-modal-header-border-color: var(--tf-border);
  --bs-modal-footer-border-color: var(--tf-border);
  --bs-modal-box-shadow: var(--tf-shadow-md);
  --bs-modal-padding: 1.25rem;
}
.modal-title { font-size: var(--tf-fs-md); font-weight: 650; }
.modal-backdrop { --bs-backdrop-bg: #04060f; --bs-backdrop-opacity: 0.55; }
.modal-footer { gap: 0.5rem; }
.modal-footer > * { margin: 0; }
.offcanvas {
  --bs-offcanvas-bg: var(--tf-surface);
  --bs-offcanvas-border-color: var(--tf-border);
  --bs-offcanvas-color: var(--tf-text);
}
.confirm-icon {
  display: grid; place-items: center; width: 2.75rem; height: 2.75rem; border-radius: 50%;
  background: rgba(var(--tf-danger-rgb), 0.14); color: var(--tf-danger); flex: none;
}
.confirm-icon.is-primary { background: var(--tf-primary-soft); color: var(--tf-primary-text); }

/* ---- Toasts ---------------------------------------------------------------------------------- */
.toast-stack {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 2000;
  display: grid;
  gap: 0.625rem;
  width: min(22rem, calc(100vw - 2rem));
  pointer-events: none;
}
.tf-toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  background: var(--tf-surface);
  border: 1px solid var(--tf-border);
  border-left: 3px solid var(--toast-c, var(--tf-primary));
  border-radius: var(--tf-radius);
  box-shadow: var(--tf-shadow-md);
  animation: tf-toast-in 220ms var(--tf-ease);
}
.tf-toast.is-leaving { opacity: 0; transform: translateY(6px); transition: opacity 160ms, transform 160ms; }
.tf-toast .icon { color: var(--toast-c, var(--tf-primary)); margin-top: 0.0625rem; }
.tf-toast-title { font-weight: 600; line-height: 1.35; }
.tf-toast-msg { font-size: var(--tf-fs-sm); color: var(--tf-text-muted); margin-top: 0.125rem; }
.tf-toast-close { margin-left: auto; }
.tf-toast[data-type="success"] { --toast-c: var(--tf-success); }
.tf-toast[data-type="warning"] { --toast-c: var(--tf-warning); }
.tf-toast[data-type="danger"] { --toast-c: var(--tf-danger); }
.tf-toast[data-type="info"] { --toast-c: var(--tf-info); }
@keyframes tf-toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---- Empty state --------------------------------------------------------------------------------- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 3rem 1.5rem;
  gap: 0.25rem;
}
.empty-state-icon {
  display: grid; place-items: center;
  width: 3.5rem; height: 3.5rem; margin-bottom: 0.75rem;
  border-radius: 14px;
  background: var(--tf-primary-soft);
  color: var(--tf-primary-text);
}
.empty-state-icon .icon { width: 1.5rem; height: 1.5rem; }
.empty-state-title { font-size: var(--tf-fs-md); font-weight: 650; margin: 0; }
.empty-state-text { max-width: 24rem; margin: 0 0 1rem; color: var(--tf-text-muted); }

/* ---- Stat cards -------------------------------------------------------------------------------------- */
.stat-card .card-body { display: flex; flex-direction: column; gap: 0.75rem; }
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.stat-label { font-size: var(--tf-fs-sm); font-weight: 550; color: var(--tf-text-muted); }
.stat-icon {
  display: grid; place-items: center; width: 2.25rem; height: 2.25rem; border-radius: 9px; flex: none;
  background: color-mix(in srgb, var(--stat-c, var(--tf-primary)) 14%, transparent);
  color: var(--stat-c, var(--tf-primary-text));
}
.stat-value { font-size: var(--tf-fs-2xl); font-weight: 700; letter-spacing: -0.025em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-delta { display: inline-flex; align-items: center; gap: 0.25rem; font-size: var(--tf-fs-sm); font-weight: 600; }
.stat-delta.is-up { color: var(--tf-success); }
.stat-delta.is-down { color: var(--tf-danger); }
.stat-delta .stat-delta-note { font-weight: 450; color: var(--tf-text-muted); margin-left: 0.25rem; }
@media (max-width: 575.98px) {
  .stat-delta { flex-wrap: wrap; row-gap: 0; }
  .stat-delta .stat-delta-note { flex-basis: 100%; margin-left: 0; }
  .stat-value { font-size: var(--tf-fs-xl); }
}

/* ---- Chart card ----------------------------------------------------------------------------------------- */
.chart-box { position: relative; width: 100%; height: 16rem; }
.chart-box-sm { height: 11rem; }
.chart-box-lg { height: 20rem; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 0.375rem 1rem; margin-top: 1rem; font-size: var(--tf-fs-sm); color: var(--tf-text-muted); }
.chart-legend .swatch { display: inline-block; width: 0.625rem; height: 0.625rem; border-radius: 3px; margin-right: 0.4375rem; background: var(--sw); }

/* ---- Lists & key-value ------------------------------------------------------------------------------------ */
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-row {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem var(--tf-card-pad);
  border-bottom: 1px solid var(--tf-border);
}
.list-row:last-child { border-bottom: 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.625rem 1.25rem; margin: 0; }
.kv dt { font-weight: 500; color: var(--tf-text-muted); }
.kv dd { margin: 0; font-weight: 550; }

/* ---- Alerts --------------------------------------------------------------------------------------------------- */
.alert {
  --bs-alert-border-radius: var(--tf-radius);
  display: flex; gap: 0.75rem; align-items: flex-start;
  border: 1px solid var(--al-border, var(--tf-border));
  background: var(--al-bg, var(--tf-surface-2));
  color: var(--tf-text);
  padding: 0.875rem 1rem;
}
.alert .icon { margin-top: 0.0625rem; color: var(--al-c, var(--tf-primary-text)); }
.alert-info { --al-c: var(--tf-info); --al-bg: rgba(var(--tf-info-rgb), 0.08); --al-border: rgba(var(--tf-info-rgb), 0.28); }
.alert-success { --al-c: var(--tf-success); --al-bg: rgba(var(--tf-success-rgb), 0.08); --al-border: rgba(var(--tf-success-rgb), 0.28); }
.alert-warning { --al-c: var(--tf-warning); --al-bg: rgba(var(--tf-warning-rgb), 0.09); --al-border: rgba(var(--tf-warning-rgb), 0.3); }
.alert-danger { --al-c: var(--tf-danger); --al-bg: rgba(var(--tf-danger-rgb), 0.08); --al-border: rgba(var(--tf-danger-rgb), 0.3); }

/* ---- Tooltips ---------------------------------------------------------------------------------------------------- */
.tooltip { --bs-tooltip-bg: #111631; --bs-tooltip-color: #f1f3fb; --bs-tooltip-font-size: var(--tf-fs-xs); --bs-tooltip-border-radius: 6px; }
[data-bs-theme="dark"] .tooltip { --bs-tooltip-bg: #e9ebf5; --bs-tooltip-color: #0c0f1d; }

/* ---- Drag & drop (SortableJS) ---------------------------------------------------------------------------------------- */
.sortable-ghost { opacity: 0.4; }
.sortable-chosen { cursor: grabbing; }
.drag-handle { cursor: grab; color: var(--tf-text-subtle); }

/* ---- Auth + error layouts (shared by later phases) --------------------------------------------------------------------- */
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem 1rem; background: var(--tf-bg); }
.auth-card { width: 100%; max-width: 26rem; padding: 1.75rem; border-radius: var(--tf-radius-lg); }
.error-shell { min-height: 100vh; display: grid; place-items: center; padding: 2rem 1rem; text-align: center; }
.error-code { font-size: clamp(4rem, 18vw, 8rem); font-weight: 800; letter-spacing: -0.05em; line-height: 1; color: var(--tf-primary-text); }

/* ---- Section helper for showcase / docs ----------------------------------------------------------------------------------- */
.swatch-tile { height: 3.25rem; border-radius: var(--tf-radius-sm); border: 1px solid var(--tf-border); background: var(--sw); }

/* Phase 10 accessibility: contrast and link affordance */
[data-bs-theme="light"] .avatar { color: color-mix(in srgb, var(--av-fg, var(--tf-primary-text)) 58%, #000); }
p a:not(.btn):not(.nav-link), .small a:not(.btn):not(.nav-link), .text-muted a:not(.btn), .form-text a, .form-check-label a, .demo-banner a, #board-note a, td > a:not(.btn):not([class]) { text-decoration: underline; text-underline-offset: 0.18em; }
[data-bs-theme="dark"] .avatar { color: color-mix(in srgb, var(--av-fg, var(--tf-primary-text)) 72%, #fff); }
