/**
 * Component Utilities & Base Styles
 * ========================================
 * Reusable component patterns and utility classes
 */

/* ========================================
   BUTTONS
   ======================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--padding-md) var(--padding-lg);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  line-height: var(--line-height-normal);
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: var(--transition-default);
  text-decoration: none;
  gap: var(--gap-sm);
  min-height: var(--button-height-md);
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Button Variants */
.btn-primary {
  background: var(--gradient-primary);
  color: var(--text-inverse);
  border: 2px solid transparent;
  box-shadow: var(--shadow-primary);
}

.btn-primary:hover {
  filter: brightness(1.04);
  box-shadow: var(--elevation-2);
}

.btn-primary:focus {
  outline: none;
  box-shadow: var(--focus-ring);
}

.btn-secondary {
  background: var(--gradient-secondary);
  color: var(--text-inverse);
}

.btn-secondary:hover {
  background-color: var(--color-secondary-dark);
  box-shadow: var(--elevation-2);
}

.btn-outline {
  background-color: transparent;
  color: var(--color-primary);
  border: 2px solid color-mix(in srgb, var(--color-primary) 44%, var(--border-medium));
}

.btn-outline:hover {
  background-color: var(--color-primary-lighter);
}

.btn-ghost {
  background-color: transparent;
  color: var(--color-primary);
  border: none;
}

.btn-ghost:hover {
  background-color: var(--bg-tertiary);
}

.btn-danger {
  background-color: var(--color-error);
  color: var(--text-inverse);
}

.btn-danger:hover {
  background-color: var(--color-error-dark);
}

.btn-success {
  background-color: var(--color-success);
  color: var(--text-inverse);
}

.btn-success:hover {
  background-color: var(--color-success-dark);
}

/* Button Sizes */
.btn-sm {
  padding: var(--padding-sm) var(--padding-md);
  min-height: var(--button-height-sm);
  font-size: var(--text-xs);
}

.btn-lg {
  padding: var(--padding-lg) var(--padding-xl);
  min-height: var(--button-height-lg);
  font-size: var(--text-base);
}

.btn-full {
  width: 100%;
}

/* ========================================
   CARDS
   ======================================== */

.card {
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--surface-strong) 100%, transparent), color-mix(in srgb, var(--surface-raised) 98%, transparent));
  border-radius: var(--radius-lg);
  border: 1px solid var(--chrome-border);
  padding: var(--padding-lg);
  box-shadow: var(--elevation-1);
  transition: var(--transition-default);
}

.card:hover {
  box-shadow: var(--elevation-2);
  border-color: var(--border-medium);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--spacing-6);
  padding-bottom: var(--spacing-4);
  border-bottom: 1px solid var(--border-light);
}

.card-header h3 {
  margin: 0;
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: var(--gap-md);
}

.card-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--gap-md);
  margin-top: var(--spacing-6);
  padding-top: var(--spacing-4);
  border-top: 1px solid var(--border-light);
}

.card-title {
  margin: 0;
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
}

.card-actions {
  display: flex;
  align-items: center;
  gap: var(--gap-sm);
  margin-inline-start: auto;
}

.card-content {
  display: flex;
  flex-direction: column;
  gap: var(--gap-md);
  padding: var(--space-6);
  flex: 1;
}

.card-flat {
  box-shadow: none;
  background: color-mix(in srgb, var(--panel-bg) 92%, transparent);
}

/* ========================================
   INPUT & FORM ELEMENTS
   ======================================== */

.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--gap-sm);
  margin-bottom: var(--spacing-6);
}

label {
  font-weight: var(--font-medium);
  font-size: var(--text-sm);
  color: var(--text-primary);
}

.form-label-required::after {
  content: ' *';
  color: var(--color-error);
}

input:not([type='checkbox']):not([type='radio']):not([type='range']):not([type='file']):not([type='color']):not([type='submit']):not([type='button']):not([type='reset']),
textarea,
select,
.form-control,
.form-select {
  width: 100%;
  padding: var(--padding-md);
  min-height: var(--input-height-md);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  font-size: var(--text-base);
  font-family: inherit;
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--surface-strong) 94%, transparent), color-mix(in srgb, var(--bg-primary) 96%, transparent));
  color: var(--text-primary);
  box-shadow: inset 0 1px 0 color-mix(in srgb, var(--surface-strong) 72%, transparent);
  transition:
    border-color var(--transition-fast),
    box-shadow var(--transition-fast),
    background-color var(--transition-fast),
    transform var(--transition-fast);
}

input:not([type='checkbox']):not([type='radio']):not([type='range']):not([type='file']):not([type='color']):not([type='submit']):not([type='button']):not([type='reset'])::placeholder,
textarea::placeholder,
.form-control::placeholder,
.form-select::placeholder {
  color: var(--text-tertiary);
}

input:not([type='checkbox']):not([type='radio']):not([type='range']):not([type='file']):not([type='color']):not([type='submit']):not([type='button']):not([type='reset']):hover,
textarea:hover,
select:hover,
.form-control:hover,
.form-select:hover {
  border-color: color-mix(in srgb, var(--color-primary) 18%, var(--border-medium));
}

input:focus,
textarea:focus,
select:focus,
.form-control:focus,
.form-select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: var(--focus-ring);
}

