/**
 * OpsFlow PWA Mobile Styles
 * Mobile-optimized UI components, touch targets, and responsive enhancements
 */

/* ==================== Mobile Viewport Optimizations ==================== */

/* Prevent text size adjustment on iOS */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* Prevent zoom on input focus (iOS Safari) - Use 16px minimum font size */
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="tel"],
input[type="url"],
textarea,
select {
    font-size: 16px !important;
}

/* Smooth scrolling with momentum (iOS) */
body {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
}

/* ==================== Touch-Friendly Targets ==================== */

/* Minimum 44x44px touch targets (Apple HIG, Material Design) */
.mobile-touch-target,
.kt-btn,
button,
a.kt-btn,
[role="button"] {
    min-height: 44px;
    min-width: 44px;
}

/* Mobile button sizing */
@media (max-width: 768px) {
    .kt-btn-sm {
        min-height: 40px;
        padding: 0.5rem 1rem;
    }

    .kt-btn,
    .kt-btn-md {
        min-height: 44px;
        padding: 0.625rem 1.25rem;
    }

    .kt-btn-lg {
        min-height: 52px;
        padding: 0.875rem 1.5rem;
        font-size: 1rem;
    }
}

/* Tap highlight color */
* {
    -webkit-tap-highlight-color: rgba(59, 130, 246, 0.1);
}

/* Active state feedback for touch */
.mobile-touch-target:active,
button:active,
a:active {
    transform: scale(0.98);
    transition: transform 0.1s ease;
}

/* ==================== Mobile Navigation ==================== */

/* Bottom navigation bar for mobile */
.mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: var(--background);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

/* Add safe area inset for iOS notch */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .mobile-bottom-nav {
        padding-bottom: env(safe-area-inset-bottom);
        height: calc(60px + env(safe-area-inset-bottom));
    }
}

.mobile-bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 0.5rem;
    color: var(--muted-foreground);
    text-decoration: none;
    transition: color 0.2s ease;
    min-height: 44px;
}

.mobile-bottom-nav-item:active {
    background: var(--accent);
}

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

.mobile-bottom-nav-item i {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
}

.mobile-bottom-nav-item span {
    font-size: 0.75rem;
    font-weight: 500;
}

/* Hide desktop sidebar on mobile when bottom nav is shown */
@media (max-width: 768px) {
    body.mobile-nav-enabled .kt-sidebar {
        display: none;
    }

    body.mobile-nav-enabled .kt-app-main {
        padding-bottom: 60px;
    }

    body.mobile-nav-enabled .kt-app-main {
        padding-bottom: calc(60px + env(safe-area-inset-bottom));
    }
}

/* ==================== Mobile Header ==================== */

.mobile-header {
    position: sticky;
    top: 0;
    z-index: 999;
    background: var(--background);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

/* Safe area for iOS notch */
@supports (padding-top: env(safe-area-inset-top)) {
    .mobile-header {
        padding-top: calc(0.75rem + env(safe-area-inset-top));
    }
}

.mobile-header-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--foreground);
    margin: 0;
}

.mobile-menu-btn {
    background: none;
    border: none;
    padding: 0.5rem;
    color: var(--foreground);
    cursor: pointer;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ==================== Pull to Refresh ==================== */

.pull-to-refresh-container {
    position: relative;
    overflow: hidden;
}

.pull-to-refresh-indicator {
    position: absolute;
    top: -60px;
    left: 0;
    right: 0;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--background);
    transition: top 0.2s ease;
    z-index: 10;
}

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

.pull-to-refresh-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ==================== Mobile Cards ==================== */

/* Larger padding for mobile card taps */
@media (max-width: 768px) {
    .kt-card {
        padding: 1rem;
    }

    .kt-card-header {
        padding: 1rem;
        min-height: 44px;
    }

    .kt-card-content {
        padding: 1rem;
    }
}

/* Mobile card with swipe actions */
.mobile-card-swipeable {
    position: relative;
    overflow: hidden;
    touch-action: pan-y;
}

.mobile-card-content {
    transition: transform 0.2s ease;
}

.mobile-card-actions {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    display: flex;
    transform: translateX(100%);
}

