*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  background: #f2f2ee;
  color: #1a1a1a;
  font-size: 15px;
  line-height: 1.5;
}

/* ── Layout ──────────────────────────────────────────────────────── */
.layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 420px;
  min-width: 300px;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 1.5rem 1.25rem 3rem;
  background: #f2f2ee;
  border-right: 1px solid #ddd;
}

.map-panel {
  flex: 1;
  overflow: hidden;
  position: relative;
}

#map-lock {
  position: absolute;
  inset: 0;
  z-index: 1000;
  cursor: not-allowed;
}

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

/* ── Headings ────────────────────────────────────────────────────── */
h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: #c8102e;
  margin-bottom: 2rem;
  letter-spacing: -0.01em;
}
h1 .arrow { color: #888; font-weight: 300; }

h2 {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #888;
  margin-bottom: 0.75rem;
}

section { margin-bottom: 1.75rem; }

/* ── Search ──────────────────────────────────────────────────────── */
.search-row {
  display: flex;
  gap: 0.5rem;
}
.search-row input { flex: 1; }

#search-results {
  list-style: none;
  background: #fff;
  border: 1px solid #ccc;
  border-top: none;
  border-radius: 0 0 4px 4px;
  max-height: 180px;
  overflow-y: auto;
}
#search-results:empty { display: none; }
#search-results li {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  font-size: 0.875rem;
  border-bottom: 1px solid #eee;
}
#search-results li:last-child { border-bottom: none; }
#search-results li:hover { background: #f5f5f5; }

/* ── Coordinates ─────────────────────────────────────────────────── */
.coord-row {
  display: flex;
  gap: 1rem;
  margin-top: 0.75rem;
}
.coord-row label {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: #666;
  font-weight: 500;
}
.coord-row .size-input { width: 100%; }
.coord-row .size-input input { width: 100%; min-width: 0; }

/* Hide number-input spinner arrows on read-only fields (lat/lon) — the arrows
   are misleading when the value can't be edited. */
.coord-row input[type="number"][readonly]::-webkit-inner-spin-button,
.coord-row input[type="number"][readonly]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.coord-row input[type="number"][readonly] { -moz-appearance: textfield; appearance: textfield; }

.hint {
  font-size: 0.8rem;
  color: #999;
  margin-top: 0.4rem;
}

/* ── Shape row ───────────────────────────────────────────────────── */
.shape-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.shape-row label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
}
.size-label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: #666;
  font-weight: 500;
}
.shape-row .size-label { align-items: flex-start; }
/* Uniform input cell width for Size / Length / Rotation / Vertices etc.,
   so every label in the shape-row is the same visible width regardless of
   whether it has a unit suffix. */
.shape-row .size-input { width: 110px; }
.shape-row .size-input input { flex: 1; min-width: 0; width: auto; }

/* ── Field header (label + inline control on one row) ────────────── */
.field-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.size-input {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}
.size-input input { width: 90px; }
.unit { font-size: 0.8rem; color: #888; }

.shape-break { width: 100%; height: 0; }

/* ── Draw ────────────────────────────────────────────────────────── */
.draw-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
}
.draw-row .hint { margin-top: 0; }
#draw-btn.draw-active {
  background: #c8102e;
  color: #fff;
  border-color: #c8102e;
}

/* ── Info box ────────────────────────────────────────────────────── */
.info-box {
  margin-top: 1.75rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: #fafafa;
}
.info-box summary {
  padding: 0.6rem 1rem;
  cursor: pointer;
  font-size: 0.875rem;
  color: #555;
  user-select: none;
}
.info-box summary:hover { color: #222; }
.info-body {
  padding: 0 1rem 0.9rem;
  font-size: 0.82rem;
  color: #555;
  line-height: 1.55;
}
.info-body p { margin-bottom: 0.6rem; }
.info-body ol {
  margin: 0 0 0.6rem 1.1rem;
}
.info-body ol li { margin-bottom: 0.25rem; }
.info-note { color: #888; font-size: 0.78rem; margin-bottom: 0 !important; }

/* ── Advanced ────────────────────────────────────────────────────── */
details {
  margin-bottom: 1.75rem;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: #fafafa;
}
summary {
  padding: 0.75rem 1rem;
  cursor: pointer;
  font-size: 0.875rem;
  color: #555;
  user-select: none;
}
summary:hover { color: #222; }
.advanced-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  padding: 0 1rem 1rem;
}
.advanced-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.8rem;
  color: #555;
  font-weight: 500;
  min-width: 0;          /* allow inputs to shrink with the column */
}
/* Inside the advanced grid, let inputs fill their cell width so every column
   pair lines up the same way regardless of label content. */
.advanced-grid .size-input { width: 100%; }
.advanced-grid .size-input input { width: 100%; min-width: 0; }
.advanced-grid input[type="text"] { width: 100%; }
/* Field header (e.g., Z-scale on the left, Auto checkbox pushed to the
   right edge of the cell). */
.advanced-grid .field-header { justify-content: space-between; gap: 0.5rem; }
/* `.auto-check` is a <label> nested inside another label; the .advanced-grid
   label rule turns it into a column, which stacks the checkbox under the
   word "Auto". Override to keep it inline. */
.advanced-grid .auto-check {
  flex-direction: row;
  align-items: center;
  gap: 0.3rem;
}
/* Import / Export row: 3 equal columns so every button fits on one line at
   the same width. */
.advanced-grid .import-export-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.5rem;
  margin-top: 0;
}
.advanced-grid .import-export-row button { white-space: nowrap; }

