/* GymTracker Custom Styles */

/* ==================== Theme System ==================== */
:root {
    /* Default: Dark mode with Indigo */
    --color-bg: #0f0f1a;
    --color-surface: #1a1a2e;
    --color-card: #252540;
    --color-border: #3a3a5c;
    --color-text: #ffffff;
    --color-text-secondary: #9ca3af;
    --color-text-muted: #6b7280;

    /* Primary color (default: indigo) */
    --color-primary-50: #eef2ff;
    --color-primary-100: #e0e7ff;
    --color-primary-200: #c7d2fe;
    --color-primary-300: #a5b4fc;
    --color-primary-400: #818cf8;
    --color-primary-500: #6366f1;
    --color-primary-600: #4f46e5;
    --color-primary-700: #4338ca;
    --color-primary-800: #3730a3;
    --color-primary-900: #312e81;
}

/* Light mode */
[data-theme="light"] {
    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-card: #f1f5f9;
    --color-border: #e2e8f0;
    --color-text: #1e293b;
    --color-text-secondary: #64748b;
    --color-text-muted: #94a3b8;
}

/* Color themes */
[data-color="emerald"] {
    --color-primary-50: #ecfdf5;
    --color-primary-100: #d1fae5;
    --color-primary-200: #a7f3d0;
    --color-primary-300: #6ee7b7;
    --color-primary-400: #34d399;
    --color-primary-500: #10b981;
    --color-primary-600: #059669;
    --color-primary-700: #047857;
    --color-primary-800: #065f46;
    --color-primary-900: #064e3b;
}

[data-color="blue"] {
    --color-primary-50: #eff6ff;
    --color-primary-100: #dbeafe;
    --color-primary-200: #bfdbfe;
    --color-primary-300: #93c5fd;
    --color-primary-400: #60a5fa;
    --color-primary-500: #3b82f6;
    --color-primary-600: #2563eb;
    --color-primary-700: #1d4ed8;
    --color-primary-800: #1e40af;
    --color-primary-900: #1e3a8a;
}

[data-color="violet"] {
    --color-primary-50: #f5f3ff;
    --color-primary-100: #ede9fe;
    --color-primary-200: #ddd6fe;
    --color-primary-300: #c4b5fd;
    --color-primary-400: #a78bfa;
    --color-primary-500: #8b5cf6;
    --color-primary-600: #7c3aed;
    --color-primary-700: #6d28d9;
    --color-primary-800: #5b21b6;
    --color-primary-900: #4c1d95;
}

[data-color="pink"] {
    --color-primary-50: #fdf2f8;
    --color-primary-100: #fce7f3;
    --color-primary-200: #fbcfe8;
    --color-primary-300: #f9a8d4;
    --color-primary-400: #f472b6;
    --color-primary-500: #ec4899;
    --color-primary-600: #db2777;
    --color-primary-700: #be185d;
    --color-primary-800: #9d174d;
    --color-primary-900: #831843;
}

[data-color="orange"] {
    --color-primary-50: #fff7ed;
    --color-primary-100: #ffedd5;
    --color-primary-200: #fed7aa;
    --color-primary-300: #fdba74;
    --color-primary-400: #fb923c;
    --color-primary-500: #f97316;
    --color-primary-600: #ea580c;
    --color-primary-700: #c2410c;
    --color-primary-800: #9a3412;
    --color-primary-900: #7c2d12;
}

[data-color="cyan"] {
    --color-primary-50: #ecfeff;
    --color-primary-100: #cffafe;
    --color-primary-200: #a5f3fc;
    --color-primary-300: #67e8f9;
    --color-primary-400: #22d3ee;
    --color-primary-500: #06b6d4;
    --color-primary-600: #0891b2;
    --color-primary-700: #0e7490;
    --color-primary-800: #155e75;
    --color-primary-900: #164e63;
}

/* Apply theme variables */
body {
    background-color: var(--color-bg) !important;
    color: var(--color-text) !important;
}

/* Override Tailwind classes with CSS variables */
.bg-dark-bg {
    background-color: var(--color-bg) !important;
}

.bg-dark-surface {
    background-color: var(--color-surface) !important;
}

.bg-dark-card {
    background-color: var(--color-card) !important;
}

.border-dark-border {
    border-color: var(--color-border) !important;
}

/* Text colors that need to adapt to theme */
[data-theme="light"] .text-white {
    color: var(--color-text) !important;
}

[data-theme="light"] .text-gray-300 {
    color: #475569 !important;
}

[data-theme="light"] .text-gray-400 {
    color: var(--color-text-secondary) !important;
}

