/**
 * Dubuz 2026 - HD Design Theme System
 * Semantic tokens for 4 themes (Red, Blue, Purple, Dark)
 */

:root {
  /* Shared Functional Colors (Standard across all themes) */
  --success: #12B76A;
  --success-strong: #067647;
  --success-soft: #ECFDF3;
  --success-subtle: #D1FADF;

  --warning: #F79009;
  --warning-strong: #B54708;
  --warning-soft: #FFFAEB;
  --warning-subtle: #FEF0C7;

  --danger: #F04438;
  --danger-strong: #B42318;
  --danger-soft: #FEF3F2;
  --danger-subtle: #FEE4E2;

  --info: #2E90FA;
  --info-strong: #175CD3;
  --info-soft: #EFF8FF;
  --info-subtle: #D1E9FF;

  /* Base Radii Scale */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  /* Spacing Scale (8px base) */
  --spacing-1: 4px;
  --spacing-2: 8px;
  --spacing-3: 12px;
  --spacing-4: 16px;
  --spacing-6: 24px;
  --spacing-8: 32px;
  --spacing-10: 40px;
  --spacing-12: 48px;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(16,24,40,.04);
  --shadow-sm: 0 2px 6px rgba(16,24,40,.06);
  --shadow-md: 0 8px 24px rgba(16,24,40,.08);
  --shadow-lg: 0 16px 40px rgba(16,24,40,.12);
}

/* Light Mode Defaults (Neutral System) */
[data-mode="light"], :root:not([data-mode="dark"]) {
  --page-bg: #F7F8FA;
  --surface: #FFFFFF;
  --surface-subtle: #FAFAFB;
  --surface-hover: #F5F6F8;
  --surface-active: #F2F4F7;

  --text-primary: #101828;
  --text-secondary: #344054;
  --text-tertiary: #667085;
  --text-muted: #98A2B3;
  --text-disabled: #B8C0CC;

  --border-light: #EAECF0;
  --border: #D0D5DD;
  --border-strong: #98A2B3;

  --color-shadow: rgba(16, 24, 40, 0.06);
  --color-shadow-hover: rgba(16, 24, 40, 0.14);

  --bg-card-rgb: 255, 255, 255;
}

/* THEME: RED (Default) */
[data-theme="red"] {
  --brand: #FF4B33;
  --brand-hover: #E83F29;
  --brand-active: #CC351F;
  --brand-soft: #FFF5F2;
  --brand-subtle: #FFE9E4;
  --brand-muted: #FFD1C8;
  --brand-border: #FFB5A8;
  --text-on-brand: #FFFFFF;
  --primary: var(--brand); /* Legacy bridge */
}

/* THEME: BLUE */
[data-theme="blue"] {
  --brand: #2563EB;
  --brand-hover: #1D4ED8;
  --brand-active: #1E40AF;
  --brand-soft: #EFF6FF;
  --brand-subtle: #DBEAFE;
  --brand-muted: #BFDBFE;
  --brand-border: #93C5FD;
  --text-on-brand: #FFFFFF;
  --primary: var(--brand);
}

/* THEME: PURPLE */
[data-theme="purple"] {
  --brand: #7C3AED;
  --brand-hover: #6D28D9;
  --brand-active: #5B21B6;
  --brand-soft: #F5F3FF;
  --brand-subtle: #EDE9FE;
  --brand-muted: #DDD6FE;
  --brand-border: #C4B5FD;
  --text-on-brand: #FFFFFF;
  --primary: var(--brand);
}

/* THEME: DARK (HD Deep Dark) */
[data-theme="dark"], [data-mode="dark"] {
  --page-bg: #0F1115;
  --surface: #171A21;
  --surface-subtle: #1D2129;
  --surface-hover: #242934;
  --surface-active: #2A2020;

  --text-primary: #F8FAFC;
  --text-secondary: #CBD5E1;
  --text-tertiary: #94A3B8;
  --text-muted: #64748B;
  --text-disabled: #475569;

  --border-light: #252B35;
  --border: #343B48;
  --border-strong: #475569;

  --brand: #FF5A43;
  --brand-hover: #FF705C;
  --brand-active: #E83F29;
  --brand-soft: rgba(255, 75, 51, 0.12);
  --brand-subtle: rgba(255, 75, 51, 0.18);
  --brand-muted: rgba(255, 75, 51, 0.28);
  --brand-border: rgba(255, 75, 51, 0.35);

  --text-on-brand: #FFFFFF;
  --bg-card-rgb: 23, 26, 33;

  --color-shadow: rgba(0, 0, 0, 0.4);
  --color-shadow-hover: rgba(0, 0, 0, 0.6);
}

