/* =====================================================
   TehGuys Design-System Component Layer
   Reusable UI primitives built ONLY on theme.css tokens.
   No hardcoded colors or spacing — everything via var(--...).
   ===================================================== */

/* =====================================================
   Card — .ds-card + header / body / footer
   ===================================================== */
.ds-card {
  background: var(--bg-card);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-card);
  color: var(--text-primary);
  transition: box-shadow var(--transition-base), border-color var(--transition-base);
}

.ds-card__header {
  font-weight: 600;
  font-size: var(--font-size-lg);
  color: var(--text-primary);
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--border-dark);
}

.ds-card__body {
  color: var(--text-secondary);
  font-size: var(--font-size-base);
}

.ds-card__footer {
  margin-top: var(--space-md);
  padding-top: var(--space-md);
  border-top: 1px solid var(--border-dark);
  display: flex;
  gap: var(--space-sm);
  align-items: center;
}

@media (prefers-reduced-motion: reduce) {
  .ds-card {
    transition: none;
  }
}

/* =====================================================
   Button — .ds-btn + variants + sizes + states
   ===================================================== */
.ds-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-lg);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-family: var(--font-family);
  font-size: var(--font-size-sm);
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  -webkit-appearance: none;
  appearance: none;
  transition: background var(--transition-fast), border-color var(--transition-fast),
    color var(--transition-fast), box-shadow var(--transition-fast);
}

.ds-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-blue-glow);
}

.ds-btn:disabled,
.ds-btn[aria-disabled="true"] {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}

/* Sizes */
.ds-btn--sm {
  padding: var(--space-xs) var(--space-md);
  font-size: var(--font-size-xs);
  border-radius: var(--radius-sm);
}

.ds-btn--lg {
  padding: var(--space-md) var(--space-xl);
  font-size: var(--font-size-base);
  border-radius: var(--radius-lg);
}

/* Variants */
.ds-btn--primary {
  background: var(--accent-blue);
  /* Ink on light accents (Electric Green); white on dark accents (Indigo /
     Dark Purple). Per-palette --accent-contrast keeps the label readable. */
  color: var(--accent-contrast, #0E2233);
  border-color: var(--accent-blue);
}

.ds-btn--primary:hover {
  background: var(--accent-blue-hover);
  border-color: var(--accent-blue-hover);
  color: var(--accent-contrast, #0E2233);
}

.ds-btn--secondary {
  background: var(--surface-light);
  color: var(--text-primary);
  border-color: var(--border-medium);
}

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

.ds-btn--ghost {
  background: rgba(83, 232, 103, 0.04);
  color: var(--text-secondary);
  border-color: var(--border-medium);
}

.ds-btn--ghost:hover {
  background: var(--surface-light);
  color: var(--text-primary);
  border-color: var(--border-light);
}

.ds-btn--danger {
  background: var(--accent-red);
  color: #fff;
  border-color: var(--accent-red);
}

.ds-btn--danger:hover {
  background: var(--accent-red);
  border-color: var(--accent-red);
  color: #fff;
  filter: brightness(0.92);
}

/* Accent (craft pink) — used for the profile Message button so it stays
   visually distinct from the indigo primary Subscribe button beside it. */
.ds-btn--accent {
  background: var(--craft-pink);
  color: #fff;
  border-color: var(--craft-pink);
}

.ds-btn--accent:hover {
  background: var(--craft-pink);
  border-color: var(--craft-pink);
  color: #fff;
  filter: brightness(0.94);
}

/* ── Alert (token-styled message box) ──────────────────────────────────── */
.ds-alert {
  display: flex;
  gap: var(--space-sm);
  align-items: flex-start;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-medium);
  background: var(--surface-light);
  color: var(--text-secondary);
  font-size: 0.9rem;
}
.ds-alert--info {
  border-color: var(--craft-indigo);
  background: var(--craft-indigo-tint);
  color: var(--craft-indigo);
}
.ds-alert--success {
  border-color: var(--accent-green);
  background: color-mix(in srgb, var(--accent-green) 10%, transparent);
  color: var(--accent-green);
}
.ds-alert--warning {
  border-color: var(--accent-yellow);
  background: color-mix(in srgb, var(--accent-yellow) 12%, transparent);
  color: var(--text-primary);
}
.ds-alert--danger {
  border-color: var(--accent-red);
  background: var(--craft-pink-tint);
  color: var(--accent-red);
}

/* ── Tabs (token-styled tab row) ───────────────────────────────────────── */
.ds-tabs {
  display: flex;
  gap: var(--space-xs);
  border-bottom: 2px solid var(--border-dark);
  overflow-x: auto;
  scrollbar-width: none;
}
.ds-tabs::-webkit-scrollbar {
  display: none;
}
.ds-tab {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: color 0.15s, border-color 0.15s;
}
.ds-tab:hover {
  color: var(--text-primary);
}
.ds-tab.is-active,
.ds-tab[aria-selected="true"] {
  color: var(--craft-indigo);
  border-bottom-color: var(--craft-indigo);
  font-weight: 600;
}

@media (prefers-reduced-motion: reduce) {
  .ds-btn {
    transition: none;
  }
}

/* =====================================================
   Field — .ds-field (label, input, help, error)
   ===================================================== */
.ds-field {
  display: flex;
  flex-direction: column;
  gap: var(--space-xs);
}

.ds-field__label {
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-secondary);
}

