/* ============================================================
   RESPONSIVE.CSS — Breakpoints & Mobile App Layout
   ============================================================ */

/* ── Desktop default: hide mobile-only elements ─────────── */
/* MUST be at the TOP so mobile media queries below override */
#mobile-nav {
  display: none;
}

#mobile-preview-toggle {
  display: none !important;
}

/* ── Tablet (≤ 1024px) ──────────────────────────────────── */
@media (max-width: 1024px) {
  #editor-content {
    padding: 20px 22px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-grid-3 {
    grid-template-columns: 1fr 1fr;
  }

  .tpl-modern {
    grid-template-columns: 175px 1fr;
  }

  .template-grid {
    grid-template-columns: 1fr;
  }
}

/* ─────────────────────────────────────────────────────────
   MOBILE (≤ 768px) — Full-screen app-like layout
   ───────────────────────────────────────────────────────── */
@media (max-width: 768px) {

  body {
    overflow: hidden;
  }

  body.editor-open {
    height: 100% !important;
    height: 100dvh !important;
    overflow: hidden !important;
  }

  #app {
    min-height: 0 !important;
    height: 100% !important;
    height: 100vh !important;
    height: calc(var(--vh, 1vh) * 100) !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  #app.fullscreen {
    position: fixed !important;
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    inset: 0 !important;
    width: 100% !important;
    min-height: 0 !important;
    height: 100% !important;
    height: 100vh !important;
    height: calc(var(--vh, 1vh) * 100) !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
  }

  /* ── Top bar ──────────────────────────────────────────── */
  #top-bar {
    height: 52px;
    padding: 0 12px;
    gap: 8px;
    flex-shrink: 0;
  }
  #top-bar .top-bar-left {
    gap: 8px;
    min-width: 0;             /* allow flex children to shrink */
    flex: 1 1 auto;
    overflow: hidden;
  }
  #top-bar .logo { flex: none; }
  #top-bar .logo-icon { width: 28px; height: 28px; font-size: 14px; }

  .mode-tabs { display: none !important; }
  .top-bar-actions .autosave-indicator { display: none; }

  /* Resume switcher — tighten for mobile.
     Keep the active pill + a compact 'Add' button, hide the extra chrome
     (role stack, score chip, count badge, chevron, labels) so the header
     fits on a 360-375px phone.
     IMPORTANT: no `overflow:hidden` on the switcher containers — the dropdown
     is absolutely positioned INSIDE them and must escape the clip rect.
     Instead we use `min-width:0` + ellipsis on the text node to shrink. */
  #resume-switcher-container { min-width: 0; flex: 1 1 auto; }
  .resume-switcher-area { gap: 6px; min-width: 0; flex-wrap: nowrap; }
  .resume-switcher-pill {
    padding: 4px 8px; gap: 6px;
    min-width: 0; max-width: 100%;
  }
  .resume-switcher-pill .role-icon-box { font-size: 15px; }
  .resume-switcher-pill .resume-name-box {
    min-width: 0;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .resume-switcher-pill .resume-name-text {
    font-size: 12.5px;
    max-width: 110px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block;
  }
  .resume-switcher-pill .resume-target-badge { display: none; }
  .resume-switcher-pill .resume-score-chip   { display: none; }
  .resume-switcher-pill .resume-count-badge  { display: none; }
  .resume-switcher-pill .resume-chevron-icon { opacity: 0.7; }

  .switcher-other-roles { display: none !important; }   /* reclaim lots of space */
  .switcher-add-role-btn { padding: 5px 8px; }
  .switcher-add-role-btn .add-role-label { display: none; }

  /* Dropdown must appear below the pill and span the full viewport width on
     mobile so all the resume rows are tappable. */
  .resume-switcher-dropdown {
    position: fixed !important;
    left: 8px !important; right: 8px !important;
    top: 56px !important;              /* just below the 52px top-bar */
    width: auto !important;
    max-width: none !important;
    max-height: calc(100dvh - 72px);
    overflow-y: auto;
    z-index: 1000;
  }

  /* Action buttons — Upload & Reset collapse to icon-only squares, Download
     keeps its label with proper padding so it reads as the primary CTA. */
  .top-bar-actions { gap: 6px; align-items: center; }
  .top-bar-actions .btn-sm { height: 36px; min-height: 36px; box-sizing: border-box; }

  /* Icon-only square buttons — NO text on mobile.
     Approach: fixed 36×36 button; the SVG is pulled out of the normal flow
     with absolute positioning + centred; the trailing text node is clipped by
     overflow:hidden AND rendered invisible via color:transparent (so it never
     overlaps the icon). We DELIBERATELY avoid `font-size:0` because some
     mobile WebKit builds skip click dispatch on buttons whose font-size is 0.
     The SVG uses `pointer-events:none` so taps always bubble to the <button>. */
  #editor-upload-btn, #reset-all-btn {
    position: relative !important;
    width: 36px !important;
    min-width: 36px !important;
    height: 36px !important;
    padding: 0 !important;
    gap: 0 !important;
    overflow: hidden !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    color: transparent !important;        /* hide the label text */
    text-indent: 999px;                   /* belt-and-braces: push text out */
    white-space: nowrap;
  }
  #editor-upload-btn > svg,
  #reset-all-btn   > svg {
    position: absolute;
    left: 50%; top: 50%;
    transform: translate(-50%, -50%);
    width: 15px !important;
    height: 15px !important;
    color: #0f172a !important;            /* restore icon colour (stroke="currentColor") */
    stroke: #0f172a;
    flex: none;
    pointer-events: none;                 /* clicks go to the <button>, not the SVG */
    text-indent: 0;
  }

  /* Download button — keep the "Download" label with a comfortable pill
     width. Explicit padding beats any !important the earlier rule applied. */
  #download-btn {
    padding: 0 14px !important;
    font-size: 12.5px;
    gap: 6px;
    white-space: nowrap;
  }
  #download-btn > svg { width: 13px; height: 13px; flex: none; }

  /* ── Main — fills between top bar and bottom nav ──────── */
  #main {
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
  }

  /* Row becomes a positioned container — this lets the cols
     use position:absolute so they fill 100% width/height
     without fighting Bootstrap's col-6 width:50% */
  #main>.row {
    position: relative !important;
    flex: 1 1 0 !important;
    min-height: 0;
    flex-direction: row !important;
    /* keep row direction; absolute children ignore it */
  }

  /* Both cols: absolutely fill the row area */
  #left-col,
  #right-col {
    position: absolute !important;
    inset: 0 !important;
    /* top/right/bottom/left all 0 */
    width: 100% !important;
    height: 100% !important;
    border-right: none !important;
  }

  /* Default view: show editor/customize, hide preview */
  #left-col {
    display: flex !important;
    flex-direction: column;
  }

  #right-col {
    display: none !important;
  }

  /* Preview tab: swap */
  body[data-mobile-view="preview"] #left-col {
    display: none !important;
  }

  body[data-mobile-view="preview"] #right-col {
    display: flex !important;
    flex-direction: column;
  }

  /* ── Mobile bottom nav ────────────────────────────────── */
  /* position:static — real flex child of #app, not overlapping */
  #mobile-nav {
    display: flex;
    flex-shrink: 0;
    position: static;
    min-height: 52px;
    height: auto;
    padding: 3px 8px;
    padding-bottom: max(6px, env(safe-area-inset-bottom, 6px));
    background: var(--bg-panel, #ffffff);
    box-sizing: border-box;
    border-top: 1px solid var(--border, #e2e8f0);
    z-index: 10;
  }

  .mobile-nav-tab {
    flex: 1;
    min-width: unset;
    padding: 5px 4px;
    font-size: 0.6rem;
    border-radius: 0;
  }

  .mobile-nav-tab svg {
    width: 22px;
    height: 22px;
  }

  /* ── Panels fill their column ─────────────────────────── */
  #editor-panel,
  #customize-panel,
  #preview-panel {
    flex: 1 1 0;
    min-height: 0;
  }

  #editor-panel {
    border-right: none;
  }

  /* ── Editor content ───────────────────────────────────── */
  #editor-content {
    padding: 16px 14px 28px 14px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ── Bottom step nav ──────────────────────────────────── */
  #bottom-nav {
    padding: 8px 14px;
    flex-shrink: 0;
    background: var(--bg-panel, #ffffff);
    border-top: 1px solid var(--border, #e2e8f0);
    box-sizing: border-box;
    z-index: 9;
  }

  #bottom-nav .btn {
    min-height: 42px;
  }

  .bottom-nav-left .step-dots {
    display: none;
  }

  /* ── Customize tabs horizontal scroll ─────────────────── */
  .customize-tabs {
    overflow-x: auto;
    scrollbar-width: none;
  }

  .customize-tabs::-webkit-scrollbar {
    display: none;
  }

  .customize-tab {
    white-space: nowrap;
    flex-shrink: 0;
  }

  #customize-content {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ── Preview ──────────────────────────────────────────── */
  #preview-toolbar {
    padding: 8px 12px;
  }

  .page-format-toggle {
    display: none;
  }

  #preview-viewport {
    padding: 12px 8px;
  }

  /* ── Forms ────────────────────────────────────────────── */
  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-grid-3 {
    grid-template-columns: 1fr;
  }

  .additional-sections-grid {
    grid-template-columns: 1fr;
  }

  .date-range {
    grid-template-columns: 1fr;
  }

  .form-control {
    padding: 11px 12px;
    font-size: 1rem;
  }

  /* 16px prevents iOS zoom */
  textarea.form-control {
    min-height: 90px;
  }

  .form-group {
    margin-bottom: 14px;
  }

  /* ── Entry cards ──────────────────────────────────────── */
  .entry-card-header {
    padding: 14px 12px;
  }

  .entry-card-body {
    padding: 12px;
  }

  /* ── Templates ────────────────────────────────────────── */
  .template-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* ── Modal: bottom sheet ──────────────────────────────── */
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .modal {
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    max-height: 88vh;
    width: 100%;
    max-width: 100%;
    animation: slideUpSheet 250ms var(--ease-out) forwards;
  }


  /* ── ATS widget above bottom nav ─────────────────────── */
  .ats-score-widget {
    bottom: calc(60px + env(safe-area-inset-bottom, 0px) + 12px);
    left: 12px;
    right: 12px;
    min-width: auto;
  }
}

