:root {
  --ink: #17211d;
  --muted: #657069;
  --paper: #f8f6ee;
  --panel: #ffffff;
  --line: #d9d5c8;
  --line-strong: #9fa99e;
  --green: #0e6f5c;
  --green-2: #2fb28f;
  --gold: #c88719;
  --coral: #e15f3f;
  --cyan: #4aa3b5;
  --shadow: 0 24px 60px rgba(23, 33, 29, 0.13);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Gill Sans", "Trebuchet MS", ui-sans-serif, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(23, 33, 29, 0.05) 1px, transparent 1px),
    linear-gradient(0deg, rgba(23, 33, 29, 0.04) 1px, transparent 1px),
    var(--paper);
  background-size: 34px 34px;
}

button,
input {
  font: inherit;
}

input,
textarea,
.code-pane,
.code-pane * {
  -webkit-user-select: text;
  user-select: text;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  padding: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(300px, 380px) 1fr;
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

.control-panel {
  position: relative;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 14px;
  max-height: 100vh;
  border-right: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(18px);
  padding: 22px 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark-button {
  display: block;
  flex: 0 0 48px;
  width: 48px;
  height: 48px;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  cursor: pointer;
}

.brand-mark-button:focus-visible {
  outline: 3px solid rgba(47, 178, 143, 0.35);
  outline-offset: 6px;
}

.brand-mark-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.brand-mark {
  display: block;
  width: 48px;
  height: 48px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 5px 5px 0 var(--ink);
  object-fit: cover;
  transition: transform 150ms ease, box-shadow 150ms ease;
}

.brand-mark-button:not(:disabled):hover .brand-mark {
  transform: translate(-1px, -1px);
  box-shadow: 6px 6px 0 var(--ink);
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.1;
  letter-spacing: 0;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
}

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

.file-summary {
  display: grid;
  gap: 4px;
  min-height: 76px;
  align-content: center;
  border: 1px solid var(--line);
  background: rgba(248, 246, 238, 0.72);
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 160ms ease, background-color 160ms ease;
}

.file-summary:hover,
.file-summary.dragging,
.file-summary.has-file {
  border-color: var(--green);
  background: rgba(47, 178, 143, 0.09);
}

.file-summary strong {
  overflow-wrap: anywhere;
}

.file-summary span:last-child {
  color: var(--muted);
  font-size: 0.84rem;
}

.drop-zone {
  position: relative;
  display: grid;
  gap: 8px;
  min-height: 100%;
  align-content: center;
  justify-items: center;
  border: 1px dashed var(--line-strong);
  background:
    radial-gradient(circle at 18px 18px, rgba(14, 111, 92, 0.11) 0 2px, transparent 2px),
    rgba(248, 246, 238, 0.72);
  background-size: 20px 20px, auto;
  padding: 34px;
  text-align: center;
  cursor: pointer;
  transition: border-color 160ms ease, transform 160ms ease, background-color 160ms ease;
}

.drop-zone:hover,
.drop-zone.dragging {
  border-color: var(--green);
  background-color: rgba(47, 178, 143, 0.11);
  transform: translateY(-1px);
}

.drop-zone input {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.drop-zone strong {
  overflow-wrap: anywhere;
  font-size: 1.75rem;
  line-height: 1.05;
}

.drop-zone span:last-child {
  color: var(--muted);
}

.drop-mark {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border: 2px solid var(--ink);
  background: var(--gold);
  box-shadow: 5px 5px 0 var(--ink);
  color: var(--ink);
  font-size: 2rem;
  font-weight: 900;
  line-height: 1;
}

.eyebrow {
  color: var(--green);
  font-size: 0.74rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 750;
}

.field input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 13px 12px;
  outline: none;
}

.field input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(47, 178, 143, 0.18);
}

.run-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px;
  gap: 10px;
  align-items: start;
}

.advanced {
  position: relative;
  min-height: 40px;
  padding: 0;
  z-index: 30;
}

