/**
 * URLement Design System - Utility Classes
 * 
 * Common utility classes built on design tokens for rapid UI development.
 * Use these classes for consistent styling across the application.
 * 
 * Usage: <div class="card text-primary spacing-lg">...</div>
 */

/* ============================================
   SPACING UTILITIES
   ============================================ */

/* Padding */
.p-xs { padding: var(--spacing-xs); }
.p-sm { padding: var(--spacing-sm); }
.p-md { padding: var(--spacing-md); }
.p-base { padding: var(--spacing-base); }
.p-lg { padding: var(--spacing-lg); }
.p-xl { padding: var(--spacing-xl); }
.p-2xl { padding: var(--spacing-2xl); }
.p-3xl { padding: var(--spacing-3xl); }

/* Padding X (horizontal) */
.px-xs { padding-left: var(--spacing-xs); padding-right: var(--spacing-xs); }
.px-sm { padding-left: var(--spacing-sm); padding-right: var(--spacing-sm); }
.px-md { padding-left: var(--spacing-md); padding-right: var(--spacing-md); }
.px-base { padding-left: var(--spacing-base); padding-right: var(--spacing-base); }
.px-lg { padding-left: var(--spacing-lg); padding-right: var(--spacing-lg); }
.px-xl { padding-left: var(--spacing-xl); padding-right: var(--spacing-xl); }
.px-2xl { padding-left: var(--spacing-2xl); padding-right: var(--spacing-2xl); }

/* Padding Y (vertical) */
.py-xs { padding-top: var(--spacing-xs); padding-bottom: var(--spacing-xs); }
.py-sm { padding-top: var(--spacing-sm); padding-bottom: var(--spacing-sm); }
.py-md { padding-top: var(--spacing-md); padding-bottom: var(--spacing-md); }
.py-base { padding-top: var(--spacing-base); padding-bottom: var(--spacing-base); }
.py-lg { padding-top: var(--spacing-lg); padding-bottom: var(--spacing-lg); }
.py-xl { padding-top: var(--spacing-xl); padding-bottom: var(--spacing-xl); }
.py-2xl { padding-top: var(--spacing-2xl); padding-bottom: var(--spacing-2xl); }

/* Margin */
.m-xs { margin: var(--spacing-xs); }
.m-sm { margin: var(--spacing-sm); }
.m-md { margin: var(--spacing-md); }
.m-base { margin: var(--spacing-base); }
.m-lg { margin: var(--spacing-lg); }
.m-xl { margin: var(--spacing-xl); }
.m-2xl { margin: var(--spacing-2xl); }
.m-3xl { margin: var(--spacing-3xl); }

/* Margin X (horizontal) */
.mx-xs { margin-left: var(--spacing-xs); margin-right: var(--spacing-xs); }
.mx-sm { margin-left: var(--spacing-sm); margin-right: var(--spacing-sm); }
.mx-md { margin-left: var(--spacing-md); margin-right: var(--spacing-md); }
.mx-base { margin-left: var(--spacing-base); margin-right: var(--spacing-base); }
.mx-lg { margin-left: var(--spacing-lg); margin-right: var(--spacing-lg); }
.mx-xl { margin-left: var(--spacing-xl); margin-right: var(--spacing-xl); }
.mx-auto { margin-left: auto; margin-right: auto; }

/* Margin Y (vertical) */
.my-xs { margin-top: var(--spacing-xs); margin-bottom: var(--spacing-xs); }
.my-sm { margin-top: var(--spacing-sm); margin-bottom: var(--spacing-sm); }
.my-md { margin-top: var(--spacing-md); margin-bottom: var(--spacing-md); }
.my-base { margin-top: var(--spacing-base); margin-bottom: var(--spacing-base); }
.my-lg { margin-top: var(--spacing-lg); margin-bottom: var(--spacing-lg); }
.my-xl { margin-top: var(--spacing-xl); margin-bottom: var(--spacing-xl); }
.my-2xl { margin-top: var(--spacing-2xl); margin-bottom: var(--spacing-2xl); }

/* Gap */
.gap-xs { gap: var(--spacing-xs); }
.gap-sm { gap: var(--spacing-sm); }
.gap-md { gap: var(--spacing-md); }
.gap-base { gap: var(--spacing-base); }
.gap-lg { gap: var(--spacing-lg); }
.gap-xl { gap: var(--spacing-xl); }
.gap-2xl { gap: var(--spacing-2xl); }

/* ============================================
   TYPOGRAPHY UTILITIES
   ============================================ */

