/*
 * GmarApp Login/Register Page
 * Design System Tokens Implementation
 * Version: 2.0.0
 * RTL + WCAG AA Compliant
 */

/* ============================================
   Design System Tokens (CSS Custom Properties)
   ============================================ */
:root {
  /* Colors - Background */
  --color-bg-page: #f5f0e8;
  --color-bg-surface: #ffffff;

  /* Colors - Text */
  --color-text-primary: #2c1810;
  --color-text-secondary: #6b5d52;

  /* Colors - Borders */
  --color-border-subtle: #e0d5c7;

  /* Colors - Brand */
  --color-brand-primary: #c7a853;
  --color-brand-secondary: #876c2c;

  /* Colors - States */
  --color-state-success: #28a745;
  --color-state-warning: #ffc107;
  --color-state-error: #dc3545;
  --color-state-info: #17a2b8;

  /* Typography - Font Family */
  --font-family-base: 'Assistant', 'Heebo', sans-serif;

  /* Typography - Font Sizes */
  --font-size-xs: 0.75rem;    /* 12px */
  --font-size-sm: 0.875rem;   /* 14px */
  --font-size-md: 1rem;       /* 16px */
  --font-size-lg: 1.125rem;   /* 18px */
  --font-size-xl: 1.5rem;     /* 24px */
  --font-size-2xl: 2rem;      /* 32px */

  /* Typography - Line Heights */
  --line-height-tight: 1.25;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.75;

  /* Typography - Font Weights */
  --font-weight-regular: 400;
  --font-weight-medium: 500;
  --font-weight-semibold: 600;
  --font-weight-bold: 700;

  /* Spacing (8px base) */
  --space-1: 0.25rem;  /* 4px */
  --space-2: 0.5rem;   /* 8px */
  --space-3: 0.75rem;  /* 12px */
  --space-4: 1rem;     /* 16px */
  --space-5: 1.5rem;   /* 24px */
  --space-6: 2rem;     /* 32px */
  --space-7: 2.5rem;   /* 40px */
  --space-8: 3rem;     /* 48px */

  /* Border Radius */
  --radius-sm: 0.375rem;  /* 6px */
  --radius-md: 0.75rem;   /* 12px */
  --radius-lg: 1.5rem;    /* 24px */

  /* Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms ease;
}

/* ============================================
   Base Styles & Reset
   ============================================ */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Remove tap highlight on mobile */
* {
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-family-base);
  font-size: var(--font-size-md);
  line-height: var(--line-height-normal);
  color: var(--color-text-primary);
  background: linear-gradient(135deg, #2c1810, #4a2f1c);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================
   Accessibility Utilities
   ============================================ */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* 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-width: 0;
}

/* Focus visible styles */
*:focus-visible {
  outline: 3px solid rgba(199, 168, 83, 0.3);
  outline-offset: 2px;
}

/* ============================================
   Page Layout
   ============================================ */
.auth-page {
  width: 100%;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.auth-container {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
}

.auth-card {
  background: var(--color-bg-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-6);
  animation: slideUp 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================
   Flash Messages
   ============================================ */
.flash-messages {
  margin-bottom: var(--space-5);
}

.alert {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-3);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  animation: slideInDown 300ms ease;
}

.alert-error {
  background: rgba(220, 53, 69, 0.1);
  color: var(--color-state-error);
  border: 1px solid rgba(220, 53, 69, 0.2);
}

.alert-success {
  background: rgba(40, 167, 69, 0.1);
  color: var(--color-state-success);
  border: 1px solid rgba(40, 167, 69, 0.2);
}

.alert i {
  font-size: var(--font-size-lg);
  flex-shrink: 0;
}

.alert span {
  flex: 1;
}

.alert-close {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: var(--space-1);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background var(--transition-base);
}

.alert-close:hover {
  background: rgba(0, 0, 0, 0.05);
}

@keyframes slideInDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================
   Tabs Navigation
   ============================================ */
.tabs {
  display: flex;
  gap: var(--space-2);
  justify-content: center;
  margin-bottom: var(--space-5);
  background: transparent;
  border: none;
  padding: 0;
}

.tab-button {
  flex: 0 1 auto;
  min-width: 120px;
  padding: var(--space-2) var(--space-5);
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  color: var(--color-text-primary);
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
  font-family: var(--font-family-base);
  cursor: pointer;
  transition: all var(--transition-base);
  text-align: center;
}

.tab-button:hover:not(.active) {
  background: var(--color-bg-page);
}

.tab-button.active {
  background: var(--color-brand-primary);
  color: var(--color-bg-surface);
}

.tab-button:focus-visible {
  outline: 3px solid rgba(199, 168, 83, 0.3);
  outline-offset: 2px;
}

/* ============================================
   Tab Panels
   ============================================ */
.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
  animation: fadeIn 300ms ease;
}

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

/* ============================================
   Panel Header
   ============================================ */
.panel-header {
  text-align: center;
  margin-bottom: var(--space-5);
}

.panel-title {
  font-size: var(--font-size-2xl);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  margin: 0 0 var(--space-2) 0;
  line-height: var(--line-height-tight);
}

.brand-name {
  color: var(--color-brand-primary);
}

.panel-subtitle {
  font-size: var(--font-size-md);
  color: var(--color-text-secondary);
  margin: 0;
  line-height: var(--line-height-normal);
}

/* ============================================
   Forms
   ============================================ */
.auth-form {
  margin-bottom: var(--space-4);
}

.form-field {
  margin-bottom: var(--space-3);
}

.form-field:last-child {
  margin-bottom: 0;
}

/* Input Wrapper */
.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  right: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-secondary);
  font-size: var(--font-size-md);
  pointer-events: none;
  z-index: 1;
}