/* Dark mode — card and form field depth */
[data-theme='dark'] .card {
  border-color: var(--chrome-border);
  background: linear-gradient(180deg, var(--surface-strong), var(--surface-raised));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.03),
    0 20px 40px -28px rgba(0, 0, 0, 0.7);
}

[data-theme='dark'] .card:hover {
  border-color: var(--border-medium);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    0 26px 48px -30px rgba(0, 0, 0, 0.85);
}

[data-theme='dark'] input:not([type='checkbox']):not([type='radio']):not([type='range']):not([type='file']):not([type='color']):not([type='submit']):not([type='button']):not([type='reset']),
[data-theme='dark'] textarea,
[data-theme='dark'] select,
[data-theme='dark'] .form-control,
[data-theme='dark'] .form-select {
  border-color: var(--border-medium);
  background: var(--surface-subtle);
}

[data-theme='dark'] select,
[data-theme='dark'] .form-select,
[data-theme='dark'] select.form-control {
  color-scheme: dark;
}

[data-theme='dark'] input[type='date'],
[data-theme='dark'] input[type='time'],
[data-theme='dark'] input[type='datetime-local'],
[data-theme='dark'] input[type='month'],
[data-theme='dark'] input[type='week'] {
  color-scheme: dark;
}

[data-theme='dark'] select option,
[data-theme='dark'] .form-select option,
[data-theme='dark'] .form-control option {
  background-color: var(--bg-primary);
  color: var(--text-primary);
}

[data-theme='dark'] input[type='file'],
[data-theme='dark'] .form-control[type='file'] {
  background: var(--surface-subtle);
  border-color: var(--border-medium);
}

[data-theme='dark'] input[type='file']::file-selector-button,
[data-theme='dark'] .form-control[type='file']::file-selector-button {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.28);
  color: var(--color-primary-light);
}

[data-theme='dark'] .settings-panel {
  border-color: var(--chrome-border);
  background: linear-gradient(180deg, var(--surface-strong), var(--surface-raised));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.03),
    0 20px 40px -28px rgba(0, 0, 0, 0.7);
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible,
button:focus-visible,
.btn:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--color-primary) 65%, var(--surface-strong));
  outline-offset: 2px;
}

input:disabled,
textarea:disabled,
select:disabled,
.form-control:disabled,
.form-select:disabled {
  background-color: var(--bg-tertiary);
  cursor: not-allowed;
  opacity: 0.6;
}

select option,
.form-select option,
.form-control option {
  background-color: var(--bg-primary);
  color: var(--text-primary);
}

select optgroup,
.form-select optgroup,
.form-control optgroup {
  background-color: var(--bg-primary);
  color: var(--text-secondary);
}

select option:checked,
.form-select option:checked,
.form-control option:checked {
  background: color-mix(in srgb, var(--color-primary) 22%, var(--bg-primary));
  color: var(--text-primary);
}

input[type='file'],
.form-control[type='file'] {
  width: 100%;
  min-height: var(--input-height-md);
  padding: var(--space-2);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--surface-strong) 94%, transparent), color-mix(in srgb, var(--bg-primary) 96%, transparent));
  color: var(--text-primary);
  box-shadow: inset 0 1px 0 color-mix(in srgb, var(--surface-strong) 72%, transparent);
}

input[type='file']::file-selector-button,
.form-control[type='file']::file-selector-button {
  margin-inline-end: var(--space-3);
  padding: 0.55rem 0.9rem;
  border: 1px solid color-mix(in srgb, var(--color-primary) 16%, var(--border-medium));
  border-radius: calc(var(--radius-md) - 0.2rem);
  background: color-mix(in srgb, var(--color-primary) 10%, var(--bg-primary));
  color: var(--color-primary);
  font: inherit;
  font-weight: var(--font-semibold);
  cursor: pointer;
  transition: var(--transition-fast-default);
}

input[type='file']::file-selector-button:hover,
.form-control[type='file']::file-selector-button:hover {
  background: color-mix(in srgb, var(--color-primary) 16%, var(--bg-primary));
  border-color: color-mix(in srgb, var(--color-primary) 28%, var(--border-medium));
}

textarea {
  resize: vertical;
  min-height: 120px;
}

.field-control {
  width: 100%;
  min-height: var(--input-height-md);
}

/* Suppress double-indicator only for pointer users; keyboard users still get the outline */
.field-control:focus:not(:focus-visible) {
  outline: none;
}

.field-sm {
  min-height: var(--input-height-sm);
}

.field-md {
  min-height: var(--input-height-md);
}

.field-lg {
  min-height: var(--input-height-lg);
}

.form-control-sm,
.form-select-sm {
  min-height: var(--input-height-sm);
  padding: 0.4rem 0.75rem;
  font-size: var(--text-sm);
  border-radius: var(--radius-sm);
}

input[type='checkbox'],
input[type='radio'] {
  cursor: pointer;
  accent-color: var(--color-primary);
}

/* ========================================
   SETTINGS PANELS
   ======================================== */

.settings-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  padding: var(--space-4);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  background: color-mix(in srgb, var(--panel-bg) 92%, transparent);
}

/* Relying on generic variables instead of explicitly redefining Settings Panel in dark mode */

