/* ============================================================
   HAPPIE HUB — NATIVE MOBILE SHELL  (Stage 1: shell only)
   ------------------------------------------------------------
   A SEPARATE mobile app surface (#m-app), parallel to the
   desktop #app. Every rule here is scoped under #m-app / .m-*
   so it can NEVER leak into the desktop layout, and the desktop
   DOM is never styled from this file. The only cross-cutting
   rules are the visibility swap at the 768px breakpoint.

   > 768px : desktop #app shows as-is, #m-app hidden.
   <=768px : #app hidden, #m-app shown (the native shell).
   ============================================================ */

/* ---- Breakpoint swap (the ONLY place desktop DOM is touched) ---- */
#m-app { display: none; }
@media (max-width: 768px) {
  #app { display: none !important; }
  #m-app { display: flex; }
}

/* ============================================================
   Design tokens — local to the mobile surface, theme-aware.
   ============================================================ */
#m-app {
  --m-bg:        #eef1f5;
  --m-surface:   #ffffff;
  --m-surface-2: #f7f9fc;
  --m-text:      #16202e;
  --m-muted:     #67748a;
  --m-border:    #e6eaf0;
  --m-accent:    #00b894;
  --m-accent-in: #ffffff;
  --m-primary:   #123458;
  --m-gold:      #f4b400;
  --m-red:       #e74c3c;
  --m-shadow:    0 1px 3px rgba(18,52,88,.10), 0 6px 18px rgba(18,52,88,.06);
  --m-shadow-lg: 0 8px 28px rgba(18,52,88,.18);
  --m-header-h:  56px;
  --m-tabbar-h:  58px;
  --m-safe-b:    env(safe-area-inset-bottom, 0px);
  --m-safe-t:    env(safe-area-inset-top, 0px);
}
[data-theme="dark"] #m-app {
  --m-bg:        #0d0f14;
  --m-surface:   #171a22;
  --m-surface-2: #1e222c;
  --m-text:      #e6e9f2;
  --m-muted:     #97a2b6;
  --m-border:    #262b37;
  --m-primary:   #7eb8ff;
  --m-shadow:    0 1px 3px rgba(0,0,0,.4), 0 6px 18px rgba(0,0,0,.30);
  --m-shadow-lg: 0 8px 28px rgba(0,0,0,.55);
}

/* ============================================================
   Shell scaffold
   ============================================================ */
#m-app {
  position: fixed;
  inset: 0;
  z-index: 1;                 /* below login overlay / modals / toasts */
  flex-direction: column;
  background: var(--m-bg);
  color: var(--m-text);
  font-family: 'DM Sans','Poppins',-apple-system,BlinkMacSystemFont,'Segoe UI',sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
#m-app *, #m-app *::before, #m-app *::after { box-sizing: border-box; }

/* The stage that holds all screens (fills space above the tab bar) */
.m-viewport {
  position: relative;
  flex: 1 1 auto;
  overflow: hidden;
}

/* ============================================================
   Screens — root tabs stack + pushed detail overlays
   ============================================================ */
.m-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--m-bg);
}

/* Root (tab) screens crossfade; only the active one is interactive */
.m-screen[data-root] {
  z-index: 1;
  opacity: 0;
  visibility: hidden;
  transform: translateY(6px);
  transition: opacity .2s ease, transform .2s ease, visibility 0s linear .2s;
}
.m-screen[data-root].is-active {
  opacity: 1;
  visibility: visible;
  transform: none;
  transition: opacity .22s ease, transform .22s ease;
}

/* Pushed detail screens slide in from the right, OVER the tab bar */
.m-screen.m-detail {
  z-index: 30;
  transform: translateX(100%);
  transition: transform .3s cubic-bezier(.32,.72,0,1);
  box-shadow: -12px 0 30px rgba(0,0,0,.12);
}
.m-screen.m-detail.is-in { transform: translateX(0); }

@media (prefers-reduced-motion: reduce) {
  .m-screen[data-root], .m-screen.m-detail { transition-duration: .01ms; }
}

/* ============================================================
   Per-screen sticky header
   ============================================================ */