/* ── Inputs ──────────────────────────────────────────────────────── */
input[type="text"],
input[type="number"],
select {
  padding: 0.45rem 0.65rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.9rem;
  background: #fff;
  width: 100%;
  transition: border-color 0.15s;
}
input:focus, select:focus {
  outline: none;
  border-color: #c8102e;
}

/* ── Buttons ─────────────────────────────────────────────────────── */
button {
  padding: 0.5rem 1.1rem;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  font-size: 0.9rem;
  color: #333;
  transition: background 0.15s, border-color 0.15s;
}
button:hover { background: #f0f0f0; }
button.primary {
  background: #c8102e;
  color: #fff;
  border-color: #c8102e;
  font-weight: 600;
  padding: 0.65rem 1.75rem;
}
button.primary:hover { background: #a80d27; border-color: #a80d27; }

.actions { margin-top: 0.5rem; text-align: center; }
.actions button + button { margin-left: 0.5rem; }

/* ── Progress ────────────────────────────────────────────────────── */
#state-progress { padding: 2rem 0; }

.phase-label {
  font-size: 0.95rem;
  color: #333;
  margin-bottom: 0.75rem;
  min-height: 1.4em;
}
.progress-track {
  height: 10px;
  background: #e0e0e0;
  border-radius: 5px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}
.progress-fill {
  height: 100%;
  background: #c8102e;
  border-radius: 5px;
  width: 0%;
  transition: width 0.4s ease;
}
.time-remaining {
  font-size: 0.8rem;
  color: #888;
  min-height: 1.2em;
}

/* ── Result / Error ──────────────────────────────────────────────── */
.result-box {
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 2.5rem 2rem;
  text-align: center;
  margin-top: 1rem;
}
.result-box.error { border-color: #f5c0c8; background: #fff8f9; }

.result-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
  color: #2c9e4a;
}
.result-box.error .result-icon { color: #c8102e; }

.result-label {
  font-size: 1rem;
  color: #444;
  margin-bottom: 1.5rem;
}

.result-box button { margin: 0.35rem; }

/* ── Map handles ── */
.shape-handle-vertex,
.shape-handle-corner,
.shape-handle-rotate,
.shape-handle-radius {
  background: white;
  border: 2px solid #c8102e;
  border-radius: 50%;
  cursor: move;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
.shape-handle-rotate {
  border-color: #0066cc;
}

/* ── Phase log ───────────────────────────────────────────────────── */
.phase-log {
  list-style: none;
  margin: 1rem 0;
  padding: 0;
  font-size: 0.85rem;
}
.phase-item {
  display: flex;
  justify-content: space-between;
  padding: 0.25rem 0;
  border-bottom: 1px dotted #e0e0e0;
}
.phase-item:last-child { border-bottom: none; }
.phase-text  { color: #333; }
.phase-time  { color: #888; font-variant-numeric: tabular-nums; }
.phase-running .phase-text { color: #c8102e; font-weight: 500; }
.phase-running .phase-time { color: #c8102e; }
.phase-total {
  margin-top: 0.25rem;
  border-top: 1px solid #ccc;
  padding-top: 0.5rem;
  border-bottom: none;
  font-weight: 500;
}
.phase-stat .phase-text { color: #666; font-style: italic; }
.phase-stat .phase-time { color: #888; font-style: italic; }