.settings-panel-header {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.settings-panel-header h3 {
  margin: 0;
  font-size: var(--text-base);
}

.settings-edit-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-4);
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.settings-input {
  min-height: var(--input-height-lg);
  padding-inline: 1rem;
  border-radius: var(--radius-md);
  border-color: var(--border-light);
  background: var(--bg-primary);
  box-shadow: none;
}

.settings-textarea {
  min-height: 7rem;
  padding-block: 0.85rem;
  resize: vertical;
}

.settings-toggles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-3);
}

.settings-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--input-height-lg);
  padding: 0.85rem 1rem;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  color: var(--text-primary);
}

.settings-checkbox {
  margin: 0;
}

.settings-actions {
  display: flex;
  justify-content: flex-start;
}

/* Form Validation */
.form-group.is-invalid label {
  color: var(--color-error);
}

.form-group.is-invalid input,
.form-group.is-invalid textarea,
.form-group.is-invalid select {
  border-color: var(--color-error);
}

input:invalid,
textarea:invalid,
select:invalid {
  border-color: color-mix(in srgb, var(--color-error) 70%, var(--border-medium));
}

/* Blazor EditContext validation — uses .invalid class, not :invalid pseudo-class */
.field-control.invalid,
input.invalid,
select.invalid,
textarea.invalid {
  border-color: var(--color-error);
  background-color: color-mix(in srgb, var(--color-error) 4%, var(--bg-primary));
}

.field-control.invalid:focus,
input.invalid:focus,
select.invalid:focus,
textarea.invalid:focus {
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.18);
  border-color: var(--color-error);
}

.form-field-error {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.form-field-error input,
.form-field-error textarea,
.form-field-error select {
  border-color: var(--color-error);
  background-color: color-mix(in srgb, var(--color-error) 4%, var(--bg-primary));
}

.form-error {
  font-size: var(--text-xs);
  color: var(--color-error);
  margin-top: var(--space-1);
}

.form-help {
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

/* Required field legend */
.form-required-legend {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin: 0;
}

.form-required-legend span[aria-hidden] {
  color: var(--color-error);
  font-weight: var(--font-bold);
  margin-inline-end: var(--space-1);
}

/* Fieldset section grouping */
fieldset.form-section {
  border: none;
  padding: 0;
  margin: 0;
}

.form-section-legend {
  font-size: var(--text-lg);
  font-weight: var(--font-bold);
  color: var(--text-primary);
  padding: 0;
  margin-bottom: var(--space-4);
  letter-spacing: var(--letter-spacing-tight);
}

/* Validation summary banner (above action row) */
.validation-summary-errors {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border-left: 4px solid var(--color-error);
  background-color: var(--color-error-light);
  color: var(--color-error-dark);
  font-size: var(--text-sm);
}

.validation-summary-errors ul {
  margin: var(--space-1) 0 0;
  padding-inline-start: var(--space-5);
}

.validation-summary-errors li {
  margin-top: var(--space-1);
}

/* ========================================
   ALERTS & NOTIFICATIONS
   ======================================== */

.alert {
  padding: var(--padding-md) var(--padding-lg);
  border-radius: var(--radius-md);
  border-left: 4px solid;
  display: flex;
  align-items: flex-start;
  gap: var(--gap-md);
  margin-bottom: var(--spacing-4);
  animation: slideDown 300ms ease-out;
}

.alert-success {
  background-color: var(--color-success-light);
  border-left-color: var(--color-success);
  color: var(--color-success-dark);
}

.alert-warning {
  background-color: var(--color-warning-light);
  border-left-color: var(--color-warning);
  color: var(--color-warning-dark);
}

.alert-error {
  background-color: var(--color-error-light);
  border-left-color: var(--color-error);
  color: var(--color-error-dark);
}

.alert-info {
  background-color: var(--color-info-light);
  border-left-color: var(--color-info);
  color: var(--color-info-dark);
}

.alert-icon {
  font-size: var(--font-size-lg);
  flex-shrink: 0;
}

.alert-close {
  background: none;
  border: none;
  font-size: var(--font-size-xl);
  cursor: pointer;
  color: inherit;
  opacity: 0.7;
  transition: opacity var(--duration-fast);
  margin-inline-start: auto;
  flex-shrink: 0;
}

.alert-close:hover {
  opacity: 1;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ========================================
   BADGES & TAGS
   ======================================== */

.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  border-radius: var(--radius-full);
  width: fit-content;
}

.badge-primary {
  background-color: var(--color-primary-lighter);
  color: var(--color-primary-dark);
}

.badge-success {
  background-color: var(--color-success-light);
  color: var(--color-success-dark);
}

.badge-warning {
  background-color: var(--color-warning-light);
  color: var(--color-warning-dark);
}

.badge-error {
  background-color: var(--color-error-light);
  color: var(--color-error-dark);
}

.badge-info {
  background-color: var(--color-info-light);
  color: var(--color-info-dark);
}

/* ========================================
   LOADING STATES
   ======================================== */

.spinner {
  display: inline-block;
  width: 1.5rem;
  height: 1.5rem;
  border: 3px solid var(--border-light);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.spinner-lg {
  width: 3rem;
  height: 3rem;
}

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

.skeleton {
  background: linear-gradient(
    90deg,
    var(--border-light) 25%,
    var(--bg-tertiary) 50%,
    var(--border-light) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 2s infinite;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* ========================================
   TABLES
   ======================================== */

.table {
  width: 100%;
  border-collapse: collapse;
  background-color: var(--bg-primary);
}

.table thead th {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  font-weight: var(--font-semibold);
  font-size: var(--text-sm);
  padding: var(--padding-md) var(--padding-lg);
  text-align: start;
  border-bottom: 2px solid var(--border-medium);
}

.table tbody td {
  padding: var(--padding-md) var(--padding-lg);
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

.table tbody tr:hover {
  background-color: var(--bg-secondary);
}

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

/* ========================================
   UTILITIES
   ======================================== */

.clearfix::after {
  content: '';
  display: table;
  clear: both;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.line-clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.gap-sm {
  gap: var(--gap-sm);
}

.gap-md {
  gap: var(--gap-md);
}

.gap-lg {
  gap: var(--gap-lg);
}

/* Responsive Grid */
.grid-auto {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: var(--gap-lg);
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--gap-lg);
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--gap-lg);
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap-lg);
}

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

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

/* Margin Utilities */
.mb-x {
  margin-bottom: var(--spacing-4);
}

.mb-lg {
  margin-bottom: var(--spacing-8);
}

.mt-lg {
  margin-top: var(--spacing-8);
}

.p-md {
  padding: var(--padding-md);
}

.p-lg {
  padding: var(--padding-lg);
}

/* ========================================
   TOAST NOTIFICATIONS
   ======================================== */

.toast-container {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-width: 380px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  pointer-events: all;
  transition:
    opacity var(--duration-base) var(--easing-standard),
    transform var(--duration-base) var(--easing-standard);
}

.toast-enter {
  opacity: 1;
  transform: translateX(0);
}

.toast-exit {
  opacity: 0;
  transform: translateX(100%);
}

.toast-success { border-left: 4px solid var(--color-success); }
.toast-error   { border-left: 4px solid var(--color-error); }
.toast-warning { border-left: 4px solid var(--color-warning); }
.toast-info    { border-left: 4px solid var(--color-info); }

.toast-success .toast-icon { color: var(--color-success); }
.toast-error   .toast-icon { color: var(--color-error); }
.toast-warning .toast-icon { color: var(--color-warning); }
.toast-info    .toast-icon { color: var(--color-info); }

.toast-icon {
  font-size: var(--font-size-base);
  flex-shrink: 0;
  margin-top: 1px;
}

.toast-content {
  flex: 1;
}

.toast-message {
  font-size: var(--text-sm);
  color: var(--text-primary);
  line-height: var(--line-height-normal);
}

.toast-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-tertiary);
  font-size: 1rem;
  line-height: 1;
  padding: 0;
  flex-shrink: 0;
  transition: color var(--duration-fast);
}

.toast-close:hover {
  color: var(--text-primary);
}

/* ========================================
   DIALOG / MODAL
   ======================================== */

.dialog-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  padding: var(--space-4);
}

.dialog-container {
  background: var(--bg-primary);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-2xl);
  width: 100%;
  max-width: 720px;
  max-height: min(92vh, 960px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-5) var(--space-6);
  border-bottom: 1px solid var(--border-light);
}

