/* ============================================================
   AutoMatch Admin — Enterprise Design System v2
   Global component polish. Loaded after admin.css.
   ============================================================ */

/* ── Shell: topbar alignment ─────────────────────────────────── */
#page-topbar {
  background-color: var(--admin-topbar-bg);
  border-bottom: 1px solid var(--admin-topbar-border);
  box-shadow: none;
}

.navbar-header {
  gap: var(--sp-2);
}

.topbar-controls {
  gap: var(--sp-2);
}

#vertical-menu-btn,
.topbar-controls .theme-toggle,
.topbar-controls .dropdown:not(.user-dropdown) > .header-item {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
}

/* Language pill — must not inherit icon-button 36×36 sizing */
.topbar-controls .lang-toggle,
.auth-header__controls .lang-toggle {
  width: auto;
  min-width: 0;
  height: 34px;
  padding: 2px;
  flex: 0 0 auto;
  border-radius: var(--radius-full);
  justify-content: stretch;
}

.topbar-controls .lang-toggle__option,
.auth-header__controls .lang-toggle__option {
  min-width: 4.25rem;
  padding: 0 10px;
  font-size: 12px;
}

.app-search-box input {
  height: var(--admin-input-height);
  font-size: 13px;
  border-color: var(--border-default);
  background: var(--surface-raised);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast);
}

.app-search-box input:focus {
  border-color: var(--color-primary);
  box-shadow: var(--focus-ring);
  background: var(--surface-base);
}

.user-dropdown .header-item {
  height: var(--admin-input-height);
  padding-inline: 10px;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  background: var(--surface-raised);
}

/* Dropdown dividers — theme-aware (profile menu, notifications, etc.) */
.dropdown-divider,
.user-menu-dropdown .dropdown-divider {
  border-color: var(--border-subtle) !important;
  border-top-color: var(--border-subtle) !important;
  opacity: 1;
}

html[data-theme="dark"] .dropdown-divider,
html[data-theme="dark"] .user-menu-dropdown .dropdown-divider {
  border-color: var(--border-subtle) !important;
  border-top-color: var(--border-subtle) !important;
}

.user-avatar-topbar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: var(--bg-card-elevated);
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

/* ── Sidebar polish ──────────────────────────────────────────── */
.vertical-menu {
  border-inline-end: 1px solid rgba(148, 163, 184, 0.08);
  background: var(--sidebar-bg);
}

.navbar-brand-box {
  border-bottom: 1px solid rgba(148, 163, 184, 0.08);
}

#sidebar-menu .menu-title {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--sidebar-section-color);
  padding: 14px 16px 6px;
  margin-top: 4px;
}

#sidebar-menu ul li > a {
  min-height: 40px;
  margin: 1px 10px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  color: var(--sidebar-item-color);
  gap: 10px;
}

#sidebar-menu ul li > a i {
  font-size: var(--admin-icon-md);
  width: 20px;
  text-align: center;
  color: inherit;
  opacity: 0.85;
}

#sidebar-menu ul li > a:hover {
  color: var(--sidebar-item-active-color);
  background: var(--sidebar-item-hover-bg);
}

#sidebar-menu ul li.mm-active > a {
  color: var(--sidebar-item-active-color);
  background: var(--sidebar-item-active-bg);
  font-weight: 600;
}

#sidebar-menu ul li.mm-active > a i {
  color: #7da2ff;
  opacity: 1;
}

#sidebar-menu ul li.mm-active > a::before {
  display: block;
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--accent-nav-line, #3b82f6);
  border-radius: 0 2px 2px 0;
}

html[dir="rtl"] #sidebar-menu ul li.mm-active > a::before {
  left: auto;
  right: 0;
  border-radius: 2px 0 0 2px;
}

.sidebar-user-section {
  margin: 8px 10px 12px;
  padding: 10px 12px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-default);
  background: transparent;
}

/* ── Page header — floating card ─────────────────────────────── */
.page-title-box,
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  margin-bottom: var(--sp-5);
  background: var(--surface-base);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}

