/* =====================================================
   WEB ASSESSOR — Mobile-first, iPhone optimized
   ===================================================== */

/* Override common.css for mobile */
body {
  margin: 0;
  padding: 0;
  background: #f5f5f5;
  background-image: none;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
.container { max-width: 100%; padding: 0; }

/* =====================================================
   TOP BAR
   ===================================================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #1976D2;
  color: white;
  display: flex;
  align-items: center;
  padding: 0 12px;
  height: 56px;
  padding-top: env(safe-area-inset-top);
  box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}
.topbar-back {
  background: none;
  border: none;
  color: white;
  font-size: 32px;
  padding: 0;
  cursor: pointer;
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.topbar-title {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 8px;
}
.topbar-home {
  color: white;
  font-size: 26px;
  text-decoration: none;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.9;
}
.topbar-home:active { opacity: 0.6; }
.topbar-save {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  font-size: 15px;
  font-weight: 600;
  padding: 8px 18px;
  border-radius: 8px;
  cursor: pointer;
  min-height: 38px;
  flex-shrink: 0;
}
.topbar-save:disabled { opacity: 0.35; }
.topbar-save:active:not(:disabled) { background: rgba(255,255,255,0.35); }

/* =====================================================
   APP & SCREENS
   ===================================================== */
.app {
  padding-bottom: 80px;
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
}
.screen-pad { padding: 16px; }

/* =====================================================
   FORM ELEMENTS — 16px font prevents iOS zoom
   ===================================================== */
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #888;
  margin: 14px 16px 4px;
}
.mobile-select,
.mobile-input {
  display: block;
  width: calc(100% - 32px);
  margin: 0 16px;
  padding: 12px 14px;
  font-size: 16px;
  border: 1px solid #ddd;
  border-radius: 10px;
  background: white;
  color: #333;
  -webkit-appearance: none;
  appearance: none;
}
.mobile-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23999' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}
textarea.mobile-input { resize: vertical; font-family: inherit; }

/* =====================================================
   CARD LISTS — nav cards for drill-down
   ===================================================== */
