/* Earth Agent UI. Palette and type follow kaashyapmurali.com: warm ivory / olive, yellow-lime controls,
   Newsreader headings, DM Sans body, MesloLGS NF (fallback: system mono) for code. */

:root,
html[data-theme="light"] {
  --background: #f8f6f0;
  --surface: #fffefa;
  --foreground: #1a1b1a;
  --accent: #1e3207;
  --visual-accent: #5b7b25;
  --button: #dcef54;
  --button-hover: #e4f47c;
  --button-foreground: #1a1b1a;
  --muted: #eeece3;
  --muted-foreground: #626357;
  --border: #d9dacd;
  --danger: #b3261e;
  --warn-bg: #fbf3d5;
  --viz-1: #1f7dcf;
  --viz-2: #00863b;
  --viz-3: #bb5d00;
  --viz-4: #8264c8;
  --shadow: 0 1px 2px rgb(30 50 7 / 0.06), 0 8px 24px rgb(30 50 7 / 0.06);
}

html[data-theme="dark"] {
  --background: #191d16;
  --surface: #1f241b;
  --foreground: #eeeae0;
  --accent: #c5d5a5;
  --visual-accent: #c5d5a5;
  --button: #dcef54;
  --button-hover: #e4f47c;
  --button-foreground: #1a1b1a;
  --muted: #242a1e;
  --muted-foreground: #b0b6a3;
  --border: #3e4834;
  --danger: #f28881;
  --warn-bg: #2f2e1b;
  --viz-1: #67b0f9;
  --viz-2: #69c27e;
  --viz-3: #e99355;
  --viz-4: #b199f4;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 8px 24px rgb(0 0 0 / 0.25);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--background);
  color: var(--foreground);
  font: 15px/1.6 "DM Sans", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

code,
pre,
.crumb {
  font-family: "MesloLGS NF", ui-monospace, SFMono-Regular, Menlo, monospace;
}

:focus-visible {
  outline: 2px solid var(--visual-accent);
  outline-offset: 2px;
}

/* ---------- layout ---------- */

.app {
  display: grid;
  grid-template-columns: 272px 1fr;
  height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem 0.75rem;
  border-right: 1px solid var(--border);
  background: var(--muted);
  min-height: 0;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 0.25rem;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.85rem;
  border-radius: 999px;
  background: var(--button);
  color: var(--button-foreground);
  font-weight: 600;
  text-decoration: none;
  font-size: 1rem;
}

.new-session {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  background: var(--surface);
  font-weight: 500;
}

.new-session:hover {
  border-color: var(--visual-accent);
}

.sessions {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-height: 0;
}

.sessions h3 {
  margin: 0.9rem 0.5rem 0.3rem;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted-foreground);
}

.session {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  border-radius: 0.6rem;
}

.session a {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.55rem;
  color: inherit;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.92rem;
}

.session:hover,
.session.active {
  background: color-mix(in srgb, var(--foreground) 7%, transparent);
}

.session.active a {
  font-weight: 600;
}

.session .running-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--visual-accent);
  animation: pulse 1.2s infinite;
}

.session .delete {
  visibility: hidden;
  border: 0;
  background: none;
  color: var(--muted-foreground);
  padding: 0.2rem 0.45rem;
  border-radius: 0.4rem;
}

.session:hover .delete,
.session .delete:focus-visible {
  visibility: visible;
}

.session .delete:hover {
  color: var(--danger);
}

.sidebar-foot {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.78rem;
  color: var(--muted-foreground);
}

.field select {
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  background: var(--surface);
}

.ghost {
  border: 0;
  background: none;
  color: var(--muted-foreground);
  padding: 0.35rem 0.5rem;
  border-radius: 0.5rem;
  text-align: left;
}

.ghost:hover {
  background: color-mix(in srgb, var(--foreground) 7%, transparent);
  color: var(--foreground);
}

.icon {
  font-size: 1rem;
  line-height: 1;
}

