:root {
  --accent: #2c3e50;
  --accent-strong: #182c41;
  --header-bg: #2c3e50;
  --sidebar-bg: #fafbfc;
  --sidebar-border: #e3e6ea;
  --text: #1f2933;
  --text-muted: #5b6573;
  --row-hover: #eef3f1;
  --caret-color: #8a94a3;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.08);
  --radius-sm: 3px;
  --radius-md: 6px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Inter", "Segoe UI", Helvetica, Arial, sans-serif;
  font-feature-settings: "cv11", "ss01";
  color: var(--text);
  background: #f3f5f7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── Header ─────────────────────────────────────────── */

.app-header {
  height: 52px;
  background: linear-gradient(180deg, #34495e 0%, #2c3e50 100%);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 22px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.18);
  z-index: 2;
  position: relative;
}

.app-header::before {
  content: "";
  display: block;
  width: 6px;
  height: 22px;
  border-radius: 2px;
  background: var(--accent);
  margin-right: 14px;
}

.app-header h1 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.3px;
}

.app-body {
  display: flex;
  height: calc(100% - 52px);
  position: relative;
}

/* ─── Sidebar ────────────────────────────────────────── */

.sidebar {
  width: 296px;
  background: var(--sidebar-bg);
  color: var(--text);
  border-right: 1px solid var(--sidebar-border);
  overflow: auto;
  transition: width 0.2s ease;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
}

.sidebar.collapsed {
  width: 0;
  border-right: 0;
  box-shadow: none;
}

.sidebar-header {
  padding: 14px 18px 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--sidebar-border);
}

/* Layer group ("Southern Rocky Mountains") */

.layer-group {
  padding: 8px 0;
}

.layer-group-header {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  border-radius: var(--radius-sm);
  margin: 0 6px;
  transition: background 0.12s;
}

.layer-group-header:hover {
  background: var(--row-hover);
}

.group-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
}

.layer-list {
  list-style: none;
  margin: 4px 0 0;
  padding: 0 6px 0 22px;
}

/* ─── Caret / chevron ─────────────────────────────────── */

.caret {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  color: var(--caret-color);
  cursor: pointer;
  user-select: none;
  transition: transform 0.15s ease;
  flex-shrink: 0;
}

.caret::before {
  content: "";
  display: block;
  width: 6px;
  height: 6px;
  border-right: 1.6px solid currentColor;
  border-bottom: 1.6px solid currentColor;
  transform: rotate(-45deg);
  margin-left: -2px;
}

/* Group caret (collapsed = pointing right, open = pointing down) */
.layer-group .caret::before {
  transform: rotate(45deg);
}
.layer-group.collapsed .caret::before {
  transform: rotate(-45deg);
}

.layer-group.collapsed .layer-list {
  display: none;
}

/* Layer row caret */
.layer-row .caret::before {
  transform: rotate(-45deg);
}
.layer-row:not(.collapsed) .caret::before {
  transform: rotate(45deg);
}

/* ─── Layer rows ─────────────────────────────────────── */

.layer-row {
  display: block;
  margin: 1px 0;
}

.layer-row-main {
  display: flex;
  align-items: center;
  padding: 6px 8px;
  gap: 8px;
  border-radius: var(--radius-sm);
  transition: background 0.12s;
}

.layer-row-main:hover {
  background: var(--row-hover);
}

.layer-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}

/* ─── Custom checkboxes ──────────────────────────────── */

input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  margin: 0;
  border: 1.5px solid #b8bfc9;
  border-radius: var(--radius-sm);
  background: #fff;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: border-color 0.12s, background 0.12s, box-shadow 0.12s;
}

input[type="checkbox"]:hover {
  border-color: var(--accent);
}

input[type="checkbox"]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(46, 125, 84, 0.25);
}

input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
  
}

input[type="checkbox"]:checked::after {
  content: "";
  display: block;
  width: 4px;
  height: 8px;
  border-right: 2px solid #fff;
  border-bottom: 2px solid #fff;
  transform: rotate(45deg) translate(-1px, -1px);
}

/* ─── Legend ─────────────────────────────────────────── */

.legend {
  list-style: none;
  margin: 2px 0 8px 12px;
  padding: 4px 0 4px 18px;
  border-left: 2px solid #e3e6ea;
}

.layer-row.collapsed .legend {
  display: none;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 3px 6px;
  font-size: 12px;
  line-height: 1.35;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
}

.legend-item:hover {
  background: var(--row-hover);
  color: var(--text);
}

.swatch {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  border-radius: var(--radius-sm);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.4);
}

.legend-name {
  flex: 1;
}

/* ─── Sidebar collapse handle ─────────────────────────── */