/* Form Inputs */
.form-input {
  width: 100%;
  padding: var(--space-3) var(--space-8) var(--space-3) var(--space-3);
  background: var(--color-bg-page);
  border: 2px solid var(--color-border-subtle);
  border-radius: var(--radius-sm);
  color: var(--color-text-primary);
  font-size: var(--font-size-md);
  font-family: var(--font-family-base);
  line-height: var(--line-height-normal);
  transition: all var(--transition-base);
  min-height: 48px;
  text-align: right;
  direction: rtl;
}

.form-input::placeholder {
  color: var(--color-text-secondary);
  opacity: 0.7;
}

.form-input:hover {
  border-color: var(--color-brand-primary);
}

.form-input:focus {
  outline: none;
  background: var(--color-bg-surface);
  border-color: var(--color-brand-primary);
  box-shadow: 0 0 0 3px rgba(199, 168, 83, 0.1);
}

.form-input:focus + .input-icon {
  color: var(--color-brand-primary);
}

/* Error State */
.form-input[aria-invalid="true"] {
  border-color: var(--color-state-error);
}

.form-input[aria-invalid="true"]:focus {
  box-shadow: 0 0 0 3px rgba(220, 53, 69, 0.1);
}

/* Success State */
.form-input.valid {
  border-color: var(--color-state-success);
}

/* Field Messages */
.field-error,
.field-success,
.field-hint {
  display: block;
  font-size: var(--font-size-sm);
  margin-top: var(--space-1);
  line-height: var(--line-height-normal);
}

.field-error {
  color: var(--color-state-error);
}

.field-error:empty {
  display: none;
}

.field-success {
  color: var(--color-state-success);
}

.field-success:empty {
  display: none;
}

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

/* ============================================
   Password Field Enhancements
   ============================================ */

/* Password fields with toggle button need extra padding on left for the eye icon */
/* But keep the same right padding as other fields */
.password-field .form-input {
  padding-left: calc(var(--space-3) + var(--space-5));  /* Extra space for eye icon */
}

.password-toggle {
  position: absolute;
  left: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--color-text-secondary);
  cursor: pointer;
  padding: var(--space-2);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: all var(--transition-base);
  z-index: 2;
}

.password-toggle:hover {
  color: var(--color-text-primary);
  background: rgba(0, 0, 0, 0.05);
}

.password-toggle:focus-visible {
  outline: 2px solid var(--color-brand-primary);
  outline-offset: 2px;
}

