/* ============================================================
   SiteWalk — mobile-first 360° site tour app
   ============================================================ */

:root {
  --bg: #0e1116;
  --bg-2: #161b22;
  --bg-3: #1c232d;
  --line: #2a323d;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #3b82f6;
  --accent-2: #22c55e;
  --danger: #ef4444;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

/* The [hidden] attribute must always win over display rules set by classes. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overscroll-behavior: none;
}

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

/* ---------- Top bar ---------- */
#topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(var(--safe-top) + 10px) 12px 10px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  z-index: 20;
}
#topbar .title { font-weight: 700; font-size: 18px; letter-spacing: 0.2px; }
#topbar .spacer { flex: 1; }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 22px;
  width: 38px; height: 38px;
  border-radius: 10px;
  cursor: pointer;
}
.icon-btn:active { background: var(--bg-3); }

/* ---------- Views ---------- */
.view { display: none; flex: 1; min-height: 0; flex-direction: column; position: relative; }
.view.active { display: flex; }

#view-projects { overflow-y: auto; padding: 16px 16px calc(var(--safe-bottom) + 90px); }

.hero h1 { margin: 8px 0 4px; font-size: 24px; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.hero p { margin: 0 0 16px; }

/* ---------- Card grid (projects) ---------- */
.card-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 620px) { .card-grid { grid-template-columns: 1fr 1fr; } }

.project-card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
}
.project-card:active { transform: scale(0.995); }
.project-card .thumb {
  height: 130px;
  background: var(--bg-3) center/cover no-repeat;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 34px;
}
.project-card .meta { padding: 12px 14px; display: flex; align-items: center; gap: 8px; }
.project-card .meta .name { font-weight: 600; flex: 1; }
.project-card .meta .count { color: var(--muted); font-size: 13px; }
.project-card .del { color: var(--muted); font-size: 18px; padding: 4px 8px; }

/* ---------- Floating action button ---------- */
.fab {
  position: absolute;
  right: 18px;
  bottom: calc(var(--safe-bottom) + 22px);
  width: 58px; height: 58px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 30px;
  line-height: 1;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  cursor: pointer;
  z-index: 15;
}
.fab:active { transform: scale(0.94); }

