:root {
  --bg-page: #f1f5f9;
  --bg-card: #ffffff;
  --bg-dark: #0f172a;
  --bg-dark-2: #1e293b;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --primary: #21357A;
  --primary-hover: #18275C;
  --primary-soft: #EEF2FF;
  --success: #059669;
  --success-soft: #ecfdf5;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --info: #2563eb;
  --info-soft: #eff6ff;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: #cbd5e1;
  color: var(--text-primary);
  line-height: 1.45;
  min-height: 100vh;
  display: flex;
  justify-content: center;
}

#app-shell {
  width: 100%;
  max-width: 480px;
  min-height: 100vh;
  background: var(--bg-page);
  position: relative;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 40px rgba(15, 23, 42, 0.18);
}

.hidden { display: none !important; }
.print-only { display: none; }

/* ==================== BUTTONS & INPUTS ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: none;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease, opacity 0.15s ease;
  min-height: 44px;
}
.btn:active { transform: scale(0.98); }
.btn svg { width: 18px; height: 18px; flex-shrink: 0; }
.btn-block { width: 100%; }
.btn-lg { padding: 14px 20px; font-size: 1rem; }
.btn-sm { padding: 8px 12px; font-size: 0.82rem; min-height: 36px; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--bg-dark); color: #fff; }
.btn-outline {
  background: #fff;
  color: var(--text-primary);
  border: 1.5px solid var(--border);
}
.btn-danger-outline {
  background: #fff;
  color: var(--danger);
  border: 1.5px solid #fecaca;
}
.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-weight: 700;
  font-size: 0.84rem;
  cursor: pointer;
  font-family: inherit;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; }

input, select, textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.94rem;
  color: var(--text-primary);
  background: #fff;
  outline: none;
  transition: border-color 0.15s ease;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
}

.form-group { margin-bottom: 14px; }
.form-group label, .field-title {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* ==================== LOGIN VIEW ==================== */
#login-view {
  min-height: 100vh;
  background: linear-gradient(165deg, #0f172a 0%, #162454 55%, #21357A 100%);
  color: #fff;
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.login-wrapper {
  width: 100%;
  max-width: 400px;
  margin: 0 auto;
}
.login-brand {
  text-align: center;
  margin-bottom: 24px;
}
.brand-badge {
  width: 72px;
  height: 72px;
  margin: 0 auto 14px;
  border-radius: 18px;
  background: #21357A;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 25px rgba(33, 53, 122, 0.45);
}
.brand-badge img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.company-tag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 1.5px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #93c5fd;
  margin-bottom: 8px;
}
.login-brand h1 { font-size: 1.55rem; font-weight: 800; margin-bottom: 6px; }
.login-brand p { font-size: 0.82rem; color: #cbd5e1; }

.login-card {
  background: #fff;
  color: var(--text-primary);
  border-radius: 18px;
  padding: 22px 18px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
}
.input-icon-wrap { position: relative; }
.input-icon-wrap .input-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-muted);
}
.input-icon-wrap input { padding-left: 38px; }

.alert-error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 12px;
}

.demo-accounts {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
}
.demo-accounts p {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-align: center;
}
.demo-chips { display: flex; flex-direction: column; gap: 6px; }
.chip-btn {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #f8fafc;
  font-family: inherit;
  font-size: 0.78rem;
  color: var(--text-secondary);
  cursor: pointer;
  text-align: left;
}
.chip-btn:hover { border-color: var(--primary); background: var(--primary-soft); }
.login-footer { text-align: center; margin-top: 18px; font-size: 0.76rem; color: #94a3b8; }

/* ==================== HEADER & LAYOUT ==================== */
#main-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--bg-dark);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 12px rgba(15, 23, 42, 0.2);
}
.header-left { display: flex; align-items: center; gap: 10px; }
.header-logo {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: #21357A;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.header-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.header-company {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 1px;
  color: #93c5fd;
}
.header-title { font-size: 1rem; font-weight: 700; }
.header-right { display: flex; align-items: center; gap: 8px; }
.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  font-size: 0.78rem;
  font-weight: 600;
}
.user-dot { width: 7px; height: 7px; border-radius: 50%; background: #10b981; }

.app-content {
  flex: 1;
  padding: 14px 14px calc(86px + var(--safe-bottom));
}
.tab-view { display: none; }
.tab-view.active { display: block; animation: fadeIn 0.18s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ==================== CARDS & DASHBOARD ==================== */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(226, 232, 240, 0.8);
}
.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
}
.card-head h3 { font-size: 1rem; font-weight: 700; }
.card-head p, .muted-text { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }

