/*
 * BrandMyInstitute design system component layer.
 *
 * Built entirely on the tokens in tokens.css. Every class is prefixed `ds-`
 * so it can coexist with Bootstrap without fighting it. Do not add hardcoded
 * colour values here; reference the custom properties instead.
 */

/* Scoped reset — only applies inside .ds-page, leaves Bootstrap alone. */
.ds-page {
  background-color: rgb(var(--bmi-bg));
  color: rgb(var(--bmi-text));
  min-height: 100vh;
}

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

.ds-numeric {
  font-variant-numeric: tabular-nums;
}

/* Container */
.ds-container {
  max-width: 1280px;
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--bmi-space-6);
  padding-right: var(--bmi-space-6);
}

@media (max-width: 640px) {
  .ds-container {
    padding-left: var(--bmi-space-4);
    padding-right: var(--bmi-space-4);
  }
}

/* Toolbar — page header bar with title, subtitle, and right-aligned actions. */
.ds-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--bmi-space-4);
  margin-bottom: var(--bmi-space-6);
}

.ds-toolbar__title {
  font-size: 24px;
  font-weight: 700;
  color: rgb(var(--bmi-text));
  margin: 0;
}

.ds-toolbar__subtitle {
  font-size: 14px;
  color: rgb(var(--bmi-text-muted));
  margin-top: var(--bmi-space-1);
}

.ds-toolbar__actions {
  display: flex;
  align-items: center;
  gap: var(--bmi-space-2);
  flex-shrink: 0;
}

@media (max-width: 720px) {
  .ds-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .ds-toolbar__actions {
    justify-content: flex-start;
  }
}

/* Breadcrumb */
.ds-breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--bmi-space-1);
  font-size: 13px;
  color: rgb(var(--bmi-text-muted));
  margin-bottom: var(--bmi-space-4);
}

.ds-breadcrumb__item {
  color: rgb(var(--bmi-text-muted));
  text-decoration: none;
}

.ds-breadcrumb__item:last-child {
  color: rgb(var(--bmi-text));
  font-weight: 600;
}

.ds-breadcrumb__item:hover {
  color: rgb(var(--bmi-accent));
}

.ds-breadcrumb__sep {
  color: rgb(var(--bmi-text-subtle));
}

/* Card */
.ds-card {
  background-color: rgb(var(--bmi-surface));
  border: var(--bmi-border-width) solid rgb(var(--bmi-border));
  border-radius: var(--bmi-radius-card);
  padding: var(--bmi-space-4);
}

.ds-card--sunken {
  background-color: rgb(var(--bmi-surface-sunken));
}

.ds-card--flush {
  padding: 0;
}

.ds-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--bmi-space-3);
  padding: var(--bmi-space-4);
  border-bottom: var(--bmi-border-width) solid rgb(var(--bmi-border));
  font-size: 15px;
  font-weight: 600;
}

/* Section header */
.ds-section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--bmi-space-4);
  margin-bottom: var(--bmi-space-4);
}

.ds-section-header__title {
  font-size: 20px;
  font-weight: 600;
  color: rgb(var(--bmi-text));
  margin: 0;
}

.ds-section-header__subtitle {
  font-size: 13px;
  color: rgb(var(--bmi-text-muted));
  margin-top: var(--bmi-space-1);
}

/* Grid */
.ds-grid {
  display: grid;
  gap: var(--bmi-space-4);
}

.ds-grid--2 {
  grid-template-columns: repeat(2, 1fr);
}

.ds-grid--3 {
  grid-template-columns: repeat(3, 1fr);
}

.ds-grid--4 {
  grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 1024px) {
  .ds-grid--4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .ds-grid--2,
  .ds-grid--3,
  .ds-grid--4 {
    grid-template-columns: 1fr;
  }
}

/* Stat tile */
.ds-stat__label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgb(var(--bmi-text-subtle));
}

.ds-stat__value {
  font-size: 24px;
  font-weight: 700;
  color: rgb(var(--bmi-text));
  font-variant-numeric: tabular-nums;
  margin-top: var(--bmi-space-1);
}

.ds-stat__delta {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--bmi-radius-pill);
  margin-top: var(--bmi-space-2);
}

.ds-stat__delta.is-up {
  color: rgb(var(--bmi-success));
  background-color: rgb(var(--bmi-success-wash));
}

