:root {
  --bg: #18181b;
  --surface: #27272a;
  --surface-2: #3f3f46;
  --text: #fafafa;
  --muted: #a1a1aa;
  --accent: #f59e0b;
  --accent-text: #1c1400;
  --danger: #ef4444;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
.error { color: var(--danger); }

/* ---- Login ---- */
.login-view {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 50;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 340px;
  text-align: center;
}
.login-logo { width: 72px; height: 72px; border-radius: 18px; }
.login-card h1 { margin: 12px 0 4px; }
.login-card form { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

/* ---- Layout ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  position: sticky;
  top: 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  z-index: 10;
}
.topbar-logo { width: 28px; height: 28px; border-radius: 8px; }
.topbar-title { font-weight: 700; font-size: 18px; letter-spacing: 0.3px; }

main {
  padding: 8px 16px calc(env(safe-area-inset-bottom) + 92px);
  max-width: 720px;
  margin: 0 auto;
}

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--surface-2);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 20;
}
.tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  padding: 10px 0 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
}
.tab span { font-size: 11px; font-family: inherit; }
.tab.active { color: var(--accent); }

/* ---- Inputs & buttons ---- */
input[type="text"], input[type="search"], input[type="password"] {
  width: 100%;
  padding: 13px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--surface-2);
  background: var(--surface);
  color: var(--text);
  font-size: 16px; /* prevents iOS zoom-on-focus */
  outline: none;
}
input:focus { border-color: var(--accent); }

.btn {
  padding: 13px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--surface-2);
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { background: none; border-color: var(--danger); color: var(--danger); }
.btn:disabled { opacity: 0.5; }

/* ---- Find ---- */
.searchbar { display: flex; gap: 8px; margin: 8px 0 16px; }
.searchbar input { flex: 1; }
.searchbar .btn { flex-shrink: 0; }

.result-list { display: flex; flex-direction: column; gap: 10px; }
.result {
  display: flex;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 10px;
  align-items: center;
  cursor: pointer;
}
.result img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 10px;
  background: var(--surface-2);
  flex-shrink: 0;
}
.result-info { min-width: 0; }
.result-info .name { font-weight: 700; }
.result-info .loc { color: var(--accent); font-size: 14px; margin-top: 2px; }
.result-info .why { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* ---- Browse ---- */
.filterbar { margin: 8px 0 14px; }
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
}
.grid-item { position: relative; cursor: pointer; }
.grid-item img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 10px;
  background: var(--surface-2);
  display: block;
}
.grid-item .label {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.grid-item .dot {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
}
.dot.pending { background: var(--accent); }
.dot.failed { background: var(--danger); }

/* ---- Add ---- */
.add-form { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.photo-picker {
  border: 2px dashed var(--surface-2);
  border-radius: var(--radius);
  min-height: 180px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  overflow: hidden;
  position: relative;
  color: var(--muted);
}
.photo-picker img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#photo-hint { position: relative; z-index: 1; padding: 8px 12px; }
.photo-picker.has-photo { border-style: solid; }
.photo-picker.has-photo #photo-hint {
  background: rgba(0,0,0,0.55);
  border-radius: 8px;
  font-size: 13px;
}

/* ---- Modal ---- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 40;
}
.modal-card {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  position: relative;
}
.modal-card > img {
  width: 100%;
  max-height: 44vh;
  object-fit: contain;
  background: #000;
  display: block;
}
.modal-body { padding: 16px 16px calc(env(safe-area-inset-bottom) + 20px); }
.modal-head { display: flex; align-items: center; gap: 10px; }
.modal-head h2 { margin: 0; font-size: 20px; flex: 1; }
.modal-location { color: var(--accent); font-weight: 600; margin: 8px 0; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  border: none;
  background: rgba(0,0,0,0.55);
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 15px;
  cursor: pointer;
}
#modal-edit-form { display: flex; flex-direction: column; gap: 10px; }

.chip {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  flex-shrink: 0;
}
.chip.pending { background: #78350f; color: #fcd34d; }
.chip.failed { background: #7f1d1d; color: #fca5a5; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tags .chip { background: var(--surface-2); color: var(--text); }

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 76px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  color: var(--text);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 60;
  max-width: 90vw;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}