.dialog-title {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  margin: 0;
}

.dialog-close-btn {
  background: none;
  border: none;
  font-size: var(--font-size-lg);
  cursor: pointer;
  color: var(--text-tertiary);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  transition: background var(--duration-fast), color var(--duration-fast);
}

.dialog-close-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.dialog-body {
  padding: var(--space-6);
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.dialog-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-light);
}

/* ========================================
   SHELL PAGE PATTERNS
   ======================================== */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.page-header-content {
  flex: 1;
  min-width: 0;
}

.page-title {
  margin: 0 0 var(--space-2);
  font-size: var(--text-heading-page, clamp(1.75rem, 2.8vw, 2.25rem));
  font-weight: var(--font-heading-display, 800);
  color: var(--text-primary);
  letter-spacing: var(--letter-spacing-heading-xl, -0.04em);
  line-height: var(--line-height-tight);
}

.page-description {
  margin: 0;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  line-height: var(--line-height-relaxed);
  margin-block-start: var(--space-1);
}

.page-header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  flex-wrap: wrap;
}

/* ========================================
   ADMIN WORKSPACE
   ======================================== */

.admin-page {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.admin-tabbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  padding: var(--space-5);
}

.admin-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 var(--space-4);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-full);
  background: color-mix(in srgb, var(--surface-subtle) 92%, transparent);
  color: var(--text-secondary);
  font-weight: var(--font-semibold);
  cursor: pointer;
  text-decoration: none;
  transition: var(--transition-default);
}

.admin-tab:hover {
  border-color: var(--border-medium);
  color: var(--text-primary);
}

.admin-tab.active,
.admin-navlink.active {
  background: var(--gradient-primary);
  border-color: transparent;
  color: var(--text-inverse);
  box-shadow: var(--shadow-primary);
}

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

.admin-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
  padding: var(--space-5);
}

.admin-section-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
}

.admin-kicker {
  display: inline-block;
  margin-bottom: var(--space-2);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: var(--font-size-xs);
  font-weight: var(--font-extrabold);
  color: var(--text-tertiary);
}

.admin-section-header h2,
.admin-section-header h3 {
  margin: 0;
}

