/* ==========================================================================
   SK Auto Hub — Design System component library
   ==========================================================================
   Requires design-tokens.css to be loaded first.

   Scope of this file: NEW, token-driven components (prefixed `ds-`) for use
   in future pages, plus a small set of consolidations for patterns that
   existed in two slightly different forms (see comments per-section).

   This file is purely additive. It does not modify or remove any existing
   class (.admin-card, .admin-table, .sk-pill, .stat-card, .btn-accent,
   etc.) — those keep working exactly as before on every existing page.
   New pages should prefer the `ds-` components documented here and in the
   style guide at /admin/design-system.
   ========================================================================== */

/* ==========================================================================
   1. Buttons
   Bootstrap's .btn / .btn-primary / .btn-accent already cover most cases —
   use those first. .ds-btn exists for the cases they don't: a ghost/icon
   button and a consistent size scale.
   ========================================================================== */
.ds-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-weight: var(--fw-medium);
  font-size: var(--font-size-base);
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-4);
  border: 1px solid transparent;
  transition: background var(--duration-fast) var(--ease-standard),
              border-color var(--duration-fast) var(--ease-standard),
              color var(--duration-fast) var(--ease-standard);
  cursor: pointer;
  text-decoration: none;
  line-height: var(--line-height-tight);
}
.ds-btn:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }

