:root {
  --bg: #f1f5f9;
  --surface: #fff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --radius: 14px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Header ── */
header {
  background: var(--primary);
  color: #fff;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
header h1 { font-size: 1.25rem; font-weight: 700; }
header .header-sub { font-size: .8rem; opacity: .8; margin-top: 2px; }
header .spacer { flex: 1; }
#api-key-btn {
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.3);
  color: #fff;
  border-radius: 8px;
  padding: 6px 14px;
  font-size: .85rem;
  cursor: pointer;
  transition: background .2s;
}
#api-key-btn:hover { background: rgba(255,255,255,.25); }

/* ── Tabs ── */
.tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 2px solid var(--border);
  padding: 0 24px;
}
.tab-btn {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  padding: 14px 20px;
  font-size: .95rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: color .2s, border-color .2s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ── Tab panels ── */
.tab-panel { display: block; }
.tab-panel.hidden { display: none; }

/* ── Main layout ── */
main {
  max-width: 900px;
  margin: 32px auto;
  padding: 0 16px;
}

/* ── Search wrap ── */
.search-wrap {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  margin-bottom: 24px;
}
.search-row {
  display: flex;
  gap: 10px;
}
.search-row input {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 1rem;
  outline: none;
  transition: border-color .2s;
}
.search-row input:focus { border-color: var(--primary); }
.search-row button {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 22px;
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s;
  white-space: nowrap;
}
.search-row button:hover { background: var(--primary-dark); }

/* ── Result card (phone search) ── */
.result-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  margin-bottom: 16px;
}
.result-card .num-type {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .8rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  margin-bottom: 10px;
}
.result-card .phone-num {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--text);
}
.result-card .region {
  color: var(--text-muted);
  font-size: .9rem;
  margin-top: 4px;
}
.result-card .desc {
  font-size: .85rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Biz card (phone search → business info) ── */
.biz-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  margin-bottom: 16px;
}
.biz-name {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}
.biz-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.biz-badge {
  font-size: .78rem;
  padding: 2px 10px;
  border-radius: 20px;
  background: #eff6ff;
  color: var(--primary);
  font-weight: 500;
}
.biz-addr {
  font-size: .9rem;
  color: var(--text-muted);
}
.biz-rating {
  font-size: .9rem;
  color: #f59e0b;
  margin-top: 4px;
}

/* ── Map ── */
#map {
  height: 300px;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
#map.hidden { display: none; }

/* ── Error ── */
.error-card {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: 16px 20px;
  color: #b91c1c;
  font-size: .95rem;
}

/* ── Loading ── */
.loading-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: .95rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.spinner {
  display: inline-block;
  width: 22px; height: 22px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
  margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px 32px;
  max-width: 460px;
  width: 90%;
  box-shadow: 0 8px 40px rgba(0,0,0,.18);
}
.modal h2 { font-size: 1.1rem; font-weight: 700; margin-bottom: 12px; }
.modal p  { font-size: .9rem; color: var(--text-muted); margin-bottom: 16px; line-height: 1.6; }
.modal input {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: .95rem;
  margin-bottom: 16px;
  outline: none;
}
.modal input:focus { border-color: var(--primary); }
.modal-btns { display: flex; gap: 10px; justify-content: flex-end; }
.modal-btns button {
  border: none;
  border-radius: 8px;
  padding: 8px 20px;
  font-size: .9rem;
  cursor: pointer;
  font-weight: 500;
}
.btn-cancel { background: var(--bg); color: var(--text-muted); }
.btn-save   { background: var(--primary); color: #fff; }
.btn-save:hover { background: var(--primary-dark); }

/* ── Reverse lookup section ── */
.rev-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
  margin-bottom: 24px;
}
.rev-section h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 16px;
}

#rev-results.hidden { display: none; }

.rev-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.rev-loading {
  text-align: center;
  color: var(--text-muted);
  font-size: .95rem;
}

.rev-result-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.rev-keyword {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}
.rev-count {
  font-size: .85rem;
  color: var(--text-muted);
}
.rev-source-badge {
  font-size: .75rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  background: #eff6ff;
  color: var(--primary);
}
.rev-source-badge.osm {
  background: #f0fdf4;
  color: #16a34a;
}

.rev-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rev-item-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
}
.rev-item-name {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
}
.rev-item-cat {
  font-size: .8rem;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.rev-item-phone {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: .04em;
  margin-bottom: 6px;
}
.rev-item-phone a {
  color: inherit;
  text-decoration: none;
}
.rev-item-phone a:hover { text-decoration: underline; }

.rev-no-phone-block {
  margin-bottom: 8px;
}
.rev-no-phone-label {
  display: inline-block;
  background: #fef9c3;
  color: #854d0e;
  border: 1px solid #fde047;
  border-radius: 6px;
  padding: 4px 12px;
  font-size: .8rem;
  font-weight: 600;
}
.rev-api-hint {
  font-size: .78rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.rev-copy-btn {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 10px;
  font-size: .8rem;
  cursor: pointer;
  margin-left: 8px;
  vertical-align: middle;
  transition: background .15s;
}
.rev-copy-btn:hover { background: #dbeafe; }
.rev-copy-btn.copied { background: #dcfce7; border-color: #86efac; }

.rev-item-addr {
  font-size: .85rem;
  color: var(--text-muted);
  margin-top: 4px;
}
.rev-item-source {
  font-size: .75rem;
  color: var(--text-muted);
  margin-top: 6px;
  font-style: italic;
}
.rev-item-rating {
  font-size: .85rem;
  color: #f59e0b;
  margin-top: 2px;
}

.rev-osm-note {
  margin-top: 14px;
  padding: 10px 14px;
  background: #f8fafc;
  border-radius: 8px;
  font-size: .8rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.rev-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: .95rem;
  padding: 24px 0;
}

/* ── Responsive ── */
@media (max-width: 600px) {
  header { padding: 12px 16px; }
  header h1 { font-size: 1rem; }
  main { margin: 16px auto; }
  .tabs { padding: 0 8px; }
  .tab-btn { padding: 12px 12px; font-size: .85rem; }
  .search-wrap, .rev-section { padding: 16px; }
  .search-row { flex-direction: column; }
  .result-card .phone-num { font-size: 1.3rem; }
  .rev-item-phone { font-size: 1.2rem; }
}
