/* ============================================================
   Saudi DGA Unified Design System Compliance Layer
   كود المنصات — هيئة الحكومة الرقمية
   Reference: https://design.dga.gov.sa
   ============================================================

   This file layers Saudi DGA design tokens, accessibility
   requirements, and component standards on top of the existing
   SaudiOne Tourism theme. It maps govsa tokens to the theme's
   CSS custom properties for full compliance.
   ============================================================ */

/* ============================================================
   1. NATIONAL IDENTITY COLOR PALETTE (DGA)
   ============================================================ */
:root {
  /* Primary — Green (أخضر) — Saudi Flag */
  --govsa-green-900: #1B5E20;
  --govsa-green-700: #388E3C;
  --govsa-green-500: #4CAF50;
  --govsa-green-300: #81C784;
  --govsa-green-100: #C8E6C9;
  --govsa-green-50:  #E8F5E9;

  /* Secondary — Neutrals / Black (أسود) — Bisht */
  --govsa-black:     #000000;
  --govsa-gray-900:  #212121;
  --govsa-gray-700:  #616161;
  --govsa-gray-500:  #9E9E9E;
  --govsa-gray-300:  #E0E0E0;
  --govsa-gray-100:  #F5F5F5;
  --govsa-white:     #FFFFFF;

  /* Accent — Gold (ذهبي) — Ardah Sword & Desert */
  --govsa-gold-700:  #F9A825;
  --govsa-gold-500:  #FFD54F;
  --govsa-gold-300:  #FFF176;
  --govsa-gold-100:  #FFF8E1;

  /* Accent — Purple (بنفسجي) — Lavender */
  --govsa-purple-900: #4A148C;
  --govsa-purple-700: #7B1FA2;
  --govsa-purple-500: #AB47BC;
  --govsa-purple-300: #CE93D8;
  --govsa-purple-100: #F3E5F5;

  /* Semantic Colors */
  --govsa-success: #4CAF50;
  --govsa-warning: #F9A825;
  --govsa-error:   #D32F2F;
  --govsa-info:    #1976D2;

  /* ============================================================
     2. TYPOGRAPHY — IBM Plex Sans Arabic (DGA Mandatory)
     ============================================================ */
  --govsa-font-family: 'IBM Plex Sans Arabic', 'Tajawal', var(--so-font-sans);

  /* Type Scale (DGA Specification) */
  --govsa-display-2xl: 2.5rem;    /* 40px — Hero headings */
  --govsa-heading-h1:  2rem;      /* 32px — Page titles */
  --govsa-heading-h2:  1.5rem;    /* 24px — Section headings */
  --govsa-heading-h3:  1.25rem;   /* 20px — Subsection headings */
  --govsa-heading-h4:  1.125rem;  /* 18px — Card titles */
  --govsa-body-large:  1.125rem;  /* 18px — Lead paragraphs */
  --govsa-body:        1rem;      /* 16px — Body text */
  --govsa-body-small:  0.875rem;  /* 14px — Captions, helper text */
  --govsa-label:       0.75rem;   /* 12px — Form labels, tags */

  /* ============================================================
     3. SPACING SYSTEM — 4px Base Unit (DGA)
     ============================================================ */
  --govsa-space-1:  0.25rem;   /* 4px */
  --govsa-space-2:  0.5rem;    /* 8px */
  --govsa-space-3:  0.75rem;   /* 12px */
  --govsa-space-4:  1rem;      /* 16px */
  --govsa-space-5:  1.25rem;   /* 20px */
  --govsa-space-6:  1.5rem;    /* 24px */
  --govsa-space-8:  2rem;      /* 32px */
  --govsa-space-10: 2.5rem;    /* 40px */
  --govsa-space-12: 3rem;      /* 48px */
  --govsa-space-16: 4rem;      /* 64px */

  /* ============================================================
     4. RESPONSIVE BREAKPOINTS (DGA)
     ============================================================ */
  --govsa-breakpoint-sm:  576px;
  --govsa-breakpoint-md:  768px;
  --govsa-breakpoint-lg:  992px;
  --govsa-breakpoint-xl:  1200px;
  --govsa-breakpoint-xxl: 1400px;

  /* ============================================================
     5. FOCUS RING — DGA Accessibility (minimum 2px)
     ============================================================ */
  --govsa-focus-ring: 3px solid var(--govsa-green-700);
  --govsa-focus-offset: 2px;

  /* Touch target minimum (WCAG 2.2 Level AA) */
  --govsa-touch-target: 2.75rem; /* 44px */
}

/* ============================================================
   6. RTL TYPOGRAPHY — IBM Plex Sans Arabic as primary for RTL
   ============================================================ */
[dir="rtl"] body,
[dir="rtl"] {
  font-family: var(--govsa-font-family);
}