/* --color-* (theme-system v1 vocabulary) → semantic tokens.
   Kept here so pages/partials that still reference the old names resolve
   correctly in both light and night mode, without loading theme-system.css. */
:root {
  --color-primary: var(--brand);
  --color-primary-hover: var(--brand-hover);
  --color-primary-light: var(--brand-soft);
  --color-primary-ring: color-mix(in srgb, var(--brand) 30%, transparent);
  --color-on-primary: var(--text-on-brand);
  --color-accent: var(--brand);
  --color-accent-hover: var(--brand-hover);
  --color-accent-light: var(--brand-soft);
  --color-on-accent: var(--text-on-brand);
  --color-surface: var(--surface);
  --color-surface-hover: var(--surface-hover);
  --color-bg: var(--page-bg);
  --color-text: var(--text-primary);
  --color-text-muted: var(--text-muted);
  --color-border: var(--border);
  --color-placeholder: var(--text-muted);
}

/* -- Legacy bridge (theme-system.css vocabulary) → semantic tokens.
   Re-points every existing sng / dash / al / alibaba component token to
   the semantic tokens so THIS file can be the single token source on the
   account + auth pages too (replacing theme-system.css). Declared on
   :root AND re-asserted under html.night-mode so night mode resolves. */
:root,
html.night-mode {
  --primary: var(--brand);
  --primary-hover: var(--brand-hover);
  --primary-light: var(--brand-soft);
  --primary-text: var(--text-on-brand);
  --gradient-primary: linear-gradient(135deg, var(--brand), var(--brand-hover));

  --bg-page: var(--page-bg);
  --bg-card: var(--surface);
  --card-bg: var(--surface);
  --text-main: var(--text-primary);
  --text-body: var(--text-primary);
  --text-heading: var(--text-primary);
  --placeholder: var(--text-muted);
  --hover-bg: var(--surface-hover);
  --active-bg: var(--brand-soft);
  --sidebar-hover: var(--surface-hover);

  --error: var(--danger);
  --focus-ring: 0 0 0 3px color-mix(in srgb, var(--brand) 20%, transparent);

  --color-success: var(--success);
  --color-success-on: #FFFFFF;
  --color-success-hover: color-mix(in srgb, var(--success), black 15%);
  --color-success-light: var(--success-soft);
  --color-success-bg: var(--success-soft);
  --color-success-text: var(--success-strong);
  --color-danger: var(--danger);
  --color-danger-on: #FFFFFF;
  --color-danger-hover: color-mix(in srgb, var(--danger), black 15%);
  --color-danger-light: var(--danger-soft);
  --color-danger-bg: var(--danger-soft);
  --color-danger-border: var(--danger-subtle);
  --color-danger-text: var(--danger-strong);
  --color-warning: var(--warning);
  --color-warning-on: #FFFFFF;
  --color-warning-hover: color-mix(in srgb, var(--warning), black 15%);
  --color-warning-light: var(--warning-soft);
  --color-warning-bg: var(--warning-soft);
  --color-warning-border: var(--warning-subtle);
  --color-warning-text: var(--warning-strong);
  --color-info: var(--info);
  --color-info-on: #FFFFFF;
  --color-info-hover: color-mix(in srgb, var(--info), black 15%);
  --color-info-light: var(--info-soft);
  --color-info-accent: var(--info);

  --shadow-popup: 0 4px 24px rgba(16, 24, 40, 0.12);
  --shadow-card: 0 2px 8px rgba(16, 24, 40, 0.10);

  --input-bg: var(--surface);
  --input-border: var(--border);
  --input-border-hover: var(--border-strong);
  --input-border-focus: var(--brand);
  --input-border-error: var(--danger);
  --input-border-success: var(--success);
  --selected-bg: var(--brand-soft);
  --selected-text: var(--brand-hover);
  --selected-border: var(--brand-border);
  --nav-active-bg: var(--brand-soft);
  --nav-active-text: var(--brand-hover);
  --tab-active-color: var(--brand);
}

