/**
 * Shared Base Styles
 * Common CSS patterns used across all Rogue Origin apps
 * Consolidates: CSS variables, resets, typography, dark mode, animations
 */

/* ========================================
   CSS VARIABLES - THEME SYSTEM
   ======================================== */
:root {
  /* Rogue Origin Brand Colors */
  --ro-green: #668971;
  --ro-gold: #e4aa4f;
  --ro-gold-text: #9A7A2E; /* WCAG AA compliant gold for text on light backgrounds */

  /* Legacy aliases for backwards compatibility */
  --gold: var(--ro-gold);
  --green: var(--ro-green);

  /* Extended Brand Colors */
  --gold-light: #f0cb60;
  --gold-dim: rgba(228, 170, 79, 0.12);
  --green-light: #7a9d86;
  --green-dim: rgba(102, 137, 113, 0.12);
  --green-dark: #4a6b54;
  --sungrown: #bf8e4e;
  --sungrown-dim: rgba(191, 142, 78, 0.12);
  --greenhouse: #8f9263;
  --greenhouse-dim: rgba(143, 146, 99, 0.12);
  --indoor: #62758d;
  --indoor-dim: rgba(98, 117, 141, 0.12);

  /* Semantic Colors */
  --success: #668971;
  --warning: #e4aa4f;
  --danger: #c45c4a;
  --danger-dim: rgba(196, 92, 74, 0.12);
  --info: #62758d;

  /* Typography */
  --font-display: 'DM Serif Display', serif;
  --font-mono: 'JetBrains Mono', monospace;
  --font-ui: 'Outfit', 'Inter', system-ui, sans-serif;

  /* Light Theme (default) */
  --bg: #faf8f5;
  --bg-warm: #f3efe7;
  --bg-card: #ffffff;
  --bg-dark: #2d3a2e;
  --glass: rgba(255, 255, 255, 0.6);
  --glass-border: rgba(102, 137, 113, 0.15);
  --border: rgba(102, 137, 113, 0.2);
  --border-strong: rgba(102, 137, 113, 0.2);
  --border-light: rgba(102, 137, 113, 0.1);
  --text: #2d3a32;
  --text-secondary: #5a6b5f;
  --text-muted: #637168; /* WCAG AA compliant (was #8a9a8e at 2.79:1, now 4.51:1 on #faf8f5) */
  --text-light: #94a397;

  /* Spacing System */
  --space-xs: 8px;
  --space-sm: 16px;
  --space-md: 24px;
  --space-lg: 40px;
  --space-xl: 64px;

  /* Border Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* Shadows */
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 16px rgba(0, 0, 0, 0.1);
  --shadow-elevated:
    0 2px 4px rgba(0, 0, 0, 0.04),
    0 8px 16px rgba(0, 0, 0, 0.08);

  /* Header specific */
  --header-bg: #2d3a2e;
  --header-text: #faf8f4;

  /* Mobile Viewport Height (iOS Safari fix) */
  --app-height: 100vh;
  --header-height: 52px;
}

/* ========================================
   DARK MODE
   ======================================== */
body.dark-mode,
[data-theme="dark"] {
  --bg: #141816;
  --bg-warm: #1a1f16;
  --bg-card: rgba(26, 30, 27, 0.85);
  --bg-dark: #0f1210;
  --glass: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(102, 137, 113, 0.15);
  --border: rgba(102, 137, 113, 0.15);
  --border-strong: rgba(102, 137, 113, 0.2);
  --border-light: rgba(102, 137, 113, 0.1);
  --text: rgba(255, 255, 255, 0.88);
  --text-secondary: rgba(255, 255, 255, 0.6);
  --text-muted: rgba(255, 255, 255, 0.4);
  --text-light: rgba(255, 255, 255, 0.3);
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 8px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 16px rgba(0, 0, 0, 0.5);
  --gold-dim: rgba(228, 170, 79, 0.18);
  --green-dim: rgba(102, 137, 113, 0.18);
  --sungrown-dim: rgba(191, 142, 78, 0.18);
  --greenhouse-dim: rgba(143, 146, 99, 0.18);
  --indoor-dim: rgba(98, 117, 141, 0.18);
  --header-bg: #0f1210;
}

/* ========================================
   RESET & BASE STYLES
   ======================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* ========================================
   ACCESSIBILITY - FOCUS INDICATORS
   ======================================== */
