/* =====================================================================
   Components
   ===================================================================== */

/* ---------------------------------------------------------------------
   Buttons
   ------------------------------------------------------------------ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-base);
  font-weight: 550;
  line-height: 1.3;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background var(--t-fast) var(--ease),
              border-color var(--t-fast) var(--ease),
              color var(--t-fast) var(--ease),
              box-shadow var(--t-fast) var(--ease),
              transform var(--t-fast) var(--ease);
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}

.btn--primary {
  background: var(--brand-600);
  border-color: var(--brand-600);
  color: #fff;
  box-shadow: var(--sh-xs);
}
.btn--primary:hover { background: var(--brand-700); border-color: var(--brand-700); color: #fff; }

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

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

.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--danger:hover { filter: brightness(0.92); color: #fff; }

.btn--success { background: var(--success); border-color: var(--success); color: #fff; }
.btn--success:hover { filter: brightness(0.92); color: #fff; }

.btn--warning { background: var(--warning); border-color: var(--warning); color: #422006; }
.btn--warning:hover { filter: brightness(0.94); color: #422006; }

.btn--outline-danger { background: transparent; border-color: var(--danger-br); color: var(--danger-fg); }
.btn--outline-danger:hover { background: var(--danger-bg); color: var(--danger-fg); }

.btn--sm { padding: 6px 11px; font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn--lg { padding: 12px 22px; font-size: var(--fs-md); border-radius: var(--r-lg); }
.btn--block { display: flex; width: 100%; }
.btn--icon { padding: 8px; border-radius: var(--r-md); }
.btn--icon.btn--sm { padding: 5px; }

.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--r-md) 0 0 var(--r-md); margin-left: 0; }
.btn-group .btn:last-child  { border-radius: 0 var(--r-md) var(--r-md) 0; }
.btn-group .btn.is-active { background: var(--brand-600); border-color: var(--brand-600); color: #fff; z-index: 1; }

/* ---------------------------------------------------------------------
   Cards & panels
   ------------------------------------------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-xs);
}
.card--flush { box-shadow: none; }
.card--raised { box-shadow: var(--sh-md); }

.card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
}
.card__title { margin: 0; font-size: var(--fs-md); font-weight: 650; }
.card__subtitle { margin: 2px 0 0; font-size: var(--fs-sm); color: var(--text-muted); font-weight: 400; }
.card__body { padding: var(--sp-5); }
.card__body--tight { padding: var(--sp-4); }
.card__body--flush { padding: 0; }
.card__foot {
  padding: var(--sp-3) var(--sp-5);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
}

.panel { background: var(--surface-inset); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--sp-4); }

/* ---------------------------------------------------------------------
   Badges & pills
   ------------------------------------------------------------------ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border: 1px solid transparent;
  border-radius: var(--r-full);
  font-size: var(--fs-xs);
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  vertical-align: middle;
}
.badge--neutral { background: var(--neutral-bg); color: var(--neutral-fg); border-color: var(--neutral-br); }
.badge--success { background: var(--success-bg); color: var(--success-fg); border-color: var(--success-br); }
.badge--warning { background: var(--warning-bg); color: var(--warning-fg); border-color: var(--warning-br); }
.badge--danger  { background: var(--danger-bg);  color: var(--danger-fg);  border-color: var(--danger-br); }
.badge--info    { background: var(--info-bg);    color: var(--info-fg);    border-color: var(--info-br); }
.badge--brand   { background: var(--brand-50);   color: var(--brand-700);  border-color: var(--brand-200); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.chip__remove { display: inline-flex; border: 0; background: none; padding: 0; cursor: pointer; color: inherit; opacity: 0.6; }
.chip__remove:hover { opacity: 1; }

/* ---------------------------------------------------------------------
   Alerts
   ------------------------------------------------------------------ */

.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid;
  border-radius: var(--r-md);
  font-size: var(--fs-base);
  margin-bottom: var(--sp-4);
}
.alert > svg { margin-top: 2px; }
.alert > span { flex: 1 1 auto; }
.alert--success { background: var(--success-bg); border-color: var(--success-br); color: var(--success-fg); }
.alert--warning { background: var(--warning-bg); border-color: var(--warning-br); color: var(--warning-fg); }
.alert--danger  { background: var(--danger-bg);  border-color: var(--danger-br);  color: var(--danger-fg); }
.alert--info    { background: var(--info-bg);    border-color: var(--info-br);    color: var(--info-fg); }
.alert__close { background: none; border: 0; cursor: pointer; color: inherit; opacity: 0.6; padding: 0; display: inline-flex; }
.alert__close:hover { opacity: 1; }

