/* ── Segmented control — Transactions/Charts and Nearby sub-tabs ── */
.seg-ctrl {
  display: flex;
  width: max-content;
  min-width: max-content;
  margin: 0 auto;
}
.seg-btn {
  position: relative;
  padding: 5px 8px;
  min-height: 32px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .01em;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 0;
  margin-left: -1px;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
  font-family: inherit;
  -webkit-appearance: none;
  appearance: none;
}
.seg-btn:first-child { margin-left: 0; border-radius: 8px 0 0 8px; }
.seg-btn:last-child  { border-radius: 0 8px 8px 0; }
.seg-btn:only-child  { border-radius: 8px; }
.seg-btn--active { background: var(--accent); border-color: var(--accent); color: #fff; z-index: 1; }
.seg-btn:not(.seg-btn--active):hover { background: var(--chip-active); color: var(--text); z-index: 1; }
#detail-panel-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.detail-panel--txn-scroll #detail-panel-body {
  overflow: hidden;
}

/* Stat tiles — headline numbers. auto-fit so 2 tiles fill 50/50, 3 tiles fill 33/33/33. */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
  gap: 6px;
  margin-bottom: 7px;
}
.stat-tile {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 7px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
}
.stat-num { font-size: 18px; font-weight: 700; color: var(--text); line-height: 1.1; }
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.panel-section-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.chart-reset-btn {
  font-size: 14px;
  line-height: 1;
  padding: 2px 6px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  cursor: pointer;
  flex-shrink: 0;
}
.chart-reset-btn:hover { background: var(--chip-active); color: var(--text); }
.chart-event-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 4px 0 2px;
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.25;
}
.chart-event-toggle {
  min-height: 26px;
  padding: 2px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}
.chart-event-toggle.is-on {
  border-color: var(--accent-soft-border);
  background: var(--accent-soft);
  color: var(--accent-fg);
}
.chart-event-toggle:hover {
  border-color: var(--accent-soft-border);
  color: var(--accent-fg);
}
.panel-subtitle {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
}

#detail-chart-section,
#detail-rent-section {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}
#detail-chart { width: 100%; height: 320px; }

#detail-rent-chart { width: 100%; height: 360px; }

.panel-empty { font-size: 13px; color: var(--text-muted); padding: 8px 0; }

/* ── Transactions tab — sortable table ─────────── */
/* overflow-x lets the table scroll horizontally on narrow panels (mobile bottom-sheet). */
#detail-txn-table-wrap {
  flex: 1;
  min-height: 0;
  display: block;
  overflow-x: auto;
  overflow-y: auto;
  padding: 0 6px 12px;
}
.txn-empty { padding: 24px 16px; color: var(--text-muted); font-size: 14px; margin: 0; }

/* Caption under the price chart when the model-history lines are drawn. */
.chart-model-note {
  margin: 4px 6px 0;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.4;
}

/* Chart-area feedback while the Plotly bundle loads (see chartPlotly). */
.chart-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 180px;
  color: var(--text-dim);
  font-size: 13px;
}
.chart-loading-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: chart-spin .7s linear infinite;
}
@keyframes chart-spin { to { transform: rotate(360deg); } }
#detail-txn-table-wrap .detail-txns-table {
  width: 100%;
  min-width: max-content;
  border-collapse: collapse;
  font-size: 14px;
  color: var(--text);
  table-layout: auto;
  margin-inline: 0;
  border-radius: 10px;
  box-shadow: 0 0 0 1px var(--border);
  background: var(--surface-1);
}
#detail-txn-table-wrap .detail-txns-table thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2);
  color: var(--text-muted); font-weight: 800; font-size: 11px;
  letter-spacing: .035em; text-align: left;
  padding: 10px 8px 9px;
  border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  box-shadow: none;
  white-space: nowrap; user-select: none;
}
#detail-txn-table-wrap .detail-txns-table th[data-col="month"] { width: 88px; }
#detail-txn-table-wrap .detail-txns-table th[data-col="flat"] { width: 52px; }
#detail-txn-table-wrap .detail-txns-table th[data-col="storey"] { width: 56px; }
#detail-txn-table-wrap .detail-txns-table th[data-col="sqft"] { width: 54px; }
#detail-txn-table-wrap .detail-txns-table th[data-col="price"] { width: 88px; }
#detail-txn-table-wrap .detail-txns-table th[data-col="psf"] { width: 58px; }
/* Vertical separators between header cells */
#detail-txn-table-wrap .detail-txns-table th + th { border-left: 1px solid var(--border); }
#detail-txn-table-wrap .detail-txns-table th.sortable { cursor: pointer; }
#detail-txn-table-wrap .detail-txns-table th.sortable:hover { color: var(--text-dim); background: var(--surface-2); }
#detail-txn-table-wrap .detail-txns-table th.sorted { color: var(--accent); }
#detail-txn-table-wrap .detail-txns-table th.sorted::after { content: " ▼"; font-size: 9px; }
#detail-txn-table-wrap .detail-txns-table th.sorted.asc::after { content: " ▲"; }
#detail-txn-table-wrap .detail-txns-table td {
  padding: 8px 4px;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
  line-height: 1.4;
  vertical-align: middle;
  background-clip: padding-box;
  font-variant-numeric: tabular-nums;
  text-align: center;
}
/* Vertical separators between body cells */
#detail-txn-table-wrap .detail-txns-table td + td { border-left: 1px solid var(--border-soft); }
#detail-txn-table-wrap .detail-txns-table tbody tr:nth-child(even) td { background-color: var(--surface-1); }
#detail-txn-table-wrap .detail-txns-table tbody tr:hover td { background-color: var(--surface-2) !important; }

