/* ═══════════════════════════════════════════════════════════════════
   BizTracko — premium mobile layer
   Applies only at phone widths (≤720px): the Android app and the mobile
   PWA. Desktop layout is untouched. Colours come from the theme tokens
   in index.html, so dark and light themes both work.
   ═══════════════════════════════════════════════════════════════════ */
@media (max-width: 720px) {
  :root {
    --m-gutter: 16px;
    --m-radius: 20px;
    --m-radius-sm: 14px;
    --m-tabbar: 66px;
    --m-ease: cubic-bezier(.2, .8, .2, 1);
    --m-card-shadow: 0 1px 0 rgba(255,255,255,.035) inset, 0 10px 28px rgba(0,0,0,.22);
    --m-glass: color-mix(in srgb, var(--bg2) 80%, transparent);
    /* System-bar insets: browser env() or the values the Android app injects */
    --m-safe-t: max(env(safe-area-inset-top), var(--safe-area-inset-top, 0px));
    --m-safe-b: max(env(safe-area-inset-bottom), var(--safe-area-inset-bottom, 0px));
  }
  /* In the Android app the WebView can extend under the gesture/navigation
     bar on some phones (e.g. Samsung) — always keep the tab bar clear of it. */
  html.native-app {
    --m-safe-b: max(24px, env(safe-area-inset-bottom), var(--safe-area-inset-bottom, 0px));
  }
  body.light-theme {
    --m-card-shadow: 0 1px 2px rgba(15,23,42,.04), 0 8px 24px rgba(15,23,42,.06);
    --m-glass: color-mix(in srgb, #FFFFFF 84%, transparent);
  }

  html { -webkit-tap-highlight-color: transparent; }
  body { overscroll-behavior-y: none; -webkit-font-smoothing: antialiased; }
  button, .btn, .nav-item, .mbn-item, .user-badge, .theme-toggle {
    -webkit-user-select: none; user-select: none; touch-action: manipulation;
  }

  /* ── Top bar: frosted glass, safe-area aware ───────────────────── */
  .topbar,
  body.light-theme .topbar {
    height: auto;
    min-height: 60px;
    padding: var(--m-safe-t) 10px 0 6px;
    background: color-mix(in srgb, var(--bg) 80%, transparent);
    border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
    box-shadow: none;
    backdrop-filter: blur(20px) saturate(1.4);
    -webkit-backdrop-filter: blur(20px) saturate(1.4);
  }
  .topbar-title {
    font-size: 19px; font-weight: 800; letter-spacing: -.3px;
    max-width: 52vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  #hamburger-btn, #back-btn {
    width: 40px; height: 40px; padding: 0;
    align-items: center; justify-content: center;
    border-radius: 12px; font-size: 20px;
  }
  #hamburger-btn:active, #back-btn:active { background: var(--surface); }
  /* Title takes the free space and truncates; the right-hand icons never get pushed off-screen */
  .topbar > div:first-child { flex: 1 1 auto; min-width: 0; gap: 2px !important; }
  .topbar-title { flex: 1 1 auto; min-width: 0; max-width: none; font-size: 18px; }
  .topbar-right { gap: 4px; flex-shrink: 0; }
  /* Theme switch lives in the profile menu on phones */
  .theme-toggle { display: none !important; }
  .user-menu-item.m-only { display: block; }
  /* Android app: the system back gesture/button already goes back */
  html.native-app #back-btn { display: none !important; }
  #admin-notif-bell {
    width: 38px; height: 38px; align-items: center; justify-content: center;
    border-radius: 12px;
  }
  /* Avatar only — the name lives in the menu */
  .user-badge {
    padding: 2px !important; gap: 0 !important;
    background: transparent !important; border: 0 !important; border-radius: 999px !important;
  }
  .user-badge > #user-name-badge,
  .user-badge > span:not(.user-avatar) { display: none !important; }
  .user-avatar {
    width: 36px !important; height: 36px !important; font-size: 15px !important;
    box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px color-mix(in srgb, var(--accent) 45%, transparent);
  }
  .user-menu { right: 0; min-width: 210px; border-radius: 16px; overflow: hidden; }
  .user-menu-item { padding: 13px 16px; font-size: 14px; }

  /* ── Page content ─────────────────────────────────────────────── */
  .content { padding: 14px var(--m-gutter) 28px; }
  body.has-mobile-nav #page-content {
    padding-bottom: calc(var(--m-tabbar) + 34px + var(--m-safe-b));
  }
  #page-content > * { animation: mPageIn .32s var(--m-ease) both; }
  #page-content > *:nth-child(2) { animation-delay: .03s; }
  #page-content > *:nth-child(3) { animation-delay: .06s; }
  #page-content > *:nth-child(4) { animation-delay: .09s; }
  #page-content > *:nth-child(n+5) { animation-delay: .12s; }

  /* ── Cards ────────────────────────────────────────────────────── */
  .card {
    border-radius: var(--m-radius);
    padding: 16px;
    border-color: color-mix(in srgb, var(--border) 85%, transparent);
    box-shadow: var(--m-card-shadow);
  }
  .card-header { margin-bottom: 14px; gap: 10px; flex-wrap: wrap; }
  .card-title { font-size: 16px; font-weight: 800; letter-spacing: -.2px; }

  /* ── KPI cards: hero + 2-column grid ──────────────────────────── */
  .kpi-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px; margin-bottom: 16px;
  }
  .kpi-card {
    border-radius: 18px; padding: 14px 14px 13px;
    box-shadow: var(--m-card-shadow);
  }
  .kpi-card::before { display: none; }
  .kpi-label {
    display: flex; align-items: center; gap: 6px;
    font-size: 10.5px; letter-spacing: .6px; margin-bottom: 7px;
  }
  .kpi-label::before {
    content: ''; width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0;
    background: var(--kpi-color, var(--accent));
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--kpi-color, var(--accent)) 22%, transparent);
  }
  .kpi-value { font-size: clamp(16px, 4.7vw, 19px); letter-spacing: -.3px; }
  .kpi-sub { font-size: 11px; line-height: 1.4; margin-top: 5px; }
  .kpi-card:not(.kpi-card--hero) .kpi-icon { display: none; }

  .kpi-card--hero {
    grid-column: 1 / -1;
    padding: 20px 20px 18px;
    border-color: color-mix(in srgb, var(--kpi-color, var(--accent)) 40%, transparent);
    background:
      radial-gradient(120% 140% at 100% 0%, color-mix(in srgb, var(--kpi-color, var(--accent)) 30%, transparent) 0%, transparent 60%),
      linear-gradient(160deg, color-mix(in srgb, var(--kpi-color, var(--accent)) 12%, var(--bg2)), var(--bg2));
    box-shadow: 0 14px 34px color-mix(in srgb, var(--kpi-color, var(--accent)) 22%, transparent);
  }
  .kpi-card--hero .kpi-label { font-size: 11px; color: var(--text2); }
  .kpi-card--hero .kpi-value { font-size: clamp(30px, 9vw, 36px) !important; font-weight: 800; letter-spacing: -1px; margin-top: 2px; }
  /* Odd one out (hero + 3 small) — let the last small card span the row */
  .kpi-grid > .kpi-card--hero:first-child ~ .kpi-card:last-child:nth-child(even) { grid-column: 1 / -1; }
  .kpi-card--hero .kpi-sub { font-size: 12.5px; color: var(--text2); }
  .kpi-card--hero .kpi-icon { right: 18px; top: 18px; transform: none; font-size: 34px !important; opacity: .22 !important; }

  /* ── Dashboard stock overview: swipeable row ──────────────────── */
  .dash-stock-grid {
    display: flex !important; gap: 10px !important;
    overflow-x: auto; scroll-snap-type: x mandatory;
    margin: 0 -16px; padding: 2px 16px 6px;
    scrollbar-width: none;
  }
  .dash-stock-grid::-webkit-scrollbar { display: none; }
  .dash-stock-grid > div {
    flex: 0 0 152px; scroll-snap-align: start;
    border-radius: 16px !important; padding: 12px 13px !important;
  }

  /* ── No horizontal overflow ───────────────────────────────────────
     Grid/flex items default to min-width:auto, so one wide table made the
     whole column (and the form card next to it) wider than the screen.
     Let them shrink; wide tables scroll inside their own .table-wrap. */
  #page-content [style*="display:grid"] > *,
  #page-content [style*="display: grid"] > *,
  #page-content .card,
  #page-content .kpi-card { min-width: 0; }
  #page-content .card { max-width: 100%; }

  /* ── Alerts ───────────────────────────────────────────────────── */
  .alert { border-radius: var(--m-radius-sm); padding: 12px 14px; }

  /* ── Buttons: comfortable touch targets + press feedback ──────── */
  .btn {
    min-height: 42px; border-radius: 12px; justify-content: center;
    font-size: 14px; transition: transform .12s var(--m-ease), background .15s, box-shadow .15s;
  }
  .btn-sm { min-height: 34px; padding: 6px 12px; font-size: 12.5px; border-radius: 10px; }
  .btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 35%, transparent);
  }
  .btn-primary:hover { transform: none; }
  .btn:active, .nav-item:active, .kpi-card:active, .mbn-item:active, .icon-btn:active { transform: scale(.96); }
  /* Small row actions (view / edit / delete) — reach a usable tap size */
  .icon-btn {
    min-height: 34px; min-width: 34px;
    padding: 6px 10px !important; font-size: 12.5px !important;
    border-radius: 10px !important;
    display: inline-flex; align-items: center; justify-content: center;
  }

  /* ── Forms ────────────────────────────────────────────────────── */
  .form-control {
    min-height: 48px; border-radius: 12px;
    transition: border-color .15s, box-shadow .15s;
  }
  textarea.form-control { min-height: 88px; }
  .form-control:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent);
  }
  .form-label { font-size: 12.5px; font-weight: 600; letter-spacing: .2px; }

  /* ── Tables ───────────────────────────────────────────────────── */
  .table-wrap { border-radius: var(--m-radius-sm); }
  .table-wrap th, .table-wrap td:first-child, .td-mono, .td-num { white-space: nowrap; }

  /* ── Modals become bottom sheets ──────────────────────────────── */
  .modal-overlay {
    align-items: flex-end;
    background: rgba(3, 8, 18, .55);
    backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  }
  .modal {
    width: 100vw; max-width: 100vw; min-width: 0 !important;
    max-height: 92vh;
    border-radius: 26px 26px 0 0;
    border-bottom: 0;
    padding: 10px 18px calc(20px + var(--m-safe-b));
    transform: translateY(100%);
    transition: transform .34s var(--m-ease);
    box-shadow: 0 -12px 40px rgba(0,0,0,.35);
  }
  .modal-overlay.open .modal { transform: translateY(0); }
  .modal::before {
    content: ''; display: block;
    width: 40px; height: 5px; border-radius: 3px;
    background: var(--border2); margin: 0 auto 10px;
  }
  .modal-header {
    position: sticky; top: -10px; z-index: 2;
    margin: 0 -18px 14px; padding: 6px 18px 10px;
    background: var(--bg2);
  }
  .modal-title { font-size: 19px; font-weight: 800; letter-spacing: -.3px; }
  .modal-close {
    width: 36px; height: 36px; border-radius: 50%;
    background: var(--bg3); font-size: 16px;
    display: flex; align-items: center; justify-content: center;
  }
  #modal-footer .btn { flex: 1; }

  /* ── Sidebar drawer ───────────────────────────────────────────── */
  #sidebar {
    width: min(84vw, 320px);
    border-radius: 0 24px 24px 0;
    padding-top: var(--m-safe-t);
    box-shadow: 20px 0 60px rgba(0,0,0,.35);
    transition: transform .3s var(--m-ease);
  }
  /* Hide the scrollbar track (it showed as a white strip on the dark menu) */
  #sidebar { scrollbar-width: none; }
  #sidebar::-webkit-scrollbar { display: none; }
  #sidebar-overlay { background: rgba(3, 8, 18, .5); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
  .nav-item { min-height: 46px; padding: 10px 14px; font-size: 14.5px; border-radius: 12px; }

  /* ── Toasts & reminder banners sit above the tab bar ──────────── */
  #toast {
    left: 14px; right: 14px;
    bottom: calc(var(--m-tabbar) + 24px + var(--m-safe-b));
    align-items: stretch;
  }
  .toast-msg {
    border-radius: 14px; padding: 13px 16px; font-size: 13.5px;
    background: var(--m-glass);
    backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  }
  .rem-banner {
    left: 12px !important; right: 12px !important; max-width: none !important;
    top: calc(70px + var(--m-safe-t)) !important;
    border-radius: 18px !important;
  }

  /* ── Bottom tab bar: floating glass pill ──────────────────────── */
  #mobile-bottom-nav,
  body.light-theme #mobile-bottom-nav {
    left: 10px; right: 10px;
    bottom: calc(10px + var(--m-safe-b));
    padding: 6px;
    gap: 4px;
    border-radius: 24px;
    border: 1px solid color-mix(in srgb, var(--border2) 70%, transparent);
    background: var(--m-glass);
    backdrop-filter: blur(22px) saturate(1.5);
    -webkit-backdrop-filter: blur(22px) saturate(1.5);
    box-shadow: 0 12px 36px rgba(0,0,0,.38);
  }
  body.light-theme #mobile-bottom-nav { box-shadow: 0 12px 32px rgba(15,23,42,.14); }
  #mobile-bottom-nav.mbn-4 { grid-template-columns: repeat(4, 1fr) !important; }
  .mbn-item {
    position: relative;
    min-height: 52px; padding: 7px 2px 6px; gap: 3px;
    border-radius: 18px; color: var(--text3);
    transition: color .2s, background .2s, transform .12s var(--m-ease);
  }
  .mbn-item:hover { background: transparent; }
  .mbn-item .mbn-icon { display: flex; align-items: center; justify-content: center; height: 24px; font-size: 19px; }
  .mbn-item .mbn-icon svg { width: 23px; height: 23px; }
  .mbn-item .mbn-label { font-size: 10.5px; font-weight: 700; letter-spacing: .1px; }
  .mbn-item.active {
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 14%, transparent);
  }
  .mbn-item.mbn-more { background: transparent; color: var(--text3); }
  /* Raised centre action */
  .mbn-item.mbn-fab { background: transparent; color: var(--text2); }
  .mbn-item.mbn-fab .mbn-icon {
    width: 50px; height: 50px; margin-top: -24px;
    border-radius: 18px; color: #fff;
    background: linear-gradient(140deg, var(--accent), var(--accent2) 70%, var(--purple));
    box-shadow: 0 10px 24px color-mix(in srgb, var(--accent) 50%, transparent), 0 0 0 5px var(--bg);
  }
  .mbn-item.mbn-fab .mbn-icon svg { width: 26px; height: 26px; }
  .mbn-item.mbn-fab.active { background: transparent; color: var(--accent); }

  /* ── "New version available" bar floats above the tab bar ─────── */
  body #pwa-update-bar {
    left: 12px; right: 12px;
    bottom: calc(var(--m-tabbar) + 24px + var(--m-safe-b));
    padding: 10px 10px 10px 16px; gap: 10px;
    justify-content: space-between;
    border-radius: 18px; font-size: 13.5px;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    box-shadow: 0 14px 34px color-mix(in srgb, var(--accent) 40%, transparent);
  }
  body #pwa-update-bar button { border-radius: 12px; padding: 9px 16px; }
  body:not(.has-mobile-nav) #pwa-update-bar { bottom: calc(14px + var(--m-safe-b)); }

  /* ── Login ────────────────────────────────────────────────────── */
  /* Full-screen, native-style sign-in on phones */
  #login-screen {
    align-items: stretch;
    padding: calc(var(--m-safe-t) + 12px) 0 var(--m-safe-b);
  }
  .login-card {
    width: 100% !important; max-width: 440px;
    display: flex; flex-direction: column; justify-content: center;
    min-height: 100%;
    padding: 28px 24px 22px !important;
    background: transparent; border: 0; box-shadow: none;
    backdrop-filter: none; -webkit-backdrop-filter: none;
    border-radius: 0 !important;
  }
  .login-brand { margin-bottom: 26px; gap: 14px; }
  .login-mark { width: 76px; height: 76px; border-radius: 24px; }
  .login-mark img { width: 54px; height: 54px; }
  .login-head { margin-bottom: 26px; }
  .login-head h2 { font-size: 30px; }
  .login-field input { height: 54px; }
  .login-btn { height: 54px; }
  #login-api-url { display: none !important; }
}

