/* ============================================
   Buttons
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 1.25rem;
  font-size: var(--font-size-sm);
  font-weight: 600;
  font-family: var(--font-family);
  border-radius: var(--border-radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.5;
  position: relative;
}
.btn:hover {
  text-decoration: none;
  transform: translateY(-1px);
}
.btn:active {
  transform: translateY(0);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}
.btn:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
}

.btn-primary {
  background: var(--gradient-primary);
  color: white;
  border-color: transparent;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}
.btn-primary:hover:not(:disabled) {
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
  filter: brightness(1.05);
}

.btn-secondary {
  background: var(--bg-primary);
  color: var(--text-primary);
  border-color: var(--border-primary);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--bg-tertiary);
  border-color: var(--border-secondary);
}

.btn-success {
  background: var(--gradient-success);
  color: white;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
}
.btn-success:hover:not(:disabled) {
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
  filter: brightness(1.05);
}

.btn-danger {
  background: var(--gradient-danger);
  color: white;
  box-shadow: 0 2px 8px rgba(244, 63, 94, 0.3);
}
.btn-danger:hover:not(:disabled) {
  box-shadow: 0 6px 20px rgba(244, 63, 94, 0.4);
  filter: brightness(1.05);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}
.btn-ghost:hover {
  transform: none;
}

.btn-sm { padding: 0.3rem 0.75rem; font-size: var(--font-size-xs); }
.btn-lg { padding: 0.7rem 1.75rem; font-size: var(--font-size-base); }
.btn-icon {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: var(--border-radius-sm);
}
.btn-icon:hover { transform: none; }
.btn-block { width: 100%; }

/* ============================================
   Forms
   ============================================ */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: 600;
  margin-bottom: 0.4rem;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

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

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.625rem 0.9375rem;
  font-size: var(--font-size-sm);
  font-family: var(--font-family);
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1.5px solid var(--border-primary);
  border-radius: var(--border-radius-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  line-height: 1.5;
}

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

.form-input::placeholder {
  color: var(--text-tertiary);
  font-weight: 400;
}

.form-input.error {
  border-color: var(--danger-500);
  box-shadow: var(--shadow-focus-danger);
}

.form-error {
  font-size: var(--font-size-xs);
  color: var(--danger-500);
  margin-top: 0.25rem;
}

.form-help {
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
  margin-top: 0.25rem;
}

.form-textarea { min-height: 80px; resize: vertical; }

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.875rem center;
  padding-right: 2.25rem;
}

.form-checkbox-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.form-checkbox {
  width: 18px;
  height: 18px;
  accent-color: var(--primary-600);
  border-radius: var(--border-radius-xs);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

/* ============================================
   Cards
   ============================================ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-card);
  transition: box-shadow var(--transition-base), transform var(--transition-base);
  padding: 1.5rem;
}

.card:hover {
  box-shadow: var(--shadow-card-hover);
}

.card-header {
  padding: 1.125rem 1.5rem;
  border-bottom: 1px solid var(--border-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h3 {
  font-size: var(--font-size-base);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.card-body {
  padding: 1.5rem;
}

.card-footer {
  padding: 0.875rem 1.5rem;
  border-top: 1px solid var(--border-primary);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* ============================================
   Stat Cards
   ============================================ */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-primary);
  border-radius: var(--border-radius-lg);
  padding: 1.375rem 1.5rem;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  transition: box-shadow var(--transition-base), transform var(--transition-base);
  border-left: 4px solid var(--primary-400);
  box-shadow: var(--shadow-card);
}