.advanced summary {
  display: grid;
  width: 40px;
  min-height: 40px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(248, 246, 238, 0.78);
  color: var(--ink);
  cursor: pointer;
  list-style: none;
  transition: border-color 150ms ease, background-color 150ms ease, box-shadow 150ms ease;
}

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

.advanced[open] summary,
.advanced summary:hover {
  border-color: var(--green);
  background: rgba(47, 178, 143, 0.12);
  box-shadow: 0 0 0 3px rgba(47, 178, 143, 0.12);
}

.settings-icon {
  display: grid;
  width: 18px;
  gap: 3px;
}

.settings-icon span {
  position: relative;
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.settings-icon span::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 5px;
  height: 5px;
  border: 1px solid currentColor;
  border-radius: 50%;
  background: var(--panel);
  transform: translate(-50%, -50%);
}

.settings-icon span:nth-child(1)::after {
  left: 5px;
}

.settings-icon span:nth-child(2)::after {
  left: 13px;
}

.settings-icon span:nth-child(3)::after {
  left: 8px;
}

.advanced-fields {
  position: absolute;
  top: 0;
  left: calc(100% + 12px);
  z-index: 60;
  display: none;
  width: 320px;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 36px rgba(23, 33, 29, 0.16);
  padding: 12px;
}

.advanced[open] .advanced-fields {
  display: grid;
}

.compact input {
  padding: 10px 11px;
}

.primary-action,
.ghost-action,
.new-run-button,
.tab {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--ink);
  cursor: pointer;
  font-weight: 850;
}

.primary-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--ink);
  color: white;
  padding: 0 14px;
  box-shadow: 6px 6px 0 var(--green-2);
}

.primary-action:disabled {
  border-color: var(--line-strong);
  background: #69736c;
  box-shadow: none;
  cursor: not-allowed;
  opacity: 0.72;
}

.progress-panel {
  display: grid;
  flex: 0 0 auto;
  gap: 7px;
  border-top: 1px solid var(--line);
  padding: 12px 6px 0;
}

.progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

#statusText {
  display: block;
  margin-top: 2px;
  line-height: 1.1;
}

#percentText {
  font-variant-numeric: tabular-nums;
  font-weight: 900;
  white-space: nowrap;
}

.meter {
  height: 9px;
  border: 1px solid var(--ink);
  background: var(--panel);
  overflow: hidden;
}

.meter span {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--gold), var(--coral));
  transition: width 320ms ease;
}

.progress-note {
  margin: -2px 0 0;
  min-height: 1.9rem;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.18;
}

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

.timeline li {
  display: grid;
  gap: 4px;
  align-content: start;
  min-height: 34px;
  border: 1px solid rgba(217, 213, 200, 0.72);
  background: rgba(248, 246, 238, 0.45);
  padding: 5px;
  color: var(--muted);
  font-size: 0.69rem;
  line-height: 1.05;
}

.timeline li > span:last-child {
  display: grid;
  gap: 2px;
  min-height: 0;
}

.timeline small {
  color: inherit;
  font-size: 0.55rem;
  font-weight: 750;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.timeline li.running,
.timeline li.done {
  color: var(--ink);
}

.timeline li.error {
  color: var(--coral);
}

.step-dot {
  width: 9px;
  height: 9px;
  border: 1px solid var(--line-strong);
  border-radius: 50%;
  background: var(--panel);
}

.timeline li.running .step-dot {
  border-color: var(--green);
  background: var(--green-2);
  box-shadow: 0 0 0 4px rgba(47, 178, 143, 0.14);
}

.timeline li.done .step-dot {
  border-color: var(--green);
  background: var(--green);
}

.timeline li.error .step-dot {
  border-color: var(--coral);
  background: var(--coral);
}

.timeline b {
  display: block;
  color: inherit;
  overflow: hidden;
  font-size: 0.65rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-height: 0;
  flex: 1 1 180px;
  border-top: 1px solid var(--line);
  padding: 14px 0 0;
}

.history-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 10px;
}

.history-head h2 {
  margin: 3px 0 0;
  font-size: 1rem;
  line-height: 1.1;
}

