html, body { max-width: 100%; overflow-x: clip; -webkit-text-size-adjust: 100%; }
img, svg, table, pre { max-width: 100%; }
img { height: auto; }
* { min-width: 0; }

.main-content { padding-left: max(18px, env(safe-area-inset-left)); }

@media (max-width: 900px) {
  .topbar {
    flex-wrap: wrap;
    gap: 12px;
    position: sticky; top: 0; z-index: 40;
    background: rgba(237, 243, 247, 0.9);
    backdrop-filter: blur(10px);
    padding: 10px 0;
    margin-bottom: 16px;
    border-bottom: 1px solid rgba(17, 32, 52, 0.05);
  }
  .topbar > * { min-width: 0; }
  .page-title { font-size: 18px; }
  .page-subtitle { font-size: 12px; }
  .mobile-toggle { width: 46px; height: 46px; flex-shrink: 0; }
  .sidebar { width: min(84vw, 280px); left: calc(-1 * min(84vw, 280px)); overflow-y: auto; }
  .sidebar-backdrop {
    position: fixed; inset: 0; background: rgba(15,23,42,.42);
    z-index: 150; opacity: 0; pointer-events: none; transition: opacity .2s ease;
  }
  body.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  body.sidebar-open { overflow: hidden; }
  .sidebar nav a { height: 46px; min-height: 46px; padding: 11px 12px; font-size: 14.5px; }
  .sidebar::-webkit-scrollbar { width: 6px; }
  .sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 999px; }
  .card-header { flex-wrap: wrap; gap: 10px; padding: 14px 16px; }
  .card-body { padding: 16px; }
  .modal-backdrop { padding: 12px; align-items: flex-end; }
  .modal { max-height: 88vh; border-radius: 16px; }
  .modal-footer { flex-direction: column-reverse; }
  .modal-footer .btn { width: 100%; }
  .toast-stack { left: 12px; right: 12px; top: 12px; }
  .toast { min-width: 0; max-width: none; }
  .notif-panel { left: 8px; right: 8px; width: auto; }
}

@media (max-width: 720px) {
  .form-input, .form-select, .form-textarea, input, select, textarea,
  .search-input-wrap input { font-size: 16px !important; }
  .form-input, .form-select, .search-input-wrap input { min-height: 44px; }
  .btn { min-height: 44px; }
  .search-row .btn, .card-header .btn, .topbar .btn { width: 100%; }
  .topbar .btn { width: auto; }
  .btn-group, .action-row { display: flex; flex-wrap: wrap; gap: 8px; }
}