.stat-card:nth-child(1) { border-left-color: #6366f1; }
.stat-card:nth-child(2) { border-left-color: #10b981; }
.stat-card:nth-child(3) { border-left-color: #0ea5e9; }
.stat-card:nth-child(4) { border-left-color: #f59e0b; }

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

.stat-card-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--border-radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1.25rem;
}

.stat-card-icon.blue {
  background: linear-gradient(135deg, #eef2ff, #e0e7ff);
  color: #4f46e5;
}
.stat-card-icon.green {
  background: linear-gradient(135deg, #ecfdf5, #d1fae5);
  color: #059669;
}
.stat-card-icon.yellow {
  background: linear-gradient(135deg, #fffbeb, #fef3c7);
  color: #d97706;
}
.stat-card-icon.red {
  background: linear-gradient(135deg, #fff1f2, #ffe4e6);
  color: #e11d48;
}
.stat-card-icon.sky {
  background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
  color: #0284c7;
}

[data-theme="dark"] .stat-card-icon.blue { background: rgba(99,102,241,0.15); }
[data-theme="dark"] .stat-card-icon.green { background: rgba(16,185,129,0.15); }
[data-theme="dark"] .stat-card-icon.yellow { background: rgba(245,158,11,0.15); }
[data-theme="dark"] .stat-card-icon.red { background: rgba(244,63,94,0.15); }
[data-theme="dark"] .stat-card-icon.sky { background: rgba(14,165,233,0.15); }

.stat-card-value {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.03em;
  color: var(--text-primary);
}

.stat-card-label {
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
  font-weight: 600;
  letter-spacing: 0.01em;
  margin-top: 0.125rem;
  text-transform: uppercase;
}

/* ============================================
   Tables
   ============================================ */
.table-container {
  overflow-x: auto;
  border: 1px solid var(--border-primary);
  border-radius: var(--border-radius-lg);
  background: var(--bg-card);
  box-shadow: var(--shadow-card);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-sm);
}

.data-table th {
  background: var(--bg-secondary);
  padding: 0.875rem 1rem;
  text-align: left;
  font-weight: 700;
  font-size: var(--font-size-xs);
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border-primary);
  white-space: nowrap;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.data-table td {
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border-primary);
  color: var(--text-primary);
}

.data-table tbody tr {
  transition: background var(--transition-fast);
}

.data-table tbody tr:nth-child(even) {
  background: var(--bg-secondary);
}

.data-table tbody tr:hover {
  background: var(--primary-50);
}

[data-theme="dark"] .data-table tbody tr:hover {
  background: rgba(99, 102, 241, 0.06);
}

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

/* ============================================
   Badges
   ============================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  font-size: var(--font-size-xs);
  font-weight: 600;
  border-radius: var(--border-radius-full);
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.badge-primary { background: #eef2ff; color: #4f46e5; }
.badge-success { background: #ecfdf5; color: #047857; }
.badge-warning { background: #fffbeb; color: #b45309; }
.badge-danger { background: #fff1f2; color: #be123c; }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }
.badge-info { background: #f0f9ff; color: #0369a1; }

[data-theme="dark"] .badge-primary { background: rgba(99,102,241,0.2); color: #a5b4fc; }
[data-theme="dark"] .badge-success { background: rgba(16,185,129,0.2); color: #6ee7b7; }
[data-theme="dark"] .badge-warning { background: rgba(245,158,11,0.2); color: #fcd34d; }
[data-theme="dark"] .badge-danger { background: rgba(244,63,94,0.2); color: #fda4af; }
[data-theme="dark"] .badge-gray { background: rgba(107,114,128,0.2); color: var(--gray-300); }
[data-theme="dark"] .badge-info { background: rgba(14,165,233,0.2); color: #7dd3fc; }

/* ============================================
   Modal
   ============================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-modal-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal);
  padding: 1rem;
  backdrop-filter: blur(8px);
}

.modal {
  position: fixed;
  inset: 0;
  background: var(--bg-modal-overlay);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: var(--z-modal, 1000);
  padding: 1rem;
  backdrop-filter: blur(8px);
}

.modal.modal-open {
  display: flex;
}

.modal-content {
  background: var(--bg-primary);
  border-radius: var(--border-radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  animation: modalFadeIn 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-content.modal-lg,
.modal-lg > .modal-content { max-width: 800px; }
.modal-content.modal-xl,
.modal-xl > .modal-content { max-width: 1100px; }

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: var(--font-size-lg);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-primary);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* ============================================
   Toast / Notification
   ============================================ */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--border-radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 320px;
  max-width: 420px;
  animation: toastSlideIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  backdrop-filter: blur(10px);
  font-weight: 500;
}

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

@keyframes toastSlideIn {
  from { transform: translateX(100%) scale(0.95); opacity: 0; }
  to { transform: translateX(0) scale(1); opacity: 1; }
}

/* ============================================
   Pagination
   ============================================ */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1rem;
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.pagination-btn {
  padding: 0.375rem 0.7rem;
  border: 1px solid var(--border-primary);
  background: var(--bg-primary);
  color: var(--text-primary);
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  font-size: var(--font-size-sm);
  transition: all var(--transition-fast);
  font-weight: 500;
}
.pagination-btn:hover:not(:disabled) {
  background: var(--bg-tertiary);
  border-color: var(--primary-300);
}
.pagination-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination-btn.active {
  background: var(--gradient-primary);
  color: white;
  border-color: transparent;
  box-shadow: 0 2px 6px rgba(99, 102, 241, 0.3);
}

/* ============================================
   Tabs
   ============================================ */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--border-primary);
  gap: 0;
}

.tab {
  padding: 0.75rem 1.25rem;
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--text-tertiary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all var(--transition-fast);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
  font-family: var(--font-family);
}
.tab:hover {
  color: var(--text-primary);
}
.tab.active {
  color: var(--primary-600);
  border-bottom-color: var(--primary-600);
  font-weight: 700;
}

/* ============================================
   Search
   ============================================ */
.search-input-wrapper {
  position: relative;
}
.search-input-wrapper .search-icon {
  position: absolute;
  left: 0.875rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  pointer-events: none;
}
.search-input-wrapper .form-input {
  padding-left: 2.5rem;
}

/* ============================================
   Empty State
   ============================================ */
.empty-state {
  text-align: center;
  padding: 3.5rem 1.5rem;
  color: var(--text-secondary);
}

.empty-state-icon {
  font-size: 3.5rem;
  margin-bottom: 1rem;
  opacity: 0.4;
}

.empty-state-title {
  font-size: var(--font-size-lg);
  font-weight: 700;
  margin-bottom: 0.375rem;
  color: var(--text-primary);
}

.empty-state-text {
  font-size: var(--font-size-sm);
  max-width: 400px;
  margin: 0 auto;
  color: var(--text-tertiary);
  line-height: 1.6;
}

/* ============================================
   Loading / Spinner
   ============================================ */
.spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid var(--border-primary);
  border-top-color: var(--primary-500);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.spinner-lg { width: 36px; height: 36px; border-width: 3px; }

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

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  backdrop-filter: blur(4px);
}

[data-theme="dark"] .loading-overlay {
  background: rgba(15,23,42,0.8);
}

/* ============================================
   Dropdown
   ============================================ */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.375rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--border-radius-md);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  z-index: var(--z-dropdown);
  padding: 0.375rem;
  animation: dropdownFadeIn 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.75rem;
  font-size: var(--font-size-sm);
  color: var(--text-primary);
  border-radius: var(--border-radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: var(--font-family);
  font-weight: 500;
}
.dropdown-item:hover {
  background: var(--bg-tertiary);
  color: var(--primary-600);
}
.dropdown-divider {
  height: 1px;
  background: var(--border-primary);
  margin: 0.375rem 0;
}