[data-theme="light"] .text-gray-500 {
    color: var(--color-text-muted) !important;
}

[data-theme="light"] .text-gray-600 {
    color: var(--color-text-muted) !important;
}

[data-theme="light"] .placeholder-gray-500::placeholder {
    color: #94a3b8 !important;
}

/* Light mode specific backgrounds */
[data-theme="light"] .bg-dark-bg {
    background-color: #f8fafc !important;
}

[data-theme="light"] .bg-dark-surface {
    background-color: #ffffff !important;
}

[data-theme="light"] .bg-dark-card {
    background-color: #f1f5f9 !important;
}

[data-theme="light"] .border-dark-border {
    border-color: #e2e8f0 !important;
}

[data-theme="light"] #bottom-nav {
    background-color: #ffffff !important;
    border-color: #e2e8f0 !important;
}

[data-theme="light"] .stat-card {
    background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%) !important;
    border-color: #cbd5e1 !important;
}

[data-theme="light"] .set-row {
    background-color: #f1f5f9 !important;
}

[data-theme="light"] input,
[data-theme="light"] select {
    background-color: #ffffff !important;
    border-color: #e2e8f0 !important;
    color: #1e293b !important;
}

[data-theme="light"] .inc-dec-btn {
    background-color: #e2e8f0 !important;
    color: #1e293b !important;
}

/* Primary color utilities - use CSS variables */
.bg-primary-500 {
    background-color: var(--color-primary-500) !important;
}

.bg-primary-600 {
    background-color: var(--color-primary-600) !important;
}

.bg-primary-700 {
    background-color: var(--color-primary-700) !important;
}

.text-primary-400 {
    color: var(--color-primary-400) !important;
}

.text-primary-500 {
    color: var(--color-primary-500) !important;
}

.border-primary-500 {
    border-color: var(--color-primary-500) !important;
}

.hover\:bg-primary-500:hover {
    background-color: var(--color-primary-500) !important;
}

.hover\:bg-primary-400:hover {
    background-color: var(--color-primary-400) !important;
}

.hover\:text-primary-400:hover {
    color: var(--color-primary-400) !important;
}

.focus\:border-primary-500:focus {
    border-color: var(--color-primary-500) !important;
}

.focus\:ring-primary-500:focus {
    --tw-ring-color: var(--color-primary-500) !important;
}

.shadow-primary-600\/30 {
    --tw-shadow-color: var(--color-primary-600) !important;
}

/* Primary color with opacity */
.bg-primary-600\/20 {
    background-color: color-mix(in srgb, var(--color-primary-600) 20%, transparent) !important;
}

.bg-primary-500\/20 {
    background-color: color-mix(in srgb, var(--color-primary-500) 20%, transparent) !important;
}

.text-primary-400 {
    color: var(--color-primary-400) !important;
}

/* Gradient with theme color */
.gradient-text {
    background: linear-gradient(135deg, var(--color-primary-500), var(--color-primary-400)) !important;
    -webkit-background-clip: text !important;
    -webkit-text-fill-color: transparent !important;
    background-clip: text !important;
}

.bg-gradient-primary,
.from-primary-500,
.bg-gradient-to-br.from-primary-500 {
    background: linear-gradient(135deg, var(--color-primary-500), var(--color-primary-700)) !important;
}

.bg-gradient-primary {
    background: linear-gradient(135deg, var(--color-primary-500), var(--color-primary-700));
}

/* Safe area for iOS devices */
.safe-area-bottom {
    padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Page transitions */
.page-enter {
    opacity: 0;
    transform: translateX(20px);
}

.page-enter-active {
    opacity: 1;
    transform: translateX(0);
    transition: opacity 200ms ease-out, transform 200ms ease-out;
}

.page-exit {
    opacity: 1;
    transform: translateX(0);
}

.page-exit-active {
    opacity: 0;
    transform: translateX(-20px);
    transition: opacity 150ms ease-in, transform 150ms ease-in;
}

/* Button press feedback */
.btn-press:active {
    transform: scale(0.97);
    transition: transform 100ms ease;
}

/* Button loading state - prevents double-click */
.is-loading {
    cursor: not-allowed !important;
    opacity: 0.85;
    transform: scale(1) !important;
}

.is-loading:active {
    transform: scale(1) !important;
}

/* Card hover/press effects */
.card-interactive {
    transition: transform 150ms ease, box-shadow 150ms ease;
}

.card-interactive:active {
    transform: scale(0.98);
}

/* Input focus styles */
input:focus,
select:focus,
textarea:focus {
    outline: none;
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-primary-500) 50%, transparent);
}

