/**
 * Responsive Typography
 * Text scaling, line heights, and readability across breakpoints
 * 
 * Requirements: 10.1, 10.2, 10.3, 10.5
 * - 10.1: Base font size of 16px on mobile devices
 * - 10.2: Scale headings proportionally across breakpoints
 * - 10.3: Maintain line heights between 1.5 and 1.8 for readability
 * - 10.5: Prevent text overflow with appropriate wrapping
 */

/* ============================================
   CSS Variables for Typography Scale
   ============================================ */

:root {
    /* Mobile base (320px - 639px) */
    --font-size-xs: 0.75rem;    /* 12px */
    --font-size-sm: 0.875rem;   /* 14px */
    --font-size-base: 1rem;     /* 16px - Requirement 10.1 */
    --font-size-lg: 1.125rem;   /* 18px */
    --font-size-xl: 1.25rem;    /* 20px */
    --font-size-2xl: 1.5rem;    /* 24px */
    --font-size-3xl: 1.875rem;  /* 30px */
    
    /* Line heights - Requirement 10.3 */
    --line-height-tight: 1.25;
    --line-height-normal: 1.5;
    --line-height-relaxed: 1.6;
    --line-height-loose: 1.8;
}

/* Tablet: Slight increase (640px+) */
@media (min-width: 640px) {
    :root {
        --font-size-2xl: 1.75rem;   /* 28px */
        --font-size-3xl: 2.25rem;   /* 36px */
    }
}

/* Desktop: Full scale (1024px+) */
@media (min-width: 1024px) {
    :root {
        --font-size-2xl: 2rem;      /* 32px */
        --font-size-3xl: 2.5rem;    /* 40px */
    }
}

