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

:root {
  --navy: #1a1a2e;
  --navy-light: #16213e;
  --accent: #4a6cf7;
  --accent-hover: #3a5ce6;
  --text-primary: #ffffff;
  --text-secondary: rgba(255,255,255,0.6);
  --text-muted: rgba(255,255,255,0.35);
  --surface: rgba(255,255,255,0.06);
  --surface-hover: rgba(255,255,255,0.1);
  --border: rgba(255,255,255,0.1);
  --success: #22c55e;
  --error: #ef4444;
  --warning: #f59e0b;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 20px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--navy);
  color: var(--text-primary);
  min-height: 100vh;
  font-size: 16px;
  line-height: 1.5;
}

/* AUTH SCREENS */
.auth-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px 24px;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  box-sizing: border-box;
}

.auth-logo {
  width: 80px;
  height: 80px;
  object-fit: contain;
  margin-bottom: 24px;
  border-radius: var(--radius);
}

.auth-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
  text-align: center;
}

.auth-subtitle {
  font-size: 15px;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 40px;
}

.auth-card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
}

.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.form-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}

.form-input:focus {
  border-color: var(--accent);
}

.form-input::placeholder {
  color: var(--text-muted);
}

.btn {
  width: 100%;
  padding: 15px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  margin-top: 8px;
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.error-message {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 14px;
  color: var(--error);
  margin-top: 12px;
  display: none;
}

.error-message.show {
  display: block;
}

.loading-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 8px;
}

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

/* PORTAL LAYOUT */
.portal-header {
  background: var(--navy-light);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: sticky;
  top: 0;
  z-index: 100;
  text-align: center;
}

.portal-header-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.portal-logo {
  width: 120px;
  height: 50px;
  object-fit: contain;
  margin-bottom: 4px;
}

.portal-agency {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.portal-user {
  font-size: 13px;
  color: var(--text-secondary);
}

.btn-logout {
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-logout:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

.portal-content {
  padding: 20px;
  max-width: 600px;
  margin: 0 auto;
}

/* CARDS */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.card:hover {
  background: var(--surface-hover);
  border-color: rgba(255,255,255,0.2);
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 4px;
}

.card-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
}

.card-meta {
  display: flex;
  gap: 12px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.card-meta-item {
  font-size: 12px;
  color: var(--text-muted);
}

.card-cover {
  width: 100%;
  height: 140px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
}

/* STATUS BADGES */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-scheduled { background: rgba(74,108,247,0.15); color: #4a6cf7; }
.badge-in-progress { background: rgba(245,158,11,0.15); color: #f59e0b; }
.badge-completed { background: rgba(34,197,94,0.15); color: #22c55e; }
.badge-needs-attention { background: rgba(239,68,68,0.15); color: #ef4444; }
.badge-canceled { background: rgba(255,255,255,0.1); color: var(--text-muted); }

/* SECTION HEADER */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-title {
  font-size: 20px;
  font-weight: 700;
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  padding: 0;
}

.back-btn:hover {
  color: var(--text-primary);
}

/* DETAIL VIEW */
.detail-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
}

.detail-section h3 {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-secondary);
  margin-bottom: 14px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.detail-field label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  display: block;
  margin-bottom: 3px;
}

.detail-field p {
  font-size: 14px;
  color: var(--text-primary);
}

.detail-field.full {
  grid-column: span 2;
}

/* PHOTOS */
.photos-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.photo-thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

/* ACTION BUTTONS */
.action-bar {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  background: var(--navy-light);
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 10px;
}

.action-bar .btn {
  margin-top: 0;
}

/* EMPTY STATE */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
}

.empty-state p {
  font-size: 15px;
  margin-bottom: 20px;
}

/* MODAL */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  display: none;
}

.modal-overlay.show {
  display: flex;
}

.modal {
  background: var(--navy-light);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  width: 90%;
  max-width: 600px;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 20px;
}

.modal-close {
  float: right;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
}

/* FILE UPLOAD */
.file-upload-area {
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 8px;
}

.file-upload-area:hover {
  border-color: var(--accent);
  background: rgba(74,108,247,0.05);
}

.file-upload-area p {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 6px;
}

.file-preview {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 8px;
}

.file-preview-thumb {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius-sm);
}

/* CERTIFICATE LINK */
.certificate-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(34,197,94,0.1);
  border: 1px solid rgba(34,197,94,0.2);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}

