/* ============================================================
   BDO Unified Design System — Components
   Section 3 of the unification brief.
   ============================================================ */

/* ----------------------------------------------------------
   Typography utilities
   ---------------------------------------------------------- */
.t-display  { font-size: var(--text-display); font-weight: var(--weight-bold); line-height: var(--leading-tight); letter-spacing: -0.01em; }
.t-h1       { font-size: var(--text-h1); font-weight: var(--weight-bold); line-height: var(--leading-tight); }
.t-h2       { font-size: var(--text-h2); font-weight: var(--weight-bold); line-height: var(--leading-tight); }
.t-h3       { font-size: var(--text-h3); font-weight: var(--weight-bold); line-height: var(--leading-normal); }
.t-body     { font-size: var(--text-body); font-weight: var(--weight-regular); line-height: var(--leading-normal); }
.t-body-em  { font-size: var(--text-body); font-weight: var(--weight-semibold); }
.t-small    { font-size: var(--text-small); font-weight: var(--weight-regular); line-height: var(--leading-normal); }
.t-caption  { font-size: var(--text-caption); font-weight: var(--weight-regular); line-height: var(--leading-normal); }
.t-eyebrow  { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: var(--weight-semibold); color: var(--bdo-text-secondary); }

.t-secondary { color: var(--bdo-text-secondary); }
.t-tertiary  { color: var(--bdo-text-tertiary); }
.t-primary   { color: var(--bdo-text-primary); }
.t-red       { color: var(--bdo-red); }
.t-info      { color: var(--bdo-accent-info); }

/* ----------------------------------------------------------
   Button
   ---------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 40px;
  padding: 0 var(--space-5);
  border-radius: var(--radius-md);
  font-size: var(--text-body);
  font-weight: var(--weight-semibold);
  border: 1px solid transparent;
  background: transparent;
  color: var(--bdo-text-primary);
  cursor: pointer;
  transition: background var(--motion-fast) var(--motion-ease),
              border-color var(--motion-fast) var(--motion-ease),
              color var(--motion-fast) var(--motion-ease),
              box-shadow var(--motion-fast) var(--motion-ease);
  white-space: nowrap;
}
.btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.btn[disabled], .btn.is-disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.btn .icon { width: 18px; height: 18px; flex: none; }

.btn-sm { height: 32px; padding: 0 var(--space-4); font-size: var(--text-small); }
.btn-lg { height: 48px; padding: 0 var(--space-6); font-size: 15px; }
.btn-block { display: flex; width: 100%; }

/* Primary */
.btn-primary {
  background: var(--bdo-red);
  color: var(--bdo-text-inverse);
  border-color: var(--bdo-red);
}
.btn-primary:hover { background: var(--bdo-red-hover); border-color: var(--bdo-red-hover); }
.btn-primary:active { background: var(--bdo-red-active); border-color: var(--bdo-red-active); }

/* Secondary */
.btn-secondary {
  background: var(--bdo-bg-primary);
  color: var(--bdo-text-primary);
  border-color: var(--bdo-border-default);
}
.btn-secondary:hover { background: var(--bdo-bg-secondary); }
.btn-secondary:active { background: var(--bdo-bg-tertiary); }

/* Ghost */
.btn-ghost {
  background: transparent;
  color: var(--bdo-text-primary);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--bdo-bg-secondary); }
.btn-ghost:active { background: var(--bdo-bg-tertiary); }

/* Destructive */
.btn-destructive {
  background: transparent;
  color: var(--bdo-red);
  border-color: transparent;
}
.btn-destructive:hover { background: var(--bdo-accent-danger-bg); }

/* Icon-only button */
.btn-icon {
  width: 40px; padding: 0; flex: none;
}
.btn-icon.btn-sm { width: 32px; }
.btn-icon.btn-lg { width: 48px; }