/* ============================================
   Avatar
   ============================================ */
.avatar {
  width: 38px;
  height: 38px;
  border-radius: var(--border-radius-full);
  background: var(--gradient-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: var(--font-size-sm);
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(99, 102, 241, 0.3);
}
.avatar-sm { width: 28px; height: 28px; font-size: var(--font-size-xs); }
.avatar-lg { width: 48px; height: 48px; font-size: var(--font-size-lg); }

/* ============================================
   Alerts
   ============================================ */
.alert {
  padding: 0.875rem 1.125rem;
  border-radius: var(--border-radius-md);
  font-size: var(--font-size-sm);
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  line-height: 1.5;
  font-weight: 500;
}

.alert-info { background: #eef2ff; color: #4338ca; border: 1px solid #c7d2fe; }
.alert-success { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.alert-danger { background: #fff1f2; color: #be123c; border: 1px solid #fecdd3; }

/* ============================================
   Signature Canvas
   ============================================ */
.signature-canvas-container {
  border: 2px dashed var(--border-primary);
  border-radius: var(--border-radius-md);
  padding: 0.25rem;
  background: var(--bg-primary);
  transition: border-color var(--transition-fast);
  position: relative;
}

.signature-canvas-container:hover,
.signature-canvas-container.active {
  border-color: var(--primary-400);
}

.signature-canvas-container.signed {
  border-style: solid;
  border-color: var(--success-500);
}

.signature-canvas {
  display: block;
  width: 100%;
  height: 150px;
  cursor: crosshair;
  border-radius: var(--border-radius-sm);
  touch-action: none;
}

.signature-canvas-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.375rem;
}

.signature-canvas-hint {
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
}

/* ============================================
   Logo Upload
   ============================================ */
.logo-upload-area {
  border: 2px dashed var(--border-primary);
  border-radius: var(--border-radius-lg);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  background: var(--bg-secondary);
}

.logo-upload-area:hover {
  border-color: var(--primary-400);
  background: var(--primary-50);
}

.logo-upload-area.has-logo {
  border-style: solid;
  border-color: var(--border-primary);
  padding: 1rem;
}

.logo-upload-preview {
  width: 80px;
  height: 80px;
  border-radius: var(--border-radius-md);
  object-fit: contain;
  margin: 0 auto 0.75rem;
  display: block;
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
}

.logo-upload-icon {
  font-size: 2rem;
  color: var(--text-tertiary);
  margin-bottom: 0.5rem;
  opacity: 0.5;
}

.logo-upload-text {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
}

.logo-upload-hint {
  font-size: var(--font-size-xs);
  color: var(--text-tertiary);
  margin-top: 0.25rem;
}

/* =============================================================================
   Control Tower overrides — applies new design tokens to legacy components
   so existing pages inherit the premium look automatically.
   ============================================================================= */

/* --- Buttons --- */
.btn {
  border-radius: var(--radius-control);
  font-family: var(--font-primary);
  font-weight: 600;
  font-size: 14px;
  line-height: 20px;
  padding: 9px 16px;
  letter-spacing: -0.005em;
  transition: all var(--motion-hover) var(--motion-ease);
}
.btn:hover { transform: translateY(-1px); }
.btn-sm { padding: 6px 12px; font-size: 13px; line-height: 18px; border-radius: 10px; }
.btn-lg { padding: 12px 22px; font-size: 15px; line-height: 22px; }
.btn-icon { width: 40px; height: 40px; border-radius: var(--radius-control); }

.btn-primary {
  background: var(--brand-primary);
  border-color: var(--brand-primary);
  box-shadow: 0 1px 2px rgba(67, 56, 202, 0.16), 0 0 0 1px rgba(67, 56, 202, 0.08) inset;
}
.btn-primary:hover:not(:disabled) {
  background: var(--brand-primary-hover);
  box-shadow: 0 6px 18px rgba(67, 56, 202, 0.28), 0 0 0 1px rgba(67, 56, 202, 0.16) inset;
}
.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border-subtle);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--brand-primary-soft);
  border-color: var(--brand-primary);
  color: var(--brand-primary);
}
.btn-ghost { color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) {
  background: var(--brand-primary-soft);
  color: var(--brand-primary);
}
.btn-success { background: var(--state-success); border-color: var(--state-success); }
.btn-success:hover:not(:disabled) { background: #0F6B30; filter: none; }
.btn-danger  { background: var(--state-danger);  border-color: var(--state-danger); }
.btn-danger:hover:not(:disabled)  { background: #A81818; filter: none; }
.btn-warning { background: var(--state-warning); border-color: var(--state-warning); color: white; }

/* --- Inputs --- */
.form-input,
.form-select,
.form-textarea,
input[type="text"]:not(.search-input):not(.global-search__input),
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"]:not(.global-search__input),
input[type="date"],
input[type="time"],
input[type="datetime-local"],
select:not(.form-select),
textarea {
  height: 40px;
  padding: 0 14px;
  font-family: var(--font-primary);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-control);
  transition: all var(--motion-hover) var(--motion-ease);
  line-height: 1.4;
  width: 100%;
}
textarea, .form-textarea { height: auto; padding: 10px 14px; resize: vertical; min-height: 80px; }
.form-input:hover, .form-select:hover { border-color: var(--border-default); }
.form-input:focus, .form-select:focus, textarea:focus,
input:focus, select:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: var(--shadow-focus);
}
.form-input::placeholder, textarea::placeholder { color: var(--text-tertiary); }
.form-label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: -0.005em;
}
.form-error { display: block; color: var(--state-danger); font-size: 12px; margin-top: 4px; }
.form-group { margin-bottom: 14px; }

