:root {
  --bg: #fafafa;
  --surface: #fff;
  --text: #1a1a1a;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --green: #059669;
  --red: #dc2626;
  --orange: #d97706;
  --tag-bg: #f3f4f6;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111827;
    --surface: #1f2937;
    --text: #f9fafb;
    --muted: #9ca3af;
    --border: #374151;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --tag-bg: #374151;
  }
}

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

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

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px;
}

header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 32px;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

header h1 span { color: var(--accent); }

header nav { margin-left: auto; display: flex; gap: 16px; }
header nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
}
header nav a:hover { color: var(--text); }

h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
}

form label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--text);
}

form .hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 4px;
}

form input, form select, form textarea {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  background: var(--bg);
  color: var(--text);
  margin-bottom: 16px;
}

form input:focus, form select:focus, form textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

form textarea { resize: vertical; min-height: 60px; }

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
}

@media (max-width: 640px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0 16px;
}

@media (max-width: 640px) {
  .grid-3 { grid-template-columns: 1fr; }
}

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  font-size: 0.875rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--tag-bg);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.tag-green { background: #d1fae5; color: #065f46; }
.tag-red { background: #fee2e2; color: #991b1b; }
.tag-orange { background: #fef3c7; color: #92400e; }
.tag-blue { background: #dbeafe; color: #1e40af; }
.tag-gray { background: var(--tag-bg); color: var(--muted); }

.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
  transition: box-shadow 0.15s;
}
.result-card:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.result-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 0.875rem;
  margin-right: 12px;
  flex-shrink: 0;
}

.result-header {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}

.result-name {
  font-size: 1.1rem;
  font-weight: 600;
}

.result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.result-note {
  font-size: 0.8125rem;
  color: var(--muted);
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.result-contact {
  font-size: 0.875rem;
  margin-top: 8px;
}

.excluded-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.excluded-table th {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 2px solid var(--border);
  font-weight: 600;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.excluded-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.excluded-table tr:last-child td { border-bottom: none; }

.summary-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  padding: 16px 0;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
}

.summary-stat { text-align: center; }
.summary-stat .num {
  font-size: 1.5rem;
  font-weight: 700;
}
.summary-stat .label {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 0.875rem;
}
.alert-warning {
  background: #fef3c7;
  border: 1px solid #f59e0b;
  color: #92400e;
}
.alert-danger {
  background: #fee2e2;
  border: 1px solid #ef4444;
  color: #991b1b;
}
.alert-success {
  background: #d1fae5;
  border: 1px solid #10b981;
  color: #065f46;
}

.htmx-indicator {
  display: none;
}
.htmx-request .htmx-indicator {
  display: inline-block;
}
.htmx-request .btn-text {
  display: none;
}

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid #fff;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 8px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.addr-wrap {
  position: relative;
}
.addr-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  z-index: 100;
  max-height: 200px;
  overflow-y: auto;
  display: none;
}
.addr-suggestions.open { display: block; }
.addr-suggestion {
  padding: 8px 12px;
  font-size: 0.8125rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.addr-suggestion:last-child { border-bottom: none; }
.addr-suggestion:hover, .addr-suggestion.active {
  background: var(--accent);
  color: #fff;
}

footer {
  margin-top: 48px;
  padding: 16px 0;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
}