.progress-banner {
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.15);
}
.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.progress-label { font-size: 0.74rem; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.6px; }
.progress-header h2 { font-size: 1.15rem; font-weight: 700; }
.progress-percent {
  font-size: 1.5rem;
  font-weight: 800;
  color: #34d399;
  font-family: 'JetBrains Mono', monospace;
}
.progress-track {
  height: 8px;
  background: rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 10px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #10b981, #34d399);
  border-radius: 999px;
  transition: width 0.4s ease;
}
.progress-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  color: #cbd5e1;
}
.progress-meta .link-btn { color: #93c5fd; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.kpi-card {
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--bg-dark);
}
.kpi-good { border-left-color: var(--success); }
.kpi-warn { border-left-color: var(--warning); }
.kpi-pending { border-left-color: var(--text-muted); }
.kpi-value {
  font-size: 1.5rem;
  font-weight: 800;
  font-family: 'JetBrains Mono', monospace;
}
.kpi-label { font-size: 0.78rem; color: var(--text-muted); font-weight: 600; }

.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}
.search-box {
  flex: 1;
  position: relative;
}
.search-box svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 17px;
  height: 17px;
  color: var(--text-muted);
}
.search-box input { padding-left: 36px; }

.filter-pills {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 10px;
  scrollbar-width: none;
}
.filter-pills::-webkit-scrollbar { display: none; }
.pill {
  flex-shrink: 0;
  padding: 7px 13px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  white-space: nowrap;
  cursor: pointer;
}
.pill.active {
  background: var(--bg-dark);
  color: #fff;
  border-color: var(--bg-dark);
}

/* APAR Item Card */
.apar-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.apar-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.apar-id {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--primary);
}
.apar-loc { font-size: 0.96rem; font-weight: 700; margin-top: 2px; }
.apar-specs { font-size: 0.78rem; color: var(--text-muted); }

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge-good { background: var(--success-soft); color: var(--success); }
.badge-warn { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-pending { background: #f1f5f9; color: var(--text-muted); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-mono {
  font-family: 'JetBrains Mono', monospace;
  background: var(--bg-dark);
  color: #fff;
}

.apar-card-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-top: 8px;
  border-top: 1px solid #f1f5f9;
  font-size: 0.76rem;
  color: var(--text-muted);
}
.apar-actions { display: flex; gap: 6px; }

/* ==================== SCANNER VIEW ==================== */
.scanner-box {
  position: relative;
  width: 100%;
  min-height: 240px;
  background: #0f172a;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}
#qr-reader,
#public-qr-reader {
  width: 100%;
}
#qr-reader video,
#public-qr-reader video {
  width: 100% !important;
  height: auto !important;
  display: block;
}
.scanner-placeholder {
  text-align: center;
  color: #94a3b8;
  padding: 24px;
}
.scanner-placeholder svg { width: 52px; height: 52px; margin-bottom: 10px; color: #f87171; }
.scanner-placeholder p { font-size: 0.82rem; }
.scan-controls { display: flex; flex-direction: column; gap: 8px; }

.manual-input-row {
  display: flex;
  gap: 8px;
  margin: 10px 0 14px;
}
.manual-input-row input {
  flex: 1;
  font-family: 'JetBrains Mono', monospace;
  text-transform: uppercase;
}
.manual-input-row .btn { width: auto; padding: 0 20px; }
.chip-wrap { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.mini-chip {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #f8fafc;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--text-primary);
  cursor: pointer;
}
.mini-chip:hover { border-color: var(--primary); color: var(--primary); }

/* ==================== INSPECT VIEW ==================== */
.inspect-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--text-primary);
  cursor: pointer;
}
.btn-back svg { width: 18px; height: 18px; }

