/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary: #FFFFFF;
  --bg-secondary: #F4F5F7;
  --bg-card: #FFFFFF;
  --accent: #18BA40;
  --accent-hover: #15a338;
  --accent-glow: rgba(24, 186, 64, 0.1);
  --text-primary: #1A1A2E;
  --text-secondary: #5A5A6E;
  --text-muted: #9090A0;
  --success: #18BA40;
  --success-bright: #6CE142;
  --warning: #e89209;
  --danger: #dc3545;
  --border: #E0E0E6;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow: hidden;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ===== Navigation Bar ===== */
#nav-bar {
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: var(--bg-primary);
  border-top: 1px solid var(--border);
  padding: 8px 0;
  padding-bottom: env(safe-area-inset-bottom, 8px);
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  padding: 4px 16px;
  cursor: pointer;
  transition: color 0.2s;
}

.nav-btn.active {
  color: var(--accent);
}

.nav-btn svg {
  width: 22px;
  height: 22px;
}

/* ===== Page Container ===== */
#page-container {
  flex: 1;
  overflow-y: auto;

  padding-bottom: 70px; /* nav bar height */
}

.page {
  min-height: 100%;
  padding: 20px 16px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Auth Pages ===== */
.auth-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.auth-page h1 {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
}

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

.auth-form {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input {
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 16px; /* prevents iOS zoom */
  outline: none;
  transition: border-color 0.2s;
}

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

.form-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 20px;
}

/* ===== Buttons ===== */
.btn {
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  text-align: center;
}

.btn:active {
  transform: scale(0.97);
}

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

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

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

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

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

.btn-sm {
  padding: 8px 16px;
  font-size: 14px;
}

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

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 14px;
  cursor: pointer;
  text-decoration: underline;
}

/* ===== Camera / Scan Page ===== */
.scan-page {
  padding: 0;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 70px);
}

.camera-container {
  position: relative;
  flex: 1;
  background: #000;
  overflow: hidden;
}

.camera-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-guide {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 80%;
  max-width: 340px;
  aspect-ratio: 3.375 / 2.125; /* standard badge ratio */
  border: 2px solid rgba(24, 186, 64, 0.7);
  border-radius: var(--radius);
  pointer-events: none;
}

.camera-guide::after {
  content: 'Align badge here';
  position: absolute;
  bottom: -28px;
  left: 50%;
  transform: translateX(-50%);
  color: rgba(255, 255, 255, 0.7);
  font-size: 13px;
  white-space: nowrap;
}

.scan-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 20px;
  padding: 16px;
  background: var(--bg-secondary);
}

.capture-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 3px solid var(--accent);
  background: transparent;
  cursor: pointer;
  position: relative;
  transition: background 0.2s;
}

.capture-btn::after {
  content: '';
  position: absolute;
  top: 6px;
  left: 6px;
  right: 6px;
  bottom: 6px;
  border-radius: 50%;
  background: var(--accent);
  transition: transform 0.1s;
}

.capture-btn:active::after {
  transform: scale(0.85);
}

.scan-status {
  text-align: center;
  padding: 12px;
  font-size: 14px;
  color: var(--text-secondary);
}

/* Scanning spinner overlay */
.scan-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 10;
  color: #fff;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* ===== Results Page ===== */
.results-page {
  padding: 16px;
}

.results-page h2 {
  font-size: 20px;
  margin-bottom: 16px;
}

/* Primary match — the identified person */
.primary-match {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}

/* Match card header with badge + score */
.match-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.match-card-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-glow);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.match-score {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-glow);
  padding: 4px 10px;
  border-radius: 999px;
}

/* Name & credentials */
.match-card-name {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.match-card-credentials {
  font-size: 13px;
  color: var(--accent);
  font-weight: 500;
  min-height: 18px;
}

/* Divider line */
.match-card-divider {
  height: 1px;
  background: var(--border);
  margin: 14px 0;
}

/* Info rows with icons */
.match-card-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.info-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.info-row-icon {
  flex-shrink: 0;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  margin-top: 1px;
}

.info-row-content {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.info-row-primary {
  font-size: 15px;
  color: var(--text-primary);
  word-break: break-word;
}

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

/* "Not the right person?" link */
.not-right-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  text-decoration: underline;
  padding: 8px;
}

.not-right-btn:active {
  color: var(--text-secondary);
}

/* Alternative match cards */
.alt-section {
  margin-top: 16px;
}

.alt-match-card {
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 8px;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: border-color 0.2s;
}

.alt-match-card:active {
  background: var(--bg-card);
}

.alt-match-card.selected {
  border-color: var(--accent);
}

.alt-match-name {
  font-size: 15px;
  font-weight: 600;
}

.alt-match-detail {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ===== Note Taking ===== */
.note-section {
  margin-top: 20px;
}

.note-section textarea {
  width: 100%;
  min-height: 100px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
  outline: none;
}

.note-section textarea:focus {
  border-color: var(--accent);
}

.tag-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.tag-btn {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
}

.tag-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* ===== Contacts Page ===== */
.contacts-page h2 {
  font-size: 20px;
  margin-bottom: 16px;
}

.search-bar {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 15px;
  outline: none;
  margin-bottom: 16px;
}

.search-bar:focus {
  border-color: var(--accent);
}

.contact-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
}

.contact-name {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 2px;
}

.contact-meta {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.contact-notes {
  font-size: 14px;
  color: var(--text-secondary);
  font-style: italic;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.contact-tags {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.contact-tag {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent);
  color: white;
}

.contact-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}

.empty-state svg {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
  opacity: 0.4;
}

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

/* ===== Settings Page ===== */
.settings-page h2 {
  font-size: 20px;
  margin-bottom: 20px;
}

.settings-section {
  margin-bottom: 24px;
}

.settings-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.settings-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 4px 16px;
  border: 1px solid var(--border);
}

.settings-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.settings-item:last-child {
  border-bottom: none;
}

.settings-label {
  font-size: 15px;
  color: var(--text-primary);
}

.settings-value {
  font-size: 14px;
  color: var(--text-secondary);
  text-align: right;
  max-width: 60%;
  word-break: break-word;
}

/* ===== Toast ===== */
#toast-container {
  position: fixed;
  top: 16px;
  left: 16px;
  right: 16px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  animation: slideDown 0.3s ease;
  pointer-events: auto;
}

