/* ==========================================================================
   Component library — buttons, cards, badges, forms, tables, overlays, nav
   ========================================================================== */

/* ---------------------------------- Buttons ---------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-weight: 600;
  font-size: var(--fs-sm);
  border-radius: var(--radius-md);
  padding: 0.7rem 1.4rem;
  border: 1px solid transparent;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  transition: transform var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out),
              background-color var(--dur-fast) var(--ease-out), border-color var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn-lg { padding: 0.9rem 1.9rem; font-size: var(--fs-base); border-radius: var(--radius-lg); }
.btn-sm { padding: 0.4rem 0.9rem; font-size: var(--fs-xs); border-radius: var(--radius-sm); }
.btn-icon { padding: 0.6rem; width: 40px; height: 40px; border-radius: var(--radius-md); }

.btn-primary {
  background: var(--gradient-brand);
  background-size: 160% 160%;
  color: #fff;
  box-shadow: var(--shadow-brand);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 18px 40px rgba(213, 24, 45, 0.34); background-position: 100% 0; }

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-primary);
  border-color: var(--border-default);
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--border-strong); }

.btn-outline {
  background: transparent;
  color: var(--brand-600);
  border-color: var(--brand-300);
}
[data-theme="dark"] .btn-outline { color: var(--brand-400); border-color: rgba(213,24,45,0.4); }
.btn-outline:hover { background: var(--brand-50); transform: translateY(-2px); }
[data-theme="dark"] .btn-outline:hover { background: rgba(213,24,45,0.12); }

.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-surface-2); color: var(--text-primary); }

.btn-danger { background: var(--danger-500); color: #fff; }
.btn-danger:hover { transform: translateY(-2px); box-shadow: 0 14px 32px rgba(240, 68, 56, 0.32); }

.btn-dark { background: var(--ink-950); color: #fff; }
[data-theme="dark"] .btn-dark { background: var(--ink-25); color: var(--ink-950); }
.btn-dark:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.btn-block { width: 100%; }
.btn[disabled] { opacity: 0.55; cursor: not-allowed; transform: none !important; }

/* Ripple */
.ripple-wrap { position: relative; overflow: hidden; }
.ripple-el {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  transform: scale(0);
  animation: ripple 600ms var(--ease-out);
  pointer-events: none;
}
.btn-secondary .ripple-el, .btn-outline .ripple-el, .btn-ghost .ripple-el { background: rgba(213, 24, 45, 0.18); }