/* ============================================================
   7. FOCUS INDICATORS — DGA WCAG Compliance
   All interactive elements must have visible focus outlines
   ============================================================ */

/* Buttons */
.so-btn:focus-visible,
.button:focus-visible,
.btn:focus-visible,
.so-card__btn:focus-visible {
  outline: var(--govsa-focus-ring);
  outline-offset: var(--govsa-focus-offset);
  box-shadow: 0 0 0 6px rgba(56, 142, 60, 0.15);
}

/* Links */
a:focus-visible {
  outline: var(--govsa-focus-ring);
  outline-offset: var(--govsa-focus-offset);
  border-radius: 2px;
}

/* Form inputs */
.form-text:focus-visible,
.form-email:focus-visible,
.form-tel:focus-visible,
.form-select:focus-visible,
.form-search:focus-visible,
textarea:focus-visible,
input[type="text"]:focus-visible,
input[type="email"]:focus-visible,
input[type="tel"]:focus-visible,
input[type="number"]:focus-visible,
input[type="search"]:focus-visible,
input[type="password"]:focus-visible,
input[type="url"]:focus-visible,
select:focus-visible {
  outline: var(--govsa-focus-ring);
  outline-offset: 0;
  border-color: var(--govsa-green-700);
  box-shadow: 0 0 0 4px rgba(56, 142, 60, 0.12);
}

/* Checkboxes and Radios */
input[type="checkbox"]:focus-visible,
input[type="radio"]:focus-visible {
  outline: var(--govsa-focus-ring);
  outline-offset: var(--govsa-focus-offset);
}

/* Header interactive elements */
.so-header__icon-btn:focus-visible,
.so-header__mobile-toggle:focus-visible {
  outline: var(--govsa-focus-ring);
  outline-offset: var(--govsa-focus-offset);
  border-radius: var(--so-radius-sm, 0.375rem);
}

/* Nav items */
.so-nav a:focus-visible,
.so-menu a:focus-visible {
  outline: var(--govsa-focus-ring);
  outline-offset: var(--govsa-focus-offset);
}

/* Footer links */
.so-footer a:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.6);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Tab elements */
.so-chat__tab:focus-visible,
[role="tab"]:focus-visible {
  outline: var(--govsa-focus-ring);
  outline-offset: -2px;
}

/* ============================================================
   8. TOUCH TARGETS — Minimum 44x44px (WCAG 2.2)
   ============================================================ */

/* Buttons */
.so-btn,
.button,
.btn {
  min-height: var(--govsa-touch-target);
  min-width: var(--govsa-touch-target);
}

/* Icon buttons */
.so-header__icon-btn,
.so-header__mobile-toggle,
.so-floating-actions__btn,
.so-chat__trigger,
.so-a11y-trigger {
  min-width: var(--govsa-touch-target);
  min-height: var(--govsa-touch-target);
}

/* Card action buttons */
.so-card__btn {
  min-height: var(--govsa-touch-target);
  padding-block: var(--govsa-space-2);
}

/* Navigation links — ensure adequate hit area */
.so-nav a,
.so-menu a {
  min-height: var(--govsa-touch-target);
  display: inline-flex;
  align-items: center;
}

/* Footer links */
.so-footer__links a {
  min-height: calc(var(--govsa-touch-target) - 4px);
  display: inline-flex;
  align-items: center;
}

/* Form inputs */
.form-text,
.form-email,
.form-tel,
.form-select,
.form-search,
select,
textarea {
  min-height: var(--govsa-touch-target);
}

/* Pagination */
.pager__item a,
.pager__item span {
  min-width: var(--govsa-touch-target);
  min-height: var(--govsa-touch-target);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ============================================================
   9. REDUCED MOTION — DGA WCAG Compliance
   ============================================================ */
@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;
  }
}

/* ============================================================
   10. COLOR CONTRAST ENHANCEMENTS
   Ensure text on colored backgrounds meets 4.5:1 ratio
   ============================================================ */

/* Status badges — ensure accessible contrast */
.so-card__badge {
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* Placeholder text — improve contrast */
::placeholder {
  color: var(--govsa-gray-700);
  opacity: 1;
}

/* Disabled states — maintain readability */
[disabled],
.is-disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ============================================================
   11. SEMANTIC HTML & LANDMARK ENHANCEMENTS
   ============================================================ */

/* Ensure main content landmark is identifiable */
[role="main"],
main {
  min-height: 50vh;
}

/* Screen reader only text (DGA pattern) */
.govsa-sr-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;
}

/* ============================================================
   12. RTL LOGICAL PROPERTIES — DGA Compliance
   Override physical properties with logical equivalents
   ============================================================ */

/* Card border accent */
[dir="rtl"] .so-card {
  border-inline-start: none;
}

/* Breadcrumb separator direction */
[dir="rtl"] .breadcrumb-list {
  direction: rtl;
}