.mobile-card-action {
    width: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    border: none;
    cursor: pointer;
}

.mobile-card-action-edit {
    background: var(--primary);
}

.mobile-card-action-delete {
    background: var(--destructive);
}

/* ==================== Offline Indicator ==================== */

.offline-indicator {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--warning);
    color: var(--warning-foreground);
    padding: 0.5rem 1rem;
    text-align: center;
    z-index: 9999;
    font-size: 0.875rem;
    font-weight: 500;
    display: none;
    animation: slideDown 0.3s ease;
}

@supports (padding-top: env(safe-area-inset-top)) {
    .offline-indicator {
        padding-top: calc(0.5rem + env(safe-area-inset-top));
    }
}

.offline-indicator.show {
    display: block;
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
    }
    to {
        transform: translateY(0);
    }
}

/* Sync status indicator */
.sync-status {
    position: fixed;
    bottom: 1rem;
    left: 1rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 9999px;
    padding: 0.5rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    z-index: 999;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
}

/* Mobile: move above bottom nav */
@media (max-width: 768px) {
    .sync-status {
        bottom: 70px;
    }

    @supports (bottom: calc(70px + env(safe-area-inset-bottom))) {
        .sync-status {
            bottom: calc(70px + env(safe-area-inset-bottom));
        }
    }
}

.sync-status.show {
    opacity: 1;
    transform: translateY(0);
}

.sync-status-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.sync-status-icon {
    font-size: 1rem;
}

.sync-status.syncing .sync-status-icon {
    color: var(--primary);
}

.sync-status.success .sync-status-icon {
    color: var(--success);
}

.sync-status.error .sync-status-icon {
    color: var(--destructive);
}

/* ==================== Install Prompt ==================== */

.pwa-install-prompt {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    left: auto;
    width: 100%;
    max-width: 400px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1rem;
    box-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    z-index: 1001;
    display: none;
    animation: slideUp 0.3s ease;
}

/* Mobile: full width at bottom */
@media (max-width: 768px) {
    .pwa-install-prompt {
        left: 1rem;
        right: 1rem;
        bottom: 70px;
        max-width: none;
    }

    @supports (bottom: calc(70px + env(safe-area-inset-bottom))) {
        .pwa-install-prompt {
            bottom: calc(70px + env(safe-area-inset-bottom));
        }
    }
}

.pwa-install-prompt.show {
    display: block;
}

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

.pwa-install-prompt-header {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.pwa-install-prompt-icon {
    width: 48px;
    height: 48px;
    border-radius: 0.5rem;
    object-fit: cover;
}

.pwa-install-prompt-content {
    flex: 1;
}

.pwa-install-prompt-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--foreground);
    margin: 0 0 0.25rem 0;
}

.pwa-install-prompt-text {
    font-size: 0.875rem;
    color: var(--muted-foreground);
    margin: 0;
}

.pwa-install-prompt-close {
    background: none;
    border: none;
    padding: 0.25rem;
    color: var(--muted-foreground);
    cursor: pointer;
    min-width: 32px;
    min-height: 32px;
}

.pwa-install-prompt-actions {
    display: flex;
    gap: 0.5rem;
}

.pwa-install-prompt-btn {
    flex: 1;
    padding: 0.625rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
    min-height: 44px;
}

.pwa-install-prompt-btn-primary {
    background: var(--primary);
    color: var(--primary-foreground);
}

.pwa-install-prompt-btn-primary:active {
    background: var(--primary-600);
}

.pwa-install-prompt-btn-secondary {
    background: var(--secondary);
    color: var(--secondary-foreground);
}

/* ==================== Mobile Form Enhancements ==================== */

/* Larger form inputs for mobile */
@media (max-width: 768px) {
    .kt-input,
    .kt-select,
    .kt-textarea {
        min-height: 44px;
        padding: 0.625rem 0.875rem;
        font-size: 16px; /* Prevent zoom on iOS */
    }

    .kt-textarea {
        min-height: 100px;
    }

    .kt-label {
        font-size: 0.875rem;
        margin-bottom: 0.5rem;
    }
}