/* ---------------------------------------------------------------------
   Forms
   ------------------------------------------------------------------ */

.field { margin-bottom: var(--sp-4); }
.field__label {
  display: block;
  margin-bottom: 6px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text);
}
.field__label .req { color: var(--danger-fg); margin-left: 2px; }
.field__hint { margin-top: 5px; font-size: var(--fs-xs); color: var(--text-subtle); }
.field__error { margin-top: 5px; font-size: var(--fs-xs); color: var(--danger-fg); font-weight: 500; display: flex; align-items: center; gap: 4px; }

.input, .select, .textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-base);
  line-height: 1.4;
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--text-subtle); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--text-subtle); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-500) 18%, transparent);
}
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-3); color: var(--text-subtle); cursor: not-allowed; }
.input.is-invalid, .select.is-invalid, .textarea.is-invalid { border-color: var(--danger); }

.textarea { min-height: 96px; resize: vertical; line-height: var(--lh-base); }
.input--sm, .select--sm { padding: 6px 10px; font-size: var(--fs-sm); border-radius: var(--r-sm); }
.textarea--lg { min-height: 200px; }

.select {
  appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23808a99' 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 11px center;
}

.input-group { display: flex; align-items: stretch; }
.input-group .input { border-radius: var(--r-md) 0 0 var(--r-md); }
.input-group .btn  { border-radius: 0 var(--r-md) var(--r-md) 0; margin-left: -1px; }

.input-icon { position: relative; }
.input-icon > svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-subtle); pointer-events: none; }
.input-icon .input { padding-left: 36px; }

/* Checkbox / radio built from a real input so keyboard and screen
   readers keep working; the visual box is the ::before pseudo-element. */
.check {
  display: inline-flex;
  align-items: flex-start;
  gap: var(--sp-2);
  cursor: pointer;
  font-size: var(--fs-base);
  line-height: 1.4;
}
.check input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.check__box {
  flex: 0 0 auto;
  width: 18px; height: 18px;
  margin-top: 1px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--r-xs);
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--t-fast) var(--ease);
}
.check--radio .check__box { border-radius: 50%; }
.check input:checked + .check__box { background: var(--brand-600); border-color: var(--brand-600); }
.check input:checked + .check__box::after {
  content: "";
  width: 10px; height: 10px;
  background: #fff;
  clip-path: polygon(14% 47%, 0 61%, 40% 100%, 100% 22%, 85% 8%, 38% 70%);
}
.check--radio input:checked + .check__box::after { clip-path: none; border-radius: 50%; width: 7px; height: 7px; }
.check input:focus-visible + .check__box { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.check input:disabled + .check__box { background: var(--surface-3); border-color: var(--border); }

.switch { display: inline-flex; align-items: center; gap: var(--sp-3); cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch__track {
  width: 40px; height: 22px;
  background: var(--border-strong);
  border-radius: var(--r-full);
  position: relative;
  transition: background var(--t-base) var(--ease);
  flex: 0 0 auto;
}
.switch__track::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  box-shadow: var(--sh-xs);
  transition: transform var(--t-base) var(--ease);
}
.switch input:checked + .switch__track { background: var(--brand-600); }
.switch input:checked + .switch__track::after { transform: translateX(18px); }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--border-focus); outline-offset: 2px; }

.fieldset { border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--sp-4); margin-bottom: var(--sp-4); }
.fieldset > legend { padding: 0 var(--sp-2); font-size: var(--fs-sm); font-weight: 650; color: var(--text-muted); }

/* ---------------------------------------------------------------------
   Tables
   ------------------------------------------------------------------ */

.table { width: 100%; font-size: var(--fs-base); }
.table th, .table td { padding: 11px var(--sp-4); text-align: left; vertical-align: middle; }
.table thead th {
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: var(--fs-xs);
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.045em;
  color: var(--text-muted);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
}
.table tbody tr { border-bottom: 1px solid var(--border); }
.table tbody tr:last-child { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table td.right, .table th.right { text-align: right; }
.table td.center, .table th.center { text-align: center; }
.table--compact th, .table--compact td { padding: 7px var(--sp-3); }
.table--fixed { table-layout: fixed; }

.th-sort { display: inline-flex; align-items: center; gap: 3px; color: inherit; }
.th-sort:hover { color: var(--text); text-decoration: none; }
.th-sort.is-active { color: var(--brand-600); }

.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  overflow: hidden;
}
.table-wrap > .scroll-x { max-height: none; }

