/* ============================================================
   WHERE TO STAY — BASE STYLES
   ============================================================
   Modern CSS reset, root defaults, typography foundation
   and universal element behaviors.
   ============================================================ */


/* ------------------------------------------------------------
   MODERN CSS RESET
   ------------------------------------------------------------ */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  font-size: 16px;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  background-color: var(--bg-body);
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: var(--weight-normal);
  line-height: var(--leading-normal);
  transition: background-color var(--transition-base), color var(--transition-base);
}

/* Remove default styling from lists used as UI patterns */
ul[role="list"],
ol[role="list"],
ul[data-list-reset],
ol[data-list-reset] {
  list-style: none;
}

/* Prevent iOS text size adjustment after orientation change */
input,
button,
textarea,
select {
  font: inherit;
  color: inherit;
}

/* Make images and media block-level and responsive by default */
img,
picture,
video,
canvas,
svg {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Remove built-in form styling that varies across browsers */
button {
  background: none;
  border: none;
  cursor: pointer;
  color: inherit;
  font: inherit;
}

button:disabled {
  cursor: not-allowed;
}

/* Reset form element appearance */
input,
textarea,
select {
  background: none;
  border: none;
  outline: none;
  font: inherit;
  color: inherit;
}

textarea {
  resize: vertical;
  min-height: 100px;
}

/* Remove default fieldset styling */
fieldset {
  border: none;
  padding: 0;
  margin: 0;
}

legend {
  padding: 0;
}

/* Prevent horizontal scroll from tables */
table {
  border-collapse: collapse;
  border-spacing: 0;
  width: 100%;
}

/* Remove default anchor styling */
a {
  color: var(--text-link);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--text-link-hover);
}

a:focus-visible {
  outline: 2px solid var(--border-color-focus);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}


/* ------------------------------------------------------------
   ROOT SCROLLBAR STYLING (WebKit + Firefox)
   ------------------------------------------------------------ */

* {
  scrollbar-width: thin;
  scrollbar-color: var(--neutral-400) transparent;
}

*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: var(--neutral-300);
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  background-clip: content-box;
  transition: background var(--transition-fast);
}

*::-webkit-scrollbar-thumb:hover {
  background: var(--neutral-500);
  background-clip: content-box;
}

*::-webkit-scrollbar-corner {
  background: transparent;
}


/* ------------------------------------------------------------
   TYPOGRAPHY
   ------------------------------------------------------------ */

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  color: var(--text-primary);
  letter-spacing: var(--tracking-tight);
  text-wrap: balance;
}

h1 {
  font-size: var(--text-4xl);
  font-weight: var(--weight-extrabold);
  letter-spacing: var(--tracking-tighter);
}

h2 {
  font-size: var(--text-3xl);
  font-weight: var(--weight-bold);
}

h3 {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
}

h4 {
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
}

h5 {
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
}

h6 {
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-normal);
}

p {
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-relaxed);
  color: var(--text-primary);
  text-wrap: pretty;
}

/* Responsive heading sizes on larger screens */
@media (min-width: 768px) {
  h1 { font-size: var(--text-5xl); }
  h2 { font-size: var(--text-4xl); }
  h3 { font-size: var(--text-3xl); }
  h4 { font-size: var(--text-2xl); }
  h5 { font-size: var(--text-xl); }
}

@media (min-width: 1200px) {
  h1 { font-size: var(--text-6xl); }
}


/* ------------------------------------------------------------
   TEXT UTILITIES
   ------------------------------------------------------------ */