#close-sidebar,
#open-sidebar,
.scrim {
  display: none;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.crumb {
  font-size: 0.85rem;
  color: var(--muted-foreground);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.crumb b {
  color: var(--accent);
  font-weight: 400;
}

.projects {
  display: flex;
  gap: 0.35rem;
}

.chip {
  font-size: 0.75rem;
  padding: 0.1rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted-foreground);
}

.chip.on {
  border-color: var(--visual-accent);
  color: var(--accent);
}

.thread {
  flex: 1;
  overflow-y: auto;
  padding: 2rem 1.5rem 1rem;
  scroll-behavior: smooth;
}

.thread > * {
  max-width: 780px;
  margin-inline: auto;
}

/* ---------- empty state ---------- */

.empty {
  padding-top: 8vh;
}

.empty h1 {
  font-family: Newsreader, Georgia, serif;
  font-weight: 400;
  font-size: 2.6rem;
  line-height: 1.15;
  letter-spacing: -0.01em;
  color: var(--accent);
  margin: 0 0 0.5rem;
}

.empty p {
  color: var(--muted-foreground);
  margin: 0 0 1.75rem;
  max-width: 36rem;
}

.suggestions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
}

.suggestion {
  text-align: left;
  padding: 0.8rem 0.95rem;
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  background: var(--surface);
  font-size: 0.92rem;
  line-height: 1.4;
}

.suggestion small {
  display: block;
  margin-top: 0.3rem;
  color: var(--muted-foreground);
  font-size: 0.75rem;
}

.suggestion:hover {
  border-color: var(--visual-accent);
  box-shadow: var(--shadow);
}

/* ---------- turns ---------- */

.turn {
  margin-bottom: 1.75rem;
}

.user-msg {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 1rem;
}

.user-msg div {
  max-width: 82%;
  padding: 0.6rem 1rem;
  border-radius: 1.1rem 1.1rem 0.3rem 1.1rem;
  background: var(--muted);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.assistant {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

.pill {
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.1rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted-foreground);
}

.pill.in_scope {
  color: var(--viz-2);
  border-color: color-mix(in srgb, var(--viz-2) 45%, transparent);
}

.pill.general {
  color: var(--viz-1);
  border-color: color-mix(in srgb, var(--viz-1) 45%, transparent);
}

.pill.partially_in_scope {
  color: var(--viz-3);
  border-color: color-mix(in srgb, var(--viz-3) 45%, transparent);
}

.pill.out_of_scope,
.pill.unsafe {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 45%, transparent);
}

.status {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--muted-foreground);
  font-size: 0.92rem;
}

.spinner {
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--visual-accent);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes pulse {
  50% {
    opacity: 0.3;
  }
}

details.block {
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  background: var(--surface);
}

details.block > summary {
  list-style: none;
  cursor: pointer;
  padding: 0.5rem 0.85rem;
  font-size: 0.88rem;
  color: var(--muted-foreground);
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

details.block > summary::-webkit-details-marker {
  display: none;
}

details.block > summary::before {
  content: "▸";
  font-size: 0.75rem;
  transition: transform 0.15s;
}

details.block[open] > summary::before {
  transform: rotate(90deg);
}

details.block > .body {
  padding: 0 0.95rem 0.75rem;
  font-size: 0.9rem;
}

.tool summary code {
  color: var(--foreground);
  font-size: 0.8rem;
}

.tool summary .args {
  color: var(--muted-foreground);
  font-size: 0.78rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  flex: none;
  background: var(--viz-2);
}

.dot.error {
  background: var(--danger);
}

.tool pre {
  margin: 0;
  max-height: 22rem;
  overflow: auto;
  font-size: 0.75rem;
  line-height: 1.5;
  background: var(--muted);
  border-radius: 0.5rem;
  padding: 0.6rem 0.75rem;
}

.sources {
  margin-top: 0.5rem;
  font-size: 0.78rem;
  color: var(--muted-foreground);
}

/* ---------- answer markdown ---------- */

.md > :first-child {
  margin-top: 0;
}

.md > :last-child {
  margin-bottom: 0;
}

.md p,
.md ul,
.md ol {
  margin: 0.5rem 0;
}

.md ul,
.md ol {
  padding-left: 1.3rem;
}

.md li {
  margin: 0.15rem 0;
}

.md h1,
.md h2,
.md h3,
.md h4 {
  font-family: Newsreader, Georgia, serif;
  font-weight: 500;
  color: var(--accent);
  margin: 1rem 0 0.3rem;
  line-height: 1.25;
}

.md h1 {
  font-size: 1.45rem;
}

.md h2 {
  font-size: 1.3rem;
}

.md h3,
.md h4 {
  font-size: 1.12rem;
}

.md code {
  font-size: 0.82em;
  background: var(--muted);
  padding: 0.05rem 0.3rem;
  border-radius: 0.3rem;
}

.md pre {
  background: var(--muted);
  padding: 0.75rem;
  border-radius: 0.6rem;
  overflow: auto;
}

.md pre code {
  background: none;
  padding: 0;
}

.md table {
  border-collapse: collapse;
  margin: 0.6rem 0;
  font-size: 0.88rem;
  display: block;
  overflow-x: auto;
}

.md th,
.md td {
  border-bottom: 1px solid var(--border);
  padding: 0.35rem 0.7rem;
  text-align: left;
}

.md th {
  font-weight: 600;
}

.md .indent {
  margin-left: 1.2rem;
}

.answer {
  font-size: 0.97rem;
}

.refusal {
  padding: 0.75rem 1rem;
  border-left: 3px solid var(--viz-3);
  background: color-mix(in srgb, var(--viz-3) 7%, transparent);
  border-radius: 0 0.6rem 0.6rem 0;
}

.warning {
  font-size: 0.82rem;
  padding: 0.5rem 0.8rem;
  border-radius: 0.6rem;
  background: var(--warn-bg);
  color: var(--foreground);
}

.stopped-note {
  font-size: 0.85rem;
  color: var(--muted-foreground);
  font-style: italic;
}

.turn-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  font-size: 0.75rem;
  color: var(--muted-foreground);
}

