/* Ventora POS — iOS PWA Stylesheet
 * Loaded on every page. Targets:
 *  - <html class="is-ios">           — iPhone/iPad Safari
 *  - <html class="is-standalone">    — running as installed PWA (iOS or Android)
 *  - <html class="is-offline">       — no network connection
 *  - .pwa-install-btn                — install trigger button
 *  - .pwa-ios-modal-backdrop / .pwa-ios-modal — install instructions popup
 *
 * Critical iOS fixes:
 *  1. Safe-area insets (notch / Dynamic Island / home indicator)
 *  2. Prevent input auto-zoom (font-size must be ≥ 16px)
 *  3. Disable text-size-adjust quirks
 *  4. Smooth momentum scrolling
 *  5. Disable tap-highlight rectangle
 */

/* ─────────────────────────────────────────────────────────────────────────
 * 1. Safe area insets (iPhone X+ notch, Dynamic Island, home indicator)
 * ───────────────────────────────────────────────────────────────────────── */
html.is-standalone body {
    padding-top: env(safe-area-inset-top, 0);
    padding-right: env(safe-area-inset-right, 0);
    padding-bottom: env(safe-area-inset-bottom, 0);
    padding-left: env(safe-area-inset-left, 0);
}

/* If you have a fixed top bar / sticky header, push it down by safe-area-inset-top.
   Adjust selectors here to match your actual header. */
html.is-standalone .main-header,
html.is-standalone .v-top-header,
html.is-standalone .v-pos-toolbar,
html.is-standalone .pos__toolbar {
    padding-top: calc(env(safe-area-inset-top, 0) + 8px) !important;
}

/* If you have a bottom bar, lift it above the home indicator */
html.is-standalone .ai-chat-fab,
html.is-standalone .pwa-install-btn-fixed {
    bottom: calc(env(safe-area-inset-bottom, 16px) + 16px) !important;
}

/* ─────────────────────────────────────────────────────────────────────────
 * 2. Prevent iOS input auto-zoom (font-size MUST be at least 16px)
 * ───────────────────────────────────────────────────────────────────────── */
html.is-ios input[type="text"],
html.is-ios input[type="email"],
html.is-ios input[type="password"],
html.is-ios input[type="number"],
html.is-ios input[type="tel"],
html.is-ios input[type="url"],
html.is-ios input[type="search"],
html.is-ios input[type="date"],
html.is-ios input[type="datetime-local"],
html.is-ios input[type="time"],
html.is-ios textarea,
html.is-ios select {
    font-size: 16px !important;
}

/* ─────────────────────────────────────────────────────────────────────────
 * 3. iOS quirks — text-size-adjust, smooth scrolling, no tap highlight
 * ───────────────────────────────────────────────────────────────────────── */
html.is-ios {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

html.is-ios body {
    -webkit-overflow-scrolling: touch;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: contain;
}

html.is-ios button,
html.is-ios a,
html.is-ios .ai-chip,
html.is-ios .v-icon-btn,
html.is-ios .pwa-install-btn {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    -webkit-touch-callout: none;
}

/* Disable iOS long-press menu on app images & icons (but keep on content images) */
html.is-standalone .ai-chat-avatar img,
html.is-standalone .v-app-logo img,
html.is-standalone iconify-icon {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
}

/* ─────────────────────────────────────────────────────────────────────────
 * 4. Standalone-mode tweaks (when installed as PWA)
 *    Hide elements that don't make sense outside a browser tab
 * ───────────────────────────────────────────────────────────────────────── */
html.is-standalone .hide-when-installed,
html.is-standalone .pwa-install-btn {
    display: none !important;
}

/* Disable pull-to-refresh on iOS standalone — common request from users */
html.is-standalone body {
    overscroll-behavior: none;
}

/* ─────────────────────────────────────────────────────────────────────────
 * 5. PWA Install Button (floating, bottom-right by default)
 * ───────────────────────────────────────────────────────────────────────── */
.pwa-install-btn {
    display: none;
    position: fixed;
    bottom: 24px;
    left: 24px;
    z-index: 9998;
    background: #1e1b4b;
    color: #fff;
    border: none;
    padding: 12px 20px;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 10px 28px rgba(30, 27, 75, 0.35);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
    font-family: inherit;
    line-height: 1.2;
    min-height: 44px;
    /* Above iOS home indicator */
    margin-bottom: env(safe-area-inset-bottom, 0);
}

.pwa-install-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 32px rgba(30, 27, 75, 0.45);
}