.certificate-link span {
  font-size: 14px;
  color: var(--success);
  font-weight: 500;
}

.certificate-link a {
  font-size: 13px;
  color: var(--success);
  text-decoration: none;
  font-weight: 600;
}

.form-input option {
  background: var(--navy-light);
  color: var(--text-primary);
}

select.form-input {
  background: var(--surface);
  color: var(--text-primary);
}

body.auth-page {
  height: 100vh;
  overflow: hidden;
}

.category-group {
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--surface);
  cursor: pointer;
  user-select: none;
}

.category-header:active {
  background: var(--navy-light);
}

.category-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.category-label {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
}

.category-count {
  background: var(--navy-light);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 100px;
}

.category-chevron {
  font-size: 20px;
  color: var(--text-secondary);
  transition: transform 0.2s ease;
  line-height: 1;
}

.category-records {
  padding: 8px;
  background: var(--background);
}

.category-records .card {
  margin-bottom: 8px;
}

.category-records .card:last-child {
  margin-bottom: 0;
}

@media (orientation: landscape) {
  body.auth-page {
    height: auto;
    min-height: 100vh;
    overflow-y: auto;
  }
}

/* RESPONSIVE */
@media (min-width: 600px) {
  .portal-content {
    padding: 28px 24px;
  }

  .auth-container {
    padding: 40px 24px;
  }
}

/* ================================
   INSPECTION IMPORT
   ================================ */

.import-upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 36px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: transparent;
}

.import-upload-area:hover {
  border-color: var(--accent);
  background: rgba(74,108,247,0.05);
}

.import-upload-area.dragover {
  border-color: var(--accent);
  background: rgba(74,108,247,0.08);
}

.import-upload-icon {
  font-size: 36px;
  margin-bottom: 12px;
  line-height: 1;
}

.import-upload-area h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.import-upload-area p {
  font-size: 13px;
  color: var(--text-secondary);
}

.import-upload-area .file-selected {
  font-size: 13px;
  color: var(--accent);
  font-weight: 600;
  margin-top: 8px;
  word-break: break-all;
}

/* Extraction loading state */
.import-loading {
  text-align: center;
  padding: 40px 20px;
}

.import-loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

.import-loading p {
  font-size: 14px;
  color: var(--text-secondary);
}

.import-loading .import-loading-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* Extracted items review */
.import-review-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.import-review-header h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
}

.import-select-all {
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.import-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}

.import-item:hover {
  border-color: rgba(255,255,255,0.2);
  background: var(--surface-hover);
}

.import-item.selected {
  border-color: var(--accent);
  background: rgba(74,108,247,0.08);
}

.import-item-checkbox {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-radius: 4px;
  flex-shrink: 0;
  margin-top: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  background: transparent;
}

.import-item.selected .import-item-checkbox {
  background: var(--accent);
  border-color: var(--accent);
}

.import-item-checkbox::after {
  content: '';
  display: none;
  width: 5px;
  height: 9px;
  border: 2px solid white;
  border-top: none;
  border-left: none;
  transform: rotate(45deg) translateY(-1px);
}

.import-item.selected .import-item-checkbox::after {
  display: block;
}

.import-item-body {
  flex: 1;
  min-width: 0;
}

.import-item-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 3px;
}

.import-item-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.import-item-tag {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 2px 8px;
  border-radius: 100px;
  background: var(--surface);
  color: var(--text-secondary);
}

.import-item-tag.priority-high {
  background: rgba(239,68,68,0.15);
  color: #ef4444;
}

.import-item-tag.priority-medium {
  background: rgba(245,158,11,0.15);
  color: #f59e0b;
}

.import-item-tag.priority-low {
  background: rgba(74,108,247,0.15);
  color: #4a6cf7;
}

.import-item-desc {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.import-confirm-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 0;
  border-top: 1px solid var(--border);
  margin-top: 4px;
  gap: 10px;
}

.import-confirm-bar span {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.import-error {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.3);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 14px;
  color: var(--error);
  margin-top: 12px;
  display: none;
}

.import-error.show {
  display: block;
}

/* Import button */
.btn-import {
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: 13px;
  cursor: pointer;
  padding: 0;
}

#log-due-date {
  cursor: pointer;
  position: relative;
}

#log-due-date::-webkit-calendar-picker-indicator {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.import-date-picker {
  cursor: pointer;
  position: relative;
}

.import-date-picker::-webkit-calendar-picker-indicator {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}