:root {
  --bg:        #FAFAF8;
  --surface:   #FFFFFF;
  --surface-2: #F4F2EE;
  --ink:       #1A1A1A;
  --muted:     #6E6E6E;
  --muted-2:   #9A9A95;
  --line:      #E5E3DE;
  --accent:    #2E5A50;
  --accent-2:  #E6EFEC;
  --ok:        #2E7D32;
  --warn:      #B47B0F;
  --stale:     #B12D2D;
  --sans:      ui-sans-serif, system-ui, -apple-system, "Segoe UI", Inter, "Helvetica Neue", sans-serif;
  --mono:      ui-monospace, "SF Mono", Menlo, monospace;

  --shell-pad-x: 32px;
  --conv-max:    760px;
  --bubble-max:  78%;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100svh;
  display: flex; flex-direction: column;
}
button { font-family: inherit; }

/* ── App header ── */
header.app {
  padding: 18px var(--shell-pad-x);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg);
}
.mark { font-weight: 500; letter-spacing: -0.01em; font-size: 17px; }
.mark .dot { color: var(--accent); }
.status { font-family: var(--mono); font-size: 11px; color: var(--muted); letter-spacing: 0.04em; }

/* ── Landing view ── */
.landing { flex: 1; max-width: 720px; width: 100%; margin: 0 auto; padding: 64px var(--shell-pad-x); }
.eyebrow { font-family: var(--mono); font-size: 11px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--muted); margin-bottom: 18px; }
h1 { font-size: clamp(28px, 4.6vw, 40px); font-weight: 500; line-height: 1.15; letter-spacing: -0.018em; margin-bottom: 22px; max-width: 18ch; }
p.lede { color: var(--muted); font-size: 18px; margin-bottom: 28px; max-width: 56ch; }
p.body { color: var(--muted); margin-bottom: 16px; max-width: 56ch; }
.cta {
  display: inline-block;
  background: var(--accent); color: #fff;
  font-size: 15px; font-weight: 500;
  padding: 13px 22px; border: 0; border-radius: 8px;
  cursor: pointer;
  letter-spacing: -0.005em;
  transition: opacity 0.18s ease, transform 0.06s ease;
}
.cta:hover { opacity: 0.92; }
.cta:active { transform: translateY(1px); }
.cta-hint { display: block; margin-top: 12px; font-family: var(--mono); font-size: 11px; color: var(--muted); letter-spacing: 0.04em; }

/* ── Conversation view ── */
.conv-view {
  flex: 1;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
}

.conv-view.with-results {
  grid-template-columns: 1fr;
}
@media (min-width: 1080px) {
  .conv-view.with-results {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto 1fr auto;
  }
  .conv-view.with-results .progress  { grid-column: 1 / -1; }
  .conv-view.with-results .composer  { grid-column: 1; }
  .conv-view.with-results .results-panel { grid-row: 2 / span 2; grid-column: 2; border-left: 1px solid var(--line); }
}