@media (max-width: 560px) {
  body { overflow-x: hidden; }
  .stat-grid { grid-template-columns: 1fr; gap: 12px; }
  .stat-card { padding: 14px 16px; }
  .stat-value { font-size: 22px; }
  .dashboard-hero h1 { font-size: 21px; }
  .main-content { padding: 14px 12px 28px; }
  .topbar { flex-direction: column; align-items: stretch; }
  .topbar > div { width: 100%; }
  .topbar > div:last-child { display: flex; flex-wrap: wrap; gap: 8px; }
  .topbar > div:last-child > * { flex: 1 1 calc(50% - 8px); min-width: 0; }
  .card-header,
  .card-body,
  .modal-body,
  .modal-footer { padding-left: 14px; padding-right: 14px; }
  .card-header { align-items: flex-start; }
  .card-header > div,
  .card-header .btn,
  .search-row,
  .master-pagination-top,
  .history-header-controls,
  #vc-filter-form,
  form[style*="display:flex"] { width: 100%; }
  .card-header > div { display: flex !important; flex-wrap: wrap; }
  .search-row { grid-template-columns: 1fr; }
  .btn, .form-input, .form-select, textarea, input, select { max-width: 100%; }
  .form-group { margin-bottom: 14px; }
  .input-wrap { height: 52px; }
  .modal-backdrop { padding: 12px; }
  .modal { border-radius: 14px; }
  .form-grid,
  .detail-grid,
  .vc-detail-grid { grid-template-columns: 1fr; }
  .form-grid .col-2,
  .vc-detail-grid .col-2 { grid-column: auto; }
  input[style*="width:340px"],
  input[style*="width:280px"],
  input[style*="width:220px"],
  input[style*="min-width:220px"],
  select[style*="width:150px"],
  select[style*="width:170px"],
  select[style*="width:120px"],
  select[style*="min-width:170px"],
  select[style*="min-width:140px"],
  select[style*="min-width:200px"],
  .master-filter-menu > button,
  .master-filter-select {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    flex: 1 1 auto;
  }
  .master-filter-menu { position: static; }
  .master-filter-options { left: 0; right: 0; min-width: 0; width: 100%; }
  .master-pagination-top { flex-wrap: wrap; }
  .master-pagination-top > * { flex: 1 1 auto; }
  .notif-panel { left: 10px; right: 10px; }
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}
@media (max-width: 900px) {
  .table-wrap { margin-inline: -4px; }
  .data-table { font-size: 12.5px; }
  .data-table th, .data-table td { padding: 10px 10px; white-space: nowrap; }
  .data-table th { position: static; }  /* sticky th bermasalah di dalam scroll-x */
  .table-hint {
    display: block; font-size: 11.5px; color: var(--text-muted, #64748b);
    padding: 6px 2px 0;
  }
}
.table-hint { display: none; }

@media (max-width: 900px) {
  .login-shell { margin: 0; border-radius: 0; min-height: 100vh; }
  .login-form, .login-card { padding: 24px 20px; }
}

@media print {
  .sidebar, .sidebar-backdrop, .mobile-toggle, .topbar .btn { display: none !important; }
  .app-shell { display: block; }
}

@media (min-width: 901px) {
  .app-shell {
    grid-template-columns: 250px 1fr;
    align-items: stretch;
  }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 250px;
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
    overscroll-behavior: contain;
    z-index: 100;
  }
  .app-shell > .sidebar + .main-content,
  .app-shell .main-content { grid-column: 2; }
}

.sidebar { -webkit-overflow-scrolling: touch; }
.sidebar nav { flex: 1 1 auto; }
.sidebar-foot { margin-top: auto; }

@media (max-width: 900px) {
  .sidebar {
    position: fixed; top: 0; height: 100vh; height: 100dvh;
    overflow-y: auto; overscroll-behavior: contain;
  }
}

.chart-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 16px;
  margin-top: 24px;
}
.chart-box { position: relative; height: 300px; min-height: 300px; box-sizing: border-box; overflow: hidden; }
.chart-box > canvas { display: block; max-width: 100%; }

@media (max-width: 1100px) {
  .chart-grid { grid-template-columns: 1fr 1fr; }
  .chart-grid > .card:first-child { grid-column: 1 / -1; }
}
@media (max-width: 900px) {
  .chart-grid { grid-template-columns: 1fr; gap: 14px; margin-top: 18px; }
  .chart-grid > .card:first-child { grid-column: auto; }
  .chart-box { height: 260px; min-height: 260px; padding: 12px; }
  .card-header h3 { font-size: 14px; }
  .card-header > div { flex-wrap: wrap; }
  .stat-grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
}
@media (max-width: 560px) {
  .chart-box { height: 240px; min-height: 240px; padding: 10px; }
  .stat-grid-3 { grid-template-columns: 1fr !important; }
  .stat-grid { grid-template-columns: 1fr !important; }
  .card-header { align-items: flex-start; }
  .card-header .btn.btn-sm { flex: 1 1 auto; }
}


#itc-scan-modal .modal { width: 100%; }
#itc-qr-reader { position: relative; }
#itc-qr-reader video,
#itc-qr-reader canvas,
#itc-qr-reader img { width: 100% !important; height: auto !important; display: block; }
#itc-scan-modal .btn-block { display: block; }

@media (max-width: 900px) {
  #itc-scan-modal .modal-body { padding: 14px; }
  #itc-qr-reader { min-height: 200px; }
  .card-header .btn.btn-sm { padding: 10px 14px; font-size: 13.5px; }
  .form-grid { grid-template-columns: 1fr !important; }
  .form-grid .col-2 { grid-column: span 1 !important; }
  .form-input, .form-select { font-size: 16px; }
  form > div[style*="justify-content:flex-end"] { flex-direction: column-reverse; }
  form > div[style*="justify-content:flex-end"] .btn { width: 100%; }
}