/* ---------------------------------------------------------------------
   Stat cards & rings
   ------------------------------------------------------------------ */

.stat {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-xs);
  transition: box-shadow var(--t-base) var(--ease), transform var(--t-base) var(--ease);
}
a.stat:hover { text-decoration: none; box-shadow: var(--sh-md); transform: translateY(-1px); }
.stat__icon {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-md);
  background: var(--brand-50);
  color: var(--brand-600);
}
.stat__body { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.stat__label { font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: 0.045em; color: var(--text-muted); }
.stat__value { font-size: var(--fs-2xl); font-weight: 680; line-height: 1.15; letter-spacing: -0.02em; color: var(--text); font-variant-numeric: tabular-nums; }
.stat__value small { font-size: var(--fs-md); font-weight: 550; color: var(--text-muted); }
.stat__sub { font-size: var(--fs-sm); color: var(--text-muted); }
.stat__delta { display: inline-flex; align-items: center; gap: 2px; font-size: var(--fs-xs); font-weight: 650; }
.stat__delta--up   { color: var(--success-fg); }
.stat__delta--down { color: var(--danger-fg); }

.stat--success .stat__icon { background: var(--success-bg); color: var(--success-fg); }
.stat--warning .stat__icon { background: var(--warning-bg); color: var(--warning-fg); }
.stat--danger  .stat__icon { background: var(--danger-bg);  color: var(--danger-fg); }
.stat--info    .stat__icon { background: var(--info-bg);    color: var(--info-fg); }

.ring { position: relative; display: inline-grid; place-items: center; }
.ring svg { position: absolute; inset: 0; }
.ring__track { stroke: var(--surface-3); }
.ring__value { stroke: var(--brand-500); transition: stroke-dashoffset 600ms var(--ease); }
.ring--success .ring__value { stroke: var(--success); }
.ring--warning .ring__value { stroke: var(--warning); }
.ring--danger  .ring__value { stroke: var(--danger); }
.ring__text { display: flex; flex-direction: column; align-items: center; line-height: 1.1; }
.ring__text strong { font-size: var(--fs-lg); font-weight: 680; font-variant-numeric: tabular-nums; }
.ring__text strong small { font-size: 0.6em; font-weight: 550; color: var(--text-muted); }
.ring__text em { font-style: normal; font-size: var(--fs-xs); color: var(--text-muted); }

/* Confidence meter used across the AI review queue. */
.conf { display: grid; grid-template-columns: minmax(88px, auto) 1fr 40px; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); }
.conf__label { color: var(--text-muted); }
.conf__track { height: 6px; background: var(--surface-3); border-radius: var(--r-full); overflow: hidden; }
.conf__fill { display: block; height: 100%; border-radius: var(--r-full); }
.conf__fill--success { background: var(--success); }
.conf__fill--info    { background: var(--info); }
.conf__fill--warning { background: var(--warning); }
.conf__fill--danger  { background: var(--danger); }
.conf__value { text-align: right; font-variant-numeric: tabular-nums; font-weight: 650; }

/* Linear progress bar. */
.bar { height: 8px; background: var(--surface-3); border-radius: var(--r-full); overflow: hidden; }
.bar__fill { height: 100%; background: var(--brand-500); border-radius: var(--r-full); transition: width 500ms var(--ease); }
.bar--sm { height: 5px; }
.bar__fill--success { background: var(--success); }
.bar__fill--warning { background: var(--warning); }
.bar__fill--danger  { background: var(--danger); }

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

.empty { padding: var(--sp-9) var(--sp-5); text-align: center; color: var(--text-muted); }
.empty__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 66px; height: 66px;
  margin-bottom: var(--sp-4);
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text-subtle);
}
.empty__title { margin: 0 0 var(--sp-2); font-size: var(--fs-lg); color: var(--text); }
.empty__text { margin: 0 auto var(--sp-4); max-width: 46ch; }

/* ---------------------------------------------------------------------
   Tabs
   ------------------------------------------------------------------ */

.tabs {
  display: flex;
  gap: var(--sp-1);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--sp-5);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs__item {
  padding: 10px var(--sp-4);
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--text-muted);
  font: inherit;
  font-size: var(--fs-base);
  font-weight: 550;
  white-space: nowrap;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.tabs__item:hover { color: var(--text); text-decoration: none; }
