/* ==========================================================================
   PLATE CALCULATOR - SHARED STYLES
   Mobile-first design system
   ========================================================================== */

/* --------------------------------------------------------------------------
   CSS Custom Properties (Design Tokens)
   -------------------------------------------------------------------------- */
:root {
    /* Colors - Dark Theme */
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --bg-elevated: #1c2128;

    --border-default: #30363d;
    --border-muted: #21262d;
    --border-emphasis: #484f58;

    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --text-on-emphasis: #ffffff;

    --accent-blue: #58a6ff;
    --accent-blue-muted: #388bfd;
    --accent-green: #3fb950;
    --accent-green-emphasis: #238636;
    --accent-red: #f85149;
    --accent-yellow: #d29922;
    --accent-orange: #db6d28;

    /* Plate Colors (Competition Standard) */
    --plate-red: #dc2626;
    --plate-blue: #2563eb;
    --plate-yellow: #eab308;
    --plate-green: #16a34a;
    --plate-white: #f5f5f5;
    --plate-gray: #6b7280;

    /* Typography */
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans', Helvetica, Arial, sans-serif;
    --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;

    --text-xs: 0.75rem;    /* 12px */
    --text-sm: 0.875rem;   /* 14px */
    --text-base: 1rem;     /* 16px - prevents iOS zoom */
    --text-lg: 1.125rem;   /* 18px */
    --text-xl: 1.25rem;    /* 20px */
    --text-2xl: 1.5rem;    /* 24px */
    --text-3xl: 1.875rem;  /* 30px */
    --text-4xl: 2.25rem;   /* 36px */

    --leading-tight: 1.25;
    --leading-normal: 1.5;
    --leading-relaxed: 1.625;

    --font-normal: 400;
    --font-medium: 500;
    --font-semibold: 600;
    --font-bold: 700;

    /* Spacing */
    --space-1: 0.25rem;   /* 4px */
    --space-2: 0.5rem;    /* 8px */
    --space-3: 0.75rem;   /* 12px */
    --space-4: 1rem;      /* 16px */
    --space-5: 1.25rem;   /* 20px */
    --space-6: 1.5rem;    /* 24px */
    --space-8: 2rem;      /* 32px */
    --space-10: 2.5rem;   /* 40px */
    --space-12: 3rem;     /* 48px */
    --space-16: 4rem;     /* 64px */

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --radius-xl: 12px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.4);
    --shadow-glow-blue: 0 0 20px rgba(88, 166, 255, 0.3);
    --shadow-glow-green: 0 0 20px rgba(63, 185, 80, 0.3);

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 200ms ease;
    --transition-slow: 300ms ease;

    /* Touch Targets */
    --touch-target-min: 48px;
    --touch-target-comfortable: 56px;

    /* Z-Index Scale */
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-fixed: 300;
    --z-modal-backdrop: 400;
    --z-modal: 500;
    --z-toast: 600;
}

/* --------------------------------------------------------------------------
   Reset & Base Styles
   -------------------------------------------------------------------------- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-family);
    font-size: var(--text-base);
    line-height: var(--leading-normal);
    color: var(--text-primary);
    background: var(--bg-primary);
    min-height: 100vh;
    min-height: 100dvh; /* Dynamic viewport height for mobile */
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

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

@media (min-width: 768px) {
    h1 { font-size: var(--text-3xl); }
    h2 { font-size: var(--text-2xl); }
    h3 { font-size: var(--text-xl); }
}

a {
    color: var(--accent-blue);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--accent-blue-muted);
    text-decoration: underline;
}

/* --------------------------------------------------------------------------
   Layout Containers
   -------------------------------------------------------------------------- */
.container {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding: 0 var(--space-4);
}

.container-narrow {
    max-width: 600px;
}

.container-wide {
    max-width: 1200px;
}

/* --------------------------------------------------------------------------
   Navigation - Bottom Bar (Mobile First)
   -------------------------------------------------------------------------- */
.nav-bottom {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-default);
    padding: var(--space-2) var(--space-4);
    padding-bottom: calc(var(--space-2) + env(safe-area-inset-bottom, 0px));
    z-index: var(--z-fixed);
    display: flex;
    justify-content: space-around;
    gap: var(--space-2);
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: var(--touch-target-min);
    min-height: var(--touch-target-min);
    padding: var(--space-2);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: var(--text-xs);
    font-weight: var(--font-medium);
    border-radius: var(--radius-lg);
    transition: all var(--transition-fast);
}

.nav-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    text-decoration: none;
}

.nav-item.active {
    color: var(--accent-blue);
    background: rgba(88, 166, 255, 0.1);
}

.nav-icon {
    width: 24px;
    height: 24px;
    margin-bottom: var(--space-1);
}

/* Add padding to body for bottom nav */
.has-bottom-nav {
    padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px));
}

