/* ================================================================
   Resayil — Brand Design Tokens
   Phase 24 (Rebrand + UI Overhaul), Plan 24-02
   ----------------------------------------------------------------
   Source of truth for brand CSS custom properties.
   Consumed by: hooks.py (web_include_css + app_include_css),
   portal pages under erpnext_cli/www/*, Desk customizations,
   and downstream plans 24-03 .. 24-07.

   Design system: design-system/resayil-platform/MASTER.md
   Brand decisions: .planning/phases/24-rebrand-ui-overhaul/24-CONTEXT.md

   Naming: all global tokens are prefixed --rs-* to avoid collisions
   with Frappe's built-in CSS variables and with page-scoped vars
   already used by /subscribe and /brand-preview (which keep their
   unprefixed local --accent, --bg, etc. scoped to their containers).
   ================================================================ */

:root {
  /* --- Accent (Resayil Orange) --- */
  --rs-accent: #FF6A00;
  --rs-accent-hover: #e65d00;
  --rs-accent-active: #cc5200;
  --rs-accent-soft: rgba(255, 106, 0, 0.10);
  --rs-accent-glow: rgba(255, 106, 0, 0.15);
  --rs-accent-tint: #FFF4E6;

  /* --- Backgrounds (light mode default) --- */
  --rs-bg: #ffffff;
  --rs-bg-subtle: #f7f8fa;
  --rs-bg-raised: #ffffff;
  --rs-surface: #ffffff;
  --rs-surface-2: #f5f5f5;

  /* --- Foregrounds --- */
  --rs-fg: #0a0a0a;
  --rs-fg-muted: #525252;
  --rs-fg-subtle: #737373;

  /* --- Borders --- */
  --rs-border: #e5e7eb;
  --rs-border-strong: #d4d4d8;

  /* --- Status / semantic --- */
  --rs-success: #10b981;
  --rs-warning: #f59e0b;
  --rs-danger: #ef4444;
  --rs-info: #3b82f6;

  /* --- Typography --- */
  --rs-font-sans: 'Plus Jakarta Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --rs-font-arabic: 'Cairo', 'Noto Sans Arabic', 'Plus Jakarta Sans', sans-serif;
  --rs-font-mono: ui-monospace, 'JetBrains Mono', 'SF Mono', Menlo, Monaco, Consolas, monospace;

  --rs-text-xs: 0.75rem;    /* 12px */
  --rs-text-sm: 0.875rem;   /* 14px */
  --rs-text-base: 1rem;     /* 16px */
  --rs-text-lg: 1.125rem;   /* 18px */
  --rs-text-xl: 1.25rem;    /* 20px */
  --rs-text-2xl: 1.5rem;    /* 24px */
  --rs-text-3xl: 1.875rem;  /* 30px */
  --rs-text-4xl: 2.25rem;   /* 36px */
  --rs-text-5xl: 3rem;      /* 48px */

  --rs-leading-tight: 1.2;
  --rs-leading-normal: 1.5;
  --rs-leading-relaxed: 1.65;

  /* --- Spacing (8pt grid) --- */
  --rs-space-0: 0;
  --rs-space-1: 0.25rem;    /* 4px */
  --rs-space-2: 0.5rem;     /* 8px */
  --rs-space-3: 0.75rem;    /* 12px */
  --rs-space-4: 1rem;       /* 16px */
  --rs-space-5: 1.25rem;    /* 20px */
  --rs-space-6: 1.5rem;     /* 24px */
  --rs-space-8: 2rem;       /* 32px */
  --rs-space-10: 2.5rem;    /* 40px */
  --rs-space-12: 3rem;      /* 48px */
  --rs-space-16: 4rem;      /* 64px */
  --rs-space-20: 5rem;      /* 80px */

  /* --- Radii --- */
  --rs-radius-sm: 0.25rem;  /* 4px */
  --rs-radius: 0.5rem;      /* 8px  -- default control radius */
  --rs-radius-md: 0.75rem;  /* 12px -- card radius */
  --rs-radius-lg: 1rem;     /* 16px -- panel radius */
  --rs-radius-xl: 1.5rem;   /* 24px */
  --rs-radius-full: 9999px;

  /* --- Shadows (light-mode tuned) --- */
  --rs-shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --rs-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
  --rs-shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --rs-shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --rs-shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
  --rs-shadow-glow: 0 0 40px var(--rs-accent-glow), 0 20px 60px rgb(0 0 0 / 0.08);

  /* --- Motion --- */
  --rs-ease: cubic-bezier(0.4, 0, 0.2, 1);
  --rs-ease-brand: cubic-bezier(0.22, 1, 0.36, 1); /* signature Resayil curve */
  --rs-duration-fast: 150ms;
  --rs-duration: 250ms;
  --rs-duration-slow: 400ms;

  /* --- Z-index ladder --- */
  --rs-z-dropdown: 1000;
  --rs-z-sticky: 1020;
  --rs-z-fixed: 1030;
  --rs-z-modal-backdrop: 1040;
  --rs-z-modal: 1050;
  --rs-z-popover: 1060;
  --rs-z-toast: 1070;
}