.new-run-button {
  min-height: 32px;
  border-color: var(--line);
  background: rgba(248, 246, 238, 0.78);
  color: var(--ink);
  padding: 0 10px;
  font-size: 0.78rem;
  font-weight: 850;
}

.new-run-button:hover {
  border-color: var(--green);
  background: rgba(47, 178, 143, 0.12);
}

.new-run-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.history-empty {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.3;
}

.history-list {
  display: grid;
  align-content: start;
  gap: 3px;
  min-height: 0;
  margin: 10px -6px 0;
  overflow: auto;
  padding: 0 2px 2px;
  list-style: none;
}

.history-item {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  transition: background-color 150ms ease, border-color 150ms ease;
}

.history-item:hover {
  background: rgba(248, 246, 238, 0.82);
}

.history-item.starred {
  background: rgba(200, 135, 25, 0.07);
}

.history-item.active {
  border-color: rgba(14, 111, 92, 0.22);
  background: rgba(47, 178, 143, 0.12);
}

.history-main {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 9px;
  min-width: 0;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 7px 0 7px 8px;
  text-align: left;
  cursor: pointer;
}

.history-main-edit {
  cursor: default;
}

.history-main:hover strong {
  color: var(--green);
}

.history-thumb {
  width: 34px;
  height: 34px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background:
    radial-gradient(circle at 10px 10px, rgba(14, 111, 92, 0.13) 0 1.5px, transparent 1.5px),
    var(--panel);
  background-size: 11px 11px;
}

.history-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.history-copy {
  min-width: 0;
}

.history-copy strong {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-size: 0.84rem;
  line-height: 1.15;
}

.history-title-row {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 5px;
}

.history-title-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-meta {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.71rem;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-detail {
  display: none;
}

.history-rename-form {
  display: grid;
  min-width: 0;
  gap: 6px;
}

.history-rename-input {
  width: 100%;
  min-height: 30px;
  border: 1px solid var(--green);
  border-radius: 7px;
  background: var(--panel);
  color: var(--ink);
  padding: 5px 8px;
  font-size: 0.84rem;
  font-weight: 850;
  outline: none;
}

.history-rename-input:focus {
  box-shadow: 0 0 0 3px rgba(47, 178, 143, 0.16);
}

.history-rename-actions {
  display: flex;
  gap: 6px;
}

.history-rename-actions button {
  min-height: 26px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 8px;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 850;
}

.history-rename-save {
  background: var(--ink);
  color: white;
}

.history-rename-cancel {
  background: rgba(248, 246, 238, 0.78);
  color: var(--ink);
}

.history-star {
  flex: 0 0 12px;
  width: 12px;
  height: 12px;
  color: var(--gold);
  fill: currentColor;
  stroke: rgba(23, 33, 29, 0.28);
  stroke-width: 0.8px;
  overflow: visible;
}

.history-menu {
  position: relative;
  align-self: center;
  margin: 0 4px 0 0;
}

.history-menu summary {
  display: flex;
  width: 30px;
  height: 30px;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 900;
  list-style: none;
}

.history-menu summary::-webkit-details-marker {
  display: none;
}

.history-menu[open] summary,
.history-menu summary:hover {
  border-color: var(--line);
  background: var(--panel);
  color: var(--ink);
}

.kebab-icon {
  display: inline-flex;
  width: 16px;
  height: 16px;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.kebab-icon span {
  display: block;
  width: 3.5px;
  height: 3.5px;
  border-radius: 999px;
  background: currentColor;
}

.history-menu-panel {
  position: fixed;
  top: var(--history-menu-top, 0);
  left: var(--history-menu-left, 0);
  z-index: 60;
  display: grid;
  min-width: 132px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 14px 28px rgba(23, 33, 29, 0.15);
  padding: 4px;
}

.history-menu-panel button {
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 8px 9px;
  text-align: left;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 800;
}

.history-menu-panel button:hover {
  background: rgba(47, 178, 143, 0.1);
}

.history-menu-panel button[data-history-action="delete"]:hover {
  background: rgba(225, 95, 63, 0.1);
  color: var(--coral);
}

.workspace {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: minmax(420px, 1fr);
  gap: 0;
  min-height: 0;
  min-width: 0;
  padding: 24px;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: end;
  flex: 0 0 auto;
}

.ghost-action {
  display: inline-grid;
  place-items: center;
  min-width: 92px;
  background: var(--panel);
  color: var(--ink);
  padding: 0 13px;
  text-decoration: none;
}

.ghost-action:disabled,
.ghost-action.disabled {
  pointer-events: none;
  opacity: 0.45;
}

.preview-stage {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.8);
  box-shadow: var(--shadow);
}

.preview-header {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 12px;
}

.tabs {
  display: flex;
  gap: 8px;
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  padding: 0;
}

.tab {
  background: transparent;
  color: var(--muted);
  padding: 0 14px;
}

.tab.active {
  background: var(--green);
  border-color: var(--green);
  color: white;
}

.pane {
  position: relative;
  display: none;
  min-height: 0;
  overflow: auto;
  padding: 18px;
}

.pane.active {
  display: grid;
}

#inputPane {
  min-height: 100%;
}