.ds-btn-primary { background: var(--brand); border-color: var(--brand); color: var(--btn-text, #fff); }
.ds-btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: var(--btn-text, #fff); }

.ds-btn-secondary { background: var(--surface); border-color: var(--border-color); color: var(--text-primary); }
.ds-btn-secondary:hover { background: var(--bg-page); }

.ds-btn-outline { background: transparent; border-color: var(--brand); color: var(--brand-text, var(--brand)); }
.ds-btn-outline:hover { background: var(--brand); color: var(--btn-text, #fff); }

.ds-btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.ds-btn-ghost:hover { background: var(--bg-page); color: var(--text-primary); }

.ds-btn-danger { background: var(--status-danger); border-color: var(--status-danger); color: #fff; }
.ds-btn-danger:hover { background: var(--status-danger-dark); border-color: var(--status-danger-dark); }

.ds-btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--font-size-sm); border-radius: var(--radius-sm); }
.ds-btn-lg { padding: var(--space-3) var(--space-6); font-size: var(--font-size-lg); }
.ds-btn-icon { padding: var(--space-2); width: 36px; height: 36px; }

/* ==========================================================================
   2. Cards
   For core admin list/detail pages, .admin-card already does this job well
   — keep using it. .ds-card is the same visual language expressed with
   tokens so it also works unmodified on the public site (account pages,
   dealer-facing widgets) where .admin-card isn't available.
   ========================================================================== */
.ds-card {
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.ds-card-header {
  padding: var(--space-4) var(--space-5);
  font-size: var(--font-size-md);
  font-weight: var(--fw-bold);
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}
.ds-card-body { padding: var(--space-5); }
.ds-card-footer {
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border-color);
  background: var(--bg-page);
}

/* ---- Stat card ----
   Canonical replacement for the two parallel stat-card systems found in
   style.css (.admin-stat-card and the older border-left .stat-card). Both
   keep working unchanged on existing pages; use .ds-stat-card going
   forward so every new stat tile shares one visual language. */
.ds-stat-card {
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  transition: box-shadow var(--duration-base) var(--ease-standard);
}
.ds-stat-card:hover { box-shadow: var(--shadow-sm); }
.ds-stat-card .ds-stat-label { font-size: var(--font-size-sm); color: var(--text-muted); font-weight: var(--fw-medium); margin-bottom: var(--space-1); }
.ds-stat-card .ds-stat-value { font-size: var(--font-size-2xl); font-weight: var(--fw-bold); color: var(--text-primary); line-height: var(--line-height-tight); }
.ds-stat-card .ds-stat-sub { font-size: var(--font-size-xs); color: var(--text-muted); }
.ds-stat-card .ds-stat-icon {
  width: 44px; height: 44px; border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; flex-shrink: 0;
}
.ds-stat-icon.is-success { background: var(--status-success-light); color: var(--status-success-dark); }
.ds-stat-icon.is-danger  { background: var(--status-danger-light);  color: var(--status-danger-dark); }
.ds-stat-icon.is-warning { background: var(--status-warning-light); color: var(--status-warning-dark); }
.ds-stat-icon.is-info    { background: var(--status-info-light);    color: var(--status-info-dark); }
.ds-stat-icon.is-neutral { background: var(--status-neutral-light); color: var(--status-neutral-dark); }

/* ==========================================================================
   3. Status pill
   Canonical status indicator, replacing .sk-pill's ad-hoc per-page color
   choices with the shared --status-* tokens from design-tokens.css — the
   fix for "Sold" meaning a different color on different admin pages.
   .sk-pill keeps working unchanged; prefer .ds-pill in new markup.
   Usage: <span class="ds-pill ds-pill-success">Available</span>
   ========================================================================== */
.ds-pill {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  font-size: var(--font-size-xs);
  font-weight: var(--fw-semibold);
  white-space: nowrap;
}
.ds-pill::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.ds-pill-success { background: var(--status-success-light); color: var(--status-success-dark); }
.ds-pill-danger  { background: var(--status-danger-light);  color: var(--status-danger-dark); }
.ds-pill-warning { background: var(--status-warning-light); color: var(--status-warning-dark); }
.ds-pill-info    { background: var(--status-info-light);    color: var(--status-info-dark); }
.ds-pill-neutral { background: var(--status-neutral-light); color: var(--status-neutral-dark); }

/* ==========================================================================
   4. Tables
   Token-driven equivalent of .admin-table, usable on public-facing list
   pages too (e.g. saved vehicles, invoices) where .admin-table isn't
   available. Wrap a Bootstrap .table in .ds-table.
   ========================================================================== */
.ds-table { background: var(--surface); border: 1px solid var(--border-color); border-radius: var(--radius-lg); overflow: hidden; }
.ds-table .table { margin-bottom: 0; }
.ds-table .table thead th {
  background: var(--bg-page);
  font-size: var(--font-size-xs);
  font-weight: var(--fw-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  border-bottom: 1px solid var(--border-color);
  padding: var(--space-3) var(--space-4);
}
.ds-table .table tbody td {
  padding: var(--space-3) var(--space-4);
  vertical-align: middle;
  font-size: var(--font-size-base);
  color: var(--text-primary);
  border-color: var(--border-color);
}
.ds-table .table tbody tr:hover { background: var(--bg-page); }
.ds-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
@media (max-width: 767px) {
  .ds-table .table thead th, .ds-table .table tbody td { padding: var(--space-2) var(--space-3); font-size: var(--font-size-sm); }
}

/* ==========================================================================
   5. Forms
   Nothing like this existed platform-wide before — pages hand-rolled
   required-field asterisks and rarely showed help/error text. This is the
   canonical field pattern for new forms.

   Usage:
   <div class="ds-field">
     <label class="ds-label" for="vin">VIN <span class="ds-required">*</span></label>
     <input class="form-control" id="vin" name="vin">
     <p class="ds-help">17-character vehicle identification number.</p>
   </div>
   ========================================================================== */
.ds-field { margin-bottom: var(--space-4); }
.ds-label { display: block; font-size: var(--font-size-base); font-weight: var(--fw-medium); color: var(--text-primary); margin-bottom: var(--space-2); }
.ds-required { color: var(--status-danger); }
.ds-help { font-size: var(--font-size-sm); color: var(--text-muted); margin: var(--space-1) 0 0; }
.ds-error { font-size: var(--font-size-sm); color: var(--status-danger); margin: var(--space-1) 0 0; display: flex; align-items: center; gap: var(--space-1); }
.ds-form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--space-4) var(--space-5); }
.ds-form-actions { display: flex; gap: var(--space-3); margin-top: var(--space-6); padding-top: var(--space-5); border-top: 1px solid var(--border-color); }

/* ==========================================================================
   6. Alerts
   ========================================================================== */
.ds-alert { display: flex; gap: var(--space-3); align-items: flex-start; padding: var(--space-4); border-radius: var(--radius-md); font-size: var(--font-size-base); border: 1px solid transparent; }
.ds-alert-success { background: var(--status-success-light); color: var(--status-success-dark); border-color: var(--status-success-light); }
.ds-alert-danger  { background: var(--status-danger-light);  color: var(--status-danger-dark);  border-color: var(--status-danger-light); }
.ds-alert-warning { background: var(--status-warning-light); color: var(--status-warning-dark); border-color: var(--status-warning-light); }
.ds-alert-info    { background: var(--status-info-light);    color: var(--status-info-dark);    border-color: var(--status-info-light); }

/* ==========================================================================
   7. Pagination
   Wrap Bootstrap's default <ul class="pagination"> in .ds-pagination to
   pick up token-driven styling without touching the global .pagination
   rule (which is untouched and still Bootstrap-default everywhere else).
   ========================================================================== */
.ds-pagination .page-link { color: var(--brand-text, var(--brand)); border-color: var(--border-color); }
.ds-pagination .page-item.active .page-link { background: var(--brand); border-color: var(--brand); color: var(--btn-text, #fff); }
.ds-pagination .page-link:hover { background: var(--bg-page); }

/* ==========================================================================
   8. Tabs / nav
   ========================================================================== */
.ds-tabs { border-bottom: 1px solid var(--border-color); gap: var(--space-2); }
.ds-tabs .nav-link { border: none; border-bottom: 2px solid transparent; color: var(--text-muted); font-weight: var(--fw-medium); padding: var(--space-3) var(--space-4); }
.ds-tabs .nav-link.active, .ds-tabs .nav-link:hover { color: var(--brand-text, var(--brand)); border-bottom-color: var(--brand); background: transparent; }

/* ==========================================================================
   9. Page templates
   Shared layout scaffolding for list pages, detail pages, and form pages.
   Mirrors patterns already proven in ownershipiq (.oiq-grid) and the core
   admin (.admin-page-header), generalized with tokens so they also work on
   the public site.
   ========================================================================== */
.ds-page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}
.ds-page-header h1 { font-size: var(--font-size-2xl); font-weight: var(--fw-bold); color: var(--text-primary); margin: 0; }
.ds-page-header p { color: var(--text-muted); font-size: var(--font-size-base); margin: var(--space-1) 0 0; }
.ds-page-header .ds-page-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }

.ds-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  margin-bottom: var(--space-5);
}

.ds-grid { display: grid; gap: var(--space-5); grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.ds-grid-2 { display: grid; gap: var(--space-5); grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); }
.ds-section { margin-bottom: var(--space-7); }

.ds-empty-state {
  text-align: center;
  padding: var(--space-9) var(--space-5);
  color: var(--text-muted);
}
.ds-empty-state .ds-empty-icon { font-size: 2.5rem; color: var(--border-color); margin-bottom: var(--space-3); }
.ds-empty-state h3 { font-size: var(--font-size-lg); color: var(--text-primary); margin-bottom: var(--space-2); }

/* ==========================================================================
   10. Motion
   Promoted from ownershipiq's fade-in-up + stagger pattern (the most
   mature motion pattern found in the audit) so any page can opt in.
   Respects prefers-reduced-motion via design-tokens.css's duration
   collapse, plus an explicit kill switch here for the animation itself.
   ========================================================================== */
@keyframes ds-fade-in-up {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.ds-fade-in-up { animation: ds-fade-in-up var(--duration-slow) var(--ease-standard) both; }
.ds-stagger > * { animation: ds-fade-in-up var(--duration-slow) var(--ease-standard) both; }
.ds-stagger > *:nth-child(1) { animation-delay: .03s; }
.ds-stagger > *:nth-child(2) { animation-delay: .06s; }
.ds-stagger > *:nth-child(3) { animation-delay: .09s; }
.ds-stagger > *:nth-child(4) { animation-delay: .12s; }
.ds-stagger > *:nth-child(5) { animation-delay: .15s; }
.ds-stagger > *:nth-child(n+6) { animation-delay: .18s; }

@media (prefers-reduced-motion: reduce) {
  .ds-fade-in-up, .ds-stagger > * { animation: none !important; }
}

/* ==========================================================================
   11. Icons
   Icon library platform-wide is Bootstrap Icons (bi bi-*). Size utilities
   for consistent icon scaling inside buttons, stat tiles, and empty states.
   ========================================================================== */
.ds-icon-sm { font-size: .85rem; }
.ds-icon-md { font-size: 1.1rem; }
.ds-icon-lg { font-size: 1.5rem; }
.ds-icon-xl { font-size: 2rem; }

/* ==========================================================================
   12. Chart color palette
   No charting library is wired up platform-wide yet. When one is added
   (Chart.js/ApexCharts), use this token-derived, ordered palette so charts
   match the rest of the UI instead of a library's default colors.
   window.dsChartPalette gives the same colors to JS-side chart configs.
   ========================================================================== */
:root {
  --chart-1: var(--sk-blue, #1a56db);
  --chart-2: var(--sk-green, #4caf50);
  --chart-3: var(--sk-purple, #5b6fd8);
  --chart-4: #f5a524;
  --chart-5: var(--sk-teal, #00897b);
  --chart-6: var(--sk-red, #e53935);
}