/* --al-* (alibaba/Temu component vocabulary) → semantic tokens.
   Powers the al-* component layer in mobile-layout-theme.css (topbar,
   bottom nav, category strip, product cards, skeletons). */
:root {
  --al-primary: var(--brand);
  --al-primary-hover: var(--brand-hover);
  --al-primary-light: var(--brand-soft);
  --al-bg: var(--page-bg);
  --al-card: var(--surface);
  --al-text: var(--text-primary);
  --al-text-secondary: var(--text-secondary);
  --al-text-muted: var(--text-muted);
  --al-border: var(--border);
  --al-border-light: var(--border-light);
  --al-nav-height: 56px;
  --al-topbar-height: 48px;
  --al-safe-bottom: env(safe-area-inset-bottom, 0px);
  --al-safe-top: env(safe-area-inset-top, 0px);
  --al-radius-sm: 8px;
  --al-radius-md: 12px;
  --al-radius-lg: 16px;
  --al-radius-xl: 20px;
  --al-shadow-sm: var(--shadow-sm);
  --al-shadow-md: var(--shadow-md);
  --al-shadow-lg: var(--shadow-lg);
  --al-font: var(--font-family-primary);
}

/* ============================================================
   COMPONENT CONTRACTS (merged from theme-system.css §7-§10) —
   Select2 panels, button hierarchy, badges, surface transitions,
   account header theme toggle. These were the only non-token rules
   theme-system.css shipped; they live here so account + auth pages
   can drop theme-system.css with zero regression.
   ============================================================ */
/* ---- 6b. Canonical form control standard (single form system) ----
   Every .form-control input/select/textarea resolves to ONE standard:
   44px height, radius 10, 1px --border, --surface-subtle fill, 13px/500,
   --text-primary, brand focus ring (3px rgba(255,75,51,.15)). Component
   pages (marketplace filters, auth, post-ad) reuse the same values. */
