/* ============================================================
   Tailorly mobile responsive overrides
   Loaded after each page's embedded <style>, so these win.
   Breakpoints: 900px (tablet), 720px (mobile), 420px (small)
============================================================ */

/* -------- universal: prevent horizontal overflow -------- */
@media (max-width: 900px) {
  html, body { overflow-x: hidden; }
  img, svg, video { max-width: 100%; height: auto; }
}

/* ============================================================
   TOP NAV (index, pricing, resources, plan-features)
============================================================ */
@media (max-width: 720px) {
  nav.top .row,
  nav.top .nav-links,
  nav.top .links {
    gap: 8px !important;
  }
  nav.top .nav-links a:not(.btn),
  nav.top .links a:not(.btn) {
    display: none !important;
  }
  nav.top .logo { font-size: 20px !important; }
  .btn { padding: 7px 11px !important; font-size: 12.5px !important; }
}

/* ============================================================
   INDEX.HTML — hero + demo sections
============================================================ */
@media (max-width: 900px) {
  .hero { padding: 56px 0 36px !important; }
  .hero h1 { font-size: clamp(34px, 8vw, 48px) !important; }
  .hero p, .hero .sub { font-size: 16px !important; }
  .hero-cta { flex-wrap: wrap; gap: 10px; }

  /* Stack any 2-3 column section grid */
  section .grid-2,
  section .grid-3,
  section .two-col,
  section .three-col,
  .how-grid,
  .how-row,
  .features-grid,
  .stack-row {
    grid-template-columns: 1fr !important;
    display: grid !important;
    gap: 16px !important;
  }

  /* Demo cards (chat / funnel / tailor / deck) — make sure they render */
  .demo-card,
  .card,
  .hw-card,
  .hw1, .hw2, .hw3, .hw4 {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }

  /* Chat demo: shrink avatar, allow wrap */
  .chat-win, .chat-row, .msg-row {
    width: 100% !important;
    max-width: 100% !important;
  }
  .chat-msg, .msg-bubble { max-width: 86% !important; }
  .chip-row, .chips, .picker {
    flex-wrap: wrap !important;
    gap: 6px !important;
  }

  /* Funnel/match icons — keep contained */
  .funnel, .funnel-stage, .match-stage {
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Source marquee — pause animation if it overflows weirdly */
  .marquee, .marquee-track { width: 100% !important; }

  /* Card deck (04 / control) */
  .card-deck, .deck { width: 100% !important; }
  .card-meta-row {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }
  .card-meta-cell { flex: 1 1 45% !important; min-width: 0 !important; }

  /* Pricing plan grid on landing */
  .pricing-grid, .plans, .plan-grid {
    grid-template-columns: 1fr !important;
  }
}

@media (max-width: 720px) {
  section { padding-left: 16px !important; padding-right: 16px !important; }
  .wrap { padding-left: 16px !important; padding-right: 16px !important; }
  .hw4-btn-tailor, .hw4-btn-apply, .hw4-btn-skip {
    flex: 1 1 30% !important;
    font-size: 12px !important;
    padding: 8px 6px !important;
  }
}

/* ============================================================
   DASHBOARD SHELL (dashboard, dashboard-onboarding,
   resume-preview, master-resume-builder, job-search-setup,
   tier2-deep-build)
============================================================ */
@media (max-width: 900px) {
  .shell, .db-shell {
    grid-template-columns: 1fr !important;
    display: block !important;
  }
  .sidebar, .db-side, .side {
    position: fixed !important;
    top: 0; left: 0;
    height: 100vh;
    width: 280px !important;
    max-width: 86vw !important;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 0 12px 40px rgba(0,0,0,.18);
    overflow-y: auto;
  }
  .sidebar.is-open, .db-side.is-open, .side.is-open {
    transform: translateX(0);
  }
  /* Backdrop appears when sidebar is open */
  body.sb-open::before {
    content: "";
    position: fixed; inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 150;
    transition: opacity .25s ease;
  }
  .main, .db-main, .builder-main, .layout {
    width: 100% !important;
    max-width: 100% !important;
    padding: 16px !important;
    box-sizing: border-box;
  }
  .main-col { padding: 0 !important; }

  /* Hamburger trigger — show on mobile */
  .sidebar-fab, .mobile-menu-btn {
    display: flex !important;
    position: fixed !important;
    top: 14px; left: 14px;
    z-index: 180;
    width: 40px; height: 40px;
    border-radius: 10px;
    background: var(--ts-ink, #16161a);
    color: #fff;
    align-items: center; justify-content: center;
    border: none; cursor: pointer;
    box-shadow: 0 4px 14px rgba(0,0,0,.2);
  }
  .sidebar-fab i, .mobile-menu-btn i { width: 20px; height: 20px; }
}

/* ============================================================
   DASHBOARD DRAWER — slide up from bottom on mobile
============================================================ */
@media (max-width: 900px) {
  .drawer {
    position: fixed !important;
    bottom: 0 !important; left: 0 !important; right: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    max-height: 80vh !important;
    border-left: none !important;
    border-top: 1px solid var(--ts-border) !important;
    border-radius: 16px 16px 0 0 !important;
    z-index: 220 !important;
    box-shadow: 0 -10px 40px rgba(0,0,0,.18) !important;
    /* Closed-state: slid below viewport. JS toggles .is-open to reveal. */
    transform: translateY(100%) !important;
    transition: transform .25s cubic-bezier(0.22,1,0.36,1) !important;
    pointer-events: none !important;
  }
  .drawer.is-open {
    transform: translateY(0) !important;
    pointer-events: auto !important;
  }
}

/* ============================================================
   STEP / PROGRESS BARS — horizontal scroll on mobile
============================================================ */
@media (max-width: 900px) {
  .prog, .progress, .builder-header .progress, .hdr .prog {
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 4px;
  }
  .prog::-webkit-scrollbar,
  .progress::-webkit-scrollbar { display: none; }
  .prog .stp, .progress .prog-step {
    flex-shrink: 0 !important;
    white-space: nowrap;
    font-size: 12px !important;
  }
  .prog .stp-line, .progress .prog-line {
    flex-shrink: 0 !important;
    min-width: 18px !important;
  }
}

@media (max-width: 720px) {
  .builder-header, .hdr, .db-header {
    flex-wrap: wrap !important;
    padding: 12px 14px !important;
    gap: 8px !important;
  }
  .builder-header .logo, .hdr .logo, .db-header .db-logo,
  .hdr-back, .hdr-actions, .db-back, .tier-badge, .upgrade-pill, .db-badge {
    font-size: 12px !important;
  }
  /* Hide multi-step progress bars entirely on mobile — replace with compact pill */
  .builder-header .progress, .hdr .prog {
    display: none !important;
  }
  /* Show a compact "Step X of Y · {label}" pill if author included one */
  .progress-mobile, .prog-mobile {
    display: inline-flex !important;
    align-items: center; gap: 6px;
    font-size: 11px; font-weight: 600;
    padding: 5px 10px; border-radius: 99px;
    background: rgba(22,22,26,.05); color: #16161a;
    letter-spacing: .02em;
  }
  .hdr-actions { gap: 6px !important; }
  .upgrade-pill { padding: 5px 9px !important; }
  .tier-badge { padding: 4px 8px !important; }
}

/* ============================================================
   APP-PAGE TOPBAR — pad left for hamburger on mobile
============================================================ */
@media (max-width: 900px) {
  .topbar, .db-topbar, .builder-topbar {
    padding-left: 64px !important;
  }
  /* Pages with a sidebar (resume-preview uses `aside.side`) — pad the .hdr too */
  body:has(aside.side) .hdr {
    padding-left: 64px !important;
  }
  /* Pages without a sidebar (job-search-setup) — keep .hdr edge-to-edge */
  body:not(:has(aside.side)):not(:has(.sidebar)):not(:has(.db-side)) .hdr {
    padding-left: 14px !important;
  }
}

/* ============================================================
   RESUME-PREVIEW floating toolbar → flow layout
============================================================ */
@media (max-width: 720px) {
  .doc-toolbar, .resume-toolbar, .preview-toolbar {
    position: static !important;
    transform: none !important;
    width: 100% !important;
    margin: 8px 0 12px !important;
    flex-wrap: wrap !important;
    justify-content: flex-start !important;
  }
  /* Some pages name it differently */
  [class*="toolbar"][class*="preview"],
  [class*="preview"][class*="actions"] {
    position: static !important;
    transform: none !important;
  }
}

/* ============================================================
   NAV BUTTONS no-wrap on tight viewports
============================================================ */
@media (max-width: 720px) {
  nav.top .btn,
  nav.top a.btn,
  nav.top .nav-links a.btn,
  nav .btn-sm,
  nav .btn-primary-sm,
  nav .btn-outline,
  nav.top .links a.btn {
    white-space: nowrap !important;
  }
}

/* ============================================================
   JOB-SEARCH-SETUP layout (header + .layout grid)
============================================================ */
@media (max-width: 900px) {
  .layout {
    display: block !important;
    grid-template-columns: 1fr !important;
    padding: 16px !important;
  }
  .layout .left, .layout .right {
    width: 100% !important;
    max-width: 100% !important;
  }
  .layout .right { margin-top: 20px; }
  .chip-group { flex-wrap: wrap !important; gap: 6px !important; }
  .chip { font-size: 12.5px !important; padding: 7px 11px !important; }
}

/* ============================================================
   RESUME-PREVIEW shell (3-col → 1-col)
============================================================ */
@media (max-width: 900px) {
  .preview-shell, .preview-cols, .resume-preview-shell {
    grid-template-columns: 1fr !important;
    display: block !important;
  }
  .preview-side, .preview-aside, .preview-toc {
    position: static !important;
    width: 100% !important;
    margin-bottom: 16px;
  }
  .preview-doc, .resume-doc, .doc-preview {
    width: 100% !important;
    max-width: 100% !important;
    padding: 24px !important;
    font-size: 13px !important;
  }
}

/* ============================================================
   MASTER-RESUME-BUILDER (.builder-main wide step layout)
============================================================ */
@media (max-width: 900px) {
  .builder-main, .step, .step-body {
    padding: 16px !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
  }
  .step-h, .step h1 { font-size: clamp(24px, 6vw, 32px) !important; }
  .ex-card, .ex-grid {
    grid-template-columns: 1fr !important;
    padding: 16px !important;
  }
}

/* ============================================================
   TIER2-DEEP-BUILD (.db-shell side+main)
============================================================ */
@media (max-width: 900px) {
  .db-shell {
    display: block !important;
    grid-template-columns: 1fr !important;
  }
  .db-side {
    /* Already covered by sidebar rule above, but force same behavior */
    width: 280px !important;
  }
  .db-main, .db-content {
    width: 100% !important;
    padding: 16px !important;
  }
  .db-step-item { padding: 12px !important; }
}

/* ============================================================
   PRICING — table-style plan compare → stack
============================================================ */
@media (max-width: 720px) {
  .compare-table, .plans-compare {
    font-size: 13px !important;
  }
}

/* ============================================================
   RESOURCES (already responsive but add safety nets)
============================================================ */
@media (max-width: 720px) {
  .res-hero { padding: 36px 0 24px !important; }
  .res-h { font-size: clamp(28px, 7vw, 38px) !important; }
}

/* ============================================================
   FOOTER stack
============================================================ */
@media (max-width: 720px) {
  footer .row {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 10px !important;
  }
  footer .links { flex-wrap: wrap; gap: 12px !important; }
}

/* ============================================================
   DASHBOARD JOB ROWS — card layout on mobile
============================================================ */
@media (max-width: 720px) {
  .list-head { display: none !important; }
  .job-row {
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 6px !important;
    padding: 16px 18px !important;
    grid-template-columns: none !important;
    position: relative !important;
    border-bottom: 1px solid var(--ts-border, #eee5d8) !important;
  }
  .job-row > * {
    width: 100% !important;
    min-width: 0 !important;
    text-align: left !important;
    overflow: visible !important;
    text-overflow: clip !important;
    white-space: normal !important;
  }
  /* Score chip pinned top-right */
  .job-row > *:first-child {
    position: absolute !important;
    top: 14px !important; right: 16px !important;
    width: auto !important;
  }
  /* Title gets prominence; pad-right so score doesn't overlap */
  .job-row > *:nth-child(2) {
    font-size: 14.5px !important;
    font-weight: 600 !important;
    padding-right: 56px !important;
  }
  /* Meta cells render as small grey text */
  .job-row > *:nth-child(n+3) {
    font-size: 12px !important;
    color: var(--ts-ink-3, #6b6b73) !important;
  }
  /* Toolbar: stack search above chips on mobile so search gets full width */
  .toolbar {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
    overflow-x: visible !important;
    flex-wrap: wrap !important;
    padding: 10px 14px !important;
  }
  .toolbar__search {
    flex: 1 1 100% !important;
    width: 100% !important;
    min-width: 0 !important;
  }
  .toolbar__search input { width: 100% !important; min-width: 0 !important; }
  .toolbar > *:not(.toolbar__search) {
    flex: 0 0 auto;
  }
  /* Chip strip becomes horizontal-scroll row */
  .tabs, .filter-bar, .chip-row.filters {
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    width: 100% !important;
  }
}

/* ============================================================
   RESUME-PREVIEW header collision fix
   .hdr has back, logo, identity tabs, and actions on one row.
   On mobile, stack actions onto a second row.
============================================================ */
@media (max-width: 720px) {
  .hdr {
    flex-wrap: wrap !important;
    height: auto !important;
    padding: 10px 14px 10px 64px !important;
    gap: 8px !important;
  }
  .hdr-actions {
    order: 99;
    width: 100%;
    justify-content: flex-end !important;
    margin-left: 0 !important;
  }
  .id-tabs {
    order: 98;
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap !important;
  }
}

/* ============================================================
   DASHBOARD KPI tiles + filter tabs
============================================================ */
@media (max-width: 720px) {
  .stats {
    flex-wrap: wrap !important;
  }
  .stats .stat {
    flex: 1 1 50% !important;
    min-width: 0 !important;
    border-right: none !important;
    border-bottom: 1px solid var(--ts-border, #eee5d8) !important;
    padding: 12px 14px !important;
  }
  .stats .stat:nth-child(odd) {
    border-right: 1px solid var(--ts-border, #eee5d8) !important;
  }
  .stats .stat:nth-last-child(-n+2) {
    border-bottom: none !important;
  }
  /* Filter chips horizontal scroll instead of cutting off */
  .tabs, .filter-bar, .chip-row.filters {
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
}

/* ============================================================
   UPGRADE MODAL (.tup-plans) — stack plans on mobile
============================================================ */
@media (max-width: 720px) {
  .tup-overlay { padding: 12px !important; }
  .tup-box {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 92vh !important;
    overflow-y: auto !important;
    padding: 18px !important;
  }
  .tup-plans {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  .tup-plan { padding: 14px !important; }
}

/* ============================================================
   GLOBAL touch-friendly tap targets
============================================================ */
@media (max-width: 720px) {
  button, .btn, a.btn { min-height: 40px; }
  input, select, textarea { font-size: 16px !important; } /* iOS no-zoom */
}
