/* HDB resale prices — page styles (no framework).
   Look: HDB estate signage. Block numbers sit on painted plates, prices use
   bold tabular figures; everything else stays quiet. */

@font-face {
  font-family: "Overpass";
  src: url("../fonts/overpass-latin-var.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #eef3f0; /* void-deck grey-green */
  --surface: #ffffff;
  --ink: #17312b; /* deep estate green */
  --muted: #5e716b;
  --line: #cfdad5;
  --line-strong: #a9bbb4;
  --accent: #1f6f5b; /* corridor green */
  --accent-dark: #185a4a;
  --accent-soft: #e3f1ec;
  --focus: #f2b705; /* signage yellow */
  --warn-ink: #7a5000;
  --warn-soft: #fff4d1;
  --error-ink: #a1261b;
  --error-soft: #fcebe8;

  --font: "Overpass", system-ui, "Segoe UI", Roboto, sans-serif;
  --step--1: 0.8125rem; /* 13px */
  --step-0: 1rem; /* 16px */
  --step-1: 1.3125rem; /* 21px */
  --step-2: 1.75rem; /* 28px */
  --step-3: 2.5rem; /* 40px */

  --radius-s: 4px;
  --radius-m: 8px;
  --gap: 1.25rem;
}

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

/* Toggled by app.js everywhere; must beat any display rule */
.hidden {
  display: none !important;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--step-0);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

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

button,
input {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -3rem;
  background: var(--ink);
  color: #fff;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-s);
  z-index: 100;
}
.skip-link:focus {
  top: 1rem;
}

.wrap {
  max-width: 72rem;
  margin: 0 auto;
  padding: 0 1rem;
}

/* ---- Masthead --------------------------------------------------------- */

.masthead {
  padding: 2.5rem 0 1.5rem;
}
.masthead h1 {
  margin: 0;
  font-size: var(--step-3);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -0.02em;
}
.lede {
  margin: 0.75rem 0 0;
  max-width: 38rem;
  color: var(--muted);
}

/* ---- Search form ------------------------------------------------------ */

.search {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
  padding: 1.5rem;
}

.fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap) 1.5rem;
}
.field--wide {
  grid-column: 1 / -1;
}

.field-head {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.375rem;
}
.field-head label,
.field-head .label {
  font-weight: 700;
}
.field-note {
  font-size: var(--step--1);
  color: var(--muted);
}
.field-head .link-btn {
  margin-left: auto;
}

.link-btn {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font-size: var(--step--1);
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.link-btn:hover {
  color: var(--accent-dark);
}

.text-input {
  width: 100%;
  min-height: 2.75rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-s);
}
.text-input::placeholder {
  color: #8a9a95;
}
.text-input:focus {
  border-color: var(--accent);
}

.input-row {
  display: flex;
}
.input-row .text-input {
  border-radius: var(--radius-s) 0 0 var(--radius-s);
}
.input-row .btn {
  border-radius: 0 var(--radius-s) var(--radius-s) 0;
}

.combo {
  position: relative;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.75rem;
  padding: 0.5rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-s);
  font-weight: 700;
  cursor: pointer;
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn--primary {
  background: var(--accent);
  color: #fff;
}
.btn--primary:hover:not(:disabled) {
  background: var(--accent-dark);
}
.btn--secondary {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--ink);
}
.btn--secondary:hover:not(:disabled) {
  border-color: var(--ink);
}
.btn--add {
  background: var(--ink);
  color: #fff;
}
.btn--add:hover {
  background: #0f231e;
}

.actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 1.5rem;
}
.actions .btn--primary {
  min-width: 12rem;
  font-size: 1.0625rem;
}

/* Tags (picked towns, blocks, streets, multiselect values) */
.tag-list,
.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}
.tag-list {
  margin-top: 0.5rem;
}
.tag-list:empty {
  display: none;
}
/* Tag lists placed above their input (towns, street): the suggestion list opens
   below the input, so the tags can never be covered while it is open. */