.unit-summary-card {
  background: linear-gradient(135deg, #fff 0%, #f8fafc 100%);
  border-left: 4px solid var(--primary);
}
.unit-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
  font-size: 0.8rem;
}
.unit-meta-grid div span { display: block; color: var(--text-muted); font-size: 0.72rem; }

.section-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 14px 2px 8px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-secondary);
}

.check-item {
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 13px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.check-item-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 8px;
}
.check-title { font-size: 0.9rem; font-weight: 700; }
.check-desc { font-size: 0.76rem; color: var(--text-muted); margin-top: 2px; }

.toggle-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 8px;
}
.toggle-btn {
  padding: 9px 10px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: #f8fafc;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-secondary);
  cursor: pointer;
}
.toggle-btn.ok.active {
  background: var(--success-soft);
  border-color: var(--success);
  color: var(--success);
}
.toggle-btn.nok.active {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}
.check-note {
  margin-top: 8px;
  font-size: 0.82rem;
  padding: 8px 10px;
}
.check-note.is-invalid {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.month-filter-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}
.month-filter-row input[type="month"] {
  flex: 1;
}
.month-filter-row .btn {
  width: auto;
  white-space: nowrap;
}

.unit-history-section {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
}
.unit-history-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.unit-history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
  margin-bottom: 6px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  font-family: inherit;
}
.unit-history-item:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.photo-preview {
  position: relative;
  margin-top: 10px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.photo-preview img { width: 100%; max-height: 220px; object-fit: cover; display: block; }
.btn-remove-photo {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: rgba(15, 23, 42, 0.75);
  color: #fff;
  font-size: 1.1rem;
  cursor: pointer;
}
.inspector-meta-box {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}
.sticky-submit { margin-top: 6px; box-shadow: 0 8px 20px rgba(33, 53, 122, 0.28); }

/* ==================== HISTORY & REPORT ==================== */
.history-card {
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 13px 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  cursor: pointer;
}
.history-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}
.history-meta { font-size: 0.76rem; color: var(--text-muted); margin-top: 4px; }

.action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.action-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #f8fafc;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}
.action-tile svg { width: 22px; height: 22px; margin-bottom: 4px; }
.action-tile strong { font-size: 0.86rem; color: var(--text-primary); }
.action-tile span { font-size: 0.72rem; color: var(--text-muted); }
.tile-green svg { color: var(--success); }
.tile-blue svg { color: var(--info); }
.tile-red svg { color: var(--danger); }
.tile-slate svg { color: var(--bg-dark); }

.import-box { display: flex; flex-direction: column; gap: 10px; }
.import-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ==================== BOTTOM NAV ==================== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  background: #fff;
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 6px 6px calc(6px + var(--safe-bottom));
  z-index: 40;
}
.nav-item {
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 4px;
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}
.nav-item svg { width: 20px; height: 20px; }
.nav-item.active { color: var(--primary); font-weight: 700; }
.nav-scan { position: relative; }
.scan-fab {
  width: 42px;
  height: 42px;
  margin-top: -18px;
  border-radius: 14px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 16px rgba(33, 53, 122, 0.35);
}

/* ==================== MODAL & TOAST ==================== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
}
.modal-sheet {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 88vh;
  background: #fff;
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.2s ease;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1rem; font-weight: 700; }
.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
}
.modal-body { padding: 16px 18px 24px; overflow-y: auto; }

.barcode-label-box {
  border: 2px dashed var(--bg-dark);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  margin-bottom: 14px;
  background: #fff;
}
.barcode-bars {
  height: 48px;
  margin: 10px auto;
  max-width: 220px;
  background: repeating-linear-gradient(
    90deg,
    #0f172a 0px, #0f172a 3px,
    transparent 3px, transparent 5px,
    #0f172a 5px, #0f172a 6px,
    transparent 6px, transparent 9px,
    #0f172a 9px, #0f172a 13px,
    transparent 13px, transparent 15px
  );
}

.toast {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-dark);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  z-index: 200;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
  max-width: 90%;
  text-align: center;
}

.empty-state {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-muted);
  font-size: 0.86rem;
}

/* Mobile header menu hidden on desktop */
.mobile-menu-btn { display: none; }
.mobile-nav-menu { display: none; }