html[data-theme="dark"] .page-title-box,
html[data-theme="dark"] .page-header {
  background: var(--surface-base);
  border-color: var(--border-default);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.page-title-main,
.page-title-box > div:first-child:not(.page-title-right),
.page-header > div:first-child {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  padding-inline-start: 14px;
}

.page-title-main::before,
.page-title-box > div:first-child:not(.page-title-right)::before,
.page-header > div:first-child::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: 3px;
  bottom: 3px;
  width: 3px;
  border-radius: 2px;
  background: var(--color-primary);
}

.page-title-box h4,
.page-header .page-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
  color: var(--text-primary);
  margin: 0 0 2px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.page-title-description,
.page-subtitle {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-tertiary);
  line-height: 1.45;
  margin: 0 0 var(--sp-1);
}

.page-title-box .breadcrumb {
  margin-top: 2px;
  font-size: 12px;
}

.page-title-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-2);
  flex-shrink: 0;
  flex-wrap: wrap;
}

/* Header meta pills */
.page-header-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-lg);
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  border: 1px solid transparent;
  text-decoration: none;
  transition: background var(--transition-fast), border-color var(--transition-fast);
}

.page-header-pill i {
  font-size: 14px;
  line-height: 1;
}

.page-header-pill--muted {
  background: var(--surface-raised, #f1f5f9);
  color: var(--text-secondary);
  border-color: var(--border-subtle);
}

.page-header-pill--warning {
  background: #fff7ed;
  color: #c2410c;
  border-color: #fed7aa;
}

.page-header-pill--warning:hover {
  background: #ffedd5;
  color: #9a3412;
}

.page-header-pill--info {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #bfdbfe;
}

.page-header-pill--success {
  background: #f0fdf4;
  color: #15803d;
  border-color: #bbf7d0;
}

.page-header-pill .badge {
  font-size: 10px;
  padding: 2px 6px;
}

html[data-theme="dark"] .page-header-pill--muted {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--border-default);
  color: var(--text-secondary);
}

html[data-theme="dark"] .page-header-pill--warning {
  background: rgba(234, 88, 12, 0.12);
  border-color: rgba(234, 88, 12, 0.25);
  color: #fb923c;
}

html[data-theme="dark"] .page-header-pill--info {
  background: rgba(37, 99, 235, 0.12);
  border-color: rgba(37, 99, 235, 0.25);
  color: #60a5fa;
}

html[data-theme="dark"] .page-header-pill--success {
  background: rgba(22, 163, 74, 0.12);
  border-color: rgba(22, 163, 74, 0.25);
  color: #4ade80;
}

.page-title-right .btn-sm {
  height: 34px;
  padding-inline: 12px;
  display: inline-flex;
  align-items: center;
}

.breadcrumb-item a {
  color: var(--text-tertiary);
  font-weight: 500;
}

.breadcrumb-item.active {
  color: var(--text-secondary);
  font-weight: 600;
}

/* ── KPI / stat cards ────────────────────────────────────────── */
.kpi-grid {
  --bs-gutter-x: 12px;
  --bs-gutter-y: 12px;
}

.kpi-grid > [class*="col-"] {
  display: flex;
}

.kpi-grid > [class*="col-"] > .mini-stat,
.kpi-grid > [class*="col-"] > .card {
  width: 100%;
  flex: 1 1 auto;
  min-width: 0;
}

.kpi-grid .card {
  width: 100%;
  margin-bottom: 0;
}

.kpi-grid .card-body {
  padding: var(--sp-4);
}

[class*="col-"] > .mini-stat {
  width: 100%;
  min-width: 0;
}

/* Standalone mini-stat — self-contained KPI card */
.mini-stat {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4);
  background: var(--card-bg, var(--surface-base));
  border: 1px solid var(--card-border, var(--border-default));
  border-radius: var(--radius-md);
  box-shadow: var(--card-shadow, var(--shadow-sm));
  height: 100%;
}

/* Nested inside .card — flat content, outer card provides surface */
.card .mini-stat {
  align-items: flex-start;
  padding: 0;
  background: transparent;
  border: 0;
  box-shadow: none;
}

.mini-stat-content {
  flex: 1;
  min-width: 0;
}

.mini-stat-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.card .mini-stat-icon {
  width: 36px;
  height: 36px;
  font-size: 16px;
  background: var(--empty-icon-bg);
  color: var(--text-tertiary);
}

