/* =====================================================
   VIEWER STYLES
   ===================================================== */

.container { max-width: 1200px; }

/* Selector bar */
.selector-bar {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.selector-bar select {
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
  background: white;
  cursor: pointer;
  min-width: 180px;
}
.selector-bar select:focus { outline: none; border-color: #2196F3; }
.selector-bar select:disabled { background: #f5f5f5; cursor: not-allowed; }

/* Search and filter */
.search-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.search-bar input {
  flex: 1;
  min-width: 200px;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
}
.search-bar input:focus { outline: none; border-color: #2196F3; }
.search-bar select {
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 14px;
  background: white;
}
.search-bar select:focus { outline: none; border-color: #2196F3; }

.export-btn {
  background: #4CAF50;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}
.export-btn:hover { background: #43A047; }
.export-btn:disabled { background: #ccc; cursor: not-allowed; }

/* Stats row */
.stats-row {
  display: flex;
  gap: 15px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.stat-badge {
  background: #e3f2fd;
  color: #1565c0;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
}

/* Asset table */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead th {
  background: #f5f5f5;
  padding: 10px 12px;
  text-align: left;
  border-bottom: 2px solid #ddd;
  font-weight: 600;
  color: #333;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
thead th:hover { background: #e8e8e8; }
thead th .sort-arrow { margin-left: 4px; color: #999; }
thead th .sort-arrow.active { color: #2196F3; }
tbody tr { border-bottom: 1px solid #eee; }
tbody tr:hover { background: #f8f9ff; }
tbody td {
  padding: 10px 12px;
  color: #444;
  max-width: 250px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}
.badge.arch { background: #e8f5e9; color: #2e7d32; }
.badge.mep  { background: #e3f2fd; color: #1565c0; }
.badge.status { background: #f5f5f5; color: #666; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #999;
}
.empty-state .icon { font-size: 48px; margin-bottom: 10px; }

/* Pagination */
.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  font-size: 13px;
  color: #666;
}
.pagination button {
  background: #2196F3;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
.pagination button:hover { background: #1976D2; }
.pagination button:disabled { background: #ccc; cursor: not-allowed; }
.pagination .page-buttons { display: flex; gap: 6px; }

/* =====================================================
   TREE VIEW
   ===================================================== */
.tree-card { margin-bottom: 20px; }
.tree-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.tree-header h2 { margin: 0; }
.tree-stats { display: flex; gap: 15px; flex-wrap: wrap; }
.tree-stat { font-size: 13px; color: #666; }
.tree-stat strong { color: #333; }
.tree-list { list-style: none; padding: 0; margin: 0; }
.tree-list li { padding: 0; }
.tree-item {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.1s;
}
.tree-item:hover { background: #f5f5f5; }
.tree-item.selected { background: #e3f2fd; }
.tree-item .expand {
  width: 20px;
  margin-right: 6px;
  color: #999;
  font-size: 12px;
  text-align: center;
  flex-shrink: 0;
}
.tree-item .label { flex: 1; font-size: 14px; color: #333; }
.tree-item .count { font-size: 12px; color: #999; margin-left: 8px; }
.tree-children { padding-left: 26px; display: none; }
.tree-children.open { display: block; }

/* =====================================================
   DETAIL PANEL
   ===================================================== */
.detail-panel {
  background: #fafafa;
  border-radius: 6px;
  padding: 16px;
  margin-bottom: 16px;
  display: none;
}
.detail-panel.show { display: block; }
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}
.detail-item { font-size: 13px; }
.detail-item .dlabel {
  color: #999;
  font-size: 11px;
  text-transform: uppercase;
  margin-bottom: 2px;
}
.detail-item .dvalue { color: #333; font-weight: 500; }

/* Edit mode */
.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.detail-header h2 { margin: 0; }
.edit-actions { display: flex; gap: 8px; align-items: center; }

.save-btn {
  background: #4CAF50;
  color: white;
  border: none;
  padding: 8px 20px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}
.save-btn:hover { background: #43A047; }
.save-btn:disabled { background: #ccc; cursor: not-allowed; }

.cancel-btn {
  background: none;
  border: 1px solid #999;
  color: #666;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
.cancel-btn:hover { background: #f5f5f5; }

.edit-input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
}
.edit-input:focus {
  outline: none;
  border-color: #2196F3;
  box-shadow: 0 0 0 2px rgba(33,150,243,0.15);
}
.edit-input.changed { border-color: #FF9800; background: #fff8e1; }

.edit-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.edit-input-row .edit-input { flex: 1; }
.edit-suffix {
  font-size: 13px;
  font-weight: 600;
  color: #555;
  white-space: nowrap;
}

.edit-select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 13px;
  background: white;
}
.edit-select:focus { outline: none; border-color: #2196F3; }
.edit-select.changed { border-color: #FF9800; background: #fff8e1; }

.detail-item .readonly-badge {
  font-size: 9px;
  color: #999;
  text-transform: uppercase;
  margin-left: 6px;
}

.save-status {
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 4px;
  margin-top: 12px;
  display: none;
}
.save-status.show { display: block; }
.save-status.success { background: #e8f5e9; color: #2e7d32; }
.save-status.error   { background: #ffebee; color: #c62828; }
.save-status.saving  { background: #e3f2fd; color: #1565c0; }

/* =====================================================
   BULK OPERATIONS
   ===================================================== */
.bulk-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #e3f2fd;
  padding: 10px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
}
.bulk-bar span { font-weight: 600; color: #1565c0; font-size: 14px; }
.bulk-btn {
  border: none;
  padding: 7px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}
.bulk-btn.update { background: #FF9800; color: white; }
.bulk-btn.update:hover { background: #F57C00; }
.bulk-btn.delete { background: #f44336; color: white; }
.bulk-btn.delete:hover { background: #d32f2f; }
.bulk-btn.clear { background: white; color: #666; border: 1px solid #ccc; }
.bulk-btn.clear:hover { background: #f5f5f5; }
.bulk-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.cb-col { width: 40px; text-align: center; }
.cb-col input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }
thead th.cb-col { cursor: default; }
thead th.cb-col:hover { background: #f5f5f5; }
tbody tr.selected-row { background: #e3f2fd; }
tbody tr.selected-row:hover { background: #bbdefb; }

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal {
  background: white;
  border-radius: 8px;
  padding: 28px;
  max-width: 480px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.modal h3 { margin: 0 0 8px 0; color: #333; }
.modal p { color: #666; margin: 0 0 16px 0; font-size: 14px; line-height: 1.5; }
.modal label { display: block; font-size: 13px; color: #666; margin-bottom: 4px; }
.modal select,
.modal input[type="text"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 14px;
  background: white;
}
.modal select:focus,
.modal input[type="text"]:focus { outline: none; border-color: #2196F3; }
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}
.delete-confirm-btn {
  background: #f44336;
  color: white;
  border: none;
  padding: 8px 20px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}
.delete-confirm-btn:hover { background: #d32f2f; }
.delete-confirm-btn:disabled { background: #ccc; cursor: not-allowed; }

.bulk-progress { margin-top: 12px; font-size: 13px; color: #666; }
.bulk-progress .bar {
  height: 6px;
  background: #e0e0e0;
  border-radius: 3px;
  margin-top: 6px;
  overflow: hidden;
}
.bulk-progress .bar-fill {
  height: 100%;
  background: #2196F3;
  border-radius: 3px;
  transition: width 0.2s;
}

/* =====================================================
   ADD ASSET MODAL
   ===================================================== */
.modal.wide {
  max-width: 680px;
  max-height: 90vh;
  overflow-y: auto;
}
.add-form-section { margin-bottom: 16px; }
.add-form-section h4 {
  margin: 0 0 10px 0;
  font-size: 13px;
  text-transform: uppercase;
  color: #999;
  border-bottom: 1px solid #eee;
  padding-bottom: 6px;
}
.add-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.add-form-grid .full-width { grid-column: 1 / -1; }
.add-field label { display: block; font-size: 12px; color: #666; margin-bottom: 3px; }
.add-field label .req { color: #f44336; }
.add-field label .uom-label { font-weight: 600; color: #444; }
.add-field input,
.add-field select,
.add-field textarea {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid #ddd;
  border-radius: 4px;
  font-size: 13px;
  font-family: inherit;
  background: white;
}
.add-field input:focus,
.add-field select:focus,
.add-field textarea:focus {
  outline: none;
  border-color: #2196F3;
  box-shadow: 0 0 0 2px rgba(33,150,243,0.12);
}
.add-field textarea { resize: vertical; min-height: 50px; }
.add-asset-btn {
  background: #2196F3;
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}
.add-asset-btn:hover { background: #1976D2; }
.add-asset-btn:disabled { background: #ccc; cursor: not-allowed; }

/* =====================================================
   PHOTO GALLERY
   ===================================================== */
.photo-section {
  margin-top: 20px;
  border-top: 1px solid #eee;
  padding-top: 16px;
}
.photo-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.photo-section-header h3 { margin: 0; font-size: 15px; color: #333; }
.photo-count-badge {
  background: #e3f2fd;
  color: #1565c0;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}
.photo-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.photo-thumb {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  background: #f0f0f0;
  cursor: pointer;
  aspect-ratio: 1;
  border: 2px solid transparent;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.photo-thumb:hover {
  border-color: #2196F3;
  box-shadow: 0 2px 8px rgba(33,150,243,0.25);
}
.photo-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.photo-thumb .photo-label {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.7));
  color: white;
  padding: 18px 8px 6px;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.photo-thumb .photo-primary-badge {
  position: absolute;
  top: 6px; left: 6px;
  background: #FF9800;
  color: white;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 3px;
  text-transform: uppercase;
}

.photo-upload-btn {
  background: #2196F3;
  color: white;
  border: none;
  padding: 6px 14px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
}
.photo-upload-btn:hover { background: #1976D2; }
.photo-upload-btn:disabled { background: #ccc; cursor: not-allowed; }

.photo-upload-progress {
  margin-top: 8px;
  font-size: 12px;
  color: #1565c0;
  display: none;
}
.photo-upload-progress.show { display: block; }
.photo-upload-progress .bar {
  height: 4px;
  background: #e0e0e0;
  border-radius: 2px;
  margin-top: 4px;
  overflow: hidden;
}
.photo-upload-progress .bar-fill {
  height: 100%;
  background: #2196F3;
  border-radius: 2px;
  transition: width 0.2s;
}

.photo-empty {
  color: #999;
  font-size: 13px;
  padding: 20px;
  text-align: center;
  background: #fafafa;
  border-radius: 6px;
}
.photo-loading {
  color: #666;
  font-size: 13px;
  padding: 16px;
  text-align: center;
}

/* Add Asset — photo previews */
.add-photo-area {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 10px;
}
.add-photo-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 100%;
}
.add-photo-previews:empty { display: none; }
.add-photo-preview {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid #ddd;
  background: #f5f5f5;
}
.add-photo-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.add-photo-preview .remove-photo {
  position: absolute;
  top: 2px;
  right: 2px;
  background: rgba(0,0,0,0.6);
  color: white;
  border: none;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  font-size: 14px;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
  padding: 0;
}
.add-photo-preview .remove-photo:hover { background: rgba(200,0,0,0.8); }

/* Photo count in table */
.photo-count-cell { color: #1565c0; font-weight: 500; }
.photo-count-cell .cam-icon { font-size: 12px; margin-right: 2px; }

/* =====================================================
   LIGHTBOX
   ===================================================== */
.lightbox-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
.lightbox-close {
  position: absolute;
  top: 16px; right: 20px;
  background: none;
  border: none;
  color: white;
  font-size: 32px;
  cursor: pointer;
  padding: 4px 12px;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.lightbox-close:hover { opacity: 1; }
.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  font-size: 28px;
  cursor: pointer;
  padding: 12px 16px;
  border-radius: 4px;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.15s, background 0.15s;
}
.lightbox-nav:hover { opacity: 1; background: rgba(255,255,255,0.25); }
.lightbox-nav.prev { left: 16px; }
.lightbox-nav.next { right: 16px; }
.lightbox-nav:disabled { opacity: 0.2; cursor: default; background: none; }
.lightbox-img-wrap {
  max-width: 90vw;
  max-height: 80vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-img-wrap img {
  max-width: 100%;
  max-height: 80vh;
  border-radius: 4px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
}
.lightbox-caption {
  color: white;
  text-align: center;
  margin-top: 14px;
  font-size: 14px;
  max-width: 90vw;
}
.lightbox-caption .lb-name { font-weight: 600; font-size: 15px; }
.lightbox-caption .lb-meta { color: rgba(255,255,255,0.6); font-size: 12px; margin-top: 4px; }

/* =====================================================
   DEFICIENCY SECTION
   ===================================================== */
.deficiency-section {
  margin-top: 20px;
  border-top: 1px solid #eee;
  padding-top: 16px;
}
.deficiency-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.deficiency-section-header h3 { margin: 0; font-size: 15px; color: #333; }
.deficiency-count-badge {
  background: #e3f2fd;
  color: #1565c0;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  margin-left: 8px;
}
.deficiency-card {
  display: flex;
  flex-direction: column;
  background: white;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 8px;
  position: relative;
}
.deficiency-card:hover { border-color: #bbb; }
.def-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.severity-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}
.severity-badge.major   { background: #ffebee; color: #c62828; }
.severity-badge.moderate { background: #fff3e0; color: #e65100; }
.severity-badge.minor   { background: #f5f5f5; color: #666; }
.def-type { font-weight: 600; font-size: 14px; color: #333; }
.life-safety-flag {
  display: inline-block;
  background: #c62828;
  color: white;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 3px;
  text-transform: uppercase;
}
.def-card-body { font-size: 13px; color: #555; }
.def-details { margin-bottom: 4px; }
.def-notes { color: #777; font-style: italic; margin-top: 4px; }
.def-photos {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.def-photo-thumb {
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 4px;
  cursor: pointer;
  border: 1px solid #ddd;
  transition: border-color 0.15s;
}
.def-photo-thumb:hover { border-color: #2196F3; }
.def-card-actions {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 4px;
}
.def-edit-btn,
.def-delete-btn {
  background: none;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 14px;
  color: #666;
  transition: background 0.15s, border-color 0.15s;
}
.def-edit-btn:hover { background: #e3f2fd; border-color: #2196F3; color: #2196F3; }
.def-delete-btn:hover { background: #ffebee; border-color: #f44336; color: #f44336; }

/* Deficiency count badge in table */
.def-count-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.def-count-badge:hover { opacity: 0.8; }
.def-count-badge.major   { background: #ffebee; color: #c62828; }
.def-count-badge.moderate { background: #fff3e0; color: #e65100; }
.def-count-badge.minor   { background: #f5f5f5; color: #666; }

/* Pending deficiency cards in Add Asset modal */
.add-deficiency-area { margin-top: 4px; }
.pending-def-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin-top: 8px;
  background: #f9f9f9;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  position: relative;
}
.pending-def-actions {
  margin-left: auto;
  display: flex;
  gap: 4px;
}

/* Deficiency modal photo section */
.def-modal-photo-section {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid #eee;
}
.def-modal-photo-section h4 { margin: 0 0 8px 0; font-size: 14px; }
.def-photo-error {
  color: #c62828;
  font-size: 12px;
  font-weight: 400;
  margin-left: 8px;
}

/* Deficiency modal checkbox */
.def-checkbox-field {
  display: flex;
  align-items: center;
}
.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #333;
  cursor: pointer;
}
.checkbox-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}
