:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #14181f;
  --muted: #5b6574;
  --line: #e1e5ea;
  --brand: #0f8a5f;
  --brand-dark: #0b6b49;
  --brand-ink: #ffffff;
  --warn: #b42318;
  --radius: 12px;
}

/* Dark theme: follows the system unless the user picked a theme with the toggle (data-theme). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1318;
    --card: #181d24;
    --ink: #eef1f5;
    --muted: #9aa5b4;
    --line: #2a313b;
    --brand: #2bbf8a;
    --brand-dark: #1f9a6d;
    --brand-ink: #06231a;
    --warn: #ff8a80;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1318;
  --card: #181d24;
  --ink: #eef1f5;
  --muted: #9aa5b4;
  --line: #2a313b;
  --brand: #2bbf8a;
  --brand-dark: #1f9a6d;
  --brand-ink: #06231a;
  --warn: #ff8a80;
}
:root { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { color-scheme: dark; } }

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* header */
.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; font-size: 20px; letter-spacing: -0.02em; color: var(--brand); }
.auth-area { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.quota { font-size: 13px; color: var(--muted); }
.user { font-size: 14px; font-weight: 600; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  padding: 9px 14px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; padding: 0;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); color: var(--ink); cursor: pointer;
}
.icon-btn:hover { border-color: var(--brand); color: var(--brand); }
#themeBtn .i-sun { display: none; }
#themeBtn[data-mode="dark"] .i-sun { display: inline; }
#themeBtn[data-mode="dark"] .i-moon { display: none; }

/* search */
.searchbar { padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
#searchForm { display: flex; gap: 8px; flex-wrap: wrap; }
#q { flex: 1 1 100%; min-width: 0; }
#searchForm select { flex: 1 1 110px; min-width: 0; }
#q, select {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: var(--bg);
  color: var(--ink);
}
/* map + results */
.layout { flex: 1; display: grid; grid-template-columns: 1fr 380px; min-height: 0; }
.mapwrap { position: relative; min-height: 420px; }
#map { position: absolute; inset: 0; }
.here { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 5; box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25); }

