/* ==========================================================================
   PWMP MIS — mobile "super app" shell
   On phones the MIS presents itself as an app: a branded hero header, a grid of
   service tiles, quick stats and a bottom tab bar — while the same server-rendered
   pages continue to work underneath.
   ========================================================================== */

.mobile-header, .tabbar, .fab, .m-only { display: none; }

@media (max-width: 1023px) {
  :root { --topbar-h: 56px; }

  .m-only { display: revert; }
  .d-only { display: none !important; }

  /* Sidebar becomes an off-canvas drawer */
  .sidebar {
    position: fixed; inset: 0 auto 0 0;
    width: min(300px, 86vw);
    transform: translateX(-100%);
    transition: transform var(--dur-base) var(--ease-out);
    z-index: 130; height: 100dvh;
  }
  .app.is-menu-open .sidebar { transform: none; box-shadow: var(--shadow-xl); }
  .sidebar-scrim {
    position: fixed; inset: 0; z-index: 120; background: var(--scrim);
    opacity: 0; pointer-events: none; transition: opacity var(--dur-base);
    backdrop-filter: blur(2px);
  }
  .app.is-menu-open .sidebar-scrim { opacity: 1; pointer-events: auto; }

  .topbar { padding: 0 var(--sp-3); }
  .topbar-title h1 { font-size: var(--fs-md); }
  .content { padding: var(--sp-4) var(--sp-3) calc(var(--tabbar-h) + var(--sp-8)); }
  .page-head h1 { font-size: var(--fs-xl); }

  .card-body { padding: var(--sp-4); }
  .card-head { padding: var(--sp-3) var(--sp-4); }
  .modal { max-width: none; border-radius: var(--r-lg) var(--r-lg) 0 0; margin-top: auto; max-height: 92dvh; }
  .modal-backdrop { padding: 0; align-items: end; }

  /* Tables collapse into stacked cards on narrow screens */
  table.data.stack-mobile thead { display: none; }
  table.data.stack-mobile tbody tr {
    display: block; padding: var(--sp-3) var(--sp-4);
    border: 1px solid var(--border); border-radius: var(--r-md);
    margin-bottom: var(--sp-3); background: var(--surface);
  }
  table.data.stack-mobile tbody td {
    display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3);
    padding: 5px 0; border: 0; text-align: right;
  }
  table.data.stack-mobile tbody td::before {
    content: attr(data-label);
    font-size: var(--fs-xs); font-weight: 600; color: var(--text-muted);
    text-align: left; flex: none;
  }
  table.data.stack-mobile tbody td:first-child {
    border-bottom: 1px solid var(--divider); padding-bottom: var(--sp-3); margin-bottom: var(--sp-2);
    display: block; text-align: left;
  }
  table.data.stack-mobile tbody td:first-child::before { display: none; }

  /* ---- Bottom tab bar --------------------------------------------------- */
  .tabbar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: saturate(1.8) blur(18px);
    -webkit-backdrop-filter: saturate(1.8) blur(18px);
    border-top: 1px solid var(--border);
  }
  .tabbar-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; color: var(--text-subtle); font-size: var(--fs-2xs); font-weight: 500;
    position: relative; padding-top: 6px; -webkit-tap-highlight-color: transparent;
    transition: color var(--dur-fast);
  }
  .tabbar-item .ic { width: 22px; height: 22px; transition: transform var(--dur-base) var(--ease-spring); }
  .tabbar-item.is-active { color: var(--primary); font-weight: 600; }
  .tabbar-item.is-active .ic { transform: translateY(-2px) scale(1.08); }
  .tabbar-item.is-active::after {
    content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
    width: 26px; height: 3px; border-radius: 0 0 3px 3px; background: var(--primary);
  }
  .tabbar-item .badge-dot {
    position: absolute; top: 5px; right: calc(50% - 16px);
    min-width: 16px; height: 16px; padding: 0 4px; border-radius: var(--r-full);
    background: var(--red-500); color: #fff; font-size: 9px; font-weight: 700;
    display: grid; place-items: center;
  }

  /* ---- Floating action button ------------------------------------------- */
  .fab {
    display: grid; place-items: center; position: fixed;
    right: var(--sp-4); bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--sp-4));
    width: 54px; height: 54px; border-radius: 50%; z-index: 99;
    background: var(--brand-gradient); color: #fff; border: 0;
    box-shadow: 0 8px 22px rgba(23,149,60,.4); cursor: pointer;
    transition: transform var(--dur-base) var(--ease-spring);
  }
  .fab:active { transform: scale(.9); }
  .fab .ic { width: 24px; height: 24px; stroke-width: 2.2; }
}