.admin-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-3);
}

.metric-card {
  padding: var(--space-4);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  background: var(--bg-tertiary);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.metric-card span {
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
}

.metric-card strong {
  font-size: var(--font-size-xl);
}

.admin-empty-state {
  display: grid;
  place-items: center;
  min-height: 180px;
  padding: var(--space-5);
  border: 1px dashed var(--border-light);
  border-radius: var(--radius-xl);
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  text-align: center;
}

/* ========================================
   SHARED SMALL COMPONENT HELPERS
   ======================================== */

.spinner-mini {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.btn-primary .spinner-mini,
.btn-danger .spinner-mini,
.btn-secondary .spinner-mini,
.btn-success .spinner-mini {
  border-color: rgba(255, 255, 255, 0.28);
  border-top-color: currentColor;
}

/* ========================================
   DARK MODE COMPONENT OVERRIDES
   ======================================== */

/* Alerts */
[data-theme="dark"] .alert-success {
  background-color: rgba(16, 185, 129, 0.14);
  border-left-color: #10b981;
  color: #34d399;
}
[data-theme="dark"] .alert-warning {
  background-color: rgba(251, 191, 36, 0.14);
  border-left-color: #fbbf24;
  color: #fcd34d;
}
[data-theme="dark"] .alert-error {
  background-color: rgba(239, 68, 68, 0.14);
  border-left-color: #ef4444;
  color: #f87171;
}
[data-theme="dark"] .alert-info {
  background-color: rgba(14, 165, 233, 0.14);
  border-left-color: #0ea5e9;
  color: #38bdf8;
}

/* Badges */
[data-theme="dark"] .badge-primary {
  background-color: rgba(16, 185, 129, 0.20);
  color: #34d399;
}
[data-theme="dark"] .badge-success {
  background-color: rgba(16, 185, 129, 0.20);
  color: #34d399;
}
[data-theme="dark"] .badge-warning {
  background-color: rgba(251, 191, 36, 0.20);
  color: #fcd34d;
}
[data-theme="dark"] .badge-error {
  background-color: rgba(239, 68, 68, 0.20);
  color: #f87171;
}
[data-theme="dark"] .badge-info {
  background-color: rgba(14, 165, 233, 0.20);
  color: #38bdf8;
}

/* Toast */
[data-theme="dark"] .toast {
  background: var(--surface-strong);
  border-color: var(--border-light);
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255, 255, 255, 0.04);
}

/* Metric card */
[data-theme="dark"] .metric-card {
  background: var(--surface-subtle);
  border-color: var(--border-light);
}

/* Validation summary */
[data-theme="dark"] .validation-summary-errors {
  background-color: rgba(239, 68, 68, 0.14);
  border-left-color: #ef4444;
  color: #f87171;
}

/* Table */
[data-theme="dark"] .table thead th {
  background-color: var(--surface-strong);
  border-bottom-color: var(--border-medium);
  color: var(--text-secondary);
}
[data-theme="dark"] .table tbody tr:hover {
  background-color: var(--surface-subtle);
}
[data-theme="dark"] .table tbody td {
  border-bottom-color: var(--border-light);
}

/* Admin empty state */
[data-theme="dark"] .admin-empty-state {
  background: var(--surface-subtle);
  border-color: var(--border-light);
}

/* ========================================
   BOOTSTRAP COMPATIBILITY LAYER
   ======================================== */

.container-fluid {
  width: 100%;
}

.row {
  display: flex;
  flex-wrap: wrap;
  margin-inline: calc(var(--space-3) * -1);
}

.row > [class*='col-'] {
  min-width: 0;
  width: 100%;
  padding-inline: var(--space-3);
}

.g-3 {
  row-gap: var(--space-4);
}

.col-4 { flex: 0 0 33.3333%; width: 33.3333%; }
.col-12 { flex: 0 0 100%; width: 100%; }

@media (min-width: 576px) {
  .col-sm-4 { flex: 0 0 33.3333%; width: 33.3333%; }
  .col-sm-8 { flex: 0 0 66.6667%; width: 66.6667%; }
}

@media (min-width: 768px) {
  .col-md-3 { flex: 0 0 25%; width: 25%; }
  .col-md-4 { flex: 0 0 33.3333%; width: 33.3333%; }
  .col-md-6 { flex: 0 0 50%; width: 50%; }
  .col-md-8 { flex: 0 0 66.6667%; width: 66.6667%; }
  .col-md-9 { flex: 0 0 75%; width: 75%; }
}

.d-flex { display: flex; }
.d-block { display: block; }
.justify-content-between { justify-content: space-between; }
.justify-content-around { justify-content: space-around; }
.justify-content-center { justify-content: center; }
.align-items-center { align-items: center; }
.align-items-start { align-items: flex-start; }
.text-center { text-align: center; }
.text-end { text-align: end; }
.flex-shrink-0 { flex-shrink: 0; }
.cursor-pointer { cursor: pointer; }
.opacity-50 { opacity: 0.5; }
.rounded { border-radius: var(--radius-lg); }

.p-0 { padding: 0 !important; }
.p-2 { padding: var(--space-2) !important; }
.p-3 { padding: var(--space-4) !important; }
.px-3 { padding-inline: var(--space-4) !important; }
.py-1 { padding-block: var(--space-1) !important; }
.py-2 { padding-block: var(--space-2) !important; }
.py-3 { padding-block: var(--space-4) !important; }
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: var(--space-1) !important; }
.mb-2 { margin-bottom: var(--space-2) !important; }
.mb-3 { margin-bottom: var(--space-4) !important; }
.mt-1 { margin-top: var(--space-1) !important; }
.mt-2 { margin-top: var(--space-2) !important; }
.mt-3 { margin-top: var(--space-4) !important; }
.me-1 { margin-inline-end: var(--space-1) !important; }
.me-2 { margin-inline-end: var(--space-2) !important; }
.ms-2 { margin-inline-start: var(--space-2) !important; }
.h-100 { height: 100%; }
.w-100 { width: 100%; }
.small { font-size: var(--text-xs); }
.fw-bold { font-weight: var(--font-bold); }
.fs-1 { font-size: 2.5rem; }
.fs-5 { font-size: 1.25rem; }