.search-input {
  height: 40px;
  padding: 0 14px 0 38px;
  border-radius: var(--radius-control);
}
.search-container { position: relative; }

/* --- Card (legacy class, now bridge to .surface) --- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow var(--motion-hover) var(--motion-ease);
}
.card:hover { box-shadow: var(--shadow-md); }
.card-header, .card-body, .card-footer { padding: 18px 20px; }
.card-header { border-bottom: 1px solid var(--border-subtle); }
.card-body { padding: 20px; }

/* --- Badges --- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-primary);
  border-radius: var(--radius-pill);
  letter-spacing: 0.02em;
  line-height: 18px;
}
.badge-primary   { background: var(--brand-primary-soft);  color: var(--brand-primary); }
.badge-secondary { background: var(--state-neutral-soft);  color: var(--text-secondary); }
.badge-success   { background: var(--state-success-soft);  color: var(--state-success); }
.badge-warning   { background: var(--state-warning-soft);  color: var(--state-warning); }
.badge-danger    { background: var(--state-danger-soft);   color: var(--state-danger); }
.badge-info      { background: var(--state-info-soft);     color: var(--state-info); }

/* --- Tables --- */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-family: var(--font-primary);
}
.table thead th {
  padding: 10px 14px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  color: var(--text-tertiary);
  background: var(--bg-canvas);
  border-bottom: 1px solid var(--border-default);
  text-align: left;
  white-space: nowrap;
  position: sticky;
  top: 0;
}
.table tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  height: 48px;
}
.table tbody tr {
  transition: background var(--motion-hover) var(--motion-ease);
}
.table tbody tr:hover { background: var(--bg-surface-alt); }
.table tbody tr:last-child td { border-bottom: none; }

