* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: #1c1c1e;
}

body {
  display: grid;
  grid-template-columns: 320px 1fr;
  grid-template-rows: 60vh 40vh;
  grid-template-areas:
    "sidebar map"
    "sidebar results";
  height: 100vh;
}

#sidebar {
  grid-area: sidebar;
  padding: 16px;
  border-right: 1px solid #e5e5ea;
  overflow-y: auto;
  background: #f9f9fb;
}

#sidebar h1 {
  font-size: 18px;
  margin: 0 0 8px;
}

#sidebar p { margin: 8px 0; font-size: 13px; line-height: 1.4; }
.muted { color: #6b6b70; }
.small { font-size: 11px; margin-top: 24px; }

fieldset {
  border: 1px solid #e5e5ea;
  border-radius: 6px;
  padding: 8px 12px;
  margin: 12px 0;
}
.filters-note {
  display: block;
  margin-top: 8px;
  color: #6b6b70;
  font-size: 11px;
  line-height: 1.3;
}
legend { font-size: 12px; color: #6b6b70; padding: 0 4px; }
fieldset label {
  display: block;
  font-size: 13px;
  padding: 4px 0;
  cursor: pointer;
}

.search-form {
  display: flex;
  gap: 6px;
  margin: 12px 0;
}
.search-form input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  font-size: 13px;
  border: 1px solid #c7c7cc;
  border-radius: 6px;
  background: #fff;
}
.search-form input:focus {
  outline: none;
  border-color: #007aff;
  box-shadow: 0 0 0 3px rgba(0,122,255,0.2);
}
.search-form button {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  background: #007aff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}
.search-form button:hover { background: #0066d6; }
.search-form button:disabled { opacity: 0.5; cursor: not-allowed; }

.status {
  min-height: 40px;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid #e5e5ea;
  border-radius: 6px;
  font-size: 13px;
  margin: 12px 0;
}
.status.error { color: #c0392b; border-color: #f1c9c4; background: #fdecea; }
.status.done  { color: #1f7a3a; border-color: #c6e7d1; background: #e9f7ee; }

.actions { display: flex; gap: 8px; margin: 12px 0; }
.actions button {
  flex: 1;
  padding: 8px 10px;
  font-size: 13px;
  border: 1px solid #c7c7cc;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}
.actions button:disabled { opacity: 0.4; cursor: not-allowed; }
.actions button:not(:disabled):hover { background: #f1f1f3; }

#map { grid-area: map; }

#results {
  grid-area: results;
  overflow: auto;
  border-top: 1px solid #e5e5ea;
  background: #fff;
}

#results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
#results-table th, #results-table td {
  padding: 6px 8px;
  border-bottom: 1px solid #eee;
  text-align: left;
  white-space: nowrap;
}
#results-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f9f9fb;
  border-bottom: 1px solid #d1d1d6;
  box-shadow: 0 1px 0 #d1d1d6;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  color: #1c1c1e;
}
#results-table thead th.sort-asc::after  { content: " ▲"; color: #6b6b70; }
#results-table thead th.sort-desc::after { content: " ▼"; color: #6b6b70; }
#results-table tbody tr { cursor: pointer; }
#results-table tbody tr:hover { background: #f6f6f8; }
#results-table tbody tr.pinned { background: #fff6e5; }
#results-table tbody tr.pinned:hover { background: #ffeccc; }
#results-table td .cell-sub { color: #6b6b70; font-size: 11px; }
#results-table td.status-oos { color: #b34a00; font-weight: 600; }
#results-table td.status-in  { color: #6b6b70; }
#results-table td.source-county { color: #0a7f5f; font-weight: 600; }
#results-table td.source-fallback { color: #6b6b70; }
#results-table td a { color: #007aff; text-decoration: none; }
#results-table td a:hover { text-decoration: underline; }

#pins-section {
  margin-top: 16px;
  border-top: 1px solid #e5e5ea;
  padding-top: 12px;
}

.tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 8px;
  border-bottom: 1px solid #e5e5ea;
}
.tab {
  flex: 1;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 600;
  color: #6b6b70;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  margin-bottom: -1px;
}
.tab:hover { color: #1c1c1e; }
.tab.active {
  color: #007aff;
  border-bottom-color: #007aff;
}
.tab-count {
  background: #e5e5ea;
  color: #1c1c1e;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 600;
  min-width: 16px;
  text-align: center;
}
.tab.active .tab-count {
  background: #007aff;
  color: #fff;
}

.pin-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 320px;
  overflow-y: auto;
}
.pin-list.hidden { display: none; }
.pin-list .pins-empty {
  font-size: 12px;
  color: #8e8e93;
  font-style: italic;
  padding: 8px 0;
}
.pin-list li.pin-item {
  padding: 8px;
  border: 1px solid #e5e5ea;
  border-radius: 6px;
  margin-bottom: 6px;
  background: #fff;
  font-size: 12px;
}
.pin-list li.pin-item:hover { background: #f6f6f8; border-color: #d1d1d6; }
.pin-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 6px;
  cursor: pointer;
}
.pin-item .pin-info { flex: 1; min-width: 0; }
.pin-item .pin-addr {
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.pin-item .pin-addr-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pin-item .pin-sub {
  color: #6b6b70;
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pin-item .pin-remove {
  background: transparent;
  border: none;
  color: #8e8e93;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  flex-shrink: 0;
}
.pin-item .pin-remove:hover { color: #c0392b; }

.pin-action-row {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}
.pin-action {
  flex: 1;
  padding: 4px 6px;
  font-size: 11px;
  border: 1px solid #c7c7cc;
  border-radius: 4px;
  background: #fff;
  color: #1c1c1e;
  cursor: pointer;
}
.pin-action:hover { background: #f1f1f3; border-color: #a1a1a6; }

.pin-notes { margin-top: 6px; }
.pin-notes.hidden { display: none; }
.pin-notes-editor {
  width: 100%;
  min-height: 56px;
  padding: 6px 8px;
  font-size: 12px;
  font-family: inherit;
  color: #1c1c1e;
  border: 1px solid #c7c7cc;
  border-radius: 4px;
  background: #fdfdff;
  resize: vertical;
}
.pin-notes-editor:focus {
  outline: none;
  border-color: #007aff;
  box-shadow: 0 0 0 2px rgba(0,122,255,0.2);
}

.status-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  flex-shrink: 0;
}
.status-badge.pinned { background: #e5e5ea; color: #1c1c1e; }
.status-badge.reached { background: #d4efdd; color: #1f7a3a; }

.parcel-marker {
  background: transparent;
  border: none;
}
.parcel-marker .parcel-marker-pin {
  display: block;
  width: 20px;
  height: 20px;
  border-radius: 50% 50% 50% 0;
  border: 2px solid #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
  transform: rotate(-45deg);
  margin: 2px 0 0 2px;
}
.parcel-marker-pinned  .parcel-marker-pin { background: #007aff; }
.parcel-marker-reached .parcel-marker-pin { background: #1f7a3a; }

.parcel-popup h3 { margin: 0 0 6px; font-size: 13px; }
.parcel-popup dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 8px;
  font-size: 12px;
}
.parcel-popup dt { color: #6b6b70; }
.parcel-popup dd { margin: 0; }
.parcel-popup .popup-link { margin: 8px 0 0; font-size: 12px; }
.parcel-popup .popup-link a { color: #007aff; text-decoration: none; }
.parcel-popup .popup-link a:hover { text-decoration: underline; }
.parcel-popup .popup-remove {
  margin-top: 8px;
  padding: 4px 10px;
  font-size: 11px;
  border: 1px solid #c0392b;
  background: #fff;
  color: #c0392b;
  border-radius: 4px;
  cursor: pointer;
}
.parcel-popup .popup-remove:hover { background: #c0392b; color: #fff; }

#auth-gate {
  position: fixed;
  inset: 0;
  background: rgba(20, 20, 30, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  backdrop-filter: blur(4px);
}
#auth-gate.hidden { display: none; }
#auth-form {
  background: #fff;
  padding: 28px 32px;
  border-radius: 12px;
  width: 320px;
  box-shadow: 0 12px 32px rgba(0,0,0,0.3);
}
#auth-form h2 {
  margin: 0 0 4px;
  font-size: 20px;
}
#auth-form p {
  margin: 0 0 16px;
  font-size: 13px;
  color: #6b6b70;
}
#auth-form input {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  border: 1px solid #c7c7cc;
  border-radius: 6px;
  margin-bottom: 12px;
}
#auth-form input:focus {
  outline: none;
  border-color: #007aff;
  box-shadow: 0 0 0 3px rgba(0,122,255,0.2);
}
#auth-form button {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: #007aff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}
#auth-form button:hover { background: #0066d6; }
#auth-form .hidden { display: none; }
#auth-error {
  color: #c0392b;
  font-size: 13px;
  margin: 10px 0 0;
}

.user-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 10px;
  border-bottom: 1px solid #e5e5ea;
  margin-bottom: 12px;
  font-size: 12px;
}
.user-bar span {
  color: #6b6b70;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-bar button {
  padding: 4px 8px;
  font-size: 11px;
  border: 1px solid #c7c7cc;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  flex-shrink: 0;
}
.user-bar button:hover { background: #f1f1f3; }
