:root {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --surface-2: #f0f3f6;
  --border: #d0d7de;
  --border-subtle: #e4e8ec;
  --ink: #1f2328;
  --ink-muted: #57606a;
  --ink-subtle: #adb5bd;
  --accent: #0969da;
  --accent-hover: #0550ae;
  --accent-muted: rgba(9, 105, 218, 0.1);
  --accent-border: rgba(9, 105, 218, 0.3);
  --success: #1a7f37;
  --warning: #9a6700;
  --danger: #cf222e;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 3px rgba(31,35,40,0.08);
  --shadow-md: 0 4px 16px rgba(31,35,40,0.12);
  --shadow-lg: 0 8px 32px rgba(31,35,40,0.16);
}

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

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

button, input, textarea, select {
  font: inherit;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1, h2, h3, h4, p {
  margin-top: 0;
}

/* ── Top nav ── */
.topnav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.topnav-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
}

.topnav-icon {
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}

.topnav-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.topnav-badge {
  font-size: 11px;
  font-weight: 600;
  background: var(--accent-muted);
  color: var(--accent);
  border: 1px solid var(--accent-border);
  border-radius: 999px;
  padding: 2px 8px;
  letter-spacing: 0.02em;
}

/* ── Tab nav ── */
.tab-nav {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0;
}

.tab-btn {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--ink-muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  padding: 8px 14px 10px;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

.tab-btn:hover {
  color: var(--ink);
  background: none;
}

.tab-btn.active {
  border-bottom-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
  background: none;
}

.tab-panel {
  /* visible by default; hidden via .hidden */
}

/* ── Tab header ── */
.tab-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.tab-header h1 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}

.tab-header p {
  color: var(--ink-muted);
  font-size: 13px;
  margin: 0;
}

.tab-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* ── Foreclosure listings ── */
.county-section {
  margin-bottom: 28px;
}

.county-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.county-heading h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.county-heading h2::before {
  content: '';
  display: inline-block;
  width: 3px;
  height: 15px;
  background: var(--accent);
  border-radius: 999px;
}

.count-badge {
  font-size: 11px;
  font-weight: 700;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
  color: var(--ink-muted);
}

.foreclosure-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.foreclosure-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-muted);
  padding: 8px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

.foreclosure-table th:first-child { border-radius: var(--radius-sm) 0 0 0; }
.foreclosure-table th:last-child  { border-radius: 0 var(--radius-sm) 0 0; }

.foreclosure-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
  color: var(--ink);
}

.foreclosure-table tr:last-child td {
  border-bottom: none;
}

.foreclosure-table tr:hover td {
  background: var(--surface-2);
}

.foreclosure-table .addr-cell {
  font-weight: 500;
}

.foreclosure-table .addr-cell a {
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
}

.foreclosure-table .addr-cell a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.foreclosure-table .amount {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.foreclosure-table .muted-cell {
  color: var(--ink-muted);
}

.btn-xs {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  background: var(--accent-muted);
  border: 1px solid var(--accent-border);
  color: var(--accent);
  cursor: pointer;
  transition: background 0.15s;
}

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

/* ── Legal notices ── */
.legal-list {
  display: grid;
  gap: 14px;
}

.legal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 18px;
}

.legal-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.legal-card h2 {
  font-size: 15px;
  font-weight: 650;
  margin-bottom: 3px;
}

.legal-card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.legal-source-link {
  text-decoration: none;
}

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

.legal-facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.legal-facts div {
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 9px 10px;
}

.legal-facts span {
  display: block;
  color: var(--ink-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.07em;
  margin-bottom: 3px;
  text-transform: uppercase;
}

.legal-facts strong {
  color: var(--ink);
  display: block;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
}

.legal-details {
  border-top: 1px solid var(--border-subtle);
  padding-top: 10px;
}

.legal-details + .legal-details {
  margin-top: 10px;
}

.legal-details summary {
  color: var(--accent);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
}

.legal-details p {
  color: var(--ink-muted);
  font-size: 12px;
  margin: 8px 0 0;
}

/* ── Page shell ── */
.shell {
  width: min(1100px, calc(100% - 48px));
  margin: 0 auto;
  padding: 40px 0 80px;
}

/* ── Page header ── */
.page-header {
  margin-bottom: 32px;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
  color: var(--ink);
}

.page-header p {
  color: var(--ink-muted);
  font-size: 13px;
  margin: 0;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}

/* ── Lookup card ── */
.lookup-card {
  margin-bottom: 20px;
}

.lookup-card label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
  margin-bottom: 8px;
}

