/* === Flexible Mobile & Tablet - Sidebar drawer + fluid layout (desktop >860px untouched) === */
.mobile-header { display: none; }
.mobile-backdrop { display: none; }

/* — Prevent any horizontal overflow globally — */
html { overflow-x: hidden; }
body { overflow-x: hidden; }
img, video, iframe { max-width: 100%; }
table { word-break: break-word; }

/* Smooth scrolling for tables on iOS */
.table-card, .table-scroll { -webkit-overflow-scrolling: touch; }

/* — Tablet / small laptop down to 1024 — just tighten padding, keep sidebar — */
@media (max-width: 1024px) {
  .main-content { padding: 32px 28px !important; }
}

/* — Main breakpoint: drawer + fluid (860px) — replaces old broken top-navbar — */
@media (max-width: 860px) {
  .mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 1002;
    height: 56px;
    padding: 0 14px 0 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }
  .mobile-header__brand { display:flex; align-items:center; gap:10px; text-decoration:none; color:var(--forest); font-weight:800; font-size:.95rem; letter-spacing:.04em; }
  .mobile-header__brand img { width:32px; height:32px; object-fit:contain; }
  .mobile-header__toggle { display:inline-flex; align-items:center; justify-content:center; width:42px; height:42px; border-radius:10px; border:1px solid var(--border); background:var(--input-bg); color:var(--text); cursor:pointer; font-size:1.35rem; line-height:1; transition: background .2s, transform .15s; }
  .mobile-header__toggle:active { transform:scale(.95); }
  .mobile-header__toggle .icon-close { display:none; }
  .mobile-header__toggle.is-open .icon-hamburger { display:none; }
  .mobile-header__toggle.is-open .icon-close { display:inline; }

  .layout { flex-direction: column !important; }

  /* off-canvas sidebar */
  .sidebar {
    position: fixed !important;
    top: 0; left: 0;
    width: 300px !important;
    max-width: 86vw;
    height: 100vh !important;
    height: 100dvh !important;
    z-index: 1003;
    border-right: 1px solid var(--border) !important;
    border-bottom: none !important;
    transform: translateX(-100%);
    transition: transform .32s cubic-bezier(.32,.72,0,1);
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: 16px 0 40px rgba(0,0,0,.18);
  }
  .sidebar.is-open { transform: translateX(0); }
  .sidebar .nav-list { flex-direction: column !important; }

  .mobile-backdrop {
    display: block;
    position: fixed; inset: 0;
    z-index: 1001;
    background: rgba(0,0,0,.45);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .28s ease;
  }
  .mobile-backdrop.is-open { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }

  .theme-toggle { top: 70px !important; right: 14px !important; z-index: 1000 !important; }
  .cursor-glow { display: none !important; }

  .content-column { width: 100%; }
  .main-content { padding: 24px 20px !important; }
  .container { padding: 24px 16px 40px !important; max-width: 100% !important; }

  /* Page header - smaller on tablet */
  h1 { font-size: 1.6rem !important; }
  .page-header { margin-bottom: 20px !important; }

  /* Cards */
  .cards-grid { grid-template-columns: 1fr 1fr !important; gap: 14px !important; }
  .card { padding: 20px !important; }
  .cta-section { padding: 20px !important; flex-direction: column; align-items: stretch !important; }
  .cta-section .btn-submit { width: 100%; }

  /* Tables - always scrollable */
  .table-card { overflow-x: auto !important; }
  table { min-width: 640px; }
  thead th, tbody td { padding: 12px 14px !important; font-size: .82rem !important; white-space: nowrap; }

  /* Filter / toolbar */
  .filter-card { padding: 16px !important; }
  .filter-form { grid-template-columns: repeat(2, 1fr) !important; gap: 12px !important; }
  .toolbar { flex-direction: column; align-items: stretch !important; gap: 12px !important; }
  .toolbar .toolbar-actions, .toolbar .month-switch { width: 100%; justify-content: center; }
  .search-bar { flex-wrap: wrap !important; }
  .option-grid { grid-template-columns: 1fr !important; }
  .form-grid, .step.active { grid-template-columns: 1fr 1fr !important; }

  /* Pagination stacks */
  .pagination { flex-direction: column; align-items: stretch !important; }
  .pager-btns { justify-content: center; }

  footer { padding: 20px 16px !important; font-size: .8rem !important; }
}

/* iOS: prevent zoom on focus */
@media (max-width: 860px) {
  input, select, textarea { font-size: 16px !important; }
}

/* — Phone 640px — single column, full fluid — */
@media (max-width: 640px) {
  h1 { font-size: 1.45rem !important; }
  .subtitle { font-size: .85rem !important; }
  .cards-grid { grid-template-columns: 1fr !important; }
  .filter-form { grid-template-columns: 1fr !important; }
  .filter-form > div:last-child, .filter-form > div:nth-last-child(2) { grid-column: auto !important; }
  .filter-card { border-radius: 14px !important; }
  .table-card { border-radius: 14px !important; }
  .card { border-radius: 14px !important; }
  .form-grid, .step.active { grid-template-columns: 1fr !important; }
  .soft-card { padding: 20px 18px !important; }
  .btn-submit, .btn-filter, .btn-pdf, .btn-fill { width: 100%; justify-content: center; }
  .toolbar-actions { flex-direction: column; }
  .toolbar-actions a, .toolbar-actions button { width: 100%; justify-content: center; }
  .month-switch { width: 100%; }
  .month-label { min-width: 0 !important; flex: 1; }
  .search-bar { flex-direction: column !important; }
  .search-bar input, .search-bar select, .search-bar .btn-submit { width: 100% !important; flex: none !important; }
  .rekap-chips { padding: 12px 16px 20px !important; }
  .pagination { gap: 10px !important; }
}

/* — Small phone 480px — tighten everything — */
@media (max-width: 480px) {
  .mobile-header { height: 52px; padding: 0 10px 0 12px; }
  .mobile-header__brand { font-size: .88rem; }
  .mobile-header__brand img { width: 28px; height: 28px; }
  .sidebar { width: 82vw !important; max-width: 300px !important; padding: 22px 16px !important; }
  .main-content { padding: 16px 14px !important; }
  .container { padding: 16px 12px 32px !important; }
  h1 { font-size: 1.35rem !important; }
  .card { padding: 16px !important; }
  .table-card { margin-bottom: 16px !important; }
  table { min-width: 560px; }
  .form-card { padding: 18px !important; }
}
