/**
 * Retailer — trade management
 * Brand Design System
 * WCAG 2.2 Level AA Compliant
 */

/* ============================================
   CSS Custom Properties (Design Tokens)
   ============================================ */
:root {
  /* Brand Colors */
  --brand-primary: #D24347;           /* AA on white (4.53:1) for normal text */
  --brand-primary-700: #B03438;       /* Higher contrast (5.88:1) for UI states */
  --brand-primary-800: #932E31;       /* AAA on white (7.85:1) for small text */
  
  /* Text Colors */
  --text-strong: #5A5A5A;             /* AAA on white (9.73:1) - body text */
  --text-medium: #6E6E6E;             /* AA on white (6.14:1) - secondary text */
  --text-light: #8A8A8A;              /* AA on white (4.53:1) - hint text */
  --text-inverse: #FFFFFF;            /* White text for dark backgrounds */
  
  /* Background & Surface Colors */
  --bg: #FFFFFF;                      /* Main background */
  --surface: #FAFAFA;                 /* Cards, panels */
  --surface-hover: #F5F5F5;           /* Hover states */
  --border: #E5E5E5;                  /* Default borders */
  --border-focus: var(--brand-primary-700);  /* Focus borders */
  
  /* Semantic Colors (all AA compliant) */
  --success: #1E7F4F;                 /* AA on white (4.51:1) */
  --success-bg: #F0F9F4;              /* Light success background */
  --warning: #A15C00;                 /* AA on white (4.52:1) */
  --warning-bg: #FFF8E6;              /* Light warning background */
  --error: #B3261E;                   /* AA on white (5.04:1) */
  --error-bg: #FFF6F6;                /* Light error background */
  --info: #0B5394;                    /* AA on white (7.12:1) */
  --info-bg: #E8F4FD;                 /* Light info background */
  
  /* Spacing Scale */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 24px;
  --space-2xl: 32px;
  --space-3xl: 48px;
  
  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-size-xs: 12px;
  --font-size-sm: 14px;
  --font-size-base: 16px;
  --font-size-lg: 18px;
  --font-size-xl: 20px;
  --font-size-2xl: 24px;
  --font-size-3xl: 30px;
  
  --line-height-tight: 1.25;
  --line-height-normal: 1.5;
  --line-height-relaxed: 1.75;
  
  /* Border Radius */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-full: 9999px;
  
  /* 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);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  
  /* Z-Index Scale */
  --z-base: 0;
  --z-dropdown: 1000;
  --z-sticky: 1100;
  --z-modal: 1200;
  --z-toast: 1300;
  
  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-base: 200ms ease;
  --transition-slow: 300ms ease;
}

/* ============================================
   Reset & Base Styles
   ============================================ */
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: var(--line-height-normal);
  color: var(--text-strong);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   WCAG 2.2 Focus Indicators
   ============================================ */
:where(a, button, [role="button"], input, select, textarea):focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  transition: outline-offset var(--transition-fast);
}

/* Ensure focus is never suppressed */
:focus:not(:focus-visible) {
  outline: none;
}

/* Enhanced focus for keyboard users */
.focus-visible:focus-visible {
  outline: 3px solid var(--brand-primary);
  outline-offset: 3px;
}

/* ============================================
   Skip Link (WCAG 2.4.1 Bypass Blocks)
   ============================================ */
.skip-link {
  position: absolute;
  left: -9999px;
  top: auto;
  width: 1px;
  height: 1px;
  overflow: hidden;
  z-index: var(--z-toast);
}

.skip-link:focus {
  position: fixed;
  top: var(--space-sm);
  left: var(--space-sm);
  width: auto;
  height: auto;
  padding: var(--space-md) var(--space-lg);
  background: var(--brand-primary-800);
  color: var(--text-inverse);
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  box-shadow: var(--shadow-lg);
}

/* ============================================
   Typography
   ============================================ */
