:root {
  --bg: #eef2f6;
  --panel: #ffffff;
  --panel-2: #f6f8fb;
  --line: #d5dce6;
  --line-strong: #b8c3d2;
  --text: #1f2937;
  --muted: #627084;
  --accent: #1667c2;
  --accent-2: #0f55a7;
  --ok: #16803a;
  --warn: #a15c00;
  --danger: #c7352b;
  --chip: #edf2f8;
  --shadow: rgba(15, 23, 42, .14);
  --mono: "Cascadia Code", "JetBrains Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { width: 100%; height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Apple SD Gothic Neo", Arial, sans-serif;
  font-size: 13px;
  overflow: hidden;
}
button, input { font: inherit; color: inherit; }

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  grid-template-rows: 48px minmax(0, 1fr) 28px;
  grid-template-areas: "top top" "map panel" "status status";
  width: 100vw;
  height: 100vh;
}

/* Top bar */
.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.brand {
  flex: 0 0 auto;
  font-weight: 800;
  letter-spacing: .3px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
}
.brand:hover { color: var(--accent); }
.brand-mark {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  border-radius: 6px;
  background: url("/static/landformstudio.png") center / contain no-repeat;
  color: transparent;
  overflow: hidden;
}
.brand-sub { color: var(--muted); font-weight: 600; font-size: 12px; }
.search { position: relative; flex: 1; min-width: 180px; max-width: 520px; display: flex; gap: 6px; }
.search input {
  flex: 1; min-height: 32px; background: #fff; border: 1px solid var(--line-strong);
  border-radius: 6px; padding: 6px 10px; outline: none;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(22, 103, 194, .14); }