/* --- Modals ---
   NOTE: Legacy pages use <div class="modal"> as the overlay (hidden by
   default, shown when .modal-open is present) and <div class="modal-content">
   for the inner card. New pages use <div class="modal-overlay"> + <div class="modal">.
   We style BOTH conventions without breaking the hide/show behavior.
-------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed !important;
  inset: 0 !important;
  z-index: 9000 !important;             /* force above sticky rails and top-nav */
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-overlay);
  backdrop-filter: blur(var(--blur-glass-soft));
  -webkit-backdrop-filter: blur(var(--blur-glass-soft));
  padding: 20px;
}
/* Inner card (both .modal-content legacy AND .modal-overlay > .modal new) */
.modal-content,
.modal-overlay > .modal {
  background: var(--bg-surface);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 40px);
  display: flex; flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border-subtle);
}
/* Legacy overlay behavior preserved: .modal hidden until .modal-open.
   Use :has() to scope this ONLY to the legacy pattern (.modal > .modal-content)
   so new-pattern cards (<div class="modal-overlay"><div class="modal">...</div></div>)
   are NOT hidden. */
.modal:has(> .modal-content):not(.modal-open) {
  display: none !important;
}
.modal-header {
  padding: 20px 24px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
}
.modal-header h2, .modal-header h3 {
  font-size: 18px; line-height: 24px; font-weight: 600; margin: 0;
}
.modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 14px 24px;
  display: flex; gap: 12px; justify-content: flex-end;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-canvas);
}
.btn-close {
  background: transparent; border: none;
  width: 32px; height: 32px;
  border-radius: var(--radius-control);
  color: var(--text-tertiary);
  cursor: pointer;
  font-size: 20px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all var(--motion-hover) var(--motion-ease);
}
.btn-close:hover { background: var(--bg-canvas); color: var(--text-primary); }

