/* ESAS inside its iOS / Android app. Every rule is scoped to html.in-app, which only the app sets
   (see the head snippet in the layouts and js/native-app.js), so a browser renders exactly as
   before. */

/* Things that only make sense in the app: hidden everywhere else. */
html:not(.in-app) .app-only { display: none !important; }

/* And the reverse: sign-up and plan purchases stay on the website (see js/native-app.js). */
.in-app .app-hide,
.in-app a[href^="/subscription" i],
.in-app a[href*="/account/Register" i] { display: none !important; }

/* ── Safe areas ──────────────────────────────────────────────────────────────
   The app draws edge to edge, under the status bar, the notch and the home indicator. The
   insets come from env() (iOS, recent Android WebViews) or from the --safe-area-inset-*
   variables Capacitor provides for older Android WebViews — whichever is larger. */
html.in-app {
    --app-inset-top: max(env(safe-area-inset-top, 0px), var(--safe-area-inset-top, 0px));
    --app-inset-bottom: max(env(safe-area-inset-bottom, 0px), var(--safe-area-inset-bottom, 0px));
    --app-inset-left: max(env(safe-area-inset-left, 0px), var(--safe-area-inset-left, 0px));
    --app-inset-right: max(env(safe-area-inset-right, 0px), var(--safe-area-inset-right, 0px));
}
.in-app .app-body {
    grid-template-rows: calc(64px + var(--app-inset-top)) 1fr;
    padding-left: var(--app-inset-left);
    padding-right: var(--app-inset-right);
    box-sizing: border-box;
}
@media (max-width: 960px) {
    .in-app .app-body { grid-template-rows: calc(64px + var(--app-inset-top)) 1fr; }
}
/* The top bar grows by the status bar's height and keeps its own colour behind it. */
.in-app .app-topbar { padding-top: var(--app-inset-top); }
.in-app .app-sidebar {
    padding-top: calc(18px + var(--app-inset-top));
    padding-bottom: calc(24px + var(--app-inset-bottom));
}
.in-app .app-main { padding-bottom: calc(28px + var(--app-inset-bottom)); }
@media (max-width: 540px) {
    .in-app .app-main { padding-bottom: calc(16px + var(--app-inset-bottom)) !important; }
}
/* Sign-in and other pages outside the dashboard shell. */
.in-app body:not(.app-body) {
    padding-top: var(--app-inset-top);
    padding-bottom: var(--app-inset-bottom);
}
.in-app .toast-stack { margin-bottom: var(--app-inset-bottom); }

/* A phone app does not select its own chrome on a long press. */
.in-app .app-topbar, .in-app .app-sidebar, .in-app .btn { -webkit-user-select: none; user-select: none; }
.in-app { -webkit-tap-highlight-color: transparent; }

/* ── Scan button beside a barcode field ─────────────────────────────────────── */
.scan-field { display: flex; align-items: stretch; gap: 8px; width: 100%; }
.scan-field > input { flex: 1; min-width: 0; margin-bottom: 0 !important; }
.scan-btn {
    flex: none;
    min-width: 46px;
    min-height: 44px;
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    border: 1px solid var(--c-border);
    background: var(--c-surface);
    color: var(--c-primary);
    cursor: pointer;
}
.scan-btn svg { width: 22px; height: 22px; }
.scan-field + * { margin-top: 12px; }

/* ── Bottom sheet (Face ID offer, notices) ─────────────────────────────────── */
.app-sheet-backdrop {
    position: fixed; inset: 0; z-index: 1000;
    background: rgba(15, 23, 42, .45);
    display: flex; align-items: flex-end; justify-content: center;
}
.app-sheet {
    width: 100%; max-width: 520px;
    background: var(--c-surface);
    color: var(--c-text);
    border-radius: 18px 18px 0 0;
    padding: 22px 20px calc(20px + var(--app-inset-bottom, 0px));
    box-shadow: 0 -8px 30px rgba(0,0,0,.18);
}
.app-sheet h3 { margin: 0 0 6px; font-size: 1.1rem; }
.app-sheet p { margin: 0 0 18px; color: var(--c-body); line-height: 1.6; }
.app-sheet .app-sheet-actions { display: flex; flex-direction: column; gap: 10px; }
.app-sheet .btn { width: 100%; min-height: 48px; justify-content: center; }

/* ── Lock screen ────────────────────────────────────────────────────────────
   Set on <html> by the head snippet before the first paint on a cold start, so the books are
   never on screen before the owner's face or finger has been checked. */
html.app-locked body { visibility: hidden; }
html.app-locked .app-lock { visibility: visible; }
.app-lock {
    position: fixed; inset: 0; z-index: 2000;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
    padding: calc(24px + var(--app-inset-top, 0px)) 24px calc(24px + var(--app-inset-bottom, 0px));
    background: var(--c-surface);
    color: var(--c-text);
    text-align: center;
}
.app-lock img { width: 76px; height: 76px; }
.app-lock h2 { margin: 6px 0 0; font-size: 1.25rem; }
.app-lock p { margin: 0; color: var(--c-body); }
.app-lock .btn { min-width: 220px; min-height: 48px; justify-content: center; }
.app-lock .app-lock-alt { background: none; border: 0; color: var(--c-primary); font: inherit; padding: 10px; cursor: pointer; }

/* ── Offline strip ─────────────────────────────────────────────────────────── */
.app-offline {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 900;
    padding: 10px 16px calc(10px + var(--app-inset-bottom, 0px));
    background: #7C2D12; color: #FFF7ED; text-align: center; font-size: .9rem;
}

/* ── Quick sign-in on the login page ───────────────────────────────────────── */
.quick-signin { margin-top: 14px; width: 100%; min-height: 48px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.quick-signin svg { width: 22px; height: 22px; }
.quick-signin-note { margin-top: 10px; font-size: .88rem; color: var(--c-body); text-align: center; }

/* ── App settings page ─────────────────────────────────────────────────────── */
.app-setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.app-setting + .app-setting { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--c-border-soft); }
.app-setting .app-setting-text { flex: 1; min-width: 200px; }
.app-setting .app-setting-text strong { display: block; margin-bottom: 2px; }
.app-setting .app-setting-text span { color: var(--c-body); font-size: .9rem; }
