:root {
  --surface: #f2f2f2;
  --panel: #ffffff;
  --ink: #1a1a1a;
  --muted: #626b64;
  --line: #dfe4dd;
  --line-strong: #bfc8bd;
  --accent: #0b5e14;
  --accent-dark: #07470e;
  --gold: #ffb300;
  --green: #0b5e14;
  --leaf: #1e7a1e;
  --grass: #6bae55;
  --blue: #327b9b;
  --amber: #ffb300;
  --sidebar: 358px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; background: var(--surface); }
button, a { font: inherit; }
button { color: inherit; }

.app-shell { height: 100%; display: grid; grid-template-rows: 58px 1fr; }
.topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 14px 0 18px;
  background: rgba(255, 255, 255, 0.97);
  border-bottom: 1px solid var(--line);
  z-index: 1001;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo {
  width: 186px; height: 38px; object-fit: contain; object-position: left center;
  flex: 0 0 auto;
}
.brand h1 { margin: 0; font-size: 15px; line-height: 1.15; letter-spacing: 0; }
.brand p { margin: 3px 0 0; font-size: 11px; color: var(--muted); }
.status-line { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 11px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--amber); }
.status-line.ready .status-dot { background: var(--green); }
.header-actions { display: flex; justify-content: flex-end; align-items: center; gap: 6px; }
.place-select-wrap {
  display: flex; align-items: center; gap: 7px; font-size: 11px; color: var(--muted);
  margin-right: 4px;
}
.place-select-wrap select {
  max-width: 150px; border: 1px solid var(--line); border-radius: 5px;
  background: white; color: var(--ink); padding: 7px 26px 7px 9px; font: inherit;
}
.icon-button {
  width: 34px; height: 34px; display: grid; place-items: center; padding: 0;
  border: 0; background: transparent; border-radius: 4px; cursor: pointer;
}
.icon-button:hover { background: #eef4ed; }
.icon-button svg { width: 17px; height: 17px; }

.workspace { position: relative; min-height: 0; overflow: hidden; }
#map { position: absolute; inset: 0; background: #e9ebe5; }
.leaflet-container { font: inherit; }
.leaflet-control-zoom a { border-radius: 0 !important; color: var(--ink); }
.leaflet-control-scale-line { border-color: var(--ink); color: var(--ink); background: rgba(255,255,255,.78); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { border-radius: 4px; box-shadow: 0 4px 18px rgba(24, 34, 27, .16); }
.leaflet-popup-content { margin: 12px 14px; font-size: 12px; line-height: 1.45; }

.sidebar {
  position: absolute; z-index: 800; top: 12px; right: 12px; bottom: 42px;
  width: var(--sidebar); display: grid; grid-template-rows: 58px 1fr;
  background: rgba(252, 252, 249, .97); border: 1px solid var(--line-strong);
  box-shadow: 0 8px 28px rgba(31, 42, 35, .14);
  transition: transform 180ms ease, opacity 180ms ease;
}
.sidebar.collapsed { transform: translateX(calc(100% + 18px)); opacity: 0; pointer-events: none; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--line); }
.tab-button {
  border: 0; background: transparent; display: grid; place-items: center; align-content: center;
  gap: 3px; font-size: 10px; color: var(--muted); cursor: pointer; position: relative;
}
.tab-button svg { width: 16px; height: 16px; }
.tab-button.active { color: var(--ink); }
.tab-button.active::after { content: ""; position: absolute; bottom: -1px; left: 18px; right: 18px; height: 2px; background: var(--gold); }
.panel-scroll { overflow: auto; overscroll-behavior: contain; }
.tab-panel { display: none; padding: 18px; animation: panel-in 160ms ease; }
.tab-panel.active { display: block; }
@keyframes panel-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; }
.eyebrow { color: var(--muted); font-size: 10px; text-transform: uppercase; font-weight: 700; }
.panel-heading h2 { margin: 3px 0 0; font-size: 20px; letter-spacing: 0; }
.text-button { border: 0; background: transparent; color: var(--accent-dark); font-size: 11px; cursor: pointer; padding: 4px; }