/* --- Toast --- */
.toast-container {
  position: fixed;
  top: 88px;
  right: 24px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-left-width: 4px;
  border-radius: var(--radius-control);
  box-shadow: var(--shadow-md);
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  pointer-events: auto;
  animation: slideIn 220ms var(--motion-spring);
  min-width: 280px;
}
.toast-info    { border-left-color: var(--state-info); }
.toast-success { border-left-color: var(--state-success); }
.toast-warning { border-left-color: var(--state-warning); }
.toast-error, .toast-danger { border-left-color: var(--state-danger); }
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* --- Spinner --- */
.spinner {
  width: 22px; height: 22px;
  border: 2px solid var(--border-subtle);
  border-top-color: var(--brand-primary);
  border-radius: 50%;
  animation: spin 600ms linear infinite;
}
.spinner-lg { width: 36px; height: 36px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Avatar --- */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  background: var(--gradient-brand);
  color: white;
  font-size: 13px;
  font-weight: 700;
  border-radius: 50%;
  font-family: var(--font-primary);
}
.avatar-sm { width: 28px; height: 28px; font-size: 11px; }
.avatar-lg { width: 48px; height: 48px; font-size: 16px; }

/* --- Alert --- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-control);
  font-size: 13px;
  border: 1px solid transparent;
  margin-bottom: 12px;
}
.alert-info    { background: var(--state-info-soft);    color: var(--state-info);    border-color: rgba(3, 105, 161, 0.20); }
.alert-success { background: var(--state-success-soft); color: var(--state-success); border-color: rgba(21, 127, 59, 0.20); }
.alert-warning { background: var(--state-warning-soft); color: var(--state-warning); border-color: rgba(179, 90, 0, 0.20); }
.alert-danger  { background: var(--state-danger-soft);  color: var(--state-danger);  border-color: rgba(200, 30, 30, 0.20); }

/* --- Page header (legacy wrapper) --- */
.page-header {
  margin-bottom: 20px;
}
.page-header h1 {
  font-size: var(--type-page-title-size);
  line-height: calc(var(--type-page-title-lh) / var(--type-page-title-size));
  font-weight: var(--type-page-title-weight);
  margin: 0 0 4px;
}
.page-header p, .page-header .text-muted {
  color: var(--text-secondary);
  font-size: 14px;
}

/* --- Empty state (legacy) --- */
.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-tertiary);
}

/* --- Auth card (login) — premium look --- */
.auth-layout {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(ellipse at top left, rgba(67, 56, 202, 0.15) 0%, transparent 50%),
              radial-gradient(ellipse at bottom right, rgba(96, 165, 250, 0.15) 0%, transparent 50%),
              var(--bg-canvas);
}
.auth-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-lg);
  padding: 40px;
  width: 100%;
  max-width: 440px;
}
.auth-logo {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 24px;
}
.auth-logo-icon {
  width: 48px; height: 48px;
  background: var(--gradient-brand);
  border-radius: var(--radius-control);
  color: white;
  font-weight: 800;
  font-size: 18px;
  display: inline-flex; align-items: center; justify-content: center;
}
.auth-logo-text { font-size: 22px; font-weight: 700; color: var(--text-primary); }
.auth-title {
  font-size: 24px; line-height: 32px; font-weight: 650;
  margin: 0 0 8px;
}
.auth-subtitle {
  font-size: 14px; color: var(--text-secondary); margin-bottom: 20px;
}

/* --- Utility helpers used in the app --- */
.d-flex { display: flex; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.align-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