/* Font Sizes */
.text-xs { font-size: var(--font-size-xs); }
.text-sm { font-size: var(--font-size-sm); }
.text-base { font-size: var(--font-size-base); }
.text-md { font-size: var(--font-size-md); }
.text-lg { font-size: var(--font-size-lg); }
.text-xl { font-size: var(--font-size-xl); }
.text-2xl { font-size: var(--font-size-2xl); }
.text-3xl { font-size: var(--font-size-3xl); }

/* Font Weights */
.font-light { font-weight: var(--font-weight-light); }
.font-regular { font-weight: var(--font-weight-regular); }
.font-medium { font-weight: var(--font-weight-medium); }
.font-semibold { font-weight: var(--font-weight-semibold); }
.font-bold { font-weight: var(--font-weight-bold); }

/* Text Colors */
.text-primary { color: var(--color-text-primary); }
.text-secondary { color: var(--color-text-secondary); }
.text-tertiary { color: var(--color-text-tertiary); }
.text-muted { color: var(--color-text-muted); }
.text-success { color: var(--color-success); }
.text-warning { color: var(--color-warning); }
.text-error { color: var(--color-error); }
.text-white { color: white; }

/* Line Heights */
.leading-tight { line-height: var(--line-height-tight); }
.leading-normal { line-height: var(--line-height-normal); }
.leading-relaxed { line-height: var(--line-height-relaxed); }
.leading-loose { line-height: var(--line-height-loose); }

/* Letter Spacing */
.tracking-tight { letter-spacing: var(--letter-spacing-tight); }
.tracking-normal { letter-spacing: var(--letter-spacing-normal); }
.tracking-wide { letter-spacing: var(--letter-spacing-wide); }

/* Text Alignment */
.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }

/* ============================================
   COLOR UTILITIES
   ============================================ */

/* Background Colors */
.bg-white { background-color: var(--color-bg); }
.bg-secondary { background-color: var(--color-bg-secondary); }
.bg-tertiary { background-color: var(--color-bg-tertiary); }
.bg-muted { background-color: var(--color-bg-muted); }
.bg-primary { background-color: var(--color-primary); }
.bg-success { background-color: var(--color-success); }
.bg-warning { background-color: var(--color-warning); }
.bg-error { background-color: var(--color-error); }

/* Background Colors - Light Variants */
.bg-success-light { background-color: var(--color-success-light); }
.bg-warning-light { background-color: var(--color-warning-light); }
.bg-error-light { background-color: var(--color-error-light); }

/* Border Colors */
.border-color { border-color: var(--color-border); }
.border-color-alt { border-color: var(--color-border-alt); }

/* ============================================
   BORDER UTILITIES
   ============================================ */

/* Border Radius */
.rounded-sm { border-radius: var(--radius-sm); }
.rounded-md { border-radius: var(--radius-md); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-xl { border-radius: var(--radius-xl); }
.rounded-full { border-radius: var(--radius-full); }

/* Border Width */
.border { border-width: var(--border-width); }
.border-thick { border-width: var(--border-width-thick); }
.border-thicker { border-width: var(--border-width-thicker); }

/* Border Sides */
.border-t { border-top-width: var(--border-width); }
.border-r { border-right-width: var(--border-width); }
.border-b { border-bottom-width: var(--border-width); }
.border-l { border-left-width: var(--border-width); }

/* ============================================
   SHADOW UTILITIES
   ============================================ */

.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow-md { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: var(--shadow-lg); }
.shadow-xl { box-shadow: var(--shadow-xl); }
.shadow-primary { box-shadow: var(--shadow-primary); }
.shadow-success { box-shadow: var(--shadow-success); }
.shadow-warning { box-shadow: var(--shadow-warning); }
.shadow-error { box-shadow: var(--shadow-error); }

/* ============================================
   LAYOUT UTILITIES
   ============================================ */

/* Display */
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.grid { display: grid; }
.block { display: block; }
.inline-block { display: inline-block; }
.hidden { display: none; }

/* Flex Direction */
.flex-row { flex-direction: row; }
.flex-col { flex-direction: column; }

/* Flex Alignment */
.items-start { align-items: flex-start; }
.items-center { align-items: center; }
.items-end { align-items: flex-end; }
.justify-start { justify-content: flex-start; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }
.justify-between { justify-content: space-between; }
.justify-around { justify-content: space-around; }

/* Width */
.w-full { width: 100%; }
.w-auto { width: auto; }
.max-w-container { max-width: var(--container-max-width); }

/* ============================================
   COMPONENT UTILITIES
   ============================================ */

/* Card */
.card {
    background: var(--color-bg);
    border: var(--card-border);
    border-radius: var(--card-border-radius);
    padding: var(--card-padding);
    box-shadow: var(--card-shadow);
    transition: all var(--transition-base);
}

.card:hover {
    box-shadow: var(--card-shadow-hover);
}

/* Button Base */
.btn {
    padding: var(--button-padding-y) var(--button-padding-x);
    border-radius: var(--button-border-radius);
    font-size: var(--button-font-size);
    font-weight: var(--button-font-weight);
    border: none;
    cursor: pointer;
    transition: all var(--transition-base);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-sm);
    text-decoration: none;
}

