/**
 * Base Styles - Foundation
 * 
 * Global resets and base element styles
 * Import design-tokens.css before this file
 */

/* ═══════════════════════════════════════════════════════════
   MODERN CSS RESET
   Based on Josh Comeau's CSS Reset
   ══════════════════════════════════════════════════════════ */

*, *::before, *::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

html {
  /* Prevent font size inflation */
  -moz-text-size-adjust: none;
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  
  /* Smooth scrolling */
  scroll-behavior: smooth;
  
  /* Base font size */
  font-size: 15px;
}

/* Remove default margin and improve text rendering */
body {
  min-height: 100vh;
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  
  /* Design tokens */
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
}

/* Improve media defaults */
img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
}

/* Remove built-in form typography styles */
input, button, textarea, select {
  font: inherit;
}

/* Avoid text overflows */
p, h1, h2, h3, h4, h5, h6 {
  overflow-wrap: break-word;
}

/* Improve line wrapping */
p {
  text-wrap: pretty;
}

h1, h2, h3, h4, h5, h6 {
  text-wrap: balance;
}


/* ═══════════════════════════════════════════════════════════
   TYPOGRAPHY SYSTEM
   ══════════════════════════════════════════════════════════ */

h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-bold);
  color: var(--text-primary);
  line-height: var(--leading-tight);
}

h1 {
  font-size: var(--text-4xl);
  margin-bottom: var(--space-6);
}

h2 {
  font-size: var(--text-3xl);
  margin-bottom: var(--space-5);
}

h3 {
  font-size: var(--text-2xl);
  margin-bottom: var(--space-4);
}

h4 {
  font-size: var(--text-xl);
  margin-bottom: var(--space-3);
}

h5 {
  font-size: var(--text-lg);
  margin-bottom: var(--space-3);
}

h6 {
  font-size: var(--text-base);
  margin-bottom: var(--space-2);
}

p {
  margin-bottom: var(--space-4);
  color: var(--text-primary);
  font-size: var(--text-base);
  line-height: var(--leading-relaxed);
}

small {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

strong, b {
  font-weight: var(--font-semibold);
}

em, i {
  font-style: italic;
}

a {
  color: var(--text-link);
  text-decoration: underline;
  transition: var(--transition-colors);
}

a:hover {
  color: var(--text-link-hover);
}

a:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--bg-tertiary);
  padding: 0.125em 0.375em;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

pre {
  font-family: var(--font-mono);
  background: var(--bg-tertiary);
  padding: var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  overflow-x: auto;
  margin-bottom: var(--space-4);
}

pre code {
  background: none;
  padding: 0;
  border: none;
}


/* ═══════════════════════════════════════════════════════════
   LAYOUT UTILITIES
   ══════════════════════════════════════════════════════════ */

.container {
  width: 100%;
  max-width: var(--container-lg);
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--space-6);
  padding-right: var(--space-6);
  padding-top: var(--space-8);
  padding-bottom: var(--space-8);
}

@media (max-width: 768px) {
  .container {
    padding-left: var(--space-4);
    padding-right: var(--space-4);
    padding-top: var(--space-6);
    padding-bottom: var(--space-6);
  }
}

/* Skip Link for Accessibility */
.skip-link {
  position: absolute;
  top: -100px;
  left: var(--space-4);
  background: var(--interactive-primary);
  color: var(--text-inverse);
  padding: var(--space-3) var(--space-4);
  text-decoration: none;
  border-radius: var(--radius-md);
  font-weight: var(--font-semibold);
  z-index: calc(var(--z-modal) + 10);
}

.skip-link:focus {
  top: var(--space-4);
}


/* ═══════════════════════════════════════════════════════════
   FORM ELEMENTS BASE
   ══════════════════════════════════════════════════════════ */

input, select, textarea {
  background: var(--bg-tertiary);
  border: var(--border-width-thin) solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  padding: var(--input-padding-y) var(--input-padding-x);
  font-size: var(--text-base);
  transition: var(--transition-colors);
  width: 100%;
  min-height: var(--input-height-md);
}

input:hover, select:hover, textarea:hover {
  border-color: var(--border-default);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: var(--shadow-focus);
}

input:disabled, select:disabled, textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

input[aria-invalid="true"], 
select[aria-invalid="true"], 
textarea[aria-invalid="true"] {
  border-color: var(--status-error);
}

input[aria-invalid="true"]:focus,
select[aria-invalid="true"]:focus,
textarea[aria-invalid="true"]:focus {
  box-shadow: var(--shadow-focus-error);
}

/* Better styling for select dropdowns */
select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%23a8a2c0' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right var(--space-3) center;
  background-repeat: no-repeat;
  background-size: 1.5em 1.5em;
  padding-right: var(--space-10);
}

select option {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* label selector defined in components/forms.css */


/* ═══════════════════════════════════════════════════════════
   LISTS
   ══════════════════════════════════════════════════════════ */

ul, ol {
  list-style-position: inside;
  margin-bottom: var(--space-4);
}

ul ul, ol ol, ul ol, ol ul {
  margin-left: var(--space-6);
  margin-bottom: var(--space-2);
}


/* ═══════════════════════════════════════════════════════════
   TABLES
   ══════════════════════════════════════════════════════════ */

table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: var(--space-6);
}

th {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-weight: var(--font-semibold);
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border-bottom: var(--border-width-medium) solid var(--border-emphasis);
}

td {
  padding: var(--space-3) var(--space-4);
  border-bottom: var(--border-width-thin) solid var(--border-subtle);
}

tr:hover td {
  background: var(--bg-tertiary);
}


/* ═══════════════════════════════════════════════════════════
   ANIMATIONS
   ══════════════════════════════════════════════════════════ */

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slide-up {
  from {
    transform: translateY(1rem);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@keyframes scale-in {
  from {
    transform: scale(0.95);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

/* Reduced motion for accessibility */
@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;
  }
}


/* ═══════════════════════════════════════════════════════════
   PRINT STYLES
   ══════════════════════════════════════════════════════════ */

@media print {
  *,
  *::before,
  *::after {
    background: white !important;
    color: black !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }

  a,
  a:visited {
    text-decoration: underline;
  }

  a[href]::after {
    content: " (" attr(href) ")";
  }

  pre {
    white-space: pre-wrap !important;
  }

  pre,
  blockquote {
    border: 1px solid #999;
    page-break-inside: avoid;
  }

  thead {
    display: table-header-group;
  }

  tr,
  img {
    page-break-inside: avoid;
  }

  p,
  h2,
  h3 {
    orphans: 3;
    widows: 3;
  }

  h2,
  h3 {
    page-break-after: avoid;
  }
}
