:root {
  --st-bg: #0f1714;
  --st-panel: #17221e;
  --st-panel-edge: #24352e;
  --st-text: #e8f0eb;
  --st-muted: #9bb0a6;
  --st-accent: #3d9b6e;
  --st-accent-strong: #2f7a56;
  --st-warn: #d4a24c;
  --st-danger: #c45c4a;
  --st-input: #0c1210;
  --st-radius: 10px;
  --st-font: "DM Sans", system-ui, sans-serif;
  --st-mono: "IBM Plex Mono", ui-monospace, monospace;
  --st-topbar: 64px;
}

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

html,
body.sprinkler-tool-page {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--st-font);
  color: var(--st-text);
  background: var(--st-bg);
}

.st-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, rgba(61, 155, 110, 0.18), transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(212, 162, 76, 0.08), transparent 50%),
    var(--st-bg);
}

.st-topbar {
  height: var(--st-topbar);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 1rem 0 0.75rem;
  border-bottom: 1px solid var(--st-panel-edge);
  background: rgba(15, 23, 20, 0.92);
  backdrop-filter: blur(8px);
}

.st-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.st-home-link {
  display: grid;
  place-items: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 8px;
  color: var(--st-text);
  background: var(--st-panel);
  border: 1px solid var(--st-panel-edge);
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.st-home-link:hover {
  background: var(--st-panel-edge);
  border-color: var(--st-accent);
  color: var(--st-text);
}

.st-eyebrow {
  margin: 0;
  font-size: 0.7rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--st-muted);
  font-family: var(--st-mono);
}

.st-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.2;
}

.st-phase-badge {
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: rgba(61, 155, 110, 0.15);
  border: 1px solid rgba(61, 155, 110, 0.35);
  color: #8fd4b0;
  white-space: nowrap;
}

.st-top-actions {
  display: flex;
  gap: 0.5rem;
}

.st-alert {
  flex-shrink: 0;
  margin: 0;
  padding: 0.75rem 1rem;
  background: rgba(196, 92, 74, 0.15);
  border-bottom: 1px solid rgba(196, 92, 74, 0.4);
  color: #f0c4bc;
  font-size: 0.9rem;
}

.st-alert code {
  font-family: var(--st-mono);
  font-size: 0.85em;
}

.st-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, 320px) 1fr;
}

.st-sidebar {
  min-height: 0;
  overflow-y: auto;
  padding: 1rem;
  border-right: 1px solid var(--st-panel-edge);
  background: rgba(23, 34, 30, 0.85);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.st-panel {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

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

.st-panel-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
}

.st-subtitle {
  margin: 0.5rem 0 0;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--st-muted);
}

.st-help {
  margin: 0;
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--st-muted);
}

.st-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--st-muted);
}

.st-input {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--st-panel-edge);
  background: var(--st-input);
  color: var(--st-text);
  font: inherit;
  font-size: 1rem;
}

.st-input:focus {
  outline: none;
  border-color: var(--st-accent);
  box-shadow: 0 0 0 2px rgba(61, 155, 110, 0.25);
}

.st-search-row {
  display: flex;
  gap: 0.4rem;
  align-items: stretch;
}

.st-search-row .st-input {
  flex: 1;
  min-width: 0;
}

.st-search-row .st-btn {
  flex-shrink: 0;
  padding-left: 0.75rem;
  padding-right: 0.75rem;
}

/* Keep Places dropdown above the tool chrome */
.pac-container {
  z-index: 10000 !important;
  font-family: var(--st-font);
}

.st-btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.st-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  border: 1px solid transparent;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease, border-color 0.15s ease;
}

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

.st-btn-primary {
  background: var(--st-accent);
  color: #07140e;
}

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

.st-btn-primary.is-drawing {
  box-shadow: 0 0 0 2px rgba(143, 212, 176, 0.55);
  background: var(--st-accent-strong);
  color: #fff;
}

.st-btn-accent {
  background: transparent;
  border-color: var(--st-accent);
  color: #8fd4b0;
}

.st-btn-accent:hover:not(:disabled) {
  background: rgba(61, 155, 110, 0.15);
}

.st-btn-ghost {
  background: transparent;
  border-color: var(--st-panel-edge);
  color: var(--st-muted);
}

.st-btn-ghost:hover:not(:disabled) {
  border-color: var(--st-warn);
  color: var(--st-warn);
}

.st-btn-danger {
  background: rgba(196, 92, 74, 0.15);
  border-color: rgba(196, 92, 74, 0.45);
  color: #f0c4bc;
}

.st-btn-danger:hover:not(:disabled) {
  background: rgba(196, 92, 74, 0.28);
}

.st-tool-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
}