.text-primary { color: var(--color-primary) !important; }
.text-secondary { color: var(--color-secondary) !important; }
.text-success { color: var(--color-success) !important; }
.text-warning { color: var(--color-warning) !important; }
.text-danger { color: var(--color-error) !important; }
.text-info { color: var(--color-info) !important; }
.text-muted { color: var(--text-secondary) !important; }
.text-white { color: var(--text-inverse) !important; }
.text-dark { color: var(--text-primary) !important; }

.bg-primary { background: var(--color-primary) !important; color: var(--text-inverse) !important; }
.bg-secondary { background: var(--color-secondary) !important; color: var(--text-inverse) !important; }
.bg-success { background: var(--color-success) !important; color: var(--text-inverse) !important; }
.bg-warning { background: var(--color-warning-light) !important; color: var(--color-warning-dark) !important; }
.bg-danger { background: var(--color-error) !important; color: var(--text-inverse) !important; }
.bg-info { background: var(--color-info-light) !important; color: var(--color-info-dark) !important; }
.bg-light { background: var(--bg-tertiary) !important; }

.border { border: 1px solid var(--border-light) !important; }
.border-top { border-top: 1px solid var(--border-light) !important; }
.border-bottom { border-bottom: 1px solid var(--border-light) !important; }
.border-primary { border-color: color-mix(in srgb, var(--color-primary) 60%, white) !important; }
.border-success { border-color: color-mix(in srgb, var(--color-success) 60%, white) !important; }
.border-warning { border-color: color-mix(in srgb, var(--color-warning) 60%, white) !important; }
.border-danger { border-color: color-mix(in srgb, var(--color-error) 60%, white) !important; }

.badge.bg-primary,
.badge.bg-secondary,
.badge.bg-success,
.badge.bg-warning,
.badge.bg-danger,
.badge.bg-info,
.badge.bg-light {
  border-radius: var(--radius-full);
  border: 1px solid transparent;
}

.btn-outline-primary,
.btn-outline-secondary,
.btn-outline-danger,
.btn-outline-light {
  background: transparent;
  border-width: 1px;
  border-style: solid;
}

.btn-outline-primary {
  color: var(--color-primary);
  border-color: color-mix(in srgb, var(--color-primary) 35%, transparent);
}

.btn-outline-primary:hover {
  background: var(--color-primary-lighter);
}

.btn-outline-secondary {
  color: var(--text-primary);
  border-color: var(--border-medium);
}

.btn-outline-secondary:hover,
.btn-light {
  background: var(--bg-tertiary);
}

.btn-outline-light {
  color: var(--text-inverse);
  border-color: rgba(255, 255, 255, 0.34);
}

.btn-outline-light:hover {
  background: rgba(255, 255, 255, 0.14);
}

.btn-outline-danger {
  color: var(--color-error);
  border-color: color-mix(in srgb, var(--color-error) 32%, transparent);
}

.btn-outline-danger:hover {
  background: var(--color-error-light);
}

.btn-group {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.btn-group > .btn {
  border-radius: var(--radius-lg);
}

.form-label {
  display: inline-block;
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-primary);
}

.input-group {
}

@media (max-width: 768px) {
  .page-header-actions {
    justify-content: flex-start;
  }

  .row > [class*='col-'] {
    width: 100%;
    flex-basis: 100%;
  }

  .modal {
    padding: var(--space-3);
  }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding-inline: var(--space-4);
  }

  .admin-tabbar,
  .admin-section {
    padding: var(--space-4);
  }

  .admin-section-header {
    flex-direction: column;
  }
}

/* ========================================
   HIS CLINICAL BADGE VOCABULARY
   Additive — does not replace badge-primary/success/warning/error.
   Requires his-bridge.css (--badge-* and --status-* tokens).
   ======================================== */

.badge-waiting  { background: var(--badge-waiting-bg);   color: var(--badge-waiting-fg); }
.badge-consult  { background: var(--badge-consult-bg);   color: var(--badge-consult-fg); }
.badge-done     { background: var(--badge-done-bg);      color: var(--badge-done-fg); }
.badge-critical { background: var(--status-critical-bg); color: var(--status-critical-fg); }
.badge-urgent   { background: var(--status-urgent-bg);   color: var(--status-urgent-fg); }
.badge-normal   { background: var(--status-success-bg);  color: var(--status-success-fg); }
.badge-sm       { font-size: 10px; padding: 2px 6px; font-weight: var(--font-bold); }