.form-control,
select.form-control,
textarea.form-control {
  height: 44px;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background-color: var(--surface-subtle, #F8FAFA);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
}
textarea.form-control {
  height: auto;
  min-height: 88px;
  padding: 10px 12px;
}
.form-control:focus,
select.form-control:focus,
textarea.form-control:focus {
  border-color: var(--brand, var(--primary));
  background-color: var(--surface);
  box-shadow: 0 0 0 3px rgba(255, 75, 51, 0.15);
  outline: none;
}
.form-control::placeholder,
select.form-control::placeholder,
textarea.form-control::placeholder { color: var(--text-muted); }
.form-control:disabled,
select.form-control:disabled,
textarea.form-control:disabled { opacity: .55; cursor: not-allowed; }

/* ---- 7. Global Select2 (search2) dropdown standard ----
   Single look for EVERY Select2 on the site: 42px trigger, radius 10,
   13px/600 rendered text, brand focus ring; panel radius 10 on --surface;
   options 13px/500 with brand hover and brand-bg selected state.
   Night-mode safe — everything resolves through theme tokens. */
.select2-container .select2-selection--single {
  height: 42px !important;
  min-height: 42px !important;
  border: 1px solid var(--border) !important;
  border-radius: 10px !important;
  background: var(--surface-subtle, #F8FAFC) !important;
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
}
.select2-container .select2-selection--single .select2-selection__rendered {
  display: flex;
  align-items: center;
  line-height: normal;
  font-size: 13px !important;
  font-weight: 600 !important;
  color: var(--text-primary) !important;
  padding-left: 14px;
  padding-right: 36px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.select2-container .select2-selection__placeholder {
  color: var(--text-muted, #98A2B3) !important;
  font-weight: 500;
}
.select2-container .select2-selection--single:hover {
  border-color: var(--brand, var(--primary));
}
.select2-container--focus .select2-selection--single,
.select2-container--open .select2-selection--single {
  border-color: var(--brand, var(--primary)) !important;
  background: var(--surface) !important;
  box-shadow: 0 0 0 3px rgba(255, 75, 51, 0.15) !important;
}
.select2-container--disabled .select2-selection--single {
  opacity: .55;
  cursor: not-allowed;
}
.select2-container .select2-dropdown {
  border: 1px solid var(--border, #E2E8F0) !important;
  border-radius: 10px !important;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.14) !important;
  background: var(--surface, #fff) !important;
  padding: 4px !important;
  z-index: 1200 !important;
}
.select2-container .select2-search--dropdown { padding: 6px 6px 4px !important; }
.select2-container .select2-search--dropdown .select2-search__field {
  border: 1px solid var(--border, #EAECF0) !important;
  border-radius: 8px !important;
  font-size: 13px !important;
  font-weight: 500 !important;
  line-height: 1.4 !important;
  color: var(--text-primary, #111827) !important;
  background: var(--surface-subtle, #F8FAFC) !important;
  padding: 8px 12px !important;
  outline: none;
  transition: border-color 0.15s;
}
.select2-container .select2-search--dropdown .select2-search__field::placeholder { color: var(--text-muted, #9CA3AF); }
.select2-container .select2-search--dropdown .select2-search__field:focus { border-color: var(--brand, var(--primary)) !important; }
.select2-container .select2-results__option {
  font-size: 13px !important;
  font-weight: 500 !important;
  color: var(--text-secondary, #374151) !important;
  line-height: 1.4 !important;
  padding: 8px 12px !important;
  border-radius: 8px !important;
  margin: 1px 0 !important;
  background: transparent !important;
  transition: background-color 0.12s, color 0.12s;
}
.select2-container .select2-results__option--selectable:hover {
  background-color: var(--brand-soft, #FFF5F2) !important;
  color: var(--brand, var(--primary)) !important;
}
.select2-container .select2-results__option--highlighted.select2-results__option--selectable,
.select2-container .select2-results__option--highlighted[aria-selected] {
  background-color: var(--brand-soft, #FFF5F2) !important;
  color: var(--brand, var(--primary)) !important;
}
.select2-container .select2-results__option[aria-selected="true"] {
  background-color: var(--brand, var(--primary)) !important;
  color: #fff !important;
  font-weight: 600 !important;
}
.select2-container .select2-selection__arrow {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M5 6 0 0h10z' fill='%23667085'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 10px;
  transition: transform 0.18s ease;
}
.select2-container .select2-selection__arrow b { display: none; }
.select2-container--open .select2-selection__arrow { transform: rotate(180deg); }

/* ---- 8. Button hierarchy (semantic) ---- */
.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--text-on-brand);
}
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: var(--text-on-brand); }
.btn-primary:active { background: var(--brand-active); border-color: var(--brand-active); }
.btn-secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text-primary);
}
.btn-secondary:hover { background: var(--surface-hover); }
.btn-light-brand, .btn-brand-soft {
  background: var(--brand-soft);
  border-color: transparent;
  color: var(--brand-hover);
}
.btn-light-brand:hover, .btn-brand-soft:hover { background: var(--brand-subtle); }
.btn-neutral {
  background: var(--surface-active);
  border-color: transparent;
  color: var(--text-secondary);
}
.btn-neutral:hover { background: var(--surface-hover); }
.btn-danger {
  background: var(--danger-soft);
  border-color: var(--danger-subtle);
  color: var(--danger-strong);
}
.btn-danger:hover { background: var(--danger-subtle); }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-solid:hover { background: var(--danger-strong); border-color: var(--danger-strong); }

/* ---- 9. Badges — semantic soft variants ---- */
.badge.badge-featured, .badge-featured {
  background: var(--brand-soft);
  color: var(--brand-hover);
}
.badge-verified, .badge.badge-success {
  background: var(--success-soft);
  color: var(--success-strong);
}
.badge-sold, .badge.badge-neutral {
  background: var(--surface-active);
  color: var(--text-secondary);
}
.badge-pending, .badge.badge-warning {
  background: var(--warning-soft);
  color: var(--warning-strong);
}
.badge-report, .badge-scam, .badge.badge-danger {
  background: var(--danger-soft);
  color: var(--danger-strong);
}
.badge-info, .badge.badge-info {
  background: var(--info-soft);
  color: var(--info-strong);
}

/* ---- 10. Surface transitions + account theme toggle ---- */
html, body, .qa-sidebar, .dash-sidebar, .dash-content, .sng-header,
.sng-sidebar, .feed-post, .card, .post-card, .dash-card {
  transition: background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease;
}
.theme-mode-toggle {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 15px;
  transition: all 0.2s ease;
}
.theme-mode-toggle:hover {
  background: var(--surface-hover);
  border-color: var(--brand);
}