.card-list { padding: 8px 12px; }
.nav-card {
  display: flex;
  align-items: center;
  background: white;
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
.nav-card:active { background: #f4f4f4; }
.nav-card-body { flex: 1; min-width: 0; }
.nav-card-title {
  font-size: 16px;
  font-weight: 600;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-card-sub {
  font-size: 13px;
  color: #999;
  margin-top: 2px;
}
.nav-card-count {
  background: #e8eaf6;
  color: #3949ab;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 12px;
  margin-left: 8px;
  flex-shrink: 0;
}
.nav-card-chevron {
  color: #ccc;
  font-size: 22px;
  margin-left: 8px;
  flex-shrink: 0;
}

/* =====================================================
   SYSTEM/SUBSYSTEM GROUP HEADERS
   ===================================================== */
.group-section { padding: 0 12px; }
.group-header {
  padding: 14px 4px 6px;
  font-size: 13px;
  font-weight: 700;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 4px;
}
.group-header:active { color: #666; }
.group-header-chevron {
  font-size: 10px;
  display: inline-block;
  transition: transform 0.15s;
}
.group-section.collapsed > .card-list { display: none; }
.group-header-count {
  background: #e8eaf6;
  color: #3949ab;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 4px;
}

/* =====================================================
   ASSET CARD
   ===================================================== */
.asset-card {
  background: white;
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}
.asset-card:active { background: #f4f4f4; }
.asset-card-name {
  font-size: 16px;
  font-weight: 600;
  color: #333;
}
.asset-card-group {
  font-size: 12px;
  color: #999;
  margin-top: 2px;
}
.asset-card-attrs {
  font-size: 13px;
  color: #666;
  margin-top: 2px;
  font-weight: 500;
}
.asset-card-meta {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
  align-items: center;
}
.chip {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 10px;
  background: #f0f0f0;
  color: #666;
}
.chip.status-preloaded { background: #fff3e0; color: #e65100; }
.chip.status-review { background: #ffebee; color: #b71c1c; }
.chip.photo { background: #f3e5f5; color: #7b1fa2; }
.chip.def-major { background: #ffebee; color: #c62828; }
.chip.def-moderate { background: #fff3e0; color: #e65100; }
.chip.def-minor { background: #f5f5f5; color: #666; }

/* =====================================================
   DETAIL SCREEN
   ===================================================== */
.detail-name {
  font-size: 22px;
  font-weight: 700;
  color: #333;
  padding: 16px 16px 4px;
}
.detail-status { padding: 0 16px 8px; }
.detail-fields { padding: 0 16px; }
.detail-field {
  padding: 0 0 4px;
}
.detail-fields .form-section {
  border-top: 1px solid #eee;
  margin-top: 8px;
  padding-top: 4px;
}
.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 11px 0;
  border-bottom: 1px solid #f0f0f0;
  font-size: 14px;
  gap: 12px;
}
.detail-row-label { color: #999; flex-shrink: 0; }
.detail-row-value {
  color: #333;
  font-weight: 500;
  text-align: right;
  word-break: break-word;
}
.edit-actions {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
}
.edit-actions .mobile-btn {
  margin: 0;
  width: auto;
  flex: 1;
  border: 1px solid #1976D2;
  border-style: solid;
}
.edit-actions .mobile-btn.save {
  background: #1976D2;
  color: white;
  border-color: #1976D2;
}
.edit-actions .mobile-btn.save:disabled {
  background: #b0b0b0;
  border-color: #b0b0b0;
}
.edit-actions .mobile-btn.cancel {
  background: white;
  color: #666;
  border-color: #ccc;
}
.edit-actions .mobile-btn.cancel:active { background: #f5f5f5; }

/* Section dividers */
.section-divider {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 8px;
  border-top: 6px solid #eee;
  margin-top: 4px;
}
.section-divider h3 {
  margin: 0;
  font-size: 16px;
  color: #333;
}
.section-action-btn {
  background: #1976D2;
  color: white;
  border: none;
  padding: 8px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  min-height: 38px;
}
.section-action-btn:active { opacity: 0.85; }
.count-badge {
  background: #e3f2fd;
  color: #1565c0;
  padding: 2px 9px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
  margin-left: 6px;
  vertical-align: middle;
}

/* =====================================================
   DEFICIENCY CARDS (detail screen)
   ===================================================== */
.def-card {
  background: white;
  border-radius: 12px;
  padding: 14px 16px;
  margin: 0 12px 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.def-card-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.sev-badge {
  padding: 3px 9px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}
.sev-badge.major { background: #ffebee; color: #c62828; }
.sev-badge.moderate { background: #fff3e0; color: #e65100; }
.sev-badge.minor { background: #f5f5f5; color: #666; }
.def-card-type { font-weight: 600; font-size: 15px; color: #333; }
.ls-flag {
  background: #c62828;
  color: white;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 3px;
  text-transform: uppercase;
}
.def-card-info {
  font-size: 13px;
  color: #777;
  margin-top: 6px;
  line-height: 1.4;
}
.def-card-photos {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.def-card-photos img {
  width: 52px;
  height: 52px;
  object-fit: cover;
  border-radius: 6px;
}
.def-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #f0f0f0;
}
.def-action-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  background: white;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  min-height: 42px;
}
.def-action-btn:active { background: #f5f5f5; }
.def-action-btn.delete { color: #c62828; border-color: #ffcdd2; }
.def-action-btn.delete:active { background: #ffebee; }

/* =====================================================
   PHOTO GRID (detail screen)
   ===================================================== */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 0 12px 16px;
}
.photo-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  cursor: pointer;
}
.photo-upload-status {
  text-align: center;
  padding: 8px 16px;
  color: #1565c0;
  font-size: 14px;
}

/* =====================================================
   FAB (Floating Action Button)
   ===================================================== */
.fab {
  position: fixed;
  bottom: 24px;
  right: 20px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #1976D2;
  color: white;
  border: none;
  font-size: 30px;
  font-weight: 300;
  box-shadow: 0 4px 14px rgba(25,118,210,0.45);
  cursor: pointer;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
}
.fab:active { transform: scale(0.9); }

/* =====================================================
   FULL-SCREEN MODALS
   ===================================================== */
.modal-fullscreen {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #f5f5f5;
  z-index: 200;
  display: flex;
  flex-direction: column;
}
.modal-topbar {
  background: #1976D2;
  color: white;
  display: flex;
  align-items: center;
  padding: 0 12px;
  min-height: 56px;
  padding-top: env(safe-area-inset-top);
  flex-shrink: 0;
}
.modal-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 40px;
  padding-bottom: calc(40px + env(safe-area-inset-bottom));
}

/* Form sections */
.form-section { padding: 8px 0 4px; }
.form-section h4 {
  font-size: 12px;
  font-weight: 700;
  color: #999;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 8px 16px 0;
  margin: 0;
}

/* Read-only context fields in Add Asset */
.aa-readonly-fields {
  padding: 4px 16px;
}
.aa-readonly-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #f0f0f0;
  font-size: 14px;
}
.aa-readonly-row .label {
  color: #999;
  flex-shrink: 0;
}
.aa-readonly-row .value {
  color: #333;
  font-weight: 500;
  text-align: right;
  word-break: break-word;
}

/* Mobile button (dashed outline) */
.mobile-btn {
  display: block;
  margin: 8px 16px;
  padding: 14px;
  background: white;
  border: 1px dashed #bbb;
  border-radius: 10px;
  font-size: 15px;
  color: #1976D2;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  width: calc(100% - 32px);
  min-height: 48px;
}
.mobile-btn:active { background: #e3f2fd; border-color: #90caf9; }

/* Photo previews */
.photo-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 16px;
}
.photo-preview {
  position: relative;
  width: 72px;
  height: 72px;
}
.photo-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 8px;
}
.photo-preview .remove {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #333;
  color: white;
  border: 2px solid white;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Checkbox row */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  font-size: 16px;
  color: #333;
  cursor: pointer;
}
.checkbox-row input[type="checkbox"] {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

/* Errors & status */
.photo-error {
  color: #c62828;
  font-size: 13px;
  font-weight: 500;
  padding: 4px 16px;
}
.save-status {
  padding: 10px 16px;
  font-size: 14px;
  text-align: center;
}
.save-status.saving { color: #1565c0; }
.save-status.success { color: #2e7d32; }
.save-status.error { color: #c62828; }
.req { color: #c62828; }

/* Search */
.search-wrap { padding: 8px 12px 0; }
.mobile-search {
  width: 100%;
  padding: 12px 16px;
  font-size: 16px;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  background: white;
  -webkit-appearance: none;
  appearance: none;
}

/* Empty state */
.empty-msg {
  text-align: center;
  padding: 48px 16px;
  color: #aaa;
  font-size: 15px;
}

/* =====================================================
   LIGHTBOX
   ===================================================== */
.lightbox-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.95);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lb-close {
  position: absolute;
  top: 12px; right: 12px;
  top: calc(12px + env(safe-area-inset-top));
  background: none;
  border: none;
  color: white;
  font-size: 36px;
  cursor: pointer;
  padding: 8px;
  z-index: 301;
}
.lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: white;
  font-size: 48px;
  cursor: pointer;
  padding: 16px;
  z-index: 301;
  min-width: 48px;
  min-height: 64px;
}
.lb-nav.prev { left: 0; }
.lb-nav.next { right: 0; }
.lb-img-wrap { max-width: 100%; max-height: 100%; }
.lb-img-wrap img {
  max-width: 100vw;
  max-height: 100vh;
  object-fit: contain;
}

/* =====================================================
   PENDING DEF CARDS (add-asset modal)
   ===================================================== */
.pending-def {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  margin: 4px 16px;
  background: white;
  border-radius: 10px;
  border: 1px solid #e0e0e0;
  flex-wrap: wrap;
}
.pending-def .sev-badge { flex-shrink: 0; }
.pending-def .def-card-type { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pending-def .remove {
  margin-left: auto;
  background: none;
  border: none;
  color: #c62828;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  flex-shrink: 0;
}

/* =====================================================
   BARCODE INPUT ROW
   ===================================================== */
.barcode-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 16px;
}
.barcode-input-row .mobile-input {
  flex: 1;
  margin: 0;
  width: auto;
}
.barcode-scan-btn {
  background: #1976D2;
  color: white;
  border: none;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  white-space: nowrap;
  flex-shrink: 0;
}
.barcode-scan-btn:active { opacity: 0.85; }

/* =====================================================
   BARCODE SCANNER OVERLAY
   ===================================================== */
.scanner-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: #000;
  z-index: 250;
  display: flex;
  flex-direction: column;
}
.scanner-body {
  flex: 1;
  position: relative;
  overflow: hidden;
}
#scannerReader {
  width: 100%;
  height: 100%;
}
#scannerReader video {
  object-fit: cover !important;
}
.scanner-status {
  position: absolute;
  bottom: 40px;
  left: 0; right: 0;
  text-align: center;
  color: white;
  font-size: 16px;
  font-weight: 500;
  text-shadow: 0 1px 4px rgba(0,0,0,0.6);
  z-index: 1;
  pointer-events: none;
}

/* =====================================================
   ACTION SHEET (iOS-style bottom picker)
   ===================================================== */
.action-sheet-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 260;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.action-sheet {
  background: #f5f5f5;
  width: 100%;
  max-width: 500px;
  border-radius: 14px 14px 0 0;
  padding: 8px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
}
.action-sheet-title {
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: #999;
  padding: 10px 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.action-sheet-btn {
  display: block;
  width: 100%;
  padding: 14px;
  border: none;
  background: white;
  font-size: 17px;
  color: #1976D2;
  cursor: pointer;
  text-align: center;
  border-radius: 0;
  margin-bottom: 1px;
}
.action-sheet-btn:first-of-type { border-radius: 10px 10px 0 0; }
.action-sheet-btn:last-of-type { border-radius: 0 0 10px 10px; }
.action-sheet-btn:only-of-type { border-radius: 10px; }
.action-sheet-btn:active { background: #e8e8e8; }
.action-sheet-btn.cancel {
  margin-top: 8px;
  border-radius: 10px;
  font-weight: 600;
  color: #c62828;
}

/* =====================================================
   PHOTO LABEL ON THUMBNAILS
   ===================================================== */
.photo-preview .photo-label,
.photo-grid .photo-label {
  font-size: 10px;
  font-weight: 600;
  color: #555;
  text-align: center;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.photo-grid-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.photo-grid-item img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 8px;
  cursor: pointer;
}
.photo-grid-item .photo-label {
  font-size: 10px;
  font-weight: 600;
  color: #555;
  text-align: center;
  margin-top: 2px;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* =====================================================
   NOTES INPUT ROW (with phrase button)
   ===================================================== */
.notes-input-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 16px;
}
.notes-input-row .mobile-input {
  flex: 1;
  margin: 0;
  width: auto;
}
.notes-phrase-btn {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid #ddd;
  background: white;
  font-size: 24px;
  color: #1976D2;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  margin-top: 2px;
}
.notes-phrase-btn:active { background: #e3f2fd; }