/* ----------------------------------------------------------
   Input fields
   ---------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: var(--space-2); }
.field-label {
  font-size: var(--text-small);
  font-weight: var(--weight-semibold);
  color: var(--bdo-text-primary);
}
.field-label .required { color: var(--bdo-red); margin-left: 2px; }
.field-helper {
  font-size: var(--text-caption);
  color: var(--bdo-text-secondary);
}
.field-error { color: var(--bdo-red); }

.input,
.textarea,
.select {
  width: 100%;
  height: 40px;
  padding: 0 var(--space-4);
  background: var(--bdo-bg-primary);
  border: 1px solid var(--bdo-border-default);
  border-radius: var(--radius-md);
  font-size: var(--text-body);
  color: var(--bdo-text-primary);
  transition: border-color var(--motion-fast) var(--motion-ease),
              box-shadow var(--motion-fast) var(--motion-ease);
}
.input::placeholder, .textarea::placeholder { color: var(--bdo-text-tertiary); }
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--bdo-red);
  box-shadow: var(--shadow-focus);
}
.textarea {
  min-height: 80px;
  height: auto;
  padding: var(--space-3) var(--space-4);
  resize: vertical;
  line-height: var(--leading-normal);
}
.field.has-error .input,
.field.has-error .textarea,
.field.has-error .select { border-color: var(--bdo-red); }

/* Select with chevron */
.select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23333333' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* Search input with icon */
.input-search {
  position: relative;
}
.input-search .input { padding-left: 40px; }
.input-search > .icon {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--bdo-text-secondary); pointer-events: none;
}

/* ----------------------------------------------------------
   Card
   ---------------------------------------------------------- */
.card {
  background: var(--bdo-bg-primary);
  border: 1px solid var(--bdo-border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}
.card-hover {
  transition: border-color var(--motion-fast) var(--motion-ease),
              box-shadow var(--motion-fast) var(--motion-ease),
              transform var(--motion-fast) var(--motion-ease);
}
.card-hover:hover {
  border-color: var(--bdo-border-default);
  box-shadow: var(--shadow-sm);
}

/* ----------------------------------------------------------
   App header (Section 4)
   ---------------------------------------------------------- */
.app-header {
  display: flex;
  align-items: center;
  height: var(--header-height);
  padding: 0 var(--space-4);
  background: var(--bdo-bg-primary);
  border-bottom: 1px solid var(--bdo-border-subtle);
}
.app-header__logo {
  display: flex; align-items: center; height: 32px;
}
.app-header__logo img,
.app-header__logo svg {
  height: 32px; width: auto; display: block;
}
.app-header__sep {
  width: 1px; height: 24px;
  background: var(--bdo-border-subtle);
  margin: 0 var(--space-6);
}
.app-header__app {
  display: flex; align-items: center; gap: var(--space-3);
  color: var(--bdo-text-primary);
}
.app-header__app .icon {
  width: 20px; height: 20px; stroke-width: 2;
  color: var(--bdo-text-primary);
}
.app-header__app-name {
  font-size: var(--text-h3);
  font-weight: var(--weight-semibold);
  color: var(--bdo-text-primary);
}
.app-header__spacer { flex: 1; }
.app-header__actions {
  display: flex; align-items: center; gap: var(--space-2);
  padding-right: var(--space-4);
}

/* ----------------------------------------------------------
   Sidebar
   ---------------------------------------------------------- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bdo-bg-primary);
  border-right: 1px solid var(--bdo-border-subtle);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  overflow-y: auto;
}
.sidebar__section {
  display: flex; flex-direction: column; gap: 2px;
  margin-top: var(--space-4);
}
.sidebar__section:first-child { margin-top: 0; }
.sidebar__heading {
  font-size: var(--text-caption);
  font-weight: var(--weight-semibold);
  color: var(--bdo-text-secondary);
  padding: var(--space-2) var(--space-3);
  text-transform: none;
}
.nav-item {
  display: flex; align-items: center; gap: var(--space-3);
  height: 40px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-md);
  font-size: var(--text-body);
  color: var(--bdo-text-primary);
  text-decoration: none;
  border-left: 3px solid transparent;
  margin-left: -3px;
  padding-left: calc(var(--space-3));
  transition: background var(--motion-fast) var(--motion-ease);
  cursor: pointer;
}
.nav-item:hover { background: var(--bdo-bg-secondary); text-decoration: none; }
.nav-item .icon { width: 20px; height: 20px; flex: none; color: var(--bdo-text-secondary); }
.nav-item.is-active {
  background: var(--bdo-bg-secondary);
  border-left-color: var(--bdo-red);
  font-weight: var(--weight-semibold);
}
.nav-item.is-active .icon { color: var(--bdo-text-primary); }
.nav-item__count {
  margin-left: auto;
  font-size: var(--text-caption);
  color: var(--bdo-text-secondary);
}

/* ----------------------------------------------------------
   Tabs
   ---------------------------------------------------------- */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--bdo-border-subtle);
  gap: var(--space-1);
}
.tab {
  height: 40px;
  padding: 0 var(--space-4);
  font-size: var(--text-body);
  font-weight: var(--weight-semibold);
  color: var(--bdo-text-primary);
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  transition: background var(--motion-fast) var(--motion-ease);
}
.tab:hover { background: var(--bdo-bg-secondary); }
.tab.is-active { border-bottom-color: var(--bdo-red); }