/* Desktop: Convert to top nav */
@media (min-width: 768px) {
    .nav-bottom {
        position: static;
        border-top: none;
        border-bottom: 1px solid var(--border-default);
        padding: var(--space-3) var(--space-6);
        justify-content: center;
        gap: var(--space-6);
    }

    .nav-item {
        flex-direction: row;
        gap: var(--space-2);
        font-size: var(--text-sm);
        padding: var(--space-3) var(--space-4);
    }

    .nav-icon {
        margin-bottom: 0;
    }

    .has-bottom-nav {
        padding-bottom: 0;
    }
}

/* --------------------------------------------------------------------------
   Cards
   -------------------------------------------------------------------------- */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
}

.card-elevated {
    background: var(--bg-elevated);
    box-shadow: var(--shadow-md);
}

.card-header {
    margin-bottom: var(--space-5);
    padding-bottom: var(--space-4);
    border-bottom: 1px solid var(--border-muted);
}

.card-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
}

.card-subtitle {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin-top: var(--space-1);
}

/* Feature cards for home page */
.feature-grid {
    display: grid;
    gap: var(--space-4);
    margin-top: var(--space-6);
}

@media (min-width: 768px) {
    .feature-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

.feature-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: var(--space-6);
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    text-decoration: none;
    color: inherit;
    transition: all var(--transition-base);
}

.feature-card:hover {
    border-color: var(--accent-blue);
    background: var(--bg-tertiary);
    transform: translateY(-2px);
    text-decoration: none;
}

.feature-icon {
    width: 48px;
    height: 48px;
    margin-bottom: var(--space-4);
    color: var(--accent-blue);
}

.feature-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    margin-bottom: var(--space-2);
}

.feature-description {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: var(--touch-target-min);
    padding: var(--space-3) var(--space-5);
    font-family: inherit;
    font-size: var(--text-base);
    font-weight: var(--font-medium);
    line-height: 1;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    white-space: nowrap;
    -webkit-user-select: none;
    user-select: none;
}

.btn:hover {
    background: var(--border-default);
    border-color: var(--border-emphasis);
}

.btn:active {
    transform: scale(0.98);
}

.btn:focus-visible {
    outline: 2px solid var(--accent-blue);
    outline-offset: 2px;
}

.btn-primary {
    background: var(--accent-green-emphasis);
    border-color: var(--accent-green-emphasis);
    color: var(--text-on-emphasis);
}

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

.btn-blue {
    background: var(--accent-blue-muted);
    border-color: var(--accent-blue-muted);
    color: var(--text-on-emphasis);
}

.btn-blue:hover {
    background: var(--accent-blue);
    border-color: var(--accent-blue);
}

.btn-ghost {
    background: transparent;
    border-color: transparent;
}

.btn-ghost:hover {
    background: var(--bg-tertiary);
}

.btn-lg {
    min-height: var(--touch-target-comfortable);
    padding: var(--space-4) var(--space-6);
    font-size: var(--text-lg);
}

.btn-sm {
    min-height: 36px;
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
}

.btn-block {
    width: 100%;
}

/* Button group for toggle switches */
.btn-group {
    display: inline-flex;
    background: var(--bg-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.btn-group .btn {
    border: none;
    border-radius: 0;
    min-height: var(--touch-target-min);
}

.btn-group .btn.active {
    background: var(--accent-green-emphasis);
    color: var(--text-on-emphasis);
}

/* --------------------------------------------------------------------------
   Form Inputs
   -------------------------------------------------------------------------- */
.form-group {
    margin-bottom: var(--space-5);
}

.form-label {
    display: block;
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    color: var(--text-secondary);
    margin-bottom: var(--space-2);
}

.form-input {
    width: 100%;
    min-height: var(--touch-target-min);
    padding: var(--space-3) var(--space-4);
    font-family: inherit;
    font-size: var(--text-base); /* Prevents iOS zoom */
    color: var(--text-primary);
    background: var(--bg-primary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
    -webkit-appearance: none;
    appearance: none;
}

.form-input:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.2);
}

.form-input::placeholder {
    color: var(--text-muted);
}

/* Large weight input */
.input-weight {
    font-size: var(--text-3xl);
    font-weight: var(--font-bold);
    text-align: center;
    padding: var(--space-4);
    min-height: 72px;
}

.form-select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%238b949e' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 12px center;
    background-repeat: no-repeat;
    background-size: 20px;
    padding-right: 44px;
}

/* Quick weight buttons */
.quick-weights {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-top: var(--space-3);
}

.quick-weight-btn {
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-full);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.quick-weight-btn:hover {
    background: var(--border-default);
    border-color: var(--accent-blue);
}

.quick-weight-btn:active {
    transform: scale(0.95);
}

/* --------------------------------------------------------------------------
   Barbell Visualization
   -------------------------------------------------------------------------- */
.barbell-container {
    padding: var(--space-6) var(--space-4);
    background: var(--bg-primary);
    border-radius: var(--radius-lg);
    overflow-x: auto;
    margin: var(--space-5) 0;
}

.barbell {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 140px;
    position: relative;
    min-width: 320px;
}

