/* Mobile / PWA overlay on top of the desktop style.css.
   Desktop layout is a fixed 220px sidebar + main. On phones we drop the sidebar to a
   bottom tab bar, stack the content, and make panels/modals full-bleed. */

/* Burger lives only on mobile */
.nav-burger { display: none; background: transparent; border: none; padding: 6px; color: var(--text-primary); }

/* "More" tab is mobile-only — hidden in the desktop sidebar (which lists every module). */
.nav-more { display: none; }

/* Dashboard quick actions that target desktop-only modules are hidden on the web
   build so they aren't dead buttons. (html.vela-web is set inline.) Accounting now
   ships on web (cloud-synced), so only Memory stays hidden here. */
.vela-web [data-go="memory"] { display: none !important; }

@media (max-width: 760px) {
  html, body { overflow: auto; }
  body { flex-direction: column; }

  /* ---- Sidebar becomes a bottom tab bar ---- */
  #sidebar {
    order: 2;
    position: fixed; left: 0; right: 0; bottom: 0;
    width: 100%; min-width: 0; height: auto;
    flex-direction: row;
    padding: 0; padding-bottom: env(safe-area-inset-bottom);
    border-right: none; border-top: 1px solid var(--border);
    z-index: 1000;
  }
  #vela-logo, #sidebar-footer { display: none; }
  #nav {
    flex-direction: row; justify-content: space-around;
    gap: 0; padding: 0; width: 100%;
  }
  /* Bottom bar = 4 primary tabs + More. Overflow modules live in the More sheet. */
  #nav .nav-item:not(.nav-primary) { display: none; }
  #nav-more { display: flex; }
  .nav-item, #nav-more {
    position: relative; flex: 1;
    flex-direction: column; gap: 4px;
    justify-content: center; align-items: center;
    padding: 9px 4px 7px; border: none; border-radius: 0;
    font-size: 10.5px; font-weight: 500; letter-spacing: .1px;
    color: var(--text-muted); text-decoration: none; background: transparent;
  }
  .nav-item i, #nav-more i { width: 22px; height: 22px; }
  .nav-item.active, #nav-more.active { color: var(--accent); background: transparent; }
  /* Clean accent indicator above the active tab */
  .nav-item.active::before, #nav-more.active::before {
    content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
    width: 26px; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent);
  }

  /* ---- Main + top bar ---- */
  #main { order: 1; height: auto; min-height: 100vh; }
  #topbar {
    position: sticky; top: 0; z-index: 900;
    height: auto; min-height: 56px; padding: 8px 14px 10px; gap: 8px;
    background: var(--bg-base);
    flex-wrap: wrap;
    padding-top: calc(8px + env(safe-area-inset-top));
  }
  .nav-burger { display: none; } /* bottom bar replaces it; keep hidden */
  #module-title { font-size: 16px; flex: 1 1 auto; }
  .topbar-right { gap: 8px; flex: 1 1 100%; flex-wrap: wrap; } /* search drops to its own row */
  #global-search { display: block; flex: 1 1 140px; width: auto; } /* searchable on mobile */
  .ccp-pill { padding: 7px 10px; font-size: 11px; flex: 0 0 auto; }

  #content { padding: 16px 14px 90px; } /* bottom padding clears the tab bar */

  /* ---- Density / grids ---- */
  .metrics { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; }
  .dash-grid { grid-template-columns: 1fr !important; }
  .memory-layout { grid-template-columns: 1fr !important; }  /* stack the section nav above content */
  .page-head { gap: 10px; }
  .page-head h2 { font-size: 15px; }

  /* Notification bell: a touch larger + higher-contrast so it doesn't read as a stray dot */
  .notif-bell { width: 38px; height: 38px; flex: 0 0 auto; color: var(--text-primary); }
  .notif-bell i { width: 19px; height: 19px; }

  /* Tables scroll horizontally instead of squishing */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 540px; }

  /* Kanban scrolls sideways, columns sized for thumb */
  .kanban { display: flex; overflow-x: auto; gap: 12px; -webkit-overflow-scrolling: touch; }
  .kan-col { min-width: 78vw; }

  /* Map height for small screens */
  #map { height: 56vh !important; }

  /* Modals + detail panel go full-screen */
  .modal { width: 92vw !important; max-width: 92vw; max-height: 86vh; overflow-y: auto; }
  .form-grid { grid-template-columns: 1fr !important; }
  #detail-panel {
    width: 100% !important; max-width: 100%;
    left: 0; right: 0;
    z-index: 1100; /* above the bottom tab bar (z-index 1000) */
  }
  /* The panel covers the topbar AND the bottom tabs, so its own close button is the
     only way out — keep it clear of the notch/status bar and make it a fat tap target.
     (Back button / backdrop also close it now, but this stays the obvious affordance.) */
  #detail-panel .dp-head { padding-top: calc(22px + env(safe-area-inset-top)); }
  #detail-panel .dp-close {
    font-size: 28px; line-height: 1; padding: 10px 14px; margin: -6px -6px 0 0;
    min-width: 44px; min-height: 44px;
  }
  #detail-backdrop { z-index: 1099; } /* just under the panel, above the tab bar */
  #modal-root { z-index: 1200; }

  /* Email composer stacks (drop the side column) */
  .email-layout { display: flex !important; flex-direction: column; gap: 14px; }
  .ac-list.open { max-height: 240px; overflow-y: auto; }

  /* Bigger touch targets */
  button { padding: 11px 14px; }
  .src-btn { padding: 9px 12px; }
  input, select, textarea { font-size: 16px; } /* prevents iOS zoom-on-focus */
}

/* Small phones: single-column metrics */
@media (max-width: 420px) {
  .metrics { grid-template-columns: 1fr !important; }
}

/* ---- "More" bottom sheet (mobile overflow nav) ---- */
#more-sheet { position: fixed; inset: 0; z-index: 1300; display: none; }
#more-sheet.open { display: block; }
#more-sheet .more-backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,.5);
  opacity: 0; transition: opacity .2s ease;
}
#more-sheet.open .more-backdrop { opacity: 1; }
#more-sheet .more-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--bg-panel); border-top: 1px solid var(--border);
  border-radius: 18px 18px 0 0; padding: 10px 16px calc(20px + env(safe-area-inset-bottom));
  box-shadow: 0 -12px 40px rgba(0,0,0,.45);
  transform: translateY(100%); transition: transform .24s cubic-bezier(.22,.61,.36,1);
}
#more-sheet.open .more-panel { transform: translateY(0); }
#more-sheet .more-grip {
  width: 36px; height: 4px; border-radius: 2px; background: var(--border);
  margin: 4px auto 12px;
}
#more-sheet .more-title {
  font-size: 12px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-muted); margin: 0 4px 12px;
}
#more-sheet .more-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
#more-sheet .more-row {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 16px 8px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--bg-base); color: var(--text-primary);
  font-size: 12px; font-weight: 500; cursor: pointer;
}
#more-sheet .more-row:active { background: var(--bg-hover); }
#more-sheet .more-row i { width: 22px; height: 22px; color: var(--accent); }
