/* Main Styles */
* {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

/* Allow selection only in input fields */
input, textarea {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* Disable image dragging */
img, svg {
    pointer-events: none;
    -webkit-user-drag: none;
    -khtml-user-drag: none;
    -moz-user-drag: none;
    -o-user-drag: none;
    user-drag: none;
}

/* Disable text highlighting */
::selection {
    background: transparent;
}
::-moz-selection {
    background: transparent;
}

body { 
    -webkit-tap-highlight-color: transparent; 
    overscroll-behavior: none;
}

/* iOS safe-area header padding - fixed 47px for notch devices */
.app-header {
    padding-top: 47px;
    padding-top: calc(constant(safe-area-inset-top, 47px) + 0.5rem);
    padding-top: calc(env(safe-area-inset-top, 47px) + 0.5rem);
}

.app-header-lg {
    padding-top: 50px;
    padding-top: calc(constant(safe-area-inset-top, 50px) + 0.75rem);
    padding-top: calc(env(safe-area-inset-top, 50px) + 0.75rem);
}

@supports (padding-top: env(safe-area-inset-top)) {
    .app-header {
        padding-top: calc(env(safe-area-inset-top) + 0.5rem);
    }
    .app-header-lg {
        padding-top: calc(env(safe-area-inset-top) + 0.75rem);
    }
}

/* Prevent body scroll when modal is open */
body.modal-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
}

/* Modal overlay - matches app container width */
.modal-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    width: 100% !important;
    max-width: 28rem !important; /* max-w-md = 28rem */
    height: 100vh !important;
    height: 100dvh !important;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
    box-sizing: border-box;
}

/* On mobile, use full width */
@media (max-width: 767px) {
    .modal-overlay {
        left: 0 !important;
        transform: none !important;
        width: 100vw !important;
        max-width: none !important;
    }
}

/* Ensure modal content fits within container */
.modal-overlay > div {
    position: relative;
    width: 100%;
    max-width: 100%;
}

/* Timer floating overlay - sticky at bottom of viewport */
.timer-floating-overlay {
    position: fixed !important;
    bottom: 20px !important;
    left: 20px !important;
    right: 20px !important;
    z-index: 100;
    pointer-events: none; /* Allow clicks through overlay */
}

.timer-floating-card {
    pointer-events: auto; /* Re-enable clicks on the card */
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
}

/* Minimized timer circle */
.timer-minimized-circle {
    position: fixed !important;
    top: 20px !important;
    right: 20px !important;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #1d4ed8);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.4);
    cursor: pointer;
    z-index: 101;
    transition: transform 0.2s ease;
}

.timer-minimized-circle:active {
    transform: scale(0.95);
}

.timer-minimized-circle .timer-seconds {
    color: white;
    font-weight: bold;
    font-size: 16px;
    font-variant-numeric: tabular-nums;
}

