/* ============================================================================
   EMAdvertise Frontend — Global CSS
   Reset, typography, RTL, responsive utilities, accessibility
   ============================================================================ */

/* === RESET === */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family-main);
  font-size: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  font-weight: var(--font-weight-normal);
  line-height: var(--line-height-normal);
  color: var(--color-text-primary);
  background-color: var(--color-bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

img,
svg {
  display: block;
  max-width: 100%;
  height: auto;
}

a {
  color: var(--color-accent);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--color-accent-hover);
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input,
select,
textarea {
  font: inherit;
  color: inherit;
}

ul,
ol {
  list-style: none;
}

/* === TYPOGRAPHY === */
h1 {
  font-size: clamp(1.75rem, 1.5rem + 1vw, 2.5rem);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
  letter-spacing: var(--letter-spacing-tight);
  color: var(--color-text-primary);
}

h2 {
  font-size: clamp(1.5rem, 1.3rem + 0.75vw, 2rem);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
  color: var(--color-text-primary);
}

h3 {
  font-size: clamp(1.25rem, 1.15rem + 0.5vw, 1.5rem);
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-tight);
  color: var(--color-text-primary);
}

h4 {
  font-size: clamp(1.125rem, 1.05rem + 0.25vw, 1.25rem);
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-tight);
}

p {
  color: var(--color-text-secondary);
  line-height: var(--line-height-normal);
}

.text-xs {
  font-size: clamp(0.625rem, 0.6rem + 0.125vw, 0.75rem);
  color: var(--color-text-muted);
}

.text-sm {
  font-size: clamp(0.75rem, 0.7rem + 0.2vw, 0.875rem);
}

.text-muted {
  color: var(--color-text-muted);
}

.text-secondary {
  color: var(--color-text-secondary);
}

/* === FOCUS & ACCESSIBILITY === */
:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
}

:focus:not(:focus-visible) {
  outline: none;
}

/* === REDUCED MOTION === */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* === CONTAINER === */
.container {
  width: 100%;
  padding-left: calc(var(--container-padding) + var(--safe-area-left));
  padding-right: calc(var(--container-padding) + var(--safe-area-right));
  margin-left: auto;
  margin-right: auto;
  max-width: var(--container-max-width);
}

/* === BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--btn-padding-y) var(--btn-padding-x);
  border-radius: var(--btn-radius);
  font-size: var(--btn-font-size);
  font-weight: var(--btn-font-weight);
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
  text-decoration: none;
  transition: all var(--transition-fast);
  white-space: nowrap;
  position: relative;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, var(--color-gradient-start), var(--color-gradient-end));
  color: #ffffff;
  box-shadow: var(--shadow-glow);
}

.btn-primary:hover {
  box-shadow: 0 0 30px rgba(79, 195, 247, 0.5);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--color-bg-tertiary);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover {
  background: var(--color-bg-hover);
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-secondary);
}

.btn-ghost:hover {
  background: var(--color-accent-subtle);
  color: var(--color-accent);
}

.btn-icon {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.btn-icon svg {
  width: 20px;
  height: 20px;
}

/* Full-width on mobile */
@media (max-width: 479px) {
  .btn-responsive {
    display: flex;
    width: 100%;
  }
}

@media (min-width: 480px) {
  .btn-responsive {
    min-width: 220px;
  }
}

/* === CARDS === */
.card {
  background: var(--color-bg-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--card-radius);
  padding: var(--card-padding);
  box-shadow: var(--shadow-card);
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.card:hover {
  transform: scale(1.02);
  box-shadow: var(--shadow-md);
}

.card:active {
  transform: scale(0.98);
}

/* === NAVBAR === */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--navbar-height);
  padding-top: var(--safe-area-top);
  background: var(--navbar-bg);
  backdrop-filter: blur(var(--navbar-blur));
  -webkit-backdrop-filter: blur(var(--navbar-blur));
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
}

.navbar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: var(--font-weight-bold);
  font-size: var(--font-size-lg);
  color: var(--color-text-primary);
  text-decoration: none;
}

.navbar-brand img,
.navbar-brand svg {
  max-width: 120px;
  height: auto;
}

@media (min-width: 768px) {
  .navbar-brand img,
  .navbar-brand svg {
    max-width: 160px;
  }
}

.navbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* === LANGUAGE SELECTOR === */
.lang-selector {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.lang-selector select {
  appearance: none;
  -webkit-appearance: none;
  background: var(--color-bg-tertiary);
  color: var(--color-text-primary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-full);
  padding: var(--space-2) var(--space-8) var(--space-2) var(--space-4);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  min-height: 44px;
  transition: border-color var(--transition-fast);
}

.lang-selector select:focus {
  border-color: var(--color-accent);
}

.lang-selector::after {
  content: '';
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--color-text-muted);
}

/* RTL adjust for selector arrow */
[dir="rtl"] .lang-selector::after {
  right: auto;
  left: 12px;
}

[dir="rtl"] .lang-selector select {
  padding: var(--space-2) var(--space-4) var(--space-2) var(--space-8);
}

/* === ANIMATIONS === */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.animate-fade-in-up {
  animation: fadeInUp 300ms ease forwards;
}

.animate-fade-in {
  animation: fadeIn 250ms ease forwards;
}

/* Staggered animation for card children */
.stagger-children > * {
  opacity: 0;
  animation: fadeInUp 300ms ease forwards;
}

.stagger-children > *:nth-child(1) { animation-delay: 0ms; }
.stagger-children > *:nth-child(2) { animation-delay: 50ms; }
.stagger-children > *:nth-child(3) { animation-delay: 100ms; }
.stagger-children > *:nth-child(4) { animation-delay: 150ms; }
.stagger-children > *:nth-child(5) { animation-delay: 200ms; }
.stagger-children > *:nth-child(6) { animation-delay: 250ms; }

/* === LOADER === */
.loader {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
}

/* === TOAST FALLBACK === */
.toast-fallback {
  position: fixed;
  bottom: calc(var(--space-4) + var(--safe-area-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  background: var(--color-bg-tertiary);
  color: var(--color-text-primary);
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-lg);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  white-space: nowrap;
  border: 1px solid var(--color-border);
  animation: fadeInUp 250ms ease forwards;
}

/* === SCREEN READER ONLY === */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* === RTL OVERRIDES === */
[dir="rtl"] {
  --letter-spacing-tight: 0;
}

[dir="rtl"] .icon-directional {
  transform: scaleX(-1);
}

/* === RESPONSIVE UTILITIES === */
.hidden-mobile {
  display: none;
}

@media (min-width: 768px) {
  .hidden-mobile {
    display: initial;
  }
  .hidden-tablet-up {
    display: none;
  }
}

/* === LANDSCAPE PHONE OPTIMIZATION === */
@media (orientation: landscape) and (max-height: 500px) {
  :root {
    --navbar-height: 48px;
  }

  .card {
    --card-padding: var(--space-4);
    --section-card-min-height: 120px;
  }
}

/* === BACK LINK === */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  min-height: 44px;
  padding: var(--space-2) 0;
  transition: color var(--transition-fast);
}

.back-link:hover {
  color: var(--color-accent);
}

.back-link svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}