/* Segmented control */
.segmented {
  display: inline-flex;
  padding: 4px;
  background: var(--bdo-bg-secondary);
  border-radius: var(--radius-md);
  gap: 2px;
}
.segmented button {
  height: 32px;
  padding: 0 var(--space-4);
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  font-size: var(--text-small);
  font-weight: var(--weight-semibold);
  color: var(--bdo-text-primary);
  cursor: pointer;
}
.segmented button.is-active {
  background: var(--bdo-red);
  color: var(--bdo-text-inverse);
}

/* ----------------------------------------------------------
   Badge / Pill
   ---------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-caption);
  font-weight: var(--weight-semibold);
  background: var(--bdo-bg-secondary);
  color: var(--bdo-text-primary);
  white-space: nowrap;
}
.badge-info    { background: var(--bdo-accent-info-bg);    color: var(--bdo-accent-info); }
.badge-success { background: var(--bdo-accent-success-bg); color: var(--bdo-accent-success); }
.badge-warning { background: var(--bdo-accent-warning-bg); color: var(--bdo-accent-warning); }
.badge-danger  { background: var(--bdo-accent-danger-bg);  color: var(--bdo-accent-danger); }
.badge .icon { width: 12px; height: 12px; }

/* ----------------------------------------------------------
   Data table
   ---------------------------------------------------------- */
.table {
  width: 100%;
  font-size: var(--text-body);
  border-collapse: separate;
  border-spacing: 0;
}
.table thead th {
  height: 48px;
  padding: 0 var(--space-4);
  background: var(--bdo-bg-secondary);
  font-weight: var(--weight-semibold);
  color: var(--bdo-text-primary);
  text-align: left;
  font-size: var(--text-small);
  border-bottom: 1px solid var(--bdo-border-subtle);
}
.table thead th:first-child { border-top-left-radius: var(--radius-md); }
.table thead th:last-child  { border-top-right-radius: var(--radius-md); }
.table tbody td {
  height: 48px;
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--bdo-border-subtle);
  color: var(--bdo-text-primary);
  vertical-align: middle;
}
.table tbody tr { transition: background var(--motion-fast) var(--motion-ease); }
.table tbody tr:hover { background: var(--bdo-bg-tertiary); }
.table tbody tr.is-selected td:first-child {
  box-shadow: inset 3px 0 0 var(--bdo-red);
}
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions {
  display: flex; gap: var(--space-2); align-items: center;
}
.table .actions .icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: var(--radius-sm);
  color: var(--bdo-text-primary); background: transparent; border: none; cursor: pointer;
}
.table .actions .icon-btn:hover { background: var(--bdo-bg-secondary); }
.table .actions .icon-btn .icon { width: 18px; height: 18px; }

/* ----------------------------------------------------------
   Chat bubbles
   ---------------------------------------------------------- */
.bubble {
  max-width: 70%;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-body);
  line-height: var(--leading-normal);
  border-radius: var(--radius-lg);
}
.bubble-user {
  background: var(--bdo-red);
  color: var(--bdo-text-inverse);
  border-bottom-right-radius: var(--radius-sm);
  margin-left: auto;
}
.bubble-ai {
  background: var(--bdo-bg-secondary);
  color: var(--bdo-text-primary);
  border-bottom-left-radius: var(--radius-sm);
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
}
.bubble-ai .ai-spark {
  width: 16px; height: 16px;
  color: var(--bdo-accent-info);
  flex: none;
  margin-top: 2px;
}
.bubble-row {
  display: flex; margin-bottom: var(--space-3);
}
.bubble-row.from-user { justify-content: flex-end; }
.system-msg {
  text-align: center;
  font-size: var(--text-small);
  color: var(--bdo-text-secondary);
  padding: var(--space-2) 0;
}