.btn-primary {
    background: var(--color-primary);
    color: white;
}

.btn-primary:hover {
    background: var(--color-primary-hover);
}

.btn-secondary {
    background: var(--color-bg-tertiary);
    color: var(--color-text-primary);
    border: var(--border-width) solid var(--color-border);
}

.btn-secondary:hover {
    background: var(--color-bg-secondary);
    border-color: var(--color-border-alt);
}

/* Badge */
.badge {
    padding: var(--badge-padding-y) var(--badge-padding-x);
    border-radius: var(--badge-border-radius);
    font-size: var(--badge-font-size);
    font-weight: var(--badge-font-weight);
    letter-spacing: var(--badge-letter-spacing);
    display: inline-flex;
    align-items: center;
    text-transform: uppercase;
}

/* Input */
.input {
    padding: var(--input-padding-y) var(--input-padding-x);
    border: var(--input-border);
    border-radius: var(--input-border-radius);
    font-size: var(--input-font-size);
    font-family: var(--font-family);
    transition: all var(--transition-base);
    background: var(--color-bg);
    color: var(--color-text-primary);
}

.input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

/* ============================================
   TRANSITION UTILITIES
   ============================================ */

.transition { transition: all var(--transition-base); }
.transition-fast { transition: all var(--transition-fast); }
.transition-smooth { transition: all var(--transition-smooth); }
.transition-slow { transition: all var(--transition-slow); }

/* ============================================
   RESPONSIVE UTILITIES
   ============================================ */

/* Mobile First - Base styles apply to mobile */
/* Then override for larger screens */

/* ============================================
   MOBILE UTILITIES (≤640px)
   ============================================ */

@media (max-width: 640px) {
    /* Display */
    .mobile-hidden { display: none !important; }
    .mobile-block { display: block !important; }
    .mobile-flex { display: flex !important; }
    .mobile-inline-flex { display: inline-flex !important; }
    
    /* Layout */
    .mobile-full { width: 100% !important; }
    .mobile-w-auto { width: auto !important; }
    .mobile-flex-col { flex-direction: column !important; }
    .mobile-flex-row { flex-direction: row !important; }
    
    /* Spacing */
    .mobile-p-0 { padding: 0 !important; }
    .mobile-p-sm { padding: var(--spacing-mobile-sm) !important; }
    .mobile-p-base { padding: var(--spacing-mobile-base) !important; }
    .mobile-p-lg { padding: var(--spacing-mobile-lg) !important; }
    .mobile-px-base { padding-left: var(--spacing-mobile-base) !important; padding-right: var(--spacing-mobile-base) !important; }
    .mobile-px-lg { padding-left: var(--spacing-mobile-lg) !important; padding-right: var(--spacing-mobile-lg) !important; }
    .mobile-py-base { padding-top: var(--spacing-mobile-base) !important; padding-bottom: var(--spacing-mobile-base) !important; }
    .mobile-m-0 { margin: 0 !important; }
    .mobile-mb-base { margin-bottom: var(--spacing-mobile-base) !important; }
    .mobile-mb-lg { margin-bottom: var(--spacing-mobile-lg) !important; }
    .mobile-mt-base { margin-top: var(--spacing-mobile-base) !important; }
    
    /* Typography */
    .mobile-text-xs { font-size: var(--font-size-mobile-xs) !important; }
    .mobile-text-sm { font-size: var(--font-size-mobile-sm) !important; }
    .mobile-text-base { font-size: var(--font-size-mobile-base) !important; }
    .mobile-text-lg { font-size: var(--font-size-mobile-lg) !important; }
    .mobile-text-xl { font-size: var(--font-size-mobile-xl) !important; }
    .mobile-text-2xl { font-size: var(--font-size-mobile-2xl) !important; }
    .mobile-text-center { text-align: center !important; }
    .mobile-text-left { text-align: left !important; }
    .mobile-font-medium { font-weight: var(--font-weight-medium) !important; }
    .mobile-font-semibold { font-weight: var(--font-weight-semibold) !important; }
    
    /* Alignment */
    .mobile-items-start { align-items: flex-start !important; }
    .mobile-items-center { align-items: center !important; }
    .mobile-justify-center { justify-content: center !important; }
    .mobile-justify-between { justify-content: space-between !important; }
    
    /* Gap */
    .mobile-gap-sm { gap: var(--spacing-mobile-sm) !important; }
    .mobile-gap-base { gap: var(--spacing-mobile-base) !important; }
    .mobile-gap-lg { gap: var(--spacing-mobile-lg) !important; }
    
    /* Buttons - Full width on mobile */
    .mobile-btn-full { width: 100% !important; }
    .mobile-btn-block { display: block !important; width: 100% !important; }
    
    /* Grid - Single column on mobile */
    .mobile-grid-1 { grid-template-columns: 1fr !important; }
    
    /* Hide scrollbars on mobile if needed */
    .mobile-scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .mobile-scroll-y { overflow-y: auto; -webkit-overflow-scrolling: touch; }
    
    /* Touch targets - Ensure minimum size */
    .mobile-touch-target {
        min-height: var(--touch-target-min) !important;
        min-width: var(--touch-target-min) !important;
    }
}