/* ---------------------------------- Cards ---------------------------------- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-base) var(--ease-out), box-shadow var(--dur-base) var(--ease-out), border-color var(--dur-base) var(--ease-out);
}
.card-lift:hover { transform: translateY(-6px); box-shadow: var(--shadow-lg); border-color: var(--border-default); }
.card-body { padding: var(--space-6); }
.card-pad-lg { padding: var(--space-8); }

.card-glass {
  background: var(--bg-glass);
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
  border: 1px solid rgba(255,255,255,0.35);
}
[data-theme="dark"] .card-glass { border-color: rgba(255,255,255,0.08); }

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-base) var(--ease-out), box-shadow var(--dur-base) var(--ease-out);
}
.stat-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }
.stat-card .stat-icon {
  width: 46px; height: 46px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  background: var(--brand-50); color: var(--brand-600);
}
[data-theme="dark"] .stat-card .stat-icon { background: rgba(213,24,45,0.14); color: var(--brand-400); }
.stat-card .stat-value { font-size: var(--fs-3xl); font-weight: 800; letter-spacing: -0.02em; }
.stat-card .stat-label { font-size: var(--fs-sm); color: var(--text-secondary); font-weight: 600; }
.stat-delta { display: inline-flex; align-items: center; gap: 4px; font-size: var(--fs-xs); font-weight: 700; padding: 2px 8px; border-radius: var(--radius-full); width: fit-content; }
.stat-delta.up { color: var(--success-500); background: var(--success-100); }
.stat-delta.down { color: var(--danger-500); background: var(--danger-100); }
[data-theme="dark"] .stat-delta.up { background: rgba(18,183,106,0.15); }
[data-theme="dark"] .stat-delta.down { background: rgba(240,68,56,0.15); }

.pricing-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-2xl);
  padding: var(--space-8);
  position: relative;
  transition: transform var(--dur-base) var(--ease-out), box-shadow var(--dur-base) var(--ease-out), border-color var(--dur-base) var(--ease-out);
}
.pricing-card:hover { transform: translateY(-8px); box-shadow: var(--shadow-lg); }
.pricing-card.featured {
  border: 2px solid var(--brand-500);
  box-shadow: var(--shadow-brand);
  background: var(--gradient-brand-soft);
}
.pricing-card .badge-featured {
  position: absolute; top: -14px; left: 50%; transform: translateX(-50%);
  background: var(--gradient-brand); color: #fff; font-size: var(--fs-xs); font-weight: 700;
  padding: 6px 18px; border-radius: var(--radius-full); box-shadow: var(--shadow-brand);
}

/* ---------------------------------- Badges / Pills ---------------------------------- */
.badge-pill {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: 0.01em;
  padding: 4px 12px; border-radius: var(--radius-full);
  border: 1px solid transparent;
}
.badge-pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--success-100); color: #067647; }
.badge-warning { background: var(--warning-100); color: #93370d; }
.badge-danger  { background: var(--danger-100); color: #b42318; }
.badge-info    { background: var(--info-100); color: #344054; }
.badge-brand   { background: var(--brand-50); color: var(--brand-700); }
[data-theme="dark"] .badge-success { background: rgba(18,183,106,0.15); color: #3fdb8f; }
[data-theme="dark"] .badge-warning { background: rgba(247,144,9,0.15); color: #ffb648; }
[data-theme="dark"] .badge-danger  { background: rgba(240,68,56,0.15); color: #ff8177; }
[data-theme="dark"] .badge-info    { background: rgba(255,255,255,0.08); color: var(--ink-300); }
[data-theme="dark"] .badge-brand   { background: rgba(213,24,45,0.15); color: var(--brand-400); }

/* ---------------------------------- Alerts ---------------------------------- */
.alert-modern {
  display: flex; gap: var(--space-3); align-items: flex-start;
  padding: var(--space-4) var(--space-5);
  border-radius: var(--radius-md);
  border: 1px solid;
  font-size: var(--fs-sm);
}
.alert-modern.alert-success { background: var(--success-100); border-color: #a6f4c5; color: #067647; }
.alert-modern.alert-warning { background: var(--warning-100); border-color: #fedf89; color: #93370d; }
.alert-modern.alert-danger  { background: var(--danger-100); border-color: #fda29b; color: #b42318; }
.alert-modern.alert-info    { background: var(--brand-50); border-color: var(--brand-100); color: var(--brand-700); }
[data-theme="dark"] .alert-modern.alert-success { background: rgba(18,183,106,0.12); border-color: rgba(18,183,106,0.3); color: #3fdb8f; }
[data-theme="dark"] .alert-modern.alert-warning { background: rgba(247,144,9,0.12); border-color: rgba(247,144,9,0.3); color: #ffb648; }
[data-theme="dark"] .alert-modern.alert-danger  { background: rgba(240,68,56,0.12); border-color: rgba(240,68,56,0.3); color: #ff8177; }
[data-theme="dark"] .alert-modern.alert-info    { background: rgba(213,24,45,0.12); border-color: rgba(213,24,45,0.3); color: var(--brand-400); }

/* ---------------------------------- Toasts ---------------------------------- */
.toast-stack { position: fixed; top: 20px; right: 20px; z-index: 1080; display: flex; flex-direction: column; gap: 10px; width: 340px; max-width: calc(100vw - 32px); }
.toast-modern {
  background: var(--bg-elevated); border: 1px solid var(--border-subtle); border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg); padding: var(--space-4); display: flex; gap: var(--space-3); align-items: flex-start;
  animation: toastIn var(--dur-base) var(--ease-out);
}
@keyframes toastIn { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: translateX(0); } }
.toast-modern .toast-icon { width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

/* ---------------------------------- Forms ---------------------------------- */
.form-floating-modern { position: relative; }
.form-control-modern, .form-select-modern {
  width: 100%; background: var(--bg-surface); border: 1.5px solid var(--border-default);
  border-radius: var(--radius-md); padding: 0.85rem 1rem; font-size: var(--fs-sm); color: var(--text-primary);
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out);
}
.form-control-modern:focus, .form-select-modern:focus {
  outline: none; border-color: var(--brand-500); box-shadow: 0 0 0 4px var(--brand-50);
}
[data-theme="dark"] .form-control-modern:focus, [data-theme="dark"] .form-select-modern:focus { box-shadow: 0 0 0 4px rgba(213,24,45,0.16); }
.form-control-modern.is-invalid { border-color: var(--danger-500); }
.form-control-modern.is-valid { border-color: var(--success-500); }
.form-label-modern { font-size: var(--fs-sm); font-weight: 600; color: var(--text-primary); margin-bottom: var(--space-2); display: block; }
.form-hint { font-size: var(--fs-xs); color: var(--text-tertiary); margin-top: 4px; }
.form-error { font-size: var(--fs-xs); color: var(--danger-500); margin-top: 4px; font-weight: 600; }

.input-icon-group { position: relative; }
.input-icon-group .form-control-modern { padding-left: 2.7rem; }
.input-icon-group .input-icon { position: absolute; left: 1rem; top: 50%; transform: translateY(-50%); color: var(--text-tertiary); }

.check-modern { display: flex; align-items: center; gap: var(--space-2); cursor: pointer; }
.check-modern input { width: 18px; height: 18px; accent-color: var(--brand-500); cursor: pointer; }

.switch-modern { position: relative; display: inline-block; width: 42px; height: 24px; }
.switch-modern input { opacity: 0; width: 0; height: 0; }
.switch-slider { position: absolute; inset: 0; background: var(--border-default); border-radius: var(--radius-full); cursor: pointer; transition: background var(--dur-fast); }
.switch-slider::before { content: ''; position: absolute; height: 18px; width: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform var(--dur-fast) var(--ease-out); box-shadow: var(--shadow-xs); }
.switch-modern input:checked + .switch-slider { background: var(--gradient-brand); }
.switch-modern input:checked + .switch-slider::before { transform: translateX(18px); }

/* ---------------------------------- Tables ---------------------------------- */
/* No overflow:hidden here on purpose — row-action dropdown menus (position:absolute) live
   inside this wrapper, and clipping would cut them off for any row near the bottom of the
   table. Rounded corners are instead carved directly into the corner cells below. */
.table-modern-wrap { border: 1px solid var(--border-subtle); border-radius: var(--radius-xl); background: var(--bg-surface); }
.table-modern { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table-modern thead th {
  text-align: left; font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-tertiary); font-weight: 700; padding: var(--space-4) var(--space-5);
  background: var(--bg-surface-2); border-bottom: 1px solid var(--border-subtle); white-space: nowrap;
}
.table-modern thead tr:first-child th:first-child { border-top-left-radius: var(--radius-xl); }
.table-modern thead tr:first-child th:last-child { border-top-right-radius: var(--radius-xl); }
.table-modern tbody td { padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border-subtle); color: var(--text-primary); vertical-align: middle; }
.table-modern tbody tr:last-child td { border-bottom: none; }
.table-modern tbody tr { transition: background var(--dur-fast); }
.table-modern tbody tr:hover { background: var(--bg-surface-2); }
.table-modern tbody tr:last-child:hover td:first-child { border-bottom-left-radius: var(--radius-xl); }
.table-modern tbody tr:last-child:hover td:last-child { border-bottom-right-radius: var(--radius-xl); }
.table-modern .cell-muted { color: var(--text-tertiary); }

.pagination-modern { display: flex; align-items: center; justify-content: space-between; padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border-subtle); flex-wrap: wrap; gap: var(--space-3); }
.pagination-modern .page-btns { display: flex; gap: 6px; }
.pagination-modern .page-btn {
  width: 34px; height: 34px; border-radius: var(--radius-sm); border: 1px solid var(--border-default);
  display: flex; align-items: center; justify-content: center; font-size: var(--fs-xs); font-weight: 700;
  background: var(--bg-surface); color: var(--text-secondary); cursor: pointer; transition: all var(--dur-fast);
}
.pagination-modern .page-btn:hover { border-color: var(--brand-400); color: var(--brand-600); }
.pagination-modern .page-btn.active { background: var(--gradient-brand); color: #fff; border-color: transparent; }
.pagination-modern .page-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination-modern .page-btn:disabled:hover { border-color: var(--border-default); color: var(--text-secondary); }

/* ---------------------------------- Avatar ---------------------------------- */
.avatar-modern { width: 40px; height: 40px; border-radius: var(--radius-md); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: var(--fs-sm); background: var(--gradient-brand); color: #fff; flex-shrink: 0; }
.avatar-sm { width: 30px; height: 30px; font-size: var(--fs-xs); }
.avatar-lg { width: 56px; height: 56px; font-size: 1.4rem; border-radius: var(--radius-lg); }
.avatar-modern.avatar-img { background: var(--bg-surface-2); padding: 0; overflow: hidden; }
.avatar-modern.avatar-img img { width: 100%; height: 100%; object-fit: cover; }
.avatar-stack { display: flex; }
.avatar-stack .avatar-modern { margin-left: -10px; border: 2px solid var(--bg-surface); }
.avatar-stack .avatar-modern:first-child { margin-left: 0; }

/* ---------------------------------- Progress ---------------------------------- */
.progress-modern { width: 100%; height: 8px; background: var(--bg-surface-2); border-radius: var(--radius-full); overflow: hidden; }
.progress-modern-bar { height: 100%; background: var(--gradient-brand); border-radius: var(--radius-full); transition: width var(--dur-slow) var(--ease-out); }

/* ---------------------------------- Skeleton ---------------------------------- */
.skeleton {
  background: linear-gradient(90deg, var(--bg-surface-2) 25%, var(--border-subtle) 37%, var(--bg-surface-2) 63%);
  background-size: 400px 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: var(--radius-sm);
}

/* ---------------------------------- Empty state ---------------------------------- */
.empty-state { text-align: center; padding: var(--space-16) var(--space-6); }
.empty-state .empty-icon {
  width: 76px; height: 76px; border-radius: 50%; margin: 0 auto var(--space-5);
  display: flex; align-items: center; justify-content: center; font-size: 2rem;
  background: var(--brand-50); color: var(--brand-500);
}
[data-theme="dark"] .empty-state .empty-icon { background: rgba(213,24,45,0.12); }

/* ---------------------------------- Tabs ---------------------------------- */
.tabs-modern { display: flex; gap: var(--space-2); border-bottom: 1px solid var(--border-subtle); overflow-x: auto; }
.tabs-modern .tab-item {
  padding: var(--space-3) var(--space-4); font-size: var(--fs-sm); font-weight: 600; color: var(--text-secondary);
  border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap; transition: all var(--dur-fast);
}
.tabs-modern .tab-item:hover { color: var(--text-primary); }
.tabs-modern .tab-item.active { color: var(--brand-600); border-color: var(--brand-500); }
[data-theme="dark"] .tabs-modern .tab-item.active { color: var(--brand-400); }

/* ---------------------------------- Accordion ---------------------------------- */
.accordion-modern .acc-item { border: 1px solid var(--border-subtle); border-radius: var(--radius-md); margin-bottom: var(--space-3); overflow: hidden; background: var(--bg-surface); }
.accordion-modern .acc-header {
  display: flex; align-items: center; justify-content: space-between; padding: var(--space-4) var(--space-5);
  cursor: pointer; font-weight: 700; font-size: var(--fs-base);
}
.accordion-modern .acc-header .acc-icon { transition: transform var(--dur-base) var(--ease-out); color: var(--brand-500); }
.accordion-modern .acc-item.open .acc-icon { transform: rotate(45deg); }
.accordion-modern .acc-body { max-height: 0; overflow: hidden; transition: max-height var(--dur-slow) var(--ease-out); padding: 0 var(--space-5); }
.accordion-modern .acc-item.open .acc-body { padding-bottom: var(--space-5); }

/* ---------------------------------- Modal ---------------------------------- */
.modal-modern .modal-content { border-radius: var(--radius-xl); border: 1px solid var(--border-subtle); background: var(--bg-elevated); box-shadow: var(--shadow-xl); }
.modal-modern .modal-header, .modal-modern .modal-footer { border-color: var(--border-subtle); }

/* ---------------------------------- Breadcrumb ---------------------------------- */
.breadcrumb-modern { display: flex; align-items: center; gap: var(--space-2); font-size: var(--fs-sm); color: var(--text-tertiary); flex-wrap: wrap; }
.breadcrumb-modern a { color: var(--text-secondary); font-weight: 600; }
.breadcrumb-modern a:hover { color: var(--brand-600); }
.breadcrumb-modern .sep { opacity: 0.5; }
.breadcrumb-modern .current { color: var(--text-primary); font-weight: 700; }

/* ---------------------------------- Dropdown ---------------------------------- */
.dropdown-modern { position: relative; }
.dropdown-modern .dropdown-menu-modern {
  border-radius: var(--radius-md); border: 1px solid var(--border-subtle); box-shadow: var(--shadow-lg);
  background: var(--bg-elevated); padding: var(--space-2); min-width: 220px;
}
.dropdown-modern .dropdown-item-modern {
  display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm); font-size: var(--fs-sm); font-weight: 500; color: var(--text-primary); cursor: pointer;
}
.dropdown-modern .dropdown-item-modern:hover { background: var(--bg-surface-2); color: var(--brand-600); }

/* Generic Bootstrap .dropdown-menu polish, so every native Bootstrap dropdown (row action
   menus, filters, etc.) matches the design system without needing a bespoke class each time. */
.dropdown-menu {
  border-radius: var(--radius-md); border: 1px solid var(--border-subtle); box-shadow: var(--shadow-lg);
  background: var(--bg-elevated); padding: var(--space-2); font-family: var(--font-base);
}
.dropdown-menu .dropdown-item { border-radius: var(--radius-sm); font-size: var(--fs-sm); font-weight: 500; padding: 6px 10px; color: var(--text-primary); display: flex; align-items: center; gap: 8px; }
.dropdown-menu .dropdown-item:hover, .dropdown-menu .dropdown-item:focus { background: var(--bg-surface-2); color: var(--brand-600); }
.dropdown-menu .dropdown-item.text-danger:hover, .dropdown-menu .dropdown-item.text-danger:focus { background: var(--danger-100); color: var(--danger-500); }
.dropdown-menu .dropdown-divider { border-color: var(--border-subtle); margin: 6px 0; }
.row-action-btn {
  width: 32px; height: 32px; border-radius: var(--radius-sm); border: 1px solid var(--border-default);
  background: var(--bg-surface); display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-secondary); cursor: pointer; transition: all var(--dur-fast);
}
.row-action-btn:hover { border-color: var(--border-strong); color: var(--text-primary); }

/* ---------------------------------- Icon badge ----------------------------------
   Generic rounded icon container (confirm dialogs, empty-ish states, etc). Note:
   auth.css also has a visually identical .auth-card .auth-eyebrow-icon, but that rule
   is scoped to .auth-card — it doesn't apply outside the auth split-screen pages, so
   anything else (confirm modals in particular) needs this unscoped version instead. */
.icon-badge-lg {
  width: 52px; height: 52px; border-radius: var(--radius-lg); background: var(--brand-50); color: var(--brand-600);
  display: flex; align-items: center; justify-content: center; font-size: 1.4rem; margin-bottom: var(--space-5);
}
[data-theme="dark"] .icon-badge-lg { background: rgba(213, 24, 45, 0.14); color: var(--brand-400); }

/* ---------------------------------- Loader ---------------------------------- */
.spinner-modern { width: 20px; height: 20px; border: 2.5px solid rgba(255,255,255,0.35); border-top-color: #fff; border-radius: 50%; animation: spin 0.7s linear infinite; }
.spinner-brand { border: 2.5px solid var(--brand-100); border-top-color: var(--brand-500); }

/* ---------------------------------- Section headers ---------------------------------- */
.section-head { max-width: 640px; margin-inline: auto; text-align: center; margin-bottom: var(--space-16); }
.section-head.align-left { margin-inline: 0; text-align: left; }
.section-head h2 { font-size: var(--fs-4xl); margin-block: var(--space-4); }
@media (max-width: 768px) { .section-head h2 { font-size: var(--fs-3xl); } }