.mini-stat-value {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.mini-stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini-stat-delta {
  font-size: 11px;
  margin-top: 4px;
}

/* ── Filter toolbar ──────────────────────────────────────────── */
.filter-toolbar,
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--sp-2);
}

.filter-toolbar-start,
.filter-bar-start {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--sp-2);
  flex: 1 1 auto;
  min-width: 0;
}

.filter-toolbar-end,
.filter-bar-end {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-shrink: 0;
}

.filter-field {
  min-width: 140px;
}

.filter-field--search {
  min-width: 200px;
  flex: 1 1 200px;
  max-width: 320px;
}

.filter-section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
  display: block;
}

.filter-panel.card .card-body {
  padding: var(--sp-3) var(--sp-4);
}

/* ── Forms ───────────────────────────────────────────────────── */
.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.form-control,
.form-select {
  min-height: var(--admin-input-height);
  border-color: var(--border-default);
  background: var(--surface-base);
  font-size: 13px;
  border-radius: var(--radius-md);
}

.form-control-sm,
.form-select-sm,
.input-group-sm > .form-control,
.input-group-sm > .form-select {
  min-height: var(--admin-input-height-sm);
  font-size: 12.5px;
}

.form-control:focus,
.form-select:focus {
  border-color: var(--color-primary);
  box-shadow: var(--focus-ring);
}

.form-section {
  margin-bottom: var(--sp-6);
}

.form-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  padding-bottom: var(--sp-2);
  margin-bottom: var(--sp-4);
  border-bottom: 1px solid var(--border-subtle);
}

/* ── Data tables ─────────────────────────────────────────────── */
.data-panel .card-header {
  min-height: 48px;
  padding: var(--sp-3) var(--sp-4);
}

.data-panel .card-title {
  font-size: 14px;
  font-weight: 700;
}

.table {
  font-size: 13px;
  margin-bottom: 0;
}

.table thead th {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
  background: var(--table-head-bg);
  border-bottom: 1px solid var(--border-default) !important;
  padding: 10px 14px;
  white-space: nowrap;
}

.table tbody td {
  padding: 10px 14px;
  vertical-align: middle;
  border-color: var(--table-cell-border);
  min-height: var(--admin-table-row-height);
}

.table tbody tr {
  transition: background var(--transition-fast);
}

.table tbody tr:hover {
  background: var(--table-row-hover-bg);
}

.table-action-col {
  width: 48px;
  text-align: end;
}

.btn-table-action,
.dropdown-toggle-nocaret {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-default);
  background: var(--surface-base);
  color: var(--text-tertiary);
}

.btn-table-action:hover,
.dropdown-toggle-nocaret:hover {
  background: var(--surface-overlay);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

/* ── Badges & chips ──────────────────────────────────────────── */
.badge,
.status-chip,
.verify-pill {
  font-weight: 600;
  letter-spacing: 0;
}

.role-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.4;
}

.role-badge-admin   { background: var(--accent-danger-bg);   color: var(--accent-danger-text); }
.role-badge-seller  { background: var(--accent-success-bg);  color: var(--accent-success-text); }
.role-badge-buyer   { background: var(--accent-info-bg);     color: var(--accent-info-text); }
.role-badge-both    { background: var(--accent-warning-bg);  color: var(--accent-warning-text); }
.role-badge-guest   { background: var(--accent-neutral-bg); color: var(--accent-neutral-text); }
.role-badge-default { background: var(--accent-neutral-bg); color: var(--accent-neutral-text); }

.access-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  font-size: 10px;
  font-weight: 600;
  background: var(--accent-neutral-bg);
  color: var(--text-secondary);
}

.meta-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  background: var(--surface-raised);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