/* Password Strength Meter */
.password-strength {
  margin-top: var(--space-2);
}

.strength-meter {
  height: 4px;
  background: var(--color-bg-page);
  border-radius: var(--radius-sm);
  overflow: hidden;
  margin-bottom: var(--space-1);
}

.strength-bar {
  height: 100%;
  width: 0%;
  transition: all var(--transition-slow);
  border-radius: var(--radius-sm);
}

.strength-bar[data-strength="0"] {
  width: 0%;
  background: transparent;
}

.strength-bar[data-strength="1"] {
  width: 25%;
  background: var(--color-state-error);
}

.strength-bar[data-strength="2"] {
  width: 50%;
  background: var(--color-state-warning);
}

.strength-bar[data-strength="3"] {
  width: 75%;
  background: var(--color-state-success);
}

.strength-bar[data-strength="4"] {
  width: 100%;
  background: var(--color-state-success);
}

.strength-label {
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  font-weight: var(--font-weight-medium);
}

/* ============================================
   Form Options
   ============================================ */
.form-options {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* Checkbox */
.checkbox-label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  margin: 0;
  user-select: none;
}

.checkbox-input {
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-base);
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background: var(--color-bg-surface);
  position: relative;
  flex-shrink: 0;
}

.checkbox-input:checked {
  background: var(--color-brand-primary);
  border-color: var(--color-brand-primary);
}

.checkbox-input:checked::after {
  content: '\f00c';
  font-family: 'Font Awesome 6 Free';
  font-weight: 900;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--color-bg-surface);
  font-size: 12px;
}

.checkbox-input:focus-visible {
  outline: 2px solid var(--color-brand-primary);
  outline-offset: 2px;
}