/* Date freshness pill — color encodes recency. Lease shown inline via .txn-lease-line */
.txn-date-pill {
  display: inline-block; font-size: 11px; font-weight: 600;
  padding: 3px 9px; border-radius: 20px; white-space: nowrap; cursor: default;
}
.txn-lease-line {
  display: block; font-size: 10px; color: var(--text-muted);
  text-align: center; margin-top: 2px; cursor: help; white-space: nowrap;
}
.txn-date-old    { background: var(--chip); color: var(--text-muted); }
.txn-date-recent { background: var(--accent-soft); color: var(--accent-fg); }
.txn-date-fresh  { background: rgba(74,222,128,.18); color: #4ade80; }

/* Flat type chips — shared between table and popup/nearby panels */
.ft-chip {
  display: inline-block; font-size: 11px; font-weight: 700;
  padding: 2px 7px; border-radius: 5px; white-space: nowrap; line-height: 1.7;
}
/* Flat code badge — larger primary identifier; flat detail in tooltip */
.txn-code-badge {
  display: inline-block; font-size: 13px; font-weight: 800;
  padding: 2px 7px; border-radius: 5px; letter-spacing: .03em;
  white-space: nowrap; line-height: 1.6; cursor: default;
}
.ft-1    { background: var(--ft-1-bg);    color: var(--ft-1-fg); }
.ft-2    { background: var(--ft-2-bg);    color: var(--ft-2-fg); }
.ft-3    { background: var(--ft-3-bg);    color: var(--ft-3-fg); }
.ft-4    { background: var(--ft-4-bg);    color: var(--ft-4-fg); }
.ft-5    { background: var(--ft-5-bg);    color: var(--ft-5-fg); }
.ft-exec { background: var(--ft-exec-bg); color: var(--ft-exec-fg); }
.ft-multi{ background: var(--ft-multi-bg);color: var(--ft-multi-fg); }
.ft-other{ background: var(--chip); color: var(--text-dim); }

/* Light mode overrides */
:root[data-theme="light"] .popup-market-band {
  background: linear-gradient(180deg, color-mix(in srgb, white 80%, var(--accent-soft) 20%) 0%, color-mix(in srgb, white 72%, var(--surface-2) 28%) 100%);
}
:root[data-theme="light"] .txn-date-fresh  { background: rgba(21,128,61,.12); color: #15803d; }

@media (max-width: 640px) {
  #detail-txn-table-wrap {
    overflow-x: auto;
    padding: 0 6px 10px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  #detail-txn-table-wrap .detail-txns-table {
    font-size: 12px;
  }

  #detail-txn-table-wrap .detail-txns-table thead th {
    font-size: 10px;
    letter-spacing: .02em;
    padding: 8px 4px 7px;
  }

  #detail-txn-table-wrap .detail-txns-table th[data-col="month"] { width: 74px; }
  #detail-txn-table-wrap .detail-txns-table th[data-col="flat"] { width: 42px; }
  #detail-txn-table-wrap .detail-txns-table th[data-col="storey"] { width: 42px; }
  #detail-txn-table-wrap .detail-txns-table th[data-col="sqft"] { width: 44px; }
  #detail-txn-table-wrap .detail-txns-table th[data-col="price"] { width: 76px; }
  #detail-txn-table-wrap .detail-txns-table th[data-col="psf"] { width: 48px; }

  #detail-txn-table-wrap .detail-txns-table td {
    padding-left: 2px;
    padding-right: 2px;
  }

  .txn-date-pill {
    font-size: 10px;
    padding: 2px 7px;
  }

  .txn-lease-line {
    font-size: 9px;
    margin-top: 1px;
  }

  .txn-code-badge {
    font-size: 12px;
    padding: 2px 6px;
    line-height: 1.45;
  }
}
