/* Wasla Optics — app.css
   Raw CSS only — no @apply (Tailwind Play CDN does not process @apply in external files).
   Badge dark-mode handled via .dark selector. */

/* ─── Base font ──────────────────────────────────────────────────────────────
   Fallback if Tailwind config doesn't pick up font-family for some reason. */
html { font-family: 'Cairo', 'Tajawal', system-ui, sans-serif; }

/* ─── Status Badges ──────────────────────────────────────────────────────────
   Usage: <span class="badge badge-delivered">Delivered</span> */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.625rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.25rem;
  white-space: nowrap;
}

/* Order statuses */
.badge-pending      { background: #fef3c7; color: #92400e; }
.badge-confirmed    { background: #dbeafe; color: #1e40af; }
.badge-processing   { background: #dbeafe; color: #1e40af; }
.badge-shipped      { background: #e0e7ff; color: #3730a3; }
.badge-delivered    { background: #d1fae5; color: #065f46; }
.badge-cancelled    { background: #ffe4e6; color: #9f1239; }

/* Payment statuses */
.badge-paid         { background: #d1fae5; color: #065f46; }
.badge-unpaid       { background: #fef3c7; color: #92400e; }
.badge-partially-paid { background: #e0e7ff; color: #3730a3; }
.badge-refunded     { background: #e2e8f0; color: #1e293b; }

/* Shipping statuses */
.badge-not-shipped  { background: #fef3c7; color: #92400e; }
.badge-preparing    { background: #dbeafe; color: #1e40af; }
.badge-returned     { background: #e2e8f0; color: #1e293b; }

/* Affiliate / account statuses */
.badge-active       { background: #d1fae5; color: #065f46; }
.badge-suspended    { background: #ffe4e6; color: #9f1239; }
.badge-rejected     { background: #ffe4e6; color: #9f1239; }

/* Landing page / product status */
.badge-published    { background: #d1fae5; color: #065f46; }
.badge-draft        { background: #e2e8f0; color: #475569; }
.badge-disabled     { background: #ffe4e6; color: #9f1239; }

/* Affiliate levels */
.badge-bronze       { background: rgba(253,224,71,0.35);  color: #78350f; }
.badge-silver       { background: rgba(203,213,225,0.6);  color: #1e293b; }
.badge-gold         { background: rgba(251,191,36,0.3);   color: #713f12; }
.badge-platinum     { background: rgba(196,181,253,0.5);  color: #4c1d95; }

/* Dark mode badges */
.dark .badge-pending      { background: rgba(120,53,15,0.4);   color: #fde68a; }
.dark .badge-confirmed    { background: rgba(30,58,138,0.4);   color: #bfdbfe; }
.dark .badge-processing   { background: rgba(30,58,138,0.4);   color: #bfdbfe; }
.dark .badge-shipped      { background: rgba(55,48,163,0.4);   color: #c7d2fe; }
.dark .badge-delivered    { background: rgba(6,78,59,0.4);     color: #a7f3d0; }
.dark .badge-cancelled    { background: rgba(136,19,55,0.4);   color: #fecdd3; }
.dark .badge-paid         { background: rgba(6,78,59,0.4);     color: #a7f3d0; }
.dark .badge-unpaid       { background: rgba(120,53,15,0.4);   color: #fde68a; }
.dark .badge-partially-paid { background: rgba(55,48,163,0.4); color: #c7d2fe; }
.dark .badge-refunded     { background: #334155;               color: #e2e8f0; }
.dark .badge-not-shipped  { background: rgba(120,53,15,0.4);   color: #fde68a; }
.dark .badge-preparing    { background: rgba(30,58,138,0.4);   color: #bfdbfe; }
.dark .badge-returned     { background: #334155;               color: #e2e8f0; }
.dark .badge-active       { background: rgba(6,78,59,0.4);     color: #a7f3d0; }
.dark .badge-suspended    { background: rgba(136,19,55,0.4);   color: #fecdd3; }
.dark .badge-rejected     { background: rgba(136,19,55,0.4);   color: #fecdd3; }
.dark .badge-published    { background: rgba(6,78,59,0.4);     color: #a7f3d0; }
.dark .badge-draft        { background: #334155;               color: #cbd5e1; }
.dark .badge-disabled     { background: rgba(136,19,55,0.4);   color: #fecdd3; }
.dark .badge-bronze       { background: rgba(120,53,15,0.3);   color: #fcd34d; }
.dark .badge-silver       { background: rgba(71,85,105,0.4);   color: #e2e8f0; }
.dark .badge-gold         { background: rgba(113,63,18,0.3);   color: #fcd34d; }
.dark .badge-platinum     { background: rgba(76,29,149,0.3);   color: #ddd6fe; }

/* ─── Focus ring ─────────────────────────────────────────────────────────────
   Applied with class="focus-ring" on interactive elements. */
.focus-ring:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px #ffffff, 0 0 0 4px #6366f1;
}
.dark .focus-ring:focus-visible {
  box-shadow: 0 0 0 2px #0f172a, 0 0 0 4px #6366f1;
}

/* ─── Primary call-to-action fill (042) ──────────────────────────────────────
   Same indigo→violet hues as the brand gradient, two steps darker so white text clears
   WCAG AA (4.5:1) across the whole button: the shipped gradient ends at #3b82f6, which
   gives white text only 3.7:1. Used by the sign-up entry points (nav, /join/, home). */
.cta-brand {
  background-image: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  color: #ffffff;
}
.cta-brand:hover {
  background-image: linear-gradient(135deg, #4338ca 0%, #6d28d9 100%);
}

/* Placeholder text is text (WCAG 1.4.3, 4.5:1).  Tailwind's preflight paints every placeholder slate-400, which is 2.56:1 on white and
   4.04:1 on a slate-700 field.  This default (slate-500: 4.76:1 on white, 4.55:1 on slate-50; dark: 4.75:1 on slate-700) applies to every
   field that does not set its own `placeholder:` colour, public pages included; the extra `html` keeps it above the preflight rule. */
html input::placeholder,
html textarea::placeholder {
  color: #64748b;
  opacity: 1;
}
html.dark input::placeholder,
html.dark textarea::placeholder {
  color: #a3b1c4;
}

/* A scrollable table wrapper that main.js made a tab stop (initScrollableRegions) shows where focus is. */
.table-responsive[data-scroll-region]:focus-visible {
  outline: 2px solid #4f46e5;
  outline-offset: 2px;
}
.dark .table-responsive[data-scroll-region]:focus-visible {
  outline-color: #818cf8;
}

/* ─── Brand colour as TEXT on a dark page ────────────────────────────────────
   The Tailwind token `brand-primary` (templates/base.html) is #4f46e5: a surface that carries white text (6.3:1) and a text
   colour on the light page (6.0-6.3:1), but only ~3:1 against the dark page. Wherever it is used as text in dark mode the
   lighter indigo-400 step is used (6.0:1 on slate-900, 6.8:1 on slate-950, 4.9:1 on slate-800).
   Specificity (.dark + class) beats the generated utility whatever the order of the two style sheets. Shared by every page
   that loads this file. The public pages define --brand-on-dark themselves (public_base.html): the lightened default, or the
   owner's own colour untouched; every other shell has the fixed brand token and gets the fallback. */
.dark .text-brand-primary,
.dark .hover\:text-brand-primary:hover,
.dark .group:hover .group-hover\:text-brand-primary {
  color: var(--brand-on-dark, #818cf8);
}

/* ─── Brand gradient text utility ────────────────────────────────────────────
   Usage: <span class="gradient-brand-text">text</span> */
.gradient-brand-text {
  background: linear-gradient(135deg, #6366f1, #8b5cf6, #3b82f6);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ─── Sidebar active state ────────────────────────────────────────────────── */
.sidebar-link[aria-current="page"] {
  background: rgba(99,102,241,0.2);
  color: #ffffff;
}
.sidebar-link[aria-current="page"] [data-lucide] {
  color: #818cf8;
}

/* ─── Table Responsive ───────────────────────────────────────────────────────
   Wraps any <table> to scroll horizontally on small viewports.
   Approach: overflow-x-auto at all sizes + sticky first column at ≥640px.
   This is the consistent approach used across every list page (FR-040). */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 0.75rem;
}
@media (min-width: 640px) {
  .table-responsive thead th:first-child,
  .table-responsive tbody td:first-child {
    position: sticky;
    inset-inline-start: 0;
    background: inherit;
    z-index: 1;
  }
}

/* ─── Scroll affordance for wide tables (041 portals) ────────────────────────
   On a phone a list table scrolls sideways and nothing says there is more. The
   three marketplace portals put `table-fade` on <body>; their `.table-responsive`
   wrappers then fade out the edge that still has columns behind it. The mask only
   dims content while more is left to scroll to, so a table that fits (or one
   scrolled to its end) is untouched, and nothing is added to the layout.
   Browsers with scroll-driven animations do it in CSS alone; main.js sets the same
   --tr-fade property on the others (initTableScrollFade). Physical gradient
   directions: the fade belongs on the inline-END edge, i.e. right in LTR, left in RTL. */
@property --tr-fade { syntax: '<length>'; inherits: false; initial-value: 0px; }
.table-fade .table-responsive {
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - var(--tr-fade)), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - var(--tr-fade)), transparent);
}
[dir="rtl"] .table-fade .table-responsive {
  -webkit-mask-image: linear-gradient(to left, #000 calc(100% - var(--tr-fade)), transparent);
  mask-image: linear-gradient(to left, #000 calc(100% - var(--tr-fade)), transparent);
}
@keyframes table-scroll-fade { from { --tr-fade: 1.75rem; } to { --tr-fade: 0px; } }
@supports (animation-timeline: scroll()) {
  .table-fade .table-responsive {
    animation: table-scroll-fade linear both;
    animation-timeline: scroll(self inline);
    animation-range: calc(100% - 2rem) 100%;
  }
}

/* ─── Copied Toast ───────────────────────────────────────────────────────────
   Injected and shown by main.js copy handler. */
#copied-toast {
  position: fixed;
  bottom: 1.5rem;
  inset-inline-end: 1.5rem;
  z-index: 9999;
  background: #1e293b;
  color: #f1f5f9;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-family: 'Cairo', 'Tajawal', system-ui, sans-serif;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  opacity: 0;
  transform: translateY(0.5rem);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
}
#copied-toast.show { opacity: 1; transform: translateY(0); }

/* ─── Sidebar transition ─────────────────────────────────────────────────────
   Defined on element via Tailwind; this is just the fallback. */
#sidebar {
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── Modal backdrop ─────────────────────────────────────────────────────────
   main.js toggles hidden/flex; transition added here for smooth fade. */
[data-modal-backdrop] {
  transition: opacity 0.2s ease;
}
[data-modal-backdrop].flex { display: flex !important; }

/* ─── Print: invoice area ────────────────────────────────────────────────────
   Only the invoice card prints; everything else is hidden. */
@media print {
  body > *:not([data-print-area="invoice"]) { display: none !important; }
  [data-print-area="invoice"] {
    display: block !important;
    position: static !important;
    width: 100% !important;
    box-shadow: none !important;
  }
}

/* ─── RTL directional icon fix ───────────────────────────────────────────────
   Lucide chevron-right/arrow-right should point ← in RTL "forward" context. */
[dir="rtl"] [data-lucide="chevron-right"],
[dir="rtl"] [data-lucide="arrow-right"] {
  transform: scaleX(-1);
}

/* ─── Sidebar scrollbar ──────────────────────────────────────────────────────
   Thin, brand-tinted scrollbar for sidebar overflow on webkit browsers. */
#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-track { background: transparent; }
#sidebar::-webkit-scrollbar-thumb { background: #334155; border-radius: 2px; }
#sidebar::-webkit-scrollbar-thumb:hover { background: #6366f1; }

/* ─── Date-range popover ─────────────────────────────────────────────────────
   Visual-only popover opened/closed by main.js. */
[data-date-popover] {
  position: absolute;
  z-index: 50;
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 0.75rem;
  box-shadow: 0 8px 32px rgba(0,0,0,.12);
  padding: 1rem;
  min-width: 260px;
}
.dark [data-date-popover] {
  background: #1e293b;
  border-color: #334155;
}

/* ─── Tab active state ───────────────────────────────────────────────────────
   .tab-active is toggled by main.js tab switcher. */
.tab-active {
  color: #4f46e5;
  border-bottom-color: #4f46e5;
  font-weight: 600;
}
.dark .tab-active {
  color: #818cf8;
  border-bottom-color: #818cf8;
}

/* ─── Affiliate Bottom Navigation ───────────────────────────────────────────
   Fixed mobile bottom bar for the affiliate seller portal.
   Uses logical properties for RTL support. */
.affiliate-bottom-nav {
  box-shadow: 0 -1px 3px rgba(0, 0, 0, 0.06);
}
.affiliate-bottom-nav a[data-nav-target].is-active {
  color: #4f46e5;
  position: relative;
}
.affiliate-bottom-nav a[data-nav-target].is-active::before {
  content: '';
  position: absolute;
  inset-inline-start: 50%;
  top: 0;
  transform: translateX(-50%);
  width: 1.5rem;
  height: 0.2rem;
  border-radius: 9999px;
  background: #6366f1;
}
.dark .affiliate-bottom-nav a[data-nav-target].is-active {
  color: #818cf8;
}
.dark .affiliate-bottom-nav a[data-nav-target].is-active::before {
  background: #818cf8;
}

/* ─── Product Card ──────────────────────────────────────────────────────────
   Reusable card component for the affiliate product catalogue. */
.product-card .product-img-wrapper {
  position: relative;
  padding-top: 100%;
  overflow: hidden;
}
.product-card .product-img-wrapper img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ─── Line-clamp helper (if not already via Tailwind) ────────────────────── */
.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ─── Segmented Tabs ────────────────────────────────────────────────────────
   Used for category tabs on the dashboard and status filters on orders.
   Visual-only active state; no panel switching. */
[data-segments] {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
[data-segments]::-webkit-scrollbar { display: none; }
[data-segment] {
  display: inline-flex;
  align-items: center;
  padding: 0.375rem 0.875rem;
  border-radius: 9999px;
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
  border: 1px solid #e2e8f0;
  background: transparent;
  color: #64748b;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
[data-segment]:hover {
  background: #f1f5f9;
  color: #334155;
}
[data-segment].is-active {
  background: #4f46e5;
  color: #ffffff;
  border-color: #4f46e5;
}
.dark [data-segment] {
  border-color: #334155;
  color: #94a3b8;
}
.dark [data-segment]:hover {
  background: #1e293b;
  color: #e2e8f0;
}
.dark [data-segment].is-active {
  background: #4f46e5;
  color: #ffffff;
  border-color: #4f46e5;
}

/* ─── Empty State ─────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 1.5rem;
  gap: 1rem;
}

/* ─── Card Badge Tones ──────────────────────────────────────────────────────
   Small absolutely-positioned badges on product cards.
   Reuse existing .badge-* for order/earnings/level/account states. */
.badge-bestseller { background: #fef3c7; color: #92400e; }
.badge-new        { background: #d1fae5; color: #065f46; }
.badge-hot        { background: #ffe4e6; color: #9f1239; }

.dark .badge-bestseller { background: rgba(120,53,15,0.4);  color: #fde68a; }
.dark .badge-new        { background: rgba(6,78,59,0.4);    color: #a7f3d0; }
.dark .badge-hot        { background: rgba(136,19,55,0.4);  color: #fecdd3; }

/* ─── Desktop sidebar active state (affiliate) ──────────────────────────── */
.affiliate-bottom-nav a[data-nav-target].is-active,
.sidebar-link.is-active[aria-current="page"] {
  background: rgba(99,102,241,0.1);
  color: #4f46e5;
}
.dark .sidebar-link.is-active[aria-current="page"] {
  background: rgba(99,102,241,0.2);
  color: #818cf8;
}
.sidebar-link.is-active[aria-current="page"] [data-lucide] {
  color: #6366f1;
}
.dark .sidebar-link.is-active[aria-current="page"] [data-lucide] {
  color: #818cf8;
}

/* ─── Favorite heart toggle ──────────────────────────────────────────────── */
[data-favorite-toggle].is-favorited svg,
[data-favorite-toggle].is-favorited [data-lucide] {
  fill: currentColor;
  color: #f43f5e;
}
.dark [data-favorite-toggle].is-favorited svg,
.dark [data-favorite-toggle].is-favorited [data-lucide] {
  fill: currentColor;
  color: #fb7185;
}
/* When NOT favorited the heart must read as an outline, even if the markup
   hard-codes `fill-current`. Higher specificity than Tailwind's .fill-current
   so toggling the class off always visually empties the heart. */
[data-favorite-toggle]:not(.is-favorited) svg,
[data-favorite-toggle]:not(.is-favorited) [data-lucide] {
  fill: none;
}