.search button { min-height: 32px; padding: 0 14px; background: var(--panel-2); border: 1px solid var(--line-strong); border-radius: 6px; cursor: pointer; }
.search button:hover { border-color: var(--accent); }
.search-results {
  display: none; position: absolute; top: 38px; left: 0; right: 0; z-index: 1200;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; overflow: hidden;
  box-shadow: 0 12px 30px var(--shadow);
}
.search-results.visible { display: block; }
.search-results button {
  display: flex; flex-direction: column; gap: 2px; width: 100%; text-align: left;
  border: 0; border-bottom: 1px solid var(--line); background: transparent; padding: 8px 11px; cursor: pointer;
}
.search-results button:hover { background: var(--chip); }
.search-result-label { font-weight: 600; color: var(--text); }
.search-result-detail { font-size: 11px; color: var(--muted); }
.search-message { padding: 10px; color: var(--muted); }
.search-message.error { color: var(--danger); }
.topbar-right { display: flex; align-items: center; gap: 6px; margin-left: auto; min-width: 0; overflow: hidden; }
.badge { flex: 0 1 auto; min-width: 0; color: #435268; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Map */
.map-area { grid-area: map; position: relative; min-width: 0; min-height: 0; }
#map { width: 100%; height: 100%; background: #dde6ef; }
.leaflet-container { background: #dde6ef; }
.leaflet-control-zoom a {
  color: var(--text);
}
/* OpenStreetMap's usage policy requires this attribution to stay visible -
   just made small/low-contrast so it's unobtrusive rather than removed. */
.leaflet-control-attribution {
  background: rgba(255, 255, 255, .55);
  color: #6b7688;
  font-size: 9px;
  padding: 0 4px;
}
.leaflet-control-attribution a { color: #6b7688; }

/* Panel */
.panel { grid-area: panel; min-width: 0; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; overflow-x: hidden; }
.sec { padding: 14px; border-bottom: 1px solid var(--line); }
.sec-search .search { width: 100%; max-width: none; min-width: 0; margin-bottom: 10px; }
.sec-search .search-results { top: 38px; }
.sec-title { margin: 0 0 10px; font-size: 12px; letter-spacing: .4px; color: var(--muted); text-transform: uppercase; font-weight: 700; }
.muted-box { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; color: #49576b; white-space: pre-line; font-size: 12px; }
.public-panel {
  margin-top: 10px;
  padding: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.public-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.public-title { font-size: 12px; font-weight: 800; color: var(--text); }
.public-status {
  flex: 0 0 auto;
  max-width: 150px;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.public-address {
  min-height: 28px;
  margin-bottom: 8px;
  color: #49576b;
  font-size: 11px;
  line-height: 1.35;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
.public-links { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.public-link {
  min-width: 0;
  min-height: 58px;
  padding: 7px 5px;
  background: var(--panel-2);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  cursor: pointer;
  text-align: center;
}
.public-link:hover:not(:disabled) { border-color: var(--accent); background: #eef5ff; }
.public-link:disabled { opacity: .48; cursor: not-allowed; }
.public-link-main {
  display: block;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.25;
}
.public-link-sub {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.25;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 11px; color: var(--muted); }
.field input { background: #fff; border: 1px solid var(--line-strong); border-radius: 6px; padding: 7px 8px; outline: none; }
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(22, 103, 194, .14); }
.hint { margin: 8px 0 0; color: var(--muted); font-size: 11px; }

.btn { width: 100%; min-height: 36px; background: var(--panel-2); border: 1px solid var(--line-strong); border-radius: 6px; cursor: pointer; font-weight: 600; }
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-2); }
.btn-accent { display: block; margin-top: 8px; background: var(--ok); color: #fff; border-color: var(--ok); text-align: center; line-height: 34px; text-decoration: none; }

/* Profile chips */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 6px 12px; background: var(--chip); border: 1px solid var(--line); border-radius: 6px; cursor: pointer; font-weight: 600; font-size: 12px; }
.chip:hover { border-color: var(--accent); }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.chip.disabled { opacity: .4; cursor: not-allowed; }
.chip-icon { display: inline-flex; align-items: center; gap: 6px; }
.chip-icon svg { width: 16px; height: 16px; flex: 0 0 auto; }

/* Options */
.opt-row { display: flex; flex-direction: column; align-items: stretch; gap: 6px; margin-bottom: 10px; }
.opt-label { color: var(--muted); font-size: 12px; }
.seg { display: flex; width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg-btn { flex: 1 1 0; min-width: 0; border: 0; background: transparent; padding: 6px 8px; cursor: pointer; color: var(--muted); border-left: 1px solid var(--line); font-size: 12px; white-space: nowrap; }
.seg-btn:first-child { border-left: 0; }
.seg-btn.active { background: var(--accent); color: #fff; font-weight: 700; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 12px; color: var(--text); cursor: pointer; }
.tag { font-size: 10px; color: var(--warn); border: 1px solid var(--warn); border-radius: 4px; padding: 0 4px; }

/* Layers */
.layer-group { margin-bottom: 10px; }
.layer-group-title { font-size: 10px; color: var(--muted); letter-spacing: .5px; margin-bottom: 4px; }
.layer { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 5px 6px; border-radius: 5px; font-size: 12px; cursor: pointer; }
.layer:hover { background: var(--panel-2); }
.layer.disabled { opacity: .5; cursor: not-allowed; }
.layer input { flex: 0 0 auto; margin-left: auto; }
.layer .tag { flex: 0 0 auto; margin-left: 0; white-space: nowrap; }
.swatch { width: 12px; height: 12px; border-radius: 3px; background: var(--c); border: 1px solid rgba(15,23,42,.18); }

/* Preview */
.preview { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 12px; font-size: 12px; }
.preview dt { color: var(--muted); }
.preview dd { margin: 0; font-family: var(--mono); }
.preview-panel-block { margin-bottom: 14px; }
.preview-subtitle { margin: 0 0 8px; color: var(--text); font-size: 12px; font-weight: 800; }

/* Job */
.jobbar { margin-top: 8px; height: 6px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.jobfill { height: 100%; width: 0; background: var(--accent); transition: width .25s; }

/* Status bar */
.statusbar {
  grid-area: status; display: flex; align-items: center; gap: 18px;
  padding: 0 14px; background: var(--panel); border-top: 1px solid var(--line);
  font-family: var(--mono); font-size: 11px; color: var(--muted); overflow: hidden;
}
.statusbar span { white-space: nowrap; }
.sb-job { flex: 0 0 auto; margin-left: auto; color: var(--text); }
.sb-job.running { color: var(--accent); }
.sb-job.completed { color: var(--ok); }
.sb-job.done { color: var(--ok); }
.sb-job.failed { color: var(--danger); }
.sb-job.error { color: var(--danger); }

/* Download preview - renders in the map area itself, not a popup */
.preview-viewer {
  position: absolute; inset: 0; z-index: 500;
  width: 100%; height: 100%; background: #12181f;
}
.preview-viewer canvas { display: block; }
.preview-viewer-hint {
  position: absolute; left: 10px; bottom: 8px; z-index: 502; margin: 0;
  color: rgba(255,255,255,.75); font-size: 11px;
}
.preview-loading, .preview-error {
  position: absolute; inset: 0; z-index: 501; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px;
  background: rgba(18, 24, 31, .85); color: #fff; text-align: center; padding: 20px;
}
.preview-error { color: #ffb4ac; }
.preview-spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid rgba(255,255,255,.25); border-top-color: #fff;
  animation: preview-spin .8s linear infinite;
}
@keyframes preview-spin { to { transform: rotate(360deg); } }
#previewExitBtn { margin-bottom: 10px; }

@media (max-width: 860px) {
  body { overflow: auto; }
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 48px minmax(360px, 48vh) auto 32px;
    grid-template-areas: "top" "map" "panel" "status";
    min-height: 100vh;
    height: auto;
  }
  .brand-sub, .topbar-right { display: none; }
  .panel { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .statusbar { gap: 10px; overflow-x: auto; }
  .sb-job { margin-left: 0; }
}