.layer-group { padding: 12px 0; border-top: 1px solid var(--line); }
.layer-group:first-child { border-top: 0; padding-top: 0; }
.layer-group h3, .legend h3, .tool-result h3, .profile-header h3, .buffer-control h3,
.landcover-section h3 { font-size: 12px; margin: 0; letter-spacing: 0; }
.layer-row { display: grid; grid-template-columns: 28px 1fr auto; align-items: center; min-height: 38px; }
.layer-symbol { width: 16px; height: 16px; display: grid; place-items: center; color: var(--muted); }
.layer-symbol svg { width: 15px; height: 15px; }
.layer-copy strong { display: block; font-size: 12px; font-weight: 600; }
.layer-copy small { display: block; font-size: 10px; color: var(--muted); margin-top: 1px; }
.switch { position: relative; width: 30px; height: 17px; }
.switch input { opacity: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: #c8ccc8; border-radius: 9px; cursor: pointer; transition: 150ms; }
.switch span::after { content: ""; position: absolute; width: 13px; height: 13px; left: 2px; top: 2px; background: white; border-radius: 50%; transition: 150ms; }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::after { transform: translateX(13px); }
.legend { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 5px; }
.legend h3 { margin-bottom: 10px; }
.legend-row { display: flex; gap: 9px; align-items: center; font-size: 11px; margin: 7px 0; color: #4f5752; }
.swatch { width: 22px; height: 3px; flex: 0 0 auto; }
.boundary-new { background: var(--accent); height: 7px; opacity: .75; }
.boundary-old { border-top: 2px dashed #66716a; background: transparent; }
.road { background: #9b7d50; }
.water { background: var(--blue); }
.hydro-river { background: #105f8b; height: 5px; }

.map-toolbar {
  position: absolute; z-index: 700; left: 12px; top: 12px; display: flex;
  background: rgba(252,252,249,.97); border: 1px solid var(--line-strong);
  box-shadow: 0 5px 18px rgba(31,42,35,.12);
}
.tool-button {
  min-width: 39px; height: 42px; border: 0; border-right: 1px solid var(--line);
  background: transparent; display: flex; align-items: center; gap: 6px; padding: 0 10px;
  cursor: pointer; font-size: 11px;
}
.tool-button:last-child { border-right: 0; }
.tool-button svg { width: 15px; height: 15px; }
.tool-button:hover { background: #f4f8f3; }
.tool-button.active { background: var(--green); color: white; }

.north-arrow {
  position: absolute; z-index: 600; left: 18px; bottom: 76px;
  display: grid; place-items: center; color: var(--ink); text-shadow: 0 1px 2px white;
}
.north-arrow span { font-size: 11px; font-weight: 800; }
.north-arrow svg { width: 28px; height: 28px; fill: rgba(255,255,255,.7); }
.coordinate-bar {
  position: absolute; z-index: 700; left: 12px; bottom: 12px;
  height: 28px; display: flex; align-items: center; gap: 10px; padding: 0 10px;
  background: rgba(252,252,249,.94); border: 1px solid var(--line-strong);
  font-size: 10px; color: #4c544f;
}
.divider { width: 1px; height: 12px; background: var(--line-strong); }

.empty-state { padding: 34px 12px; text-align: center; color: var(--muted); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.empty-state svg { width: 24px; height: 24px; }
.empty-state p { font-size: 11px; line-height: 1.5; max-width: 230px; margin: 10px auto 0; }
.hidden { display: none !important; }
.metric-list { margin: 0; }
.metric-list > div { display: flex; justify-content: space-between; gap: 20px; padding: 9px 0; border-top: 1px solid var(--line); font-size: 11px; }
.metric-list dt { color: var(--muted); }
.metric-list dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; font-weight: 600; }
.metric-list.compact > div { padding: 8px 0; }
.primary-button {
  width: 100%; border: 0; border-radius: 4px; background: var(--green); color: white;
  min-height: 38px; display: flex; justify-content: center; align-items: center; gap: 8px;
  font-size: 11px; cursor: pointer; margin-top: 14px;
}
.primary-button:hover { background: var(--accent-dark); }
.primary-button svg { width: 15px; height: 15px; }
.tool-result { margin-top: 18px; padding: 13px 0; border-top: 1px solid var(--line); }
.tool-result h3 { margin-top: 4px; }
.tool-result p { font-size: 11px; color: var(--muted); line-height: 1.5; margin: 5px 0 0; }
.profile-wrap { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 14px; }
.profile-header { display: flex; justify-content: space-between; }
.profile-header span { font-size: 10px; color: var(--muted); }
#profile-chart { width: 100%; height: 125px; margin-top: 8px; }

.summary-grid { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.summary-grid div { min-height: 72px; padding: 11px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.summary-grid span { display: block; color: var(--muted); font-size: 10px; }
.summary-grid strong { display: block; margin-top: 8px; font-size: 17px; font-variant-numeric: tabular-nums; }
.comparison-bar { height: 8px; display: flex; margin: 16px 0 8px; background: #e5e7e3; }
.comparison-bar span { height: 100%; }
.bar-overlap { background: var(--green); }
.bar-added { background: var(--gold); }
.buffer-control { border-top: 1px solid var(--line); padding: 16px 0; margin-top: 8px; }
.buffer-control p { margin: 4px 0 10px; font-size: 10px; color: var(--muted); }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); border: 1px solid var(--line-strong); }
.segmented button { border: 0; border-right: 1px solid var(--line); background: white; height: 30px; font-size: 10px; cursor: pointer; }
.segmented button:last-child { border-right: 0; }
.segmented button.active { background: var(--green); color: white; }
.landcover-section { border-top: 1px solid var(--line); padding-top: 15px; }
.section-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.section-row span { font-size: 9px; color: var(--muted); }
.landcover-row { display: grid; grid-template-columns: 10px 1fr auto; gap: 8px; align-items: center; font-size: 10px; padding: 4px 0; }
.landcover-dot { width: 8px; height: 8px; }
.landcover-row strong { font-variant-numeric: tabular-nums; }
.classification-note { margin: 10px 0 0; padding-top: 9px; border-top: 1px solid var(--line); color: var(--muted); font-size: 9px; line-height: 1.45; }

.download-featured {
  display: grid; gap: 9px; margin-bottom: 12px;
}
.download-card {
  display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: center;
  min-height: 76px; padding: 12px; color: inherit; text-decoration: none;
  border: 1px solid var(--line-strong); background: #ffffff;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}
.download-card:hover { background: #f7faf6; border-color: var(--green); transform: translateY(-1px); }
.download-icon {
  width: 34px; height: 34px; display: grid; place-items: center;
  background: #eaf3e8; color: var(--green); border-radius: 4px;
}
.download-card svg { width: 17px; height: 17px; }
.download-card strong, .download-card small, .download-card span { display: block; }
.download-card strong { font-size: 12px; }
.download-card small { font-size: 9px; color: var(--muted); margin-top: 3px; line-height: 1.35; }
.download-meta {
  margin-top: 7px; font-size: 9px; color: var(--accent-dark); font-weight: 700; text-transform: uppercase;
}
.download-action { color: var(--green); }
.download-list { border-top: 1px solid var(--line); }
.download-list a {
  display: grid; grid-template-columns: 28px 1fr 18px; align-items: center; min-height: 58px;
  color: inherit; text-decoration: none; border-bottom: 1px solid var(--line);
}
.download-list a:hover { background: #f4f8f3; }
.download-list svg { width: 16px; height: 16px; }
.download-list strong, .download-list small { display: block; }
.download-list strong { font-size: 11px; }
.download-list small { font-size: 9px; color: var(--muted); margin-top: 3px; }
.metadata-note { display: grid; grid-template-columns: 20px 1fr; gap: 7px; margin-top: 18px; color: var(--muted); }
.metadata-note svg { width: 16px; height: 16px; }
.metadata-note p { margin: 0; font-size: 10px; line-height: 1.5; }
.metadata-note a { color: var(--accent-dark); }

.point-label { background: white; border: 1px solid var(--ink); border-radius: 2px; box-shadow: none; color: var(--ink); font-size: 9px; font-weight: 700; padding: 1px 3px; }
.vertex-label { background: rgba(255,255,255,.84); border: 0; box-shadow: none; font-size: 8px; color: #5a625d; }

@media (max-width: 840px) {
  .topbar { grid-template-columns: 1fr auto; }
  .status-line { display: none; }
  .sidebar { width: min(92vw, 358px); }
  .tool-button span { display: none; }
  .tool-button { padding: 0; justify-content: center; width: 41px; min-width: 41px; }
  .coordinate-bar { right: 12px; overflow: hidden; white-space: nowrap; }
}

@media (max-width: 520px) {
  .brand-logo { width: 42px; height: 38px; object-fit: cover; object-position: left center; }
  .brand p { display: none; }
  .topbar { height: 52px; padding-left: 10px; }
  .app-shell { grid-template-rows: 52px 1fr; }
  .sidebar { top: 62px; left: 8px; right: 8px; bottom: 42px; width: auto; }
  .sidebar.collapsed { transform: translateY(calc(100% + 60px)); }
  .map-toolbar { left: 8px; top: 8px; }
  .north-arrow { display: none; }
  .coordinate-bar { left: 8px; right: 8px; bottom: 8px; }
  .coordinate-bar .divider, #map-scale { display: none; }
}

@media print {
  .topbar, .sidebar, .map-toolbar, .coordinate-bar { display: none !important; }
  .app-shell { display: block; }
  .workspace, #map { position: fixed; inset: 0; }
}
