:root {
  --bg: #eef3ef;
  --panel: #ffffff;
  --panel-soft: #f7faf7;
  --ink: #17241e;
  --muted: #68786f;
  --line: #d7e0d8;
  --rail: #18372d;
  --rail-soft: #24483c;
  --accent: #2f7358;
  --accent-dark: #1f513e;
  --copper: #b46d4e;
  --blue: #496f89;
  --danger: #ad4d55;
  --success: #2d7458;
  --shadow: 0 18px 48px rgba(23, 36, 30, 0.12);
  --radius: 8px;
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(47, 115, 88, 0.12), transparent 34%),
    linear-gradient(180deg, #fbfdfb, var(--bg));
  color: var(--ink);
}

button,
textarea,
a {
  font: inherit;
}

a { color: inherit; }

.estate-shell {
  display: grid;
  grid-template-columns: 284px minmax(0, 1fr);
  min-height: 100vh;
}

.ops-rail {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 22px;
  height: 100vh;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(180, 109, 78, 0.18), transparent 38%),
    linear-gradient(155deg, rgba(73, 111, 137, 0.15), transparent 56%),
    var(--rail);
  color: #f6fbf7;
}

.back-link {
  width: fit-content;
  color: #cfe7da;
  font-size: 13px;
  font-weight: 850;
  text-decoration: none;
}

.agency-brand {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 12px;
  align-items: center;
}

.agency-brand > span {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: var(--radius);
  background: #f6fbf7;
  color: var(--rail);
  font-weight: 950;
}

.agency-brand strong,
.agency-brand small {
  display: block;
}

.agency-brand strong {
  line-height: 1.12;
}

.agency-brand small {
  margin-top: 4px;
  color: #c9d9d0;
}

nav {
  display: grid;
  gap: 8px;
}

nav a {
  border-radius: var(--radius);
  padding: 10px 12px;
  color: #d8e5dd;
  font-size: 14px;
  font-weight: 800;
  text-decoration: none;
}

nav a.active,
nav a:hover {
  background: rgba(255, 255, 255, 0.10);
  color: #fff;
}

.boundary-card {
  margin-top: auto;
  border: 1px solid rgba(255, 255, 255, 0.17);
  border-radius: var(--radius);
  padding: 14px;
  background: rgba(255, 255, 255, 0.08);
}

.boundary-card b {
  display: block;
  margin-bottom: 7px;
}

.boundary-card p {
  margin: 0;
  color: #dce8df;
  font-size: 13px;
  line-height: 1.5;
}

.deal-workspace {
  min-width: 0;
  padding: 26px;
}

.deal-header,
.runway,
.metric-strip,
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.deal-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  padding: 18px 20px;
  margin-bottom: 16px;
}

.label {
  margin: 0 0 7px;
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 950;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 { font-size: clamp(1.62rem, 3vw, 2.72rem); }

h2 {
  font-size: clamp(1.24rem, 2vw, 1.68rem);
  line-height: 1.08;
}

.source-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 9px;
}

.source-links a,
.source-tabs button,
.review-actions button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  cursor: pointer;
  font-weight: 850;
  text-decoration: none;
}

.source-links a {
  padding: 9px 11px;
  color: var(--accent-dark);
  font-size: 13px;
}

.runway {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 334px;
  gap: 18px;
  align-items: stretch;
  padding: 22px;
  margin-bottom: 16px;
  overflow: hidden;
  background:
    linear-gradient(120deg, rgba(47, 115, 88, 0.14), transparent 40%),
    linear-gradient(90deg, #fff, #f8faf7);
}

.runway-copy {
  position: relative;
  padding-left: 22px;
}

.property-line {
  position: absolute;
  left: 0;
  top: 4px;
  width: 9px;
  height: 104px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--accent), var(--copper));
}

.runway-copy p {
  max-width: 780px;
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.run-card {
  display: grid;
  gap: 12px;
  align-content: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--panel-soft);
}

.run-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.run-meta strong { color: var(--accent-dark); }

#run-workflow {
  min-height: 46px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 900;
}

#run-note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 16px;
  overflow: hidden;
}

.metric-strip div {
  padding: 15px 18px;
  border-right: 1px solid var(--line);
}

.metric-strip div:last-child { border-right: 0; }

.metric-strip b,
.metric-strip span {
  display: block;
}

.metric-strip b {
  color: var(--accent-dark);
  font-size: 25px;
}