.m-header {
  flex: 0 0 auto;
  min-height: var(--m-header-h);
  padding-top: var(--m-safe-t);
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 16px;
  padding-right: 12px;
  background: var(--m-surface);
  border-bottom: 1px solid var(--m-border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.m-header .m-h-titles { flex: 1 1 auto; min-width: 0; }
.m-header .m-h-title {
  font-family: 'Poppins',sans-serif;
  font-size: 20px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.m-header .m-h-sub {
  font-size: 12px;
  color: var(--m-muted);
  margin-top: 1px;
}
.m-header .m-h-action,
.m-header .m-back {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  color: var(--m-text);
  font-size: 20px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.m-header .m-back { font-size: 24px; margin-left: -8px; }
.m-header .m-h-action:active,
.m-header .m-back:active { background: var(--m-surface-2); }

/* ============================================================
   Scroll body + pull-to-refresh
   ============================================================ */
.m-body {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  /* The tab bar sits below the viewport (in flow), so the body only needs
     breathing room, not the tab bar's height. */
  padding: 14px 14px 28px;
}

.m-ptr {
  height: 0;
  overflow: hidden;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  transition: height .18s ease;
  margin-top: -4px;
}
.m-ptr::before {
  content: "";
  width: 22px; height: 22px;
  margin-bottom: 6px;
  border-radius: 50%;
  border: 2.5px solid var(--m-border);
  border-top-color: var(--m-accent);
  opacity: .55;
}
.m-ptr.ready::before { opacity: 1; transform: rotate(140deg); }
.m-ptr.spinning::before { animation: m-spin .7s linear infinite; opacity: 1; }
@keyframes m-spin { to { transform: rotate(360deg); } }

/* ============================================================
   Cards
   ============================================================ */
.m-card {
  background: var(--m-surface);
  border: 1px solid var(--m-border);
  border-radius: 16px;
  padding: 15px 16px;
  margin-bottom: 12px;
  box-shadow: var(--m-shadow);
  transition: transform .12s ease, background .12s ease;
}
.m-card[data-push] { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.m-card[data-push]:active { transform: scale(.985); background: var(--m-surface-2); }

/* Row card: avatar + text + trailing */
.m-row { display: flex; align-items: center; gap: 13px; }
.m-avatar {
  flex: 0 0 auto;
  width: 46px; height: 46px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px;
  color: #fff;
  background: linear-gradient(135deg, var(--m-accent), #0a8f74);
}
.m-row-main { flex: 1 1 auto; min-width: 0; }
.m-row-title { font-size: 15.5px; font-weight: 600; letter-spacing: -.1px; }
.m-row-sub { font-size: 13px; color: var(--m-muted); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.m-row-trail { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.m-chev { color: var(--m-muted); font-size: 20px; flex: 0 0 auto; opacity: .6; }

.m-amt { font-size: 15px; font-weight: 700; }

/* Status pills */
.m-pill {
  font-size: 11px; font-weight: 700; letter-spacing: .2px;
  padding: 3px 9px; border-radius: 999px; white-space: nowrap;
}
.m-pill.ok   { background: rgba(0,184,148,.14);  color: #0a8f74; }
.m-pill.due  { background: rgba(244,180,0,.16);   color: #b58600; }
.m-pill.bad  { background: rgba(231,76,60,.14);    color: #d0392b; }
[data-theme="dark"] #m-app .m-pill.ok  { color: #35d6b0; }
[data-theme="dark"] #m-app .m-pill.due { color: #f4c74f; }
[data-theme="dark"] #m-app .m-pill.bad { color: #ff7a6b; }

/* Section label */
.m-sec {
  font-size: 12px; font-weight: 700; letter-spacing: .5px;
  text-transform: uppercase; color: var(--m-muted);
  margin: 18px 4px 9px;
}
.m-sec:first-child { margin-top: 4px; }

/* ============================================================
   Home: hero + quick tiles
   ============================================================ */
.m-hero {
  background: linear-gradient(135deg, var(--m-primary), #0d2540);
  color: #fff;
  border-radius: 20px;
  padding: 18px;
  margin-bottom: 6px;
  box-shadow: var(--m-shadow-lg);
}
[data-theme="dark"] #m-app .m-hero { background: linear-gradient(135deg,#1c3a5e,#0c1a2c); }
.m-hero-greet { font-size: 13px; opacity: .82; }
.m-hero-row { display: flex; gap: 10px; margin-top: 12px; }
.m-hero-stat { flex: 1 1 0; background: rgba(255,255,255,.12); border-radius: 14px; padding: 11px 12px; }
.m-hero-val { font-size: 22px; font-weight: 800; font-family:'Poppins',sans-serif; line-height: 1; }
.m-hero-lbl { font-size: 11px; opacity: .85; margin-top: 5px; }

.m-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.m-tile {
  background: var(--m-surface);
  border: 1px solid var(--m-border);
  border-radius: 16px;
  padding: 16px;
  display: flex; flex-direction: column; gap: 8px;
  box-shadow: var(--m-shadow);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: transform .12s ease, background .12s ease;
}
.m-tile:active { transform: scale(.97); background: var(--m-surface-2); }
.m-tile-ico { font-size: 26px; }
.m-tile-lbl { font-size: 14px; font-weight: 600; }
.m-tile-sub { font-size: 12px; color: var(--m-muted); }

/* ============================================================
   Empty state + skeletons
   ============================================================ */
.m-empty {
  text-align: center;
  padding: 56px 24px;
  color: var(--m-muted);
}
.m-empty-ico { font-size: 52px; margin-bottom: 12px; }
.m-empty-title { font-size: 17px; font-weight: 700; color: var(--m-text); }
.m-empty-sub { font-size: 13.5px; margin-top: 6px; line-height: 1.5; }
.m-empty .m-btn { margin-top: 18px; }

.m-btn {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--m-accent); color: var(--m-accent-in);
  border: none; border-radius: 12px;
  font-size: 14.5px; font-weight: 700;
  padding: 12px 20px; min-height: 44px;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.m-btn:active { filter: brightness(.94); }
.m-btn.ghost { background: var(--m-surface); color: var(--m-text); border: 1px solid var(--m-border); }

.m-skel-card {
  background: var(--m-surface);
  border: 1px solid var(--m-border);
  border-radius: 16px;
  padding: 15px 16px; margin-bottom: 12px;
  display: flex; align-items: center; gap: 13px;
}
.m-sk { background: var(--m-border); border-radius: 8px; position: relative; overflow: hidden; }
.m-sk::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.35), transparent);
  transform: translateX(-100%); animation: m-shimmer 1.3s infinite;
}
[data-theme="dark"] #m-app .m-sk::after { background: linear-gradient(90deg, transparent, rgba(255,255,255,.06), transparent); }
@keyframes m-shimmer { to { transform: translateX(100%); } }
.m-sk.circ { width: 46px; height: 46px; border-radius: 14px; flex: 0 0 auto; }
.m-sk.line { height: 12px; }
.m-sk-main { flex: 1 1 auto; }
.m-sk.w70 { width: 70%; } .m-sk.w40 { width: 40%; margin-top: 8px; }

/* ============================================================
   Floating action button
   ============================================================ */
.m-fab {
  position: absolute;
  right: 18px;
  bottom: 18px;                /* relative to the screen (which sits above the tab bar) */
  width: 56px; height: 56px;
  border-radius: 18px;
  border: none;
  background: var(--m-accent);
  color: #fff;
  font-size: 28px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 22px rgba(0,184,148,.45);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  z-index: 15;
  transition: transform .12s ease;
}
.m-fab:active { transform: scale(.92); }

/* ============================================================
   Bottom tab bar
   ============================================================ */
.m-tabbar {
  flex: 0 0 auto;
  display: flex;
  background: var(--m-surface);
  border-top: 1px solid var(--m-border);
  padding-bottom: var(--m-safe-b);
  z-index: 20;
  box-shadow: 0 -2px 14px rgba(18,52,88,.05);
}
.m-tab {
  flex: 1 1 0;
  height: var(--m-tabbar-h);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px;
  border: none; background: transparent;
  color: var(--m-muted);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: color .15s ease;
  position: relative;
}
.m-tab-ico { font-size: 22px; line-height: 1; transition: transform .15s ease; }
.m-tab-lbl { font-size: 10.5px; font-weight: 600; letter-spacing: .1px; }
.m-tab.is-active { color: var(--m-accent); }
.m-tab.is-active .m-tab-ico { transform: translateY(-1px) scale(1.06); }
.m-tab:active .m-tab-ico { transform: scale(.9); }
