/**
 * Housing Society Management Portal - Mobile App Experience Stylesheet
 * Native App Navigation, Bottom Sheet Drawer, Launcher Grid & Feature Icons
 */

:root {
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
}

/* -------------------------------------------------------------
 * 1. Dedicated Icon Gradient Squircles
 * ----------------------------------------------------------- */
.app-icon-squircle {
  width: 50px;
  height: 50px;
  border-radius: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff !important;
  font-size: 1.5rem;
  flex-shrink: 0;
  position: relative;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
  user-select: none;
  -webkit-user-select: none;
}

.app-icon-squircle.sm {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  font-size: 1.25rem;
}

.app-icon-squircle.lg {
  width: 58px;
  height: 58px;
  border-radius: 18px;
  font-size: 1.8rem;
}

/* Palette Variations */
.icon-gradient-blue {
  background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.35);
}

.icon-gradient-indigo {
  background: linear-gradient(135deg, #6366f1 0%, #4338ca 100%);
  box-shadow: 0 6px 16px rgba(79, 70, 229, 0.35);
}

.icon-gradient-emerald {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  box-shadow: 0 6px 16px rgba(16, 185, 129, 0.35);
}

.icon-gradient-rose {
  background: linear-gradient(135deg, #f43f5e 0%, #be123c 100%);
  box-shadow: 0 6px 16px rgba(225, 29, 72, 0.35);
}

.icon-gradient-amber {
  background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  box-shadow: 0 6px 16px rgba(217, 119, 6, 0.35);
}

.icon-gradient-purple {
  background: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%);
  box-shadow: 0 6px 16px rgba(109, 40, 217, 0.35);
}

.icon-gradient-cyan {
  background: linear-gradient(135deg, #06b6d4 0%, #0e7490 100%);
  box-shadow: 0 6px 16px rgba(8, 145, 178, 0.35);
}

.icon-gradient-orange {
  background: linear-gradient(135deg, #f97316 0%, #c2410c 100%);
  box-shadow: 0 6px 16px rgba(234, 88, 12, 0.35);
}

.icon-gradient-teal {
  background: linear-gradient(135deg, #14b8a6 0%, #0f766e 100%);
  box-shadow: 0 6px 16px rgba(15, 118, 110, 0.35);
}

.icon-gradient-pink {
  background: linear-gradient(135deg, #ec4899 0%, #be185d 100%);
  box-shadow: 0 6px 16px rgba(219, 39, 119, 0.35);
}

.icon-gradient-slate {
  background: linear-gradient(135deg, #64748b 0%, #334155 100%);
  box-shadow: 0 6px 16px rgba(71, 85, 105, 0.35);
}

.icon-gradient-dark {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.35);
}

/* Badge overlay on icon */
.app-icon-squircle .icon-badge-pill {
  position: absolute;
  top: -4px;
  right: -5px;
  background: #ef4444;
  color: #ffffff;
  font-size: 0.68rem;
  font-weight: 800;
  line-height: 1;
  padding: 3px 6px;
  border-radius: 999px;
  border: 2px solid #ffffff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

/* -------------------------------------------------------------
 * 2. Mobile App Quick Launcher (Dashboard Widget)
 * ----------------------------------------------------------- */
.mobile-app-launcher {
  display: none; /* Shown on mobile via media query */
  background: #ffffff;
  border-radius: 20px;
  border: 1px solid rgba(226, 232, 240, 0.9);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.05);
  padding: 1.25rem 1rem 1rem;
  margin-bottom: 1.5rem;
  position: relative;
  overflow: hidden;
}

.launcher-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  padding: 0 4px;
}

.launcher-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.launcher-title {
  font-size: 0.98rem;
  font-weight: 800;
  color: #1e293b;
  margin: 0;
}

.launcher-badge {
  font-size: 0.72rem;
  font-weight: 700;
  background: #eef2ff;
  color: #4f46e5;
  padding: 2px 8px;
  border-radius: 20px;
  border: 1px solid #c7d2fe;
}

.launcher-all-btn {
  background: #f1f5f9;
  border: none;
  color: #4f46e5;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 20px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
  text-decoration: none;
}

.launcher-all-btn:hover {
  background: #e0e7ff;
  color: #3730a3;
}

.launcher-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px 6px;
}

/* App Tile (Individual Button in Launcher & Sheets) */
.app-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  text-decoration: none;
  background: transparent;
  border: none;
  border-radius: 14px;
  padding: 6px 2px;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.app-tile:active {
  transform: scale(0.92);
}

.app-tile:hover {
  background: rgba(241, 245, 249, 0.6);
}

.app-tile-label {
  margin-top: 7px;
  font-size: 0.73rem;
  font-weight: 600;
  color: #334155;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  max-width: 72px;
  word-break: break-word;
}

/* -------------------------------------------------------------
 * 3. Slide-Up Mobile App Sheet (All Features Bottom Drawer)
 * ----------------------------------------------------------- */
.mobile-app-sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1060;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.3s ease;
}

.mobile-app-sheet-backdrop.open {
  opacity: 1;
  visibility: visible;
}

.mobile-app-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-width: 600px;
  margin: 0 auto;
  max-height: 88vh;
  background: #ffffff;
  border-radius: 26px 26px 0 0;
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.28);
  z-index: 1070;
  display: flex;
  flex-direction: column;
  transform: translateY(105%);
  transition: transform 0.36s cubic-bezier(0.16, 1, 0.3, 1);
  padding-bottom: var(--sab);
  overflow: hidden;
}