.ds-field__input {
  width: 100%;
  padding: var(--space-md);
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.ds-field__input::placeholder {
  color: var(--text-placeholder);
}

.ds-field__input:focus,
.ds-field__input:focus-visible {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px var(--accent-blue-glow);
}

.ds-field__help {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
}

.ds-field__error {
  font-size: var(--font-size-xs);
  color: var(--accent-red);
  font-weight: 500;
}

/* Invalid state */
.ds-field--invalid .ds-field__input {
  border-color: var(--accent-red);
}

.ds-field--invalid .ds-field__input:focus,
.ds-field--invalid .ds-field__input:focus-visible {
  box-shadow: 0 0 0 3px var(--accent-blue-glow);
  border-color: var(--accent-red);
}

@media (prefers-reduced-motion: reduce) {
  .ds-field__input {
    transition: none;
  }
}

/* =====================================================
   Empty state — .ds-empty (icon, title, subtitle, action)
   ===================================================== */
.ds-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: var(--space-md);
  padding: var(--space-2xl) var(--space-lg);
  color: var(--text-secondary);
}

.ds-empty__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--avatar-lg);
  height: var(--avatar-lg);
  border-radius: var(--radius-full);
  background: var(--surface-light);
  color: var(--text-muted);
  font-size: var(--font-size-4xl);
}

.ds-empty__title {
  font-size: var(--font-size-xl);
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.ds-empty__subtitle {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  max-width: 40ch;
  margin: 0;
}

.ds-empty__action {
  margin-top: var(--space-sm);
}

/* =====================================================
   Avatar — .ds-avatar (sizes sm/md/lg, circle, fallback)
   ===================================================== */
.ds-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--avatar-md);
  height: var(--avatar-md);
  border-radius: var(--radius-full);
  background: var(--gradient-primary);
  color: #fff;
  font-weight: 600;
  font-size: var(--font-size-base);
  overflow: hidden;
  flex-shrink: 0;
  text-transform: uppercase;
  line-height: 1;
}

.ds-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
}

.ds-avatar--sm {
  width: var(--avatar-sm);
  height: var(--avatar-sm);
  font-size: var(--font-size-sm);
}

.ds-avatar--lg {
  width: var(--avatar-lg);
  height: var(--avatar-lg);
  font-size: var(--font-size-3xl);
}

/* =====================================================
   Badge — .ds-badge (default/success/warning/danger + dot)
   ===================================================== */