/* Mobile modal adjustments */
@media (max-width: 768px) {
    .fixed.inset-0 > .relative {
        margin: 0;
        padding: 1rem;
    }

    .fixed.inset-0 .glass-strong,
    .fixed.inset-0 .kt-card {
        max-height: 90vh;
        overflow-y: auto;
    }
}

/* ==================== Utility Classes ==================== */

/* Hide on mobile */
@media (max-width: 768px) {
    .hide-mobile {
        display: none !important;
    }
}

/* Show only on mobile */
.show-mobile {
    display: none !important;
}

@media (max-width: 768px) {
    .show-mobile {
        display: block !important;
    }

    .show-mobile-flex {
        display: flex !important;
    }

    .show-mobile-inline {
        display: inline !important;
    }
}

/* Mobile spacing adjustments */
@media (max-width: 768px) {
    .mobile-p-4 {
        padding: 1rem;
    }

    .mobile-px-4 {
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .mobile-py-4 {
        padding-top: 1rem;
        padding-bottom: 1rem;
    }

    .mobile-mb-4 {
        margin-bottom: 1rem;
    }
}

/* ==================== Responsive Tables ==================== */

/* Scrollable tables on mobile */
@media (max-width: 768px) {
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table-responsive table {
        min-width: 100%;
    }
}

/* ==================== Loading States ==================== */

/* Skeleton loading for mobile */
.mobile-skeleton {
    background: linear-gradient(
        90deg,
        var(--muted) 0%,
        var(--muted-foreground/10) 50%,
        var(--muted) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 0.25rem;
}

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

/* ==================== Landscape Mode Adjustments ==================== */

/* Reduce header/footer height in landscape on phones */
@media (max-width: 768px) and (orientation: landscape) {
    .mobile-header {
        padding-top: 0.5rem;
        padding-bottom: 0.5rem;
    }

    .mobile-bottom-nav {
        height: 48px;
    }

    .mobile-bottom-nav-item span {
        display: none; /* Hide labels in landscape */
    }
}

/* ==================== Dark Mode Optimizations ==================== */

@media (prefers-color-scheme: dark) {
    .offline-indicator {
        background: #f59e0b;
        color: #1f2937;
    }
}
/* ==================== PWA Update Notification ==================== */

.pwa-update-notification {
    position: fixed;
    top: -200px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 2rem);
    max-width: 500px;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 1rem;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1);
    backdrop-filter: blur(10px);
    z-index: 2000;
    transition: top 0.3s ease;
    overflow: hidden;
}

.pwa-update-notification.show {
    top: 1rem;
}

.pwa-update-content {
    display: flex;
    align-items: center;
    padding: 1rem;
    gap: 1rem;
}

.pwa-update-icon {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(59, 130, 246, 0.1);
    border-radius: 12px;
}

.pwa-update-text {
    flex: 1;
}

.pwa-update-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--foreground);
    margin-bottom: 0.25rem;
}

.pwa-update-message {
    font-size: 0.875rem;
    color: var(--muted-foreground);
    margin: 0;
}

.pwa-update-actions {
    display: flex;
    gap: 0.5rem;
    padding: 0 1rem 1rem 1rem;
    justify-content: flex-end;
}

.pwa-update-btn {
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
}

.pwa-update-btn-primary {
    background: #3b82f6;
    color: white;
}

.pwa-update-btn-primary:hover {
    background: #2563eb;
}

.pwa-update-btn-secondary {
    background: transparent;
    color: var(--foreground);
    border: 1px solid var(--border);
}

.pwa-update-btn-secondary:hover {
    background: var(--muted);
}

@media (max-width: 640px) {
    .pwa-update-notification {
        width: calc(100% - 1rem);
        border-radius: 0.75rem;
    }

    .pwa-update-notification.show {
        top: 0.5rem;
    }

    .pwa-update-content {
        padding: 0.875rem;
    }

    .pwa-update-icon {
        width: 40px;
        height: 40px;
    }

    .pwa-update-title {
        font-size: 0.9375rem;
    }

    .pwa-update-message {
        font-size: 0.8125rem;
    }

    .pwa-update-actions {
        padding: 0 0.875rem 0.875rem 0.875rem;
    }
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
    .pwa-update-notification {
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
    }
}