.text-xs { font-size: var(--text-xs); }
.text-sm { font-size: var(--text-sm); }
.text-base { font-size: var(--text-base); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.text-2xl { font-size: var(--text-2xl); }
.text-3xl { font-size: var(--text-3xl); }
.text-4xl { font-size: var(--text-4xl); }
.text-5xl { font-size: var(--text-5xl); }

.text-display-sm { font-size: var(--text-display-sm); font-family: var(--font-heading); font-weight: var(--weight-extrabold); line-height: var(--leading-tight); letter-spacing: var(--tracking-tighter); }
.text-display-md { font-size: var(--text-display-md); font-family: var(--font-heading); font-weight: var(--weight-extrabold); line-height: var(--leading-tight); letter-spacing: var(--tracking-tighter); }
.text-display-lg { font-size: var(--text-display-lg); font-family: var(--font-heading); font-weight: var(--weight-black); line-height: var(--leading-tight); letter-spacing: var(--tracking-tighter); }
.text-display-xl { font-size: var(--text-display-xl); font-family: var(--font-heading); font-weight: var(--weight-black); line-height: var(--leading-tight); letter-spacing: var(--tracking-tighter); }

.font-light { font-weight: var(--weight-light); }
.font-normal { font-weight: var(--weight-normal); }
.font-medium { font-weight: var(--weight-medium); }
.font-semibold { font-weight: var(--weight-semibold); }
.font-bold { font-weight: var(--weight-bold); }
.font-extrabold { font-weight: var(--weight-extrabold); }
.font-black { font-weight: var(--weight-black); }

.leading-none { line-height: var(--leading-none); }
.leading-tight { line-height: var(--leading-tight); }
.leading-snug { line-height: var(--leading-snug); }
.leading-normal { line-height: var(--leading-normal); }
.leading-relaxed { line-height: var(--leading-relaxed); }
.leading-loose { line-height: var(--leading-loose); }

.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.text-muted { color: var(--text-muted); }
.text-inverse { color: var(--text-inverse); }
.text-brand { color: var(--brand-primary); }
.text-accent { color: var(--brand-accent); }
.text-gold { color: var(--brand-secondary); }
.text-success { color: var(--color-success); }
.text-warning { color: var(--color-warning); }
.text-error { color: var(--color-error); }
.text-info { color: var(--color-info); }

.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-justify { text-align: justify; }

.text-uppercase { text-transform: uppercase; letter-spacing: var(--tracking-wider); }
.text-lowercase { text-transform: lowercase; }
.text-capitalize { text-transform: capitalize; }
.text-normal-case { text-transform: none; }

.text-tighter { letter-spacing: var(--tracking-tighter); }
.text-tight { letter-spacing: var(--tracking-tight); }
.text-wide { letter-spacing: var(--tracking-wide); }
.text-wider { letter-spacing: var(--tracking-wider); }
.text-widest { letter-spacing: var(--tracking-widest); }

.text-nowrap { white-space: nowrap; }
.text-wrap { white-space: normal; }

.text-truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.text-clamp-1 {
  display: -webkit-box;
  -webkit-line-clamp: 1;
  line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.text-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.text-clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.text-clamp-4 {
  display: -webkit-box;
  -webkit-line-clamp: 4;
  line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}


/* ------------------------------------------------------------
   SEMANTIC ELEMENTS
   ------------------------------------------------------------ */

blockquote {
  border-left: 4px solid var(--brand-primary);
  padding: var(--space-4) var(--space-6);
  margin: var(--space-6) 0;
  font-style: italic;
  color: var(--text-secondary);
  background-color: var(--bg-surface-alt);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

blockquote p {
  color: inherit;
}

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  padding: 0.15em 0.4em;
  background-color: var(--bg-surface-alt);
  color: var(--brand-accent);
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-color-light);
}

pre {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  padding: var(--space-4);
  background-color: var(--neutral-900);
  color: var(--neutral-100);
  border-radius: var(--radius-md);
  overflow-x: auto;
  line-height: var(--leading-relaxed);
}

pre code {
  background: none;
  color: inherit;
  padding: 0;
  border: none;
}

hr {
  border: none;
  height: 1px;
  background: var(--border-color);
  margin: var(--space-8) 0;
}

mark {
  background-color: var(--brand-secondary-100);
  color: var(--text-primary);
  padding: 0.05em 0.25em;
  border-radius: var(--radius-xs);
}

kbd {
  font-family: var(--font-mono);
  font-size: 0.85em;
  padding: 0.15em 0.5em;
  background-color: var(--bg-surface-alt);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-bottom-width: 2px;
  border-radius: var(--radius-xs);
  box-shadow: var(--shadow-xs);
}

address {
  font-style: normal;
  line-height: var(--leading-relaxed);
}

small {
  font-size: var(--text-sm);
  color: var(--text-tertiary);
}

strong,
b {
  font-weight: var(--weight-semibold);
}

em,
i {
  font-style: italic;
}

sub,
sup {
  font-size: 0.75em;
  line-height: 0;
}


/* ------------------------------------------------------------
   LISTS (When not reset)
   ------------------------------------------------------------ */

ul:not([role="list"]):not([data-list-reset]),
ol:not([role="list"]):not([data-list-reset]) {
  padding-left: var(--space-6);
  line-height: var(--leading-relaxed);
}

li {
  margin-bottom: var(--space-2);
}

li:last-child {
  margin-bottom: 0;
}


/* ------------------------------------------------------------
   FORM ELEMENT DEFAULTS
   ------------------------------------------------------------ */

/* Remove Chrome autofill yellow background */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
input:-webkit-autofill:active,
textarea:-webkit-autofill,
select:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 1000px var(--bg-surface) inset !important;
  -webkit-text-fill-color: var(--text-primary) !important;
  transition: background-color 5000s ease-in-out 0s;
  caret-color: var(--text-primary);
}