.checkbox-text {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.checkbox-field {
  margin-bottom: var(--space-4);
}

/* ============================================
   Links
   ============================================ */
.link-primary,
.link-secondary {
  font-size: var(--font-size-sm);
  color: var(--color-brand-primary);
  text-decoration: none;
  font-weight: var(--font-weight-medium);
  transition: all var(--transition-base);
  cursor: pointer;
  background: none;
  border: none;
  font-family: var(--font-family-base);
  padding: 0;
}

.link-primary:hover,
.link-secondary:hover {
  text-decoration: underline;
  color: var(--color-brand-secondary);
}

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

.link-inline {
  color: var(--color-brand-primary);
  text-decoration: none;
  font-weight: var(--font-weight-semibold);
  transition: all var(--transition-base);
}

.link-inline:hover {
  text-decoration: underline;
  color: var(--color-brand-secondary);
}

/* ============================================
   Buttons
   ============================================ */
.btn-primary,
.btn-secondary,
.btn-tertiary {
  width: 100%;
  min-height: 48px;
  padding: var(--space-3) var(--space-5);
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  font-family: var(--font-family-base);
  cursor: pointer;
  transition: all var(--transition-base);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  position: relative;
  margin-bottom: var(--space-4);
}

.btn-primary {
  background: var(--color-brand-primary);
  color: var(--color-bg-surface);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover:not(:disabled) {
  background: var(--color-brand-secondary);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: var(--shadow-sm);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-tertiary {
  background: transparent;
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  margin-bottom: 0;
}

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

/* Button Loading State */
.btn-spinner {
  display: none;
  width: 20px;
  height: 20px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.btn-primary.loading .btn-spinner,
.btn-secondary.loading .btn-spinner {
  display: block;
}

.btn-primary.loading,
.btn-secondary.loading {
  opacity: 0.7;
  cursor: not-allowed;
  pointer-events: none;
}

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

/* ============================================
   Divider
   ============================================ */
.divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: var(--space-4) 0;
  color: var(--color-text-secondary);
  font-size: var(--font-size-sm);
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--color-border-subtle);
}

.divider-text {
  padding: 0 var(--space-3);
}

/* ============================================
   Social Authentication
   ============================================ */
.social-auth {
  margin-bottom: var(--space-4);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Google Sign-In Button Wrapper */
.g_id_signin {
  width: 100% !important;
  display: flex !important;
  justify-content: center !important;
}

/* ============================================
   Panel Footer
   ============================================ */
.panel-footer {
  text-align: center;
  margin-top: var(--space-4);
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

.footer-text {
  margin-left: var(--space-2);
}

/* ============================================
   Modal System
   ============================================ */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  z-index: 999;
  animation: fadeIn 200ms ease;
}

.modal-overlay.active {
  display: block;
}

.modal {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1000;
  max-width: 90%;
  width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal.active {
  display: block;
  animation: fadeInScale 200ms ease-out;
}

.modal.modal-large {
  width: 600px;
}

@keyframes fadeInScale {
  from {
    opacity: 0;
    transform: translate(-50%, -48%) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

.modal-content {
  background: var(--color-bg-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-lg);
  position: relative;
}

.modal-close {
  position: absolute;
  top: var(--space-4);
  left: var(--space-4);
  background: none;
  border: none;
  color: var(--color-text-secondary);
  cursor: pointer;
  padding: var(--space-2);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: all var(--transition-base);
  font-size: var(--font-size-lg);
  width: 32px;
  height: 32px;
}

.modal-close:hover {
  color: var(--color-text-primary);
  background: var(--color-bg-page);
}

.modal-title {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  margin: 0 0 var(--space-4) 0;
  padding-left: var(--space-8);
}

.modal-description {
  font-size: var(--font-size-md);
  color: var(--color-text-secondary);
  margin: 0 0 var(--space-5) 0;
  line-height: var(--line-height-relaxed);
}

.modal-body {
  max-height: 50vh;
  overflow-y: auto;
  margin-bottom: var(--space-4);
  padding: var(--space-4);
  background: var(--color-bg-page);
  border-radius: var(--radius-md);
  color: var(--color-text-primary);
  line-height: var(--line-height-relaxed);
}

.modal-form {
  margin: 0;
}

.modal-form .btn-primary,
.modal-form .btn-tertiary {
  margin-bottom: var(--space-3);
}

.modal-form .btn-tertiary:last-child {
  margin-bottom: 0;
}

/* ============================================
   Responsive Design
   ============================================ */

/* Mobile Small (320px - 375px) */
@media (max-width: 375px) {
  .auth-card {
    padding: var(--space-4);
    border-radius: var(--radius-md);
  }

  .panel-title {
    font-size: var(--font-size-xl);
  }

  .panel-subtitle {
    font-size: var(--font-size-sm);
  }

  .tab-button {
    min-width: 100px;
    padding: var(--space-2) var(--space-4);
    font-size: var(--font-size-sm);
  }

  .form-input {
    font-size: var(--font-size-sm);
  }

  .btn-primary {
    font-size: var(--font-size-md);
  }
}

/* Mobile Large (376px - 480px) */
@media (max-width: 480px) {
  .auth-page {
    padding: var(--space-3);
  }

  .auth-card {
    padding: var(--space-5);
  }

  .tabs {
    margin-bottom: var(--space-4);
  }

  .panel-header {
    margin-bottom: var(--space-4);
  }

  .modal {
    width: 95%;
  }

  .modal-content {
    padding: var(--space-5);
  }

  .form-options {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* Tablet (481px - 768px) */
@media (min-width: 481px) and (max-width: 768px) {
  .auth-container {
    max-width: 480px;
  }
}

/* Desktop (769px+) */
@media (min-width: 769px) {
  .auth-container {
    max-width: 400px;
  }

  .auth-card:hover {
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  }
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
  .auth-page {
    background: white;
  }

  .auth-card {
    box-shadow: none;
    border: 1px solid #000;
  }

  .btn-primary,
  .social-auth,
  .modal {
    display: none;
  }
}

/* ============================================
   High Contrast Mode Support
   ============================================ */
@media (prefers-contrast: high) {
  .form-input {
    border-width: 2px;
  }

  .btn-primary {
    border: 2px solid currentColor;
  }

  .checkbox-input {
    border-width: 3px;
  }
}

/* ============================================
   Reduced Motion Support
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