.turn-foot button {
  border: 0;
  background: none;
  color: inherit;
  padding: 0.1rem 0.3rem;
  border-radius: 0.3rem;
}

.turn-foot button:hover {
  color: var(--foreground);
  background: var(--muted);
}

/* ---------- visuals ---------- */

.visuals {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

figure.viz {
  margin: 0;
  padding: 0.85rem 1rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.9rem;
  background: var(--surface);
}

figure.viz figcaption {
  font-family: Newsreader, Georgia, serif;
  font-size: 1.05rem;
  color: var(--accent);
  margin-bottom: 0.5rem;
}

figure.viz .viz-note {
  font-size: 0.75rem;
  color: var(--muted-foreground);
  margin-top: 0.35rem;
}

figure.viz svg {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}

.viz text {
  fill: var(--foreground);
  font-size: 11px;
  font-family: "DM Sans", system-ui, sans-serif;
}

.viz .axis-label {
  fill: var(--muted-foreground);
  font-size: 10.5px;
}

.viz .gridline {
  stroke: var(--border);
  stroke-width: 1;
}

.viz .legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.9rem;
  font-size: 0.78rem;
  color: var(--muted-foreground);
  margin-bottom: 0.35rem;
}

.viz .legend span::before {
  content: "";
  display: inline-block;
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 2px;
  margin-right: 0.35rem;
  vertical-align: -0.05rem;
  background: var(--c);
}

.scene-wrap {
  position: relative;
  border-radius: 0.6rem;
  overflow: hidden;
  background: #000;
}

.scene-wrap img {
  display: block;
  width: 100%;
  height: auto;
}

.scene-wrap svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.scene-wrap polygon {
  stroke: var(--c);
  stroke-width: 2.2;
  fill: color-mix(in srgb, var(--c) 28%, transparent);
  vector-effect: non-scaling-stroke;
}

.scene-wrap polygon.wrong {
  stroke-dasharray: 5 3;
}

.scene-wrap polygon.missed {
  --c: #ffffff;
  fill: none;
  stroke-dasharray: 2 3;
}

.scene-wrap.hide-outlines svg {
  display: none;
}

.scene-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.55rem 0 0.25rem;
}

.seg {
  padding: 0.2rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.78rem;
}

.seg[aria-pressed="true"] {
  background: var(--button);
  color: var(--button-foreground);
  border-color: var(--button);
}

.scene-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 1rem;
  font-size: 0.8rem;
  color: var(--muted-foreground);
}

.scene-stats b {
  color: var(--foreground);
  font-weight: 600;
}

/* ---------- composer ---------- */

.composer {
  width: min(780px, calc(100% - 2rem));
  margin: 0 auto;
  border: 1px solid var(--border);
  border-radius: 1.4rem;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 0.75rem 0.75rem 0.55rem 1.1rem;
}

.composer:focus-within {
  border-color: var(--visual-accent);
}

.composer textarea {
  width: 100%;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  max-height: 12rem;
  line-height: 1.5;
}

.composer-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.model-pill {
  appearance: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 1.6rem 0.25rem 0.75rem;
  font-size: 0.8rem;
  background: var(--muted)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23626357' stroke-width='1.5'/%3E%3C/svg%3E")
    no-repeat right 0.6rem center / 0.6rem;
  cursor: pointer;
}

.toggle-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.22rem 0.7rem;
  font-size: 0.8rem;
  background: transparent;
  color: var(--muted-foreground);
}

