/* ============================================
   Calculator-Cloud.com - Advanced Mobile Enhancements
   Bottom navigation, gestures, animations, and UX improvements
   ============================================ */

/* ============================================
   MOBILE BOTTOM NAVIGATION BAR
   ============================================ */

.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 65px;
    background: linear-gradient(135deg, #053b7d 0%, #0a5a9c 100%);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    z-index: 9999;
    padding-bottom: env(safe-area-inset-bottom, 0);
}

.mobile-bottom-nav-inner {
    display: flex;
    justify-content: space-around;
    align-items: center;
    height: 100%;
    max-width: 500px;
    margin: 0 auto;
    padding: 0 10px;
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 10px;
    font-weight: 500;
    padding: 8px 12px;
    border-radius: 12px;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
    min-width: 60px;
}

.mobile-nav-item i {
    font-size: 20px;
    margin-bottom: 4px;
    transition: transform 0.2s ease;
}

.mobile-nav-item.active,
.mobile-nav-item:active {
    color: #fff;
    background: rgba(255, 255, 255, 0.15);
}

.mobile-nav-item.active i {
    transform: scale(1.1);
}

.mobile-nav-item span {
    white-space: nowrap;
}

/* Favorites badge */
.mobile-nav-item .nav-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    background: #ff6b6b;
    color: white;
    font-size: 9px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

/* Search button in nav */
.mobile-nav-search {
    position: relative;
}

.mobile-nav-search i {
    font-size: 22px;
}

@media (max-width: 768px) {
    .mobile-bottom-nav {
        display: block;
    }

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

    /* Adjust footer margin */
    footer {
        margin-bottom: 0;
    }
}

/* ============================================
   MOBILE SEARCH MODAL
   ============================================ */

.mobile-search-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-search-overlay.active {
    display: block;
    opacity: 1;
}