/* Remove number input spinners */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

/* Search input clear button */
input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-results-button,
input[type="search"]::-webkit-search-results-decoration {
  -webkit-appearance: none;
}

/* Placeholder styling */
::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

/* Selection styling */
::selection {
  background-color: var(--brand-primary);
  color: var(--text-on-primary);
}

::-moz-selection {
  background-color: var(--brand-primary);
  color: var(--text-on-primary);
}


/* ------------------------------------------------------------
   FOCUS STYLES (Accessibility)
   ------------------------------------------------------------ */

:focus {
  outline: none;
}

:focus-visible {
  outline: 2px solid var(--border-color-focus);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

button:focus-visible,
[role="button"]:focus-visible {
  outline: 2px solid var(--border-color-focus);
  outline-offset: 3px;
}

input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: none;
  border-color: var(--border-color-focus);
  box-shadow: var(--shadow-focus);
}


/* ------------------------------------------------------------
   VISUALLY HIDDEN (Accessibility helper)
   ------------------------------------------------------------ */

.sr-only,
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Show sr-only content when focused (for skip links) */
.sr-only:focus,
.sr-only:active,
.visually-hidden:focus,
.visually-hidden:active {
  position: static;
  width: auto;
  height: auto;
  padding: var(--space-2) var(--space-4);
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
  background: var(--brand-primary);
  color: var(--text-on-primary);
  border-radius: var(--radius-md);
  z-index: var(--z-max);
}


/* ------------------------------------------------------------
   SKIP TO MAIN CONTENT (Accessibility)
   ------------------------------------------------------------ */

.skip-to-main {
  position: absolute;
  top: -100px;
  left: var(--space-4);
  z-index: var(--z-max);
  padding: var(--space-3) var(--space-6);
  background: var(--brand-primary);
  color: var(--text-on-primary);
  font-weight: var(--weight-semibold);
  border-radius: var(--radius-md);
  transition: top var(--transition-base);
  box-shadow: var(--shadow-lg);
}

.skip-to-main:focus {
  top: var(--space-4);
  color: var(--text-on-primary);
}


/* ------------------------------------------------------------
   IMAGE LOADING & PLACEHOLDERS
   ------------------------------------------------------------ */

img {
  background-color: var(--bg-surface-alt);
}

img[loading="lazy"] {
  opacity: 0;
  transition: opacity var(--transition-slow);
}