.bdot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
  background: currentColor;
  flex-shrink: 0;
}

/* ========================================
   HIS STAT CARDS
   For dashboard KPI / metric panels.
   ======================================== */

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-muted);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  box-shadow: var(--sh-xs);
  position: relative;
  overflow: hidden;
  transition:
    transform var(--duration-fast, .15s) var(--easing-standard, ease),
    box-shadow var(--duration-fast, .15s) var(--easing-standard, ease);
}

/* Top accent line — replaces left-border-accent anti-pattern */
.stat-card::before {
  content: '';
  position: absolute;
  inset-block-start: 0;
  inset-inline: 0;
  block-size: 2px;
  background: var(--stat-accent, var(--his-500));
  opacity: 0;
  transition: opacity var(--duration-fast, .15s);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--sh-sm);
}

.stat-card:hover::before {
  opacity: 1;
}

.stat-label {
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.stat-value {
  font-size: var(--text-2xl);
  font-weight: var(--font-bold);
  letter-spacing: -.035em;
  line-height: 1;
  margin: 6px 0 4px;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

.stat-sub { font-size: var(--text-xs); color: var(--text-muted); }

.stat-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: var(--font-semibold);
  padding: 2px 7px;
  border-radius: var(--r-pill);
  margin-top: var(--sp-2);
}

.chip-warn    { background: var(--badge-waiting-bg);  color: var(--badge-waiting-fg); }
.chip-success { background: var(--status-success-bg); color: var(--status-success-fg); }
.chip-info    { background: var(--status-info-bg);    color: var(--status-info-fg); }
.chip-primary { background: var(--primary-50);        color: var(--primary-700); }

[data-theme="dark"] .chip-primary {
  background: var(--surface-strong);
  color: var(--color-primary-light);
}

/* ========================================
   HIS DASHBOARD COMPOSITION
   Shared dashboard layout used by module dashboards.
   ======================================== */

.his-dashboard {
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
}

.his-dashboard__kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--sp-4);
}

.his-dashboard__alert-icon {
  inline-size: var(--sp-4);
  block-size: var(--sp-4);
  flex-shrink: 0;
  margin-block-start: var(--sp-1);
}

.his-dashboard__quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--sp-3);
}

.his-dashboard-action {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--bg-surface);
  box-shadow: var(--sh-xs);
  color: var(--text-primary);
  text-decoration: none;
  transition: border-color .15s, box-shadow .15s;
}

.his-dashboard-action:hover {
  border-color: var(--his-400);
  box-shadow: var(--sh-sm);
  transform: translateY(-1px);
}

.his-dashboard-action--primary {
  border-color: var(--his-400);
  background: linear-gradient(
    to bottom right,
    var(--his-50),
    color-mix(in srgb, var(--his-50) 60%, var(--neutral-0, white))
  );
  box-shadow: inset 0 0 0 1px var(--his-200), var(--sh-xs);
}

.his-dashboard-action__badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-inline-size: var(--sp-8);
  block-size: var(--sp-8);
  border-radius: var(--r-md);
  background: var(--gradient-primary);
  color: var(--text-inverse);
  font-size: var(--text-xs);
  font-weight: var(--font-bold);
  flex-shrink: 0;
  box-shadow: 0 4px 8px -2px rgba(15, 118, 110, 0.30);
}

.his-dashboard-action--primary .his-dashboard-action__badge {
  background: var(--his-600);
  color: var(--text-on-brand);
}

[data-theme="dark"] .his-dashboard-action--primary {
  border-color: color-mix(in srgb, var(--his-400) 68%, var(--border));
  background:
    linear-gradient(
      to bottom right,
      color-mix(in srgb, var(--his-800) 42%, var(--surface-strong)),
      color-mix(in srgb, var(--his-900) 28%, var(--surface-raised))
    );
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--his-400) 24%, transparent), var(--sh-xs);
}

[data-theme="dark"] .his-dashboard-action--primary:hover {
  border-color: var(--his-400);
  background:
    linear-gradient(
      to bottom right,
      color-mix(in srgb, var(--his-700) 46%, var(--surface-strong)),
      color-mix(in srgb, var(--his-900) 32%, var(--surface-raised))
    );
}

[data-theme="dark"] .his-dashboard-action--primary .his-dashboard-action__badge {
  background: var(--his-500);
  color: var(--neutral-50);
}

.his-dashboard-action__copy {
  display: flex;
  flex-direction: column;
  min-inline-size: 0;
}

.his-dashboard-action__label {
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
}

.his-dashboard-action__hint {
  color: var(--text-muted);
  font-size: var(--text-xs);
}

.his-dashboard__work-area {
  display: grid;
  gap: var(--sp-4);
}

.his-dashboard__work-area--split {
  grid-template-columns: minmax(0, 1fr) minmax(280px, 30%);
}

.his-dashboard-queue {
  overflow: hidden;
}

.his-dashboard-queue__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.his-dashboard-queue__mrn {
  color: var(--text-secondary);
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
  font-size: var(--text-xs);
}

.his-dashboard-empty-inline {
  color: var(--text-muted);
  padding: var(--sp-4);
  text-align: center;
}