.mobile-search-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #fff;
    z-index: 10001;
    transform: translateY(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 100vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.mobile-search-modal.active {
    transform: translateY(0);
}

.mobile-search-header {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    background: #053b7d;
    gap: 12px;
}

.mobile-search-back {
    color: white;
    font-size: 24px;
    padding: 8px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.mobile-search-input-wrapper {
    flex: 1;
    position: relative;
}

.mobile-search-input {
    width: 100%;
    padding: 12px 40px 12px 15px;
    border: none;
    border-radius: 25px;
    font-size: 16px;
    background: rgba(255, 255, 255, 0.95);
    color: #333;
    outline: none;
}

.mobile-search-clear {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #999;
    font-size: 18px;
    padding: 5px;
    cursor: pointer;
    display: none;
}

.mobile-search-clear.visible {
    display: block;
}

.mobile-search-results {
    padding: 0;
    max-height: calc(100vh - 70px);
    overflow-y: auto;
}

.mobile-search-result-item {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid #eee;
    text-decoration: none;
    color: #333;
    gap: 15px;
    transition: background 0.2s;
}

.mobile-search-result-item:active {
    background: #f5f5f5;
}

.mobile-search-result-item i {
    font-size: 20px;
    color: #053b7d;
    width: 30px;
    text-align: center;
}

.mobile-search-result-info {
    flex: 1;
}

.mobile-search-result-title {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 2px;
}

.mobile-search-result-category {
    font-size: 12px;
    color: #888;
}

.mobile-search-empty {
    padding: 40px 20px;
    text-align: center;
    color: #888;
}

.mobile-search-empty i {
    font-size: 48px;
    margin-bottom: 15px;
    color: #ddd;
}

/* ============================================
   STICKY CALCULATOR RESULT
   ============================================ */

@media (max-width: 768px) {
    .sticky-result {
        position: sticky;
        bottom: calc(65px + env(safe-area-inset-bottom, 0));
        background: linear-gradient(to top, white 90%, transparent);
        padding: 15px 10px;
        margin: 0 -10px;
        z-index: 100;
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
        border-radius: 15px 15px 0 0;
    }

    .sticky-result #result {
        max-height: 35vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0;
        padding: 10px;
        background: #f8f9fa;
        border-radius: 10px;
    }
}

/* ============================================
   SWIPE INDICATOR
   ============================================ */

.swipe-indicator {
    display: none;
    text-align: center;
    padding: 8px;
    color: #999;
    font-size: 12px;
}

.swipe-indicator i {
    margin-right: 5px;
}

@media (max-width: 768px) {
    .swipe-indicator {
        display: block;
    }
}

/* ============================================
   PULL TO REFRESH
   ============================================ */

.pull-to-refresh {
    position: fixed;
    top: 60px;
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    background: #053b7d;
    color: white;
    padding: 10px 20px;
    border-radius: 0 0 20px 20px;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 1000;
    transition: transform 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.pull-to-refresh.pulling {
    transform: translateX(-50%) translateY(0);
}

.pull-to-refresh i {
    animation: none;
}

.pull-to-refresh.refreshing i {
    animation: spin 1s linear infinite;
}

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

/* ============================================
   TOUCH FEEDBACK EFFECTS
   ============================================ */

.touch-ripple {
    position: relative;
    overflow: hidden;
}

.touch-ripple::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
}

.touch-ripple:active::after {
    width: 200%;
    height: 200%;
    opacity: 1;
    transition: width 0.3s, height 0.3s, opacity 0.3s;
}

/* Button press animation */
.mobile-press {
    transition: transform 0.1s ease;
}

.mobile-press:active {
    transform: scale(0.95);
}

/* ============================================
   ENHANCED FORM INPUTS FOR MOBILE
   ============================================ */

@media (max-width: 768px) {
    /* Larger touch targets for inputs */
    input[type="text"],
    input[type="number"],
    input[type="tel"],
    input[type="email"],
    select {
        min-height: 50px;
        font-size: 16px !important; /* Prevents iOS zoom */
        padding: 14px 16px;
        border-radius: 10px;
        border: 2px solid #e0e0e0;
        transition: border-color 0.2s, box-shadow 0.2s;
    }

    input:focus,
    select:focus {
        border-color: #053b7d;
        box-shadow: 0 0 0 4px rgba(5, 59, 125, 0.1);
        outline: none;
    }

    /* Input error state */
    input.input-error {
        border-color: #dc3545;
        background: #fff5f5;
        animation: shake 0.4s ease;
    }

    @keyframes shake {
        0%, 100% { transform: translateX(0); }
        20%, 60% { transform: translateX(-5px); }
        40%, 80% { transform: translateX(5px); }
    }

    /* Input success state */
    input.input-success {
        border-color: #28a745;
        background: #f0fff4;
    }

    /* Labels above inputs on mobile */
    .input-container {
        flex-direction: column;
        align-items: stretch;
    }

    .input-container label {
        margin-bottom: 8px;
        font-weight: 600;
        color: #333;
    }

    /* Better select styling */
    select {
        appearance: none;
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 15px center;
        padding-right: 40px;
    }
}

/* ============================================
   CALCULATOR BUTTON ENHANCEMENTS
   ============================================ */

@media (max-width: 768px) {
    .calculator-grid > button,
    #button-container button {
        position: relative;
        overflow: hidden;
        -webkit-tap-highlight-color: transparent;
    }

    /* Ripple effect on calculator buttons */
    .calculator-grid > button::before {
        content: '';
        position: absolute;
        top: 50%;
        left: 50%;
        width: 0;
        height: 0;
        background: rgba(255, 255, 255, 0.4);
        border-radius: 50%;
        transform: translate(-50%, -50%);
        transition: width 0.4s, height 0.4s;
    }

    .calculator-grid > button:active::before {
        width: 150%;
        height: 150%;
    }
}

/* ============================================
   MOBILE CARD SWIPE STYLES
   ============================================ */

.swipeable-card {
    position: relative;
    overflow: hidden;
    transition: transform 0.2s ease;
}

.swipeable-card.swiping {
    transition: none;
}

.swipe-action-left,
.swipe-action-right {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 20px;
}

.swipe-action-left {
    left: 0;
    background: #28a745;
}

.swipe-action-right {
    right: 0;
    background: #dc3545;
}

/* ============================================
   FLOATING ACTION BUTTON
   ============================================ */