/* ============================================
   Base Typography (Mobile-first)
   ============================================ */

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: var(--font-size-base); /* 16px base - Requirement 10.1 */
    line-height: var(--line-height-relaxed); /* 1.6 - Requirement 10.3 */
    color: var(--gray-900, #111827);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   Headings Scale - Requirement 10.2
   Proportional scaling across breakpoints
   ============================================ */

/* Mobile (320px - 639px) */
h1, .h1 {
    font-size: var(--font-size-3xl); /* 30px mobile, scales up at breakpoints */
    line-height: var(--line-height-tight); /* 1.25 */
    font-weight: 700;
    margin-top: 0;
    margin-bottom: 1rem;
}

h2, .h2 {
    font-size: var(--font-size-2xl); /* 24px mobile, scales up at breakpoints */
    line-height: 1.3;
    font-weight: 600;
    margin-top: 0;
    margin-bottom: 0.875rem;
}

h3, .h3 {
    font-size: var(--font-size-xl); /* 20px */
    line-height: 1.4;
    font-weight: 600;
    margin-top: 0;
    margin-bottom: 0.75rem;
}

h4, .h4 {
    font-size: var(--font-size-lg); /* 18px */
    line-height: var(--line-height-normal); /* 1.5 */
    font-weight: 600;
    margin-top: 0;
    margin-bottom: 0.625rem;
}

h5, .h5 {
    font-size: var(--font-size-base); /* 16px */
    line-height: var(--line-height-normal); /* 1.5 */
    font-weight: 600;
    margin-top: 0;
    margin-bottom: 0.5rem;
}

h6, .h6 {
    font-size: var(--font-size-sm); /* 14px */
    line-height: var(--line-height-normal); /* 1.5 */
    font-weight: 600;
    margin-top: 0;
    margin-bottom: 0.5rem;
}

/* Tablet (640px+) - Headings scale automatically via CSS variables */
@media (min-width: 640px) {
    /* h1 becomes 36px, h2 becomes 28px via CSS variable updates */
}

/* Tablet Large (768px+) */
@media (min-width: 768px) {
    h3, .h3 {
        font-size: 1.375rem; /* 22px - slight increase */
    }
}

/* Desktop (1024px+) - Headings scale automatically via CSS variables */
@media (min-width: 1024px) {
    /* h1 becomes 40px, h2 becomes 32px via CSS variable updates */
    h3, .h3 {
        font-size: var(--font-size-2xl); /* 24px at desktop */
    }
    
    h4, .h4 {
        font-size: 1.25rem; /* 20px at desktop */
    }
}

/* ============================================
   Body Text - Requirement 10.3
   Line heights between 1.5 and 1.8 for readability
   ============================================ */

p {
    margin-top: 0;
    margin-bottom: 1rem;
    line-height: var(--line-height-relaxed); /* 1.6 - within 1.5-1.8 range */
}

.lead {
    font-size: var(--font-size-lg); /* 18px */
    line-height: var(--line-height-loose); /* 1.8 */
    font-weight: 300;
}

@media (min-width: 768px) {
    .lead {
        font-size: var(--font-size-xl); /* 20px */
        line-height: var(--line-height-loose); /* 1.8 */
    }
}

/* ============================================
   Text Sizes - Using CSS Variables
   ============================================ */

.text-xs {
    font-size: var(--font-size-xs); /* 12px */
    line-height: var(--line-height-normal); /* 1.5 */
}

.text-sm {
    font-size: var(--font-size-sm); /* 14px */
    line-height: var(--line-height-normal); /* 1.5 */
}

.text-base {
    font-size: var(--font-size-base); /* 16px */
    line-height: var(--line-height-relaxed); /* 1.6 */
}

.text-lg {
    font-size: var(--font-size-lg); /* 18px */
    line-height: var(--line-height-relaxed); /* 1.6 */
}

.text-xl {
    font-size: var(--font-size-xl); /* 20px */
    line-height: var(--line-height-relaxed); /* 1.6 */
}

.text-2xl {
    font-size: var(--font-size-2xl); /* 24px mobile, scales up */
    line-height: var(--line-height-normal); /* 1.5 */
}

.text-3xl {
    font-size: var(--font-size-3xl); /* 30px mobile, scales up */
    line-height: 1.4;
}

/* ============================================
   Text Weights
   ============================================ */

.font-light {
    font-weight: 300;
}

.font-normal {
    font-weight: 400;
}

.font-medium {
    font-weight: 500;
}

.font-semibold {
    font-weight: 600;
}

.font-bold {
    font-weight: 700;
}

/* ============================================
   Text Alignment
   ============================================ */

.text-left {
    text-align: left;
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.text-justify {
    text-align: justify;
}

/* Responsive text alignment */
@media (max-width: 767px) {
    .text-center-mobile {
        text-align: center;
    }
    
    .text-left-mobile {
        text-align: left;
    }
}

@media (min-width: 768px) {
    .text-center-tablet {
        text-align: center;
    }
    
    .text-left-tablet {
        text-align: left;
    }
    
    .text-right-tablet {
        text-align: right;
    }
}

@media (min-width: 1024px) {
    .text-center-desktop {
        text-align: center;
    }
    
    .text-left-desktop {
        text-align: left;
    }
    
    .text-right-desktop {
        text-align: right;
    }
}

/* ============================================
   Text Colors
   ============================================ */

.text-primary {
    color: var(--primary-color, #6366f1);
}

.text-secondary {
    color: var(--gray-600, #4b5563);
}

.text-success {
    color: var(--green-600, #16a34a);
}

.text-danger {
    color: var(--red-600, #dc2626);
}

.text-warning {
    color: var(--yellow-600, #d97706);
}

.text-info {
    color: var(--blue-600, #2563eb);
}

.text-muted {
    color: var(--gray-500, #6b7280);
}

/* ============================================
   Text Overflow Handling - Requirement 10.5
   Prevent text overflow with appropriate wrapping
   ============================================ */

/* Truncate with ellipsis */
.text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Break long words and wrap text - Primary overflow prevention */
.text-break {
    word-wrap: break-word;      /* Legacy support */
    overflow-wrap: break-word;  /* Modern standard */
    word-break: break-word;     /* Break long words */
    hyphens: auto;              /* Add hyphens where appropriate */
}

/* Prevent wrapping */
.text-nowrap {
    white-space: nowrap;
}

/* Ensure all text containers prevent overflow by default */
p, div, span, td, th, li {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* ============================================
   Line Clamping
   ============================================ */

.line-clamp-1 {
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    line-clamp: 1;
    overflow: hidden;
}

.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    line-clamp: 2;
    overflow: hidden;
}

.line-clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    line-clamp: 3;
    overflow: hidden;
}

/* ============================================
   Lists
   ============================================ */

ul, ol {
    margin-top: 0;
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

ul ul,
ol ul,
ul ol,
ol ol {
    margin-bottom: 0;
}

.list-unstyled {
    padding-left: 0;
    list-style: none;
}

.list-inline {
    padding-left: 0;
    list-style: none;
}

.list-inline-item {
    display: inline-block;
    margin-right: 0.5rem;
}

/* ============================================
   Links
   ============================================ */

a {
    color: var(--primary-color, #6366f1);
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover {
    color: var(--primary-dark, #4f46e5);
    text-decoration: underline;
}

a:focus-visible {
    outline: 2px solid var(--primary-color, #6366f1);
    outline-offset: 2px;
}

/* ============================================
   Code and Pre
   ============================================ */

code {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.875em;
    padding: 0.125rem 0.25rem;
    background: var(--gray-100, #f3f4f6);
    border-radius: 3px;
    color: var(--red-600, #dc2626);
}

pre {
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.875rem;
    padding: 1rem;
    background: var(--gray-100, #f3f4f6);
    border-radius: 6px;
    overflow-x: auto;
    margin-bottom: 1rem;
}

pre code {
    padding: 0;
    background: transparent;
    color: inherit;
}

/* ============================================
   Blockquotes
   ============================================ */

blockquote {
    margin: 0 0 1rem;
    padding: 0.5rem 1rem;
    border-left: 4px solid var(--gray-300, #d1d5db);
    color: var(--gray-600, #4b5563);
    font-style: italic;
}

@media (min-width: 768px) {
    blockquote {
        padding: 1rem 1.5rem;
    }
}

/* ============================================
   Small Text
   ============================================ */

small, .small {
    font-size: 0.875em;
}

/* ============================================
   Mark/Highlight
   ============================================ */

mark, .mark {
    padding: 0.125rem 0.25rem;
    background-color: var(--yellow-200, #fef08a);
    color: var(--gray-900, #111827);
}

/* ============================================
   Abbreviations
   ============================================ */

abbr[title] {
    text-decoration: underline dotted;
    cursor: help;
    border-bottom: 0;
}

/* ============================================
   Accessibility - Screen Reader Only
   ============================================ */

.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;
}

.sr-only-focusable:focus {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* ============================================
   Text Transform
   ============================================ */

.text-lowercase {
    text-transform: lowercase;
}

.text-uppercase {
    text-transform: uppercase;
}

.text-capitalize {
    text-transform: capitalize;
}
