:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --accent: #38bdf8;
  --green: #4ade80;
  --red: #f87171;
  --amber: #fbbf24;
  --border: #334155;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }

/* --- Login --- */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
#login-form {
  background: var(--surface);
  padding: 32px;
  border-radius: 12px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  border: 1px solid var(--border);
}
#login-form h1 { font-size: 18px; margin: 0 0 8px; }
#login-form input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 14px;
}
#login-form button {
  background: var(--accent);
  color: #0f172a;
  border: none;
  padding: 10px;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
}
.error { color: var(--red); font-size: 13px; min-height: 16px; margin: 0; }

/* --- App --- */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
}
header h1 { font-size: 20px; margin: 0; }
.header-right { display: flex; align-items: center; gap: 12px; color: var(--text-dim); font-size: 14px; }
.header-right button {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  padding: 16px 28px;
}
.toolbar input[type="date"] {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 5px 8px;
  border-radius: 6px;
}
.toolbar select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 6px;
}
.toolbar button {
  background: var(--surface-2);
  color: var(--text);
  border: none;
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
}

table { width: 100%; border-collapse: collapse; padding: 0 28px; }
#offers-table { margin: 0 28px; width: calc(100% - 56px); }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--text-dim); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
tr:hover td { background: var(--surface); }
tr { cursor: pointer; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge-PENDING_APPROVAL { background: rgba(251,191,36,0.15); color: var(--amber); }
.badge-QUEUED_FOR_SEND, .badge-SENT { background: rgba(56,189,248,0.15); color: var(--accent); }
.badge-ACCEPTED { background: rgba(74,222,128,0.15); color: var(--green); }
.badge-REJECTED, .badge-BLOCKED, .badge-DEAD, .badge-WITHDRAWN { background: rgba(248,113,113,0.15); color: var(--red); }
.badge-COUNTERED { background: rgba(148,163,184,0.15); color: var(--text-dim); }

#empty-state { text-align: center; color: var(--text-dim); padding: 40px; }

/* --- Modal --- */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 10;
}
.modal-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  width: min(560px, 92vw);
  max-height: 85vh;
  overflow-y: auto;
  position: relative;
}
.modal-close {
  position: absolute; top: 16px; right: 16px;
  background: none; border: none; color: var(--text-dim);
  font-size: 22px; cursor: pointer;
}
.modal-content h2 { margin-top: 0; }
.detail-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.detail-row span:first-child { color: var(--text-dim); }
.block-reasons { background: rgba(248,113,113,0.1); border: 1px solid rgba(248,113,113,0.3); border-radius: 8px; padding: 12px; margin: 12px 0; font-size: 13px; }
.block-reasons li { margin: 4px 0; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.modal-actions button { flex: 1; padding: 10px; border-radius: 6px; border: none; cursor: pointer; font-weight: 600; }
.btn-approve { background: var(--green); color: #052e16; }
.btn-reject { background: var(--red); color: #450a0a; }
.doc-link { color: var(--accent); text-decoration: none; }

/* --- Nav --- */
.nav-tabs { display: flex; gap: 4px; padding: 0 28px; border-bottom: 1px solid var(--border); }
.nav-tabs button {
  background: none; border: none; color: var(--text-dim); padding: 12px 16px;
  font-size: 14px; cursor: pointer; border-bottom: 2px solid transparent;
}
.nav-tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

/* --- Dashboard --- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; padding: 20px 28px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; }
.stat-card .stat-num { font-size: 28px; font-weight: 700; }
.stat-card .stat-label { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.stat-card.warn .stat-num { color: var(--amber); }
.stat-card.error .stat-num { color: var(--red); }

/* --- Bulk actions --- */
.bulk-bar {
  display: flex; align-items: center; gap: 10px; padding: 10px 28px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.bulk-bar span { color: var(--text-dim); font-size: 13px; }
.bulk-bar button { background: var(--surface-2); color: var(--text); border: none; padding: 6px 12px; border-radius: 6px; cursor: pointer; }
.bulk-bar .btn-approve { background: var(--green); color: #052e16; font-weight: 600; }
.bulk-bar .btn-reject, .bulk-bar .btn-dead { background: var(--red); color: #450a0a; font-weight: 600; }
td.checkbox-col, th.checkbox-col { width: 32px; }

/* --- Health view --- */
.health-table td, .health-table th { font-size: 13px; }
.alert-row td { color: var(--amber); }
.section-title { padding: 20px 28px 4px; font-size: 13px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }

/* --- Agents view --- */
.hint { padding: 0 28px 12px; font-size: 13px; color: var(--text-dim); max-width: 720px; }
.agent-email-input { padding: 4px 8px; border-radius: 4px; border: 1px solid var(--border); background: var(--bg); color: var(--text); width: 220px; }
.agent-email-saved { color: var(--green); font-size: 12px; }

/* --- Detail modal extras --- */
.modal-content.wide { width: min(720px, 94vw); }
.property-photo { width: 100%; max-height: 220px; object-fit: cover; border-radius: 8px; margin-bottom: 12px; }
.timeline { list-style: none; padding: 0; margin: 8px 0; }
.timeline li { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.timeline .ts { color: var(--text-dim); font-size: 11px; }
.modal-actions.wrap { flex-wrap: wrap; }
.btn-secondary { background: var(--surface-2); color: var(--text); }
.btn-dead { background: var(--red); color: #450a0a; }

/* Admin view */
.admin-grid { display: grid; grid-template-columns: minmax(260px, 1fr) 2fr; gap: 16px; align-items: start; }
.admin-list { list-style: none; margin: 0; padding: 0; }
.admin-list li { padding: 8px 10px; border-bottom: 1px solid #e5e7eb; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.admin-list li:hover { background: #f3f4f6; }
#admin-editor { width: 100%; min-height: 420px; font-family: ui-monospace, Consolas, monospace; font-size: 13px; box-sizing: border-box; }
#admin-errors { white-space: pre-wrap; }
@media (max-width: 800px) { .admin-grid { grid-template-columns: 1fr; } }

/* Offer history: collapsed by default in the detail modal */
details.history { margin-top: 16px; }
details.history > summary { cursor: pointer; color: var(--muted, #9ca3af); font-size: 13px; }

/* --- Dashboard --- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; padding: 24px 28px 8px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; border-top: 3px solid var(--surface-2); }
.kpi-link { cursor: pointer; transition: border-color 0.15s, transform 0.15s; }
.kpi-link:hover { border-color: var(--accent); transform: translateY(-1px); }
.kpi-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); }
.kpi-value { font-size: 32px; font-weight: 700; margin: 6px 0 4px; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--text-dim); }
.kpi-accent { border-top-color: var(--accent); }
.kpi-amber { border-top-color: var(--amber); }
.kpi-amber .kpi-value { color: var(--amber); }
.kpi-red { border-top-color: var(--red); }
.kpi-red .kpi-value { color: var(--red); }

.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding: 8px 28px; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px; }
.panel-title { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); margin-bottom: 14px; }
.dash-systems { margin: 8px 28px 28px; }

.bar-row { display: grid; grid-template-columns: 140px 1fr 60px; align-items: center; gap: 12px; padding: 7px 0; cursor: pointer; }
.bar-row:hover .bar-label { color: var(--text); }
.bar-label { font-size: 13px; color: var(--text-dim); }
.bar-track { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: 4px; }
.bar-accent { background: var(--accent); }
.bar-amber { background: var(--amber); }
.bar-red { background: var(--red); }
.bar-green { background: var(--green); }
.bar-num { text-align: right; font-variant-numeric: tabular-nums; font-size: 14px; }

.reason-row { display: flex; gap: 14px; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.reason-row:last-child { border-bottom: none; }
.reason-num { min-width: 52px; text-align: right; font-weight: 700; color: var(--amber); font-variant-numeric: tabular-nums; }

.system-row { display: flex; flex-wrap: wrap; gap: 12px; }
.system-pill { display: flex; gap: 10px; align-items: center; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; min-width: 200px; }
.system-name { font-size: 13px; font-weight: 600; }
.system-sub { font-size: 12px; color: var(--text-dim); }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.dot-green { background: var(--green); }
.dot-amber { background: var(--amber); }
.dot-red { background: var(--red); }

@media (max-width: 800px) {
  .dash-grid { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 110px 1fr 50px; }
}

/* --- Offer detail (2026-09-27 redesign) --- */
.modal-content.wide { width: min(780px, 94vw); padding: 0 0 24px; }
.modal-content.wide > #modal-body { padding: 0 28px; }
.modal-content.wide .modal-close { z-index: 2; background: rgba(15,23,42,0.75); border-radius: 50%; width: 34px; height: 34px; line-height: 30px; padding: 0; }
.modal-content.wide .property-photo { display: block; width: calc(100% + 56px); margin: 0 -28px 20px; max-height: 260px; border-radius: 12px 12px 0 0; }
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin: 0 0 18px; padding-right: 40px; }
#modal-body > .detail-head:first-child { padding-top: 28px; }
.detail-head h2 { font-size: 22px; margin: 0 0 4px; }
.detail-sub { color: var(--text-dim); font-size: 13px; line-height: 1.5; }
.detail-head .badge { white-space: nowrap; }
.hero-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 18px; }
.hero-stat { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.hero-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); }
.hero-value { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.hero-sub { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.hero-accent { border-color: rgba(56,189,248,0.5); }
.hero-accent .hero-value { color: var(--accent); }
.hero-green .hero-value { color: var(--green); }
.hero-red .hero-value { color: var(--red); }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chip { font-size: 12px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text); }
.chip-green { background: rgba(74,222,128,0.15); color: var(--green); }
.chip-accent { background: rgba(56,189,248,0.15); color: var(--accent); }
.chip-amber { background: rgba(251,191,36,0.15); color: var(--amber); }
.chip-red { background: rgba(248,113,113,0.15); color: var(--red); }
.detail-section { border: 1px solid var(--border); border-radius: 10px; padding: 4px 16px 8px; margin-bottom: 14px; overflow: hidden; }
.detail-section-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); padding: 12px 0 6px; }
.calc-line { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding: 8px 0; border-bottom: 1px solid rgba(51,65,85,0.6); font-size: 14px; }
.calc-line:last-child { border-bottom: none; }
.calc-label { color: var(--text-dim); }
.calc-label small { display: block; font-size: 12px; color: var(--text-dim); opacity: 0.8; margin-top: 2px; }
.calc-value { text-align: right; font-variant-numeric: tabular-nums; }
.calc-value small { font-size: 12px; color: var(--text-dim); font-weight: 400; margin-left: 8px; }
.calc-sub .calc-label, .calc-sub .calc-value { color: var(--text); font-weight: 600; }
.calc-total { background: rgba(56,189,248,0.08); margin: 6px -16px -8px; padding: 12px 16px; border-bottom: none; }
.calc-total .calc-label { color: var(--text); font-weight: 600; }
.calc-total .calc-value { color: var(--accent); font-size: 18px; font-weight: 700; }
.muted { color: var(--text-dim); }
details.collapsible > summary { cursor: pointer; padding: 12px 0 8px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); }
details.collapsible > summary small { text-transform: none; letter-spacing: 0; font-weight: 400; margin-left: 8px; }
.comps-table { width: 100%; padding: 0; margin: 0 0 6px; }
.comps-table th, .comps-table td { padding: 7px 6px; font-size: 12px; }
.comps-table tr { cursor: default; }
.comps-table tr:hover td { background: transparent; }
.comps-table .num { text-align: right; font-variant-numeric: tabular-nums; }
details.remarks { padding: 8px 0 4px; font-size: 13px; }
details.remarks summary { cursor: pointer; color: var(--text-dim); }
details.remarks p { line-height: 1.55; color: var(--text); margin: 8px 0 0; }
details.history { border-top: 1px solid var(--border); padding-top: 12px; }
details.history > summary { margin-bottom: 6px; }
.btn-small { background: var(--accent); color: #0f172a; border: none; padding: 5px 12px; border-radius: 6px; font-weight: 600; cursor: pointer; font-size: 13px; }
.doc-link { font-weight: 600; }
@media (max-width: 600px) {
  .modal-content.wide > #modal-body { padding: 0 16px; }
  .modal-content.wide .property-photo { width: calc(100% + 32px); margin: 0 -16px 16px; }
  .detail-head { flex-direction: column; gap: 8px; }
  .calc-line { flex-wrap: wrap; }
}

/* Offer queue pagination */
.pager { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin: 14px 28px 28px; color: var(--text-dim); font-size: 13px; }
.pager-btns { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.pager button { background: var(--surface); color: var(--text); border: 1px solid var(--border); min-width: 34px; padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.pager button:hover:not(:disabled) { border-color: var(--accent); }
.pager button.active { background: var(--accent); color: #0f172a; border-color: var(--accent); font-weight: 600; }
.pager button:disabled { opacity: 0.4; cursor: default; }
.pager-gap { padding: 0 4px; }

.tag-special { display: inline-block; margin-left: 6px; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: rgba(74,222,128,0.15); color: var(--green); white-space: nowrap; }
.kpi-green { border-top-color: var(--green); }
.kpi-green .kpi-value { color: var(--green); }

#search-input { background: var(--surface); color: var(--text); border: 1px solid var(--border); padding: 6px 12px; border-radius: 6px; min-width: 280px; font-size: 14px; }
#search-input:focus { outline: none; border-color: var(--accent); }
@media (max-width: 600px) { #search-input { min-width: 0; width: 100%; } }