.sidebar-collapse {
  position: absolute;
  top: 50%;
  left: 296px;
  transform: translateY(-50%);
  width: 18px;
  height: 44px;
  background: #fff;
  color: var(--text-muted);
  border: 1px solid var(--sidebar-border);
  border-left: 0;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  cursor: pointer;
  z-index: 3;
  font-size: 16px;
  line-height: 1;
  transition: left 0.2s ease, color 0.12s, background 0.12s;
  padding: 0;
  box-shadow: var(--shadow-sm);
}

.sidebar-collapse:hover {
  color: var(--accent);
  background: #fff;
}

.sidebar.collapsed + .sidebar-collapse {
  left: 0;
}

.sidebar.collapsed + .sidebar-collapse::before {
  content: "›";
}

.sidebar:not(.collapsed) + .sidebar-collapse::before {
  content: "‹";
}

/* ─── Map ────────────────────────────────────────────── */

.map-wrap {
  flex: 1;
  position: relative;
  background: #1a1a1a;
}

.map {
  width: 100%;
  height: 100%;
}

/* OpenLayers control polish */
.ol-control button {
  background: rgba(255, 255, 255, 0.92) !important;
  color: var(--text) !important;
  font-weight: 600;
  border-radius: var(--radius-sm) !important;
  transition: background 0.12s, color 0.12s;
}

.ol-control button:hover {
  background: #fff !important;
  color: var(--accent) !important;
}

