@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700&display=swap');

:root {
  --primary: #1e3a5f;
  --primary-light: #2563a8;
  --accent: #f59e0b;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-600: #475569;
  --gray-800: #1e293b;
  --sidebar-w: 216px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Sarabun', sans-serif;
  background: var(--gray-100);
  color: var(--gray-800);
  display: flex;
  min-height: 100vh;
}

/* ===== SIDEBAR (compact + modern) ===== */
.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, #1e3a5f 0%, #16294a 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  box-shadow: 1px 0 8px rgba(0,0,0,.15);
  border-right: 1px solid rgba(255,255,255,.06);
}

.sidebar-logo {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: 9px;
}

.sidebar-logo .logo-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, #fb923c 0%, #f59e0b 45%, #ea580c 100%);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; color: #fff;
  box-shadow:
    0 4px 12px rgba(234,88,12,.35),
    0 1px 2px rgba(0,0,0,.15),
    inset 0 1px 0 rgba(255,255,255,.28),
    inset 0 -1px 0 rgba(0,0,0,.08);
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}
.sidebar-logo .logo-icon::after {
  /* subtle radial highlight */
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 30% 25%, rgba(255,255,255,.2), transparent 60%);
  pointer-events: none;
}
.sidebar-logo .logo-icon svg { width: 22px; height: 22px; position: relative; z-index: 1; filter: drop-shadow(0 1px 1px rgba(0,0,0,.15)); }

.sidebar-logo .logo-text { font-size: 12.5px; font-weight: 700; line-height: 1.2; letter-spacing: .2px; }
.sidebar-logo .logo-sub  { font-size: 9.5px; opacity: .55; margin-top: 1px; letter-spacing: .1px; }

.sidebar-nav { flex: 1; padding: 8px 0 12px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.15) transparent; }
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 2px; }

.nav-section {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: rgba(255,255,255,.38);
  padding: 12px 16px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 11px;
  color: rgba(255,255,255,.72);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  border-radius: 7px;
  margin: 1px 8px;
  transition: background .12s, color .12s;
  position: relative;
}