.his-dashboard-detail {
  min-block-size: 320px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.his-dashboard-detail__empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  color: var(--text-muted);
  text-align: center;
}

.his-dashboard-detail__empty strong {
  color: var(--text-secondary);
  font-weight: var(--font-medium);
}

.his-dashboard-detail__icon {
  inline-size: var(--sp-6);
  block-size: var(--sp-6);
  color: var(--text-placeholder);
}

.dashboard-updated {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

@media (max-width: 1100px) {
  .his-dashboard__work-area--split {
    grid-template-columns: 1fr;
  }
}

/* ========================================
   HIS CLINICAL TABLE
   Drop-in for Bootstrap "table table-sm" in clinical contexts.
   ======================================== */

.tbl-wrap { overflow-x: auto; }

.his-table {
  width: 100%;
  border-collapse: collapse;
}

.his-table th {
  padding: var(--sp-3) var(--sp-4);
  text-align: start;
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .07em;
  border-bottom: 1px solid var(--border-muted);
  white-space: nowrap;
}

.his-table td {
  padding: 10px var(--sp-4);
  font-size: var(--text-sm);
  border-bottom: 1px solid var(--border-muted);
  vertical-align: middle;
}

.his-table tbody tr { cursor: pointer; transition: background .1s; }
.his-table tbody tr:hover td { background: var(--bg-raised); }
.his-table tbody tr.row-selected td { background: var(--primary-50); }
.his-table tbody tr:last-child td { border-bottom: none; }

[data-theme="dark"] .his-table tbody tr.row-selected td { background: var(--surface-strong); }

.filter-bar {
  display: flex;
  gap: var(--sp-2);
  align-items: center;
  padding: var(--sp-3) var(--sp-5);
  border-bottom: 1px solid var(--border-muted);
  flex-wrap: wrap;
}

.f-input {
  flex: 1;
  min-width: 140px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-size: var(--text-sm);
  outline: none;
  transition: border-color .14s;
}

.f-input:focus {
  border-color: var(--primary-400);
  background: var(--bg-surface);
}

.f-select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-size: var(--text-sm);
  cursor: pointer;
  outline: none;
}

.f-select:focus { border-color: var(--primary-400); }

/* ========================================
   HIS WITHIN-PAGE SECTION TABS
   For section-level tabs inside a page or panel.
   Does NOT replace ModuleNav (top-level module switcher).
   ======================================== */

.his-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-muted);
  padding: 0 var(--sp-5);
  gap: 2px;
  overflow-x: auto;
}

.his-tabs::-webkit-scrollbar { display: none; }

.his-tab {
  padding: 10px var(--sp-4);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  background: transparent;
  border-top: none;
  border-left: none;
  border-right: none;
  transition: color .13s, border-color .13s;
}

.his-tab:hover { color: var(--text-primary); }

.his-tab.active {
  color: var(--primary-600);
  border-bottom-color: var(--primary-500);
  font-weight: var(--font-semibold);
}

[data-theme="dark"] .his-tab.active {
  color: var(--color-primary-light);
  border-bottom-color: var(--primary-400);
}

/* ========================================
   HIS ALERT BANNERS
   ======================================== */

.his-alert {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  font-size: var(--text-sm);
  margin-bottom: var(--sp-4);
}

.alert-warning {
  background: var(--status-urgent-bg);
  color: var(--status-urgent-fg);
  border: 1px solid var(--urgent-500);
}

.alert-critical {
  background: var(--status-critical-bg);
  color: var(--status-critical-fg);
  border: 1px solid var(--critical-500);
}

.alert-info {
  background: var(--status-info-bg);
  color: var(--status-info-fg);
  border: 1px solid var(--info-500);
}

.alert-close {
  margin-inline-start: auto;
  cursor: pointer;
  opacity: .6;
  font-size: 18px;
  background: none;
  border: none;
  color: inherit;
}

/* ========================================
   HIS CLINICAL LIST PATTERNS
   Compact inline lists for meds, labs, allergies in chart panels.
   ======================================== */

.med-list { padding: var(--sp-3) var(--sp-5); }

.med-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--border-muted);
}

.med-item:last-child { border-bottom: none; }

.med-dot  { width: 8px; height: 8px; border-radius: 50%; background: var(--primary-400); flex-shrink: 0; }
.med-name { font-size: var(--text-sm); font-weight: var(--font-medium); flex: 1; }
.med-dose { font-size: var(--text-xs); color: var(--text-muted); }

.lab-list { padding: var(--sp-3) var(--sp-5); }

.lab-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--border-muted);
}

.lab-item:last-child { border-bottom: none; }

.lab-name  { font-size: var(--text-sm); flex: 1; }
.lab-val   { font-size: var(--text-sm); font-weight: var(--font-semibold); }
.lab-range { font-size: var(--text-xs); color: var(--text-muted); }
.lab-H { color: var(--status-critical-fg); }
.lab-N { color: var(--status-success-fg); }
.lab-L { color: var(--status-info-fg); }

.allergy-tag {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  font-weight: var(--font-semibold);
  padding: 2px 8px;
  border-radius: var(--r-pill);
  background: var(--status-critical-bg);
  color: var(--status-critical-fg);
  margin-inline-end: 4px;
  margin-top: var(--sp-2);
}
