:root {
  color-scheme: dark;
  --ink: #f2f4f7;
  --muted: #a5acb8;
  --line: #313641;
  --panel: #171a20;
  --soft: #0d0f13;
  --field: #12151b;
  --mint: #8e96a3;
  --mint-dark: #d5d9df;
  --coral: #7fa36b;
  --amber: #b5c7a3;
  --sky: #9aa2ae;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.32);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Dirham-Sans", sans-serif;
}

@font-face {
  font-family: "Dirham-Sans";
  src: url("assets/dirham-sans.woff2") format("woff2");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  unicode-range: U+20C3;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--soft);
}

a {
  color: var(--mint-dark);
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 34px clamp(18px, 4vw, 56px) 22px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--coral);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(1.45rem, 4vw, 4rem);
  line-height: 0.98;
  letter-spacing: 0;
  white-space: nowrap;
}

h2 {
  margin-bottom: 8px;
  font-size: 1.05rem;
}

main {
  width: 100%;
  margin: 0;
  padding: 0 clamp(12px, 2vw, 28px);
}

.source-pill {
  flex: 0 0 auto;
  padding: 10px 14px;
  border: 1px solid rgba(127, 163, 107, 0.28);
  border-radius: 999px;
  background: rgba(23, 26, 32, 0.9);
  color: #b5c7a3;
  font-size: 0.85rem;
  font-weight: 800;
  text-align: center;
}

.control-band,
.panel,
.kpis article {
  background: rgba(23, 26, 32, 0.95);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.control-band {
  display: block;
  padding: 22px;
  border-radius: 8px;
}

.panel-head p,
footer {
  color: var(--muted);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 14px;
}

.controls > label,
.controls > fieldset,
.controls > button {
  flex: 0 0 auto;
  max-width: 100%;
}

.controls > button {
  width: 10rem;
  padding: 0 16px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

input,
select,
button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
}

input,
select {
  width: 100%;
  min-width: 10rem;
  padding: 0 12px;
  background: var(--field);
  color: var(--ink);
}

#textSearch {
  min-width: 16rem;
}

input[type="date"] {
  color-scheme: dark;
}

.toggle-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 8px;
  max-width: 100%;
  overflow-x: auto;
}

.toggle-row.two {
  display: flex;
}

.toggle {
  width: auto;
  min-width: max-content;
  min-height: 44px;
  padding: 0 10px;
  background: var(--field);
  color: var(--muted);
  white-space: nowrap;
}

.toggle.active {
  border-color: var(--coral);
  background: rgba(127, 163, 107, 0.12);
  color: #b5c7a3;
}

button {
  align-self: end;
  cursor: pointer;
  font-weight: 900;
}

.primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--field);
  color: var(--mint-dark);
}

.secondary {
  background: var(--field);
  color: var(--mint-dark);
}

.control-band label,
.control-band legend,
.control-band button {
  font-weight: 400;
}

code {
  color: var(--mint-dark);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin: 18px 0;
}

.kpis article {
  min-height: 112px;
  padding: 18px;
  border-radius: 8px;
}

.kpis article > span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.kpis strong {
  display: block;
  margin-top: 14px;
  font-size: clamp(1.35rem, 3vw, 2rem);
  letter-spacing: 0;
}

.money {
  display: inline-flex;
  align-items: center;
  gap: 0.18em;
  line-height: 1;
  white-space: nowrap;
}

.dirham-mark {
  width: auto;
  height: 1em;
  flex: 0 0 auto;
  fill: currentColor;
  transform: translateY(0.03em);
}

.kpis .dirham-mark {
  height: 0.82em;
  transform: translateY(0.04em);
}

.spinner {
  display: inline-block;
  width: 1.05em;
  height: 1.05em;
  border: 3px solid rgba(213, 217, 223, 0.16);
  border-top-color: var(--coral);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
  vertical-align: -0.14em;
}

.button-spinner {
  width: 0.9em;
  height: 0.9em;
  border-width: 2px;
  vertical-align: 0;
}

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

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(0, 0.7fr);
  gap: 18px;
  align-items: start;
}

