/* =============================================================================
   FinePointRehab Base Styles
   Foundation CSS that works with tokens.css design system
   Mobile-first responsive approach with accessibility fundamentals
   ============================================================================= */

/* =============================================================================
   CSS RESET & NORMALIZATION
   ============================================================================= */

*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

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

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

body {
  font-family: var(--font-family-sans);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
  line-height: var(--line-height-normal);
  color: var(--text-primary);
  background-color: var(--bg-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  min-height: 100vh;
  min-height: 100dvh;
}

/* =============================================================================
   TYPOGRAPHY SCALE
   ============================================================================= */

h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-tight);
  color: var(--text-primary);
  margin-bottom: var(--space-4);
}

h1 { font-size: var(--font-size-3xl); font-weight: var(--font-weight-bold); }
h2 { font-size: var(--font-size-2xl); }
h3 { font-size: var(--font-size-xl); }
h4 { font-size: var(--font-size-lg); }
h5 { font-size: var(--font-size-base); }
h6 { font-size: var(--font-size-sm); font-weight: var(--font-weight-medium); }

@media (min-width: 768px) {
  h1 { font-size: var(--font-size-4xl); }
  h2 { font-size: var(--font-size-3xl); }
  h3 { font-size: var(--font-size-2xl); }
}

@media (min-width: 1024px) {
  h1 { font-size: var(--font-size-5xl); }
}

p, ul, ol, dl, blockquote { margin-bottom: var(--space-4); }
p:last-child, ul:last-child, ol:last-child, dl:last-child, blockquote:last-child { margin-bottom: 0; }

/* =============================================================================
   LINKS & INTERACTIVE ELEMENTS
   ============================================================================= */

a {
  color: var(--brand-blue);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
  transition: color var(--duration-fast) var(--easing);
}
a:hover { color: var(--brand-teal); text-decoration-thickness: 2px; }
a:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
a:focus:not(:focus-visible) { outline: none; }

/* =============================================================================
   FORM ELEMENTS
   ============================================================================= */

button,
input,
select,
textarea {
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
}

button {
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

input,
select,
textarea {
  background-color: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  color: var(--text-primary);
  transition: border-color var(--duration-fast) var(--easing),
              box-shadow var(--duration-fast) var(--easing);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--focus);
  box-shadow: var(--shadow-focus);
}

input::placeholder,
textarea::placeholder { color: var(--text-muted); }

/* =============================================================================
   TOUCH TARGETS & MOBILE OPTIMIZATION
   ============================================================================= */

button,
input[type="button"],
input[type="submit"],
input[type="reset"],
select,
a[role="button"],
[role="button"] {
  min-height: var(--touch-target);
  min-width: var(--touch-target);
}

p a, li a, td a, span a,
input[type="checkbox"], input[type="radio"] {
  min-height: auto;
  min-width: auto;
}

button, a, input, select, textarea {
  -webkit-tap-highlight-color: rgba(72, 202, 228, 0.1);
}

/* =============================================================================
   LAYOUT UTILITIES
   ============================================================================= */

.container {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 var(--space-4);
}
@media (min-width: 640px) { .container { padding: 0 var(--space-6); } }
@media (min-width: 1024px) { .container { padding: 0 var(--space-8); } }

.grid { display: grid; gap: var(--space-4); }
.grid-cols-1 { grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid-cols-sm-2 { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 768px) {
  .grid-cols-md-2 { grid-template-columns: repeat(2, 1fr); }
  .grid-cols-md-3 { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 1024px) { .grid-cols-lg-4 { grid-template-columns: repeat(4, 1fr); } }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }

/* =============================================================================
   SPACING UTILITIES
   ============================================================================= */

.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }

.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }

.p-2 { padding: var(--space-2); }
.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }
.p-8 { padding: var(--space-8); }

.px-4 { padding-left: var(--space-4); padding-right: var(--space-4); }
.py-2 { padding-top: var(--space-2); padding-bottom: var(--space-2); }
.py-4 { padding-top: var(--space-4); padding-bottom: var(--space-4); }

/* =============================================================================
   VISIBILITY & DISPLAY UTILITIES
   ============================================================================= */

.hidden { display: none; }
.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;
}
.block { display: block; }
.inline { display: inline; }
.inline-block { display: inline-block; }

@media (max-width: 639px) { .hidden-mobile { display: none; } }
@media (min-width: 640px) { .hidden-desktop { display: none; } }

/* =============================================================================
   TEXT UTILITIES
   ============================================================================= */

.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.text-xs { font-size: var(--font-size-xs); }
.text-sm { font-size: var(--font-size-sm); }
.text-base { font-size: var(--font-size-base); }
.text-lg { font-size: var(--font-size-lg); }
.text-xl { font-size: var(--font-size-xl); }
.text-2xl { font-size: var(--font-size-2xl); }

.font-normal { font-weight: var(--font-weight-normal); }
.font-medium { font-weight: var(--font-weight-medium); }
.font-semibold { font-weight: var(--font-weight-semibold); }
.font-bold { font-weight: var(--font-weight-bold); }

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

/* =============================================================================
   FOCUS MANAGEMENT & ACCESSIBILITY
   ============================================================================= */

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
:focus:not(:focus-visible) { outline: none; }

.skip-link {
  position: fixed;
  top: -40px;
  left: 6px;
  background: var(--bg-primary);
  color: var(--text-primary);
  padding: var(--space-2) var(--space-4);
  text-decoration: none;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  z-index: var(--z-tooltip);
  transition: top var(--duration-fast) var(--easing);
}
.skip-link:focus { top: 6px; }

/* =============================================================================
   MEDIA & IMAGES
   ============================================================================= */

img, video { max-width: 100%; height: auto; display: block; }
img { border-radius: var(--radius); }

/* =============================================================================
   LOADING STATES
   ============================================================================= */

.loading { opacity: 0.6; pointer-events: none; transition: opacity var(--duration-normal) var(--easing); }
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-radius: 50%;
  border-top-color: var(--brand-blue);
  animation: spin 1s ease-in-out infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =============================================================================
   PRINT STYLES
   ============================================================================= */

@media print {
  @page { margin: 1in; }
  *, *::before, *::after {
    background: transparent !important;
    color: black !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }
  a, a:visited { text-decoration: underline; }
  img { max-width: 100% !important; page-break-inside: avoid; }
  h2, h3 { page-break-after: avoid; }
}

/* =============================================================================
   HEADER + SAFE-AREA FIX
   ============================================================================= */

:root {
  --header-height: 56px; /* adjust if your nav is taller */
}

header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--bg-secondary);
  z-index: 1000;
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
}

main {
  padding-top: calc(var(--header-height) + env(safe-area-inset-top, 0));
}