.bar {
    width: 100%;
    max-width: 350px;
    height: 14px;
    background: linear-gradient(to bottom, #7a828a, #484f58, #7a828a);
    border-radius: 2px;
    position: relative;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.sleeve {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    height: 22px;
    width: 55px;
    background: linear-gradient(to bottom, #9ca3af, #6b7280, #9ca3af);
    border-radius: 2px;
}

.sleeve.left { left: 0; }
.sleeve.right { right: 0; }

.plates-side {
    display: flex;
    align-items: center;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
}

.plates-side.left {
    right: calc(50% + 25px);
    flex-direction: row-reverse;
}

.plates-side.right {
    left: calc(50% + 25px);
}

.plate {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    font-weight: var(--font-bold);
    font-size: 10px;
    color: #fff;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    margin: 0 1px;
    box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.4);
    transition: transform var(--transition-fast);
}

/* Plate sizes - Competition colors (LB) */
.plate-55 { background: var(--plate-red); height: 100px; width: 20px; }
.plate-45 { background: var(--plate-blue); height: 100px; width: 18px; }
.plate-35 { background: var(--plate-yellow); height: 88px; width: 16px; }
.plate-25 { background: var(--plate-green); height: 76px; width: 14px; }
.plate-10 { background: var(--plate-white); color: #000; height: 60px; width: 12px; text-shadow: none; }
.plate-5 { background: var(--plate-red); height: 50px; width: 10px; }
.plate-2-5 { background: var(--plate-green); height: 42px; width: 8px; }
.plate-1-25 { background: var(--plate-gray); height: 36px; width: 6px; }

/* Plate sizes - Competition colors (KG) */
.plate-25kg { background: var(--plate-red); height: 100px; width: 20px; }
.plate-20kg { background: var(--plate-blue); height: 100px; width: 18px; }
.plate-15kg { background: var(--plate-yellow); height: 88px; width: 16px; }
.plate-10kg { background: var(--plate-green); height: 76px; width: 14px; }
.plate-5kg { background: var(--plate-white); color: #000; height: 60px; width: 12px; text-shadow: none; }
.plate-2-5kg { background: var(--plate-red); height: 50px; width: 10px; }
.plate-1-25kg { background: var(--plate-green); height: 42px; width: 8px; }

/* --------------------------------------------------------------------------
   Results Display
   -------------------------------------------------------------------------- */
.results-section {
    margin-top: var(--space-6);
}

.results-header {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    color: var(--accent-blue);
    margin-bottom: var(--space-4);
}

.plate-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
}

.plate-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
}

.plate-color {
    width: 16px;
    height: 16px;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.plate-count {
    font-weight: var(--font-bold);
    color: var(--accent-blue);
}

/* Total weight display */
.total-display {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-4) var(--space-5);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    margin-top: var(--space-5);
}

.total-label {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.total-weight {
    font-size: var(--text-2xl);
    font-weight: var(--font-bold);
    color: var(--accent-green);
}

/* --------------------------------------------------------------------------
   Messages (Error, Warning, Info)
   -------------------------------------------------------------------------- */
.message {
    padding: var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
}

.message-error {
    background: rgba(248, 81, 73, 0.15);
    color: var(--accent-red);
    border: 1px solid rgba(248, 81, 73, 0.3);
}

.message-warning {
    background: rgba(210, 153, 34, 0.15);
    color: var(--accent-yellow);
    border: 1px solid rgba(210, 153, 34, 0.3);
}

.message-info {
    background: rgba(88, 166, 255, 0.15);
    color: var(--accent-blue);
    border: 1px solid rgba(88, 166, 255, 0.3);
}

.message-success {
    background: rgba(63, 185, 80, 0.15);
    color: var(--accent-green);
    border: 1px solid rgba(63, 185, 80, 0.3);
}

/* --------------------------------------------------------------------------
   Page Header
   -------------------------------------------------------------------------- */
.page-header {
    padding: var(--space-6) 0;
    text-align: center;
}

.page-title {
    font-size: var(--text-2xl);
    font-weight: var(--font-bold);
    margin-bottom: var(--space-2);
}

.page-subtitle {
    font-size: var(--text-base);
    color: var(--text-secondary);
}

@media (min-width: 768px) {
    .page-header {
        padding: var(--space-8) 0;
    }

    .page-title {
        font-size: var(--text-3xl);
    }
}

/* --------------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------------- */
.footer {
    padding: var(--space-8) var(--space-4);
    text-align: center;
    color: var(--text-muted);
    font-size: var(--text-sm);
    border-top: 1px solid var(--border-muted);
    margin-top: var(--space-8);
}

/* --------------------------------------------------------------------------
   Utility Classes
   -------------------------------------------------------------------------- */
.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;
}

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

.text-muted { color: var(--text-secondary); }
.text-success { color: var(--accent-green); }
.text-error { color: var(--accent-red); }
.text-warning { color: var(--accent-yellow); }

.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

.hidden { display: none !important; }

/* --------------------------------------------------------------------------
   Animations
   -------------------------------------------------------------------------- */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.animate-fade-in {
    animation: fadeIn var(--transition-base) ease-out;
}

.animate-slide-up {
    animation: slideUp var(--transition-slow) ease-out;
}

/* Reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