/* =====================================================
   Dark mode — opt-in via [data-theme="dark"] on <html>
   (or on any ancestor that hosts the theme scope)
   ===================================================== */
:root[data-theme="dark"],
[data-theme="dark"] {
  --rs-bg: #0a0a0a;
  --rs-bg-subtle: #141414;
  --rs-bg-raised: #1f1f23;
  --rs-surface: #141414;
  --rs-surface-2: #1c1c1c;

  --rs-fg: #fafafa;
  --rs-fg-muted: #a3a3a3;
  --rs-fg-subtle: #737373;

  --rs-border: #262626;
  --rs-border-strong: #404040;

  --rs-accent-soft: rgba(255, 106, 0, 0.15);
  --rs-accent-glow: rgba(255, 106, 0, 0.25);
  --rs-accent-tint: rgba(255, 106, 0, 0.08);

  --rs-shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.4);
  --rs-shadow: 0 1px 3px 0 rgb(0 0 0 / 0.4), 0 1px 2px -1px rgb(0 0 0 / 0.4);
  --rs-shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.5), 0 2px 4px -2px rgb(0 0 0 / 0.4);
  --rs-shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5), 0 4px 6px -4px rgb(0 0 0 / 0.4);
  --rs-shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.6), 0 8px 10px -6px rgb(0 0 0 / 0.5);
  --rs-shadow-glow: 0 0 40px var(--rs-accent-glow), 0 20px 60px rgb(0 0 0 / 0.45);
}

/* Respect OS preference when the user hasn't explicitly picked a theme.
   data-theme on <html> always wins; this is just the unset default. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
  }
}

/* =====================================================
   RTL — Arabic swaps to Cairo, keeps all other tokens
   ===================================================== */
[dir="rtl"] {
  font-family: var(--rs-font-arabic);
}

/* =====================================================
   Reduced motion — downstream animations must respect.
   ===================================================== */
@media (prefers-reduced-motion: reduce) {
  :root {
    --rs-duration-fast: 0.01ms;
    --rs-duration: 0.01ms;
    --rs-duration-slow: 0.01ms;
  }
}

/* ================================================================
   UTILITY CLASSES
   Minimal, opt-in. Consumers must apply .rs-* explicitly — we do
   not restyle native Frappe widgets in this file.
   ================================================================ */

/* --- Buttons --- */
.rs-btn-primary,
.rs-btn-secondary,
.rs-btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--rs-space-2);
  padding: 0.625rem 1.25rem;          /* 10px 20px */
  border-radius: var(--rs-radius);
  font-family: inherit;
  font-size: var(--rs-text-sm);
  font-weight: 600;
  line-height: 1.2;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition:
    background var(--rs-duration-fast) var(--rs-ease),
    color var(--rs-duration-fast) var(--rs-ease),
    border-color var(--rs-duration-fast) var(--rs-ease),
    box-shadow var(--rs-duration-fast) var(--rs-ease),
    transform var(--rs-duration-fast) var(--rs-ease);
}