.lookup-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: stretch;
}

input[type="text"],
textarea,
select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--ink);
  padding: 10px 14px;
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}

input[type="text"]:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-muted);
}

input[type="text"]::placeholder,
textarea::placeholder {
  color: var(--ink-subtle);
}

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2357606a' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 16px;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
  text-decoration: none;
}

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

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

.btn-secondary {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-danger {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--ink-muted);
  font-size: 12px;
  padding: 6px 10px;
}

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

/* Legacy support for old class names in app.js */
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 16px;
  transition: background 0.15s;
  white-space: nowrap;
  background: var(--accent);
  color: #fff;
}

button:hover {
  background: var(--accent-hover);
}

button.secondary {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--ink);
}

button.secondary:hover {
  background: var(--border);
  color: var(--ink);
}

/* ── Message / status ── */
.message {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--ink-muted);
  min-height: 20px;
}

.warning {
  color: var(--warning);
  font-weight: 600;
}

.muted {
  color: var(--ink-muted);
  font-size: 13px;
}

.hidden {
  display: none;
}

/* ── Result card ── */
.result-card {
  margin-bottom: 20px;
}

.result-card h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 8px;
}

.result-card h2::before {
  content: '';
  display: inline-block;
  width: 3px;
  height: 16px;
  background: var(--accent);
  border-radius: 999px;
}

.result-card h3 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-muted);
  margin: 20px 0 10px;
}

/* ── Stat grid ── */
.grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.fact {
  background: var(--bg);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px;
  border-top: 2px solid var(--accent);
}

.fact span {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--ink-muted);
  margin-bottom: 6px;
}

.fact strong, .fact > :last-child {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}

/* ── Research links ── */
.links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

.links a {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
  padding: 6px 12px;
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
}

.links a:hover {
  border-color: var(--accent-border);
  background: var(--accent-muted);
  text-decoration: none;
}

.links a::after {
  content: '↗';
  font-size: 10px;
  opacity: 0.6;
}

/* ── Save panel ── */
.save-panel {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--border-subtle);
  display: grid;
  grid-template-columns: 160px 1fr auto;
  gap: 10px;
  align-items: start;
}

/* ── Saved section ── */
.saved-section {
  margin-top: 40px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-heading h2 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-heading h2::before {
  content: '';
  display: inline-block;
  width: 3px;
  height: 16px;
  background: var(--accent);
  border-radius: 999px;
}

.saved-list {
  display: grid;
  gap: 12px;
}

/* ── Saved property cards ── */
.saved-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  transition: border-color 0.15s;
}

.saved-item:hover {
  border-color: var(--accent-border);
}

.saved-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.saved-top h3 {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--ink);
}

.saved-top .muted {
  font-size: 12px;
  color: var(--ink-muted);
  margin: 0;
}

.saved-top-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.pill {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid;
}

.pill-researching {
  background: #dbeafe;
  color: #1d4ed8;
  border-color: #93c5fd;
}

.pill-drive-by {
  background: #fef9c3;
  color: #92400e;
  border-color: #fde68a;
}

.pill-bid-ready {
  background: #dcfce7;
  color: #15803d;
  border-color: #86efac;
}

.pill-skip {
  background: #fee2e2;
  color: #b91c1c;
  border-color: #fca5a5;
}

.saved-notes {
  font-size: 13px;
  color: var(--ink-muted);
  margin: 0 0 10px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border-left: 2px solid var(--border);
}

.saved-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .shell {
    width: calc(100% - 32px);
    padding: 24px 0 60px;
  }

  .lookup-row,
  .save-panel {
    grid-template-columns: 1fr;
  }

  .grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .legal-card-top {
    flex-direction: column;
  }

  .legal-card-actions {
    flex-wrap: wrap;
  }

  .legal-facts {
    grid-template-columns: repeat(2, 1fr);
  }

  .saved-top {
    flex-direction: column;
  }

  .saved-top-right {
    flex-direction: row-reverse;
    width: 100%;
    justify-content: flex-end;
  }
}

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

  .legal-facts {
    grid-template-columns: 1fr;
  }

  .topnav-badge {
    display: none;
  }
}
