/* KeiFacts - Kei Truck Legality by State */
:root,
[data-theme="dark"] {
  --bg: #0f1419;
  --surface: #1a2332;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --legal: #2ea043;
  --restricted: #e6b800;
  --illegal: #ef4444;
  --pending: #d8d8d8;
  --unknown: #4a4a4a;
  --border: #30363d;
}

/* Light theme */
[data-theme="light"] {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --text: #1f2328;
  --text-muted: #656d76;
  --accent: #0969da;
  --border: #d0d7de;
}

* { box-sizing: border-box; }

body {
  font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  margin: 0;
  padding: 0;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1rem;
}

header {
  text-align: center;
  padding: 2rem 0;
  border-bottom: 1px solid var(--border);
  position: relative;
}

body.page-home header {
  border-bottom: none;
  padding-bottom: 0.75rem;
}
body.page-home main { padding-top: 0.5rem; }
body.page-home main > .ad-banner:first-of-type { margin-top: 0.5rem; }

.theme-toggle {
  position: absolute;
  top: 1rem;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  font-size: 1.25rem;
  cursor: pointer;
  line-height: 1;
}

.theme-toggle:hover {
  border-color: var(--accent);
}

h1 {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 700;
  margin: 0 0 0.5rem;
}

.site-title {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.site-logo {
  flex-shrink: 0;
  vertical-align: middle;
}

.tagline {
  color: var(--text-muted);
  margin: 0;
  font-size: 1rem;
}

header .suggest-edit-trigger {
  margin-top: 0.75rem;
}

main { padding: 1.5rem 0 3rem; }

/* Map */
.map-section {
  margin-bottom: 2rem;
}

.map-section h2,
.state-list-section h2 {
  font-size: 1.25rem;
  margin: 0 0 0.75rem;
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.8125rem;
}

.legend-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  font-weight: 500;
  color: #fff;
  border: 1px solid rgba(255,255,255,0.25);
}

.legend-pill.legal { background: var(--legal); }
.legend-pill.restricted { background: var(--restricted); color: #1a1a1a; }
.legend-pill.illegal { background: var(--illegal); }
.legend-pill.pending { background: var(--pending); color: #1a1a1a; border-color: rgba(0,0,0,0.2); }
.legend-pill.unknown { background: var(--unknown); }

.map-container {
  position: relative;
  background: var(--surface);
  border-radius: 8px;
  overflow: hidden;
  padding: 0.5rem;
}

.map-svg-wrapper {
  display: block;
  line-height: 0;
}

.map-svg-wrapper svg {
  max-width: 100%;
  height: auto;
}

#us-map {
  width: 100%;
  height: auto;
  max-height: 75vh;
}

#us-map path {
  cursor: pointer;
  transition: filter 0.15s, transform 0.15s;
}

#us-map path:hover {
  filter: brightness(1.2);
}

.state-tooltip {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  font-size: 0.8125rem;
  max-width: 280px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  pointer-events: none;
  z-index: 1000;
  opacity: 0;
  left: 0;
  top: 0;
  transition: opacity 0.15s;
}

.state-tooltip.visible {
  opacity: 1;
}

.state-tooltip .tooltip-state { font-weight: 700; margin-bottom: 0.25rem; }
.state-tooltip .tooltip-legal { font-size: 0.75rem; color: var(--text-muted); }
.state-tooltip .tooltip-detail { margin-top: 0.25rem; font-size: 0.75rem; }

/* State list */
.state-list-section {
  margin-top: 2rem;
}

.disclaimer {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}

.state-list-controls {
  margin-bottom: 1rem;
}

.state-search-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.state-search {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.9rem;
  font-family: inherit;
}

.state-search::placeholder {
  color: var(--text-muted);
}

.state-filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.state-filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.filter-pill {
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  background: transparent;
  transition: background 0.15s, color 0.15s;
}

