/* Base Styles – Grunnmur med CSS layers */

@import "./design-tokens.css";

/* ========================================
   CSS Layers - Prevent specificity hell
   ======================================== */

@layer reset, base, components, utilities;

/* ========================================
   LAYER: Reset
   ======================================== */

@layer reset {
  /* Modern CSS reset */

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

  * {
    margin: 0;
  }

  html {
    -webkit-text-size-adjust: 100%;
    hanging-punctuation: first last;
  }

  body {
    min-height: 100vh;
    line-height: var(--line-height-base);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  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;
  }

  /* Remove default list styling for lists with class/role */
  ul[class], ol[class] {
    list-style: none;
    padding: 0;
  }
}

/* ========================================
   LAYER: Base
   ======================================== */

@layer base {
  /* Typography */

  body {
    font-family: var(--font-family-sans);
    font-size: var(--font-base);
    font-weight: 400;
    line-height: var(--line-height-base);
    color: var(--color-text);
    background: var(--color-bg);
  }

  h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-family-sans);
    line-height: var(--line-height-heading);
    font-weight: 600;
    color: var(--color-text);
  }

  /* Artikkelprosa får Plex Serif */
  article p,
  article li,
  article blockquote {
    font-family: var(--font-family-serif);
  }

  h1 {
    font-size: var(--font-h1);
    margin-top: 0;
    margin-bottom: var(--space-5);
  }

  h2 {
    font-size: var(--font-h2);
    margin-top: var(--space-6);
    margin-bottom: var(--space-4);
  }

  h3 {
    font-size: var(--font-h3);
    margin-top: var(--space-5);
    margin-bottom: var(--space-3);
  }

  /* Prose */

  p {
    margin-top: var(--space-3);
    margin-bottom: var(--space-3);
  }

  /* Lists */

  ul, ol {
    padding-left: var(--space-5);
    margin-top: var(--space-3);
    margin-bottom: var(--space-3);
  }

  li {
    margin-top: var(--space-2);
    margin-bottom: var(--space-2);
  }

  /* Links */

  a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 0.15em;
    text-decoration-thickness: 1px;
    transition: color var(--transition-fast);
  }

  a:hover {
    color: var(--color-accent);
    text-decoration: none;
  }

  a:focus-visible {
    outline: var(--focus-outline);
    outline-offset: var(--focus-outline-offset);
    border-radius: var(--radius-small);
  }

  /* Code */

  code {
    font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Monaco, monospace;
    font-size: 0.9em;
    background: var(--color-bg-elevated);
    padding: 0.125em 0.375em;
    border-radius: var(--radius-small);
    border: 1px solid var(--color-border-light);
  }

  pre {
    background: var(--color-bg-elevated);
    padding: var(--space-4);
    border-radius: var(--radius-medium);
    border: 1px solid var(--color-border);
    overflow-x: auto;
    margin: var(--space-4) 0;
  }

  pre code {
    background: none;
    padding: 0;
    border: none;
  }

  /* Horizontal rule */

  hr {
    border: none;
    border-top: 1px solid var(--color-border);
    margin: var(--space-6) 0;
  }

  /* Blockquote */

  blockquote {
    border-left: var(--border-width-thick) solid var(--color-accent);
    padding-left: var(--space-4);
    margin: var(--space-5) 0;
    color: var(--color-text-muted);
    font-style: italic;
  }
}

/* ========================================
   LAYER: Components
   ======================================== */

@layer components {
  /* Skip link for accessibility */

  .skip-link {
    position: absolute;
    top: calc(-1 * var(--space-8));
    left: var(--space-3);
    background: var(--color-accent);
    color: white;
    padding: var(--space-3) var(--space-4);
    text-decoration: none;
    font-weight: 600;
    border-radius: var(--radius-medium);
    z-index: var(--z-skip-link);
    transition: top var(--transition-fast);
  }

  .skip-link:focus {
    top: var(--space-3);
    outline: 3px solid white;
    outline-offset: 2px;
  }

  /* Layout wrapper */

  .layout-wrapper {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--layout-gap);
    max-width: var(--layout-max-width);
    margin: 0 auto;
    padding: var(--space-4);
  }

  @media (min-width: 60rem) {
    .layout-wrapper {
      grid-template-columns: 1fr var(--sidebar-width);
      padding: var(--space-6);
    }
  }

  /* Main content area */

  main {
    min-width: 0;  /* Allow grid item to shrink */
  }

  article {
    max-width: var(--content-width);
    padding: var(--space-5);
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-medium);
  }

  /* Sidebar */

  aside {
    font-size: var(--font-small);
  }

  @media (max-width: 59.99rem) {
    aside {
      order: 2;
      border-top: 1px solid var(--color-border);
      padding-top: var(--space-5);
      margin-top: var(--space-6);
    }
  }

  @media (min-width: 60rem) {
    aside {
      position: sticky;
      top: var(--space-5);
      align-self: start;
    }
  }

  /* Header */

  header {
    padding: var(--space-4);
    border-bottom: 1px solid var(--color-border);
  }

  /* Footer */

  footer {
    margin-top: var(--space-8);
    padding: var(--space-6) var(--space-4);
    border-top: 1px solid var(--color-border);
    color: var(--color-text-muted);
    font-size: var(--font-small);
  }

  /* Updated date display */

  .updated {
    margin-top: var(--space-6);
    padding-top: var(--space-5);
    border-top: 1px solid var(--color-border-light);
    font-size: var(--font-small);
    color: var(--color-text-muted);
  }
}

/* ========================================
   LAYER: Utilities
   ======================================== */

@layer utilities {
  .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
  }

  .visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
  }
}

/* ========================================
   Accessibility: Reduced Motion
   ======================================== */

@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;
  }
}

/* ========================================
   Focus-visible polyfill support
   ======================================== */

*:focus:not(:focus-visible) {
  outline: none;
}

*:focus-visible {
  outline: var(--focus-outline);
  outline-offset: var(--focus-outline-offset);
}