.toggle-pill svg {
  width: 0.9rem;
  height: 0.9rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.toggle-pill[aria-pressed="true"] {
  background: color-mix(in srgb, var(--button) 55%, transparent);
  border-color: var(--button);
  color: var(--button-foreground);
}

html[data-theme="dark"] .toggle-pill[aria-pressed="true"] {
  color: var(--foreground);
  background: color-mix(in srgb, var(--button) 22%, transparent);
}

.hint {
  flex: 1;
  font-size: 0.72rem;
  color: var(--muted-foreground);
  text-align: right;
}

.send {
  width: 2.2rem;
  height: 2.2rem;
  border-radius: 50%;
  border: 0;
  background: var(--button);
  color: var(--button-foreground);
  display: grid;
  place-items: center;
  flex: none;
}

.send:hover {
  background: var(--button-hover);
}

.send:disabled {
  opacity: 0.4;
  cursor: default;
}

.send svg {
  width: 1.1rem;
  height: 1.1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.send .i-stop {
  display: none;
  fill: currentColor;
  stroke: none;
}

.send.running {
  background: var(--foreground);
  color: var(--background);
}

.send.running .i-send {
  display: none;
}

.send.running .i-stop {
  display: block;
}

.footnote {
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted-foreground);
  margin: 0.45rem 0 0.75rem;
}

/* ---------- small screens ---------- */

@media (max-width: 820px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 280px;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.2s;
  }

  .app.sidebar-open .sidebar {
    transform: none;
  }

  .app.sidebar-open .scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 10;
    background: rgb(0 0 0 / 0.3);
  }

  #close-sidebar,
  #open-sidebar {
    display: inline-block;
  }

  .suggestions {
    grid-template-columns: 1fr;
  }

  .hint,
  .projects {
    display: none;
  }

  .empty h1 {
    font-size: 2rem;
  }
}

/* ---------- timeline: thinking, notes, streaming ---------- */

.flow {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.flow:empty {
  display: none;
}

details.thinking {
  border-style: dashed;
  background: transparent;
}

details.thinking > summary .label {
  font-style: italic;
}

details.thinking:not(.done) > summary .label {
  animation: pulse 1.4s infinite;
}

.thinking-text {
  color: var(--muted-foreground);
  font-size: 0.86rem;
  max-height: 20rem;
  overflow-y: auto;
  border-left: 2px solid var(--border);
  padding-left: 0.8rem;
  margin-left: 0.15rem;
}

.md.note {
  color: var(--muted-foreground);
  font-size: 0.9rem;
  padding-left: 0.2rem;
}

.answer.streaming > :last-child::after {
  content: "";
  display: inline-block;
  width: 0.5rem;
  height: 1rem;
  margin-left: 0.15rem;
  vertical-align: -0.15rem;
  background: var(--visual-accent);
  animation: pulse 1s infinite;
}

.status[hidden] {
  display: none;
}

/* ---------- web results and links ---------- */

.md a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent);
  text-underline-offset: 2px;
}

.web-results {
  margin: 0;
  padding-left: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  font-size: 0.88rem;
}

.web-results a {
  color: var(--accent);
  font-weight: 500;
}

.web-results .host {
  color: var(--muted-foreground);
  font-size: 0.75rem;
}

.web-results p {
  margin: 0.15rem 0 0;
  color: var(--muted-foreground);
  font-size: 0.82rem;
  line-height: 1.45;
}

/* ---------- zip map ---------- */

.zip-map {
  background: color-mix(in srgb, var(--muted) 70%, transparent);
  border-radius: 0.6rem;
}

.zip-map .zip-outline {
  fill: color-mix(in srgb, var(--visual-accent) 8%, transparent);
  stroke: var(--accent);
  stroke-width: 1.6;
}

.zip-map .scene-box {
  fill: none;
  stroke: var(--muted-foreground);
  stroke-width: 0.8;
  opacity: 0.6;
}

.zip-map .scene-box.report {
  stroke: var(--foreground);
  stroke-dasharray: 4 3;
  stroke-width: 1.4;
  opacity: 1;
}

.zip-map circle {
  stroke: none;
  opacity: 0.9;
}

.zip-map circle.miss {
  stroke: var(--foreground);
  stroke-width: 0.9;
}

/* ---------- public mode ---------- */

[hidden] {
  display: none !important;
}

#turnstile:empty {
  display: none;
}

#turnstile {
  margin: 0.4rem auto 0;
  width: fit-content;
}
