/* ==========================================================================
   Capital Razors — Responsive & Mobile-First Foundation
   BLI-0002008 | Sprint-0000200-CR-Foundation-Auth

   Mobile-first CSS approach.
   Breakpoints: 320px (base), 768px (md), 1024px (lg), 1440px (xl)
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. BASE RESET & MOBILE-FIRST DEFAULTS (320px+)
   -------------------------------------------------------------------------- */

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height for mobile browsers */
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Prevent horizontal overflow from any element */
img, video, canvas, svg {
    max-width: 100%;
    height: auto;
    display: block;
}

/* --------------------------------------------------------------------------
   2. TOUCH-FRIENDLY TAP TARGETS (44px minimum per WCAG 2.5.5)
   -------------------------------------------------------------------------- */

a,
button,
[role="button"],
input[type="submit"],
input[type="button"],
input[type="reset"],
select,
.cr-tap-target {
    min-height: 44px;
    min-width: 44px;
}

/* For inline links within text, use padding instead of min-height */
p a,
li a,
span a,
.cr-inline-link {
    min-height: auto;
    min-width: auto;
    padding-block: 4px;
}

/* Form inputs — comfortable touch targets */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="tel"],
input[type="url"],
input[type="search"],
input[type="date"],
textarea,
select {
    min-height: 44px;
    font-size: 16px; /* Prevents iOS zoom on focus */
    padding: 10px 12px;
    width: 100%;
}

/* --------------------------------------------------------------------------
   3. LAYOUT STRUCTURE — MOBILE FIRST
   -------------------------------------------------------------------------- */

/* App shell — stacked on mobile, sidebar on desktop */
.cr-app {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-height: 100dvh;
}

/* Top navigation bar */
.cr-topnav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    z-index: 40;
    display: flex;
    align-items: center;
    padding: 0 16px;
}

/* Sidebar — off-canvas on mobile */
.cr-sidebar {
    position: fixed;
    top: 56px;
    left: 0;
    bottom: 0;
    width: 280px;
    z-index: 30;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.cr-sidebar.is-open {
    transform: translateX(0);
}

/* Sidebar overlay — mobile only */
.cr-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 25;
}

.cr-sidebar-overlay.is-visible {
    display: block;
}

/* Main content area */
.cr-main {
    flex: 1;
    padding-top: 56px; /* Clear fixed topnav */
    padding-left: 0;
    transition: padding-left 0.3s ease;
    width: 100%;
    min-width: 0; /* Prevent flex overflow */
}

.cr-main-content {
    padding: 16px;
    max-width: 100%;
}

/* --------------------------------------------------------------------------
   4. RESPONSIVE GRID SYSTEM
   -------------------------------------------------------------------------- */

.cr-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: 1fr; /* Single column on mobile */
}

.cr-grid-2 { grid-template-columns: 1fr; }
.cr-grid-3 { grid-template-columns: 1fr; }
.cr-grid-4 { grid-template-columns: 1fr; }

/* --------------------------------------------------------------------------
   5. RESPONSIVE TYPOGRAPHY (fluid scaling)
   -------------------------------------------------------------------------- */

.cr-heading-1 {
    font-size: clamp(1.5rem, 4vw, 2.5rem);
    line-height: 1.2;
}

.cr-heading-2 {
    font-size: clamp(1.25rem, 3vw, 2rem);
    line-height: 1.25;
}

.cr-heading-3 {
    font-size: clamp(1.1rem, 2.5vw, 1.5rem);
    line-height: 1.3;
}

.cr-body {
    font-size: 1rem;
    line-height: 1.6;
}

.cr-body-sm {
    font-size: 0.875rem;
    line-height: 1.5;
}

/* --------------------------------------------------------------------------
   6. RESPONSIVE CARDS
   -------------------------------------------------------------------------- */

.cr-card {
    border-radius: 12px;
    padding: 16px;
    width: 100%;
    min-width: 0; /* Prevent overflow */
}

