:root {
  --bg: #f5f3ee;
  --panel: #fffefa;
  --ink: #1d2521;
  --muted: #68746d;
  --line: #d8d3c8;
  --accent: #2f5d50;
  --accent-2: #b85f38;
  --field: #f2eee5;
  --shadow: 0 10px 26px rgba(33, 38, 33, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  min-height: 42px;
  border-radius: 8px;
  cursor: pointer;
}

button:active {
  transform: translateY(1px);
}

.app-shell {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: #e7e0d3;
  border-bottom: 1px solid var(--line);
}

.project-block {
  display: grid;
  gap: 3px;
  min-width: 0;
  flex: 1;
}

.project-block label,
.field-row label,
.stacked-field {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.project-block input {
  width: 100%;
  border: 0;
  border-bottom: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  font-size: 20px;
  font-weight: 800;
  outline: 0;
}

.project-block input:focus {
  border-bottom-color: var(--accent);
}

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

.offline-badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.offline-badge.ready {
  border-color: #2f5d50;
  background: #dbe9df;
  color: #173c32;
}

.offline-badge.offline {
  border-color: #b85f38;
  background: #f3dfd4;
  color: #7a351d;
}

.offline-badge.blocked {
  border-color: #b9a76b;
  background: #f0ead2;
  color: #63561f;
}

.primary-action {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  min-width: 72px;
  font-weight: 800;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 42px;
  min-width: 42px;
  padding: 0;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.workspace {
  display: grid;
  grid-template-columns: 310px 1fr;
  min-height: 0;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
  padding: 12px;
  background: #eee8dc;
  border-right: 1px solid var(--line);
}

.panel-section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.panel-section h2 {
  margin: 0 0 10px;
  font-size: 14px;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.tool-button {
  display: grid;
  grid-template-columns: 22px 1fr;
  align-items: center;
  gap: 7px;
  padding: 8px;
  text-align: left;
  min-width: 0;
}

.tool-button span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-button.active,
.mobile-tool.active {
  background: #dbe9df;
  border-color: var(--accent);
  color: #173c32;
  font-weight: 800;
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
}

.number-field {
  display: flex;
  align-items: center;
  width: 118px;
  background: var(--field);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 8px;
}

.number-field input {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 9px 0;
  outline: 0;
}

.preset-size {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

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

.stacked-field {
  display: block;
  margin: 10px 0 6px;
}

#plantName {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  padding: 10px;
}

#plantSize {
  width: 100%;
}

.selection-empty,
.selection-form {
  color: var(--muted);
  font-size: 13px;
}

.selection-form {
  display: grid;
  gap: 9px;
}

.selection-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.selection-form input,
.selection-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  padding: 9px;
  color: var(--ink);
  font: inherit;
}

.selection-form textarea {
  min-height: 70px;
  resize: vertical;
}

.action-list {
  display: grid;
  gap: 8px;
}

.file-button {
  display: grid;
  place-items: center;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  cursor: pointer;
}

.file-button input {
  display: none;
}

.canvas-card {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  min-height: 0;
}

.canvas-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.canvas-head div:first-child {
  display: grid;
  min-width: 0;
}

#hintText {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.zoom-controls {
  display: flex;
  gap: 8px;
}

.canvas-wrap {
  position: relative;
  min-height: 0;
  overflow: auto;
  background:
    linear-gradient(45deg, rgba(0, 0, 0, 0.025) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(0, 0, 0, 0.025) 25%, transparent 25%),
    #e8e2d6;
  touch-action: none;
}

#planCanvas {
  display: block;
  width: 1800px;
  height: 1200px;
  cursor: crosshair;
  touch-action: none;
}

.bottom-tools {
  display: none;
  gap: 6px;
  padding: 7px max(8px, env(safe-area-inset-right)) calc(7px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  overflow-x: auto;
  background: #e7e0d3;
  border-top: 1px solid var(--line);
}

.mobile-tool {
  min-width: 68px;
  padding: 0 9px;
  white-space: nowrap;
}

@media (max-width: 820px) {
  body {
    overflow: hidden;
  }

  .topbar {
    padding: 8px 10px;
  }

  .project-block input {
    font-size: 17px;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .side-panel {
    position: fixed;
    z-index: 4;
    left: 10px;
    right: 10px;
    bottom: 68px;
    max-height: 42vh;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .panel-section:first-child {
    display: none;
  }

  .panel-section {
    padding: 10px;
  }

  .canvas-head {
    padding: 8px 10px;
  }

  #planCanvas {
    width: 1200px;
    height: 900px;
  }

  .bottom-tools {
    display: flex;
  }
}

@media (max-width: 520px) {
  .top-actions .icon-button {
    display: none;
  }

  .offline-badge {
    max-width: 76px;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .side-panel {
    grid-template-columns: 1fr;
    max-height: 38vh;
  }

  .panel-section:nth-child(2),
  .panel-section:nth-child(3) {
    display: block;
  }

  .panel-section:nth-child(4),
  .panel-section:nth-child(5) {
    display: none;
  }
}
