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

:root {
  --bg:          #0f1117;
  --bg2:         #1a1d27;
  --bg3:         #242838;
  --accent:      #f5a623;
  --text:        #f0f0f0;
  --text2:       #9aa0b4;
  --danger:      #ef4444;
  --success:     #22c55e;
  --info:        #3b82f6;
  --radius:      12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

#app { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }

/* ── Screens ── */
.screen { display: none; flex-direction: column; height: 100dvh; overflow: hidden; }
.screen.active { display: flex; }

/* ── Header ── */
header { padding: 16px 16px 12px; background: var(--bg2); border-bottom: 1px solid var(--bg3); display: flex; flex-direction: column; gap: 8px; }

.logo { font-size: 12px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent); }

#project-name, #context-notes { width: 100%; background: var(--bg3); border: none; border-radius: 8px; padding: 10px 14px; color: var(--text); font-size: 15px; outline: none; }
#project-name::placeholder, #context-notes::placeholder { color: var(--text2); }
#context-notes { font-size: 13px; }
#project-name:focus, #context-notes:focus { box-shadow: 0 0 0 2px var(--accent); }

/* ── GPS bar ── */
.gps-bar { height: 28px; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; flex-shrink: 0; transition: background 0.3s; }
.gps-good { background: #15803d; color: #fff; }
.gps-weak { background: #b45309; color: #fff; }
.gps-none { background: var(--bg3); color: var(--text2); }

/* ── Capture zone ── */
.capture-zone { flex: 1; display: flex; align-items: center; justify-content: center; padding: 32px 24px; }

.btn-capture { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; width: 190px; height: 190px; border-radius: 50%; background: var(--bg2); border: 3px solid var(--accent); color: var(--accent); cursor: pointer; font-size: 15px; font-weight: 600; transition: transform 0.1s, background 0.15s; user-select: none; -webkit-tap-highlight-color: transparent; }
.btn-capture:active { transform: scale(0.95); background: var(--bg3); }
.btn-capture svg { width: 52px; height: 52px; }

/* ── Home footer ── */
#home-footer { padding: 14px 16px calc(14px + var(--safe-bottom)); background: var(--bg2); border-top: 1px solid var(--bg3); display: flex; align-items: center; justify-content: space-between; }
.count-badge { font-size: 13px; color: var(--text2); }
.footer-actions { display: flex; gap: 10px; align-items: center; }

/* ── Review ── */
#screen-review { background: var(--bg); }
.preview-wrap { flex: 1; position: relative; overflow: hidden; background: #000; min-height: 0; }
#preview-img { width: 100%; height: 100%; object-fit: contain; display: block; }
.meta-overlay { position: absolute; bottom: 0; left: 0; right: 0; padding: 8px 12px; background: linear-gradient(transparent, rgba(0,0,0,0.8)); display: flex; flex-direction: column; gap: 2px; }
.meta-overlay span { font-size: 11px; color: rgba(255,255,255,0.88); font-family: 'SF Mono','Fira Code',monospace; }
#meta-seq { font-weight: 700; font-size: 13px; color: var(--accent); }

/* ── Caption card ── */
.caption-card { background: var(--bg2); padding: 12px 14px; border-top: 1px solid var(--bg3); }
.caption-status { font-size: 12px; color: var(--text2); margin-bottom: 8px; min-height: 16px; }
.caption-status.loading { color: var(--accent); }
.caption-status.done    { color: var(--success); }
.caption-status.error   { color: var(--danger); }
.caption-status.offline { color: #f59e0b; }

.caption-input-row { display: flex; gap: 8px; align-items: flex-start; }

#caption-text { flex: 1; background: var(--bg3); border: none; border-radius: 8px; padding: 10px 12px; color: var(--text); font-size: 14px; line-height: 1.5; resize: none; outline: none; font-family: inherit; }
#caption-text:focus { box-shadow: 0 0 0 2px var(--accent); }

.btn-mic { background: var(--bg3); border: none; border-radius: 8px; color: var(--text2); width: 44px; height: 44px; display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0; }
.btn-mic.listening { outline: 2px solid var(--danger); color: var(--danger); }
.btn-mic:active { opacity: 0.7; }

/* ── Tags ── */
.tag-row { display: flex; gap: 8px; margin-top: 10px; }
.tag-btn { flex: 1; padding: 9px 4px; background: var(--bg3); border: none; border-radius: 8px; color: var(--text2); font-size: 12px; font-weight: 600; cursor: pointer; transition: background 0.15s, color 0.15s; min-height: 38px; }
.tag-btn:active { opacity: 0.7; }
.tag-btn.active[data-tag="Conforming"] { background: #15803d; color: #fff; }
.tag-btn.active[data-tag="Deficiency"] { background: #b91c1c; color: #fff; }
.tag-btn.active[data-tag="As-Built"]   { background: #1d4ed8; color: #fff; }
.tag-btn.active[data-tag="Reference"]  { background: #4b5563; color: #fff; }

.gps-notice { font-size: 11px; color: #f59e0b; margin-top: 8px; text-align: center; }

/* ── Review actions ── */
.review-actions { display: flex; gap: 12px; padding: 12px 14px calc(12px + var(--safe-bottom)); background: var(--bg2); border-top: 1px solid var(--bg3); }

/* ── Log ── */
.log-header { display: flex; align-items: center; gap: 14px; padding: 14px 14px 10px; background: var(--bg2); border-bottom: 1px solid var(--bg3); flex-shrink: 0; }
#log-title { font-weight: 600; font-size: 15px; }

#filter-bar { display: flex; gap: 8px; padding: 10px 14px 4px; overflow-x: auto; flex-shrink: 0; -webkit-overflow-scrolling: touch; }
.filter-chip { background: var(--bg3); border: none; border-radius: 999px; color: var(--text2); font-size: 12px; font-weight: 600; padding: 6px 14px; cursor: pointer; white-space: nowrap; min-height: 32px; }
.filter-chip.active { background: var(--accent); color: #000; }

#photo-log { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 10px; }

.log-item { background: var(--bg2); border-radius: var(--radius); overflow: hidden; display: flex; gap: 10px; padding: 10px; align-items: flex-start; }
.log-thumb { width: 70px; height: 70px; object-fit: cover; border-radius: 8px; flex-shrink: 0; }
.log-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }

.tag-badge { display: inline-block; color: #fff; border-radius: 4px; padding: 2px 8px; font-size: 11px; font-weight: 700; width: fit-content; }
.log-seq { font-size: 11px; color: var(--text2); font-weight: 600; }
.log-caption { font-size: 13px; line-height: 1.4; }
.log-meta { font-size: 11px; color: var(--text2); font-family: monospace; }

.log-actions { display: flex; gap: 8px; margin-top: 4px; }
.log-dl  { background: var(--bg3); border: none; border-radius: 6px; color: var(--text2); padding: 4px 12px; font-size: 12px; cursor: pointer; min-height: 32px; }
.log-del { background: none; border: 1px solid #374151; border-radius: 6px; color: var(--danger); padding: 4px 10px; font-size: 12px; cursor: pointer; min-height: 32px; }
.log-dl:active, .log-del:active { opacity: 0.7; }

/* ── Buttons ── */
.btn-primary  { flex: 1; padding: 14px; background: var(--accent); color: #000; font-weight: 700; font-size: 15px; border: none; border-radius: var(--radius); cursor: pointer; transition: opacity 0.15s; }
.btn-primary:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-primary:not(:disabled):active { opacity: 0.8; }

.btn-secondary { flex: 1; padding: 14px; background: var(--bg3); color: var(--text); font-weight: 600; font-size: 15px; border: none; border-radius: var(--radius); cursor: pointer; }
.btn-secondary:active { opacity: 0.7; }

.btn-ghost { background: none; border: none; color: var(--accent); font-size: 13px; font-weight: 600; cursor: pointer; padding: 6px 4px; }
.btn-ghost:active { opacity: 0.6; }
.btn-danger { color: var(--danger); }

/* ── Toast ── */
#toast { position: fixed; bottom: calc(24px + var(--safe-bottom)); left: 50%; transform: translateX(-50%) translateY(20px); background: var(--bg3); color: var(--text); padding: 10px 20px; border-radius: 20px; font-size: 13px; opacity: 0; transition: opacity 0.2s, transform 0.2s; pointer-events: none; white-space: nowrap; z-index: 100; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