.ds-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: 600;
  line-height: 1;
  background: var(--surface-light);
  color: var(--text-secondary);
  border: 1px solid var(--border-medium);
}

.ds-badge--success {
  background: var(--accent-green);
  color: #fff;
  border-color: var(--accent-green);
}

.ds-badge--warning {
  background: var(--accent-yellow);
  color: var(--text-primary);
  border-color: var(--accent-yellow);
}

.ds-badge--danger {
  background: var(--accent-red);
  color: #fff;
  border-color: var(--accent-red);
}

/* Leading status dot */
.ds-badge__dot {
  display: inline-block;
  width: var(--space-sm);
  height: var(--space-sm);
  border-radius: var(--radius-full);
  background: currentColor;
}

/* =====================================================
   Button variant — Warning (.ds-btn--warning)
   Amber/orange surface; dark text for WCAG contrast.
   Mirrors .btn-warning in social_platform.css.
   ===================================================== */
.ds-btn--warning {
  background: var(--accent-yellow);
  color: var(--text-primary);
  border-color: var(--accent-yellow);
}

.ds-btn--warning:hover {
  background: var(--craft-orange);
  border-color: var(--craft-orange);
  color: var(--text-primary);
  filter: brightness(0.97);
}

/* =====================================================
   Modal — .ds-modal system
   Mirrors Bootstrap .modal-content / .modal-header /
   .modal-body / .modal-footer look from social_platform.css.
   ===================================================== */
.ds-modal__overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  /* Hidden by default; shown by JS via .is-open / [data-open] / .show, or kept
     visible in static demos by adding one of those. The [hidden] attribute
     (used by some templates' onclick toggles) always wins. */
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1050;
  padding: var(--space-md);
}
.ds-modal__overlay.is-open,
.ds-modal__overlay[data-open],
.ds-modal__overlay.show {
  display: flex;
}
.ds-modal__overlay[hidden] {
  display: none;
}

.ds-modal {
  background: var(--bg-card);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  color: var(--text-primary);
}

.ds-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-lg) var(--space-xl);
  border-bottom: 1px solid var(--border-dark);
  font-weight: 600;
  font-size: var(--font-size-lg);
  color: var(--text-primary);
  flex-shrink: 0;
}

.ds-modal__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: var(--font-size-lg);
  font-weight: 700;
  color: var(--text-primary);
}

.ds-modal__body {
  padding: var(--space-xl);
  color: var(--text-primary);
  flex: 1;
}

.ds-modal__footer {
  padding: var(--space-md) var(--space-xl);
  border-top: 1px solid var(--border-dark);
  display: flex;
  gap: var(--space-sm);
  justify-content: flex-end;
  flex-shrink: 0;
}

.ds-modal__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: var(--font-size-lg);
  line-height: 1;
  transition: background var(--transition-fast), color var(--transition-fast);
  flex-shrink: 0;
}

.ds-modal__close:hover {
  background: var(--surface-light);
  color: var(--text-primary);
}

/* =====================================================
   Dropdown — .ds-dropdown system
   Mirrors .dropdown-menu / .dropdown-item from theme.css.
   ===================================================== */
.ds-dropdown {
  position: relative;
  display: inline-block;
}

.ds-dropdown__menu {
  position: absolute;
  top: calc(100% + var(--space-xs));
  left: 0;
  min-width: 180px;
  background: var(--bg-card);
  border: 1px solid var(--border-medium);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-xs);
  z-index: 200;
  display: none;
}

.ds-dropdown__menu.is-open,
.ds-dropdown__menu[data-open] {
  display: block;
}

.ds-dropdown__item {
  display: block;
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-sm);
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
  font-family: var(--font-family);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
  white-space: nowrap;
}

.ds-dropdown__item:hover,
.ds-dropdown__item:focus {
  background: var(--surface-light);
  color: var(--text-primary);
}

/* =====================================================
   List — .ds-list system
   Mirrors Bootstrap .list-group / .list-group-item
   and the social_platform.css overrides.
   ===================================================== */