/* progress bar */
.progress {
  padding: 18px var(--shell-pad-x) 14px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.progress-meta {
  display: flex; align-items: baseline; justify-content: space-between;
  font-family: var(--mono); font-size: 11px;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}
.progress-meta .pct { color: var(--ink); }
.progress-meta .phase-label { color: var(--accent); }
.progress-track {
  height: 4px; background: var(--line); border-radius: 4px; overflow: hidden;
  position: relative;
}
.progress-fill {
  height: 100%; background: var(--accent);
  width: 0%;
  transition: width 0.5s cubic-bezier(0.22, 1, 0.36, 1);
}
.progress-est {
  margin-top: 8px;
  font-family: var(--mono); font-size: 10.5px;
  color: var(--muted-2); letter-spacing: 0.06em;
}

/* messages */
.thread {
  overflow-y: auto;
  padding: 24px var(--shell-pad-x) 8px;
  min-height: 0;
}
.thread-inner {
  max-width: var(--conv-max);
  margin: 0 auto;
  display: flex; flex-direction: column; gap: 18px;
}
.bubble {
  max-width: var(--bubble-max);
  padding: 12px 16px;
  border-radius: 14px;
  line-height: 1.5;
  font-size: 16.5px;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.bubble.from-user {
  background: var(--accent);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}
.bubble.from-belong {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.bubble.from-belong.thinking {
  color: var(--muted);
  font-style: italic;
}
.bubble .role-tag {
  display: block;
  font-family: var(--mono); font-size: 10.5px;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.bubble.from-user .role-tag { color: rgba(255,255,255,0.7); }

.dim-trace {
  align-self: flex-start;
  max-width: var(--bubble-max);
  margin-top: -10px;
  padding: 8px 12px;
  background: var(--surface-2);
  border-radius: 8px;
  font-family: var(--mono); font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.02em;
}
.dim-trace .dim-id { color: var(--accent); font-weight: 500; }
.dim-trace .dim-conf { color: var(--ink); }

.error {
  background: #FEF2F2;
  color: var(--stale);
  border: 1px solid #FECACA;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  align-self: stretch;
}

/* composer */
.composer {
  border-top: 1px solid var(--line);
  background: var(--bg);
  padding: 14px var(--shell-pad-x) 20px;
}
.composer-inner { max-width: var(--conv-max); margin: 0 auto; }
.quick-replies {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-bottom: 10px;
}
.qr {
  background: var(--surface);
  border: 1px solid var(--line);
  padding: 8px 14px;
  border-radius: 100px;
  font-size: 14px;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.qr:hover { background: var(--accent-2); border-color: var(--accent); }

.composer-row {
  display: flex; gap: 8px; align-items: flex-end;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px 8px 8px 16px;
}
.composer-row:focus-within { border-color: var(--accent); }
.composer-input {
  flex: 1;
  border: 0;
  resize: none;
  font-family: inherit;
  font-size: 16.5px;
  line-height: 1.5;
  color: var(--ink);
  background: transparent;
  outline: none;
  padding: 8px 0;
  min-height: 24px; max-height: 240px;
}
.send-btn {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 10px;
  width: 38px; height: 38px;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px;
  transition: opacity 0.15s ease;
}
.send-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ── Results panel ── */
.results-panel {
  overflow-y: auto;
  background: var(--bg);
  padding: 22px var(--shell-pad-x);
}
.results-header {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 18px;
}
.results-header h2 { font-size: 22px; font-weight: 500; letter-spacing: -0.012em; }
.results-meta { font-family: var(--mono); font-size: 11px; color: var(--muted); letter-spacing: 0.08em; }

.match-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 14px;
}
.match-card .row1 { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 6px; }
.match-rank { font-family: var(--mono); font-size: 11px; color: var(--muted); letter-spacing: 0.14em; text-transform: uppercase; }
.match-name { font-size: 19px; font-weight: 500; letter-spacing: -0.01em; }
.match-score {
  font-family: var(--mono); font-size: 13px; color: var(--accent);
  background: var(--accent-2);
  padding: 4px 10px; border-radius: 100px;
  letter-spacing: 0.06em;
}
.match-where { font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.match-explain { color: var(--ink); font-size: 15.5px; margin-bottom: 14px; line-height: 1.55; }
.match-toggle {
  background: transparent; border: 0; color: var(--accent);
  font-size: 13px; cursor: pointer; padding: 0;
  font-family: var(--mono); letter-spacing: 0.04em;
}
.match-toggle:hover { text-decoration: underline; }
.match-detail { display: none; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.match-detail.open { display: block; }
.dim-breakdown { display: grid; grid-template-columns: 1fr auto auto; gap: 6px 14px; font-size: 13px; }
.dim-breakdown .dim-name { color: var(--ink); }
.dim-breakdown .dim-contrib { color: var(--muted); font-family: var(--mono); }
.dim-breakdown .dim-weight  { color: var(--muted-2); font-family: var(--mono); font-size: 11px; }
.tradeoffs { margin-top: 12px; color: var(--muted); font-size: 13.5px; }
.tradeoffs .tradeoff { display: block; margin-bottom: 4px; }

.freshness {
  display: inline-block;
  font-family: var(--mono); font-size: 10.5px;
  padding: 2px 8px; border-radius: 100px;
  margin-left: 8px;
}
.freshness.current  { background: #E8F5E9; color: var(--ok); }
.freshness.moderate { background: #FFF8E1; color: var(--warn); }
.freshness.stale    { background: #FFEBEE; color: var(--stale); }

.see-more {
  margin-top: 6px;
  font-family: var(--mono); font-size: 12px;
  color: var(--accent);
  background: transparent; border: 0; padding: 8px 0;
  cursor: pointer;
}
.see-more:hover { text-decoration: underline; }

footer.app {
  padding: 18px var(--shell-pad-x);
  border-top: 1px solid var(--line);
  font-family: var(--mono); font-size: 11px;
  color: var(--muted); letter-spacing: 0.04em;
  text-align: center;
}

/* ── Responsive ── */
@media (max-width: 640px) {
  :root { --shell-pad-x: 18px; --bubble-max: 88%; }
  .landing { padding: 44px var(--shell-pad-x); }
  body { font-size: 16px; }
  .bubble { font-size: 15.5px; }
}