img[loading="lazy"].loaded,
img[loading="lazy"][data-loaded="true"] {
  opacity: 1;
}

/* Broken image fallback styling */
img[alt]:not([alt=""]):before {
  content: attr(alt);
  display: block;
  padding: var(--space-4);
  background: var(--bg-surface-alt);
  color: var(--text-tertiary);
  font-size: var(--text-sm);
  text-align: center;
  border-radius: var(--radius-md);
}


/* ------------------------------------------------------------
   BODY LOCK (Used when modal is open)
   ------------------------------------------------------------ */

body.body-lock,
body.no-scroll {
  overflow: hidden;
  position: fixed;
  width: 100%;
}


/* ------------------------------------------------------------
   PAGE LOADING STATE
   ------------------------------------------------------------ */

body.page-loading {
  cursor: wait;
}

body.page-loading * {
  pointer-events: none;
}


/* ------------------------------------------------------------
   PRINT STYLES
   ------------------------------------------------------------ */

@media print {
  *,
  *::before,
  *::after {
    background: transparent !important;
    color: #000 !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }

  html,
  body {
    background: white;
    color: black;
    font-size: 12pt;
  }

  a,
  a:visited {
    text-decoration: underline;
    color: black;
  }

  a[href]:after {
    content: " (" attr(href) ")";
    font-size: 0.85em;
  }

  a[href^="#"]:after,
  a[href^="javascript:"]:after {
    content: "";
  }

  h1, h2, h3, h4, h5, h6 {
    page-break-after: avoid;
    page-break-inside: avoid;
  }

  p, blockquote {
    page-break-inside: avoid;
    orphans: 3;
    widows: 3;
  }

  img,
  svg {
    page-break-inside: avoid;
    max-width: 100% !important;
  }

  .no-print,
  nav,
  header,
  footer,
  .navbar,
  .footer,
  button {
    display: none !important;
  }

  .print-only {
    display: block !important;
  }
}


/* ------------------------------------------------------------
   BROWSER-SPECIFIC FIXES
   ------------------------------------------------------------ */

/* Safari input styling */
@supports (-webkit-touch-callout: none) {
  input,
  textarea,
  select {
    font-size: 16px; /* Prevents iOS zoom on focus */
  }
}

/* Firefox specific */
@-moz-document url-prefix() {
  select {
    background-image: none;
  }
}

/* Edge/IE fixes */
@supports (-ms-ime-align: auto) {
  img {
    max-width: 100%;
    height: auto;
  }
}


/* ------------------------------------------------------------
   ANIMATIONS (Base keyframes for reuse)
   ------------------------------------------------------------ */

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeInLeft {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes fadeInRight {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes slideInUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

@keyframes slideInDown {
  from {
    transform: translateY(-100%);
  }
  to {
    transform: translateY(0);
  }
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}

.animate-fade-in {
  animation: fadeIn var(--transition-slow) ease-out;
}

.animate-fade-in-up {
  animation: fadeInUp var(--transition-slow) ease-out;
}

.animate-fade-in-down {
  animation: fadeInDown var(--transition-slow) ease-out;
}

.animate-scale-in {
  animation: scaleIn var(--transition-base) ease-out;
}

.animate-slide-up {
  animation: slideInUp var(--transition-smooth) ease-out;
}

.animate-spin {
  animation: spin 1s linear infinite;
}

.animate-pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.animate-shimmer {
  background: linear-gradient(
    90deg,
    var(--bg-surface-alt) 0%,
    var(--bg-surface-hover) 50%,
    var(--bg-surface-alt) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}


/* ------------------------------------------------------------
   THEME TRANSITION SMOOTHNESS
   Prevent theme change flicker on non-color properties
   ------------------------------------------------------------ */

.theme-transition,
.theme-transition * {
  transition: background-color var(--transition-base),
              color var(--transition-base),
              border-color var(--transition-base),
              box-shadow var(--transition-base) !important;
}