.st-tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.55rem 0.35rem;
  border-radius: 8px;
  border: 1px solid var(--st-panel-edge);
  background: var(--st-input);
  color: var(--st-muted);
  font: inherit;
  font-size: 0.7rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.st-tool i {
  font-size: 1.1rem;
}

.st-tool:hover {
  border-color: var(--st-accent);
  color: var(--st-text);
}

.st-tool.active {
  border-color: var(--st-accent);
  background: rgba(61, 155, 110, 0.18);
  color: #8fd4b0;
}

.st-zone-controls,
.st-feature-edit {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding-top: 0.25rem;
}

.st-zone-controls.st-panel-hidden,
.st-feature-edit.st-panel-hidden {
  display: none;
}

.st-help-tight {
  margin: 0;
  font-size: 0.72rem;
}

.st-color-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.st-color-chip {
  width: 1.65rem;
  height: 1.65rem;
  border-radius: 6px;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}

.st-color-chip.active {
  border-color: #fff;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25);
}

.st-layers {
  flex: 1;
  min-height: 0;
}

.st-layer-list {
  margin: 0.5rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  max-height: 260px;
  overflow-y: auto;
}

.st-layer-list:empty::after {
  content: "No features yet.";
  display: block;
  font-size: 0.8rem;
  color: var(--st-muted);
}

.st-layer-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.st-layer-group-title {
  margin: 0;
  padding: 0 0.15rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--st-muted);
}

.st-layer-group ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.st-layer-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  background: var(--st-input);
  border: 1px solid transparent;
  font-size: 0.8rem;
  cursor: pointer;
}

.st-layer-item:hover,
.st-layer-item.selected {
  border-color: var(--st-accent);
}

.st-layer-item .swatch {
  width: 0.75rem;
  height: 0.75rem;
  border-radius: 3px;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.35);
  box-sizing: border-box;
}