/* ---------- Buttons ---------- */
.btn {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 15px;
  cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn:active { filter: brightness(1.1); }
.btn[disabled] { opacity: 0.5; pointer-events: none; }

/* ---------- Project view tabs ---------- */
.tabbar { display: flex; background: var(--bg-2); border-bottom: 1px solid var(--line); }
.tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 12px 0;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.pane { display: none; flex: 1; min-height: 0; position: relative; }
.pane.active { display: flex; flex-direction: column; }

/* ---------- Viewer ---------- */
#viewerWrap { flex: 1; position: relative; background: #000; min-height: 0; }
#viewer { width: 100%; height: 100%; display: block; touch-action: none; }

.viewer-empty {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 24px;
}
.viewer-empty-inner .big-emoji { font-size: 54px; }
.viewer-empty-inner p { margin: 10px 0; }

.viewer-hud { position: absolute; inset: 0; pointer-events: none; }
.scene-top { position: absolute; top: 12px; left: 12px; display: flex; align-items: center; gap: 8px; max-width: 72%; }
.scene-name {
  background: rgba(0,0,0,0.5); backdrop-filter: blur(6px);
  padding: 8px 12px; border-radius: 20px; font-size: 14px; font-weight: 600;
  pointer-events: auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.small-hud { width: 40px; height: 40px; font-size: 18px; flex: none; pointer-events: auto; }
.hud-controls {
  position: absolute; right: 12px; bottom: calc(var(--safe-bottom) + 14px);
  display: flex; flex-direction: column; gap: 10px; pointer-events: auto;
}
.hud-btn {
  width: 48px; height: 48px; border-radius: 50%;
  background: rgba(20,26,33,0.8); backdrop-filter: blur(6px);
  border: 1px solid var(--line); color: var(--text);
  font-size: 20px; cursor: pointer;
}
.hud-btn.active { background: var(--accent); border-color: var(--accent); }
.hud-btn:active { transform: scale(0.92); }

.place-banner {
  position: absolute; top: 0; left: 0; right: 0;
  background: var(--accent); color: #fff;
  text-align: center; padding: 10px; font-size: 14px; font-weight: 600;
  pointer-events: auto;
}

.aim-bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: rgba(14,17,22,0.92); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding: 12px 14px calc(var(--safe-bottom) + 12px);
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  pointer-events: auto; z-index: 12;
}
#aimText { flex: 1; font-size: 14px; min-width: 140px; }
.aim-actions { display: flex; gap: 8px; }

/* priority swatches in dialogs */
.prio-row { display: flex; gap: 8px; }
.prio-opt {
  flex: 1; text-align: center; padding: 10px; border-radius: 10px; cursor: pointer;
  border: 2px solid transparent; color: #fff; font-weight: 600; font-size: 13px;
}
.prio-opt.sel { border-color: #fff; }
.prio-high { background: #ef4444; }
.prio-medium { background: #f59e0b; }
.prio-low { background: #22c55e; }

/* manage list rows */
.manage-list { display: flex; flex-direction: column; gap: 8px; max-height: 52vh; overflow-y: auto; }
.manage-row {
  display: flex; align-items: center; gap: 10px; padding: 10px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--bg-3);
}
.manage-row .m-ico { width: 26px; text-align: center; font-size: 18px; flex: none; }
.manage-row .m-body { flex: 1; min-width: 0; }
.manage-row .m-body .m-title { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.manage-row .m-body .m-sub { font-size: 12px; color: var(--muted); }
.manage-row .m-act { display: flex; gap: 6px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.section-label { font-size: 12px; color: var(--muted); margin: 12px 0 4px; text-transform: uppercase; letter-spacing: 0.5px; }

/* ---------- Floor bookmarks ---------- */
.floor-bar {
  display: flex; gap: 8px; align-items: center;
  padding: 10px 12px; overflow-x: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg-2); border-bottom: 1px solid var(--line);
  flex: 1; min-width: 0;
}
.floor-bar::-webkit-scrollbar { display: none; }
.floor-chip {
  flex: none; display: flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-radius: 20px; cursor: pointer; font-size: 14px; font-weight: 600;
  background: var(--bg-3); border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.floor-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.floor-chip .fc-menu { font-size: 15px; opacity: 0.85; padding: 0 2px; }
.floor-chip.add { color: var(--text); font-weight: 700; }

.grid-toolbar { display: flex; align-items: stretch; gap: 8px; background: var(--bg-2); border-bottom: 1px solid var(--line); }
.grid-toolbar .floor-bar { border-bottom: none; }
.grid-toolbar #btnExportTasks { align-self: center; margin: 0 12px; flex: none; }

/* ---------- Map / floor plan ---------- */
.map-toolbar { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--bg-2); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.map-wrap { flex: 1; position: relative; background: var(--bg); min-height: 0; overflow: hidden; }
#mapCanvas { width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------- Shot grid ---------- */
.shot-grid {
  flex: 1; overflow-y: auto;
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  padding: 12px 12px calc(var(--safe-bottom) + 90px);
  align-content: start;
}
@media (min-width: 620px) { .shot-grid { grid-template-columns: 1fr 1fr 1fr; } }
.shot-cell {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; cursor: pointer;
}
.shot-cell .sh-thumb { height: 100px; background: var(--bg-3) center/cover no-repeat; }
.shot-cell .sh-meta { padding: 8px 10px; display: flex; align-items: center; gap: 6px; }
.shot-cell .sh-name { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shot-cell.selected { outline: 2px solid var(--accent); }
.shot-cell { position: relative; }
.sh-badges {
  position: absolute; top: 6px; right: 6px;
  background: rgba(0,0,0,0.6); color: #fff; font-size: 11px;
  padding: 3px 7px; border-radius: 10px; letter-spacing: 0.5px;
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: flex-end; justify-content: center; z-index: 100;
}
@media (min-width: 620px) { .modal-backdrop { align-items: center; } }
.modal {
  background: var(--bg-2); width: 100%; max-width: 460px;
  border-radius: 18px 18px 0 0; padding: 20px 18px calc(var(--safe-bottom) + 20px);
  border: 1px solid var(--line);
}
@media (min-width: 620px) { .modal { border-radius: 18px; } }
.modal h2 { margin: 0 0 14px; font-size: 19px; }
.modal .field { margin-bottom: 14px; }
.modal label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.modal input[type=text], .modal textarea, .modal select {
  width: 100%; background: var(--bg-3); border: 1px solid var(--line);
  color: var(--text); border-radius: 10px; padding: 12px; font-size: 16px;
}
.modal textarea { min-height: 80px; resize: vertical; }
.modal .row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 8px; flex-wrap: wrap; }
.modal .row.spread > div { display: flex; gap: 10px; flex-wrap: wrap; }
.modal .row.spread { justify-content: space-between; }
.modal .list-choice { display: flex; flex-direction: column; gap: 8px; max-height: 45vh; overflow-y: auto; }
.modal .choice {
  display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--line);
  border-radius: 10px; cursor: pointer; background: var(--bg-3);
}
.modal .choice .c-thumb { width: 48px; height: 34px; border-radius: 6px; background: var(--bg) center/cover no-repeat; flex: none; }
.help-body p { line-height: 1.5; }
.help-body ol { line-height: 1.6; padding-left: 20px; }
.help-body code { background: var(--bg-3); padding: 1px 5px; border-radius: 4px; font-size: 13px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 24px);
  transform: translateX(-50%);
  background: var(--bg-3); border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 22px; font-size: 14px; z-index: 200;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4); max-width: 90%;
}

/* ---------- Spinner ---------- */
.spinner {
  width: 26px; height: 26px; border: 3px solid var(--line);
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite; margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-note { color: var(--muted); text-align: center; padding: 40px 20px; }
#projectList .empty-note { grid-column: 1 / -1; }

/* ---------- Drag & drop (desktop) ---------- */
.drop-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(14,17,22,0.86); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.drop-inner {
  border: 3px dashed var(--accent); border-radius: 18px;
  padding: 48px 64px; text-align: center; color: var(--text);
}
.drop-inner .big-emoji { font-size: 52px; }
.drop-inner p { font-size: 18px; font-weight: 600; margin: 10px 0 0; }

/* Hide the phone-only gyro control on non-touch (desktop) devices. */
body.no-touch #btnGyro { display: none; }

#btnAccount.signed-in { border-color: var(--accent-2); color: var(--text); }

/* ---------- Desktop layout polish ---------- */
@media (min-width: 900px) and (pointer: fine) {
  #view-projects { align-items: center; padding: 28px 24px calc(var(--safe-bottom) + 90px); }
  .hero, #projectList { width: 100%; max-width: 1180px; }
  .hero h1 { font-size: 28px; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
  .project-card .thumb { height: 170px; }

  /* Roomier management panes, centered content. */
  .shot-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); max-width: 1180px; margin: 0 auto; width: 100%; }
  .shot-cell .sh-thumb { height: 150px; }

  /* Bigger, hover-friendly HUD buttons. */
  .hud-btn { width: 52px; height: 52px; }
  .hud-btn:hover { background: var(--accent); border-color: var(--accent); }
  .fab:hover { filter: brightness(1.08); }
  .project-card:hover { border-color: var(--accent); }

  /* The install button reads better with a little breathing room. */
  #btnInstall { margin-right: 4px; }
}