.toast.success { background: var(--success); color: #fff; }
.toast.error { background: var(--danger); color: white; }
.toast.info { background: var(--bg-card); color: var(--text-primary); border: 1px solid var(--border); }

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== Utilities ===== */
.hidden { display: none !important; }
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }

/* Manual entry form */
.manual-entry {
  margin-top: 20px;
  padding: 16px;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.manual-entry h3 {
  font-size: 16px;
  margin-bottom: 12px;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 5000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.15s ease;
}

.modal-content {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 24px;
  width: 100%;
  max-width: 400px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

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

.modal-body {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.modal-actions .btn {
  flex: 1;
  min-width: 100px;
}

/* ===== Inline Edit ===== */
.inline-edit-notes {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.inline-notes-input {
  width: 100%;
  min-height: 72px;
  padding: 10px;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  outline: none;
}

.inline-edit-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 8px;
}

/* ===== Pagination ===== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 12px 0;
}

.pagination-indicator {
  font-size: 14px;
  color: var(--text-secondary);
  min-width: 60px;
  text-align: center;
}

.pagination .btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ===== Skeleton Loading ===== */
.skeleton-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
}

.skeleton-line {
  height: 14px;
  border-radius: 4px;
  background: linear-gradient(90deg, #E8E8ED 25%, #F4F5F7 50%, #E8E8ED 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  margin-bottom: 8px;
}

.skeleton-name { width: 60%; height: 18px; }
.skeleton-meta { width: 80%; }
.skeleton-short { width: 40%; }

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ===== Camera Denied ===== */
.camera-denied {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 32px;
  text-align: center;
  gap: 12px;
}

.camera-denied-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.camera-denied-text {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.5;
  max-width: 280px;
}

/* ===== Duplicate Warning ===== */
.duplicate-existing-info {
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-top: 12px;
  border-left: 3px solid var(--warning);
}

.duplicate-detail {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.duplicate-notes {
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 6px;
}

.duplicate-tags {
  font-size: 12px;
  color: var(--accent);
  margin-top: 4px;
}

.duplicate-date {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}

/* ===== Contacts Toolbar ===== */
.contacts-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.sort-select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  cursor: pointer;
}

.sort-select:focus {
  border-color: var(--accent);
}

/* ===== Bulk Mode ===== */
.bulk-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  border: 1px solid var(--border);
  flex-wrap: wrap;
}

.bulk-select-all {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
}

.bulk-checkbox {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
  margin-top: 2px;
  flex-shrink: 0;
}

.contact-card.contact-selected {
  border-color: var(--accent);
  background: rgba(24, 186, 64, 0.08);
}

/* ===== Search Highlight ===== */
.search-highlight {
  background: rgba(24, 186, 64, 0.3);
  color: var(--text-primary);
  padding: 0 2px;
  border-radius: 2px;
}

/* ===== Contact Detail Page ===== */
.detail-page {
  padding: 16px;
}

.detail-header {
  margin-bottom: 16px;
}

.detail-header .btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.detail-scan-image {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  display: inline-block;
}

.scan-image-preview {
  max-width: 160px;
  max-height: 120px;
  object-fit: contain;
  display: block;
  background: var(--bg-card);
}

.detail-info-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--border);
  margin-bottom: 16px;
}

.detail-name {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.detail-credentials {
  font-size: 13px;
  color: var(--accent);
  font-weight: 500;
}

.detail-divider {
  height: 1px;
  background: var(--border);
  margin: 14px 0;
}

.detail-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.detail-section {
  margin-bottom: 16px;
}

.detail-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.detail-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.detail-add-note {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.detail-add-note textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 15px;
  font-family: inherit;
  resize: vertical;
  outline: none;
}

.detail-add-note textarea:focus {
  border-color: var(--accent);
}

.detail-add-note .btn {
  align-self: flex-end;
}

.detail-no-notes {
  color: var(--text-muted);
  font-size: 14px;
  font-style: italic;
  padding: 12px 0;
}

/* Note cards */
.note-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 8px;
}

.note-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.note-author {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-glow);
  padding: 2px 8px;
  border-radius: 999px;
}

.note-date {
  font-size: 11px;
  color: var(--text-muted);
}

.note-content {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.5;
  white-space: pre-wrap;
}

.note-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  justify-content: flex-end;
}

/* Contact card clickable */
.contact-card.clickable {
  cursor: pointer;
  transition: border-color 0.2s;
}

.contact-card.clickable:active {
  background: var(--bg-secondary);
}

.contact-note-count {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ===== Missing Info Modal ===== */
.missing-info-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.missing-info-form .form-input {
  font-size: 16px;
}