h1, h2, h3, h4, h5, h6 {
  margin: 0 0 var(--space-lg) 0;
  font-weight: 600;
  line-height: var(--line-height-tight);
  color: var(--text-strong);
}

h1 { font-size: var(--font-size-3xl); }
h2 { font-size: var(--font-size-2xl); }
h3 { font-size: var(--font-size-xl); }
h4 { font-size: var(--font-size-lg); }
h5, h6 { font-size: var(--font-size-base); }

p {
  margin: 0 0 var(--space-md) 0;
}

.text-sm { font-size: var(--font-size-sm); }
.text-xs { font-size: var(--font-size-xs); }
.text-lg { font-size: var(--font-size-lg); }

.text-medium { color: var(--text-medium); }
.text-light { color: var(--text-light); }

.help, .hint {
  color: var(--text-medium);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-normal);
}

/* ============================================
   Buttons
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-xl);
  min-height: 44px; /* WCAG 2.5.8 Target Size minimum */
  font-size: var(--font-size-base);
  font-weight: 600;
  line-height: var(--line-height-tight);
  text-align: center;
  text-decoration: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-base);
  font-family: inherit;
  white-space: nowrap;
  user-select: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--brand-primary);
  color: var(--text-inverse);
  border-color: var(--brand-primary-700);
}

.btn-primary:hover:not(:disabled) {
  background: var(--brand-primary-700);
  border-color: var(--brand-primary-800);
}

.btn-primary:active:not(:disabled) {
  background: var(--brand-primary-800);
  transform: translateY(1px);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text-strong);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--text-medium);
}

.btn-full-width {
  width: 100%;
}

/* ============================================
   Form Elements
   ============================================ */
.form-group {
  margin-bottom: var(--space-lg);
}

.form-label {
  display: block;
  margin-bottom: var(--space-sm);
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--text-strong);
}

.form-label-required::after {
  content: " *";
  color: var(--error);
}

.input,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="tel"],
input[type="number"],
input[type="search"],
input[type="url"],
select,
textarea {
  display: block;
  width: 100%;
  padding: var(--space-md);
  min-height: 44px; /* WCAG 2.5.8 Target Size */
  font-size: var(--font-size-base);
  font-family: inherit;
  line-height: var(--line-height-normal);
  color: var(--text-strong);
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.input:hover,
input:hover:not(:disabled),
select:hover:not(:disabled),
textarea:hover:not(:disabled) {
  border-color: var(--text-medium);
}

.input:focus,
input:focus,
select:focus,
textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(210, 67, 71, 0.1);
  outline: none;
}

.input:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  background-color: var(--surface);
  color: var(--text-light);
  cursor: not-allowed;
  opacity: 0.6;
}

select {
  cursor: pointer;
  padding-right: var(--space-2xl); /* Space for dropdown arrow */
}

textarea {
  min-height: 100px;
  resize: vertical;
}

/* Input with icon */
.input-with-icon {
  position: relative;
}

.input-icon {
  position: absolute;
  top: 50%;
  left: var(--space-md);
  transform: translateY(-50%);
  color: var(--text-medium);
  pointer-events: none;
}

.input-with-icon input {
  padding-left: var(--space-3xl);
}

/* ============================================
   Form Validation (WCAG 2.2 Compliant)
   ============================================ */
.field-error,
.input[aria-invalid="true"],
input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
  border-color: var(--error);
  border-width: 2px;
}

.field-error:focus,
.input[aria-invalid="true"]:focus,
input[aria-invalid="true"]:focus,
select[aria-invalid="true"]:focus,
textarea[aria-invalid="true"]:focus {
  box-shadow: 0 0 0 3px rgba(179, 38, 30, 0.1);
}

.error-text,
.field-error-message {
  display: flex;
  align-items: flex-start;
  gap: var(--space-xs);
  margin-top: var(--space-xs);
  color: var(--error);
  font-size: var(--font-size-sm);
  font-weight: 600;
  line-height: var(--line-height-normal);
}

.error-text::before {
  content: "⚠";
  flex-shrink: 0;
}