html[data-theme="dark"] .role-badge-admin   { color: #fca5a5; }
html[data-theme="dark"] .role-badge-seller  { color: #6ee7b7; }
html[data-theme="dark"] .role-badge-buyer   { color: #93c5fd; }
html[data-theme="dark"] .role-badge-both    { color: #fbbf24; }
html[data-theme="dark"] .status-chip-pending,
html[data-theme="dark"] .verify-pill-locked { color: #fbbf24; }
html[data-theme="dark"] .status-chip-published { background: rgba(16, 185, 129, 0.18); color: #6ee7b7; }

/* ── Pagination ──────────────────────────────────────────────── */
.card-footer.pagination-bar,
.pagination-bar {
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface-base);
  border-top: 1px solid var(--border-subtle);
}

.pagination-sm .page-link {
  min-width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  border-color: var(--border-default);
  margin: 0 2px;
}

.pagination-sm .page-item.active .page-link {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--text-inverse);
}

/* ── Empty / loading / error states ──────────────────────────── */
.empty-state {
  padding: var(--sp-8) var(--sp-5);
}

.empty-state-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: var(--empty-icon-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: var(--text-tertiary);
  opacity: 1;
  margin-bottom: var(--sp-4);
}

.empty-state h5,
.empty-state-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--sp-2);
}

.empty-state p,
.empty-state-text {
  font-size: 13px;
  color: var(--text-tertiary);
  max-width: 360px;
  margin-bottom: var(--sp-4);
}

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-10) var(--sp-6);
  gap: var(--sp-3);
  color: var(--text-tertiary);
}

.loading-state__spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border-default);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: dsSpin 0.7s linear infinite;
}

@keyframes dsSpin {
  to { transform: rotate(360deg); }
}

.loading-state__text {
  font-size: 13px;
  font-weight: 500;
}

.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-10) var(--sp-6);
  text-align: center;
}

.error-state-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-full);
  background: var(--color-danger-light);
  color: var(--color-danger);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  margin-bottom: var(--sp-4);
}

.error-state-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--sp-2);
}

.error-state-text {
  font-size: 13px;
  color: var(--text-tertiary);
  max-width: 360px;
  margin-bottom: var(--sp-4);
}

/* ── Modals ──────────────────────────────────────────────────── */
.modal-content {
  border-radius: var(--radius-xl);
  border-color: var(--border-default);
  box-shadow: var(--shadow-lg);
}

.modal-header {
  padding: var(--sp-4) var(--sp-5);
  border-bottom-color: var(--border-subtle);
}

.modal-title {
  font-size: 15px;
  font-weight: 700;
}

.modal-body {
  padding: var(--sp-5);
}

.modal-footer {
  padding: var(--sp-3) var(--sp-5);
  border-top-color: var(--border-subtle);
  gap: var(--sp-2);
}

.modal-overlay .modal {
  border-radius: var(--radius-xl);
}

/* ── Detail sections ─────────────────────────────────────────── */
.detail-section {
  margin-bottom: var(--sp-4);
}

.detail-section-header {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  padding-bottom: var(--sp-2);
  margin-bottom: var(--sp-3);
  border-bottom: 1px solid var(--border-subtle);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-3) var(--sp-5);
}

.detail-item-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-tertiary);
  margin-bottom: 2px;
}

.detail-item-value {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

@media (max-width: 767.98px) {
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .filter-field--search {
    max-width: none;
    flex: 1 1 100%;
  }

  .page-title-box,
  .page-header {
    align-items: flex-start;
    padding: var(--sp-3) var(--sp-4);
  }

  .page-title-right {
    width: 100%;
    justify-content: flex-start;
  }

  .app-search-box {
    display: none !important;
  }
}

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  font-weight: 600;
  border-radius: var(--radius-md);
}

.btn-primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  box-shadow: none;
}

.btn-primary:hover,
.btn-primary:focus {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
  box-shadow: none;
}

.btn-secondary,
.btn-light {
  background: transparent;
  border-color: var(--border-default);
  color: var(--text-secondary);
}

.btn-secondary:hover,
.btn-light:hover {
  background: var(--surface-raised);
  border-color: var(--border-strong);
  color: var(--text-primary);
}

.btn-sm {
  min-height: var(--admin-input-height-sm);
  padding-inline: 12px;
  font-size: 12.5px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
}

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-default);
  box-shadow: none;
  background: var(--surface-base);
}

.card.elevated,
.dropdown-menu,
.modal-content {
  box-shadow: var(--shadow-md);
}

.card-body {
  padding: var(--sp-4);
}

.card-header {
  background: var(--surface-base);
  border-bottom-color: var(--border-subtle);
}

/* ── Light theme shell gradient ──────────────────────────────── */
html:not([data-theme="dark"]) body:not(.auth-body) {
  background: var(--admin-shell-bg);
}

html:not([data-theme="dark"]) .page-content {
  background: transparent;
}
