@tailwind base;
@tailwind components;
@tailwind utilities;

/* Scandinavian Design System - Clean, minimal, natural tones */

@layer base {
  :root {
    /* Core Scandinavian palette */
    --background: 40 10% 94%;   /* Benvit #F2F1EF */
    --foreground: 204 7% 28%;   /* Kolgrå #43494d */

    /* Card system */
    --card: 0 0% 100%;
    --card-foreground: 204 7% 28%;

    /* Popover system */
    --popover: 0 0% 100%;
    --popover-foreground: 204 7% 28%;

    /* Primary - Deep Nordic blue-gray med förbättrad kontrast */
    --primary: 204 7% 28%;      /* Kolgrå #43494d */
    --primary-foreground: 40 10% 94%;
    --primary-hover: 204 8% 22%;

    /* Secondary - Warm stone gray med bättre kontrast */
    --secondary: 40 10% 91%;
    --secondary-foreground: 204 7% 24%;
    --secondary-hover: 40 10% 87%;

    /* Muted tones - Enhanced contrast för accessibility */
    --muted: 40 8% 90%;
    --muted-foreground: 204 8% 34%;

    /* Accent - Sage green med betydligt förbättrad kontrast för mobil läsbarhet */
    --accent: 150 25% 30%;      /* Skogsgrön */
    --accent-foreground: 40 10% 94%;
    --accent-hover: 150 27% 25%;
    --accent-soft: 150 24% 66%;  /* Ljus skogsgrön för mörka ytor */
    --accent-soft-foreground: 150 30% 14%;

    /* Natural warm accent */
    --warm-accent: 40 12% 88%;
    --warm-accent-foreground: 204 8% 26%;

    /* Destructive */
    --destructive: 0 65% 58%;
    --destructive-foreground: 0 0% 98%;

    /* Borders and inputs - Subtle Nordic */
    --border: 40 8% 87%;
    --input: 40 8% 87%;
    --ring: 204 7% 28%;

    --radius: 0.5rem;

    /* Kameral brand fonts — Spectral (display/serif) + Inter (UI/body) */
    --font-display: Spectral, Georgia, "Times New Roman", serif;
    --font-serif: Spectral, Georgia, "Times New Roman", serif;
    --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;

    /* Sektionsrytm — tre nivåer whitespace */
    --section-tight: 3rem;
    --section-tight-lg: 4rem;
    --section-normal: 4rem;
    --section-normal-lg: 6rem;
    --section-generous: 5rem;
    --section-generous-lg: 8rem;

    /* Linjesystem — hårlinje, avdelare, stark avdelare */
    --hairline: hsl(var(--border) / 0.7);
    --rule: hsl(var(--border));
    --rule-strong: hsl(var(--foreground) / 0.18);
    --rule-inverse: hsl(var(--primary-foreground) / 0.18);


    /* Scandinavian gradients */
    --gradient-hero: linear-gradient(135deg, hsl(var(--background)), hsl(var(--accent)));
    --gradient-card: linear-gradient(180deg, hsl(var(--card)), hsl(var(--secondary)));

    /* Shadows with Nordic feel */
    --shadow-soft: 0 4px 20px -4px hsl(var(--primary) / 0.1);
    --shadow-elegant: 0 10px 40px -10px hsl(var(--primary) / 0.15);
    --shadow-dock: 0 20px 50px -12px rgba(67, 73, 77, 0.35);

    /* Transitions */
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    --sidebar-background: 0 0% 98%;

    --sidebar-foreground: 240 5.3% 26.1%;

    --sidebar-primary: 240 5.9% 10%;

    --sidebar-primary-foreground: 0 0% 98%;

    --sidebar-accent: 240 4.8% 95.9%;

    --sidebar-accent-foreground: 240 5.9% 10%;

    --sidebar-border: 220 13% 91%;

    --sidebar-ring: 217.2 91.2% 59.8%;
  }

  .dark {
    --background: 215 25% 12%;
    --foreground: 0 0% 98%;

    --card: 215 25% 15%;
    --card-foreground: 0 0% 98%;

    --popover: 215 25% 15%;
    --popover-foreground: 0 0% 98%;

    --primary: 0 0% 98%;
    --primary-foreground: 215 25% 12%;
    --primary-hover: 0 0% 90%;

    --secondary: 215 20% 20%;
    --secondary-foreground: 0 0% 98%;
    --secondary-hover: 215 20% 25%;

    --muted: 215 20% 18%;
    --muted-foreground: 220 8% 65%;

    --accent: 150 25% 34%;
    --accent-foreground: 40 10% 94%;
    --accent-hover: 150 27% 40%;
    --accent-soft: 150 24% 66%;
    --accent-soft-foreground: 150 30% 14%;

    --warm-accent: 35 15% 25%;
    --warm-accent-foreground: 35 15% 85%;

    --destructive: 0 65% 45%;
    --destructive-foreground: 0 0% 98%;

    --border: 215 20% 22%;
    --input: 215 20% 22%;
    --ring: 0 0% 98%;
    --sidebar-background: 240 5.9% 10%;
    --sidebar-foreground: 240 4.8% 95.9%;
    --sidebar-primary: 224.3 76.3% 48%;
    --sidebar-primary-foreground: 0 0% 100%;
    --sidebar-accent: 240 3.7% 15.9%;
    --sidebar-accent-foreground: 240 4.8% 95.9%;
    --sidebar-border: 240 3.7% 15.9%;
    --sidebar-ring: 217.2 91.2% 59.8%;
  }
}