.tabs__item.is-active { color: var(--brand-600); border-bottom-color: var(--brand-600); }
.tabs__count {
  padding: 1px 6px;
  background: var(--surface-3);
  border-radius: var(--r-full);
  font-size: var(--fs-xs);
  font-weight: 650;
}
.tabs__item.is-active .tabs__count { background: var(--brand-50); color: var(--brand-700); }

/* Segmented control (compact filter switch). */
.seg { display: inline-flex; padding: 3px; background: var(--surface-3); border-radius: var(--r-md); gap: 2px; }
.seg__item {
  padding: 5px 12px;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--text-muted);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 550;
  cursor: pointer;
  transition: all var(--t-fast) var(--ease);
}
.seg__item:hover { color: var(--text); text-decoration: none; }
.seg__item.is-active { background: var(--surface); color: var(--text); box-shadow: var(--sh-xs); }

/* ---------------------------------------------------------------------
   Breadcrumbs & pagination
   ------------------------------------------------------------------ */

.crumbs { font-size: var(--fs-sm); margin-bottom: var(--sp-3); }
.crumbs ol { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; list-style: none; margin: 0; padding: 0; }
.crumbs li { display: inline-flex; align-items: center; gap: 4px; margin: 0; }
.crumbs a { color: var(--text-muted); }
.crumbs a:hover { color: var(--brand-600); }
.crumbs svg { color: var(--text-subtle); }
.crumbs [aria-current] { color: var(--text); font-weight: 550; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; padding: var(--sp-3) var(--sp-4); }
.pager__list { display: flex; gap: 3px; flex-wrap: wrap; }
.pager__list a, .pager__list span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px; height: 34px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-weight: 550;
}
.pager__list a:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.pager__list .is-current { background: var(--brand-600); border-color: var(--brand-600); color: #fff; }
.pager__list .is-disabled { opacity: 0.45; pointer-events: none; }

/* ---------------------------------------------------------------------
   Modal & drawer
   ------------------------------------------------------------------ */

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--sp-5);
  background: var(--overlay);
  backdrop-filter: blur(2px);
}
.modal.is-open { display: flex; }
.modal__box {
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - var(--sp-8));
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-xl);
  animation: modal-in var(--t-base) var(--ease);
}
.modal__box--lg { max-width: 860px; }
.modal__box--xl { max-width: 1100px; }
@keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(0.985); } to { opacity: 1; transform: none; } }
.modal__head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--border); }
.modal__title { margin: 0; font-size: var(--fs-lg); }
.modal__body { padding: var(--sp-5); overflow-y: auto; }
.modal__foot { display: flex; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--r-xl) var(--r-xl); }

/* ---------------------------------------------------------------------
   Dropdown
   ------------------------------------------------------------------ */

.dropdown { position: relative; display: inline-block; }
.dropdown__menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 60;
  min-width: 200px;
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--sh-lg);
  display: none;
}
.dropdown__menu--left { right: auto; left: 0; }
.dropdown.is-open .dropdown__menu { display: block; }
.dropdown__item {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: var(--r-sm);
  background: none;
  color: var(--text);
  font: inherit;
  font-size: var(--fs-base);
  text-align: left;
  cursor: pointer;
}
.dropdown__item:hover { background: var(--surface-3); text-decoration: none; color: var(--text); }
.dropdown__item--danger { color: var(--danger-fg); }
.dropdown__divider { height: 1px; background: var(--border); margin: 5px 0; }
.dropdown__label { padding: 6px 10px 3px; font-size: var(--fs-xs); font-weight: 650; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-subtle); }