/* ----------------------------------------------------------
   Modal
   ---------------------------------------------------------- */
.modal-scrim {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal {
  background: var(--bdo-bg-primary);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-8);
  width: 100%;
  max-width: 480px;
}
.modal-md { max-width: 640px; }
.modal-lg { max-width: 800px; }
.modal__header {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: var(--space-4); margin-bottom: var(--space-4);
}
.modal__title { font-size: var(--text-h2); font-weight: var(--weight-bold); margin: 0; }
.modal__close {
  width: 32px; height: 32px; border: none; background: transparent;
  border-radius: var(--radius-sm); cursor: pointer; color: var(--bdo-text-primary);
  display: inline-flex; align-items: center; justify-content: center;
}
.modal__close:hover { background: var(--bdo-bg-secondary); }
.modal__actions {
  display: flex; justify-content: flex-end; gap: var(--space-3);
  margin-top: var(--space-8);
}

/* ----------------------------------------------------------
   Toast
   ---------------------------------------------------------- */
.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  background: var(--bdo-bg-primary);
  border: 1px solid var(--bdo-border-subtle);
  border-left: 3px solid var(--bdo-text-secondary);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow-md);
  min-width: 320px;
  max-width: 400px;
}
.toast .icon { width: 20px; height: 20px; flex: none; margin-top: 2px; }
.toast__body { flex: 1; }
.toast__title { font-size: var(--text-body); font-weight: var(--weight-semibold); margin-bottom: 2px; }
.toast__msg { font-size: var(--text-small); color: var(--bdo-text-secondary); }
.toast__dismiss {
  width: 24px; height: 24px; border: none; background: transparent;
  border-radius: var(--radius-sm); cursor: pointer; color: var(--bdo-text-secondary);
  display: inline-flex; align-items: center; justify-content: center; flex: none;
}
.toast-info    { border-left-color: var(--bdo-accent-info); }
.toast-info    .icon { color: var(--bdo-accent-info); }
.toast-success { border-left-color: var(--bdo-accent-success); }
.toast-success .icon { color: var(--bdo-accent-success); }
.toast-warning { border-left-color: var(--bdo-accent-warning); }
.toast-warning .icon { color: var(--bdo-accent-warning); }
.toast-danger  { border-left-color: var(--bdo-accent-danger); }
.toast-danger  .icon { color: var(--bdo-accent-danger); }

/* ----------------------------------------------------------
   Avatar
   ---------------------------------------------------------- */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, #5B6E7F 0%, #333333 100%);
  color: var(--bdo-text-inverse);
  font-size: var(--text-body);
  font-weight: var(--weight-semibold);
  flex: none;
}
.avatar-sm { width: 32px; height: 32px; font-size: var(--text-small); }
.avatar-lg { width: 48px; height: 48px; font-size: 16px; }

/* ----------------------------------------------------------
   Toggle / Switch
   ---------------------------------------------------------- */
.toggle {
  position: relative;
  display: inline-flex;
  width: 36px; height: 20px;
  background: var(--bdo-border-default);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background var(--motion-fast) var(--motion-ease);
  flex: none;
}
.toggle::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 16px; height: 16px;
  background: #FFFFFF;
  border-radius: var(--radius-full);
  transition: transform var(--motion-fast) var(--motion-ease);
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.toggle.is-on { background: var(--bdo-red); }
.toggle.is-on::after { transform: translateX(16px); }
.toggle-label {
  display: inline-flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-body); color: var(--bdo-text-primary); cursor: pointer;
}

/* Checkbox */
.checkbox {
  display: inline-flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-body); color: var(--bdo-text-primary); cursor: pointer;
}
.checkbox input { display: none; }
.checkbox__box {
  width: 18px; height: 18px;
  border: 1px solid var(--bdo-border-default);
  border-radius: var(--radius-sm);
  background: var(--bdo-bg-primary);
  display: inline-flex; align-items: center; justify-content: center;
  flex: none;
}
.checkbox input:checked + .checkbox__box {
  background: var(--bdo-red);
  border-color: var(--bdo-red);
}
.checkbox input:checked + .checkbox__box::after {
  content: "";
  width: 5px; height: 9px;
  border: solid #FFFFFF;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg) translate(-1px, -1px);
}