/* ── All screen sizes ───────────────────────────────────────────── */
/* Search / date range / status / CSV toolbar above lists */
.list-toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.list-toolbar .lt-search { flex: 1 1 200px; min-width: 0; }
.list-toolbar .lt-date { flex: 0 1 150px; min-width: 0; }
.list-toolbar .lt-status { flex: 0 1 150px; min-width: 0; }
@media (max-width: 720px) {
  .list-toolbar .lt-search { flex-basis: 100%; }
  .list-toolbar .lt-date, .list-toolbar .lt-status { flex: 1 1 30%; }
}
/* Total / Paid / Balance chips in payment & statement pop-ups: always 3 across */
.pay-chips { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.pay-chips .stat-chip { padding: 8px 10px; min-width: 0; }
.pay-chips .stat-chip-val { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Default BizTracko logo: icon + wordmark (text, so it adapts to the theme) */
.bzt-logo { display: inline-flex; align-items: center; gap: calc(var(--bzt-h, 36px) * .24); vertical-align: middle; line-height: 1; }
.bzt-logo img { height: var(--bzt-h, 36px); width: auto; display: block; filter: drop-shadow(0 4px 10px rgba(64,128,255,.28)); }
.bzt-logo-text {
  font-family: 'Outfit', sans-serif; font-weight: 800; letter-spacing: -.035em;
  font-size: calc(var(--bzt-h, 36px) * .68);
  color: var(--text); -webkit-text-fill-color: currentColor;
}
.sidebar-logo .bzt-logo-text { color: #fff; }               /* the menu is dark in both themes */
#sidebar-logo-h1:has(.bzt-logo, .bzt-custom-logo),
#login-logo-h1:has(.bzt-logo, .bzt-custom-logo),
.login-logo h1:has(.bzt-logo, .bzt-custom-logo) {
  background: none !important; -webkit-text-fill-color: initial !important; margin-bottom: 4px;
}
.bzt-custom-logo { display: inline-block; vertical-align: middle; }
/* Platform image logos already contain the brand icon — never show the tile twice */
.login-brand:has(#login-logo-h1 img) .login-mark,
.login-brand:has(.login-logo img) .login-mark { display: none !important; }
.user-menu-item.m-only { display: none; }
@media (max-width: 720px) {
  .user-menu-item.m-only { display: block; }
  /* Show Quick Access on phones when the user has pinned pages
     (the bottom bar shows only the first 4) */
  .quick-access-card:has(.quick-access-tile) { display: block !important; }
}

/* Shake the pinned stars when the 4-pin limit is hit */
.nav-pin.nav-pin-shake { animation: pinShake .5s ease; }
@keyframes pinShake {
  0%, 100% { transform: none; }
  20% { transform: translateX(-3px) rotate(-12deg); }
  40% { transform: translateX(3px) rotate(12deg); }
  60% { transform: translateX(-2px) rotate(-8deg); }
  80% { transform: translateX(2px) rotate(8deg); }
}

@keyframes mPageIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

@media (max-width: 720px) and (prefers-reduced-motion: reduce) {
  #page-content > *, .modal, #sidebar { animation: none !important; transition: none !important; }
}