.ol-zoom {
  background: transparent !important;
  box-shadow: var(--shadow-md);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.ol-scale-line {
  background: rgba(31, 41, 51, 0.7);
  border-radius: var(--radius-sm);
}

.ol-attribution {
  background: rgba(255, 255, 255, 0.85) !important;
  border-radius: var(--radius-sm) 0 0 0 !important;
  font-size: 11px;
}

/* ─── Scrollbar polish (WebKit / Chromium) ───────────── */

.sidebar::-webkit-scrollbar {
  width: 8px;
}
.sidebar::-webkit-scrollbar-thumb {
  background: #cdd3da;
  border-radius: 4px;
}
.sidebar::-webkit-scrollbar-thumb:hover {
  background: #b3bbc4;
}
.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

/* ─── Header actions / shared buttons ─────────────────── */

.app-header {
  justify-content: space-between;
}

.app-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.12s, color 0.12s, border-color 0.12s, box-shadow 0.12s;
  line-height: 1.2;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn[hidden] { display: none; }

.btn-accent {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.btn-accent:hover:not(:disabled) {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.btn-secondary {
  background: #fff;
  color: var(--text);
  border-color: #c4cad3;
}
.btn-secondary:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-ghost {
  

    background: #cfcfcf;
    color: #2f4356;
    border-color: rgba(255, 255, 255, 0.25);

}
.app-header .btn-ghost { color: #2f4255; }
.app-header .btn-ghost:hover { color: #fff; border-color: rgba(255, 255, 255, 0.5); }
.modal .btn-ghost { color: var(--text-muted); border-color: #c4cad3; }
.modal .btn-ghost:hover { color: var(--text); border-color: #94a0ad; }

.btn-link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--accent);
  font: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.btn-link + .btn-link { margin-left: 12px; }

/* ─── Modal ───────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  backdrop-filter: blur(2px);
}

.modal-backdrop[hidden] { display: none; }

.draw-prompt {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1001;
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 8px 8px 8px 18px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.25);
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--sidebar-border);
}
.draw-prompt[hidden] { display: none; }
.draw-prompt .btn-sm {
  padding: 4px 12px;
  font-size: 12px;
}
.draw-prompt .btn-ghost {
  color: var(--text-muted);
  border-color: #c4cad3;
  background: #fff;
}
.draw-prompt .btn-ghost:hover {
  color: var(--text);
  border-color: #94a0ad;
}

.modal {
  background: #fff;
  color: var(--text);
  border-radius: 10px;
  width: min(720px, 100%);
  max-height: calc(100vh - 48px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.35);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--sidebar-border);
}

.modal-header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.modal-close {
  background: transparent;
  border: 0;
  font-size: 24px;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}
.modal-close:hover {
  background: #f3f5f7;
  color: var(--text);
}

.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-section {
  padding: 10px 0 14px;
  border-bottom: 1px solid #eef0f3;
}
.modal-section:last-child { border-bottom: 0; }

.modal-section h3 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.hint {
  margin: 0 0 8px;
  color: var(--text-muted);
  font-size: 12.5px;
  line-height: 1.4;
}
.hint code {
  background: #f1f3f5;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 11.5px;
}
.hint-inline {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
  text-transform: none;
  letter-spacing: 0;
  margin-left: 6px;
}

.aoi-tabs {
  display: inline-flex;
  background: #f1f3f5;
  border-radius: var(--radius-md);
  padding: 3px;
  margin-bottom: 10px;
}
.aoi-tab {
  background: transparent;
  border: 0;
  padding: 6px 12px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.aoi-tab.is-active {
  background: #fff;
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.aoi-panel.hidden { display: none; }

.aoi-actions {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.aoi-summary {
  margin-top: 10px;
  padding: 8px 12px;
  background: #f7f9fa;
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  display: flex;
  gap: 8px;
}
.aoi-summary-label { font-weight: 600; color: var(--text-muted); }
.aoi-over-cap { color: #b3261e; font-weight: 600; }

.field {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}
.field > span:first-child { color: var(--text-muted); min-width: 70px; }
.field select {
  flex: 1;
  padding: 6px 10px;
  font: inherit;
  font-size: 13px;
  border: 1px solid #c4cad3;
  border-radius: var(--radius-sm);
  background: #fff;
}

.level-checks {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px 16px;
}
.level-checks label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  cursor: pointer;
}

.class-filter {
  display: grid;
  gap: 6px;
}
.class-filter-group {
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-sm);
  background: #fafbfc;
}
.class-filter-group summary {
  cursor: pointer;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 500;
  display: flex;
  justify-content: space-between;
  align-items: center;
  list-style: none;
}
.class-filter-group summary::-webkit-details-marker { display: none; }
.class-filter-group summary::before {
  content: "";
  width: 6px; height: 6px;
  border-right: 1.6px solid var(--caret-color);
  border-bottom: 1.6px solid var(--caret-color);
  transform: rotate(-45deg);
  margin-right: 10px;
  transition: transform 0.15s;
}
.class-filter-group[open] summary::before { transform: rotate(45deg); }
.class-filter-count {
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 500;
}
.class-filter-group ul {
  list-style: none;
  margin: 0;
  padding: 0 12px 8px 24px;
  max-height: 220px;
  overflow-y: auto;
}
.class-filter-controls {
  padding: 0 12px 6px 24px;
}
.legend-item-check {
  cursor: pointer;
}
.legend-item-check input { margin-right: 4px; }

.modal-error {
  background: #fff3f2;
  color: #8a1f15;
  border: 1px solid #f3c5c0;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin-top: 10px;
  font-size: 12.5px;
  white-space: pre-wrap;
}

.modal-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-top: 1px solid var(--sidebar-border);
  background: #fafbfc;
}
.modal-caps {
  font-size: 11.5px;
  color: var(--text-muted);
  flex: 1;
}

/* ─── Status page ────────────────────────────────────── */

body.status-page { background: #f3f5f7; color: var(--text); }

.status-main {
  max-width: 720px;
  margin: 32px auto;
  padding: 0 20px;
}

.status-card {
  background: #fff;
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  padding: 22px 26px;
}

.status-row {
  display: flex;
  gap: 16px;
  align-items: baseline;
  padding: 6px 0;
  border-bottom: 1px dashed #eef0f3;
  font-size: 13.5px;
}
.status-row:last-of-type { border-bottom: 0; }
.status-key {
  width: 120px;
  flex-shrink: 0;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.status-job-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  background: #f1f3f5;
  padding: 2px 6px;
  border-radius: 3px;
  word-break: break-all;
}

.status-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: #eef0f3;
  color: var(--text);
}
.status-badge[data-status="queued"]   { background: #fff8e1; color: #8a6d1a; }
.status-badge[data-status="running"]  { background: #e3f2fd; color: #0b5cad; }
.status-badge[data-status="done"]     { background: #e8f5ec; color: var(--accent); }
.status-badge[data-status="error"]    { background: #fff3f2; color: #8a1f15; }
.status-badge[data-status="expired"]  { background: #f1f3f5; color: var(--text-muted); }

.status-progress {
  height: 4px;
  background: #eef0f3;
  border-radius: 999px;
  overflow: hidden;
  margin: 18px 0;
  position: relative;
}
.status-progress[hidden] { display: none; }
.status-progress-bar {
  position: absolute;
  top: 0; left: -40%;
  height: 100%;
  width: 40%;
  background: var(--accent);
  border-radius: 999px;
  animation: statusSlide 1.2s linear infinite;
}
@keyframes statusSlide {
  0%   { left: -40%; }
  100% { left: 100%; }
}

.status-actions { margin-top: 12px; }

.status-error {
  background: #fff3f2;
  color: #8a1f15;
  border: 1px solid #f3c5c0;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-top: 14px;
  font-size: 12.5px;
}
.status-error pre {
  margin: 6px 0 0;
  white-space: pre-wrap;
  font-size: 12px;
}

.status-foot {
  color: var(--text-muted);
  font-size: 12px;
  margin: 18px 0 0;
}