/* ---------------------------------------------------------------------
   Avatar
   ------------------------------------------------------------------ */

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  object-fit: cover;
  flex: 0 0 auto;
}
.avatar--initials { color: #fff; font-size: var(--fs-sm); font-weight: 650; letter-spacing: 0.02em; }

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

.toasts { position: fixed; right: var(--sp-5); bottom: var(--sp-5); z-index: 300; display: flex; flex-direction: column; gap: var(--sp-2); pointer-events: none; }
.toast {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  min-width: 240px;
  max-width: 380px;
  padding: 11px var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--brand-500);
  border-radius: var(--r-md);
  box-shadow: var(--sh-lg);
  font-size: var(--fs-base);
  pointer-events: auto;
  animation: toast-in var(--t-base) var(--ease);
}
@keyframes toast-in { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
.toast--success { border-left-color: var(--success); }
.toast--danger  { border-left-color: var(--danger); }
.toast--warning { border-left-color: var(--warning); }
.toast.is-leaving { opacity: 0; transform: translateX(16px); transition: all var(--t-base) var(--ease); }

/* ---------------------------------------------------------------------
   Tooltip (CSS-only, no JS)
   ------------------------------------------------------------------ */

[data-tip] { position: relative; }
[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  bottom: calc(100% + 7px);
  left: 50%;
  transform: translateX(-50%);
  padding: 5px 9px;
  background: #111827;
  color: #fff;
  border-radius: var(--r-sm);
  font-size: var(--fs-xs);
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-fast) var(--ease);
  z-index: 80;
}
[data-tip]:hover::after, [data-tip]:focus-visible::after { opacity: 1; }

/* ---------------------------------------------------------------------
   Charts
   ------------------------------------------------------------------ */

.chart { position: relative; width: 100%; }
.chart--sm { height: 180px; }
.chart--md { height: 260px; }
.chart--lg { height: 340px; }

.legend { display: flex; flex-wrap: wrap; gap: var(--sp-3); margin-top: var(--sp-3); font-size: var(--fs-sm); }
.legend__item { display: inline-flex; align-items: center; gap: 6px; color: var(--text-muted); }
.legend__swatch { width: 10px; height: 10px; border-radius: 3px; flex: 0 0 auto; }

/* ---------------------------------------------------------------------
   Skeleton loading
   ------------------------------------------------------------------ */

.skeleton {
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--r-sm);
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------------------------------------------------------------------
   Bulk action bar

   Docked to the bottom of the viewport rather than sitting above the
   table: with 50 rows on screen the selection is usually made near the
   bottom, and a bar that stays in view avoids a scroll back to the top
   to act on it.
   ------------------------------------------------------------------ */

.bulkbar {
  position: sticky;
  bottom: var(--sp-4);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin-top: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-xl);
  animation: bulkbar-in var(--t-base) var(--ease);
}
.bulkbar[hidden] { display: none; }
.bulkbar__count { font-size: var(--fs-sm); color: var(--text-muted); white-space: nowrap; }
.bulkbar__count strong { color: var(--text); font-size: var(--fs-base); }
.bulkbar__extra { display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.bulkbar__extra[hidden] { display: none; }
.bulkbar .select, .bulkbar .input { width: auto; min-width: 150px; }

@keyframes bulkbar-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------------
   Question list — the paper under construction in the Test Builder.
   ------------------------------------------------------------------ */

.qlist { list-style: none; margin: 0; padding: 0; }
.qlist__item {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.qlist__item:last-child { border-bottom: 0; }
.qlist__item:hover { background: var(--surface-2); }
.qlist__item.is-dragging { opacity: 0.4; background: var(--surface-3); }
.qlist__grip { color: var(--text-subtle); cursor: grab; padding-top: 2px; flex: 0 0 auto; }
.qlist__item:active .qlist__grip { cursor: grabbing; }
.qlist__num {
  flex: 0 0 auto;
  min-width: 26px;
  font-size: var(--fs-sm);
  font-weight: 650;
  color: var(--text-muted);
  padding-top: 1px;
}
.qlist__body { flex: 1 1 auto; min-width: 0; }
.qlist__marks { flex: 0 0 auto; padding-top: 3px; }

.btn.is-disabled { opacity: 0.55; }

/* Tree navigation — the taxonomy's subject list and anything else that is
   a flat list of siblings acting as a filter. */
.tree-link {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 10px var(--sp-4);
  border-left: 2px solid transparent;
  color: var(--text-muted);
  font-size: var(--fs-sm);
}
.tree-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.tree-link.is-active {
  background: var(--surface-2);
  border-left-color: var(--brand-600);
  color: var(--text);
  font-weight: 600;
}
.tree-link__dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }

/* Raw extracted text: preserved exactly, scrollable in both directions
   so a wide table pulled out of a PDF stays readable. */
.rawtext {
  margin: 0;
  padding: var(--sp-4);
  max-height: 70vh;
  overflow: auto;
  background: var(--surface-inset);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  line-height: 1.6;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
  tab-size: 4;
}

/* ---------------------------------------------------------------------
   File drop zone

   The native file input stays in the DOM and keeps its focus ring: drag
   and drop is an addition for pointer users, never the only way in.
   ------------------------------------------------------------------ */

.dropzone {
  position: relative;
  border: 2px dashed var(--border-strong);
  border-radius: var(--r-lg);
  background: var(--surface-2);
  transition: border-color var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.dropzone.is-over { border-color: var(--brand-500); background: var(--brand-50); }
.dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  opacity: 0;
  cursor: pointer;
}
.dropzone__label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-7) var(--sp-5);
  text-align: center;
  color: var(--text-subtle);
  cursor: pointer;
}
.dropzone__title { font-size: var(--fs-base); font-weight: 600; color: var(--text); }
.dropzone__hint { font-size: var(--fs-xs); }
.dropzone input[type="file"]:focus-visible + .dropzone__label { outline: 2px solid var(--border-focus); outline-offset: 2px; border-radius: var(--r-lg); }
.dropzone__chosen {
  margin: 0;
  padding: var(--sp-3) var(--sp-4);
  border-top: 1px dashed var(--border-strong);
  font-size: var(--fs-sm);
  font-weight: 550;
  color: var(--text);
  text-align: center;
}