/* WCAG AA compliant focus indicators for keyboard navigation */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[role="button"]:focus-visible,
[tabindex="0"]:focus-visible,
[tabindex]:not([tabindex="-1"]):focus-visible {
  outline: 2px solid var(--ro-green);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Skip link visibility */
.skip-link:focus {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 9999;
  padding: 12px 16px;
  background: var(--ro-green);
  color: white;
  text-decoration: none;
  border-radius: 8px;
  outline: 2px solid var(--ro-gold);
  outline-offset: 2px;
}

/* ========================================
   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 {
  to {
    transform: rotate(360deg);
  }
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

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

@keyframes tooltip-fade-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes modal-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modal-slide-in {
  from {
    transform: translateY(-20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

/* Spacing utilities */
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mb-sm { margin-bottom: var(--space-sm); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.p-sm { padding: var(--space-sm); }
.p-md { padding: var(--space-md); }
.p-lg { padding: var(--space-lg); }

/* Text utilities */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }

/* Display utilities */
.hidden { display: none !important; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-column { flex-direction: column; }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }

/* Common transitions */
.transition-all { transition: all 0.3s ease; }
.transition-colors { transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease; }

/* ========================================
   MOBILE TYPOGRAPHY (WCAG Compliance)
   ======================================== */
@media (max-width: 768px) {
  /* Enforce 12px minimum for accessibility */
  body {
    font-size: 14px;
  }

  small,
  .small,
  .text-sm,
  .text-xs {
    font-size: 12px !important;
  }

  .label,
  .badge,
  .hint {
    font-size: 12px !important;
  }
}

/* ========================================
   SAFE AREA INSETS (iPhone X+ Notch Support)
   ======================================== */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  .header {
    padding-top: max(12px, env(safe-area-inset-top));
  }

  .fab {
    bottom: max(24px, calc(24px + env(safe-area-inset-bottom)));
    right: max(24px, calc(24px + env(safe-area-inset-right)));
  }

  .sidebar {
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }

  /* Modals */
  .modal-content,
  .modal,
  .modal-overlay {
    margin-bottom: max(20px, env(safe-area-inset-bottom));
  }

  /* Settings panel */
  .settings-panel {
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }

  /* Detail panels (orders page) */
  .detail-panel {
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }
}

/* ========================================
   TOUCH FEEDBACK & HOVER STATES
   ======================================== */

/* Suppress hover effects on touch devices */
@media (hover: hover) and (pointer: fine) {
  /* Only apply hover effects on devices with mouse */
  button:hover,
  .btn:hover,
  .nav-item:hover,
  a:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
  }
}

/* Touch-specific feedback */
@media (hover: none) and (pointer: coarse) {
  /* Active state for touch */
  button:active,
  .btn:active,
  .nav-item:active,
  a:active {
    transform: scale(0.98);
    opacity: 0.9;
  }

  /* Ensure touch targets meet WCAG minimum */
  button,
  .btn,
  .nav-item,
  a,
  input[type="checkbox"],
  input[type="radio"] {
    min-height: 44px;
    min-width: 44px;
  }

  /* Remove hover state persistence on touch devices */
  button:hover,
  .btn:hover,
  .nav-item:hover,
  a:hover {
    transform: none;
    box-shadow: none;
  }
}

/* Ripple effect for touch interactions */
@media (hover: none) {
  button,
  .btn {
    position: relative;
    overflow: hidden;
  }

  button::after,
  .btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle, rgba(255,255,255,0.3) 0%, transparent 70%);
    opacity: 0;
    pointer-events: none;
    transform: scale(0);
    transition: transform 0.6s, opacity 0.6s;
  }

  button:active::after,
  .btn:active::after {
    transform: scale(2);
    opacity: 1;
    transition: transform 0s, opacity 0s;
  }
}

/* ========================================
   LANDSCAPE ORIENTATION OPTIMIZATIONS
   ======================================== */
@media (max-height: 500px) and (orientation: landscape) {
  /* Reduce vertical padding in landscape */
  body {
    padding-top: 8px;
  }

  .header {
    padding: 8px 16px;
    min-height: 48px;
  }

  /* Modals should be scrollable in landscape */
  .modal-content {
    max-height: 90vh;
    overflow-y: auto;
  }

  /* FAB smaller in landscape */
  .fab {
    width: 48px;
    height: 48px;
    bottom: 12px;
    right: 12px;
  }
}