.ds-stat__delta.is-down {
  color: rgb(var(--bmi-error));
  background-color: rgb(var(--bmi-error-wash));
}

/* Badge */
.ds-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: var(--bmi-radius-pill);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
}

.ds-badge--neutral {
  background-color: rgb(var(--bmi-surface-sunken));
  color: rgb(var(--bmi-text-muted));
}

.ds-badge--brand {
  background-color: rgb(var(--bmi-primary));
  color: rgb(var(--bmi-accent-contrast));
}

.ds-badge--accent {
  background-color: rgb(var(--bmi-accent-light));
  color: rgb(var(--bmi-accent));
}

.ds-badge--success {
  background-color: rgb(var(--bmi-success-wash));
  color: rgb(var(--bmi-success));
}

.ds-badge--warning {
  background-color: rgb(var(--bmi-warning-wash));
  color: rgb(var(--bmi-warning));
}

.ds-badge--danger {
  background-color: rgb(var(--bmi-error-wash));
  color: rgb(var(--bmi-error));
}

/* Buttons */
.ds-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--bmi-space-2);
  height: 40px;
  padding: 0 var(--bmi-space-4);
  border-radius: var(--bmi-radius-control);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  border: var(--bmi-border-width) solid transparent;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.ds-btn--sm {
  height: 32px;
  padding: 0 var(--bmi-space-3);
  font-size: 13px;
}

.ds-btn--primary {
  background-color: rgb(var(--bmi-accent));
  color: rgb(var(--bmi-accent-contrast));
}

.ds-btn--primary:hover {
  background-color: rgb(var(--bmi-accent-hover));
}

.ds-btn--secondary {
  background-color: rgb(var(--bmi-surface));
  border-color: rgb(var(--bmi-border));
  color: rgb(var(--bmi-text));
}

.ds-btn--secondary:hover {
  background-color: rgb(var(--bmi-surface-raised));
}

.ds-btn--ghost {
  background-color: transparent;
  color: rgb(var(--bmi-accent));
}

.ds-btn--ghost:hover {
  background-color: rgb(var(--bmi-accent-light));
}

.ds-btn--danger {
  background-color: rgb(var(--bmi-error));
  color: rgb(var(--bmi-accent-contrast));
}

.ds-btn--danger:hover {
  background-color: rgb(var(--bmi-error));
  filter: brightness(0.9);
}

.ds-btn:active {
  transform: translateY(0.5px);
}

.ds-btn:disabled,
.ds-btn.is-disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.ds-btn:focus-visible,
.ds-input:focus-visible,
.ds-select:focus-visible,
.ds-textarea:focus-visible,
.ds-tab:focus-visible {
  outline: 2px solid rgb(var(--bmi-focus));
  outline-offset: 2px;
}

/* Form controls */
.ds-field {
  display: flex;
  flex-direction: column;
  gap: var(--bmi-space-1);
  margin-bottom: var(--bmi-space-4);
}

.ds-field__label {
  font-size: 13px;
  font-weight: 600;
  color: rgb(var(--bmi-text));
}

.ds-field__hint {
  font-size: 12px;
  color: rgb(var(--bmi-text-muted));
}

.ds-field__error {
  font-size: 12px;
  color: rgb(var(--bmi-error));
}

.ds-input,
.ds-select,
.ds-textarea {
  height: 40px;
  padding: 0 var(--bmi-space-3);
  border-radius: var(--bmi-radius-control);
  border: var(--bmi-border-width) solid rgb(var(--bmi-border));
  background-color: rgb(var(--bmi-surface));
  color: rgb(var(--bmi-text));
  font-size: 14px;
  width: 100%;
}

.ds-textarea {
  height: auto;
  min-height: 96px;
  padding-top: var(--bmi-space-2);
  padding-bottom: var(--bmi-space-2);
}

.ds-input::placeholder,
.ds-textarea::placeholder {
  color: rgb(var(--bmi-text-subtle));
}

/* Table */
.ds-table-wrap {
  overflow-x: auto;
}

.ds-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

.ds-table thead {
  background-color: rgb(var(--bmi-surface-sunken));
}

.ds-table th {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: rgb(var(--bmi-text-subtle));
  text-align: left;
  padding: var(--bmi-space-3);
  border-bottom: var(--bmi-border-width) solid rgb(var(--bmi-border));
}

