/**
 * Duitly PWA — Apple Finance UI Polish
 * Layered enhancement — does NOT override existing styles.
 * Adds native-feel behaviors for standalone/PWA mode.
 */

/* ──────── Safe Area (Dynamic Island, Notch, Home Indicator) ──────── */
:root {
    --sat: env(safe-area-inset-top, 0px);
    --sar: env(safe-area-inset-right, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px);
}

/* Apply safe area only in standalone mode */
@media all and (display-mode: standalone) {
    body {
        padding-top: var(--sat);
        padding-right: var(--sar);
        padding-bottom: var(--sab);
        padding-left: var(--sal);
    }
}

/* ──────── Scroll & Touch Feel ──────── */
* {
    -webkit-overflow-scrolling: touch;
    -webkit-tap-highlight-color: transparent;
}

/* Prevent text selection on navigation elements in standalone */
@media all and (display-mode: standalone) {
    nav, aside, header, button, [role="button"],
    .fin-nav-link, [x-data] button {
        -webkit-user-select: none;
        user-select: none;
    }
}

/* Pull-to-refresh prevention in standalone (avoid accidental nav) */
@media all and (display-mode: standalone) {
    html { overscroll-behavior-y: contain; }
}

/* ──────── Haptic-feel Button Press ──────── */
button:active,
[role="button"]:active,
a.fin-nav-link:active,
a[href]:active:not(main a[href]) {
    transform: scale(0.97);
    opacity: 0.85;
    transition: transform 0.08s ease, opacity 0.08s ease;
}

/* Links inside main content area should NOT scale (reading context) */
main .prose a:active,
main p a:active {
    transform: none;
    opacity: 1;
}

/* ──────── Apple Spring Animations ──────── */
@keyframes appleSlideUp {
    from { transform: translateY(20px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
}

@keyframes appleFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes appleScaleIn {
    from { transform: scale(0.95); opacity: 0; }
    to   { transform: scale(1);    opacity: 1; }
}

/* Apply slide-up to main content area on page load */
@media all and (display-mode: standalone) {
    main > div > .p-4,
    main > div > .sm\:p-6 {
        animation: appleSlideUp 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
    }
}

/* ──────── Standalone Status Bar ──────── */
@media all and (display-mode: standalone) {
    /* Extend header to cover status bar area */
    header.sticky {
        padding-top: var(--sat);
    }

    /* Ensure sidebar extends behind status bar on mobile */
    aside.fixed {
        padding-top: var(--sat);
    }
}

/* ──────── Card Glass Effect (subtle, non-breaking) ──────── */
@media all and (display-mode: standalone) {
    .bg-fin-shell\/95 {
        backdrop-filter: blur(20px) saturate(180%);
        -webkit-backdrop-filter: blur(20px) saturate(180%);
    }
}

/* ──────── Bottom FAB safe area offset ──────── */
@media all and (display-mode: standalone) {
    .fixed.bottom-6.right-6 {
        bottom: calc(1.5rem + var(--sab));
    }
}

/* ──────── Install Banner Styles ──────── */
.pwa-install-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 9999;
    padding: 12px 16px;
    padding-bottom: calc(12px + var(--sab));
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border-top: 1px solid rgba(220, 227, 237, 0.8);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: appleSlideUp 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
    font-family: 'Plus Jakarta Sans', -apple-system, 'SF Pro Display', BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
}

.pwa-install-banner__icon {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: #1D66F6;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pwa-install-banner__icon svg {
    width: 22px;
    height: 22px;
    color: white;
}

.pwa-install-banner__text {
    flex: 1;
    min-width: 0;
}

.pwa-install-banner__title {
    font-size: 14px;
    font-weight: 600;
    color: #141A26;
    line-height: 1.3;
}

.pwa-install-banner__subtitle {
    font-size: 11px;
    color: #677489;
    line-height: 1.3;
    margin-top: 1px;
}

.pwa-install-banner__btn {
    flex-shrink: 0;
    padding: 8px 18px;
    border-radius: 100px;
    background: #1D66F6;
    color: white;
    font-size: 13px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: background 0.15s ease;
}

.pwa-install-banner__btn:hover {
    background: #0A43BE;
}

.pwa-install-banner__close {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #EEF2F7;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #677489;
    transition: background 0.15s ease;
}

.pwa-install-banner__close:hover {
    background: #DCE3ED;
}

/* Hide banner when already in standalone mode */
@media all and (display-mode: standalone) {
    .pwa-install-banner { display: none !important; }
}

/* ──────── Mobile Bottom Navigation Bar ──────── */
.fin-pill-tab {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    min-width: 0;
    padding: 0;
    color: #6B7280;
    text-decoration: none;
    -webkit-user-select: none;
    user-select: none;
    border: none;
    background: none;
    cursor: pointer;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
}

.fin-pill-tab-inner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 8px 10px;
    border-radius: 16px;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
}

.fin-pill-tab-inner span {
    font-size: 11px;
    font-weight: 600;
    line-height: 1;
    display: none;
}

.fin-pill-tab.active .fin-pill-tab-inner {
    background: #1A1A1A;
    color: #FFFFFF;
    padding: 8px 14px;
}

.fin-pill-tab.active .fin-pill-tab-inner span {
    display: inline;
}

/* Prevent haptic scale on bottom nav items */
.fin-pill-tab:active {
    transform: none !important;
    opacity: 1 !important;
}

/* ──────── Bottom Sheet Items ──────── */
.fin-sheet-up {
    animation: finSheetSlideUp 0.3s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes finSheetSlideUp {
    from { transform: translateY(30%); opacity: 0; }
    to   { transform: translateY(0);   opacity: 1; }
}

.fin-sheet-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 8px 4px;
    border-radius: 14px;
    text-decoration: none;
    color: #141A26;
    transition: background 0.1s ease, transform 0.1s ease;
}

