:root {
  color-scheme: light;
  --bg: #f5f6f4;
  --panel: #ffffff;
  --text: #1d2320;
  --muted: #65706b;
  --line: #d9ded9;
  --accent: #176b55;
  --accent-dark: #0e4638;
  --danger: #a53030;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-weight: 800; color: var(--text); }
nav { display: flex; gap: 16px; }
.page {
  width: min(100%, 1440px);
  margin: 0 auto;
  padding: 24px;
  overflow-x: clip;
}
.toolbar, .detail-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 18px;
}
h1 { margin: 0 0 6px; font-size: 28px; }
h2 { margin: 18px 0 10px; font-size: 17px; }
p { line-height: 1.45; }
.muted { color: var(--muted); }
.filters {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 140px 150px 130px repeat(3, max-content) 80px;
  gap: 8px;
  align-items: end;
  min-width: min(100%, 1060px);
}
.filter-field {
  min-width: 0;
  gap: 4px;
}
.filter-field span {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}
.filter-field.wide { min-width: 220px; }
.filter-field.compact input { min-width: 0; }
.favorite-filter {
  min-height: 40px;
  padding-bottom: 1px;
}
input, select, textarea, button {
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  background: #fff;
  color: var(--text);
}
textarea { min-height: 100px; resize: vertical; }
button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}
button:hover { background: var(--accent-dark); }
button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}
button.danger { background: var(--danger); border-color: var(--danger); margin-top: 16px; }
.inline { display: flex; gap: 8px; align-items: center; white-space: nowrap; }
.inline input { width: auto; }
.source-strip, .form-panel, .table-wrap, .stats > div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.source-strip {
  padding: 12px 14px;
  margin-bottom: 16px;
  display: grid;
  gap: 6px;
  font-size: 14px;
  max-width: 100%;
  overflow: hidden;
}
.source-strip div {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 6px;
  min-width: 0;
}
.source-strip a {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 1060px; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; color: var(--muted); background: #fbfbfa; }
.sort-button {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 800;
  text-transform: inherit;
}
.sort-button:hover {
  background: transparent;
  color: var(--accent);
  text-decoration: underline;
}
.sort-button::after {
  content: "sort";
  color: var(--muted);
  font-size: 11px;
  text-transform: none;
}
.sort-button[data-direction="asc"]::after { content: "up"; }
.sort-button[data-direction="desc"]::after { content: "down"; }
.apt-link { font-weight: 800; color: var(--text); }
.apt-expand-button {
  appearance: none;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-weight: 800;
  text-align: left;
}
.apt-expand-button:hover {
  background: transparent;
  color: var(--accent);
  text-decoration: underline;
}
.listing-main-row { cursor: pointer; }
.listing-main-row:hover { background: #fbfbfa; }
.listing-main-row.expanded {
  background: #eef5f1;
}
.listing-detail-row > td {
  padding: 0;
  background: #fff;
}
.inline-detail {
  border-left: 4px solid var(--accent);
  padding: 18px;
  display: grid;
  gap: 16px;
}
.detail-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.detail-summary-grid.two-panel {
  grid-template-columns: minmax(0, 1fr) minmax(360px, 520px);
}
.detail-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
  min-width: 0;
}
.detail-card h2 {
  margin-top: 0;
}
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.section-head form {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}
.section-head h2 {
  margin: 0;
}
.detail-card h3 {
  margin: 14px 0 6px;
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
}
.diagnostic-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px dashed var(--line);
  font-size: 14px;
}
.diagnostic-row span { color: var(--muted); }
.diagnostic-row strong {
  text-align: right;
  overflow-wrap: anywhere;
}
.inline-edit-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.inline-edit-form h2,
.inline-edit-form .full,
.inline-edit-form .detail-actions {
  grid-column: 1 / -1;
}
.inline-upload {
  display: grid;
  grid-template-columns: minmax(0, 1fr) max-content;
  gap: 8px;
  margin-bottom: 10px;
}
.detail-actions {
  display: flex;
  justify-content: flex-start;
}
.delete-inline-form {
  display: flex;
  justify-content: flex-end;
}
.acris-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.financial-signal-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0;
}
.detail-financials {
  grid-template-columns: 1fr;
}
.signal-metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfbfa;
  min-width: 0;
}
.signal-metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  margin-bottom: 4px;
}
.signal-metric strong {
  overflow-wrap: anywhere;
}
.signal-metric em {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
  text-transform: uppercase;
}
.signal-list {
  display: grid;
  gap: 8px;
  margin: 12px 0;
}
.opportunity {
  border-left: 4px solid var(--line);
  background: #fbfbfa;
  padding: 10px 12px;
}
.opportunity strong,
.opportunity span {
  display: block;
}
.opportunity span {
  color: var(--muted);
  margin-top: 3px;
}
.opportunity.strong { border-left-color: var(--accent); }
.opportunity.medium { border-left-color: #96722c; }
.opportunity.neutral { border-left-color: var(--muted); }
.warning-note {
  border-left: 4px solid #96722c;
  padding: 10px 12px;
  background: #fff9ea;
  color: #58471e;
}
.compact-check {
  min-height: 0;
  padding: 0;
  font-size: 12px;
}
.financial-review-form {
  margin: 14px 0;
}
.mini-table {
  min-width: 0;
  font-size: 13px;
}
.mini-table th,
.mini-table td {
  padding: 8px;
}
.mini-table td {
  overflow-wrap: anywhere;
}
.clipped { max-width: 420px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.links { white-space: nowrap; }
.links a, .link-list a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 30px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-right: 4px;
  background: #fff;
}
.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
}
.login-panel {
  width: min(380px, calc(100vw - 32px));
  padding: 28px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.login-panel form, .grid-form { display: grid; gap: 12px; }
label { display: grid; gap: 6px; font-weight: 700; font-size: 13px; }
.error { color: var(--danger); font-weight: 700; }
.form-panel { padding: 18px; }
.grid-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.grid-form .full, .grid-form h2 { grid-column: 1 / -1; }
.two-col {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 18px;
  align-items: start;
}
.stats { display: flex; gap: 10px; }
.stats > div { padding: 12px 14px; min-width: 150px; }
.stats span { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; }
.stats strong { font-size: 20px; }
.link-list { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.floorplan-row { border-top: 1px solid var(--line); padding: 10px 0; }
.source-form {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr) 110px 70px;
  gap: 10px;
  align-items: center;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.import-form {
  display: grid;
  grid-template-columns: 150px 100px 90px max-content max-content 80px;
  gap: 8px;
  align-items: end;
  min-width: min(100%, 760px);
}
.import-form span {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}
.import-check {
  min-height: 40px;
  padding-bottom: 1px;
}
.compact-table {
  min-width: 0;
  font-size: 14px;
}
.compact-table th,
.compact-table td {
  padding: 9px 8px;
}
.imports-layout {
  grid-template-columns: minmax(0, 1fr) 320px;
  margin-bottom: 18px;
}
.import-results {
  overflow-x: auto;
}

@media (max-width: 900px) {
  .toolbar, .detail-head, .topbar { flex-direction: column; align-items: stretch; }
  .filters, .grid-form, .two-col, .source-form, .import-form { grid-template-columns: 1fr; }
  .detail-summary-grid,
  .detail-summary-grid.two-panel,
  .inline-edit-form,
  .inline-upload,
  .acris-grid,
  .financial-signal-grid {
    grid-template-columns: 1fr;
  }
  .section-head { align-items: stretch; flex-direction: column; }
  .stats { flex-direction: column; }
  nav { flex-wrap: wrap; }
}

/* AI Floorplan Calibration Styles */
.calibration-strip {
  margin-bottom: 20px;
}
.calibration-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.calibration-header {
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
  margin-bottom: 12px;
}
.calibration-badge {
  background: #eef5f1;
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}
.calibration-header strong {
  font-size: 15px;
  color: var(--text);
}
.calibration-body {
  display: grid;
  grid-template-columns: repeat(4, max-content) 1fr;
  gap: 24px;
  align-items: center;
}
.calibration-metric {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.calibration-metric span {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 600;
}
.calibration-metric strong {
  font-size: 18px;
  color: var(--accent-dark);
}
.calibration-desc {
  font-size: 13px;
  line-height: 1.4;
  color: var(--text);
  border-left: 2px solid var(--line);
  padding-left: 14px;
}
.muted-note {
  font-size: 11px;
  color: var(--muted);
  display: inline-block;
  margin-top: 4px;
}
.calibrated-sqft {
  border-bottom: 1px dashed var(--accent);
  cursor: help;
  color: var(--accent);
  font-weight: 700;
}
@media (max-width: 900px) {
  .calibration-body {
    grid-template-columns: 1fr;
    gap: 16px;
    align-items: stretch;
  }
  .calibration-desc {
    border-left: 0;
    border-top: 1px solid var(--line);
    padding-left: 0;
    padding-top: 12px;
  }
}