/* iOS touch fix */
.touch-manipulation {
    touch-action: manipulation;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

button {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.input-fade { 
    transition: background 0.3s; 
}

.timer-pulse { 
    animation: pulse 1s infinite; 
}

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

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

/* Swipe back indicator */
.swipe-indicator {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 60px;
    background: linear-gradient(to right, rgba(59, 130, 246, 0.3), transparent);
    pointer-events: none;
    opacity: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding-left: 8px;
    transition: opacity 0.15s ease-out;
}

.swipe-indicator.active {
    opacity: 1;
}

.swipe-indicator.triggered {
    background: linear-gradient(to right, rgba(34, 197, 94, 0.5), transparent);
}

.swipe-arrow {
    width: 24px;
    height: 24px;
    border-left: 3px solid white;
    border-bottom: 3px solid white;
    transform: rotate(45deg);
    opacity: 0.8;
    filter: drop-shadow(0 0 4px rgba(0,0,0,0.3));
}

/* Screen transition animations */
.screen-container {
    min-height: 100vh;
    position: relative;
}

.slide-in-right {
    animation: slideInRight 0.3s ease-out forwards;
}

.slide-out-right {
    animation: slideOutRight 0.3s ease-out forwards;
}

.slide-in-left {
    animation: slideInLeft 0.3s ease-out forwards;
}

.slide-out-left {
    animation: slideOutLeft 0.3s ease-out forwards;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0.5;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0.5;
    }
}

@keyframes slideInLeft {
    from {
        transform: translateX(-30%);
        opacity: 0.5;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutLeft {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(-30%);
        opacity: 0.5;
    }
}

/* Sync Indicator Styles */
.sync-indicator-container {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9998;
    pointer-events: none;
}

.sync-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: 50px;
    background: rgba(30, 41, 59, 0.95);
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
    animation: syncSlideUp 0.3s ease-out;
}

.sync-indicator.syncing {
    background: rgba(30, 64, 175, 0.95);
}

.sync-indicator.success {
    background: rgba(22, 101, 52, 0.95);
}

.sync-indicator.error {
    background: rgba(153, 27, 27, 0.95);
}

.sync-spinner {
    width: 18px;
    height: 18px;
    color: white;
    animation: syncSpin 1s linear infinite;
}

.sync-spinner svg {
    width: 100%;
    height: 100%;
}

.sync-check {
    width: 18px;
    height: 18px;
    color: white;
    animation: syncCheckPop 0.3s ease-out;
}

.sync-check svg {
    width: 100%;
    height: 100%;
}

.sync-error-icon {
    width: 18px;
    height: 18px;
    color: white;
}

.sync-error-icon svg {
    width: 100%;
    height: 100%;
}

.sync-text {
    font-size: 13px;
    font-weight: 600;
    color: white;
    white-space: nowrap;
}

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

@keyframes syncSpin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

@keyframes syncCheckPop {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Dark theme overrides */
.theme-dark body {
    background-color: #0b1220;
    color: #e2e8f0;
}

.theme-dark .bg-white {
    background-color: #0f172a !important;
}

.theme-dark .bg-slate-50 {
    background-color: #0f172a !important;
}

.theme-dark .bg-slate-100 {
    background-color: #111827 !important;
}

.theme-dark .bg-slate-200 {
    background-color: #1f2937 !important;
}

.theme-dark .text-slate-900 {
    color: #f8fafc !important;
}

.theme-dark .text-slate-800 {
    color: #e2e8f0 !important;
}

.theme-dark .text-slate-700 {
    color: #cbd5e1 !important;
}

.theme-dark .text-slate-600 {
    color: #94a3b8 !important;
}

.theme-dark .text-slate-500 {
    color: #94a3b8 !important;
}

.theme-dark .text-slate-400 {
    color: #94a3b8 !important;
}

.theme-dark .border-slate-200 {
    border-color: #1f2937 !important;
}

.theme-dark .border-slate-300 {
    border-color: #334155 !important;
}

.theme-dark .border-slate-100 {
    border-color: #1e293b !important;
}

.theme-dark .hover\:bg-slate-50:hover {
    background-color: #1f2937 !important;
}

.theme-dark .hover\:bg-slate-100:hover {
    background-color: #1f2937 !important;
}

.theme-dark .hover\:bg-slate-200:hover {
    background-color: #334155 !important;
}

.theme-dark .bg-slate-300 {
    background-color: #334155 !important;
}

.theme-dark .hover\:bg-slate-300:hover {
    background-color: #475569 !important;
}

.theme-dark .text-slate-300 {
    color: #94a3b8 !important;
}

/* Warm, cool, and status surfaces */
.theme-dark .bg-orange-50 { background-color: #2a1c12 !important; }
.theme-dark .bg-orange-100 { background-color: #3a2416 !important; }
.theme-dark .bg-orange-200 { background-color: #4a2a19 !important; }

.theme-dark .bg-red-50 { background-color: #2a1515 !important; }
.theme-dark .bg-red-100 { background-color: #3b1a1a !important; }
.theme-dark .bg-red-200 { background-color: #4a1f1f !important; }

.theme-dark .bg-blue-50 { background-color: #111a2e !important; }
.theme-dark .bg-blue-100 { background-color: #16213a !important; }
.theme-dark .bg-blue-200 { background-color: #1b2946 !important; }

.theme-dark .bg-green-50 { background-color: #0f2a1e !important; }
.theme-dark .bg-green-100 { background-color: #143526 !important; }
.theme-dark .bg-green-200 { background-color: #1a422f !important; }

.theme-dark .bg-amber-50 { background-color: #2a210f !important; }
.theme-dark .bg-amber-100 { background-color: #3b2a12 !important; }
.theme-dark .bg-amber-200 { background-color: #4a3315 !important; }

.theme-dark .bg-yellow-50 { background-color: #2a240f !important; }
.theme-dark .bg-yellow-100 { background-color: #3b3012 !important; }
.theme-dark .bg-yellow-200 { background-color: #4a3a15 !important; }

.theme-dark .bg-indigo-100 { background-color: #1a1f3a !important; }
.theme-dark .bg-indigo-200 { background-color: #20264a !important; }

/* Status background tints with opacity */
.theme-dark .bg-green-50\/30 { background-color: rgba(20, 53, 38, 0.4) !important; }
.theme-dark .bg-orange-50\/50 { background-color: rgba(58, 36, 22, 0.5) !important; }
.theme-dark .bg-blue-50\/30 { background-color: rgba(22, 33, 58, 0.4) !important; }

/* Matching borders for tinted states */
.theme-dark .border-orange-200 { border-color: #5c3a22 !important; }
.theme-dark .border-orange-300 { border-color: #6b4327 !important; }
.theme-dark .border-red-200 { border-color: #5a2a2a !important; }
.theme-dark .border-blue-200 { border-color: #2b3a66 !important; }
.theme-dark .border-green-200 { border-color: #24533a !important; }
.theme-dark .border-amber-200 { border-color: #5a4a20 !important; }

/* Accent text on dark surfaces */
.theme-dark .text-orange-700 { color: #fdba74 !important; }
.theme-dark .text-orange-800 { color: #fed7aa !important; }
.theme-dark .text-red-700 { color: #fca5a5 !important; }
.theme-dark .text-blue-700 { color: #93c5fd !important; }
.theme-dark .text-blue-800 { color: #bfdbfe !important; }
.theme-dark .text-green-700 { color: #86efac !important; }
.theme-dark .text-amber-700 { color: #fcd34d !important; }
.theme-dark .text-indigo-700 { color: #a5b4fc !important; }

/* Workout card outlines */
.theme-dark .workout-card {
    border-color: #1f2937 !important;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}

.theme-dark .border-blue-300 { border-color: #335187 !important; }
.theme-dark .border-blue-400 { border-color: #3b62a6 !important; }
.theme-dark .border-green-300 { border-color: #2f6b47 !important; }
.theme-dark .border-orange-200 { border-color: #6b3f22 !important; }

.theme-dark .ring-blue-100 {
    --tw-ring-color: rgba(59, 130, 246, 0.35) !important;
}

/* Workout description box */
.theme-dark .workout-description {
    background-color: #1f2937 !important;
    border-color: #374151 !important;
}

.theme-dark .workout-description svg {
    color: #fbbf24 !important;
}

.theme-dark .workout-description .text-slate-700 {
    color: #e2e8f0 !important;
}

.theme-dark .border-yellow-200 { border-color: #4a3a15 !important; }

/* Progress & History tabs */
.theme-dark .progress-history-tabs {
    background-color: #0f172a !important;
    border-color: #1f2937 !important;
}

.theme-dark .progress-history-tabs .tab-active {
    background-color: rgba(59, 130, 246, 0.18) !important;
    color: #bfdbfe !important;
    border-color: #3b82f6 !important;
}

/* Workout view dark mode tuning */
.workout-chip {
    background-color: #f1f5f9;
    color: #334155;
}

.workout-chip-danger {
    background-color: #fee2e2;
    color: #b91c1c;
}

.theme-dark .workout-screen {
    background-color: #0b1220 !important;
}

.theme-dark .workout-edit-panel {
    background-color: #0f172a !important;
    border-color: #1f2937 !important;
}

.theme-dark .workout-chip {
    background-color: #1f2937;
    color: #e2e8f0;
}

.theme-dark .workout-chip-danger {
    background-color: #3f1d1d;
    color: #fecaca;
}

.theme-dark .workout-complete-banner {
    background-color: #064e3b;
    border-color: #065f46;
}

.theme-dark .workout-complete-text {
    color: #a7f3d0;
}

.theme-dark .workout-footer {
    background-color: #0f172a !important;
    border-color: #1f2937 !important;
}