.mobile-fab {
    display: none;
    position: fixed;
    bottom: calc(80px + env(safe-area-inset-bottom, 0));
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4ecdc4 0%, #44a08d 100%);
    color: white;
    font-size: 24px;
    border: none;
    box-shadow: 0 4px 20px rgba(78, 205, 196, 0.4);
    cursor: pointer;
    z-index: 9998;
    transition: all 0.3s ease;
    -webkit-tap-highlight-color: transparent;
}

.mobile-fab:active {
    transform: scale(0.9);
}

.mobile-fab i {
    transition: transform 0.3s ease;
}

.mobile-fab.expanded i {
    transform: rotate(45deg);
}

@media (max-width: 768px) {
    .mobile-fab {
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* ============================================
   SCROLL TO TOP BUTTON
   ============================================ */

.scroll-to-top {
    display: none;
    position: fixed;
    bottom: calc(140px + env(safe-area-inset-bottom, 0));
    right: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #053b7d;
    color: white;
    font-size: 18px;
    border: none;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    z-index: 9997;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
    -webkit-tap-highlight-color: transparent;
}

.scroll-to-top.visible {
    opacity: 1;
    transform: translateY(0);
}

.scroll-to-top:active {
    transform: scale(0.9);
}

@media (max-width: 768px) {
    .scroll-to-top {
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* ============================================
   SKELETON LOADING STATES
   ============================================ */

.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-text {
    height: 16px;
    margin-bottom: 8px;
}

.skeleton-button {
    height: 48px;
    border-radius: 8px;
}

.skeleton-card {
    height: 100px;
    border-radius: 12px;
}

/* ============================================
   TOAST NOTIFICATIONS MOBILE OPTIMIZED
   ============================================ */

.mobile-toast {
    position: fixed;
    bottom: calc(80px + env(safe-area-inset-bottom, 0));
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: #333;
    color: white;
    padding: 14px 24px;
    border-radius: 25px;
    font-size: 14px;
    font-weight: 500;
    z-index: 10002;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    max-width: calc(100vw - 40px);
    text-align: center;
}

.mobile-toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.mobile-toast.success {
    background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
}

.mobile-toast.error {
    background: linear-gradient(135deg, #dc3545 0%, #ff6b6b 100%);
}

.mobile-toast.warning {
    background: linear-gradient(135deg, #ffc107 0%, #fd7e14 100%);
    color: #333;
}

/* ============================================
   OFFLINE INDICATOR
   ============================================ */

.offline-indicator {
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    background: #dc3545;
    color: white;
    padding: 8px 15px;
    text-align: center;
    font-size: 13px;
    font-weight: 500;
    z-index: 9999;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
}

.offline-indicator.show {
    transform: translateY(0);
}

.offline-indicator i {
    margin-right: 8px;
}

/* ============================================
   SAFE AREA ADJUSTMENTS (iPhone notch)
   ============================================ */

@supports (padding: env(safe-area-inset-bottom)) {
    .mobile-bottom-nav {
        padding-bottom: env(safe-area-inset-bottom);
        height: calc(65px + env(safe-area-inset-bottom));
    }

    body {
        padding-bottom: calc(65px + env(safe-area-inset-bottom));
    }
}

/* ============================================
   LANDSCAPE MODE ADJUSTMENTS
   ============================================ */

@media (max-height: 500px) and (orientation: landscape) {
    .mobile-bottom-nav {
        height: 50px;
    }

    .mobile-nav-item {
        flex-direction: row;
        gap: 8px;
        padding: 6px 15px;
    }

    .mobile-nav-item i {
        margin-bottom: 0;
        font-size: 18px;
    }

    .mobile-nav-item span {
        font-size: 12px;
    }

    body {
        padding-bottom: 50px;
    }

    .scroll-to-top {
        bottom: 60px;
    }

    .mobile-fab {
        bottom: 60px;
        width: 48px;
        height: 48px;
    }
}

/* ============================================
   DARK MODE SUPPORT (future)
   ============================================ */

@media (prefers-color-scheme: dark) {
    .mobile-search-modal {
        background: #1a1a1a;
    }

    .mobile-search-result-item {
        border-color: #333;
        color: #fff;
    }

    .mobile-search-result-item:active {
        background: #2a2a2a;
    }

    .mobile-search-result-category {
        color: #aaa;
    }
}