/* ---------------------------------------------------------------------
   Question rendering — shared by the admin bank, the review queue and
   the student test engine, so a question looks the same everywhere.
   ------------------------------------------------------------------ */

.qbody { font-size: var(--fs-lg); line-height: var(--lh-loose); color: var(--text); }
.qbody p { margin: 0 0 var(--sp-3); }
.qdir {
  padding: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-4);
  background: var(--surface-2);
  border-left: 3px solid var(--border-strong);
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  color: var(--text-muted);
  white-space: pre-line;
}

.qopts { list-style: none; margin: var(--sp-4) 0 0; padding: 0; display: grid; gap: var(--sp-2); }
.qopt {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
}
.qopt__key {
  flex: 0 0 auto;
  width: 26px; height: 26px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  font-size: var(--fs-sm);
  font-weight: 650;
  color: var(--text-muted);
}
.qopt__text { flex: 1 1 auto; }
.qopt__stat { flex: 0 0 auto; font-size: var(--fs-xs); color: var(--text-subtle); text-align: right; }

/* The correct option carries a tick and the word "Correct" as well as the
   colour, so it survives greyscale printing and colour-blind viewing. */
.qopt--correct { border-color: var(--success); background: var(--success-bg); }
.qopt--correct .qopt__key { background: var(--success); border-color: var(--success); color: #fff; }
.qopt--chosen { border-color: var(--brand-500); }
.qopt--wrong { border-color: var(--danger); background: var(--danger-bg); }
.qopt--wrong .qopt__key { background: var(--danger); border-color: var(--danger); color: #fff; }
.qopt__tag { font-size: var(--fs-xs); font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; }

/* ---------------------------------------------------------------------
   Suggestion panel

   Visually distinct from verified content because requirement 56 draws a
   hard line between the two: nothing here is part of the question until
   an editor accepts it.
   ------------------------------------------------------------------ */

.suggest {
  border: 1px dashed var(--info);
  border-radius: var(--r-lg);
  background: var(--info-bg);
  padding: var(--sp-4);
}
.suggest__head { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-3); font-weight: 650; color: var(--info-fg); }
.suggest__row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-2) 0; border-top: 1px solid color-mix(in srgb, var(--info) 25%, transparent); }
.suggest__row:first-of-type { border-top: 0; }

/* ---------------------------------------------------------------------
   Timeline — version history, audit trail, attempt events
   ------------------------------------------------------------------ */

.timeline { list-style: none; margin: 0; padding: 0 0 0 var(--sp-5); position: relative; }
.timeline::before { content: ""; position: absolute; left: 6px; top: 6px; bottom: 6px; width: 1px; background: var(--border); }
.timeline__item { position: relative; padding-bottom: var(--sp-4); }
.timeline__item::before {
  content: "";
  position: absolute;
  left: calc(var(--sp-5) * -1 + 2px);
  top: 6px;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--border-strong);
}
.timeline__item--current::before { background: var(--brand-600); border-color: var(--brand-600); }
.timeline__meta { font-size: var(--fs-xs); color: var(--text-subtle); }

/* ---------------------------------------------------------------------
   Print
   ------------------------------------------------------------------ */

@media print {
  .no-print, .app-sidebar, .app-topbar, .btn { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border-color: #ccc; box-shadow: none; break-inside: avoid; }
}
