:root {
  --bg: #eef2f5;
  --panel: #ffffff;
  --ink: #17212b;
  --muted: #647184;
  --line: #d8e0e8;
  --accent: #1f6f54;
  --accent-dark: #15503d;
  --danger: #be1e2d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

.app-topbar { height: 58px; padding: 0 28px; display: flex; align-items: center; gap: 14px; background: #fff; border-bottom: 1px solid var(--line); }
.topbar-brand { flex: 0 0 auto; color: var(--ink); text-decoration: none; }
.topbar-default-brand { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.topbar-badge { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 6px; color: #fff; background: var(--accent); font-size: 10px; font-weight: 800; }
.topbar-hail-brand { display: none; width: 154px; height: 48px; object-fit: cover; object-position: center; background: #315f36; border-radius: 4px; }
.breadcrumb { flex: 1; display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.breadcrumb a { color: var(--muted); text-decoration: none; }
.breadcrumb b { color: var(--ink); font-weight: 650; }
.app-topbar > span { color: var(--muted); font-size: 12px; }
html[data-association="hail"] { --accent: #4d873f; --accent-dark: #315f36; }
html[data-association="hail"] .topbar-default-brand { display: none; }
html[data-association="hail"] .topbar-hail-brand { display: block; }

.figure-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
  height: calc(100vh - 58px);
}

.tool-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  min-height: 0;
}

.panel-section {
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.panel-section:last-child {
  border-bottom: 0;
}

.panel-section h2 {
  margin: 0 0 12px;
  font-size: 13px;
  text-transform: uppercase;
  color: var(--muted);
  letter-spacing: .04em;
}

label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  color: var(--muted);
  font-weight: 700;
  font-size: 12px;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  font: inherit;
  color: var(--ink);
  background: #fff;
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 111, 84, .12);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.drop-zone {
  border: 2px dashed #b8c5d2;
  border-radius: 8px;
  padding: 22px 14px;
  min-height: 132px;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: #f7fafc;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.drop-zone.dragover {
  border-color: var(--accent);
  background: #edf8f2;
}

.drop-zone input {
  display: none;
}

.drop-title {
  font-size: 15px;
  color: var(--ink);
  font-weight: 800;
}

.drop-sub {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
}

.build-button {
  width: 100%;
  margin-top: 14px;
  padding: 12px 14px;
  font-size: 15px;
}

.orientation-setting {
  margin-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.orientation-seg {
  display: inline-flex;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2f5;
}

.orientation-seg button {
  padding: 6px 9px;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-size: 11px;
}

.orientation-seg button.active {
  color: #fff;
  background: var(--accent);
}

.status {
  min-height: 18px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.status.ok {
  color: var(--accent);
}

.status.err {
  color: var(--danger);
}

.meta-list {
  margin: 12px 0 0;
  padding: 10px 12px;
  background: #f6f8fa;
  border: 1px solid var(--line);
  border-radius: 7px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 10px;
  font-size: 12px;
}

.meta-list dt {
  color: var(--muted);
  font-weight: 700;
}

.meta-list dd {
  margin: 0;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.hidden {
  display: none !important;
}

button {
  border: 0;
  border-radius: 7px;
  padding: 9px 12px;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

button:disabled {
  opacity: .48;
  cursor: default;
}

button.primary {
  color: #fff;
  background: var(--accent);
}

button.primary:hover:not(:disabled) {
  background: var(--accent-dark);
}

button.ghost {
  color: var(--ink);
  background: #edf1f5;
  border: 1px solid var(--line);
}

button.ghost:hover:not(:disabled) {
  background: #e0e7ee;
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.advanced-settings summary {
  cursor: pointer;
  font-weight: 800;
  color: var(--ink);
  list-style-position: outside;
}

.advanced-settings label:first-of-type {
  margin-top: 14px;
}

.advanced-settings label {
  margin-top: 12px;
}

.hint {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.preview-panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
}

.figure-preview {
  position: relative;
  flex: 0 0 auto;
  width: 100%;
  max-height: 100%;
  aspect-ratio: 1280 / 900;
  background: #c9d1d9;
  border: 1px solid #aeb9c4;
  overflow: hidden;
}

.figure-preview[data-orientation="portrait"] {
  width: min(100%, calc((100vh - 126px) * 0.703125));
  aspect-ratio: 900 / 1280;
  align-self: center;
}

#figure-map {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.preview-inset {
  position: absolute;
  left: 12px;
  top: 12px;
  width: 29%;
  height: 34%;
  min-width: 280px;
  min-height: 210px;
  z-index: 2;
  border: 1px solid rgba(0, 0, 0, .18);
  background: #e8edf1;
  overflow: hidden;
  pointer-events: none;
}

#overview-map {
  width: 100%;
  height: 100%;
}

.inset-site-target {
  position: absolute;
  z-index: 500;
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translate(-50%, -50%);
  border: 4px solid #fff;
  border-radius: 50%;
  background: #be1e2d;
  box-shadow: 0 1px 5px rgba(0,0,0,.65);
  pointer-events: none;
}

.inset-site-target span {
  position: absolute;
  left: 20px;
  top: 50%;
  transform: translateY(-50%);
  padding: 3px 7px;
  border: 1px solid #be1e2d;
  border-radius: 4px;
  background: rgba(255,255,255,.97);
  color: #8f1522;
  font: 700 11px/1.2 Arial, sans-serif;
  letter-spacing: .04em;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}

.leaflet-control-attribution {
  display: none;
}

.figure-preview .leaflet-tile {
  filter: saturate(.88) brightness(1.02);
}

.preview-logo,
.preview-north,
.preview-legend,
.preview-scale {
  position: absolute;
  z-index: 3;
  pointer-events: none;
}

.preview-logo {
  left: 18px;
  bottom: 18px;
  width: min(220px, 22vw);
  max-height: 160px;
  object-fit: contain;
  object-position: left bottom;
}

.preview-north {
  top: 14px;
  right: 18px;
  width: 54px;
  height: 76px;
  color: #fff;
  text-align: center;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .4));
}

.preview-north span {
  display: block;
  font-weight: 700;
  font-size: 15px;
  line-height: 18px;
}

.north-mark {
  position: relative;
  width: 40px;
  height: 48px;
  margin: 0 auto;
}

.north-mark::before,
.north-mark::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 0;
  width: 15px;
  height: 46px;
  border: 3px solid #fff;
  border-bottom: 0;
  transform-origin: 50% 100%;
}

.north-mark::before {
  transform: translateX(-50%) rotate(-30deg) skewY(-18deg);
}

.north-mark::after {
  transform: translateX(-50%) rotate(30deg) skewY(18deg);
}

.preview-legend {
  left: min(25vw, 320px);
  bottom: 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255, 255, 255, .95);
  color: #111;
  padding: 8px 12px;
  border-radius: 3px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, .18);
  font-size: 16px;
}

.legend-swatch {
  width: 34px;
  height: 25px;
  border: 4px solid var(--danger);
  border-radius: 4px;
  background: rgba(255, 255, 255, .2);
  flex: 0 0 auto;
}

.preview-scale {
  right: 44px;
  bottom: 24px;
  width: 38%;
  min-width: 260px;
  height: 48px;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .6);
}

.scale-labels {
  position: relative;
  height: 22px;
  font-size: 15px;
}

.scale-labels span {
  position: absolute;
  transform: translateX(-50%);
}

.scale-labels span:first-child {
  transform: none;
}

.scale-labels span:last-child {
  transform: translateX(-100%);
}

.scale-line {
  height: 18px;
  border-left: 2px solid #fff;
  border-right: 2px solid #fff;
  border-bottom: 2px solid #fff;
  position: relative;
}

.scale-tick {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #fff;
}

.download-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  max-height: 40vh;
  overflow: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.export-figure {
  margin: 0;
}

.export-figure figcaption {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink, #1f2933);
  margin-bottom: 4px;
}

.download-wrap img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 4px;
}

@media (max-width: 900px) {
  .app-topbar { padding: 0 14px; }
  .app-topbar > span { display: none; }
  .download-wrap { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
  .app-topbar { gap: 8px; padding: 0 10px; }
  .topbar-hail-brand { width: 118px; }
  .breadcrumb { min-width: 0; gap: 4px; font-size: 11px; }
  .breadcrumb b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .figure-shell { gap: 12px; padding: 12px; }
  .preview-inset { left: 6px; top: 6px; width: 30%; height: 36%; min-width: 0; min-height: 0; }
  .preview-logo { left: 6px; bottom: 6px; width: 64px; max-height: 46px; }
  .preview-north { top: 5px; right: 5px; transform: scale(.62); transform-origin: top right; }
  .preview-legend { left: 35%; top: 7px; bottom: auto; max-width: 45%; gap: 5px; padding: 5px 7px; font-size: 10px; }
  .legend-swatch { width: 20px; height: 14px; border-width: 2px; }
  .preview-scale { right: 7px; bottom: 7px; width: 53%; min-width: 0; height: 30px; }
  .scale-labels { height: 14px; font-size: 9px; }
  .scale-line { height: 11px; border-width: 1px; }
}

@media (max-width: 900px) {
  .figure-shell {
    grid-template-columns: 1fr;
    height: auto;
  }

  .tool-panel {
    overflow: visible;
  }

  .preview-legend {
    left: 18px;
    bottom: 170px;
    font-size: 13px;
  }

  .preview-scale {
    right: 18px;
    width: 44%;
    min-width: 190px;
  }
}

@media (max-width: 520px) {
  .preview-legend { left: 35%; top: 7px; bottom: auto; max-width: 45%; gap: 5px; padding: 5px 7px; font-size: 10px; }
  .preview-scale { right: 7px; bottom: 7px; width: 53%; min-width: 0; height: 30px; }
  .scale-labels span:nth-child(even) { display: none; }
}