.mobile-app-sheet.open {
  transform: translateY(0);
}

/* Top Grab Handle */
.sheet-drag-handle {
  width: 44px;
  height: 5px;
  background: #cbd5e1;
  border-radius: 999px;
  margin: 10px auto 4px;
  flex-shrink: 0;
  cursor: grab;
}

/* Sheet Top Bar */
.sheet-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem 0.5rem;
  border-bottom: 1px solid #f1f5f9;
}

.sheet-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sheet-header-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: #eef2ff;
  color: #4f46e5;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
}

.sheet-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 800;
  color: #0f172a;
}

.sheet-subtitle {
  font-size: 0.75rem;
  color: #64748b;
  display: block;
}

.sheet-close-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #f1f5f9;
  border: none;
  color: #64748b;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  cursor: pointer;
  transition: all 0.2s;
}

.sheet-close-btn:hover {
  background: #e2e8f0;
  color: #0f172a;
}

/* Search Bar Inside Drawer */
.sheet-search-wrapper {
  padding: 0.75rem 1.25rem 0.6rem;
  position: relative;
  background: #ffffff;
}

.sheet-search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
  border: 1.5px solid #e2e8f0;
  border-radius: 14px;
  padding: 8px 12px;
  transition: all 0.2s ease;
}

.sheet-search-box:focus-within {
  border-color: #4f46e5;
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12);
}

.sheet-search-box i {
  color: #94a3b8;
  font-size: 1.15rem;
}

.sheet-search-input {
  border: none;
  background: transparent;
  outline: none;
  width: 100%;
  font-size: 0.9rem;
  color: #0f172a;
  font-family: inherit;
}

.sheet-search-clear {
  border: none;
  background: transparent;
  color: #94a3b8;
  font-size: 1rem;
  cursor: pointer;
  padding: 0;
  display: none;
}

/* Scrollable Drawer Body */
.sheet-content-scroll {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.5rem 1.25rem 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.sheet-category-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sheet-category-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #64748b;
  margin: 0;
  padding-left: 2px;
}

.sheet-category-title .title-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4f46e5;
}

.sheet-tiles-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px 6px;
}

/* Empty Search Results Message */
.sheet-empty-search {
  text-align: center;
  padding: 2.5rem 1rem;
  color: #64748b;
  display: none;
}

.sheet-empty-search i {
  font-size: 2.5rem;
  color: #cbd5e1;
  margin-bottom: 8px;
}

/* -------------------------------------------------------------
 * 4. Responsive Media Queries
 * ----------------------------------------------------------- */