.tag-list--above {
  margin-top: 0;
  margin-bottom: 0.5rem;
}
.selected-tag {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.1875rem 0.25rem 0.1875rem 0.625rem;
  background: var(--accent-soft);
  color: var(--ink);
  border-radius: 999px;
  font-size: var(--step--1);
  font-weight: 600;
}
.multiselect-box .selected-tag {
  padding-right: 0.625rem;
}
.selected-tag button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.375rem;
  height: 1.375rem;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}
.selected-tag button:hover {
  background: #cfe5dc;
  color: var(--ink);
}

/* Multiselect (Months, Flat types) — built by app.js */
.multiselect-container {
  position: relative;
}
.multiselect-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  min-height: 2.75rem;
  padding: 0.375rem 0.75rem;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-s);
  cursor: pointer;
}
.multiselect-box[aria-expanded="true"] {
  border-color: var(--accent);
}
.multiselect-box .placeholder {
  color: #8a9a95;
}
.chevron {
  flex-shrink: 0;
  width: 0.5rem;
  height: 0.5rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-2px) rotate(45deg);
}

.multiselect-dropdown,
.suggestions-container {
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  margin-top: 0.25rem;
  max-height: 16rem;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-s);
  box-shadow: 0 10px 24px rgba(23, 49, 43, 0.14);
  display: none; /* opened by app.js via style.display */
}
.multiselect-option,
.suggestion-item {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
}
.multiselect-option:hover,
.suggestion-item:hover,
.suggestion-item.active {
  background: var(--accent-soft);
}
.multiselect-option.selected {
  font-weight: 700;
}
.option-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.option-row input {
  accent-color: var(--accent);
}
.suggest-empty {
  padding: 0.5rem 0.75rem;
  color: var(--muted);
  font-size: var(--step--1);
}

/* ---- Notices ---------------------------------------------------------- */

.notice {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-s);
  border-left: 4px solid currentColor;
}
.notice--ok {
  background: var(--accent-soft);
  color: var(--accent-dark);
}
.notice--error {
  background: var(--error-soft);
  color: var(--error-ink);
}
.notice--warn {
  background: var(--warn-soft);
  color: var(--warn-ink);
}
.search .notice {
  margin-bottom: 1.25rem;
}
.feedback {
  margin-top: 1rem;
}

/* ---- Save or load panel ----------------------------------------------- */

.panel {
  margin-top: 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
}
.panel > summary {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.875rem 1.5rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.panel > summary::-webkit-details-marker {
  display: none;
}
.panel-title {
  font-weight: 700;
}
.panel-sub {
  color: var(--muted);
  font-size: var(--step--1);
}
.panel-status {
  margin-left: auto;
  flex-shrink: 0;
  padding: 0.125rem 0.625rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: var(--step--1);
  color: var(--muted);
}
.panel .chevron {
  transition: transform 0.15s;
}
.panel[open] .chevron {
  transform: translateY(2px) rotate(225deg);
}
.panel-body {
  border-top: 1px solid var(--line);
  padding: 1.25rem 1.5rem 1.5rem;
}
.panel-intro {
  margin: 0 0 1.25rem;
  max-width: 44rem;
  color: var(--muted);
  font-size: 0.9375rem;
}
.panel-intro strong {
  color: var(--ink);
}
.panel-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
}
.panel-grid section + section {
  border-left: 1px solid var(--line);
  padding-left: 1.5rem;
}
.panel-grid h3 {
  margin: 0 0 0.375rem;
  font-size: var(--step-0);
}
.panel-help {
  margin: 0 0 0.875rem;
  color: var(--muted);
  font-size: 0.9375rem;
}
.small {
  font-size: var(--step--1);
  color: var(--muted);
}
.file-input {
  display: block;
  width: 100%;
  margin-bottom: 0.625rem;
  font-size: var(--step--1);
}
.import-message {
  margin: 0.625rem 0 0;
  font-size: var(--step--1);
}
.import-message.is-ok {
  color: var(--accent-dark);
}
.import-message.is-error {
  color: var(--error-ink);
}
.check {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  font-weight: 600;
  cursor: pointer;
}
.check input {
  margin-top: 0.25rem;
  accent-color: var(--accent);
}
.status-ok {
  color: var(--accent-dark);
  font-weight: 700;
}
.status-none {
  color: var(--muted);
  font-weight: 700;
}

