/* ══════════════════════════════════════════════════════════════════════════
   Mobile responsive layer — kicks in below 900px, aggressive below 640px.
   Turns the 240px fixed sidebar into a slide-out drawer, tightens padding,
   makes tables horizontally scrollable, and stacks form fields.
   ══════════════════════════════════════════════════════════════════════════ */

/* ── Backdrop for the mobile drawer (invisible + not clickable on desktop) ── */
.mobile-nav-toggle,
.mobile-nav-backdrop {
  display: none;
}

@media (max-width: 900px) {

  /* Body no longer needs desktop side-scroll suppression */
  html, body { overflow-x: hidden; }

  /* ── Hamburger button (top-left, fixed) ── */
  .mobile-nav-toggle {
    display: flex;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 60;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    background: var(--bg-card-solid, #1e1e2e);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-primary);
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    transition: transform .15s, background .15s;
  }
  .mobile-nav-toggle:active { transform: scale(0.95); }
  .mobile-nav-toggle svg { width: 22px; height: 22px; stroke: currentColor; stroke-width: 2; fill: none; }

  /* ── Sidebar → slide-out drawer ── */
  #appShell > aside {
    position: fixed !important;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    max-width: 82vw;
    z-index: 55;
    transform: translateX(-105%);
    transition: transform .28s cubic-bezier(.4, 0, .2, 1);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.4);
  }
  #appShell.nav-open > aside {
    transform: translateX(0);
  }

  /* ── Backdrop when drawer is open ── */
  .mobile-nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity .28s;
  }
  #appShell.nav-open ~ .mobile-nav-backdrop,
  body.nav-open .mobile-nav-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  /* ── Main content — full width now, more top padding for hamburger ── */
  #appShell > main {
    width: 100%;
    max-width: 100%;
    max-height: none !important;
  }
  #appShell > main > div {
    padding: 68px 14px 20px !important;    /* room for hamburger up top */
    max-width: 100% !important;
  }

  /* Close drawer when a nav item is picked (JS also does this) */
  .sidebar-link {
    font-size: 15px;
    padding: 13px 14px;
  }

  /* ── Header row shrinks ── */
  .page-head {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 18px;
  }
  .page-head h2 { font-size: 22px; }
  .page-head .page-sub { font-size: 13px; }

  /* ── Stat cards → single column on phone ── */
  .grid { gap: 12px !important; }
  .grid.grid-cols-2, .grid.grid-cols-3, .grid.grid-cols-4,
  .grid.md\:grid-cols-2, .grid.md\:grid-cols-3, .grid.md\:grid-cols-4,
  .grid.lg\:grid-cols-2, .grid.lg\:grid-cols-3, .grid.lg\:grid-cols-4 {
    grid-template-columns: 1fr !important;
  }
  .stat-val { font-size: 28px; }

  /* ── Cards get tighter padding ── */
  .glass, .card {
    padding: 16px !important;
    border-radius: 12px;
  }

  /* ── Tables — horizontal scroll wrapper ── */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .table-wrap table {
    min-width: 640px;    /* preserves table layout instead of squashing */
  }

  /* ── Forms + input rows stack vertically ── */
  .flex.gap-3, .flex.gap-2, .flex.items-center.gap-3 {
    flex-wrap: wrap;
  }
  input[type="text"], input[type="password"], input[type="number"],
  input[type="email"], input[type="url"], select, textarea {
    font-size: 16px !important;   /* prevents iOS auto-zoom-on-focus */
  }

  /* ── Modal windows — full screen on phone ── */
  .modal, [id$="Modal"] .modal-card, [class*="modal"] > div {
    max-width: calc(100vw - 20px) !important;
    max-height: calc(100vh - 40px) !important;
  }

  /* ── Buttons in row → wrap and grow ── */
  .flex.gap-1, .flex.gap-1\.5 { flex-wrap: wrap; }
  .btn-sm { padding: 6px 10px; font-size: 12.5px; }

  /* ── Job rows get vertical layout ── */
  .job-head { flex-direction: column; align-items: flex-start; gap: 8px; }
  .job-actions { width: 100%; justify-content: flex-start; }
  .job-meta { flex-direction: column; align-items: flex-start; gap: 4px; }
  .job-stats { flex-wrap: wrap; gap: 8px !important; }

  /* ── Login card ── */
  .login-card { padding: 28px 22px; margin: 0 12px; }
}

/* ── Extra squeeze for phones under 640px ── */
@media (max-width: 640px) {
  #appShell > main > div {
    padding: 62px 10px 16px !important;
  }
  .glass, .card {
    padding: 14px !important;
  }
  .page-head h2 { font-size: 20px; letter-spacing: -.02em; }

  /* Truncate long emails aggressively */
  td .font-mono, td .text-\[11px\] {
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
    vertical-align: middle;
  }

  /* Hide the state dropdown in tables (opens a modal to change if needed) */
  .acc-state, .post-acc-state, .http-acc-state {
    width: 110px !important;
    font-size: 12px !important;
  }
}
