/*
 * Financial Planner - mobile / app-shell layer.
 *
 * Loaded after app.min.css. Desktop is left alone: everything that changes
 * layout is scoped to a max-width media query. The goal on phones is that the
 * page reads as an installed app rather than a shrunken dashboard:
 * a bottom tab bar, native-feeling taps, and no accidental browser zoom.
 *
 * Breakpoints follow the Bootstrap/theme scale already in use:
 *   <= 767.98px  phone   -> bottom tab bar, stacked lists
 *   <= 1024px    tablet  -> theme already collapses the sidebar here
 */

/* ---------------------------------------------------------------- *
 * 1. App-like touch behaviour (all touch devices)
 * ---------------------------------------------------------------- */

/* Kill the grey flash on tap; we supply our own :active states instead. */
a, button, .nav-link, .nav-icon, .btn, .fp-tab {
    -webkit-tap-highlight-color: transparent;
}

/* Chrome/Safari on iOS zoom the page when a focused input is under 16px.
   The theme's controls are 13px, so pin the *font-size only* to 16px and let
   the theme keep its own padding/height.
   The comma is an OR: phone-width screens, plus any touch device (tablets,
   touch laptops) whatever their width. */
@media (max-width: 767.98px), (hover: none) and (pointer: coarse) {
    .form-control,
    .form-select,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    input[type="number"],
    textarea,
    select {
        font-size: 16px;
    }
}

/* Chrome/Android address-bar resize causes 100vh jumps. Use the dynamic
   viewport unit where supported. */
@supports (height: 100dvh) {
    .vh-100 {
        height: 100dvh !important;
    }
}

/* ---------------------------------------------------------------- *
 * 2. Standalone (installed) PWA - respect the notch / home indicator
 * ---------------------------------------------------------------- */

/* viewport-fit=cover lets us paint under the status bar, so we owe the
   content the inset back. */
.topbar {
    padding-top: env(safe-area-inset-top, 0px);
}

.startbar {
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

@media (display-mode: standalone) {
    /* No browser chrome to bounce against, so stop the whole page from
       rubber-banding; inner scrollers still scroll normally. */
    body {
        overscroll-behavior-y: contain;
    }
}

/* ---------------------------------------------------------------- *
 * 3. Phone layout
 * ---------------------------------------------------------------- */

@media (max-width: 767.98px) {

    /* --- 3a. Tap targets ------------------------------------------------
       The theme's topbar icons are 36x36. Anything a thumb has to hit gets
       at least 44x44 (Apple HIG / WCAG 2.5.5 target size). Padding grows the
       hit area without changing the visual icon size. */
    .topbar .nav-icon,
    .topbar .mobile-menu-btn {
        min-width: 44px;
        min-height: 44px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .startbar .navbar-nav .nav-link {
        min-height: 44px;
        display: flex;
        align-items: center;
    }

    /* Text links on the auth screens (Forgot password, Create Account, Log In)
       are single-line text, so they'd otherwise be ~19px tall. */
    .auth-link {
        display: inline-flex;
        align-items: center;
        min-height: 44px;
    }

    /* --- 3b. Breathing room --------------------------------------------
       Tighten the desktop gutters so cards get more of a 375px screen. */
    .page-content .container-fluid {
        padding-left: 12px;
        padding-right: 12px;
    }

    .card {
        margin-bottom: 12px;
        border-radius: 12px;
    }

    .card-body {
        padding: 16px;
    }

    /* The breadcrumb duplicates the page title on a phone - drop it. */
    .page-title-box .breadcrumb {
        display: none;
    }

    .page-title-box {
        padding: 12px 0;
    }

    /* --- 3c. Room for the bottom tab bar --------------------------------
       Tab bar height (60px) + the iPhone home indicator. Without this the
       last card sits under the bar and can't be scrolled into view. */
    .page-wrapper .page-content {
        padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px) + 12px);
    }

    /* The footer is desktop chrome; the tab bar replaces it. */
    .footer {
        display: none;
    }
}

/* ---------------------------------------------------------------- *
 * 4. Bottom tab bar - the main "feels like an app" element
 * ---------------------------------------------------------------- */