.locate {
  position: absolute; top: 12px; right: 12px; z-index: 5;
  width: 42px; height: 42px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: 50%;
  background: var(--card); color: #1a73e8; cursor: pointer;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}
.locate:disabled { opacity: 0.6; cursor: progress; }
.me-dot {
  width: 20px; height: 20px; border-radius: 50%;
  background: #1a73e8; border: 3px solid #fff;
  box-shadow: 0 0 0 0 rgba(26, 115, 232, 0.6);
  animation: me-pulse 2s infinite;
}
@keyframes me-pulse {
  0% { box-shadow: 0 0 0 0 rgba(26, 115, 232, 0.55); }
  70% { box-shadow: 0 0 0 14px rgba(26, 115, 232, 0); }
  100% { box-shadow: 0 0 0 0 rgba(26, 115, 232, 0); }
}

.results { overflow-y: auto; background: var(--card); border-left: 1px solid var(--line); max-height: calc(100dvh - 150px); }
.results-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#status { padding: 12px 16px; color: var(--muted); font-size: 14px; flex: 1; }
.toggle { display: none; }
#status.error { color: var(--warn); font-weight: 600; }
#list { list-style: none; margin: 0; padding: 0; }
.more { display: block; width: calc(100% - 32px); margin: 12px 16px 16px; }
.item { padding: 12px 16px; border-top: 1px solid var(--line); cursor: pointer; }
.item:hover, .item.active { background: var(--bg); }
.item h3 { margin: 0 0 2px; font-size: 15px; }
.item .num { color: var(--brand); margin-right: 6px; }
.meta { font-size: 13px; color: var(--muted); }
.open { color: var(--brand); font-weight: 700; }
.closed { color: var(--warn); font-weight: 700; }
.actions { margin-top: 6px; display: flex; gap: 14px; font-size: 13px; }
.actions a { color: var(--brand); text-decoration: none; font-weight: 700; }
.actions a:hover { text-decoration: underline; }

@media (max-width: 760px) {
  /* app-style layout: header + search stay put, map on top, results scroll underneath */
  body { height: 100vh; height: 100dvh; overflow: hidden; max-width: 100vw; }
  .top { padding: 8px 12px; }
  .brand { font-size: 18px; }
  .auth-area { flex-wrap: nowrap; gap: 8px; }
  .user, .points { display: none; }
  .quota { font-size: 11px; line-height: 1.2; max-width: 84px; text-align: right; }
  .icon-btn { width: 32px; height: 32px; }
  .top .btn { padding: 6px 10px; font-size: 14px; }

  .searchbar { padding: 8px 12px; }
  #searchForm { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  #q { grid-column: 1 / 3; order: 0; flex: none; min-width: 0; padding: 9px 10px; }
  #searchForm .btn { order: 1; padding: 9px 8px; }
  #searchForm select { order: 2; flex: none; min-width: 0; padding: 8px 6px; font-size: 14px; }

  .layout { grid-template-columns: 1fr; grid-template-rows: 36vh minmax(0, 1fr); grid-template-rows: 36dvh minmax(0, 1fr); }
  .mapwrap { min-height: 0; }
  .here { top: 8px; padding: 6px 10px; font-size: 13px; }
  .results { max-height: none; min-height: 0; border-left: 0; border-top: 1px solid var(--line); overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .results-head { position: sticky; top: 0; background: var(--card); z-index: 1; padding-right: 10px; border-bottom: 1px solid var(--line); }
  #status { padding: 8px 12px; }
  .toggle { display: inline-block; padding: 5px 10px; font-size: 13px; white-space: nowrap; }
  .layout.collapsed { grid-template-rows: minmax(0, 1fr) auto; }
  .layout.collapsed #list, .layout.collapsed #loadMore, .layout.collapsed .results-sub { display: none; }
  .results-sub { padding: 0 12px 8px; }
  .more { width: calc(100% - 24px); margin: 10px 12px 14px; }
  .item { padding: 10px 12px; }
}

/* points, confirmations, share */
.points {
  font-size: 12px; font-weight: 700; padding: 4px 9px; border-radius: 999px;
  border: 1px solid var(--brand); color: var(--brand); white-space: nowrap; cursor: help;
}
.still { flex-basis: 100%; display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 4px; font-size: 12px; color: var(--muted); }
.tap {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 3px 10px; border-radius: 999px; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
}
.tap.on.yes { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.tap.on.no { background: var(--warn); border-color: var(--warn); color: #fff; }
.badge.disputed { border-left-style: dashed; }
.dispute-tag { color: var(--warn); font-weight: 700; font-size: 12px; }
.mine-note { font-style: italic; }
.comment-latest { font-size: 13px; margin-top: 6px; color: var(--ink); }
.comment-latest small { color: var(--muted); }
.comments-list { list-style: none; margin: 0 0 12px; padding: 0; max-height: 40vh; overflow-y: auto; }
.comments-list li { padding: 8px 10px; background: var(--bg); border-radius: 8px; margin-bottom: 6px; font-size: 14px; overflow-wrap: anywhere; }
.comments-list small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.comments-list .del { border: 0; background: none; color: var(--warn); font: inherit; font-size: 12px; cursor: pointer; padding: 0; margin-left: 8px; }
.comments textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; background: var(--bg); color: var(--ink); resize: vertical;
}
.comment-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; }
.tap.yes:hover { border-color: var(--brand); color: var(--brand); }
.tap.no:hover { border-color: var(--warn); color: var(--warn); }
.note.stats { font-size: 13px; }
.actions { flex-wrap: wrap; row-gap: 6px; }

/* live reports */
.live { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.badge {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px;
  padding: 5px 9px; border-radius: 8px; border-left: 3px solid var(--muted);
  background: var(--bg); font-size: 13px;
}
.badge.good { border-left-color: var(--brand); }
.badge.bad { border-left-color: var(--warn); }
.badge-main { font-weight: 700; }
.badge.good .badge-main { color: var(--brand); }
.badge.bad .badge-main { color: var(--warn); }
.badge-time { color: var(--muted); font-size: 12px; }
.linkbtn { border: 0; background: none; padding: 0; font: inherit; font-size: 13px; font-weight: 700; color: var(--brand); cursor: pointer; }
.linkbtn:hover { text-decoration: underline; }
.results-sub { padding: 0 16px 10px; }
.pill {
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
  padding: 6px 12px; border-radius: 999px; font: inherit; font-size: 13px; cursor: pointer;
}
.pill[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 700; }
.report h3 { margin: 14px 0 8px; font-size: 14px; }
.seg { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.seg button {
  flex: 1 1 auto; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--ink); font: inherit; font-size: 14px; cursor: pointer;
}
.seg button.on { border-color: var(--brand); background: var(--brand); color: var(--brand-ink); font-weight: 700; }
.field { display: block; font-size: 13px; font-weight: 600; margin-bottom: 10px; }
.field input {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px; font: inherit; background: var(--bg); color: var(--ink);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* install sheet */
.install-head { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.install-head img { border-radius: 12px; }
.install-head h2 { margin: 0; }
.install-for { font-size: 12px; font-weight: 700; letter-spacing: 0.08em; color: var(--brand); }
.install-hint { margin: 12px 0 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font-size: 14px; }
.install-actions { display: flex; gap: 10px; margin-top: 16px; }
.install-actions .btn { flex: 1; }

/* auth modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.modal-card {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px 22px 18px;
  width: 100%;
  max-width: 360px;
  max-height: 100%;
  overflow-y: auto;
}
.modal-card h2 { margin: 0 0 4px; font-size: 20px; }
.note { margin: 0 0 14px; color: var(--muted); font-size: 14px; min-height: 1em; }
.close { position: absolute; top: 8px; right: 12px; border: 0; background: none; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); }
.google-slot { display: flex; justify-content: center; min-height: 44px; }
.divider { display: flex; align-items: center; gap: 10px; margin: 14px 0; color: var(--muted); font-size: 13px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
#authForm label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 10px; }
#authForm input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: var(--bg);
  color: var(--ink);
}
.error { color: var(--warn); font-size: 13px; min-height: 1.2em; margin: 0 0 8px; }
.link { display: block; margin: 12px auto 0; border: 0; background: none; color: var(--brand); cursor: pointer; font: inherit; font-weight: 600; }

/* celebration pop-up */
.modal-card.celebrate-card { text-align: center; max-width: 340px; animation: celebrate-pop 0.4s cubic-bezier(0.2, 1.4, 0.4, 1); }
.modal-card.celebrate-card h2 { font-size: 28px; margin: 0 0 4px; }
.celebrate-points {
  width: 92px; height: 92px; margin: 0 auto 10px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 34px; font-weight: 800; color: var(--brand-ink); background: var(--brand);
  box-shadow: 0 0 0 8px rgba(15, 138, 95, 0.2);
}
.celebrate-lead { margin: 0 0 12px; color: var(--muted); }
.celebrate-list { list-style: none; margin: 0 0 10px; padding: 0; text-align: left; }
.celebrate-list li { padding: 8px 10px; background: var(--bg); border-radius: 8px; margin-bottom: 6px; font-size: 14px; }
#confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 70; }
@keyframes celebrate-pop { from { transform: scale(0.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .modal-card.celebrate-card { animation: none; } }