@media (min-width: 1024px) {
  .sidebar-scrim { display: none; }
}

/* ==========================================================================
   Super-app home (mobile dashboard)
   ========================================================================== */
.superapp { display: none; }

@media (max-width: 1023px) {
  .superapp { display: block; }
  .superapp + .desktop-dashboard { display: none; }

  .sa-hero {
    background: var(--brand-gradient);
    color: #fff; border-radius: 0 0 var(--r-xl) var(--r-xl);
    padding: var(--sp-5) var(--sp-4) var(--sp-8);
    margin: calc(-1 * var(--sp-4)) calc(-1 * var(--sp-3)) 0;
    position: relative; overflow: hidden;
  }
  .sa-hero::before, .sa-hero::after {
    content: ''; position: absolute; border-radius: 50%;
    background: rgba(255,255,255,.09); pointer-events: none;
  }
  .sa-hero::before { width: 210px; height: 210px; top: -90px; right: -60px; }
  .sa-hero::after  { width: 130px; height: 130px; bottom: -70px; left: -40px; }
  .sa-hero > * { position: relative; }

  .sa-greet { font-size: var(--fs-sm); opacity: .88; }
  .sa-name {
    font-family: var(--font-display); font-size: var(--fs-xl); font-weight: 600;
    margin: 2px 0 0; line-height: 1.35;
  }
  .sa-hero-top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-3); }
  .sa-hero-actions { display: flex; gap: var(--sp-2); }
  .sa-hero-actions .icon-btn { color: #fff; background: rgba(255,255,255,.15); }
  .sa-hero-actions .icon-btn:hover { background: rgba(255,255,255,.26); color: #fff; }
  .sa-hero-actions .icon-btn .dot { border-color: transparent; }

  .sa-progress-card {
    margin-top: var(--sp-5); background: rgba(255,255,255,.15);
    border: 1px solid rgba(255,255,255,.2);
    border-radius: var(--r-md); padding: var(--sp-4);
    backdrop-filter: blur(8px);
  }
  .sa-progress-top { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: var(--sp-3); }
  .sa-progress-top .label { font-size: var(--fs-xs); opacity: .9; }
  .sa-progress-top .value { font-family: var(--font-display); font-size: var(--fs-2xl); font-weight: 600; }
  .sa-progress-card .progress { background: rgba(255,255,255,.25); height: 8px; }
  .sa-progress-card .progress-bar { background: #fff; }
  .sa-progress-legend { display: flex; justify-content: space-between; margin-top: var(--sp-2); font-size: var(--fs-2xs); opacity: .88; }

  /* Quick stat strip that overlaps the hero */
  .sa-stats {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-2);
    margin: calc(-1 * var(--sp-5)) 0 var(--sp-5);
    position: relative; z-index: 2;
  }
  .sa-stat {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--r-md); padding: var(--sp-3);
    text-align: center; box-shadow: var(--shadow-sm);
  }
  .sa-stat .v {
    font-family: var(--font-display); font-size: var(--fs-lg); font-weight: 600;
    font-variant-numeric: tabular-nums; line-height: 1.2;
  }
  .sa-stat .l { font-size: 10px; color: var(--text-muted); margin-top: 2px; line-height: 1.35; }
  .sa-stat.danger .v { color: var(--danger-text); }
  .sa-stat.warning .v { color: var(--warning-text); }
  .sa-stat.success .v { color: var(--success-text); }

  /* App grid — the "super app" service launcher */
  .sa-section-head {
    display: flex; align-items: center; justify-content: space-between;
    margin: var(--sp-5) 0 var(--sp-3);
  }
  .sa-section-head h2 { font-size: var(--fs-md); margin: 0; }
  .sa-section-head a { font-size: var(--fs-xs); font-weight: 600; }

  .sa-apps {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-3) var(--sp-2);
  }
  .sa-app {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    color: var(--text); text-align: center;
    -webkit-tap-highlight-color: transparent;
  }
  .sa-app-icon {
    width: 52px; height: 52px; border-radius: 17px;
    display: grid; place-items: center;
    background: var(--tile-bg, var(--primary-soft));
    color: var(--tile-fg, var(--primary));
    position: relative;
    transition: transform var(--dur-base) var(--ease-spring), box-shadow var(--dur-base);
  }
  .sa-app:active .sa-app-icon { transform: scale(.88); }
  .sa-app-icon .ic { width: 24px; height: 24px; stroke-width: 1.9; }
  .sa-app-icon .count {
    position: absolute; top: -5px; right: -5px;
    min-width: 19px; height: 19px; padding: 0 5px; border-radius: var(--r-full);
    background: var(--red-500); color: #fff; font-size: 10px; font-weight: 700;
    display: grid; place-items: center; border: 2px solid var(--bg);
  }
  .sa-app span {
    font-size: 11px; line-height: 1.3; color: var(--text-muted); font-weight: 500;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  }

  /* Horizontally scrolling task cards */
  .sa-scroller {
    display: flex; gap: var(--sp-3); overflow-x: auto;
    scroll-snap-type: x mandatory; scrollbar-width: none;
    margin: 0 calc(-1 * var(--sp-3)); padding: 0 var(--sp-3) var(--sp-2);
  }
  .sa-scroller::-webkit-scrollbar { display: none; }
  .sa-scroller > * { scroll-snap-align: start; flex: 0 0 min(78vw, 300px); }

  /* .sa-list-item lives in app.css so desktop cards share the same row. */

  /* Pull-to-refresh indicator */
  .ptr {
    position: fixed; top: var(--topbar-h); left: 50%; transform: translate(-50%, -120%);
    z-index: 90; width: 34px; height: 34px; border-radius: 50%;
    background: var(--surface); box-shadow: var(--shadow-md);
    display: grid; place-items: center; color: var(--primary);
    transition: transform var(--dur-base) var(--ease-out);
  }
  .ptr.is-active { transform: translate(-50%, 10px); }
  .ptr.is-spinning .ic { animation: spin .8s linear infinite; }
}

