/* Phone layout (screen only) and @media print / @page rules */

.topbar, .topbar-nav {
  display: none;
}

@keyframes slideDownNav {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media screen and (max-width: 860px) {
  .sidebar { display: none; }
  .shell { flex-direction: column; }

  /* Mobile Top Navigation Bar */
  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--ink);
    color: #fff;
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 40;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  }
  #mobileMenuBtn {
    cursor: pointer;
    display: flex;
    align-items: center;
    padding: 6px;
    border-radius: 6px;
    background: rgba(255,255,255,0.08);
  }

  /* Vertical Mobile Navigation Drawer */
  .topbar-nav {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 14px 16px;
    background: var(--ink);
    border-bottom: 2px solid var(--brand-orange);
    box-shadow: 0 10px 25px rgba(0,0,0,0.3);
    max-height: 80vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    animation: slideDownNav 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  }
  .topbar-nav-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #E4E8F2;
    font-size: 14px;
    font-weight: 500;
    padding: 10px 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s ease;
  }
  .topbar-nav-item:hover {
    background: rgba(255,255,255,0.06);
  }
  .topbar-nav-item.active {
    background: var(--brand-orange);
    color: #fff;
    font-weight: 600;
  }

  /* Main Container Padding */
  .main {
    padding: 16px 12px 60px 12px;
  }

  /* Responsive Tables and Cards */
  .card {
    padding: 16px 14px;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .card[style*="padding:0"] {
    padding: 0 !important;
  }
  .tbl-wrap {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 0;
  }
  .tbl {
    min-width: 580px;
  }

  /* Header and Action button wrapping on mobile */
  div[style*="justify-content:space-between;align-items:center"] {
    flex-wrap: wrap;
    gap: 12px;
  }
  .h1 {
    font-size: 20px;
  }

  /* Modal Form Collapse for Mobile */
  .modal-bg {
    padding: 16px 10px;
  }
  .modal {
    padding: 18px 14px;
    border-radius: 12px;
  }
  .modal-head {
    margin-bottom: 14px;
  }

  /* Force multi-column modal grids to single column on mobile */
  .modal [style*="grid-template-columns:1fr 1fr 1fr"],
  .modal [style*="grid-template-columns: 1fr 1fr 1fr"],
  .modal [style*="grid-template-columns:1fr 1fr"],
  .modal [style*="grid-template-columns: 1fr 1fr"] {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }
  .modal [style*="grid-column:span 2"],
  .modal [style*="grid-column: span 2"] {
    grid-column: 1 / -1 !important;
  }

  /* Document Preview */
  .li-head, .li-row {
    grid-template-columns: 1fr 40px 40px 65px 55px 65px 50px 26px;
  }
  .doc-header {
    flex-direction: column;
    gap: 12px;
  }
  .doc-bizinfo, .doc-trn {
    text-align: left;
  }
  .doc-infobar, .doc-footerbar {
    grid-template-columns: 1fr;
  }
  .doc-infobar > div:first-child {
    border-right: none;
    border-bottom: 1px solid #D8D8D8;
  }
}

@media print {
  @page { size: A4; margin: 8mm; }
  html, body { width: auto; height: auto; margin: 0; padding: 0; background: #fff; }
  body * { visibility: hidden; }
  .doc-sheet, .doc-sheet *, .rv-sheet, .rv-sheet * { visibility: visible; }
  .doc-sheet {
    position: absolute; top: 0; left: 0;
    width: 194mm; max-width: 194mm;
    min-height: 281mm;
    margin: 0; padding: 0;
    box-shadow: none; border: none;
    font-size: 11px;
    transform-origin: top left;
    display: flex; flex-direction: column;
  }
  .rv-sheet {
    position: absolute; top: 0; left: 0;
    width: 198mm; max-width: 198mm;
    min-height: 136mm;
    margin: 0; padding: 0;
    box-shadow: none; border: none;
    font-size: 11px;
    transform-origin: top left;
    display: flex; flex-direction: column;
  }
  .doc-spacer, .rv-spacer { flex: 1 1 auto; }
  .doc-sheet.doc-a4 { min-height: 280mm; }
  .doc-a4 .doc-header { padding-bottom: 10px; }
  .doc-a4 .doc-signrow { margin-top: 14px; }
  .doc-a4 .doc-bottombar { margin-top: 14px; }
  .doc-a4 .qp-infobox { margin-top: 8px; }
  .doc-a4 .qp-table { margin-top: 8px; }
  .doc-a4 .qp-terms { margin-top: 8px; }
  .doc-a4 .qp-signrow { margin-top: 26px; }
  .doc-a4 .qp-footerband { margin-top: 14px; }
  .doc-a4 .doc-infobar > div { padding: 8px 14px; }
  .doc-a4 .doc-fieldrow { margin-top: 3px; }
  .doc-a4 .doc-footerbar > div { padding: 8px 14px; }
  .doc-a4 .doc-bankbox { padding: 8px 14px; }
  .doc-a4 .doc-totalrow { padding: 1px 0; }
  .doc-a4 .doc-table th { padding: 6px 6px; }
  .doc-a4 .doc-table td { padding: 5px 6px; }
  .no-print, .no-print * { display: none !important; visibility: hidden !important; }
  .modal-bg, .modal { position: static !important; background: none !important; padding: 0 !important; box-shadow: none !important; max-width: none !important; inset: auto !important; overflow: visible !important; }
  .qp-table, .doc-sheet table { page-break-inside: auto; }
  .qp-table tr, .doc-sheet tr { page-break-inside: avoid; }
}