.pwa-install-btn:active {
    transform: translateY(0);
}

.pwa-install-btn iconify-icon {
    margin-right: 6px;
    vertical-align: middle;
    font-size: 16px;
}

/* ─────────────────────────────────────────────────────────────────────────
 * 6. iOS Install Instructions Modal
 * ───────────────────────────────────────────────────────────────────────── */
.pwa-ios-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 99999;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.22s ease;
    padding: 20px;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0));
}

.pwa-ios-modal-backdrop.show {
    opacity: 1;
}

.pwa-ios-modal {
    background: #fff;
    color: #1e293b;
    border-radius: 24px 24px 24px 24px;
    padding: 28px 24px 24px;
    max-width: 420px;
    width: 100%;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
    transform: translateY(20px);
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
    position: relative;
    -webkit-overflow-scrolling: touch;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.pwa-ios-modal-backdrop.show .pwa-ios-modal {
    transform: translateY(0);
}

@media (min-width: 600px) {
    .pwa-ios-modal-backdrop {
        align-items: center;
    }
    .pwa-ios-modal {
        border-radius: 24px;
    }
}

.pwa-ios-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: #f1f5f9;
    color: #64748b;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-appearance: none;
    appearance: none;
    transition: background 0.15s ease, color 0.15s ease;
    font-family: inherit;
}

.pwa-ios-close:hover {
    background: #e2e8f0;
    color: #1e293b;
}

.pwa-ios-icon {
    width: 80px;
    height: 80px;
    border-radius: 20px;
    background: linear-gradient(135deg, #1e1b4b 0%, #312e81 100%);
    margin: 0 auto 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    box-shadow: 0 8px 20px rgba(30, 27, 75, 0.25);
}

.pwa-ios-icon img {
    width: 60px;
    height: 60px;
    border-radius: 14px;
}

.pwa-ios-modal h2 {
    font-size: 22px;
    font-weight: 700;
    margin: 0 0 6px;
    text-align: center;
    letter-spacing: -0.3px;
    color: #0f172a;
}

.pwa-ios-sub {
    color: #64748b;
    font-size: 14px;
    margin: 0 0 18px;
    text-align: center;
    line-height: 1.5;
}

.pwa-ios-warning {
    background: #fef3c7;
    border: 1px solid #fcd34d;
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 18px;
    font-size: 13px;
    line-height: 1.5;
    color: #92400e;
}

.pwa-ios-warning strong {
    display: block;
    margin-bottom: 4px;
    color: #78350f;
}

.pwa-ios-steps {
    list-style: none;
    padding: 0;
    margin: 0 0 22px;
}

.pwa-ios-steps li {
    display: flex;
    gap: 14px;
    padding: 12px 0;
    border-bottom: 1px solid #f1f5f9;
}

.pwa-ios-steps li:last-child {
    border-bottom: 0;
}

.pwa-ios-num {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #1e1b4b;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
}

.pwa-ios-steps li > div {
    flex: 1;
    min-width: 0;
}

.pwa-ios-steps strong {
    display: block;
    font-weight: 600;
    color: #0f172a;
    font-size: 15px;
    margin-bottom: 2px;
}

.pwa-ios-steps span {
    display: block;
    font-size: 13px;
    color: #64748b;
    line-height: 1.5;
}

.pwa-ios-ok {
    width: 100%;
    padding: 14px;
    background: #1e1b4b;
    color: #fff;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease;
    -webkit-appearance: none;
    appearance: none;
    min-height: 48px;
    font-family: inherit;
}

.pwa-ios-ok:hover {
    background: #312e81;
    transform: translateY(-1px);
}

.pwa-ios-ok:active {
    transform: translateY(0);
}

/* ─────────────────────────────────────────────────────────────────────────
 * 7. Offline indicator (top banner when network drops)
 * ───────────────────────────────────────────────────────────────────────── */
html.is-offline body::before {
    content: 'Offline — some features may not work';
    display: block;
    background: #ef4444;
    color: #fff;
    text-align: center;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 600;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 99999;
    padding-top: calc(6px + env(safe-area-inset-top, 0));
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

html.is-offline body {
    padding-top: calc(28px + env(safe-area-inset-top, 0)) !important;
}