.ds-table td {
  font-size: 14px;
  padding: var(--bmi-space-3);
  border-bottom: var(--bmi-border-width) solid rgb(var(--bmi-border));
  color: rgb(var(--bmi-text));
}

.ds-table tbody tr:hover {
  background-color: rgb(var(--bmi-surface-raised));
}

.ds-table--dense th,
.ds-table--dense td {
  padding: var(--bmi-space-2) var(--bmi-space-3);
}

.ds-table__num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* List */
.ds-list {
  display: flex;
  flex-direction: column;
}

.ds-list__row {
  display: flex;
  align-items: center;
  gap: var(--bmi-space-3);
  min-height: 56px;
  padding: var(--bmi-space-2) var(--bmi-space-4);
  border-bottom: var(--bmi-border-width) solid rgb(var(--bmi-border));
  border-left: 2px solid transparent;
}

.ds-list__row:hover {
  background-color: rgb(var(--bmi-surface-raised));
}

.ds-list__row.is-selected {
  background-color: rgb(var(--bmi-accent-light));
  border-left-color: rgb(var(--bmi-accent));
}

/* Progress */
.ds-progress {
  height: 6px;
  border-radius: var(--bmi-radius-pill);
  background-color: rgb(var(--bmi-surface-sunken));
  overflow: hidden;
}

.ds-progress__fill {
  height: 100%;
  background-color: rgb(var(--bmi-accent));
  border-radius: var(--bmi-radius-pill);
}

/* Empty / error states */
.ds-empty,
.ds-error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: var(--bmi-space-12) var(--bmi-space-4);
  color: rgb(var(--bmi-text-muted));
}

.ds-empty__icon,
.ds-error-state__icon {
  font-size: 32px;
  margin-bottom: var(--bmi-space-3);
  color: rgb(var(--bmi-text-subtle));
}

.ds-error-state__icon {
  color: rgb(var(--bmi-error));
}

.ds-empty__title,
.ds-error-state__title {
  font-size: 16px;
  font-weight: 600;
  color: rgb(var(--bmi-text));
  margin-bottom: var(--bmi-space-1);
}

.ds-empty__message,
.ds-error-state__message {
  font-size: 14px;
  color: rgb(var(--bmi-text-muted));
  margin-bottom: var(--bmi-space-4);
}

/* Skeleton loading */
@keyframes ds-shimmer {
  0% {
    background-color: rgb(var(--bmi-surface-sunken));
  }
  50% {
    background-color: rgb(var(--bmi-surface-raised));
  }
  100% {
    background-color: rgb(var(--bmi-surface-sunken));
  }
}

.ds-skeleton {
  border-radius: var(--bmi-radius-control);
  animation: ds-shimmer 1.6s ease-in-out infinite;
}

.ds-skeleton--text {
  height: 12px;
  border-radius: var(--bmi-radius-control);
  margin-bottom: var(--bmi-space-2);
}

@media (prefers-reduced-motion: reduce) {
  .ds-skeleton {
    animation: none;
  }

  .ds-btn,
  .ds-input,
  .ds-select,
  .ds-textarea {
    transition: none;
  }
}

/* Divider */
.ds-divider {
  border: none;
  border-top: var(--bmi-border-width) solid rgb(var(--bmi-border));
  margin: var(--bmi-space-4) 0;
}

/* Tabs */
.ds-tabs {
  display: flex;
  align-items: center;
  gap: var(--bmi-space-4);
  border-bottom: var(--bmi-border-width) solid rgb(var(--bmi-border));
}

.ds-tab {
  display: inline-flex;
  align-items: center;
  padding: var(--bmi-space-3) 0;
  font-size: 14px;
  font-weight: 600;
  color: rgb(var(--bmi-text-muted));
  text-decoration: none;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  margin-bottom: -1px;
}

.ds-tab:hover {
  color: rgb(var(--bmi-text));
}

.ds-tab.is-active {
  color: rgb(var(--bmi-text));
  border-bottom-color: rgb(var(--bmi-accent));
}

/* Alerts */
.ds-alert {
  display: flex;
  gap: var(--bmi-space-3);
  padding: var(--bmi-space-3) var(--bmi-space-4);
  border-left: 3px solid transparent;
  border-radius: var(--bmi-radius-control);
  font-size: 14px;
}