/* Number input - hide 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;
    appearance: textfield;
}

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--color-primary-500) 30%, transparent);
    border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
    background: color-mix(in srgb, var(--color-primary-500) 50%, transparent);
}

/* Toast animations */
@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes toast-out {
    from {
        opacity: 1;
        transform: translateY(0);
    }

    to {
        opacity: 0;
        transform: translateY(-20px);
    }
}

.toast-enter {
    animation: toast-in 200ms ease-out forwards;
}

.toast-exit {
    animation: toast-out 150ms ease-in forwards;
}

/* Modal animations */
@keyframes modal-backdrop-in {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes modal-content-in {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(10px);
    }

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-backdrop {
    animation: modal-backdrop-in 150ms ease-out forwards;
}

.modal-content {
    animation: modal-content-in 200ms ease-out forwards;
}

/* Success pulse animation */
@keyframes success-pulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4);
    }

    50% {
        box-shadow: 0 0 0 8px rgba(34, 197, 94, 0);
    }
}

.success-pulse {
    animation: success-pulse 600ms ease-out;
}

/* Failure indicator */
.failure-badge {
    background: linear-gradient(135deg, #f43f5e, #e11d48);
}

/* Loading skeleton */
@keyframes skeleton-pulse {

    0%,
    100% {
        opacity: 0.4;
    }

    50% {
        opacity: 0.7;
    }
}

.skeleton {
    background: linear-gradient(90deg, #252540 25%, #3a3a5c 50%, #252540 75%);
    background-size: 200% 100%;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}

/* Pull to refresh indicator */
.pull-indicator {
    transition: transform 200ms ease;
}

/* Active nav item */
.nav-item.active {
    color: var(--color-primary-500);
}

.nav-item.active svg {
    color: var(--color-primary-500);
}

/* Increment/decrement buttons */
.inc-dec-btn {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: #252540;
    color: white;
    font-size: 1.25rem;
    font-weight: 600;
    transition: background 150ms ease;
}

.inc-dec-btn:active {
    background: var(--color-primary-600);
}

/* Set row styling */
.set-row {
    display: grid;
    grid-template-columns: 40px 1fr 1fr 60px;
    gap: 8px;
    align-items: center;
    padding: 12px;
    background: #1a1a2e;
    border-radius: 12px;
    margin-bottom: 8px;
}

.set-row.is-failure {
    border-left: 3px solid #f43f5e;
}

/* Stat card */
.stat-card {
    background: linear-gradient(135deg, var(--color-surface) 0%, var(--color-card) 100%);
    border: 1px solid var(--color-border);
    border-radius: 16px;
    padding: 16px;
}


/* ==================== Enhanced UX/UI Styles ==================== */

/* Smooth focus transitions */
input,
button,
a,
select,
textarea {
    transition: all 150ms ease;
}

/* Better touch targets */
button,
a,
.touchable {
    min-height: 44px;
    min-width: 44px;
}

/* Improved card shadows */
.card-shadow {
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
}

.card-shadow-lg {
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -2px rgba(0, 0, 0, 0.2);
}

/* Glow effects */
.glow-primary {
    box-shadow: 0 0 20px color-mix(in srgb, var(--color-primary-500) 30%, transparent);
}

.glow-success {
    box-shadow: 0 0 20px rgba(34, 197, 94, 0.3);
}

/* Ripple effect for buttons */
.ripple {
    position: relative;
    overflow: hidden;
}

.ripple::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 300ms ease, height 300ms ease;
}

.ripple:active::after {
    width: 200%;
    height: 200%;
}

/* Improved loading spinner */
.spinner {
    border: 3px solid color-mix(in srgb, var(--color-primary-500) 20%, transparent);
    border-top-color: var(--color-primary-500);
    border-radius: 50%;
    animation: spin 800ms linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Slide up animation for modals on mobile */
@media (max-width: 640px) {
    @keyframes modal-slide-up {
        from {
            opacity: 0;
            transform: translateY(100%);
        }

        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    .modal-content {
        animation: modal-slide-up 300ms cubic-bezier(0.16, 1, 0.3, 1) forwards;
    }
}

/* Haptic feedback simulation */
.haptic:active {
    transform: scale(0.98);
}

/* Better empty states */
.empty-state {
    opacity: 0.7;
}

.empty-state svg {
    opacity: 0.5;
}

/* Floating action button */
.fab {
    position: fixed;
    bottom: 80px;
    right: 16px;
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--color-primary-500), var(--color-primary-600));
    box-shadow: 0 4px 12px color-mix(in srgb, var(--color-primary-500) 40%, transparent);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 40;
    transition: transform 200ms ease, box-shadow 200ms ease;
}

.fab:active {
    transform: scale(0.95);
    box-shadow: 0 2px 8px color-mix(in srgb, var(--color-primary-500) 30%, transparent);
}

/* Progress bar */
.progress-bar {
    height: 4px;
    background: #252540;
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--color-primary-500), var(--color-primary-400));
    border-radius: 2px;
    transition: width 300ms ease;
}