/* --------------------------------------------------------------------------
   7. RESPONSIVE TABLES — horizontal scroll on mobile
   -------------------------------------------------------------------------- */

.cr-table-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px;
}

.cr-table-wrap table {
    min-width: 600px; /* Force scroll if needed */
}

/* --------------------------------------------------------------------------
   8. RESPONSIVE UTILITIES
   -------------------------------------------------------------------------- */

/* Hide/show at breakpoints */
.cr-hide-mobile { display: none; }
.cr-show-mobile { display: block; }

/* Safe area padding for notched devices */
.cr-safe-area-top { padding-top: env(safe-area-inset-top, 0px); }
.cr-safe-area-bottom { padding-bottom: env(safe-area-inset-bottom, 0px); }
.cr-safe-area-left { padding-left: env(safe-area-inset-left, 0px); }
.cr-safe-area-right { padding-right: env(safe-area-inset-right, 0px); }

/* Stack on mobile, row on desktop */
.cr-stack {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Full-bleed sections on mobile */
.cr-bleed-mobile {
    margin-left: -16px;
    margin-right: -16px;
    border-radius: 0;
}

/* --------------------------------------------------------------------------
   BREAKPOINT: 768px (Tablet / md)
   -------------------------------------------------------------------------- */

@media (min-width: 768px) {
    .cr-topnav {
        height: 64px;
        padding: 0 24px;
    }

    .cr-sidebar {
        top: 64px;
        width: 260px;
        transform: translateX(0); /* Sidebar visible by default on tablet+ */
    }

    .cr-sidebar-overlay {
        display: none !important; /* No overlay needed on tablet+ */
    }

    .cr-main {
        padding-top: 64px;
        padding-left: 260px;
    }

    .cr-main-content {
        padding: 24px;
    }

    /* Sidebar collapsed state on tablet+ */
    .cr-sidebar.is-collapsed {
        width: 72px;
    }

    .cr-sidebar.is-collapsed ~ .cr-main {
        padding-left: 72px;
    }

    /* Grid: expand to 2 columns */
    .cr-grid-2 { grid-template-columns: repeat(2, 1fr); }
    .cr-grid-3 { grid-template-columns: repeat(2, 1fr); }
    .cr-grid-4 { grid-template-columns: repeat(2, 1fr); }

    .cr-grid { gap: 20px; }

    .cr-card { padding: 20px; }

    .cr-hide-mobile { display: block; }
    .cr-show-mobile { display: none; }

    .cr-stack {
        flex-direction: row;
        gap: 16px;
    }

    .cr-bleed-mobile {
        margin-left: 0;
        margin-right: 0;
        border-radius: 12px;
    }
}

/* --------------------------------------------------------------------------
   BREAKPOINT: 1024px (Desktop / lg)
   -------------------------------------------------------------------------- */

@media (min-width: 1024px) {
    .cr-main-content {
        padding: 32px;
    }

    /* Grid: expand to full columns */
    .cr-grid-3 { grid-template-columns: repeat(3, 1fr); }
    .cr-grid-4 { grid-template-columns: repeat(3, 1fr); }

    .cr-grid { gap: 24px; }

    .cr-card { padding: 24px; }
}

/* --------------------------------------------------------------------------
   BREAKPOINT: 1440px (Wide desktop / xl)
   -------------------------------------------------------------------------- */

@media (min-width: 1440px) {
    .cr-main-content {
        max-width: 1280px;
        margin: 0 auto;
        padding: 40px;
    }

    .cr-grid-4 { grid-template-columns: repeat(4, 1fr); }
}

/* --------------------------------------------------------------------------
   9. ANIMATIONS (reduced motion safe)
   -------------------------------------------------------------------------- */

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

/* --------------------------------------------------------------------------
   10. PRINT STYLES
   -------------------------------------------------------------------------- */

@media print {
    .cr-topnav,
    .cr-sidebar,
    .cr-sidebar-overlay {
        display: none !important;
    }

    .cr-main {
        padding: 0 !important;
    }

    .cr-card {
        break-inside: avoid;
    }
}