.rs-btn-primary:disabled,
.rs-btn-secondary:disabled,
.rs-btn-ghost:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none !important;
  box-shadow: none !important;
}

.rs-btn-primary {
  background: var(--rs-accent);
  color: #ffffff;
  border-color: var(--rs-accent);
}
.rs-btn-primary:hover:not(:disabled) {
  background: var(--rs-accent-hover);
  border-color: var(--rs-accent-hover);
  color: #ffffff;
  transform: translateY(-1px);
  box-shadow: 0 6px 20px var(--rs-accent-glow);
  text-decoration: none;
}
.rs-btn-primary:active:not(:disabled) {
  background: var(--rs-accent-active);
  border-color: var(--rs-accent-active);
  transform: translateY(0);
}

.rs-btn-secondary {
  background: var(--rs-surface-2);
  color: var(--rs-fg);
  border-color: var(--rs-border);
}
.rs-btn-secondary:hover:not(:disabled) {
  background: var(--rs-bg-subtle);
  border-color: var(--rs-border-strong);
  color: var(--rs-fg);
  text-decoration: none;
}

.rs-btn-ghost {
  background: transparent;
  color: var(--rs-accent);
  border-color: var(--rs-accent);
}
.rs-btn-ghost:hover:not(:disabled) {
  background: var(--rs-accent-soft);
  color: var(--rs-accent);
  text-decoration: none;
}

/* --- Cards --- */
.rs-card {
  background: var(--rs-surface);
  border: 1px solid var(--rs-border);
  border-radius: var(--rs-radius-lg);
  padding: var(--rs-space-6);
  transition:
    border-color var(--rs-duration) var(--rs-ease-brand),
    box-shadow var(--rs-duration) var(--rs-ease-brand),
    transform var(--rs-duration) var(--rs-ease-brand);
}

.rs-card-elevated {
  background: var(--rs-surface);
  border: 1px solid var(--rs-border);
  border-radius: var(--rs-radius-lg);
  padding: var(--rs-space-6);
  box-shadow: var(--rs-shadow-md);
  transition:
    border-color var(--rs-duration) var(--rs-ease-brand),
    box-shadow var(--rs-duration) var(--rs-ease-brand),
    transform var(--rs-duration) var(--rs-ease-brand);
}
.rs-card-elevated:hover {
  transform: translateY(-2px);
  box-shadow: var(--rs-shadow-lg);
  border-color: var(--rs-border-strong);
}

/* --- Badges --- */
.rs-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--rs-space-1);
  padding: 0.125rem 0.625rem;          /* 2px 10px */
  border-radius: var(--rs-radius-full);
  font-size: var(--rs-text-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--rs-bg-subtle);
  color: var(--rs-fg-muted);
  border: 1px solid var(--rs-border);
  line-height: 1.4;
}

.rs-badge-accent {
  background: var(--rs-accent-soft);
  color: var(--rs-accent);
  border-color: transparent;
}

/* --- Focus ring (keyboard-only) --- */
.rs-focus-ring:focus-visible,
.rs-btn-primary:focus-visible,
.rs-btn-secondary:focus-visible,
.rs-btn-ghost:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--rs-accent-glow);
  border-color: var(--rs-accent);
}

/* --- Skeleton (loading shimmer) --- */
.rs-skeleton {
  position: relative;
  display: block;
  background: var(--rs-bg-subtle);
  border-radius: var(--rs-radius);
  overflow: hidden;
  color: transparent;
  user-select: none;
  pointer-events: none;
}
.rs-skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(
    90deg,
    transparent 0,
    var(--rs-accent-soft) 50%,
    transparent 100%
  );
  animation: rs-skeleton-shimmer 1.4s infinite;
}
@keyframes rs-skeleton-shimmer {
  100% { transform: translateX(100%); }
}
@media (prefers-reduced-motion: reduce) {
  .rs-skeleton::after { animation: none; }
}

/* --- Visually-hidden helper (a11y) --- */
.rs-sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