@media (max-width: 992px) {
  /* Prevent horizontal rubber-banding across entire layout */
  html, body {
    max-width: 100vw;
    overflow-x: hidden;
  }

  .app-container,
  .app-main,
  .app-content {
    max-width: 100vw;
    overflow-x: hidden;
    box-sizing: border-box;
  }

  .mobile-app-launcher {
    display: block;
  }

  /* Native Mobile App Header (Sticky with glassmorphism) */
  .app-header {
    position: sticky;
    top: 0;
    z-index: 90;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(226, 232, 240, 0.85);
    height: auto;
    min-height: calc(56px + var(--sat));
    padding: calc(0.45rem + var(--sat)) 0.85rem 0.45rem;
    box-shadow: 0 1px 6px rgba(15, 23, 42, 0.04);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }

  .header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1;
  }

  .page-title {
    font-size: 1.05rem !important;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
    color: #0f172a;
  }

  .header-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
  }

  .mobile-apps-header-btn {
    display: inline-flex !important;
  }

  /* Bottom Nav Safe-Area and Active Pill */
  .mobile-bottom-nav {
    height: calc(60px + var(--sab));
    padding-bottom: var(--sab);
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid rgba(226, 232, 240, 0.85);
    z-index: 1040;
  }

  .bottom-nav-item.active {
    color: #4f46e5;
  }

  .bottom-nav-item.active i {
    transform: translateY(-1px);
    color: #4f46e5;
  }

  .bottom-nav-item.active::after {
    content: '';
    display: block;
    width: 14px;
    height: 3px;
    background: #4f46e5;
    border-radius: 999px;
    margin-top: -1px;
    animation: pillPop 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  }

  @keyframes pillPop {
    from { transform: scaleX(0); }
    to { transform: scaleX(1); }
  }

  /* Ensure page contents don't get covered by bottom nav */
  .app-main {
    padding-bottom: calc(75px + var(--sab)) !important;
  }

  .app-footer {
    padding-bottom: calc(85px + var(--sab)) !important;
  }
}

/* -------------------------------------------------------------
 * 5. Screen Layout & Alignment (< 768px)
 * ----------------------------------------------------------- */
