/**
 * Mobile-First CSS for RunMe Finance Tracker
 * Optimized for Capacitor mobile apps
 * Touch-friendly, responsive, and performant
 */

/* ============================================
   MOBILE APP DETECTION
   ============================================ */
.mobile-app-only {
    display: none;
}

.web-only {
    display: block;
}

body.is-mobile-app .mobile-app-only {
    display: block;
}

body.is-mobile-app .web-only {
    display: none;
}

/* ============================================
   SAFE AREAS & NOTCH SUPPORT
   ============================================ */
:root {
    --safe-area-inset-top: env(safe-area-inset-top);
    --safe-area-inset-right: env(safe-area-inset-right);
    --safe-area-inset-bottom: env(safe-area-inset-bottom);
    --safe-area-inset-left: env(safe-area-inset-left);
    /* Colors now use main design system tokens from tokens.css */
}

/* ============================================
   MOBILE APP LAYOUT
   ============================================ */
body.is-mobile-app {
    padding-top: var(--safe-area-inset-top);
    padding-bottom: calc(var(--safe-area-inset-bottom) + 60px); /* Bottom nav height */
    background-color: var(--color-background);
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* Allow text selection in inputs and textareas */
body.is-mobile-app input,
body.is-mobile-app textarea,
body.is-mobile-app select {
    -webkit-user-select: auto !important;
    user-select: auto !important;
    -webkit-touch-callout: default !important;
}

/* Container adjustments for mobile */
body.is-mobile-app .container {
    padding-left: max(15px, var(--safe-area-inset-left));
    padding-right: max(15px, var(--safe-area-inset-right));
    max-width: 100%;
}

/* ============================================
   TOUCH-FRIENDLY ELEMENTS
   ============================================ */

/* All buttons must be at least 44x44px */
.btn,
button,
.btn-mobile {
    min-height: 44px;
    min-width: 44px;
    padding: 12px 20px;
    font-size: 16px;
    font-weight: 500;
    border-radius: 10px;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

/* Active state for touch feedback */
.btn:active,
button:active {
    transform: scale(0.97);
    opacity: 0.8;
}

/* Input fields - larger for mobile */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="tel"],
select,
textarea {
    min-height: 50px;
    font-size: 16px; /* Prevents zoom on iOS */
    padding: 14px 16px;
    border-radius: 10px;
    border: 1px solid var(--color-border-strong);
    transition: border-color 0.2s ease;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--color-primary);
    outline: none;
    box-shadow: 0 0 0 3px var(--color-primary-bg, rgba(0, 122, 255, 0.1));
}

/* ============================================
   MOBILE NAVIGATION (BOTTOM TAB BAR)
   ============================================ */
.mobile-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(60px + var(--safe-area-inset-bottom));
    background: var(--color-surface);
    border-top: 1px solid var(--color-border-strong);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding-bottom: var(--safe-area-inset-bottom);
    z-index: 1000;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.mobile-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 60px;
    min-height: 44px;
    padding: 8px;
    text-decoration: none;
    color: var(--color-text-secondary);
    transition: color 0.2s ease;
    position: relative;
}

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

.mobile-nav-item i {
    font-size: 24px;
    margin-bottom: 4px;
}

.mobile-nav-item span {
    font-size: 11px;
    font-weight: 500;
}

.mobile-nav-item .badge {
    position: absolute;
    top: 4px;
    right: 16px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    font-size: 10px;
    line-height: 18px;
    border-radius: 9px;
    background: var(--color-danger);
    color: white;
}

/* ============================================
   MOBILE HEADER
   ============================================ */
.mobile-header {
    position: sticky;
    top: var(--safe-area-inset-top);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border-strong);
    padding: 12px 16px;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 56px;
}

.mobile-header h1 {
    font-size: 20px;
    font-weight: 600;
    margin: 0;
    color: var(--color-text-primary);
}

.mobile-header-actions {
    display: flex;
    gap: 8px;
}

.mobile-header-icon {
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: transparent;
    border: none;
    color: var(--color-text-primary);
    cursor: pointer;
}

.mobile-header-icon:active {
    background: var(--color-background);
}

/* ============================================
   CARD LAYOUT (Responsive Tables)
   ============================================ */
.mobile-card {
    background: var(--color-surface);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--color-border-strong);
}

.mobile-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.mobile-card-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--color-text-primary);
    margin: 0;
}

.mobile-card-body {
    font-size: 14px;
    color: var(--color-text-secondary);
}

/* Transaction card */
.transaction-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: var(--color-surface);
    border-radius: 10px;
    margin-bottom: 8px;
    border: 1px solid var(--color-border-strong);
}