.filter-pill.legal { border: 1.5px solid var(--legal); color: var(--legal); }
.filter-pill.legal:hover { background: rgba(46, 160, 67, 0.15); }
.filter-pill.legal.selected { background: var(--legal); color: #fff; border-color: var(--legal); }

.filter-pill.restricted { border: 1.5px solid var(--restricted); color: var(--restricted); }
.filter-pill.restricted:hover { background: rgba(230, 184, 0, 0.15); }
.filter-pill.restricted.selected { background: var(--restricted); color: #1a1a1a; border-color: var(--restricted); }

.filter-pill.illegal { border: 1.5px solid var(--illegal); color: var(--illegal); }
.filter-pill.illegal:hover { background: rgba(239, 68, 68, 0.15); }
.filter-pill.illegal.selected { background: var(--illegal); color: #fff; border-color: var(--illegal); }

.filter-pill.pending { border: 1.5px solid var(--pending); color: var(--text-muted); }
.filter-pill.pending:hover { background: rgba(216, 216, 216, 0.3); }
.filter-pill.pending.selected { background: var(--pending); color: #1a1a1a; border-color: var(--pending); }

.filter-pill.unknown { border: 1.5px solid var(--unknown); color: var(--unknown); }
.filter-pill.unknown:hover { background: rgba(74, 74, 74, 0.15); }
.filter-pill.unknown.selected { background: var(--unknown); color: #fff; border-color: var(--unknown); }

.btn-clear {
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
  flex-shrink: 0;
}

.btn-clear:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.state-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

.state-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  transition: border-color 0.15s;
}

.state-card:hover { border-color: var(--accent); }

.state-card h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
}

.state-card h3 a {
  color: inherit;
  text-decoration: none;
}

.state-card h3 a:hover { text-decoration: underline; }

.state-card .badge,
.state-page .state-badge,
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  font-weight: 500;
  color: #fff;
  border: 1px solid rgba(255,255,255,0.25);
}

.state-card .badge { font-size: 0.7rem; margin-bottom: 0.5rem; }

.badge.legal,
.state-badge.legal { background: var(--legal); }
.badge.restricted,
.state-badge.restricted { background: var(--restricted); color: #1a1a1a; }
.badge.illegal,
.state-badge.illegal { background: var(--illegal); }
.badge.pending,
.state-badge.pending { background: var(--pending); color: #1a1a1a; border-color: rgba(0,0,0,0.2); }
.badge.unknown,
.state-badge.unknown { background: var(--unknown); }

.state-card .detail {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0.15rem 0;
}

.state-list-empty {
  color: var(--text-muted);
  padding: 1.5rem;
}

.state-list-empty .link-button {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  padding: 0;
  text-decoration: underline;
}

/* Ad banners */
.ad-banner {
  margin: 1.5rem 0;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 90px;
}

.ad-banner .ad-mobile { display: none; }

@media (max-width: 768px) {
  .ad-banner .ad-desktop { display: none; }
  .ad-banner .ad-mobile { display: block; width: 100%; max-width: 100%; }
  .ad-banner.ad-mid .ad-mobile { display: block; }
  .ad-banner .ad-mobile .ad-link {
    width: 100%;
  }
  .ad-banner .ad-mobile img {
    width: 100%;
    max-width: 100%;
    height: auto;
    min-height: 60px;
    object-fit: contain;
  }
  .ad-banner .ad-mobile .ad-destination {
    font-size: 0.85rem;
    padding: 5px 8px;
  }
}

.ad-slot {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.ad-link {
  display: block;
  position: relative;
}

.ad-link,
.ad-link:link,
.ad-link:visited,
.ad-link:hover,
.ad-link:focus,
.ad-link:focus-visible {
  color: inherit;
  text-decoration: none;
}

.ad-link:hover .ad-destination {
  opacity: 1;
}

.ad-destination {
  position: absolute;
  bottom: 6px;
  right: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 4px;
  opacity: 0.9;
  color: white;
  pointer-events: none;
  font-size: 0.75rem;
}

.ad-domain {
  color: white;
}

.ad-external-icon {
  color: white;
  flex-shrink: 0;
}

.ad-external-icon svg {
  display: block;
  color: white;
}

.ad-slot img {
  display: block;
  max-width: 100%;
  height: auto;
}

.ad-mrec .ad-slot { min-height: 250px; }

/* State detail page - back button */
header nav {
  position: absolute;
  left: 0;
  top: 1rem;
}

header nav .btn-back {
  display: inline-block;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-weight: 500;
  text-decoration: none;
  transition: opacity 0.15s;
}

/* Dark mode: white background, dark text */
:root,
[data-theme="dark"] {
  --btn-back-bg: #ffffff;
  --btn-back-text: #1a1a1a;
}

/* Light mode: black background, white text */
[data-theme="light"] {
  --btn-back-bg: #1a1a1a;
  --btn-back-text: #ffffff;
}

header nav .btn-back {
  background: var(--btn-back-bg);
  color: var(--btn-back-text);
}

header nav .btn-back:hover {
  opacity: 0.9;
}

/* State detail page */
.state-page { padding: 2rem 0; }
.state-page .state-badge {
  font-size: 0.9rem;
  padding: 0.4rem 0.75rem;
  margin-bottom: 1.5rem;
}
.state-page nav { margin-bottom: 1rem; }
.state-page nav a { color: var(--accent); }
.state-details {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem 2rem;
  max-width: 600px;
}
.state-details dt { color: var(--text-muted); font-weight: 500; }
.state-details dd { margin: 0; }

.gov-source-link {
  color: var(--accent);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.gov-source-link:hover {
  text-decoration: underline;
}

.gov-source-link::after {
  content: '';
  width: 0.75em;
  height: 0.75em;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2'%3E%3Cpath d='M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6'/%3E%3Cpolyline points='15 3 21 3 21 9'/%3E%3Cline x1='10' y1='14' x2='21' y2='3'/%3E%3C/svg%3E");
  background-size: contain;
  opacity: 0.7;
}

.gov-source-link--empty {
  color: var(--text-muted);
  cursor: default;
}

.gov-source-link--empty:hover {
  text-decoration: none;
}

.gov-source-link--empty::after {
  display: none;
}

/* Footer */
footer {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}

footer a { color: var(--accent); }

.footer-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.footer-actions .btn-advertise {
  text-decoration: none;
  cursor: pointer;
}

/* Suggest Edit */
.btn-suggest {
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--border);
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

.btn-suggest:hover {
  border-color: var(--accent);
  background: rgba(88, 166, 255, 0.1);
}

.suggest-modal {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0;
  max-width: 420px;
  background: var(--surface);
  color: var(--text);
}

.suggest-modal::backdrop {
  background: rgba(0, 0, 0, 0.7);
}

.suggest-modal-content {
  position: relative;
  padding: 1.5rem;
}

.suggest-modal h2 {
  font-size: 1.25rem;
  margin: 0 0 0.5rem;
}

.suggest-modal-desc {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 0 0 1.25rem;
}

.suggest-form label {
  display: block;
  font-size: 0.85rem;
  margin: 0.75rem 0 0.25rem;
  color: var(--text-muted);
}

.suggest-form label:first-of-type { margin-top: 0; }

.suggest-form input,
.suggest-form textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
}

.suggest-form input:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.suggest-form textarea { resize: vertical; min-height: 80px; }

.suggest-form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.btn-submit {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}

.btn-submit:hover:not(:disabled) { filter: brightness(1.1); }
.btn-submit:disabled { opacity: 0.7; cursor: not-allowed; }

.btn-cancel {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}

.btn-cancel:hover { border-color: var(--text-muted); }

.suggest-success {
  color: var(--legal);
  margin: 1rem 0 0;
}

.suggest-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  padding: 0;
}

.suggest-close:hover { color: var(--text); }