.fp-tabbar {
    display: none; /* phone-only; enabled in the media query below */
}

@media (max-width: 767.98px) {
    .fp-tabbar {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 1030; /* above content, below the sidebar overlay (1040+) */
        height: calc(60px + env(safe-area-inset-bottom, 0px));
        padding-bottom: env(safe-area-inset-bottom, 0px);
        background: var(--bs-body-bg, #fff);
        border-top: 1px solid var(--bs-border-color, #e3ebf6);
        /* Frosted-glass bar, the way native tab bars read. */
        backdrop-filter: saturate(180%) blur(12px);
        -webkit-backdrop-filter: saturate(180%) blur(12px);
    }

    .fp-tab {
        flex: 1 1 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        min-height: 60px;
        padding: 6px 2px;
        text-decoration: none;
        color: var(--bs-secondary-color, #8a97ab);
        font-size: 10px;
        font-weight: 500;
        line-height: 1;
        transition: color .15s ease, transform .1s ease;
        /* Stop the label being selected on a long-press. */
        -webkit-user-select: none;
        user-select: none;
    }

    .fp-tab i {
        font-size: 21px;
        line-height: 1;
    }

    .fp-tab.active {
        color: var(--bs-primary, #556ee6);
    }

    /* Press feedback - the small dip a native tab gives you. */
    .fp-tab:active {
        transform: scale(0.92);
    }

    .fp-tab-label {
        display: block;
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* ---------------------------------------------------------------- *
 * 5. Transactions: table on desktop, stacked rows on a phone
 * ---------------------------------------------------------------- *
 * A 4-column table overflows 375px and forces a sideways scroll, which is
 * the clearest "this is a website" tell. Same markup, re-laid out with
 * grid so no JS branch and no duplicate DOM is needed.
 */

@media (max-width: 767.98px) {
    .fp-txn-table thead {
        display: none;
    }

    .fp-txn-table,
    .fp-txn-table tbody,
    .fp-txn-table tr,
    .fp-txn-table td {
        display: block;
        width: 100%;
    }

    /* Description on line 1, date + type on line 2, amount right-aligned
       across both lines. */
    .fp-txn-table tr {
        display: grid;
        grid-template-columns: auto auto 1fr auto;
        grid-template-areas:
            "name name name amount"
            "date type .    amount";
        align-items: center;
        gap: 3px 8px;
        padding: 12px 0;
        border-bottom: 1px solid var(--bs-border-color, #e3ebf6);
    }

    .fp-txn-table tr:last-child {
        border-bottom: 0;
    }

    /* Reset the theme's cell borders/padding now that cells are blocks. */
    .fp-txn-table td {
        border: 0;
        padding: 0;
        width: auto;
    }

    .fp-txn-table .txn-name {
        grid-area: name;
        /* Long fund names must ellipsis, not widen the grid. */
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .fp-txn-table .txn-date {
        grid-area: date;
        font-size: 12px;
    }

    .fp-txn-table .txn-type {
        grid-area: type;
    }

    .fp-txn-table .txn-amount {
        grid-area: amount;
        text-align: right;
        white-space: nowrap;
    }

    /* An empty-state row spans the whole grid instead of landing in "name". */
    .fp-txn-table td[colspan] {
        grid-column: 1 / -1;
    }

    /* Nothing to scroll sideways any more. */
    .fp-txn-wrap {
        overflow-x: visible;
    }
}

/* ---------------------------------------------------------------- *
 * 6. The 7-step journey strip (planner/_steps.html)
 * ---------------------------------------------------------------- *
 * Desktop: all 7 across the card, labels visible.
 * Phone:   scrolls sideways - 7 labels cannot fit 375px, and stacking
 *          them would push the actual form off the screen.
 */

.fp-steps {
    gap: 0;
    overflow-x: auto;
    /* Only this strip scrolls; the page must not. */
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    scroll-behavior: smooth;
}

.fp-steps::-webkit-scrollbar {
    display: none;
}

/* The scrollbar is hidden, so the only clue that steps 4-7 exist is a fade on
   whichever edge still has content behind it. Toggled by the script in
   planner/_steps.html, which also scrolls the current step into view. */
.fp-steps-wrap {
    position: relative;
}

.fp-steps-wrap::before,
.fp-steps-wrap::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 24px;
    pointer-events: none;    /* must never eat a tap meant for a step */
    opacity: 0;
    transition: opacity .15s ease;
    z-index: 2;
}

.fp-steps-wrap::before {
    left: 0;
    background: linear-gradient(to right,
        var(--bs-card-bg, #fff), rgba(255, 255, 255, 0));
}

.fp-steps-wrap::after {
    right: 0;
    background: linear-gradient(to left,
        var(--bs-card-bg, #fff), rgba(255, 255, 255, 0));
}

.fp-steps-wrap.fade-start::before,
.fp-steps-wrap.fade-end::after {
    opacity: 1;
}

.fp-step {
    flex: 1 1 0;
    min-width: 84px;      /* below this the label is unreadable, so scroll instead */
    position: relative;
    text-align: center;
}

/* The connector line between dots. Drawn behind, hence z-index on the dot. */
.fp-step:not(:last-child)::after {
    content: '';
    position: absolute;
    top: 15px;
    left: 50%;
    width: 100%;
    height: 2px;
    background: var(--bs-border-color, #e3ebf6);
}

.fp-step.done:not(:last-child)::after {
    background: var(--bs-primary, #8A38F5);
}

.fp-step > a {
    display: block;
    text-decoration: none;
    padding: 4px 2px;
    -webkit-tap-highlight-color: transparent;
}

.fp-step-dot {
    position: relative;
    z-index: 1;           /* sit on top of the connector */
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    margin: 0 auto 4px;
    border-radius: 50%;
    font-size: 12px;
    font-weight: 600;
    background: var(--bs-secondary-bg, #eef2f7);
    color: var(--bs-secondary-color, #8a97ab);
    border: 2px solid var(--bs-border-color, #e3ebf6);
    transition: background .15s ease, color .15s ease;
}

.fp-step-label {
    display: block;
    font-size: 11px;
    line-height: 1.2;
    color: var(--bs-secondary-color, #8a97ab);
}

/* done - Arqentis Purple. Not green: the guideline keeps greens out of brand
   graphics, and the journey strip is on every page. */
.fp-step.done .fp-step-dot {
    background: var(--bs-primary, #8A38F5);
    border-color: var(--bs-primary, #8A38F5);
    color: #fff;
}

/* current - ink, like the web's black buttons, with a lavender halo so it
   stands apart from the purple "done" dots. */
.fp-step.active .fp-step-dot {
    background: var(--bs-emphasis-color, #0A0C0E);
    border-color: var(--bs-emphasis-color, #0A0C0E);
    color: #fff;
    box-shadow: 0 0 0 4px var(--bs-primary-bg-subtle, #E8D7FD);
}

.fp-step.active .fp-step-label {
    color: var(--bs-emphasis-color, #0A0C0E);
    font-weight: 600;
}

/* locked - an earlier step is unfinished.
   Shown, not hidden: the user should see the step exists and is coming.
   FP.guardStep() strips the href, so the cursor has to say so too. */
.fp-step.locked > a {
    cursor: not-allowed;
    opacity: 0.45;
}

.fp-step.locked .fp-step-dot {
    background: var(--bs-secondary-bg, #eef2f7);
    border-style: dashed;
}

@media (max-width: 767.98px) {
    /* All seven steps have to be visible at once on a phone. The labels are what
       made that impossible - "Financial Details" needs ~76px, and 7 x 76 = 532px
       against ~343px of screen, so four steps were pushed out of sight. Drop the
       labels, keep every dot, and name the current step in .fp-steps-caption
       underneath instead. 343 / 7 = ~49px per step, comfortably over the 30px
       dot. */
    .fp-step {
        min-width: 0;
    }

    .fp-step-label {
        display: none;
    }

    /* Tap target: the dot is 30px, so pad the link out to 44px. */
    .fp-step > a {
        min-height: 44px;
        padding: 4px 0;
    }
}

/* ---------------------------------------------------------------- *
 * 7. Small-phone (<=380px) trims
 * ---------------------------------------------------------------- */

@media (max-width: 380px) {
    .fp-tab {
        font-size: 9px;
    }

    .fp-tab i {
        font-size: 19px;
    }

    .card-body {
        padding: 14px;
    }
}

/* ---------------------------------------------------------------- *
 * Brand - the Arqentis logo in the sidebar, title bar and auth pages
 * ---------------------------------------------------------------- */

/* The theme sizes its logos to 24px, which puts the Arqentis logo (about
   4.6:1) at 110px wide - under the brand's 120px minimum. 28px tall gives
   about 129px; the mark alone shows when the sidebar is collapsed. */
.startbar .brand .logo-lg {
    height: 28px;
    width: auto;
    margin-left: 0;
    object-fit: contain;
}

/* Form field headings (labels) in black, on every form - the theme greys
   them via --bs-label-color. Brand Ink rather than pure #000; white again in
   the dark theme, where black would vanish. */
label,
.form-label,
.form-check-label {
    color: #0A0C0E;
}
html[data-bs-theme="dark"] label,
html[data-bs-theme="dark"] .form-label,
html[data-bs-theme="dark"] .form-check-label {
    color: #fff;
}

/* The suggestion text inside a field is light, the same everywhere: the
   placeholder of a text box, and the prompt option of a dropdown ("Please
   select goal type") while nothing has been chosen yet. Once a real value is
   picked the select goes back to the normal text colour; the options in the
   open list stay normal too. */
.form-control::placeholder,
.form-select::placeholder {
    color: var(--bs-secondary-color);
    opacity: 1;
}
.form-select:has(> option[value=""]:checked) {
    color: var(--bs-secondary-color);
}
.form-select option {
    color: var(--bs-body-color);
}

/* Number boxes take typed figures, not nudges: no spinner arrows (a click on
   one moves an amount by a rupee or a step). The mouse wheel is stopped from
   changing them in api.js. The numeric keypad on phones is unaffected. */
input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type=number] {
    -moz-appearance: textfield;
    appearance: textfield;
}

/* ---------------------------------------------------------------- *
 * Form buttons - compact pill buttons in a right-aligned action row
 * ---------------------------------------------------------------- */

/* Every form ends in a .form-actions row: the buttons sit at their natural
   width on the RIGHT of the form, on every page including the sign-in cards,
   instead of the theme's full-width slabs. On a phone they stretch again so
   a thumb can hit them. */
.form-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: .5rem;
}
/* The buttons themselves keep the theme's own look (plain .btn-primary etc.);
   only their placement changes. */
@media (max-width: 575.98px) {
    .form-actions .btn {
        flex: 1 1 auto;
    }
}

/* Between 1024 and 1199px the theme sizes the title bar for a 70px collapsed
   sidebar, but at those widths the collapsed sidebar is off-canvas - so the
   bar stopped 70px short of the left edge. Invisible while the bar matched the
   page background; with the white Arqentis bar it shows as a gap. */
@media (max-width: 1199.98px) {
    body[data-sidebar-size=collapsed] .topbar {
        width: 100%;
    }
}

/* Title bar brand, shown only where the sidebar is off-canvas (< 1200px):
   the full logo, ink wordmark on the white bar, 26px tall = the brand's
   120px minimum width. */
.topbar-brand { margin-left: 4px; }
.topbar-brand-logo {
    height: 26px;
    width: auto;
}
.startbar .brand .logo-sm {
    height: 32px;
    width: 32px;
}
/* Collapsed sidebar: the theme hides .logo-lg by zeroing its width, so make
   sure a wordmark never overflows the 70px strip while animating. */
.startbar .brand .logo { overflow: hidden; }

/* Auth cards: the reverse logo sits on the Brand Night header box; 40px tall
   (about 185px wide), shrinking on narrow phones rather than overflowing. */
.auth-logo {
    max-width: 70%;
    height: auto;
    max-height: 40px;
    object-fit: contain;
}