.panel {
  border-radius: 8px;
  overflow: visible;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.panel-head p {
  margin-bottom: 0;
  white-space: nowrap;
}

.table-wrap {
  overflow-x: visible;
}

.pagination {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  min-width: max-content;
  padding: 0;
  border-bottom: 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.pagination:empty {
  display: none;
}

.pagination button {
  display: inline-grid;
  place-items: center;
  width: 34px;
  min-height: 32px;
  padding: 0;
  background: var(--field);
  color: var(--mint-dark);
}

.pagination-summary {
  display: inline-block;
  width: 15ch;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.pagination-icon svg {
  width: 17px;
  height: 17px;
  fill: currentColor;
}

.pagination button:disabled {
  cursor: default;
  opacity: 0.45;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.sort-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: auto;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  text-transform: uppercase;
}

.sort-button::after {
  content: "";
  width: 0.45rem;
}

.sort-button.active.asc::after {
  content: "↑";
}

.sort-button.active.desc::after {
  content: "↓";
}

.sort-button:hover,
.sort-button:focus {
  color: #b5c7a3;
  outline: 0;
}

td {
  font-size: 0.92rem;
}

.record-row {
  cursor: pointer;
}

.record-row:hover,
.record-row:focus {
  background: rgba(127, 163, 107, 0.07);
  outline: 0;
}

td[data-label="Date"] {
  white-space: nowrap;
}

td[data-label="#"] {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

td[data-label="Price"],
td[data-label="Sqft"],
td[data-label="Price/sqft"] {
  white-space: nowrap;
}

.area-size {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 5px 8px;
  border-radius: 999px;
  color: #fff;
  font-size: 0.78rem;
}

.tag.sale {
  background: #080;
}

.tag.rent {
  background: #00A;
}

.area-list {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.insights {
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 24px);
  overflow: auto;
}

.raw-detail {
  display: grid;
  gap: 8px;
}

.compact {
  width: auto;
  min-height: 36px;
  justify-self: start;
  padding: 0 12px;
}

.raw-detail h3 {
  margin: 4px 0 0;
  font-size: 0.95rem;
}

.raw-list {
  display: grid;
  grid-template-columns: minmax(0, 0.45fr) minmax(0, 1fr);
  gap: 0;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--field);
}

.raw-list dt,
.raw-list dd {
  min-width: 0;
  margin: 0;
  padding: 3px 8px;
  border-bottom: 1px solid var(--line);
  font-size: 0.76rem;
  line-height: 1.18;
  overflow-wrap: anywhere;
}

.raw-list dt {
  background: var(--soft);
  color: var(--muted);
  font-weight: 900;
}

.raw-list dd {
  color: var(--ink);
}

.raw-list dt:last-of-type,
.raw-list dd:last-of-type {
  border-bottom: 0;
}

.empty-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.area-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  cursor: pointer;
  transition: border-color 140ms ease, transform 140ms ease;
}

.area-item:hover,
.area-item:focus {
  border-color: var(--coral);
  outline: 0;
  transform: translateY(-1px);
}

.area-item.selected {
  border-color: var(--coral);
  background: rgba(127, 163, 107, 0.08);
}

.area-item strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.area-item span {
  color: var(--muted);
  font-size: 0.84rem;
}

.bar {
  grid-column: 1 / -1;
  height: 7px;
  border-radius: 999px;
  background: #252932;
  overflow: hidden;
}

.bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--mint), var(--coral));
}

footer {
  width: 100%;
  margin: 34px 0;
  padding: 0 clamp(12px, 2vw, 28px);
  font-size: 0.9rem;
}

footer nav {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
}

@media (max-width: 900px) {
  .topbar,
  .control-band,
  .split {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
    align-items: start;
  }

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

  .insights {
    position: static;
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 620px) {
  main,
  footer {
    width: 100%;
  }

  .topbar {
    padding: 24px 12px 16px;
  }

  .controls,
  .kpis {
    grid-template-columns: 1fr;
  }

  .control-band {
    padding: 16px;
  }

  .panel-head {
    display: grid;
    gap: 4px;
  }

  .panel-head p {
    white-space: normal;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 12px;
    padding: 12px;
  }

  tr {
    display: grid;
    gap: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--field);
    overflow: hidden;
  }

  td {
    display: grid;
    grid-template-columns: 88px minmax(0, 1fr);
    gap: 12px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    overflow-wrap: anywhere;
  }

  td:last-child {
    border-bottom: 0;
  }

  td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 900;
    text-transform: uppercase;
  }
}