.metric-strip span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.deal-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(370px, 0.92fr);
  grid-template-areas:
    "source review"
    "queue review"
    "proof proof";
  gap: 16px;
  align-items: start;
}

.panel {
  min-width: 0;
  padding: 18px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 14px;
}

.chip {
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 5px 9px;
  background: #e5f0e8;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 900;
}

.source-panel { grid-area: source; }

.queue-panel { grid-area: queue; }

.review-panel {
  grid-area: review;
  position: sticky;
  top: 18px;
}

.proof-panel { grid-area: proof; }

.source-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.source-tabs button {
  padding: 8px 10px;
  color: var(--muted);
}

.source-tabs button.active {
  border-color: rgba(47, 115, 88, 0.42);
  background: #e5f0e8;
  color: var(--accent-dark);
}

.source-view {
  min-height: 342px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  overflow: auto;
}

.source-text {
  margin: 0;
  padding: 14px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.58;
  white-space: pre-wrap;
}

.data-table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: top;
}

.data-table th {
  position: sticky;
  top: 0;
  background: #edf5ef;
  color: var(--accent-dark);
  font-size: 12px;
}

.deal-list {
  display: grid;
  gap: 9px;
}

.deal-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  background: #fff;
  cursor: pointer;
  text-align: left;
}

.deal-item:hover,
.deal-item.active {
  border-color: rgba(47, 115, 88, 0.45);
  background: #f7faf7;
}

.deal-item b,
.deal-item span,
.deal-item small {
  display: block;
}

.deal-item span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.deal-item small {
  width: fit-content;
  border-radius: 999px;
  padding: 4px 7px;
  background: #e5f0e8;
  color: var(--accent-dark);
  font-weight: 900;
}

.deal-item[data-status="same-day follow-up"] small,
.deal-item[data-status="client update"] small,
.deal-item[data-status="edited"] small {
  background: #fff0e9;
  color: var(--copper);
}

.deal-item[data-status="deal gap"] small,
.deal-item[data-status="missing document"] small {
  background: #ffe8eb;
  color: var(--danger);
}

.deal-item[data-status="agent review"] small {
  background: #e8f1f6;
  color: var(--blue);
}

.deal-item[data-status="approved"] small {
  background: #e0f3e8;
  color: var(--success);
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 18px;
  background: var(--panel-soft);
  color: var(--muted);
  line-height: 1.55;
}

.review-form {
  display: grid;
  gap: 12px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

textarea {
  width: 100%;
  min-height: 126px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 11px;
  background: #fff;
  color: var(--ink);
  line-height: 1.5;
}

textarea[readonly] {
  background: #f7faf7;
}

.review-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.review-actions button {
  min-height: 42px;
  padding: 8px;
}

.review-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.76;
}

.review-actions button[data-action="approve"] {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.review-actions button[data-action="approve"]:disabled {
  background: #e0f3e8;
  color: var(--success);
}

.review-actions button[data-action="agent"] {
  color: var(--blue);
}

.review-actions button[data-action="agent"]:disabled {
  color: var(--muted);
}

.proof-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.proof-list li {
  border-left: 3px solid var(--accent);
  padding: 4px 0 4px 12px;
}

.proof-list b,
.proof-list span {
  display: block;
}

.proof-list b {
  margin-bottom: 6px;
  color: var(--accent-dark);
  font-size: 12px;
  text-transform: uppercase;
}

.proof-list span {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.52;
}

@media (max-width: 1120px) {
  .estate-shell {
    grid-template-columns: 1fr;
  }

  .ops-rail {
    position: static;
    height: auto;
  }

  .runway,
  .deal-grid {
    grid-template-columns: 1fr;
  }

  .deal-grid {
    grid-template-areas:
      "source"
      "queue"
      "review"
      "proof";
  }

  .review-panel {
    position: static;
  }
}

@media (max-width: 680px) {
  .deal-workspace,
  .ops-rail {
    padding: 16px;
  }

  .deal-header,
  .panel-head,
  .run-meta {
    align-items: start;
    flex-direction: column;
  }

  .source-links {
    justify-content: flex-start;
  }

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

  .metric-strip div:nth-child(2) {
    border-right: 0;
  }

  .metric-strip div:nth-child(-n + 2) {
    border-bottom: 1px solid var(--line);
  }

  .deal-item,
  .review-actions,
  .proof-list {
    grid-template-columns: 1fr;
  }
}