/* Alert/status icon alignment */
[dir="rtl"] .so-msg {
  text-align: start;
}

/* Form labels */
[dir="rtl"] label,
[dir="rtl"] .so-field__label {
  text-align: start;
}

/* Footer grid RTL */
[dir="rtl"] .so-footer__grid {
  direction: rtl;
}

/* ============================================================
   13. FORM ACCESSIBILITY — DGA Standards
   ============================================================ */

/* Required field indicator */
.form-required::after {
  content: " *";
  color: var(--lb-ui-error-fg);
  font-weight: 700;
}

/* Error state styling */
input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"],
.has-error input,
.has-error select,
.has-error textarea {
  border-color: var(--govsa-error);
  box-shadow: 0 0 0 3px rgba(211, 47, 47, 0.12);
}

/* Error message text */
.form-item--error-message,
.error-message {
  color: var(--lb-ui-error-fg);
  font-size: var(--govsa-body-small);
  font-weight: 500;
  margin-block-start: var(--govsa-space-1);
}

/* Success state */
input[aria-invalid="false"].is-valid,
.has-success input {
  border-color: var(--govsa-success);
}

/* ============================================================
   14. BUTTON VARIANTS — DGA Component Standards
   ============================================================ */

/* Primary button — Saudi Green */
.so-btn--primary,
.button,
.btn {
  font-weight: 600;
  letter-spacing: 0.01em;
  border-radius: var(--so-radius-sm, 0.375rem);
  transition: background-color 0.2s, box-shadow 0.2s, transform 0.1s;
}

/* Button active/pressed state */
.so-btn:active,
.button:active,
.btn:active {
  transform: scale(0.98);
}

/* Danger button */
.so-btn--danger {
  background: var(--govsa-error);
  color: var(--govsa-white);
  border: none;
}
.so-btn--danger:hover {
  background: #B71C1C;
}

/* ============================================================
   15. ALERT / NOTIFICATION STANDARDS — DGA
   ============================================================ */

/* Info alert */
.so-msg[data-msg-type="status"] {
  border-inline-start: 4px solid var(--govsa-success);
}

/* Warning alert */
.so-msg[data-msg-type="warning"] {
  border-inline-start: 4px solid var(--govsa-warning);
}

/* Error alert */
.so-msg[data-msg-type="error"] {
  border-inline-start: 4px solid var(--govsa-error);
}

/* ============================================================
   16. TABLE ACCESSIBILITY — DGA
   ============================================================ */

table {
  border-collapse: collapse;
  width: 100%;
}

th {
  text-align: start;
  font-weight: 600;
  color: var(--lb-ui-text-muted);
  background: var(--govsa-gray-100);
}

th, td {
  padding: var(--govsa-space-3) var(--govsa-space-4);
  border-bottom: 1px solid var(--govsa-gray-300);
}

/* Striped rows for readability */
tbody tr:nth-child(even) {
  background: var(--govsa-gray-100);
}

/* Row hover */
tbody tr:hover {
  background: var(--govsa-green-50);
}

/* ============================================================
   17. SKIP NAVIGATION — DGA Requirement
   Ensure skip link is visible on focus
   ============================================================ */

.visually-hidden.focusable:focus,
.visually-hidden.focusable:active {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100000;
  padding: var(--govsa-space-4);
  background: var(--govsa-green-900);
  color: var(--govsa-white);
  font-size: var(--govsa-body);
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  clip: auto;
  width: auto;
  height: auto;
  margin: 0;
  overflow: visible;
  white-space: normal;
}

/* ============================================================
   18. HIGH CONTRAST MODE SUPPORT
   ============================================================ */

@media (forced-colors: active) {
  .so-btn,
  .button,
  .btn {
    border: 2px solid ButtonText;
  }
  .so-card {
    border: 1px solid CanvasText;
  }
  a {
    text-decoration: underline;
  }
  *:focus-visible {
    outline: 3px solid Highlight;
  }
}

/* ============================================================
   19. PRINT STYLES — DGA
   ============================================================ */

@media print {
  /* Hide non-essential UI */
  .so-header,
  .so-topbar,
  .so-footer,
  .so-floating-actions,
  .so-chat,
  .so-a11y-trigger,
  .so-a11y-panel,
  .so-search-popup,
  .so-back-to-top,
  nav,
  .pager,
  .so-card__btn {
    display: none !important;
  }

  /* Optimize for print */
  body {
    font-size: 12pt;
    line-height: 1.5;
    color: #000;
    background: var(--lbayk-theme-surface, #fff);
  }

  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: var(--govsa-gray-700);
  }

  /* Prevent page breaks inside cards */
  .so-card,
  .so-detail,
  table {
    break-inside: avoid;
  }

  h1, h2, h3 {
    break-after: avoid;
  }

  img {
    max-width: 100%;
    break-inside: avoid;
  }
}
