/* ================================
   Daylete Design System - Base Styles
   Modern CSS Reset + Typography + Utilities
   ================================ */

/* ================================
   Modern CSS Reset
   Based on Josh Comeau's CSS Reset
   ================================ */
*, *::before, *::after {
  box-sizing: border-box;
}

* {
  margin: 0;
}

html {
  /* Prevent iOS font size adjust after orientation change */
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
  /* Enable smooth scrolling */
  scroll-behavior: smooth;
  /* Ensure background color covers entire viewport */
  background-color: var(--bg-0);
  /* Prevent horizontal overflow */
  overflow-x: hidden;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}

body {
  line-height: var(--line-height-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Improve text rendering */
  text-rendering: optimizeSpeed;
  /* Prevent horizontal overflow on mobile */
  overflow-x: hidden;
  /* Ensure full viewport width */
  width: 100%;
  min-height: 100vh;
}

img, picture, video, canvas, svg {
  display: block;
  max-width: 100%;
}

input, button, textarea, select {
  font: inherit;
}

p, h1, h2, h3, h4, h5, h6 {
  overflow-wrap: break-word;
}

/* ================================
   Typography System
   ================================ */
body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-normal);
  line-height: var(--line-height-base);
  color: var(--text-1);
  background-color: var(--bg-0);
  transition: color var(--transition-base), background-color var(--transition-base);
}

/* Headings */
h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-weight-semibold);
  line-height: var(--line-height-tight);
  color: var(--text-1);
  margin-bottom: var(--gap-3);
}

h1 {
  font-size: var(--font-size-5xl);
  font-weight: var(--font-weight-bold);
  letter-spacing: -0.025em;
}

h2 {
  font-size: var(--font-size-4xl);
  letter-spacing: -0.025em;
}

h3 {
  font-size: var(--font-size-3xl);
  letter-spacing: -0.025em;
}

h4 {
  font-size: var(--font-size-2xl);
}

h5 {
  font-size: var(--font-size-xl);
}

h6 {
  font-size: var(--font-size-lg);
}

/* Body text */
p {
  margin-bottom: var(--gap-3);
  color: var(--text-2);
  line-height: var(--line-height-relaxed);
}

/* Links */
a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--primary-boost);
  text-decoration: underline;
}

a:focus {
  outline: 2px solid var(--primary-boost);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/* Lists */
ul, ol {
  margin-bottom: var(--gap-3);
  padding-left: var(--gap-4);
}

li {
  margin-bottom: var(--gap-1);
  color: var(--text-2);
}

/* Code */
code, pre {
  font-family: 'SF Mono', 'Monaco', 'Inconsolata', 'Roboto Mono', 'Consolas', monospace;
  font-size: 0.9em;
}

code {
  background-color: var(--bg-2);
  color: var(--text-1);
  padding: 0.125em 0.25em;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-1);
}

pre {
  background-color: var(--bg-2);
  color: var(--text-1);
  padding: var(--gap-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-1);
  overflow-x: auto;
  margin-bottom: var(--gap-3);
}

/* ================================
   Focus Management
   ================================ */
.focus-ring {
  outline: 2px solid var(--primary-boost);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/* Remove default focus styles and add consistent ones */
*:focus {
  outline: none;
}

*:focus-visible {
  outline: 2px solid var(--primary-boost);
  outline-offset: 2px;
  border-radius: var(--radius-xs);
}

/* High contrast focus for better accessibility */
@media (prefers-contrast: high) {
  *:focus-visible {
    outline: 3px solid currentColor;
    outline-offset: 2px;
  }
}

/* ================================
   Layout Utilities
   ================================ */

/* Stack - Vertical spacing utility */
.stack > * + * {
  margin-top: var(--gap-3);
}

.stack-sm > * + * {
  margin-top: var(--gap-2);
}

.stack-lg > * + * {
  margin-top: var(--gap-4);
}

/* Cluster - Horizontal spacing utility */
.cluster {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap-3);
  align-items: center;
}

.cluster-sm {
  gap: var(--gap-2);
}

.cluster-lg {
  gap: var(--gap-4);
}

/* Center content with max width */
.content-wrapper {
  max-width: 1280px;
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--gap-4);
  padding-right: var(--gap-4);
  width: 100%;
}

@media (min-width: 768px) {
  .content-wrapper {
    padding-left: var(--gap-6);
    padding-right: var(--gap-6);
  }
}

/* Prevent Bootstrap row overflow on mobile */
.row {
  margin-left: 0;
  margin-right: 0;
}

.row > * {
  padding-left: calc(var(--bs-gutter-x) * 0.5);
  padding-right: calc(var(--bs-gutter-x) * 0.5);
}

/* Ensure all content respects viewport width */
* {
  max-width: 100%;
}

/* But allow specific elements to use full width */
html,
body,
.page,
.main-content,
.content-wrapper,
.container,
.container-fluid,
.row {
  max-width: none;
}

/* ================================
   Accessibility Utilities
   ================================ */

/* Screen reader only text */
.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;
}

/* Skip to main content link */
.skip-link {
  position: absolute;
  top: -40px;
  left: var(--gap-3);
  background: var(--bg-2);
  color: var(--text-1);
  padding: var(--gap-2) var(--gap-3);
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-weight: var(--font-weight-medium);
  z-index: var(--z-tooltip);
  transition: top var(--transition-fast);
  border: 1px solid var(--border-2);
}

.skip-link:focus {
  top: var(--gap-3);
}

/* ================================
   Form Elements Base Styles
   ================================ */

/* Remove default form element styling */
input, textarea, select, button {
  background: none;
  border: none;
  outline: none;
  font-family: inherit;
  font-size: inherit;
}

/* Input base styles */
input, textarea, select {
  background-color: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--radius-sm);
  padding: var(--gap-2) var(--gap-3);
  color: var(--text-1);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

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

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

/* Disabled state */
input:disabled, textarea:disabled, select:disabled {
  background-color: var(--bg-2);
  color: var(--text-3);
  cursor: not-allowed;
  opacity: 0.6;
}

/* ================================
   Interactive States
   ================================ */

/* Hover states for interactive elements */
button, [role="button"], .clickable {
  cursor: pointer;
  transition: all var(--transition-fast);
}

button:disabled, [role="button"][aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.6;
}

/* Selection styles */
::selection {
  background-color: var(--surface-selected);
  color: var(--text-1);
}

/* ================================
   Responsive Utilities
   ================================ */

/* Hide elements responsively */
@media (max-width: 767px) {
  .hide-mobile {
    display: none !important;
  }
}

@media (min-width: 768px) {
  .hide-desktop {
    display: none !important;
  }
}

/* ================================
   Print Styles
   ================================ */
@media print {
  * {
    background: transparent !important;
    color: black !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }
  
  a, a:visited {
    text-decoration: underline;
  }
  
  a[href]:after {
    content: " (" attr(href) ")";
  }
  
  .no-print {
    display: none !important;
  }
}

/* ================================
   Loading States
   ================================ */

/* Skeleton loading animation */
@keyframes skeleton-loading {
  0% {
    background-position: -200px 0;
  }
  100% {
    background-position: calc(200px + 100%) 0;
  }
}

.skeleton {
  background-color: var(--bg-2);
  background-image: linear-gradient(
    90deg,
    var(--bg-2),
    var(--bg-3),
    var(--bg-2)
  );
  background-size: 200px 100%;
  background-repeat: no-repeat;
  border-radius: var(--radius-sm);
  animation: skeleton-loading 1.2s ease-in-out infinite;
}

@media (prefers-reduced-motion: reduce) {
  .skeleton {
    animation: none;
  }
}
