/* ChantierCam — Design System v2 (Light / Professional) */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Palette */
  --primary:        #F97316;
  --primary-dark:   #EA580C;
  --primary-light:  #FFF7ED;
  --primary-border: #FED7AA;

  --bg:             #F8FAFC;
  --bg-card:        #FFFFFF;
  --bg-input:       #F8FAFC;
  --bg-hover:       #F1F5F9;

  --text:           #0F172A;
  --text-secondary: #64748B;
  --text-tertiary:  #94A3B8;

  --border:         #E2E8F0;
  --border-focus:   #F97316;

  --success:        #10B981;
  --success-bg:     #ECFDF5;
  --danger:         #EF4444;
  --danger-bg:      #FEF2F2;
  --warning-bg:     #FFFBEB;

  /* Shadows */
  --shadow-xs:  0 1px 2px rgba(0,0,0,.04);
  --shadow-sm:  0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow:     0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -1px rgba(0,0,0,.04);
  --shadow-md:  0 10px 15px -3px rgba(0,0,0,.07), 0 4px 6px -2px rgba(0,0,0,.04);
  --shadow-lg:  0 20px 25px -5px rgba(0,0,0,.08), 0 10px 10px -5px rgba(0,0,0,.04);

  /* Shape */
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius:    12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  /* Spacing */
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ── Base ───────────────────────────────────────────────────────────────────── */

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

/* ── App shell ──────────────────────────────────────────────────────────────── */

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 640px;
  margin: 0 auto;
  background: var(--bg);
}

.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  animation: fadeSlideIn 0.18s ease-out;
}

.screen.active { display: flex; }

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

/* ── Offline banner ─────────────────────────────────────────────────────────── */

.offline-banner {
  background: var(--warning-bg);
  color: #92400E;
  border-bottom: 1px solid #FDE68A;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 500;
  padding: 8px 16px;
  display: none;
}
.offline-banner.visible { display: block; }

/* ── Header ─────────────────────────────────────────────────────────────────── */

.header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-top) + 14px) 16px 14px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-logo {
  width: 32px;
  height: 32px;
  background: var(--primary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.5px;
  flex-shrink: 0;
}

.header-title {
  flex: 1;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.2px;
}

.btn-icon {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1rem;
  transition: background 0.12s, color 0.12s;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.btn-icon:hover  { background: var(--bg-hover); color: var(--text); }
.btn-icon:active { background: var(--border); }

.btn-back {
  font-size: 1.2rem;
  color: var(--primary);
}
.btn-back:hover { background: var(--primary-light); color: var(--primary-dark); }

/* ── Scroll area ────────────────────────────────────────────────────────────── */

.scroll-area {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
}

/* ── Search ─────────────────────────────────────────────────────────────────── */

.search-wrap {
  position: relative;
  margin-bottom: 12px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  font-size: 0.95rem;
  pointer-events: none;
}

.search-input {
  width: 100%;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px 10px 38px;
  font-size: 0.95rem;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  box-shadow: var(--shadow-xs);
}
.search-input::placeholder { color: var(--text-tertiary); }
.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(249,115,22,.1);
}

/* ── Nearby button ──────────────────────────────────────────────────────────── */

.nearby-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: 99px;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 16px;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.nearby-btn:hover  { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.nearby-btn.active { border-color: var(--primary); color: var(--primary); background: var(--primary-light); font-weight: 600; }

/* ── Section label ──────────────────────────────────────────────────────────── */

.section-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  margin-bottom: 8px;
  padding-left: 2px;
}

/* ── Project cards ──────────────────────────────────────────────────────────── */

.project-list { display: flex; flex-direction: column; gap: 10px; }

.project-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
  box-shadow: var(--shadow-xs);
  -webkit-tap-highlight-color: transparent;
  text-decoration: none;
  color: inherit;
}
.project-card:hover  { border-color: var(--primary-border); box-shadow: var(--shadow-sm); }
.project-card:active { transform: scale(0.99); }