.nav-item:hover  { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active {
  background: linear-gradient(90deg, rgba(245,158,11,.18) 0%, rgba(245,158,11,.05) 100%);
  color: #fff;
  font-weight: 600;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 18px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}
.nav-item .icon {
  width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  opacity: .85;
}
.nav-item.active .icon { opacity: 1; color: var(--accent); }
.nav-item .icon svg { width: 18px; height: 18px; stroke-width: 1.8; }
.nav-item .nav-badge { background:#ef4444; color:#fff; font-size:10px; font-weight:700; padding:1px 6px; border-radius:10px; margin-left:auto; min-width:18px; text-align:center; line-height:1.4; }

.sidebar-user {
  margin-top: auto;
  padding: 10px 12px;
  border-top: 1px solid rgba(255,255,255,.08);
  background: rgba(0,0,0,.22);
}
.sidebar-user .su-info { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; }
.sidebar-user .su-avatar { width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg,#3b82f6,#1e40af); color:#fff; font-weight:700; display:flex; align-items:center; justify-content:center; font-size:13px; flex-shrink:0; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.sidebar-user .su-text { flex: 1; min-width: 0; }
.sidebar-user .su-name { font-size: 12.5px; font-weight: 600; color: #fff; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; line-height: 1.2; }
.sidebar-user .su-role { font-size: 10.5px; color: rgba(255,255,255,.55); margin-top: 1px; }
.sidebar-user .su-logout { width: 100%; padding: 6px; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1); color: rgba(255,255,255,.85); border-radius: 6px; font-family: inherit; font-size: 11.5px; cursor: pointer; transition: all .15s; display: flex; align-items: center; justify-content: center; gap: 5px; }
.sidebar-user .su-logout:hover { background: rgba(239,68,68,.25); border-color: rgba(239,68,68,.4); color: #fff; }
.sidebar-user .su-search { width: 100%; padding: 6px 8px; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1); color: rgba(255,255,255,.85); border-radius: 6px; font-family: inherit; font-size: 11.5px; cursor: pointer; transition: background .15s; margin-bottom: 7px; display: flex; align-items: center; justify-content: center; gap: 5px; }
.sidebar-user .su-search:hover { background: rgba(255,255,255,.12); }
.sidebar-user .su-search kbd { background: rgba(0,0,0,.35); border: 1px solid rgba(255,255,255,.15); padding: 0 5px; border-radius: 3px; font-family: ui-monospace, monospace; font-size: 10px; margin-left: auto; }
.sidebar-user .su-search svg, .sidebar-user .su-logout svg { width: 13px; height: 13px; stroke-width: 2; opacity: .8; }

.sidebar-footer {
  padding: 8px 14px 10px;
  font-size: 10px;
  color: rgba(255,255,255,.32);
  text-align: center;
}

/* ===== MAIN CONTENT ===== */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;            /* allow main to shrink below content size — prevents mobile overflow */
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  background: #fff;
  padding: 12px 72px 12px 24px;   /* extra right space clears the fixed notification bell */
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--gray-200);
  position: sticky; top: 0; z-index: 50;
}

.topbar-title { font-size: 18px; font-weight: 700; color: var(--primary); }
.topbar-sub   { font-size: 12px; color: var(--gray-600); }

.page-content { padding: 24px; flex: 1; }

/* ===== CARDS ===== */
.card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-title { font-size: 15px; font-weight: 700; color: var(--primary); }
.card-body  { padding: 20px; }

/* ===== STAT CARDS ===== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
  border-left: 4px solid transparent;
}

.stat-card.blue   { border-color: var(--primary-light); }
.stat-card.green  { border-color: var(--success); }
.stat-card.amber  { border-color: var(--warning); }
.stat-card.red    { border-color: var(--danger); }

.stat-icon {
  width: 50px; height: 50px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
}

.stat-card.blue  .stat-icon { background: #dbeafe; color: var(--primary-light); }
.stat-card.green .stat-icon { background: #d1fae5; color: var(--success); }
.stat-card.amber .stat-icon { background: #fef3c7; color: var(--warning); }
.stat-card.red   .stat-icon { background: #fee2e2; color: var(--danger); }

.stat-value { font-size: 28px; font-weight: 700; line-height: 1; }
.stat-label { font-size: 13px; color: var(--gray-600); margin-top: 4px; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-family: 'Sarabun', sans-serif;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all .15s;
  text-decoration: none;
}

.btn-primary   { background: var(--primary-light); color: #fff; }
.btn-primary:hover { background: var(--primary); }
.btn-success   { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(.9); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.9); }
.btn-warning   { background: var(--warning); color: #fff; }
.btn-outline   { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: var(--primary); color: #fff; }
.btn-sm        { padding: 5px 10px; font-size: 12px; }
.btn-lg        { padding: 12px 24px; font-size: 16px; }

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; }

table.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.tbl th {
  background: var(--gray-50);
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 13px;
  color: var(--gray-600);
  border-bottom: 2px solid var(--gray-200);
  white-space: nowrap;
}

.tbl td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

.tbl tr:hover td { background: var(--gray-50); }

/* ===== BADGES ===== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge-success { background: #d1fae5; color: #065f46; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info    { background: #dbeafe; color: #1e40af; }
.badge-gray    { background: #f1f5f9; color: #475569; }

/* ===== FORM ===== */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  font-family: 'Sarabun', sans-serif;
  font-size: 14px;
  color: var(--gray-800);
  transition: border-color .15s;
  background: #fff;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(37,99,168,.12);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.form-select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23475569' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }

/* ===== CHECKLIST ITEMS ===== */
.check-item {
  border: 1.5px solid var(--gray-200);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 10px;
  background: #fff;
  transition: border-color .15s;
}

.check-item:hover { border-color: var(--primary-light); }

.check-item-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.item-no {
  width: 28px; height: 28px;
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.item-no.sub { background: var(--gray-600); font-size: 11px; }

.item-name { font-size: 14px; font-weight: 600; flex: 1; }
.item-standard { font-size: 12px; color: var(--gray-600); margin-top: 2px; }

.result-radio {
  display: flex;
  gap: 12px;
  align-items: center;
}

.radio-opt {
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}

.radio-opt input[type="radio"] { accent-color: var(--primary-light); }
.radio-ok   { color: var(--success); }
.radio-fix  { color: var(--danger); }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  opacity: 0; pointer-events: none;
  transition: opacity .2s;
}

.modal-overlay.show { opacity: 1; pointer-events: auto; }

.modal {
  background: #fff;
  border-radius: 16px;
  width: 90%;
  max-width: 640px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  transform: translateY(-20px);
  transition: transform .2s;
}

.modal-overlay.show .modal { transform: translateY(0); }
.modal-title { font-size: 18px; font-weight: 700; color: var(--primary); margin-bottom: 20px; padding-right: 36px; }

/* ===== Modal X close button (top-right, sticky during scroll) ===== */
.modal-x-close {
  position: sticky;
  top: 0;
  float: right;
  width: 32px; height: 32px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 50%;
  color: #475569;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  z-index: 10;
  transition: all .15s;
  padding: 0;
  margin-bottom: -32px;       /* don't push content down */
  margin-right: 0;
  box-shadow: 0 2px 4px rgba(0,0,0,.08);
}
.modal-x-close:hover { background: #fee2e2; border-color: #fca5a5; color: #dc2626; }
.modal-x-close svg { width: 16px; height: 16px; }

/* ===== ALERT ===== */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.alert-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-danger  { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-info    { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }

/* ===== TOAST ===== */
#toast-container {
  position: fixed;
  top: 20px; right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: #fff;
  border-radius: 10px;
  padding: 12px 16px;
  box-shadow: 0 4px 20px rgba(0,0,0,.15);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 280px;
  animation: slideIn .3s ease;
  border-left: 4px solid var(--primary-light);
}

.toast.success { border-color: var(--success); }
.toast.error   { border-color: var(--danger); }
.toast-icon    { font-size: 18px; }
.toast-msg     { font-size: 13px; flex: 1; }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ===== CHART GRID ===== */
.chart-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

@media (max-width: 900px) {
  .chart-grid { grid-template-columns: 1fr; }
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--gray-600);
}

.empty-state .icon { font-size: 48px; margin-bottom: 12px; opacity: .4; }
.empty-state p { font-size: 14px; }

/* ===== LOADING ===== */
.spinner {
  width: 24px; height: 24px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary-light);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  margin: 20px auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== SECTION HEADER IN INSPECTION FORM ===== */
.section-header {
  background: var(--primary);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  margin: 20px 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===== SEARCH BAR ===== */
.search-wrap {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  align-items: center;
  flex-wrap: wrap;
}

.search-input {
  flex: 1;
  min-width: 200px;
  padding: 9px 12px 9px 36px;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  font-family: 'Sarabun', sans-serif;
  font-size: 14px;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cpath d='m21 21-4.35-4.35'/%3E%3C/svg%3E") no-repeat 10px center;
}

.search-input:focus { outline: none; border-color: var(--primary-light); }

/* ===== PRINT (global app pages) ===== */
@page {
  size: A4 portrait;
  margin: 10mm 12mm;
}

@media print {
  /* Force background colors & gradients to print */
  *, *::before, *::after {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  html, body {
    background: #fff !important;
    margin: 0 !important;
    padding: 0 !important;
    font-size: 10pt;
    line-height: 1.4;
  }

  /* Hide interactive chrome */
  .sidebar, .topbar, .btn, .hamburger,
  #toast-container, #issue-fab-wrap,
  .sticky-tr-bar, .progress-bar, .pg-wrap,
  .modal-overlay, .lightbox, .um-overlay,
  .annot-overlay, #fbi-annot-overlay,
  .modal-x-close, .sidebar-overlay { display: none !important; }

  /* Full-width content (no sidebar offset) */
  .main { margin-left: 0 !important; }
  .page-content { padding: 0 !important; }

  /* Cards — flatten for print */
  .card {
    box-shadow: none !important;
    border: 1px solid #d1d5db !important;
    page-break-inside: avoid;
    break-inside: avoid;
    margin-bottom: 8pt !important;
  }
  .card-header {
    background: #1e3a5f !important;
    color: #fff !important;
    padding: 4px 10px !important;
  }
  .card-title { font-size: 10.5pt; color: #fff !important; }
  .card-body { padding: 8pt !important; }

  /* Form controls — minimal */
  .form-control, input, select, textarea {
    border: 1px solid #cbd5e1 !important;
    background: #fff !important;
    box-shadow: none !important;
    font-size: 9.5pt;
  }

  /* Headings */
  h1, h2, h3, h4, h5 { page-break-after: avoid; break-after: avoid; }

  /* Photo grids */
  .photos-grid, .photo-pair {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  /* Tables */
  table { page-break-inside: auto; }
  tr    { page-break-inside: avoid; break-inside: avoid; }
  thead { display: table-header-group; }
  tfoot { display: table-footer-group; }
}

/* ===================================================
   RESPONSIVE — Hamburger & Overlay
   =================================================== */
.hamburger {
  display: none;
  flex-direction: column;
  gap: 5px;
  cursor: pointer;
  padding: 11px 8px;       /* 44px tall target for thumb */
  border: none;
  background: transparent;
  margin-right: 6px;
  border-radius: 8px;
  transition: background .15s;
  min-width: 44px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
}
.hamburger:active { background: rgba(0,0,0,.06); }
.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--primary);
  border-radius: 2px;
  transition: all .25s;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.55);
  backdrop-filter: blur(2px);
  z-index: 99;
}

/* ===================================================
   TABLET — 768px to 1024px
   =================================================== */
@media (max-width: 1024px) {
  :root { --sidebar-w: 200px; }

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

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

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

  .topbar-title { font-size: 15px; }
}

/* ===================================================
   MOBILE — max 768px
   =================================================== */
@media (max-width: 768px) {

  /* Sidebar: hide off-screen, slide in on open */
  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 100;
    width: 240px !important;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay {
    display: block;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s;
  }
  .sidebar-overlay.show {
    opacity: 1;
    pointer-events: auto;
  }

  /* Main takes full width */
  .main {
    margin-left: 0;
  }

  /* Topbar */
  .topbar {
    padding: 10px 14px;
    gap: 8px;
    flex-wrap: wrap;
  }
  .hamburger { display: flex; }
  .topbar-title { font-size: 14px; }
  .topbar-sub   { font-size: 11px; }

  /* Page content */
  .page-content { padding: 12px; }

  /* Stat grid — 2 columns on mobile */
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  .stat-card { padding: 14px; }
  .stat-icon { width: 40px; height: 40px; font-size: 18px; }
  .stat-value { font-size: 22px; }
  .stat-label { font-size: 11px; }

  /* Charts */
  .chart-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  /* Cards */
  .card-header {
    padding: 12px 14px;
    flex-wrap: wrap;
    gap: 8px;
  }

  /* Tables — horizontal scroll with sticky first col */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .tbl { min-width: 540px; }
  .tbl th, .tbl td { padding: 8px 10px; font-size: 12px; }

  /* Forms */
  .form-row {
    grid-template-columns: 1fr !important;
    gap: 10px;
  }
  .form-group { margin-bottom: 10px; }

  /* Buttons */
  .btn { font-size: 13px; padding: 7px 12px; }
  .btn-lg { padding: 10px 18px; font-size: 14px; }

  /* Topbar button stack */
  .topbar > div:last-child {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
  }

  /* Search bar */
  .search-wrap {
    flex-direction: column;
    align-items: stretch;
  }
  .search-input { min-width: unset; width: 100%; }

  /* Modal */
  .modal {
    width: 96%;
    padding: 16px;
    max-height: 92vh;
  }
  .modal-title { font-size: 15px; }

  /* Check items */
  .check-item { padding: 10px 12px; }
  .item-name { font-size: 13px; }

  /* Section header */
  .section-header { font-size: 13px; padding: 8px 12px; }

  /* Toast */
  #toast-container { right: 10px; left: 10px; }
  .toast { min-width: unset; }

  /* Sidebar logo text */
  .logo-text { font-size: 12px; }
}

/* ===================================================
   VERY SMALL — max 480px
   =================================================== */
@media (max-width: 480px) {
  .stat-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .stat-value { font-size: 18px; }

  .topbar-title { font-size: 13px; }

  /* Inspection measure grids go single column */
  .oil-samples {
    grid-template-columns: repeat(3, 1fr) !important;
  }

  /* Voltage/current grids */
  [style*="grid-template-columns: repeat(4,1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  [style*="grid-template-columns: repeat(3,1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  [style*="grid-template-columns: 1fr 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  .btn-sm { padding: 6px 10px; font-size: 11px; min-height: 32px; }
}

/* ===================================================
   PHASE 2 — Responsive polish (applies to all sizes)
   =================================================== */

/* Touch target enforcement — desktop keeps compact, mobile enlarges */
@media (max-width: 768px) {
  .btn:not(.btn-sm) { min-height: 40px; padding: 8px 14px; }
  .btn-sm { min-height: 36px; padding: 6px 10px; font-size: 12px; }
}
/* Keep action buttons in table cells single-line on all sizes */
td .btn-sm, td a.btn-sm { white-space: nowrap; }
/* Action column (last in tbl) — keep buttons on one row */
.tbl tbody td:last-child { white-space: nowrap; }

/* Table — horizontal scroll shadow indicator */
.table-wrap {
  position: relative;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  background:
    linear-gradient(to right, #fff 30%, rgba(255,255,255,0)) left center / 20px 100% no-repeat,
    linear-gradient(to right, rgba(255,255,255,0), #fff 70%) right center / 20px 100% no-repeat,
    linear-gradient(to right, rgba(15,23,42,.10), rgba(15,23,42,0) 20px) left center / 20px 100% no-repeat,
    linear-gradient(to left,  rgba(15,23,42,.10), rgba(15,23,42,0) 20px) right center / 20px 100% no-repeat;
  background-attachment: local, local, scroll, scroll;
}

/* Modal — tablet landscape (600-900px) */
@media (max-width: 900px) and (min-width: 601px) {
  .modal { width: 88%; max-width: 700px; padding: 20px; }
}

/* Annotation canvas — mobile-friendly toolbar */
@media (max-width: 600px) {
  .annot-toolbar,
  .fbi-toolbar {
    gap: 4px !important;
    padding: 6px !important;
    font-size: 11px;
  }
  .annot-toolbar label,
  .fbi-toolbar label { font-size: 10.5px !important; }
  .annot-toolbar input[type="range"],
  .fbi-toolbar input[type="range"] { width: 70px !important; }
  .color-swatch, .fbi-swatch { width: 24px !important; height: 24px !important; }
  .annot-modal .modal, #fbi-annot-box {
    width: 98vw !important;
    padding: 10px !important;
  }
  .annot-canvas-wrap, .fbi-canvas-wrap { max-height: 48vh !important; }
}

/* FAB (แจ้งปัญหา) — keep above bottom sheets on mobile */
@media (max-width: 600px) {
  #issue-fab-wrap { bottom: 14px !important; right: 12px !important; z-index: 9100 !important; }
}

/* Sidebar — when open on mobile, raise z-index above any FAB */
@media (max-width: 768px) {
  .sidebar.open { z-index: 9300; box-shadow: 4px 0 24px rgba(0,0,0,.3); }
  .sidebar-overlay.show { z-index: 9200; }
}

/* Input + select — better tap targets */
@media (max-width: 768px) {
  .form-control, input[type="text"], input[type="number"], input[type="email"],
  input[type="password"], input[type="date"], select, textarea {
    font-size: 16px;       /* prevents iOS Safari auto-zoom on focus */
    min-height: 40px;
  }
  textarea { min-height: 64px; }
}

/* Action button rows (e.g. transformer/inspection edit/delete) — wrap on mobile */
@media (max-width: 600px) {
  td .btn-sm, td a.btn-sm { margin: 2px; display: inline-flex; align-items: center; justify-content: center; }
}