/* ----------------------------------------------------------
   Chips (quick actions)
   ---------------------------------------------------------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: 36px;
  padding: 0 var(--space-3);
  border-radius: var(--radius-full);
  background: var(--bdo-bg-secondary);
  border: 1px solid var(--bdo-border-subtle);
  font-size: var(--text-small);
  font-weight: var(--weight-semibold);
  color: var(--bdo-text-primary);
  cursor: pointer;
  transition: background var(--motion-fast) var(--motion-ease);
}
.chip:hover { background: var(--bdo-bg-tertiary); }
.chip .icon { width: 16px; height: 16px; color: var(--bdo-text-secondary); }

/* ----------------------------------------------------------
   Breadcrumbs
   ---------------------------------------------------------- */
.breadcrumb {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-small);
  color: var(--bdo-text-secondary);
}
.breadcrumb a { color: var(--bdo-text-secondary); }
.breadcrumb a:hover { color: var(--bdo-accent-info); }
.breadcrumb__sep { color: var(--bdo-border-default); }

/* ----------------------------------------------------------
   Banner / Inline alert
   ---------------------------------------------------------- */
.banner {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--bdo-border-subtle);
  border-left-width: 3px;
  background: var(--bdo-bg-primary);
  font-size: var(--text-body);
}
.banner .icon { width: 20px; height: 20px; flex: none; margin-top: 2px; }
.banner-info    { background: var(--bdo-accent-info-bg);    border-color: var(--bdo-accent-info-bg);    border-left-color: var(--bdo-accent-info); }
.banner-info    .icon { color: var(--bdo-accent-info); }
.banner-warning { background: var(--bdo-accent-warning-bg); border-color: var(--bdo-accent-warning-bg); border-left-color: var(--bdo-accent-warning); }
.banner-warning .icon { color: var(--bdo-accent-warning); }
.banner-danger  { background: var(--bdo-accent-danger-bg);  border-color: var(--bdo-accent-danger-bg);  border-left-color: var(--bdo-accent-danger); }
.banner-danger  .icon, .banner-danger a { color: var(--bdo-accent-danger); }

/* ----------------------------------------------------------
   Layout shells
   ---------------------------------------------------------- */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.app-body {
  display: flex;
  flex: 1;
  min-height: 0;
}
.app-main {
  flex: 1;
  min-width: 0;
  background: var(--bdo-bg-primary);
}

/* AI sparkle icon helper */
.ai-spark { color: var(--bdo-accent-info); }

/* Utility */
.row { display: flex; gap: var(--space-3); align-items: center; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); }
.col { display: flex; flex-direction: column; gap: var(--space-3); }
.stack-1 > * + * { margin-top: var(--space-1); }
.stack-2 > * + * { margin-top: var(--space-2); }
.stack-3 > * + * { margin-top: var(--space-3); }
.stack-4 > * + * { margin-top: var(--space-4); }
.stack-6 > * + * { margin-top: var(--space-6); }
.stack-8 > * + * { margin-top: var(--space-8); }
.center { text-align: center; }
.muted { color: var(--bdo-text-secondary); }
.hr { height: 1px; background: var(--bdo-border-subtle); border: 0; margin: var(--space-6) 0; }

/* ----------------------------------------------------------
   Page toolbar — page title row with right-side actions.
   Used wherever a list/grid view needs filters above it.
   ---------------------------------------------------------- */
