/* =========================================================
   TechGeeks Platform — PWA CSS
   File: static/css/pwa.css

   Load AFTER:
   - css/app.css
   - module CSS files
   ========================================================= */

/* =========================
   PWA TOKENS
========================= */
:root{
  --pwa-bottom-nav-h: 64px;
  --pwa-tap-size: 44px;
  --pwa-drawer-w: min(86vw, 320px);

  --pwa-safe-top: env(safe-area-inset-top);
  --pwa-safe-right: env(safe-area-inset-right);
  --pwa-safe-bottom: env(safe-area-inset-bottom);
  --pwa-safe-left: env(safe-area-inset-left);
}

/* =========================
   VIEWPORT / APP HARDENING
========================= */
html,
body{
  width: 100%;
  min-height: 100%;
  overscroll-behavior: none;
}

body{
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

*,
*::before,
*::after{
  -webkit-tap-highlight-color: transparent;
}

img,
svg,
video,
canvas{
  max-width: 100%;
}

/* =========================
   SAFE AREA SUPPORT
========================= */
.shell{
  height: 100dvh;
  padding-top: max(var(--pad, 12px), var(--pwa-safe-top));
  padding-right: max(var(--pad, 12px), var(--pwa-safe-right));
  padding-bottom: max(var(--pad, 12px), var(--pwa-safe-bottom));
  padding-left: max(var(--pad, 12px), var(--pwa-safe-left));
}

.main{
  height: 100%;
}

.content{
  scroll-behavior: smooth;
  overscroll-behavior-y: contain;
  padding-bottom: calc(var(--content-pad, 16px) + var(--pwa-safe-bottom));
}

/* =========================
   TOUCH TARGETS
========================= */
button,
.btn,
.nav-item,
.nav-caret-btn,
.logout-btn,
.pwa-tab{
  min-height: var(--pwa-tap-size);
  touch-action: manipulation;
}

input,
select,
textarea,
.form-control{
  min-height: 40px;
}

/* Avoid iOS zoom on focus */
@media (max-width: 920px), (orientation: landscape) and (max-height: 520px){
  input,
  select,
  textarea,
  .form-control{
    font-size: 16px;
  }
}

/* =========================
   CARDS / PANELS
========================= */
.card,
.finance-card,
.activity-card,
.stat-card,
.kpi-card,
.summary-card,
.finance-section{
  border-radius: clamp(14px, 3vw, 18px);
}

.card,
.finance-card,
.activity-card,
.finance-section,
.activity-item{
  min-width: 0;
}

.activity-message,
.activity-event,
.activity-actor-value,
.detail-block{
  overflow-wrap: anywhere;
}

/* =========================
   TABLE / SCROLL PANELS
========================= */
.tg-table-wrap,
.hr-table-wrap,
.tg-md-table-wrap,
.finance-table-wrap,
.fp-table-wrap,
.finance-items-wrap{
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-gutter: stable;
  -webkit-overflow-scrolling: touch;
}

.tg-table-wrap::-webkit-scrollbar,
.hr-table-wrap::-webkit-scrollbar,
.tg-md-table-wrap::-webkit-scrollbar,
.finance-table-wrap::-webkit-scrollbar,
.fp-table-wrap::-webkit-scrollbar,
.finance-items-wrap::-webkit-scrollbar{
  height: 6px;
}

.tg-table-wrap::-webkit-scrollbar-thumb,
.hr-table-wrap::-webkit-scrollbar-thumb,
.tg-md-table-wrap::-webkit-scrollbar-thumb,
.finance-table-wrap::-webkit-scrollbar-thumb,
.fp-table-wrap::-webkit-scrollbar-thumb,
.finance-items-wrap::-webkit-scrollbar-thumb{
  background: rgba(0,0,0,.22);
  border-radius: 999px;
}

.tg-table-wrap::-webkit-scrollbar-track,
.hr-table-wrap::-webkit-scrollbar-track,
.tg-md-table-wrap::-webkit-scrollbar-track,
.finance-table-wrap::-webkit-scrollbar-track,
.fp-table-wrap::-webkit-scrollbar-track,
.finance-items-wrap::-webkit-scrollbar-track{
  background: transparent;
}

/* =========================
   FORMS
========================= */
.form-field input,
.form-field select,
.form-field textarea,
.form-control{
  line-height: 1.3;
}

textarea,
textarea.form-control{
  resize: vertical;
}

/* =========================
   PWA BOTTOM NAV
========================= */
.pwa-bottom-nav{
  display: none;
}

.pwa-tab{
  text-decoration: none;
}

/* =========================
   MOBILE DRAWER BACKDROP
========================= */
.mobile-drawer-backdrop{
  display: none;
}

/* =========================
   MOBILE / PWA LAYOUT
========================= */
@media (max-width: 920px), (orientation: landscape) and (max-height: 520px){

  body{
    position: fixed;
    inset: 0;
    width: 100%;
    overflow: hidden;
  }

  .shell{
    display: block;
    width: 100%;
    height: 100dvh;
    padding: 0;
    overflow: hidden;
  }

  .main{
    width: 100%;
    height: 100dvh;
    overflow: hidden;
  }

  .topbar{
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    border-top: 0;

    padding-top: calc(10px + var(--pwa-safe-top));
    min-height: 56px;

    z-index: 900;

    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    justify-content: space-between !important;

    gap: 8px;
  }

  .content{
    height: auto;
    flex: 1 1 auto;

    padding: 12px;
    padding-bottom: calc(
      var(--pwa-bottom-nav-h) + 24px + var(--pwa-safe-bottom)
    );

    overflow-y: auto;
    overflow-x: hidden;

    -webkit-overflow-scrolling: touch;
  }

  .page-title{
    font-size: clamp(18px, 5vw, 22px);
  }

  .card,
  .finance-card,
  .activity-card{
    padding: 14px;
  }

  .btn,
  button{
    min-height: 44px;
  }

  /* =========================
     TOPBAR / USER CHIP
  ========================= */
  .crumbs{
    flex: 1 1 auto;
    min-width: 0;
    max-width: calc(100% - 132px);
  }

  .crumb-trail{
    min-width: 0;
    overflow: hidden;
  }

  .crumb-trail a,
  .crumb-active{
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .crumb-trail a{
    font-size: 15px;
  }

  .crumb-active{
    font-size: 12px;
    max-width: 42vw;
  }

  .topbar-right{
    width: auto !important;
    flex: 0 0 auto !important;

    display: inline-flex !important;
    align-items: center !important;
    justify-content: flex-end !important;

    gap: 6px;
  }

  .topbar-right .muted{
    display: none !important;
  }

  .user-chip{
    max-width: 86px;
    font-size: 11px;
    padding: 5px 8px;
  }

  .logout-form{
    flex: 0 0 auto;
  }

  .logout-btn{
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
  }

  /* =========================
     MOBILE BOTTOM NAV
  ========================= */
  .pwa-bottom-nav{
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));

    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;

    height: calc(var(--pwa-bottom-nav-h) + var(--pwa-safe-bottom));
    padding-bottom: var(--pwa-safe-bottom);

    background: #fff;
    border-top: 1px solid var(--border, #e5e7eb);
    box-shadow: 0 -8px 24px rgba(15, 23, 42, .08);

    z-index: 950;
  }

  .pwa-tab{
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;

    min-width: 0;
    padding: 6px 4px;

    font-size: 11px;
    font-weight: 700;
    color: #667085;
  }

  .pwa-tab i{
    font-size: 18px;
    line-height: 1;
  }

  .pwa-tab span{
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .pwa-tab.active,
  .pwa-tab.is-active{
    color: var(--brand, #f7941d);
  }

  /* =========================
     MOBILE APP DRAWER
  ========================= */
  .mobile-drawer-backdrop{
    display: block;
    position: fixed;
    inset: 0;

    background: rgba(15, 23, 42, .45);
    backdrop-filter: blur(2px);

    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s ease;
  }

  body.drawer-open .mobile-drawer-backdrop{
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar{
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;

    width: var(--pwa-drawer-w);
    height: 100dvh;
    max-height: 100dvh;

    border-radius: 0 18px 18px 0;
    z-index: 1001;

    transform: translateX(-105%);
    transition: transform .25s ease;

    overflow-y: auto;
    -webkit-overflow-scrolling: touch;

    padding-top: calc(14px + var(--pwa-safe-top));
    padding-bottom: calc(18px + var(--pwa-safe-bottom));
  }

  body.drawer-open .sidebar,
  .sidebar.is-open{
    transform: translateX(0);
  }

  body.drawer-open .main,
  body.drawer-open .topbar,
  body.drawer-open .content,
  body.drawer-open .pwa-bottom-nav{
    pointer-events: none;
  }

  body.drawer-open .sidebar,
  body.drawer-open .mobile-drawer-backdrop{
    pointer-events: auto;
  }

  /* =========================
     MOBILE ACTIVITY FEED
  ========================= */
  .activity-link{
    min-height: 36px;
    display: inline-flex;
    align-items: center;
  }

  .activity-item{
    grid-template-columns: 18px 1fr;
    gap: 10px;
  }

  .activity-top{
    gap: 4px;
  }

  .activity-module{
    max-width: 100%;
  }

  /* =========================
     SAFE MODULE DEFAULTS
  ========================= */
  .hide-pwa,
  .hide-mobile{
    display: none !important;
  }

  .show-pwa{
    display: initial !important;
  }

  .card{
    border-radius: 16px;
    padding: 14px;
  }

  .module-grid{
    gap: 12px;
    grid-template-columns: 1fr;
  }

  .module-card{
    min-height: 112px;
  }

  .module-card .btn{
    width:100%;
  }
}

/* =========================
   SMALL PHONES
========================= */
@media (max-width: 420px){

  .content{
    padding: 10px;
    padding-bottom: calc(
      var(--pwa-bottom-nav-h) + 18px + var(--pwa-safe-bottom)
    );
  }

  .activity-card{
    padding: 12px;
  }

  .activity-head{
    gap: 8px;
  }

  .activity-link{
    align-self: stretch;
    justify-content: flex-end;
  }

  .activity-meta{
    flex-direction: column;
    gap: 2px;
  }

  .pwa-tab{
    font-size: 10px;
  }

  .pwa-tab i{
    font-size: 17px;
  }

  .crumbs{
    max-width: calc(100% - 116px);
  }

  .user-chip{
    max-width: 72px;
  }
}

/* =========================
   LANDSCAPE MOBILE
========================= */
@media (max-width: 920px) and (orientation: landscape){

  :root{
    --pwa-bottom-nav-h: 56px;
  }

  .pwa-tab{
    flex-direction: row;
    gap: 6px;
    font-size: 11px;
  }

  .pwa-tab i{
    font-size: 15px;
  }

  .content{
    padding-bottom: calc(
      var(--pwa-bottom-nav-h) + 16px + var(--pwa-safe-bottom)
    );
  }
}

/* =========================
   PWA OFFLINE BANNER
========================= */
.pwa-offline-banner{
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--pwa-bottom-nav-h, 64px) + 12px + env(safe-area-inset-bottom));
  z-index: 2000;

  padding: 10px 14px;
  border-radius: 999px;

  background: #111827;
  color: #fff;

  font-size: 13px;
  font-weight: 700;
  text-align: center;

  box-shadow: 0 10px 30px rgba(15, 23, 42, .22);
}

.pwa-offline-banner[hidden]{
  display: none !important;
}

/* =========================
   PWA USER CHIP
========================= */
.user-chip{
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--brand-soft, #fde6c8);
  color: #111827;
  font-size: 12px;
  font-weight: 800;
  max-width: 160px;

  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Desktop default for PWA-only elements */
.show-pwa{
  display: none !important;
}

/* =========================================================
   PWA INSTALL CHIP
========================================================= */
.pwa-install-banner{
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  z-index: 1200;

  display: flex;
  align-items: center;
  gap: 10px;

  max-width: 520px;
  margin: 0 auto;

  padding: 10px 12px;
  border-radius: 999px;

  background: #111827;
  color: #fff;
  border: 1px solid rgba(255,255,255,.12);
  box-shadow: 0 14px 34px rgba(15,23,42,.28);

  animation: pwaBannerSlideUp .25s ease;
}

.pwa-install-banner[hidden]{
  display: none !important;
}

.pwa-install-icon{
  width: 34px;
  height: 34px;
  border-radius: 999px;

  display: flex;
  align-items: center;
  justify-content: center;

  background: var(--brand, #f7941d);
  color: #111827;
  font-size: 15px;
  flex-shrink: 0;
}

.pwa-install-copy{
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.pwa-install-copy strong{
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pwa-install-copy span{
  font-size: 11px;
  color: rgba(255,255,255,.72);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pwa-install-dismiss{
  min-height: 34px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  background: transparent;
  border-color: rgba(255,255,255,.25);
  color: #fff;
}

.pwa-install-action{
  min-height: 34px;
  padding: 0 13px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

@keyframes pwaBannerSlideUp{
  from{
    transform: translateY(20px);
    opacity: 0;
  }
  to{
    transform: translateY(0);
    opacity: 1;
  }
}

@media (max-width: 420px){
  .pwa-install-dismiss{
    display: none;
  }

  .pwa-install-copy span{
    display: none;
  }
}

/* =========================
   REDUCED MOTION
========================= */
@media (prefers-reduced-motion: reduce){

  *,
  *::before,
  *::after{
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}