.transaction-card-icon {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.transaction-card-icon.income {
    background: var(--color-success-bg, rgba(52, 199, 89, 0.1));
    color: var(--color-success);
}

.transaction-card-icon.expense {
    background: var(--color-danger-bg, rgba(255, 59, 48, 0.1));
    color: var(--color-danger);
}

.transaction-card-content {
    flex: 1;
    min-width: 0;
}

.transaction-card-title {
    font-size: 15px;
    font-weight: 500;
    color: var(--color-text-primary);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.transaction-card-meta {
    font-size: 13px;
    color: var(--color-text-secondary);
    margin-top: 2px;
}

.transaction-card-amount {
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
}

.transaction-card-amount.income {
    color: var(--color-success);
}

.transaction-card-amount.expense {
    color: var(--color-danger);
}

/* ============================================
   SWIPEABLE ACTIONS
   ============================================ */
.swipeable-item {
    position: relative;
    overflow: hidden;
    touch-action: pan-y;
}

.swipe-actions {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    display: flex;
    transform: translateX(100%);
    transition: transform 0.3s ease;
}

.swipe-action {
    width: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 20px;
    cursor: pointer;
}

.swipe-action.delete {
    background: var(--color-danger);
}

.swipe-action.edit {
    background: var(--color-primary);
}

/* ============================================
   BOTTOM SHEET MODAL
   ============================================ */
.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--color-surface);
    border-radius: 20px 20px 0 0;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    z-index: 1050;
    max-height: 90vh;
    overflow-y: auto;
    padding-bottom: var(--safe-area-inset-bottom);
}

.bottom-sheet.show {
    transform: translateY(0);
}

.bottom-sheet-handle {
    width: 40px;
    height: 4px;
    background: var(--color-border-strong);
    border-radius: 2px;
    margin: 12px auto 16px;
}

.bottom-sheet-content {
    padding: 0 20px 20px;
}

.bottom-sheet-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease;
    z-index: 1049;
}

.bottom-sheet-backdrop.show {
    opacity: 1;
    visibility: visible;
}

/* ============================================
   LOADING SKELETON
   ============================================ */
.skeleton {
    background: linear-gradient(90deg, var(--color-gray-100, #f0f0f0) 25%, var(--color-gray-200, #e0e0e0) 50%, var(--color-gray-100, #f0f0f0) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: var(--radius-md, 8px);
}

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

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

.skeleton-title {
    height: 24px;
    width: 60%;
    margin-bottom: 12px;
}

.skeleton-card {
    height: 100px;
    margin-bottom: 12px;
}

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */
.toast-container-mobile {
    position: fixed;
    top: calc(var(--safe-area-inset-top) + 16px);
    left: 16px;
    right: 16px;
    z-index: 1100;
}

.toast-mobile {
    background: var(--color-surface);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: toast-slide-in 0.3s ease;
}

@keyframes toast-slide-in {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.toast-mobile.success {
    border-left: 4px solid var(--color-success);
}

.toast-mobile.error {
    border-left: 4px solid var(--color-danger);
}

.toast-mobile.warning {
    border-left: 4px solid var(--color-warning);
}

/* ============================================
   PROGRESS BARS
   ============================================ */
.mobile-progress {
    height: 8px;
    background: var(--color-background);
    border-radius: 4px;
    overflow: hidden;
    margin: 8px 0;
}

.mobile-progress-bar {
    height: 100%;
    background: var(--color-primary);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.mobile-progress-bar.success {
    background: var(--color-success);
}

.mobile-progress-bar.warning {
    background: var(--color-warning);
}

.mobile-progress-bar.danger {
    background: var(--color-danger);
}

/* ============================================
   PULL TO REFRESH
   ============================================ */
.pull-to-refresh {
    position: relative;
}

.pull-to-refresh-indicator {
    position: absolute;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: top 0.3s ease;
}

.pull-to-refresh.pulling .pull-to-refresh-indicator {
    top: 0;
}

/* ============================================
   OFFLINE INDICATOR
   ============================================ */
.offline-banner {
    position: fixed;
    top: var(--safe-area-inset-top);
    left: 0;
    right: 0;
    background: var(--color-warning);
    color: white;
    padding: 12px 16px;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    z-index: 1000;
    transform: translateY(-100%);
    transition: transform 0.3s ease;
}

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

/* ============================================
   RESPONSIVE UTILITIES
   ============================================ */
@media (max-width: 768px) {
    /* Hide desktop elements on mobile */
    .desktop-only {
        display: none !important;
    }

    /* Full-width cards */
    .card {
        border-radius: 12px;
        margin-bottom: 12px;
    }

    /* Stack form fields */
    .row {
        flex-direction: column;
    }

    .col,
    .col-md-6,
    .col-lg-4 {
        width: 100%;
        margin-bottom: 12px;
    }
}

/* ============================================
   DARK MODE SUPPORT
   ============================================ */
/* REMOVED: Auto dark mode detection - now controlled by dark-mode.js
   Dark mode styles are in dark-mode.css with body.dark-mode class */

/* ============================================
   ACCESSIBILITY
   ============================================ */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Focus visible for keyboard navigation */
*:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}