/* Validation Summary */
.validation-summary {
  margin: var(--space-lg) 0;
  padding: var(--space-md) var(--space-lg);
  background: var(--error-bg);
  border-left: 4px solid var(--error);
  border-radius: var(--radius-sm);
}

.validation-summary[role="alert"] {
  /* Announced by screen readers */
}

.validation-summary h3 {
  margin: 0 0 var(--space-sm) 0;
  font-size: var(--font-size-base);
  color: var(--error);
}

.validation-summary ul {
  margin: 0;
  padding-left: var(--space-xl);
  color: var(--error);
  font-size: var(--font-size-sm);
}

.validation-summary li {
  margin-bottom: var(--space-xs);
}

/* Success state */
.field-success {
  border-color: var(--success);
}

.success-text {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  color: var(--success);
  font-size: var(--font-size-sm);
  font-weight: 600;
}

.success-text::before {
  content: "✓";
}

/* ============================================
   Links
   ============================================ */
a {
  color: var(--brand-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--brand-primary-700);
  text-decoration: underline;
}

a:active {
  color: var(--brand-primary-800);
}

/* Ensure sufficient contrast on non-white backgrounds */
.on-dark a {
  color: var(--text-inverse);
  text-decoration: underline;
}

.on-dark a:hover {
  opacity: 0.9;
}

/* ============================================
   Cards & Containers
   ============================================ */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-xl);
  box-shadow: var(--shadow-sm);
}

.card-header {
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-lg);
  border-bottom: 1px solid var(--border);
}

.card-title {
  margin: 0;
  font-size: var(--font-size-xl);
  font-weight: 600;
  color: var(--text-strong);
}

/* ============================================
   Utilities
   ============================================ */
.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;
}

.text-center { text-align: center; }
.text-right { text-align: right; }
.text-left { text-align: left; }

.mb-xs { margin-bottom: var(--space-xs); }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.mb-xl { margin-bottom: var(--space-xl); }

.mt-xs { margin-top: var(--space-xs); }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mt-xl { margin-top: var(--space-xl); }

/* ============================================
   Login Page Specific Styles
   ============================================ */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--space-xl);
  background: linear-gradient(135deg, var(--surface) 0%, var(--bg) 100%);
}

.login-card {
  width: 100%;
  max-width: 400px;
  padding: var(--space-3xl) var(--space-2xl);
  background: var(--bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.login-logo {
  display: block;
  max-width: 250px;
  height: auto;
  margin: 0 auto var(--space-xl) auto;
}

.login-title {
  margin-bottom: var(--space-xl);
  font-size: var(--font-size-2xl);
  font-weight: 600;
  text-align: center;
  color: var(--text-strong);
}

.login-subtitle {
  margin-bottom: var(--space-2xl);
  font-size: var(--font-size-sm);
  text-align: center;
  color: var(--text-medium);
}

.login-footer {
  margin-top: var(--space-xl);
  padding-top: var(--space-lg);
  border-top: 1px solid var(--border);
  font-size: var(--font-size-xs);
  text-align: center;
  color: var(--text-light);
}

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 480px) {
  .login-card {
    padding: var(--space-xl) var(--space-lg);
  }
  
  .btn {
    padding: var(--space-sm) var(--space-lg);
  }
}

/* ============================================
   Print Styles
   ============================================ */
@media print {
  .skip-link,
  .btn {
    display: none;
  }
  
  body {
    color: #000;
    background: #fff;
  }
}

/* ============================================
   High Contrast Mode Support
   ============================================ */
@media (prefers-contrast: high) {
  :root {
    --brand-primary: #B03438;
    --text-strong: #000000;
    --border: #8A8A8A;
  }
  
  .btn-primary {
    border-width: 2px;
  }
  
  input, select, textarea {
    border-width: 2px;
  }
}

/* ============================================
   Reduced Motion Support (WCAG 2.3.3)
   ============================================ */
@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;
  }
}