.fin-sheet-item:active {
    background: #F0F3F7;
    transform: scale(0.95);
}

.fin-sheet-item span {
    font-size: 10px;
    font-weight: 600;
    line-height: 1.2;
    text-align: center;
}

.fin-sheet-icon {
    width: 44px;
    height: 44px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ──────── Mobile Content Enhancements ──────── */
@media (max-width: 1023px) {
    /* Edge-to-edge cards on mobile */
    .rounded-soft {
        border-radius: 16px;
    }

    /* Smoother scroll for main content */
    main {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }

    /* Make tables more touch-friendly */
    table td, table th {
        padding-top: 12px;
        padding-bottom: 12px;
    }

    /* Larger touch targets for action buttons */
    table .flex.gap-1 a,
    table .flex.gap-1 button {
        min-width: 36px;
        min-height: 36px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}

/* ──────── Standalone Mode: Bottom Nav Safe Area ──────── */
@media all and (display-mode: standalone) {
    .fin-pill-nav {
        margin-bottom: var(--sab) !important;
    }
}

/* ──────── Mobile-first: Hide scrollbar on touch ──────── */
@media (max-width: 1023px) {
    ::-webkit-scrollbar { width: 0; height: 0; }
    * { scrollbar-width: none; }
}

/* ──────── Dashboard Quick Action Grid ──────── */
.fin-quick-action {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 4px;
    text-decoration: none;
    color: #141A26;
    border-radius: 12px;
    transition: background 0.1s ease, transform 0.1s ease;
}

.fin-quick-action:active {
    background: #F0F3F7;
    transform: scale(0.95);
}

.fin-quick-action span {
    font-size: 10px;
    font-weight: 600;
    line-height: 1.2;
    text-align: center;
    color: #3D4A5C;
}

.fin-qa-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ──────── Mobile Hero Balance Card ──────── */
.fin-hero-card {
    border-radius: 20px;
    position: relative;
    overflow: hidden;
}

.fin-hero-card::after {
    content: '';
    position: absolute;
    top: -60%;
    right: -30%;
    width: 200px;
    height: 200px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.06);
    pointer-events: none;
}

/* ──────── Mobile Period Pill Selector ──────── */
.fin-period-pill {
    padding: 4px 14px;
    border-radius: 100px;
    font-size: 11px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    color: rgba(255, 255, 255, 0.65);
    background: rgba(255, 255, 255, 0.12);
}

.fin-period-pill.active,
.fin-period-pill:active {
    color: #1D66F6;
    background: #fff;
}

/* ──────── Mobile Metric Pill (horizontal scroll) ──────── */
.fin-metric-pill {
    flex: 0 0 auto;
    min-width: 120px;
    padding: 12px 14px;
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.fin-metric-pill .metric-label {
    font-size: 9px;
    font-weight: 500;
    color: #677489;
    line-height: 1.2;
}

.fin-metric-pill .metric-value {
    font-size: 14px;
    font-weight: 700;
    color: #141A26;
    line-height: 1.3;
    margin-top: 2px;
}

/* ──────── Mobile Transaction Item ──────── */
.fin-txn-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid #F0F3F7;
}

.fin-txn-item:last-child {
    border-bottom: none;
}

.fin-txn-icon {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ──────── Mobile Stats Card ──────── */
.fin-stat-card {
    border-radius: 16px;
    background: #fff;
    padding: 14px 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.fin-stat-card .stat-label {
    font-size: 10px;
    font-weight: 500;
    color: #677489;
}

.fin-stat-card .stat-value {
    font-size: 15px;
    font-weight: 700;
    color: #141A26;
    margin-top: 2px;
}

.fin-stat-card .stat-change {
    font-size: 9px;
    font-weight: 600;
    margin-top: 3px;
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 1px 5px;
    border-radius: 5px;
}

/* ──────── Standalone Bottom Nav safe-area ──────── */
@media all and (display-mode: standalone) {
    .fin-pill-tab.active .fin-pill-tab-inner span {
        padding-bottom: 0;
    }
}

/* ──────── Smooth Page Transitions ──────── */
@media (max-width: 1023px) {
    @keyframes mobilePageIn {
        from { opacity: 0; transform: translateY(8px); }
        to   { opacity: 1; transform: translateY(0); }
    }

    main > div {
        animation: mobilePageIn 0.25s cubic-bezier(0.22, 1, 0.36, 1) both;
    }
}

/* ──────── Mobile Form & Card Polish ──────── */
@media (max-width: 1023px) {
    /* Softer card borders on mobile for cleaner visual */
    .rounded-xl {
        border-color: #EBEBF0;
    }

    /* Form inputs: larger touch targets */
    input[type="text"],
    input[type="number"],
    input[type="date"],
    input[type="email"],
    input[type="password"],
    select,
    textarea {
        font-size: 16px !important; /* Prevents iOS auto-zoom */
        min-height: 44px;
    }

    /* More compact card padding on mobile */
    .rounded-xl.border.bg-white.p-5 {
        padding: 16px;
    }

    /* Stat cards: tighter on mobile for 2x2 grid */
    .rounded-xl.border.bg-white.p-4 {
        padding: 12px;
    }

    /* Summary numbers smaller on mobile stat cards */
    .grid-cols-2 .text-\[24px\] {
        font-size: 18px;
    }

    /* Debt show: payment form button full width */
    .grid.gap-4.lg\\:grid-cols-2 button[type="submit"] {
        width: 100%;
    }
}