.ds-alert--info {
  background-color: rgb(var(--bmi-info-wash));
  border-left-color: rgb(var(--bmi-info));
  color: rgb(var(--bmi-text));
}

.ds-alert--success {
  background-color: rgb(var(--bmi-success-wash));
  border-left-color: rgb(var(--bmi-success));
  color: rgb(var(--bmi-text));
}

.ds-alert--warning {
  background-color: rgb(var(--bmi-warning-wash));
  border-left-color: rgb(var(--bmi-warning));
  color: rgb(var(--bmi-text));
}

.ds-alert--danger {
  background-color: rgb(var(--bmi-error-wash));
  border-left-color: rgb(var(--bmi-error));
  color: rgb(var(--bmi-text));
}

/* Brand compatibility layer
   Keeps older Bootstrap/Tailwind-heavy templates aligned with the current
   heritage theme while they are migrated to ds-* components. */
:root {
  --brand: rgb(var(--bmi-accent));
  --brand-hover: rgb(var(--bmi-accent-hover));
  --brand-gold: #f59e0b;
  --brand-ivory: rgb(var(--bmi-bg));
}

body {
  background-color: rgb(var(--bmi-bg));
  color: rgb(var(--bmi-text-muted));
}

a {
  color: rgb(var(--bmi-accent));
}

a:hover {
  color: rgb(var(--bmi-accent-hover));
}

.btn,
button,
input,
select,
textarea {
  border-radius: var(--bmi-radius-control);
}

.btn-primary,
.btn-success,
.bg-primary,
.bg-success,
.bg-accent,
.bg-brand {
  background-color: rgb(var(--bmi-accent)) !important;
  border-color: rgb(var(--bmi-accent)) !important;
  color: rgb(var(--bmi-accent-contrast)) !important;
}

.btn-primary:hover,
.btn-success:hover,
.bg-accent-hover,
.hover\:bg-accent-hover:hover,
.hover\:bg-brand-hover:hover {
  background-color: rgb(var(--bmi-accent-hover)) !important;
  border-color: rgb(var(--bmi-accent-hover)) !important;
  color: rgb(var(--bmi-accent-contrast)) !important;
}

.btn-outline-primary {
  border-color: rgb(var(--bmi-accent)) !important;
  color: rgb(var(--bmi-accent)) !important;
}

.btn-outline-primary:hover {
  background-color: rgb(var(--bmi-accent)) !important;
  color: rgb(var(--bmi-accent-contrast)) !important;
}

.text-primary,
.text-accent,
.text-blue-600,
.text-blue-700,
.hover\:text-accent:hover {
  color: rgb(var(--bmi-accent)) !important;
}

.border-primary,
.border-accent,
.border-blue-500,
.focus\:border-blue-500:focus {
  border-color: rgb(var(--bmi-accent)) !important;
}

.ring-accent,
.focus\:ring-accent:focus,
.focus\:ring-blue-500:focus {
  --tw-ring-color: rgb(var(--bmi-focus)) !important;
}

.bg-blue-50,
.bg-blue-100,
.bg-accent\/10,
.bg-accent\/20 {
  background-color: rgb(var(--bmi-accent-light)) !important;
}

.bg-blue-600,
.bg-blue-700,
.hover\:bg-blue-700:hover,
.hover\:bg-blue-800:hover {
  background-color: rgb(var(--bmi-accent)) !important;
  color: rgb(var(--bmi-accent-contrast)) !important;
}

.card,
.modal-content,
.dropdown-menu,
.list-group-item {
  background-color: rgb(var(--bmi-surface));
  border-color: rgb(var(--bmi-border));
}

.table thead,
.table-light,
.thead-light {
  background-color: rgb(var(--bmi-surface-raised)) !important;
}

.form-control:focus,
.form-select:focus,
.form-check-input:focus {
  border-color: rgb(var(--bmi-focus));
  box-shadow: 0 0 0 0.2rem rgb(var(--bmi-focus) / 0.2);
}

.badge.bg-warning,
.alert-warning {
  background-color: rgb(var(--bmi-warning-wash)) !important;
  color: rgb(var(--bmi-warning)) !important;
  border-color: rgb(var(--bmi-border));
}

.alert-info,
.alert-primary {
  background-color: rgb(var(--bmi-info-wash)) !important;
  color: rgb(var(--bmi-text)) !important;
  border-color: rgb(var(--bmi-border));
}
