/**
 * PMERIT Base Styles
 * Version: 2.0
 * Last Updated: October 2025
 * 
 * Mobile-first CSS reset and foundation
 * MUST load theme-variables.css BEFORE this file
 */

/* ========================================
   CSS RESET (Modern Normalize)
   ======================================== */

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

html {
    /* Prevent font size adjustment on orientation change (iOS) */
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
    
    /* Smooth scrolling */
    scroll-behavior: smooth;
    
    /* Use dynamic viewport height (prevents iOS address bar issues) */
    height: 100dvh;
    height: 100vh; /* Fallback for older browsers */
}

body {
    min-height: 100dvh;
    min-height: 100vh; /* Fallback */
    
    /* Typography */
    font-family: var(--font-secondary);
    font-size: var(--text-base);
    font-weight: var(--weight-regular);
    line-height: var(--leading-normal);
    
    /* Colors */
    color: var(--text-primary);
    background-color: var(--bg-primary);
    
    /* Rendering optimizations */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    
    /* Prevent horizontal scroll */
    overflow-x: hidden;
}

/* Remove default margins on headings and paragraphs */
h1, h2, h3, h4, h5, h6,
p, blockquote, pre,
ul, ol, dl, dd,
figure, fieldset {
    margin: 0;
    padding: 0;
}

/* Remove list styles on ul, ol elements */
ul, ol {
    list-style: none;
}

/* Set core root defaults */
html:focus-within {
    scroll-behavior: smooth;
}

/* Make images easier to work with */
img,
picture,
video,
canvas,
svg {
    display: block;
    max-width: 100%;
    height: auto;
}

/* Inherit fonts for inputs and buttons */
input,
button,
textarea,
select {
    font: inherit;
    color: inherit;
}

/* Remove all animations and transitions for people that prefer not to see them */
@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 STYLES (Accessibility)
   ======================================== */

/* Remove default focus outline, we'll add custom */
*:focus {
    outline: none;
}

/* Custom focus styles for keyboard navigation */
*:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
    border-radius: var(--border-radius-sm);
}

/* Interactive elements focus */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}


/* ========================================
   TYPOGRAPHY BASE
   ======================================== */

/* Headings use Montserrat */
h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-primary);
    font-weight: var(--weight-semibold);
    line-height: var(--leading-tight);
    color: var(--text-primary);
}

h1 {
    font-size: var(--text-3xl);
    font-weight: var(--weight-bold);
}

h2 {
    font-size: var(--text-2xl);
}

h3 {
    font-size: var(--text-xl);
}

h4 {
    font-size: var(--text-lg);
}

/* Paragraphs and body text use Inter */
p {
    margin-bottom: var(--space-4);
}

/* Links */
a {
    color: var(--text-link);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--text-link-hover);
    text-decoration: underline;
}

/* Strong and emphasis */
strong, b {
    font-weight: var(--weight-semibold);
}

em, i {
    font-style: italic;
}

/* Small text */
small {
    font-size: var(--text-sm);
}


/* ========================================
   BUTTON RESET
   ======================================== */

button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    font: inherit;
    color: inherit;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}


/* ========================================
   INPUT RESET
   ======================================== */

input:not([type="checkbox"]):not([type="radio"]),
textarea,
select {
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
    padding: var(--space-3) var(--space-4);
    background-color: var(--bg-secondary);
    transition: border-color var(--transition-fast);
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--color-primary);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-muted);
    opacity: 1;
}

/* Remove number input spinners */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
}


/* ========================================
   MOBILE-FIRST LAYOUT
   ======================================== */

/* Main container - non-scrollable viewport */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    min-height: 100vh; /* Fallback */
    overflow: hidden; /* Prevent body scroll */
}

/* Header */
.app-header {
    flex-shrink: 0;
    height: var(--mobile-header-height);
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    
    /* iOS safe area */
    padding-top: var(--safe-area-top);
}

/* Main content - this is where scrolling happens */
.app-main {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* Footer */
.app-footer {
    flex-shrink: 0;
    min-height: var(--mobile-footer-height);
    background-color: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    
    /* iOS safe area */
    padding-bottom: var(--safe-area-bottom);
}


/* ========================================
   MOBILE TOUCH TARGETS
   ======================================== */

/* Ensure minimum 44px touch targets (iOS guidelines) */
.btn,
.touch-target,
button:not(.btn-unstyled),
a.btn {
    min-height: var(--mobile-touch-target);
    min-width: var(--mobile-touch-target);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-3) var(--space-5);
}


/* ========================================
   CONTAINER & SPACING
   ======================================== */

.container {
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    padding-left: var(--space-4);
    padding-right: var(--space-4);
}

/* Max widths for different breakpoints */
@media (min-width: 640px) {
    .container {
        max-width: 640px;
        padding-left: var(--space-6);
        padding-right: var(--space-6);
    }
}

@media (min-width: 768px) {
    .container {
        max-width: 768px;
    }
}

@media (min-width: 1024px) {
    .container {
        max-width: 1024px;
    }
}

@media (min-width: 1280px) {
    .container {
        max-width: 1280px;
    }
}


/* ========================================
   UTILITY CLASSES
   ======================================== */

/* Display */
.hidden {
    display: none !important;
}

.block {
    display: block;
}

.inline-block {
    display: inline-block;
}

.flex {
    display: flex;
}

.inline-flex {
    display: inline-flex;
}

.grid {
    display: grid;
}

/* Visibility (maintains layout space) */
.invisible {
    visibility: hidden;
}

.visible {
    visibility: visible;
}

/* Text alignment */
.text-left {
    text-align: left;
}

.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

/* Flexbox utilities */
.flex-col {
    flex-direction: column;
}

.flex-row {
    flex-direction: row;
}

.items-center {
    align-items: center;
}

.items-start {
    align-items: flex-start;
}

.items-end {
    align-items: flex-end;
}

.justify-center {
    justify-content: center;
}

.justify-between {
    justify-content: space-between;
}

.justify-start {
    justify-content: flex-start;
}

.justify-end {
    justify-content: flex-end;
}

.flex-1 {
    flex: 1;
}

.flex-shrink-0 {
    flex-shrink: 0;
}

.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.gap-8 { gap: var(--space-8); }


/* ========================================
   iOS SPECIFIC FIXES
   ======================================== */

/* Prevent zoom on input focus (iOS) */
@media (max-width: 767px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="tel"],
    input[type="number"],
    textarea,
    select {
        font-size: 16px; /* Prevents iOS zoom */
    }
}

/* Improve tap highlight color */
* {
    -webkit-tap-highlight-color: rgba(255, 107, 107, 0.1);
}

/* Disable callout on iOS (long-press menu) */
a, button {
    -webkit-touch-callout: none;
}