@layer base {
  * {
    @apply border-border;
  }

  body {
    @apply bg-background text-foreground;
  }
  
  html {
    scroll-behavior: smooth;
    /* Performance optimizations */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
  }

  /* Critical performance optimizations */
  * {
    box-sizing: border-box;
  }

  /* Spectral är en serif satt bredare än en geometrisk sans. Den tål inte
     ihopdragen tracking och behöver mer luft mellan raderna.
     400 i de största graderna, 500 i mellanstora. 600 endast som accent. */
  h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-display);
    font-weight: 400;
    font-display: swap;
  }

  /* Responsiva basstorlekar - kaskadbara, kan skrivas över av Tailwind-utilities */
  h1 {
    font-size: clamp(2.5rem, 1.6rem + 4vw, 4.25rem);
    line-height: 1.14;
    letter-spacing: -0.01em;
  }

  h2 {
    font-size: clamp(1.85rem, 1.4rem + 2vw, 2.6rem);
    line-height: 1.16;
    letter-spacing: -0.005em;
    font-weight: 500;
  }

  h3 {
    font-size: clamp(1.375rem, 1.2rem + 0.85vw, 1.75rem);
    line-height: 1.25;
    letter-spacing: 0;
    font-weight: 500;
  }

  h4 {
    font-size: 1.25rem;
    line-height: 1.35;
    letter-spacing: 0;
    font-weight: 500;
  }

  h5 {
    font-size: 1.0625rem;
    line-height: 1.5;
    letter-spacing: 0;
    font-weight: 500;
  }

  h6 {
    font-size: 0.9375rem;
    line-height: 1.5;
    letter-spacing: 0;
    font-weight: 500;
  }


  /* Optimize image loading */
  img {
    height: auto;
    max-width: 100%;
  }

  /* Reduce layout shift for lazy-loaded content */
  .lazy-placeholder {
    background: linear-gradient(90deg, hsl(var(--muted)) 25%, transparent 50%, hsl(var(--muted)) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
  }

  @keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
  }
}

@layer components {
  /* Kameral brand: uppercase eyebrows/labels — ALLTID Inter.
     Spärrad versal serif ser fel ut och hör inte hemma i uttrycket. */
  .eyebrow {
    font-family: var(--font-sans);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.18em;
  }

  /* Stora sifferelement (nyckeltal, priser, statistik) är Spectral enligt
     designspråket. Använd .stat-figure i stället för att sätta font-display
     och tabular-nums ad hoc. Aldrig på tabelldata eller etiketter. */
  .stat-figure {
    font-family: var(--font-display);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
  }

  /* ── Tvåkolumnsregel (editorial) ─────────────────────────────
     Vänsterkolumn: eyebrow + rubrik. Högerkolumn: brödtext.
     .editorial-col-lead placerar högerkolumnens första textrad optiskt
     i linje med rubrikens första rad: eyebrow-höjd + mellanrum, minus
     skillnaden i half-leading mellan Spectral-rubrik och Inter-brödtext.
     Optisk trim på första barnet kompenserar radhöjdsskillnaden.
     .editorial-col-align gör samma sak utan trim, för högerkolumner som
     inleds med en linje (listor, accordions) där linjen ska ligga still. */
  .editorial-col-lead > :first-child {
    margin-top: -0.16em;
  }

  @media (min-width: 1024px) {
    .editorial-col-lead,
    .editorial-col-align {
      padding-top: 2.65rem;
    }
  }

  /* Vänsterkolumnen får vara medvetet kort. Terminatorlinjen markerar
     att tomrummet är komposition, inte en oavsiktlig höjdskillnad. */
  .editorial-col-terminator {
    display: none;
    width: 3.5rem;
    height: 1px;
    margin-top: 2.5rem;
    background-color: hsl(var(--primary) / 0.25);
  }

  @media (min-width: 1024px) {
    .editorial-col-terminator {
      display: block;
    }
  }



  /* ── Sektionsrytm ───────────────────────────────────────────
     Tre nivåer whitespace. Använd dessa i stället för ad hoc py-*. */
  .section-tight {
    padding-top: var(--section-tight);
    padding-bottom: var(--section-tight);
  }

  .section-normal {
    padding-top: var(--section-normal);
    padding-bottom: var(--section-normal);
  }

  .section-generous {
    padding-top: var(--section-generous);
    padding-bottom: var(--section-generous);
  }

  @media (min-width: 1024px) {
    .section-tight {
      padding-top: var(--section-tight-lg);
      padding-bottom: var(--section-tight-lg);
    }

    .section-normal {
      padding-top: var(--section-normal-lg);
      padding-bottom: var(--section-normal-lg);
    }

    .section-generous {
      padding-top: var(--section-generous-lg);
      padding-bottom: var(--section-generous-lg);
    }
  }

  /* ── Linjesystem ────────────────────────────────────────────
     Hårfina linjer är Kamerals signatur. Formaliserat som tokens. */
  .rule-hairline {
    border-top: 1px solid var(--hairline);
  }

  .rule-divider {
    border-top: 1px solid var(--rule);
  }

  .rule-strong {
    border-top: 1px solid var(--rule-strong);
  }

  .rule-inverse {
    border-top: 1px solid var(--rule-inverse);
  }

  /* Numrerad/ledger-rad: hårlinje mellan rader, ingen linje överst */
  .rule-stack > * + * {
    border-top: 1px solid var(--hairline);
  }

  /* ── Container ──────────────────────────────────────────────── */
  .container-padding {
    @apply px-4 sm:px-6;
  }

  .container-padding-lg {
    @apply px-4 sm:px-6 lg:px-8;
  }

  .container-responsive {
    @apply container mx-auto px-4 sm:px-6 lg:px-8;
  }

  /* ── Touch/mobil (löser faktiska problem) ────────────────────── */
  .btn-touch {
    @apply min-h-[44px] min-w-[44px] touch-manipulation;
  }

  .mobile-nav-link {
    @apply block py-3 px-4 text-base font-medium touch-manipulation min-h-[44px];
  }
}