.st-layer-item .label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.st-layer-item .vis-toggle {
  border: none;
  background: transparent;
  color: var(--st-muted);
  padding: 0;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.st-layer-item .vis-toggle:hover {
  color: var(--st-text);
}

.st-status {
  margin: auto 0 0;
  padding-top: 0.75rem;
  border-top: 1px solid var(--st-panel-edge);
  font-size: 0.8rem;
  color: var(--st-muted);
  line-height: 1.4;
}

.st-map-wrap {
  position: relative;
  min-height: 0;
  background: #0a100e;
}

#st-map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Desktop: drawer chrome / FABs stay out of the way */
.st-drawer-handle {
  display: none;
}

.st-map-fabs {
  display: none;
}

.st-print-sheet {
  display: none;
}

@media (max-width: 820px) {
  :root {
    --st-topbar: 56px;
  }

  .st-app {
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  .st-topbar {
    padding: 0 0.65rem 0 0.5rem;
    gap: 0.5rem;
    padding-top: env(safe-area-inset-top, 0);
    height: calc(var(--st-topbar) + env(safe-area-inset-top, 0));
  }

  .st-eyebrow {
    display: none;
  }

  .st-phase-badge {
    display: none;
  }

  .st-title {
    font-size: 0.95rem;
  }

  .st-btn-iconish .st-btn-label {
    display: none;
  }

  .st-btn-iconish {
    min-width: 2.5rem;
    min-height: 2.5rem;
    padding: 0.45rem;
  }

  .st-body {
    position: relative;
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    min-height: 0;
  }

  .st-map-wrap {
    grid-row: 1;
    grid-column: 1;
    min-height: 0;
  }

  .st-sidebar {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 5;
    max-height: min(70vh, 32rem);
    border-right: none;
    border-top: 1px solid var(--st-panel-edge);
    border-radius: 16px 16px 0 0;
    background: rgba(23, 34, 30, 0.96);
    backdrop-filter: blur(10px);
    padding: 0 1rem calc(0.85rem + env(safe-area-inset-bottom, 0));
    box-shadow: 0 -8px 28px rgba(0, 0, 0, 0.35);
    transform: translateY(calc(100% - 3.1rem));
    transition: transform 0.22s ease;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
  }

  body.st-drawer-open .st-sidebar {
    transform: translateY(0);
    overflow-y: auto;
  }

  .st-drawer-handle {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
    width: 100%;
    margin: 0;
    padding: 0.55rem 0 0.15rem;
    border: none;
    background: transparent;
    color: var(--st-muted);
    font: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
    touch-action: manipulation;
  }

  .st-drawer-grip {
    width: 2.4rem;
    height: 0.28rem;
    border-radius: 999px;
    background: rgba(155, 176, 166, 0.55);
  }

  .st-help-desktop {
    display: none;
  }

  .st-tool {
    min-height: 3rem;
    padding: 0.65rem 0.35rem;
    font-size: 0.72rem;
    touch-action: manipulation;
  }

  .st-tool i {
    font-size: 1.25rem;
  }

  .st-color-chip {
    width: 2rem;
    height: 2rem;
  }

  .st-layer-list {
    max-height: 140px;
  }

  .st-status {
    margin: 0;
    padding-top: 0.5rem;
    font-size: 0.78rem;
  }

  .st-map-fabs {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.55rem;
    position: absolute;
    right: max(0.75rem, env(safe-area-inset-right, 0));
    bottom: calc(3.6rem + env(safe-area-inset-bottom, 0));
    z-index: 4;
    pointer-events: none;
  }

  body.st-drawer-open .st-map-fabs {
    bottom: calc(min(70vh, 32rem) + 0.6rem);
  }

  .st-fab {
    pointer-events: auto;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    min-height: 2.75rem;
    padding: 0.55rem 0.9rem;
    border-radius: 999px;
    border: 1px solid var(--st-panel-edge);
    background: rgba(23, 34, 30, 0.94);
    color: var(--st-text);
    font: inherit;
    font-size: 0.85rem;
    font-weight: 650;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
    cursor: pointer;
    touch-action: manipulation;
  }

  .st-fab i {
    font-size: 1.1rem;
  }

  .st-fab-finish {
    background: var(--st-accent);
    border-color: var(--st-accent-strong);
    color: #07140e;
  }

  .st-fab-finish:disabled {
    opacity: 0.45;
  }

  .st-fab-hidden {
    display: none !important;
  }

  body.st-drawer-open .st-fab-tools {
    background: rgba(61, 155, 110, 0.22);
    border-color: rgba(61, 155, 110, 0.55);
    color: #8fd4b0;
  }
}

@media print {
  @page {
    size: landscape;
    margin: 0.3in;
  }

  html,
  body.sprinkler-tool-page {
    height: auto !important;
    overflow: visible !important;
    background: #fff !important;
    color: #111 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .st-app {
    height: auto !important;
    background: #fff !important;
    display: block;
  }

  .st-topbar,
  .st-sidebar,
  .st-alert,
  .st-home-link,
  .st-top-actions,
  .st-body,
  .st-map-fabs {
    display: none !important;
  }

  .st-print-sheet {
    display: flex !important;
    flex-direction: column;
    gap: 0.25rem;
    color: #111;
    page-break-inside: avoid;
    break-inside: avoid;
    overflow: hidden;
  }

  body.st-print-landscape .st-print-sheet {
    height: 7.4in;
    max-height: 7.4in;
  }

  body.st-print-portrait .st-print-sheet {
    height: 10in;
    max-height: 10in;
  }

  .st-print-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    flex-shrink: 0;
    margin: 0;
    padding-bottom: 0.2rem;
    border-bottom: 1px solid #ccc;
  }

  .st-print-eyebrow {
    margin: 0;
    font-size: 0.65rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #555;
  }

  .st-print-title {
    margin: 0.05rem 0 0;
    font-size: 0.95rem;
    font-weight: 700;
  }

  .st-print-date {
    margin: 0;
    font-size: 0.7rem;
    color: #555;
    white-space: nowrap;
  }

  .st-print-legend {
    flex-shrink: 0;
  }

  .st-print-legend h3 {
    display: none;
  }

  .st-print-legend ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem 0.7rem;
  }

  .st-print-legend li {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.7rem;
  }

  .st-print-legend .swatch {
    width: 0.55rem;
    height: 0.55rem;
    border-radius: 2px;
    border: 1px solid rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
  }

  .st-print-map-wrap {
    flex: 1 1 auto;
    min-height: 0;
    margin: 0;
    page-break-inside: avoid;
    break-inside: avoid;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .st-print-map {
    display: block;
    width: 100%;
    height: 100%;
    border: 1px solid #bbb;
    background: #f4f6f5;
    overflow: hidden;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .st-print-composite {
    position: relative;
    display: inline-block;
    max-width: 100%;
    vertical-align: top;
  }

  body.st-print-landscape .st-print-composite,
  body.st-print-landscape .st-print-basemap {
    max-height: 6.2in;
  }

  body.st-print-portrait .st-print-composite,
  body.st-print-portrait .st-print-basemap {
    max-height: 8.6in;
  }

  .st-print-basemap {
    display: block;
    width: auto;
    max-width: 100%;
    height: auto;
  }

  .st-print-overlay {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
  }

  .st-print-map svg,
  .st-print-overlay svg {
    display: block;
    width: 100%;
    height: 100%;
  }

  .st-print-note {
    flex-shrink: 0;
    margin: 0;
    font-size: 0.6rem;
    color: #666;
  }
}