.page-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-6);
  padding-bottom: var(--space-5);
  border-bottom: 1px solid var(--bdo-border-subtle);
  margin-bottom: var(--space-6);
}
.page-toolbar__titles { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.page-toolbar__title {
  font-size: var(--text-h1);
  font-weight: var(--weight-bold);
  color: var(--bdo-text-primary);
  margin: 0;
  line-height: var(--leading-tight);
}
.page-toolbar__count {
  font-size: var(--text-small);
  color: var(--bdo-text-secondary);
}
.page-toolbar__actions {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  flex-wrap: wrap;
}

/* ----------------------------------------------------------
   Entity Card — single record summary with stats and CTA.
   Use anywhere a list view should read as cards rather than
   a table: mandates, clients, projects, agents, etc.
   Pair with .entity-grid for the responsive layout.
   ---------------------------------------------------------- */
.entity-card {
  background: var(--bdo-bg-primary);
  border: 1px solid var(--bdo-border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  transition: border-color var(--motion-base) var(--motion-ease),
              box-shadow var(--motion-base) var(--motion-ease);
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}
.entity-card:hover {
  border-color: var(--bdo-border-default);
  box-shadow: var(--shadow-md);
  text-decoration: none;
}
.entity-card:focus-visible {
  outline: none;
  border-color: var(--bdo-red);
  box-shadow: var(--shadow-focus);
}

.entity-card__header {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
}

/* Avatar: 44x44 square, Charcoal background by default.
   Brand rule: NEVER use BDO Logo Blue (#22409A) here — it is reserved
   exclusively for the master logo. Permitted backgrounds are
   --bdo-text-primary (default) or --bdo-red (rare emphasis). */
.entity-card__avatar {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--bdo-text-primary);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--weight-semibold);
  font-size: 14px;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.entity-card__title-block {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.entity-card__title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}
.entity-card__title {
  font-size: var(--text-h3);
  font-weight: var(--weight-semibold);
  color: var(--bdo-text-primary);
  line-height: 1.2;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.entity-card__subtitle {
  font-size: var(--text-caption);
  color: var(--bdo-text-secondary);
  margin: 0;
}

.entity-card__divider {
  height: 1px;
  background: var(--bdo-border-subtle);
  margin: 0;
  border: none;
}

.entity-card__stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
}
.entity-card__stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  min-width: 0;
}
.entity-card__stat-value {
  font-size: 24px;
  font-weight: var(--weight-bold);
  color: var(--bdo-text-primary);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.entity-card__stat-label {
  font-size: var(--text-caption);
  color: var(--bdo-text-secondary);
  margin-top: 2px;
}

.entity-card__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: var(--text-caption);
  color: var(--bdo-text-secondary);
  gap: var(--space-3);
}
.entity-card__footer-meta {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.entity-card__footer-meta .icon {
  width: 14px;
  height: 14px;
  color: var(--bdo-text-secondary);
  flex: none;
}
.entity-card__footer-cta {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--bdo-text-primary);
  font-weight: var(--weight-semibold);
  font-size: var(--text-body);
  flex: none;
  transition: color var(--motion-fast) var(--motion-ease),
              transform var(--motion-base) var(--motion-ease);
}
.entity-card__footer-cta .icon {
  width: 16px;
  height: 16px;
  transition: transform var(--motion-base) var(--motion-ease);
}
.entity-card:hover .entity-card__footer-cta { color: var(--bdo-red); }
.entity-card:hover .entity-card__footer-cta .icon { transform: translateX(3px); }

/* Entity Card grid — auto-fill on 320px minimum.
   Pair with parent .entity-grid--3 to cap at 3 columns. */
.entity-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: var(--space-4);
}

/* ----------------------------------------------------------
   Form submission — validation, pending and result states.
   Sequence: rest -> validate on blur -> submit -> pending ->
   success (toast or confirmation panel) or error (banner).
   ---------------------------------------------------------- */
.form-actions {
  display: flex; align-items: center; gap: var(--space-3);
  padding-top: var(--space-5);
  border-top: 1px solid var(--bdo-border-subtle);
}
.form-actions__status {
  margin-right: auto;
  display: inline-flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-small); color: var(--bdo-text-secondary);
}
.form-actions__status .icon { width: 16px; height: 16px; }

/* Error summary — sits above the first field, links to each invalid field. */
.form-summary__title { font-weight: var(--weight-semibold); }
.form-summary__list { margin: var(--space-1) 0 0; padding-left: 18px; font-size: var(--text-small); }
.form-summary__list li + li { margin-top: 2px; }

/* Field-level error: icon + message, always below the field, never a tooltip. */
.field-error {
  display: flex; align-items: flex-start; gap: var(--space-1);
  color: var(--bdo-red);
}
.field-error .icon { width: 14px; height: 14px; flex: none; margin-top: 1px; }