/* ---- Results ---------------------------------------------------------- */

.loading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 2rem 0;
  color: var(--muted);
}
.spinner {
  width: 1.5rem;
  height: 1.5rem;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.status-area {
  margin-top: 1.5rem;
}

.results {
  margin-top: 2rem;
}
.results-bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
}
.results-bar h2 {
  margin: 0;
  font-size: var(--step-2);
  font-weight: 800;
  letter-spacing: -0.01em;
}

.table-wrap {
  max-height: 75vh;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-m);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
th,
td {
  padding: 0.625rem 0.875rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--ink);
  color: #fff;
  font-size: var(--step--1);
  font-weight: 700;
  white-space: nowrap;
  vertical-align: bottom;
}
th[data-sort] {
  cursor: pointer;
}
th[data-sort]:hover {
  background: #22453c;
}
th .sort-indicator {
  color: var(--focus);
}
tbody tr:hover {
  background: #f5f9f7;
}
tbody tr:last-child td {
  border-bottom: 0;
}
.nowrap {
  white-space: nowrap;
}
.num,
.price,
th.num {
  text-align: right;
}
.price {
  font-weight: 800;
  white-space: nowrap;
}

/* Block number on a painted plate, like on an HDB block */
.plate {
  display: inline-block;
  min-width: 3.25rem;
  padding: 0.125rem 0.5rem 0;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-s);
  font-weight: 800;
  text-align: center;
  letter-spacing: 0.02em;
}

.empty {
  margin-top: 2rem;
  padding: 2rem 1.5rem;
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-m);
}
.empty p {
  margin: 0;
}
.empty p + p {
  margin-top: 0.25rem;
  color: var(--muted);
}

/* ---- About the data --------------------------------------------------- */

.notes {
  margin: 3rem 0 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--line-strong);
  color: var(--muted);
  font-size: 0.9375rem;
}
.notes h2 {
  margin: 0 0 0.75rem;
  color: var(--ink);
  font-size: var(--step-1);
}
.notes ul {
  margin: 0;
  padding-left: 1.25rem;
  max-width: 48rem;
}
.notes li + li {
  margin-top: 0.375rem;
}

/* ---- Export dialog ---------------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(23, 49, 43, 0.55);
}
.modal-box {
  width: 100%;
  max-width: 28rem;
  padding: 1.5rem;
  background: var(--surface);
  border-radius: var(--radius-m);
}
.modal-box h2 {
  margin: 0 0 0.5rem;
  font-size: var(--step-1);
}
.modal-box fieldset {
  margin: 1.25rem 0;
  padding: 0;
  border: 0;
}
.modal-box legend {
  margin-bottom: 0.375rem;
  font-weight: 700;
}
.modal-box .check {
  font-weight: 400;
  margin-bottom: 0.375rem;
}
.modal-box label[for="export-filename"] {
  display: block;
  margin-bottom: 0.375rem;
  font-weight: 700;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

/* ---- Small screens ---------------------------------------------------- */

@media (max-width: 720px) {
  .masthead {
    padding-top: 1.75rem;
  }
  .masthead h1 {
    font-size: var(--step-2);
  }
  .search {
    padding: 1.125rem;
  }
  .fields {
    grid-template-columns: 1fr;
  }
  .actions .btn--primary {
    width: 100%;
  }
  .panel > summary {
    padding: 0.875rem 1.125rem;
    flex-wrap: wrap;
  }
  .panel-body {
    padding: 1.125rem;
  }
  .panel-grid {
    grid-template-columns: 1fr;
  }
  .panel-grid section + section {
    border-left: 0;
    padding-left: 0;
    border-top: 1px solid var(--line);
    padding-top: 1.25rem;
  }
  .results-bar {
    flex-direction: column;
    gap: 0.25rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation: none;
  }
  .panel .chevron {
    transition: none;
  }
}