.project-thumb {
  width: 68px;
  height: 68px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
}
.project-thumb img { width: 100%; height: 100%; object-fit: cover; }
.project-thumb-empty {
  font-size: 1.6rem;
  color: var(--text-tertiary);
}

.project-info { flex: 1; min-width: 0; }

.project-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.project-address {
  font-size: 0.82rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 6px;
}

.project-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--bg);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.badge-orange {
  background: var(--primary-light);
  color: var(--primary-dark);
  border-color: var(--primary-border);
}

.card-chevron {
  color: var(--text-tertiary);
  font-size: 1rem;
  flex-shrink: 0;
}

/* ── FAB ─────────────────────────────────────────────────────────────────────── */

.fab {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 24px);
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  border: none;
  font-size: 1.6rem;
  cursor: pointer;
  box-shadow: var(--shadow-md), 0 0 0 0 rgba(249,115,22,.3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
  z-index: 100;
  -webkit-tap-highlight-color: transparent;
}
.fab:hover  { background: var(--primary-dark); transform: scale(1.05); box-shadow: var(--shadow-lg); }
.fab:active { transform: scale(0.97); }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 20px;
  border-radius: var(--radius);
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s, transform 0.1s, opacity 0.15s;
  width: 100%;
  letter-spacing: -0.1px;
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled  { opacity: 0.45; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(0.99); }

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 2px rgba(249,115,22,.3), 0 4px 12px rgba(249,115,22,.15);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  box-shadow: 0 1px 2px rgba(234,88,12,.4), 0 6px 16px rgba(234,88,12,.2);
}

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); border-color: #CBD5E1; }

.btn-ghost {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary-border);
}
.btn-ghost:hover:not(:disabled) { background: var(--primary-light); }

.btn-danger {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 1px 2px rgba(239,68,68,.3);
}
.btn-danger:hover:not(:disabled) { background: #DC2626; }

/* ── Forms ───────────────────────────────────────────────────────────────────── */

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

.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 7px;
  letter-spacing: 0.01em;
}

.form-input, .form-textarea {
  width: 100%;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
  box-shadow: var(--shadow-xs);
}
.form-input::placeholder, .form-textarea::placeholder { color: var(--text-tertiary); }
.form-input:focus, .form-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(249,115,22,.1);
}
.form-textarea { resize: vertical; min-height: 88px; line-height: 1.6; }

.gps-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-top: 7px;
  padding: 4px 10px;
  background: var(--bg);
  border-radius: 99px;
  border: 1px solid var(--border);
}

/* ── Project detail header ──────────────────────────────────────────────────── */

.project-detail-info {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 16px;
  flex-shrink: 0;
}

.project-detail-name {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
  margin-bottom: 3px;
  min-height: 1.4em;
}

.project-detail-address {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
  min-height: 1.3em;
}

.project-detail-notes {
  font-size: 0.875rem;
  color: var(--text-secondary);
  white-space: pre-wrap;
  line-height: 1.6;
  min-height: 1.3em;
}

[contenteditable="true"] {
  outline: none;
  border-radius: var(--radius-xs);
  padding: 2px 4px;
  margin: 0 -4px;
  transition: background 0.12s;
}
[contenteditable="true"]:focus {
  background: var(--primary-light);
  box-shadow: 0 0 0 2px var(--primary-border);
}

.edit-hint {
  font-size: 0.72rem;
  color: var(--text-tertiary);
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Photo grid ──────────────────────────────────────────────────────────────── */

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 3px;
  margin-bottom: 100px;
}

.photo-grid-item {
  aspect-ratio: 1;
  cursor: pointer;
  overflow: hidden;
  background: var(--bg);
  position: relative;
}
.photo-grid-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s;
  display: block;
}
.photo-grid-item:active img { transform: scale(0.97); }