/* Pending: button keeps its label, gains a spinner, form is locked. */
.spinner {
  width: 16px; height: 16px; flex: none;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #FFFFFF;
  border-radius: var(--radius-full);
  animation: bdo-spin 700ms linear infinite;
}
.spinner-dark { border-color: var(--bdo-border-default); border-top-color: var(--bdo-text-secondary); }
@keyframes bdo-spin { to { transform: rotate(360deg); } }
.form-locked { opacity: 0.6; pointer-events: none; }

/* Success: confirmation panel for submissions that end the task. */
.form-success {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: var(--space-3);
  padding: var(--space-10) var(--space-6);
}
.form-success__icon {
  width: 48px; height: 48px; border-radius: var(--radius-full);
  background: var(--bdo-accent-success-bg); color: var(--bdo-accent-success);
  display: flex; align-items: center; justify-content: center;
}
.form-success__icon .icon { width: 24px; height: 24px; }
.form-success__title { font-size: var(--text-h2); font-weight: var(--weight-bold); }
.form-success__msg { font-size: var(--text-body); color: var(--bdo-text-secondary); max-width: 380px; }
.form-success__actions { display: flex; gap: var(--space-3); margin-top: var(--space-3); }

/* ----------------------------------------------------------
   Drag & drop — reordering and re-parenting.
   One vocabulary for every draggable surface: list rows, tree
   nodes, board cards, table rows, file uploads.
   Grip is always visible (never hover-revealed — it makes rows
   flicker as the pointer travels). Red marks where the item
   lands; grey with not-allowed marks a target that refuses it.
   Every completed move is announced and undoable.
   ---------------------------------------------------------- */
.dnd-grip {
  width: 14px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--bdo-border-subtle);
  cursor: grab;
  line-height: 1;
}
.dnd-grip:hover, .dnd-item:hover .dnd-grip { color: var(--bdo-border-default); }
.dnd-grip:active { cursor: grabbing; }

/* The item being dragged stays in place, dimmed. */
.dnd-item.is-dragging { opacity: 0.4; }

/* Insertion between siblings: a 2px red rule on the shared edge. */
.dnd-target--before { box-shadow: inset 0 2px 0 var(--bdo-red); }
.dnd-target--after  { box-shadow: inset 0 -2px 0 var(--bdo-red); }

/* Nesting inside a container: outline the whole target. */
.dnd-target--inside {
  background: var(--bdo-accent-danger-bg);
  box-shadow: inset 0 0 0 1px var(--bdo-red);
}

/* Refused target — neutral, never alarming red. */
.dnd-target--invalid {
  background: var(--bdo-bg-tertiary);
  box-shadow: inset 0 0 0 1px var(--bdo-border-default);
  opacity: 0.6;
  cursor: not-allowed;
}

/* Empty drop zone / placeholder slot. */
.dnd-zone {
  border: 1px dashed var(--bdo-border-default);
  border-radius: var(--radius-md);
  padding: var(--space-6);
  text-align: center;
  font-size: var(--text-small);
  color: var(--bdo-text-secondary);
  transition: border-color var(--motion-fast) var(--motion-ease),
              background var(--motion-fast) var(--motion-ease);
}
.dnd-zone.is-active {
  border-color: var(--bdo-red);
  border-style: solid;
  background: var(--bdo-accent-danger-bg);
  color: var(--bdo-text-primary);
}

/* Landing confirmation: the moved item flashes once, then settles. */
.dnd-moved { animation: dnd-flash 1.2s var(--motion-ease); }
@keyframes dnd-flash { 0%, 60% { background: var(--bdo-accent-warning-bg); } 100% { background: transparent; } }

/* Result line with undo — place in the container footer, not a toast. */
.dnd-status {
  display: inline-flex; align-items: center; gap: var(--space-2);
  font-size: var(--text-caption); color: var(--bdo-text-secondary);
}
.dnd-status button {
  border: none; background: transparent; padding: 0;
  font: inherit; font-weight: var(--weight-semibold);
  color: var(--bdo-accent-info); cursor: pointer;
}
.dnd-status button:hover { text-decoration: underline; }