/* ==========================================================================
   Splash screen
   ========================================================================== */
#splash {
  position: fixed; inset: 0; z-index: 9999;
  display: grid; place-items: center;
  background: var(--brand-gradient);
  transition: opacity .5s var(--ease-out), visibility .5s;
}
#splash.is-hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.splash-inner { text-align: center; color: #fff; padding: var(--sp-6); }
.splash-logo {
  width: 108px; height: 108px; margin: 0 auto var(--sp-5);
  border-radius: 50%; background: #fff; padding: 7px;
  box-shadow: 0 14px 44px rgba(0,0,0,.28);
  animation: splash-pop .8s var(--ease-spring) both;
}
.splash-logo img { width: 100%; height: 100%; border-radius: 50%; }
.splash-title {
  font-family: var(--font-display); font-size: var(--fs-xl); font-weight: 600;
  margin: 0 0 6px; line-height: 1.45; max-width: 22ch;
  animation: splash-rise .7s var(--ease-out) .18s both;
}
.splash-sub {
  font-size: var(--fs-sm); opacity: .86; margin: 0;
  animation: splash-rise .7s var(--ease-out) .3s both;
}
.splash-bar {
  width: 132px; height: 3px; margin: var(--sp-6) auto 0;
  background: rgba(255,255,255,.28); border-radius: var(--r-full); overflow: hidden;
  animation: splash-rise .7s var(--ease-out) .42s both;
}
.splash-bar i {
  display: block; height: 100%; width: 40%; border-radius: var(--r-full);
  background: #fff; animation: splash-slide 1.15s var(--ease-in-out) infinite;
}
.splash-foot {
  position: absolute; bottom: calc(var(--sp-6) + env(safe-area-inset-bottom)); left: 0; right: 0;
  text-align: center; font-size: var(--fs-2xs); color: rgba(255,255,255,.72);
  animation: splash-rise .7s var(--ease-out) .55s both; padding: 0 var(--sp-5);
}
@keyframes splash-pop   { from { opacity: 0; transform: scale(.6) rotate(-12deg); } }
@keyframes splash-rise  { from { opacity: 0; transform: translateY(14px); } }
@keyframes splash-slide { 0% { transform: translateX(-110%); } 100% { transform: translateX(360%); } }

/* Full-page loading veil used between navigations */
#page-loader {
  position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 300;
  background: transparent; overflow: hidden; pointer-events: none;
}
#page-loader.is-active::after {
  content: ''; display: block; height: 100%; width: 45%;
  background: var(--brand-gradient);
  animation: loader-slide 1s var(--ease-in-out) infinite;
}
@keyframes loader-slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(320%); } }