@layer utilities {
  /* Touch-friendly utilities */
  .touch-target {
    @apply min-h-[44px] min-w-[44px];
  }
  
  /* Safe area handling for mobile devices */
  .safe-top {
    padding-top: env(safe-area-inset-top);
  }
  
  .safe-bottom {
    padding-bottom: env(safe-area-inset-bottom);
  }
  
  /* Mobile viewport handling */
  .min-h-screen-mobile {
    min-height: 100vh;
    min-height: 100dvh;
  }
  
  /* Text handling utilities */
  .text-responsive {
    @apply text-xs sm:text-sm lg:text-base;
  }
  
  .text-button-responsive {
    @apply text-xs sm:text-sm leading-tight;
  }
  
  /* Prevent text overflow in buttons */
  .btn-text-safe {
    overflow-wrap: break-word;
    word-wrap: break-word;
    hyphens: auto;
    max-width: 100%;
  }
  
  /* Enhanced touch targets for all interactive elements */
  .touch-enhanced {
    @apply min-h-[44px] min-w-[44px] touch-manipulation;
    -webkit-tap-highlight-color: transparent;
  }
  
  /* Responsive button padding based on screen size */
  .btn-padding-responsive {
    @apply px-2 py-2 sm:px-4 sm:py-3 lg:px-6 lg:py-3;
  }
  
  /* Mobile Sticky CTA scale animation (slide-up defined in tailwind.config.ts to preserve X-centering) */
  @keyframes scale-in {
    from {
      transform: scale(0.95);
      opacity: 0;
    }
    to {
      transform: scale(1);
      opacity: 1;
    }
  }

  .animate-scale-in {
    animation: scale-in 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  }
}

/* UI Health Monitor optimizations */
.ui-health-monitor {
  min-height: 100vh;
}

.ui-optimized {
  transition: opacity 0.3s ease-in-out;
  opacity: 1;
}

@layer components {
  .article-prose {
    color: hsl(var(--foreground) / 0.88);
  }

  .article-prose > p,
  .article-prose > ul,
  .article-prose > ol {
    max-width: 68ch;
  }

  .article-prose p {
    font-size: 1.0625rem;
    line-height: 1.75;
  }

  .article-prose h2 {
    font-family: var(--font-display);
    letter-spacing: -0.015em;
    margin-top: 3.5rem;
    padding-top: 1.75rem;
    border-top: 1px solid hsl(var(--border));
  }

  .article-prose h3 {
    font-family: var(--font-display);
    letter-spacing: -0.01em;
    margin-top: 2.25rem;
  }

  .article-prose h2:first-child,
  .article-prose h3:first-child {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
  }

  .article-prose ul li,
  .article-prose ol li {
    line-height: 1.7;
  }

  .article-prose a:not([class*="bg-"]) {
    color: hsl(var(--accent));
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-thickness: 1px;
  }

  .article-prose table {
    font-size: 0.9375rem;
  }

  .article-prose table th {
    text-align: left;
    font-weight: 600;
  }

  .article-prose input[type="checkbox"] {
    accent-color: hsl(var(--accent));
  }
}