@media (max-width: 768px) {
  .app-content {
    padding: 0.85rem !important;
  }

  /* Dashboard Welcome Banner */
  .dashboard-welcome-banner,
  .portal-hero {
    padding: 1.15rem 1rem !important;
    border-radius: 18px !important;
    margin-bottom: 1.25rem !important;
    gap: 1rem !important;
  }

  .dashboard-welcome-banner h2,
  .portal-hero h1 {
    font-size: 1.25rem !important;
    line-height: 1.3 !important;
  }

  .dashboard-welcome-banner p,
  .portal-hero p {
    font-size: 0.78rem !important;
  }

  /* Financial Year Bar Mobile Alignment */
  .fy-card-body {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 12px !important;
    padding: 0.85rem 1rem !important;
  }

  /* Compact 2-Column Stats Grid (Modern App Cards) */
  .stats-grid {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
    margin-bottom: 1.25rem !important;
  }

  .stat-card {
    padding: 0.85rem !important;
    border-radius: 14px !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 8px !important;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04) !important;
  }

  .stat-card .stat-icon {
    width: 36px !important;
    height: 36px !important;
    font-size: 1.2rem !important;
    border-radius: 10px !important;
  }

  .stat-card .stat-info {
    width: 100%;
  }

  .stat-card .stat-info h3 {
    font-size: 1.25rem !important;
    margin: 2px 0 !important;
    word-break: break-word;
  }

  .stat-card .stat-info p {
    font-size: 0.72rem !important;
    margin: 0 !important;
    line-height: 1.25;
    color: #64748b;
  }

  /* Universal Mobile Filter Bar */
  .filter-bar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
    margin-bottom: 1rem !important;
  }

  .filter-bar > div {
    width: 100% !important;
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  .filter-bar form {
    width: 100% !important;
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  .filter-bar form .form-select,
  .filter-bar form .form-control {
    flex: 1 1 calc(50% - 4px) !important;
    min-width: 120px !important;
    width: auto !important;
  }

  .search-input-wrap {
    width: 100% !important;
    min-width: 0 !important;
  }

  .filter-bar .btn {
    flex: 1 1 auto !important;
    font-size: 0.82rem !important;
    padding: 0.5rem 0.75rem !important;
    justify-content: center !important;
  }

  /* Mobile Tables Ergonomics & Smooth Scrolling */
  .table-responsive {
    margin: 0 !important;
    border: none !important;
    border-radius: 0 !important;
    position: relative;
    -webkit-overflow-scrolling: touch;
    overflow-x: auto !important;
    scroll-behavior: smooth;
  }

  .table-slide-wrapper {
    position: relative !important;
    width: 100% !important;
    overflow: visible !important;
  }

  /* Floating Slide Arrows (Accessible & Smartly Positioned on Mobile) */
  .table-slide-arrow {
    position: absolute !important;
    top: clamp(65px, 45%, 210px) !important;
    transform: translateY(-50%) !important;
    width: 38px !important;
    height: 38px !important;
    border-radius: 50% !important;
    background: rgba(255, 255, 255, 0.98) !important;
    color: #4f46e5 !important;
    border: 1.5px solid #cbd5e1 !important;
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.22) !important;
    display: none;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    z-index: 25 !important;
    backdrop-filter: blur(8px) !important;
    -webkit-backdrop-filter: blur(8px) !important;
    transition: opacity 0.2s ease, transform 0.15s ease, background 0.15s ease !important;
    font-size: 1.4rem !important;
  }

  .table-slide-arrow.left {
    left: 6px !important;
  }

  .table-slide-arrow.right {
    right: 6px !important;
  }

  .table-slide-arrow:active:not(:disabled) {
    transform: translateY(-50%) scale(0.9) !important;
    background: #4f46e5 !important;
    color: #ffffff !important;
  }

  .table-slide-arrow:disabled {
    opacity: 0 !important;
    pointer-events: none !important;
    visibility: hidden !important;
  }

  .table-slide-wrapper.has-overflow > .table-slide-arrow {
    display: flex !important;
  }

  /* Scroll Shadow Indicators on Left and Right table edges */
  .table-slide-wrapper.has-overflow::before,
  .table-slide-wrapper.has-overflow::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    width: 16px;
    pointer-events: none;
    z-index: 15;
    transition: opacity 0.25s ease;
  }

  .table-slide-wrapper.has-overflow::before {
    left: 0;
    background: linear-gradient(to right, rgba(15, 23, 42, 0.08), transparent);
    opacity: 0;
  }

  .table-slide-wrapper.has-overflow::after {
    right: 0;
    background: linear-gradient(to left, rgba(15, 23, 42, 0.08), transparent);
    opacity: 0;
  }

  .table-slide-wrapper.has-left-overflow::before {
    opacity: 1;
  }

  .table-slide-wrapper.has-right-overflow::after {
    opacity: 1;
  }

  /* Dedicated Mobile Table Navigation Bar on top of all tables */
  .mobile-table-nav-bar {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 6px 12px !important;
    background: #f8fafc !important;
    border-bottom: 1px solid #e2e8f0 !important;
    font-size: 0.74rem !important;
    color: #64748b !important;
    font-weight: 600 !important;
    user-select: none;
  }

  .table-slide-wrapper:not(.has-overflow) .mobile-table-nav-bar {
    display: none !important;
  }

  .mobile-table-nav-bar .nav-hint {
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    color: #4f46e5 !important;
    font-size: 0.74rem !important;
  }

  .mobile-table-nav-bar .nav-hint i {
    font-size: 0.95rem;
    animation: hintArrowBounce 1.6s infinite ease-in-out;
  }

  @keyframes hintArrowBounce {
    0%, 100% { transform: translateX(0); }
    50% { transform: translateX(3px); }
  }

  .mobile-table-nav-bar .nav-arrows {
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
  }

  .mobile-table-nav-bar .btn-nav-slide {
    width: 32px !important;
    height: 28px !important;
    border-radius: 7px !important;
    border: 1px solid #cbd5e1 !important;
    background: #ffffff !important;
    color: #1e293b !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 1.15rem !important;
    cursor: pointer !important;
    transition: all 0.15s ease !important;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05) !important;
  }

  .mobile-table-nav-bar .btn-nav-slide:active:not(:disabled) {
    transform: scale(0.92) !important;
    background: #4f46e5 !important;
    color: #ffffff !important;
  }

  .mobile-table-nav-bar .btn-nav-slide:disabled {
    opacity: 0.3 !important;
    cursor: not-allowed !important;
  }

  .table {
    font-size: 0.82rem !important;
    min-width: 620px;
    margin-bottom: 0 !important;
  }

  .table th, .table td {
    padding: 0.65rem 0.75rem !important;
    white-space: nowrap;
  }

  .card-header {
    padding: 0.85rem 1rem !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 6px !important;
  }

  .card-header .card-title {
    font-size: 1rem !important;
  }

  .card-header .card-subtitle {
    font-size: 0.74rem !important;
  }

  .card-header > div:last-child {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .card {
    border-radius: 16px !important;
    margin-bottom: 1.25rem !important;
  }

  /* Mobile Horizontal Scrollable Tab Bar */
  .nav-tabs {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    gap: 8px !important;
    padding-bottom: 6px !important;
    border-bottom: 2px solid #e2e8f0 !important;
    margin-bottom: 1.25rem !important;
  }

  .nav-tab-btn {
    white-space: nowrap !important;
    flex-shrink: 0 !important;
    padding: 0.55rem 0.95rem !important;
    font-size: 0.82rem !important;
    border-radius: 8px !important;
    border-bottom: none !important;
    background: #f8fafc !important;
    color: #475569 !important;
  }

  .nav-tab-btn.active {
    background: #4f46e5 !important;
    color: #ffffff !important;
    font-weight: 700 !important;
  }

  .nav-tab-btn .badge {
    display: none !important;
  }

  /* Universal Responsive Page & Form Grids on Mobile (< 768px):
     Any multi-column layout grid across the entire portal (e.g. 2fr 1fr, 1fr 1fr, minmax)
     automatically collapses into 1 clean column on mobile phones, with 100% width */
  div[style*="grid-template-columns"]:not(.stats-grid):not(.launcher-grid):not(.sheet-tiles-grid):not(.months-grid):not(.keep-grid),
  form div[style*="grid-template-columns"]:not(.stats-grid):not(.launcher-grid):not(.sheet-tiles-grid):not(.months-grid):not(.keep-grid),
  form > div[style*="grid-template-columns"]:not(.stats-grid):not(.launcher-grid):not(.sheet-tiles-grid):not(.months-grid):not(.keep-grid),
  .card-body > div[style*="grid-template-columns"]:not(.stats-grid):not(.launcher-grid):not(.sheet-tiles-grid):not(.months-grid):not(.keep-grid),
  .app-content > div[style*="grid-template-columns"]:not(.stats-grid):not(.launcher-grid):not(.sheet-tiles-grid):not(.months-grid):not(.keep-grid),
  .form-row,
  .form-grid-responsive {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 14px !important;
    width: 100% !important;
  }

  /* Reset all column spans so no element overflows or squeezes */
  div[style*="grid-template-columns"]:not(.keep-grid):not(.stats-grid):not(.launcher-grid):not(.sheet-tiles-grid) > *,
  div[style*="grid-template-columns"]:not(.keep-grid):not(.stats-grid):not(.launcher-grid):not(.sheet-tiles-grid) > [style*="grid-column"],
  form div[style*="grid-template-columns"]:not(.keep-grid) > *,
  .card-body > div[style*="grid-template-columns"]:not(.keep-grid) > *,
  form .form-group[style*="grid-column"],
  .form-row > *,
  [style*="grid-column: span"],
  .form-grid-responsive > * {
    grid-column: 1 / -1 !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  /* When forms use flex rows, ensure children stack cleanly on phones */
  .form-row[style*="display: flex"],
  form .form-row {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
  }
  .form-row[style*="display: flex"] > .form-group,
  form .form-row > .form-group {
    flex: 1 1 100% !important;
    width: 100% !important;
    margin-bottom: 0 !important;
  }

  /* Mobile Radio & Checkbox Card Tiles */
  .mobile-radio-group,
  .transfer-mode-group {
    display: flex !important;
    flex-direction: column !important;
    gap: 8px !important;
    width: 100% !important;
  }

  .mobile-radio-group label,
  .transfer-mode-group label {
    display: flex !important;
    align-items: center !important;
    gap: 10px !important;
    padding: 10px 14px !important;
    background: #ffffff !important;
    border: 1.5px solid #e2e8f0 !important;
    border-radius: 12px !important;
    font-size: 0.85rem !important;
    font-weight: 600 !important;
    width: 100% !important;
    box-sizing: border-box !important;
    cursor: pointer !important;
    transition: all 0.15s ease !important;
  }

  .mobile-radio-group label:has(input[type="radio"]:checked),
  .transfer-mode-group label:has(input[type="radio"]:checked) {
    border-color: #4f46e5 !important;
    background: #eef2ff !important;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.12) !important;
  }

  .mobile-radio-group input[type="radio"],
  .transfer-mode-group input[type="radio"] {
    width: 18px !important;
    height: 18px !important;
    accent-color: #4f46e5 !important;
    flex-shrink: 0 !important;
    margin: 0 !important;
  }

  .form-group {
    margin-bottom: 0.85rem !important;
  }

  .form-label {
    font-size: 0.82rem !important;
    font-weight: 600 !important;
    margin-bottom: 5px !important;
    display: block;
  }

  .form-control,
  .form-select,
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="date"],
  input[type="month"],
  input[type="tel"],
  select,
  textarea {
    font-size: 16px !important; /* Prevents auto-zoom in iOS Safari */
    padding: 0.7rem 0.85rem !important;
    height: auto !important;
    border-radius: 10px !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  /* Native-style File Upload Input */
  input[type="file"].form-control,
  .form-control[type="file"] {
    padding: 8px 12px !important;
    height: auto !important;
    min-height: 48px !important;
    background: #f8fafc !important;
    border: 1.5px dashed #cbd5e1 !important;
    border-radius: 12px !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    font-size: 0.85rem !important;
    color: #475569 !important;
    box-sizing: border-box !important;
    transition: border-color 0.2s, background-color 0.2s !important;
  }

  input[type="file"].form-control:hover,
  .form-control[type="file"]:hover {
    border-color: #4f46e5 !important;
    background: #eef2ff !important;
  }

  input[type="file"]::file-selector-button,
  input[type="file"]::-webkit-file-upload-button {
    background: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%) !important;
    color: #ffffff !important;
    border: none !important;
    padding: 6px 14px !important;
    border-radius: 8px !important;
    font-weight: 700 !important;
    font-size: 0.8rem !important;
    margin-right: 12px !important;
    cursor: pointer !important;
    box-shadow: 0 2px 6px rgba(79, 70, 229, 0.25) !important;
    transition: transform 0.15s ease !important;
  }

  input[type="file"]::file-selector-button:active,
  input[type="file"]::-webkit-file-upload-button:active {
    transform: scale(0.96) !important;
  }

  /* Full-width Stacked Action Buttons on Mobile (< 768px) */
  .form-actions-bar,
  form > div[style*="justify-content: flex-end"],
  form > div[style*="justify-content: space-between"]:last-child {
    display: flex !important;
    flex-direction: column-reverse !important;
    gap: 10px !important;
    width: 100% !important;
    margin-top: 1.25rem !important;
    margin-bottom: 2rem !important;
  }

  .form-actions-bar .btn,
  form > div[style*="justify-content: flex-end"] .btn,
  form > div[style*="justify-content: space-between"]:last-child .btn {
    width: 100% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0.85rem 1rem !important;
    font-size: 1rem !important;
    min-height: 48px !important;
    border-radius: 12px !important;
    font-weight: 700 !important;
    box-shadow: 0 2px 6px rgba(15, 23, 42, 0.08) !important;
  }

  /* Safe Area Bottom Spacing for Form Pages */
  .mobile-page-container {
    padding-bottom: calc(100px + var(--sab)) !important;
  }

  /* Modal Dialog Bottom-sheet on Mobile */
  .modal-overlay {
    padding: 10px !important;
    display: flex !important;
    align-items: flex-end !important;
  }

  .modal-container {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 20px 20px 0 0 !important;
    margin: 0 !important;
    max-height: 85vh !important;
    padding: 1.25rem 1rem !important;
    box-shadow: 0 -10px 40px rgba(15, 23, 42, 0.25) !important;
  }

  /* Mobile Searchable Flat Dropdown (Slide-up Bottom Sheet on phone) */
  .property-dropdown-menu,
  .portal-flat-dropdown-menu {
    position: fixed !important;
    top: auto !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 22px 22px 0 0 !important;
    max-height: 72vh !important;
    box-shadow: 0 -10px 35px rgba(15, 23, 42, 0.3) !important;
    z-index: 1080 !important;
  }

  /* Auth / Login Page Mobile Ergonomics */
  .auth-wrapper {
    padding: 1rem !important;
    min-height: 100vh !important;
    align-items: center !important;
  }

  .auth-card {
    padding: 1.5rem 1.25rem !important;
    border-radius: 20px !important;
    width: 100% !important;
    max-width: 420px !important;
  }
}

/* Custom Scrollbar for Drawer */
.sheet-content-scroll::-webkit-scrollbar {
  width: 5px;
}
.sheet-content-scroll::-webkit-scrollbar-track {
  background: transparent;
}
.sheet-content-scroll::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 999px;
}

@media (max-width: 480px) {
  .launcher-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 10px 4px;
  }

  .sheet-tiles-grid {
    grid-template-columns: repeat(4, 1fr);
    gap: 10px 4px;
  }

  .app-icon-squircle {
    width: 46px;
    height: 46px;
    border-radius: 13px;
    font-size: 1.35rem;
  }

  .app-tile-label {
    font-size: 0.7rem;
    max-width: 66px;
  }
}

@media (max-width: 360px) {
  .launcher-grid,
  .sheet-tiles-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .stats-grid {
    grid-template-columns: 1fr !important;
  }
}