/* ── Photo actions bar ───────────────────────────────────────────────────────── */

.photo-actions {
  display: flex;
  gap: 10px;
  padding: 12px 16px calc(var(--safe-bottom) + 12px);
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── Photo view (fullscreen) ─────────────────────────────────────────────────── */

#screen-photo-view { background: #000; position: relative; }

.photo-view-img-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: pinch-zoom;
}
.photo-view-img-container img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.photo-view-header {
  position: absolute;
  top: 0; left: 0; right: 0;
  padding: calc(var(--safe-top) + 10px) 12px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(rgba(0,0,0,.55), transparent);
  z-index: 10;
}
.photo-view-header .btn-icon { color: #fff; width: 40px; height: 40px; }
.photo-view-header .btn-icon:hover { background: rgba(255,255,255,.15); }

.photo-view-overlay {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,.8));
  padding: 48px 20px calc(var(--safe-bottom) + 20px);
}
.photo-view-note {
  font-size: 1rem;
  color: #fff;
  margin-bottom: 8px;
  min-height: 1.4em;
  line-height: 1.5;
}
.photo-view-note:focus { background: rgba(255,255,255,.1); border-radius: 6px; padding: 4px 6px; }
.photo-view-meta {
  font-size: 0.78rem;
  color: rgba(255,255,255,.55);
  display: flex;
  gap: 12px;
}

/* ── Capture screen ──────────────────────────────────────────────────────────── */

.photo-preview {
  width: 100%;
  max-height: 48vh;
  object-fit: contain;
  border-radius: var(--radius);
  background: var(--border);
  display: none;
  border: 1px solid var(--border);
}
.photo-preview.visible { display: block; }

.progress-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 10px;
  display: none;
}
.progress-bar.visible { display: block; }
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-dark));
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* ── Token screen ────────────────────────────────────────────────────────────── */

.token-screen-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 32px;
  gap: 0;
}

.token-logo {
  width: 72px;
  height: 72px;
  background: var(--primary);
  border-radius: var(--radius-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -1px;
  margin-bottom: 24px;
  box-shadow: 0 8px 24px rgba(249,115,22,.25);
}

.token-title {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.5px;
  margin-bottom: 8px;
}

.token-subtitle {
  font-size: 0.9rem;
  color: var(--text-secondary);
  text-align: center;
  margin-bottom: 32px;
  line-height: 1.6;
}

.token-form {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── Empty state ─────────────────────────────────────────────────────────────── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 24px;
  gap: 14px;
}
.empty-state-icon {
  width: 72px;
  height: 72px;
  background: var(--bg-hover);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
}
.empty-state-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}
.empty-state-text {
  font-size: 0.875rem;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.6;
  max-width: 240px;
}

/* ── Toast ───────────────────────────────────────────────────────────────────── */

.toast {
  position: fixed;
  bottom: calc(var(--safe-bottom) + 90px);
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  background: var(--text);
  color: #fff;
  border-radius: 99px;
  padding: 10px 20px;
  font-size: 0.875rem;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  white-space: nowrap;
  z-index: 999;
  box-shadow: var(--shadow-md);
  max-width: calc(100vw - 40px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Loader ──────────────────────────────────────────────────────────────────── */

.spinner {
  width: 28px;
  height: 28px;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.55s linear infinite;
  margin: 48px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Divider ─────────────────────────────────────────────────────────────────── */

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

/* ── Utility ─────────────────────────────────────────────────────────────────── */

.hidden  { display: none !important; }
.mt-8    { margin-top: 8px; }
.mt-12   { margin-top: 12px; }
.mt-16   { margin-top: 16px; }
.gap-8   { gap: 8px; }
.flex    { display: flex; }
.items-center { align-items: center; }
.text-secondary { color: var(--text-secondary); }
.text-primary   { color: var(--primary); }
.text-sm { font-size: 0.875rem; }