/* ── Small mobile (≤ 480px) ─────────────────────────────── */
@media (max-width: 480px) {
  #top-bar {
    padding: 0 10px;
    gap: 6px;
  }

  #top-bar .logo-text {
    display: none;              /* keep just the "R" icon */
  }

  /* Resume name narrower still */
  .resume-switcher-pill .resume-name-text { max-width: 80px; font-size: 12px; }
  .resume-switcher-pill .resume-chevron-icon { display: none; }
  .switcher-add-role-btn { padding: 5px 7px; }
  .switcher-add-role-btn svg { width: 12px; height: 12px; }

  /* Drop the Upload button at the smallest width — the upload flow is also
     reachable from inside the main picker, no need for a redundant topbar entry. */
  #editor-upload-btn { display: none; }
  .top-bar-actions { gap: 4px; }
  .top-bar-actions .btn-sm { padding: 6px 8px; }

  #editor-content {
    padding: 16px 12px;
  }

  .step-header h2 {
    font-size: 1.25rem;
  }

  .review-grid {
    grid-template-columns: 1fr;
  }

  .template-grid {
    grid-template-columns: 1fr;
  }

  .color-presets {
    gap: 6px;
  }

  .btn-lg {
    padding: 12px 20px;
    font-size: 0.9375rem;
  }

  .mobile-nav-tab {
    font-size: 0.5625rem;
    gap: 3px;
  }

  .mobile-nav-tab svg {
    width: 20px;
    height: 20px;
  }

  .modal {
    max-height: 92vh;
  }
}