/* Badge styles */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-primary {
    background: color-mix(in srgb, var(--color-primary-500) 20%, transparent);
    color: var(--color-primary-400);
}

.badge-success {
    background: rgba(34, 197, 94, 0.2);
    color: #4ade80;
}

.badge-warning {
    background: rgba(234, 179, 8, 0.2);
    color: #facc15;
}

.badge-danger {
    background: rgba(244, 63, 94, 0.2);
    color: #fb7185;
}

/* Divider */
.divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, #3a3a5c, transparent);
    margin: 16px 0;
}

/* Version footer styling */
.version-footer {
    font-size: 0.75rem;
    color: #6b7280;
    text-align: center;
    padding: 16px;
}

.version-footer a {
    color: var(--color-primary-500);
    text-decoration: none;
}

.version-footer a:hover {
    color: var(--color-primary-400);
}

/* Improved checkbox styling */
input[type="checkbox"] {
    appearance: none;
    width: 20px;
    height: 20px;
    border: 2px solid #3a3a5c;
    border-radius: 6px;
    background: #1a1a2e;
    cursor: pointer;
    transition: all 150ms ease;
}

input[type="checkbox"]:checked {
    background: var(--color-primary-500);
    border-color: var(--color-primary-500);
}

input[type="checkbox"]:checked::after {
    content: '✓';
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 12px;
    font-weight: bold;
}

/* Failure checkbox special styling */
input[type="checkbox"].failure-check:checked {
    background: #f43f5e;
    border-color: #f43f5e;
}

/* Smooth page scroll */
html {
    scroll-behavior: smooth;
}

/* Prevent text selection on interactive elements */
button,
.nav-item,
.card-interactive {
    user-select: none;
    -webkit-user-select: none;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .bg-dark-card {
        border-width: 2px;
    }

    .text-gray-400 {
        color: #9ca3af;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ==================== Weight Unit Toggle (kg/lb) ==================== */
.unit-toggle {
    display: inline-flex;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    padding: 2px;
    gap: 2px;
}

.unit-toggle-btn {
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: all 150ms ease;
    cursor: pointer;
    color: var(--color-text-muted);
    background: transparent;
    border: none;
    min-width: 40px;
    min-height: 28px;
}

.unit-toggle-btn:hover {
    color: var(--color-text-secondary);
}

.unit-toggle-btn.active {
    background: var(--color-primary-600);
    color: white;
    box-shadow: 0 2px 4px color-mix(in srgb, var(--color-primary-600) 30%, transparent);
}

.unit-toggle-btn:active {
    transform: scale(0.95);
}

/* Light mode adjustments */
[data-theme="light"] .unit-toggle {
    background: #f1f5f9;
    border-color: #e2e8f0;
}

[data-theme="light"] .unit-toggle-btn {
    color: #64748b;
}

[data-theme="light"] .unit-toggle-btn:hover {
    color: #475569;
}

[data-theme="light"] .unit-toggle-btn.active {
    background: var(--color-primary-600);
    color: white;
}

/* Weight input with unit indicator */
.weight-input-wrapper {
    position: relative;
}

.weight-unit-label {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-muted);
    pointer-events: none;
}

/* Previous set chips - clickable to autofill */
.prev-set-chip {
    padding: 6px 10px;
    background: color-mix(in srgb, var(--color-surface) 50%, transparent);
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 0.75rem;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: all 150ms ease;
}

.prev-set-chip:hover {
    background: color-mix(in srgb, var(--color-primary-500) 15%, transparent);
    border-color: var(--color-primary-500);
    color: var(--color-primary-400);
}

.prev-set-chip:active {
    transform: scale(0.95);
}

.prev-set-chip.current-workout {
    border-color: var(--color-primary-500);
    background: color-mix(in srgb, var(--color-primary-500) 10%, transparent);
}

/* Fade in animation for new elements */
.fade-in {
    animation: fadeIn 200ms ease-out forwards;
}

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