/* ============================================
   TABLET UTILITIES (641px - 1024px)
   ============================================ */

@media (min-width: 641px) and (max-width: 1024px) {
    .tablet-hidden { display: none !important; }
    .tablet-block { display: block !important; }
    .tablet-flex { display: flex !important; }
    .tablet-grid-2 { grid-template-columns: repeat(2, 1fr) !important; }
    .tablet-w-50 { width: 50% !important; }
    .tablet-text-center { text-align: center !important; }
}

/* ============================================
   DESKTOP UTILITIES (≥1025px)
   ============================================ */

@media (min-width: 1025px) {
    .desktop-hidden { display: none !important; }
    .desktop-block { display: block !important; }
    .desktop-flex { display: flex !important; }
    .desktop-grid-3 { grid-template-columns: repeat(3, 1fr) !important; }
    .desktop-grid-4 { grid-template-columns: repeat(4, 1fr) !important; }
}

/* ============================================
   RESPONSIVE COMPONENT UTILITIES
   ============================================ */

/* Cards - Responsive padding */
@media (max-width: 640px) {
    .card {
        padding: var(--spacing-mobile-base) !important;
    }
}

/* Buttons - Responsive sizing */
@media (max-width: 640px) {
    .btn {
        min-height: var(--touch-target-min);
        padding: var(--spacing-mobile-base) var(--spacing-mobile-lg) !important;
    }
}

/* Containers - Responsive padding */
@media (max-width: 640px) {
    .container-responsive {
        padding: var(--container-padding-mobile) !important;
    }
}

@media (min-width: 641px) and (max-width: 1024px) {
    .container-responsive {
        padding: var(--container-padding-tablet) !important;
    }
}

@media (min-width: 1025px) {
    .container-responsive {
        padding: var(--container-padding-desktop) !important;
    }
}

/* Typography - Responsive scaling */
@media (max-width: 640px) {
    h1 { font-size: var(--font-size-mobile-2xl) !important; }
    h2 { font-size: var(--font-size-mobile-xl) !important; }
    h3 { font-size: var(--font-size-mobile-lg) !important; }
    h4 { font-size: var(--font-size-mobile-base) !important; }
    p, body { font-size: var(--font-size-mobile-base) !important; }
}

/* Tables - Horizontal scroll on mobile */
@media (max-width: 640px) {
    .table-responsive {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .table-responsive table {
        min-width: 600px;
    }
}

/* Images - Responsive */
img {
    max-width: 100%;
    height: auto;
}

/* ============================================
   RESPONSIVE GRID UTILITIES
   ============================================ */

.responsive-grid {
    display: grid;
    gap: var(--spacing-base);
    grid-template-columns: 1fr; /* Mobile: 1 column */
}

@media (min-width: 641px) {
    .responsive-grid {
        grid-template-columns: repeat(2, 1fr); /* Tablet: 2 columns */
    }
}

@media (min-width: 1025px) {
    .responsive-grid {
        grid-template-columns: repeat(3, 1fr); /* Desktop: 3 columns */
    }
}

/* ============================================
   RESPONSIVE FLEX UTILITIES
   ============================================ */

.responsive-flex {
    display: flex;
    flex-direction: column; /* Mobile: column */
    gap: var(--spacing-base);
}

@media (min-width: 641px) {
    .responsive-flex {
        flex-direction: row; /* Tablet+: row */
    }
}