/* ── Large desktop (≥ 1400px) ───────────────────────────── */
@media (min-width: 1400px) {
  #editor-content {
    padding: 32px 40px;
  }

  .template-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ── Animations ──────────────────────────────────────────── */
@keyframes slideUpSheet {
  from {
    transform: translateY(40px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* ── RTL ─────────────────────────────────────────────────── */
[dir="rtl"] .mode-tabs {
  transform: translateX(50%);
}

[dir="rtl"] .step-header,
[dir="rtl"] .form-group,
[dir="rtl"] .entry-card-header-left {
  direction: rtl;
  text-align: right;
}

[dir="rtl"] .form-label {
  text-align: right;
}

[dir="rtl"] .bottom-nav-left {
  margin-left: auto;
  margin-right: 0;
}

[dir="rtl"] .add-entry-btn {
  flex-direction: row-reverse;
}

[dir="rtl"] .entry-card-actions {
  flex-direction: row-reverse;
}

[dir="rtl"] select.form-control {
  background-position: left 12px center;
  padding-right: 12px;
  padding-left: 36px;
}

[dir="rtl"] .drag-handle {
  order: 3;
}

[dir="rtl"] .sidebar-item {
  direction: rtl;
}

[dir="rtl"] #toast-container {
  right: auto;
  left: 24px;
}

[dir="rtl"] .toast {
  animation: toastInRtl 250ms var(--ease-out) forwards;
}

@keyframes toastInRtl {
  from {
    transform: translateX(-100%);
    opacity: 0;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* ── Reduced motion ──────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }

  .score-bar-fill {
    transition: none;
  }

  #preview-container {
    transition: none;
  }
}