#inputPane.has-content .primary-drop {
  display: none;
}

.pane img {
  display: none;
  max-width: 100%;
  max-height: calc(100vh - 250px);
  align-self: center;
  justify-self: center;
  border: 1px solid var(--line);
  background: #111;
}

.pane img.ready {
  display: block;
}

.empty-state {
  align-self: center;
  justify-self: center;
  color: var(--muted);
  font-weight: 800;
}

.pane img.ready + .empty-state,
.has-content .empty-state {
  display: none;
}

.boundary-pane {
  padding: 0;
  overflow: hidden;
  background: #f8f6ee;
}

.boundary-map {
  display: none;
  width: 100%;
  min-height: 520px;
}

.boundary-map.ready {
  display: block;
}

#boundarySvg {
  display: none;
  width: 100%;
  min-height: 420px;
}

#boundarySvg.ready {
  display: block;
}

.boundary-pane .empty-state {
  padding: 18px;
}

.maplibregl-ctrl-bottom-left,
.maplibregl-ctrl-bottom-right {
  max-width: calc(100% - 18px);
}

.maplibregl-ctrl-attrib {
  border-radius: 8px 0 0 0;
  background: rgba(248, 246, 238, 0.86);
  color: var(--muted);
}

.maplibregl-ctrl-attrib a {
  color: var(--green);
}

.maplibregl-ctrl-group {
  overflow: hidden;
  border: 1px solid rgba(23, 33, 29, 0.18);
  border-radius: 8px;
  background: rgba(248, 246, 238, 0.92);
  box-shadow: 0 8px 28px rgba(23, 33, 29, 0.14);
}

.maplibregl-ctrl-group button {
  background-color: rgba(248, 246, 238, 0.92);
}

.maplibregl-ctrl button .maplibregl-ctrl-icon {
  filter: sepia(0.2) saturate(0.8) hue-rotate(80deg);
}

.code-pane {
  height: 100%;
  min-height: 0;
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: #16382f;
  background: #fbfaf5;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.84rem;
}

.code-pane.active {
  display: block;
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .control-panel {
    order: 2;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    order: 1;
    grid-template-rows: minmax(360px, 1fr);
    height: min(720px, calc(100vh - 36px));
    padding: 18px;
  }

  .advanced-fields {
    top: calc(100% + 8px);
    right: 0;
    left: auto;
    width: min(320px, calc(100vw - 28px));
  }

}

@media (max-width: 560px) {
  .control-panel,
  .workspace {
    padding: 14px;
  }

  .workspace {
    height: min(680px, calc(100vh - 28px));
  }

  .preview-header {
    align-items: stretch;
    flex-direction: column;
  }

  .tabs {
    width: 100%;
  }

  .actions {
    width: 100%;
    justify-content: stretch;
  }

  .ghost-action {
    flex: 1;
  }

}