.ds-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.ds-list__item {
  background: var(--bg-card);
  border: 1px solid var(--border-medium);
  color: var(--text-primary);
  padding: var(--space-md) var(--space-lg);
  margin-top: -1px; /* collapse adjacent borders */
}

.ds-list__item:first-child {
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  margin-top: 0;
}

.ds-list__item:last-child {
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.ds-list__item:only-child {
  border-radius: var(--radius-md);
}

.ds-list__item--action {
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
  text-decoration: none;
  display: block;
}

.ds-list__item--action:hover {
  background: var(--surface-light);
  color: var(--text-primary);
}

/* =====================================================
   Table — .ds-table system
   Mirrors .table / .table thead th / .table tbody td
   from social_platform.css.
   ===================================================== */
.ds-table {
  width: 100%;
  border-collapse: collapse;
  color: var(--text-primary);
  font-size: var(--font-size-base);
}

.ds-table th {
  background: var(--surface-dark);
  border-bottom: 1px solid var(--border-medium);
  color: var(--text-secondary);
  font-weight: 600;
  padding: var(--space-md) var(--space-lg);
  text-align: left;
}

.ds-table td {
  border-bottom: 1px solid var(--border-medium);
  padding: var(--space-md) var(--space-lg);
  vertical-align: middle;
  color: var(--text-primary);
}

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

/* Striped variant — alternating row bg-surface-light */
.ds-table--striped tbody tr:nth-child(even) {
  background: var(--surface-light);
}

/* =====================================================
   Responsive 12-column grid — .ds-row / .ds-col-*
   Pixel-equivalent to Bootstrap's .row / .col-* grid
   (same breakpoints, same 12-col %, same gutter math).
   .ds-col-{n} → {n}/12 * 100%
   .ds-col-{bp}-{n} → responsive variant
   .ds-g-{0..5} → gutter steps (mirrors Bootstrap g-*)
   ===================================================== */
/* Base gutter size (mirrors Bootstrap $grid-gutter-width = 1.5rem → ±0.75rem) */
:root {
  --ds-gutter: 0.75rem;
}

/* Centered page container (mirrors Bootstrap .container) */
.ds-container {
  width: 100%;
  max-width: var(--content-max-width, 1400px);
  margin-inline: auto;
  padding-inline: var(--container-pad, clamp(16px, 4vw, 48px));
}
.ds-container--fluid {
  max-width: none;
}

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

.ds-row > * {
  box-sizing: border-box;
  padding-inline: var(--ds-gutter);
  width: 100%;
}

.ds-col   { flex: 1 0 0%; }

/* --- Fixed-width columns (mobile-first: all apply at any width) --- */
.ds-col-1  { width:  8.3333%; }
.ds-col-2  { width: 16.6667%; }
.ds-col-3  { width: 25%; }
.ds-col-4  { width: 33.3333%; }
.ds-col-5  { width: 41.6667%; }
.ds-col-6  { width: 50%; }
.ds-col-7  { width: 58.3333%; }
.ds-col-8  { width: 66.6667%; }
.ds-col-9  { width: 75%; }
.ds-col-10 { width: 83.3333%; }
.ds-col-11 { width: 91.6667%; }
.ds-col-12 { width: 100%; }

/* --- sm breakpoint (≥576px) --- */
@media (min-width: 576px) {
  .ds-col-sm-1  { width:  8.3333%; }
  .ds-col-sm-2  { width: 16.6667%; }
  .ds-col-sm-3  { width: 25%; }
  .ds-col-sm-4  { width: 33.3333%; }
  .ds-col-sm-5  { width: 41.6667%; }
  .ds-col-sm-6  { width: 50%; }
  .ds-col-sm-7  { width: 58.3333%; }
  .ds-col-sm-8  { width: 66.6667%; }
  .ds-col-sm-9  { width: 75%; }
  .ds-col-sm-10 { width: 83.3333%; }
  .ds-col-sm-11 { width: 91.6667%; }
  .ds-col-sm-12 { width: 100%; }
}

/* --- md breakpoint (≥768px) --- */
@media (min-width: 768px) {
  .ds-col-md-1  { width:  8.3333%; }
  .ds-col-md-2  { width: 16.6667%; }
  .ds-col-md-3  { width: 25%; }
  .ds-col-md-4  { width: 33.3333%; }
  .ds-col-md-5  { width: 41.6667%; }
  .ds-col-md-6  { width: 50%; }
  .ds-col-md-7  { width: 58.3333%; }
  .ds-col-md-8  { width: 66.6667%; }
  .ds-col-md-9  { width: 75%; }
  .ds-col-md-10 { width: 83.3333%; }
  .ds-col-md-11 { width: 91.6667%; }
  .ds-col-md-12 { width: 100%; }
}

/* --- lg breakpoint (≥992px) --- */
@media (min-width: 992px) {
  .ds-col-lg-1  { width:  8.3333%; }
  .ds-col-lg-2  { width: 16.6667%; }
  .ds-col-lg-3  { width: 25%; }
  .ds-col-lg-4  { width: 33.3333%; }
  .ds-col-lg-5  { width: 41.6667%; }
  .ds-col-lg-6  { width: 50%; }
  .ds-col-lg-7  { width: 58.3333%; }
  .ds-col-lg-8  { width: 66.6667%; }
  .ds-col-lg-9  { width: 75%; }
  .ds-col-lg-10 { width: 83.3333%; }
  .ds-col-lg-11 { width: 91.6667%; }
  .ds-col-lg-12 { width: 100%; }
}

/* --- xl breakpoint (≥1200px) --- */
@media (min-width: 1200px) {
  .ds-col-xl-1  { width:  8.3333%; }
  .ds-col-xl-2  { width: 16.6667%; }
  .ds-col-xl-3  { width: 25%; }
  .ds-col-xl-4  { width: 33.3333%; }
  .ds-col-xl-5  { width: 41.6667%; }
  .ds-col-xl-6  { width: 50%; }
  .ds-col-xl-7  { width: 58.3333%; }
  .ds-col-xl-8  { width: 66.6667%; }
  .ds-col-xl-9  { width: 75%; }
  .ds-col-xl-10 { width: 83.3333%; }
  .ds-col-xl-11 { width: 91.6667%; }
  .ds-col-xl-12 { width: 100%; }
}

/* --- Gutter utilities (mirrors Bootstrap g-0..g-5) --- */
/* g-0: no gutters */
.ds-row.ds-g-0 { margin-inline: 0; }
.ds-row.ds-g-0 > * { padding-inline: 0; }

/* g-1: 0.25rem each side → 0.5rem column gap */
.ds-row.ds-g-1 { margin-inline: -0.125rem; row-gap: 0.25rem; }
.ds-row.ds-g-1 > * { padding-inline: 0.125rem; }

/* g-2: 0.25rem each side → 0.5rem column gap (Bootstrap step) */
.ds-row.ds-g-2 { margin-inline: -0.25rem; row-gap: 0.5rem; }
.ds-row.ds-g-2 > * { padding-inline: 0.25rem; }

/* g-3: 0.5rem each side → 1rem column gap */
.ds-row.ds-g-3 { margin-inline: -0.5rem; row-gap: 1rem; }
.ds-row.ds-g-3 > * { padding-inline: 0.5rem; }

/* g-4: 0.75rem each side → 1.5rem column gap */
.ds-row.ds-g-4 { margin-inline: -0.75rem; row-gap: 1.5rem; }
.ds-row.ds-g-4 > * { padding-inline: 0.75rem; }

/* g-5: 1.5rem each side → 3rem column gap */
.ds-row.ds-g-5 { margin-inline: -1.5rem; row-gap: 3rem; }
.ds-row.ds-g-5 > * { padding-inline: 1.5rem; }