/* ==================== PRINT STYLES (PDF REPORT) ==================== */
@media print {
  body { background: #fff; display: block; }
  #app-shell { max-width: 100%; box-shadow: none; }
  #login-view, #main-container, .modal, .toast { display: none !important; }
  .print-only { display: block !important; padding: 16px; font-size: 11px; color: #000; }
  .print-header {
    border-bottom: 2px solid #0f172a;
    padding-bottom: 10px;
    margin-bottom: 14px;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
  }
  .print-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
  }
  .print-table th, .print-table td {
    border: 1px solid #94a3b8;
    padding: 6px 8px;
    text-align: left;
  }
  .print-table th { background: #e2e8f0; }
}

/* ==================== MOBILE RESPONSIVE & ACCESSIBILITY (<= 600px) ==================== */
@media (max-width: 600px) {
  html, body {
    font-size: 16px;
    overflow-x: hidden;
  }

  #app-shell {
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
    box-shadow: none;
  }

  /* Prevent automatic zoom on input focus & ensure readable form text */
  input, select, textarea, .check-note {
    font-size: 16px;
  }

  /* Constrain shrinking flex items & media to prevent horizontal overflow */
  .header-left,
  .header-left > div,
  .header-right,
  .apar-card-top > div,
  .check-item-head > div,
  .search-box,
  .manual-input-row input {
    min-width: 0;
  }

  .header-title {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  img, canvas, #qr-reader, #qr-reader video, #public-qr-reader, #public-qr-reader video {
    max-width: 100%;
    height: auto;
  }

  .brand-badge img,
  .header-logo img {
    height: 100%;
  }

  .photo-preview img {
    width: 100%;
    max-height: 220px;
  }

  /* Wrap/stack flex & grid containers cleanly on narrow screens */
  .app-header {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 12px;
  }

  .toolbar,
  .manual-input-row,
  .apar-card-foot,
  .progress-meta,
  .import-actions,
  .apar-actions,
  .inspector-meta-box {
    flex-wrap: wrap;
    gap: 8px;
  }

  .form-row,
  .unit-meta-grid {
    grid-template-columns: 1fr;
  }

  /* Minimum 44x44px tap targets for all interactive controls */
  .icon-btn,
  .mobile-menu-btn,
  .modal-close,
  .btn-remove-photo {
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .btn,
  .pill,
  .toggle-btn,
  .link-btn,
  .btn-back,
  .mini-chip {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .chip-btn {
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  /* Keep bottom nav visible on mobile for 1-tap Scan access */
  .bottom-nav {
    display: grid;
  }

  .app-content {
    padding: 14px 12px calc(86px + var(--safe-bottom));
  }

  .toast {
    bottom: 84px;
  }

  .mobile-menu-btn {
    display: none;
  }

  .mobile-nav-menu {
    display: flex;
    flex-direction: column;
    background: var(--bg-dark-2);
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    padding: 8px 12px;
    gap: 4px;
    position: sticky;
    top: 64px;
    z-index: 29;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.25);
  }

  .mobile-nav-menu.hidden {
    display: none;
  }

  .mobile-nav-menu .nav-item {
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    min-height: 44px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.94rem;
    color: #cbd5e1;
    width: 100%;
    text-align: left;
  }

  .mobile-nav-menu .nav-item.active {
    background: var(--primary);
    color: #fff;
  }
}

@media (max-width: 360px) {
  .kpi-grid,
  .action-grid,
  .toggle-pair {
    grid-template-columns: 1fr;
  }
}
