/* =========================================================================
   Garden Designer — theme & layout
   A warm, paper-like canvas with floating "glass" panels on top. Palette
   leans toward soft greens/earth tones to feel horticultural rather than
   generic-SaaS.
   ========================================================================= */

:root {
  --bg-canvas: #f3f1e8;
  --grid-line: #e2ded0;
  --grid-line-major: #d3cdb8;

  --panel-bg: rgba(255, 255, 255, 0.82);
  --panel-bg-solid: #fffdf9;
  --panel-border: rgba(36, 41, 31, 0.08);
  --panel-shadow: 0 10px 30px -8px rgba(35, 45, 25, 0.22), 0 2px 8px -2px rgba(35, 45, 25, 0.12);

  --ink: #23291d;
  --ink-soft: #5c624f;
  --ink-faint: #8b917c;

  --accent: #3f6b3a;
  --accent-strong: #2e5029;
  --accent-soft: #e6efe0;
  --accent-soft-border: #cfe0c6;

  --earth: #b07f3f;
  --earth-soft: #f4e9d6;

  --danger: #b6493a;
  --danger-soft: #f7e4e0;

  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;

  --content-left: 332px; /* sidebar width (300) + margins (16*2) */
  --content-right: 192px; /* view toolbar width (176) + right margin (16) */

  font-size: 15px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
  background: var(--bg-canvas);
}

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

#canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.empty-hint {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: var(--ink-faint);
  pointer-events: none;
  max-width: 320px;
}
.empty-hint-icon { font-size: 40px; margin-bottom: 8px; }
.empty-hint p { margin: 0; font-size: 15px; line-height: 1.5; }
.empty-hint.hidden { display: none; }

/* ---------- shared panel look ---------- */
.panel {
  background: var(--panel-bg);
  backdrop-filter: blur(14px) saturate(1.4);
  -webkit-backdrop-filter: blur(14px) saturate(1.4);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--panel-shadow);
}

/* ---------- top bar ---------- */
.floating-top {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 10px 0 8px;
  z-index: 30;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent-strong); }

.topbar-title { flex: 1; min-width: 0; }
.project-name-input {
  width: 100%;
  border: none;
  background: transparent;
  font-family: 'Fraunces', serif;
  font-size: 19px;
  font-weight: 600;
  color: var(--ink);
  padding: 6px 8px;
  border-radius: var(--radius-sm);
}
.project-name-input:hover { background: rgba(0,0,0,0.03); }
.project-name-input:focus { outline: none; background: var(--accent-soft); }

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s ease, border-color .15s ease, opacity .15s ease;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-icon { display: inline-flex; }
.btn-icon svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn-ghost {
  background: rgba(63, 107, 58, 0.07);
  color: var(--accent-strong);
}
.btn-ghost:hover:not(:disabled) { background: var(--accent-soft-border); }

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

.btn-block { width: 100%; justify-content: center; margin-top: 10px; }

.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: #f2d2cb; }

.save-status {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-faint);
  padding: 0 6px;
}
.save-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ink-faint);
  transition: background .2s ease;
}
.save-status[data-state="saving"] .save-dot { background: var(--earth); animation: pulse 1s infinite ease-in-out; }
.save-status[data-state="saved"] .save-dot { background: var(--accent); }
.save-status[data-state="error"] .save-dot { background: var(--danger); }
.save-status[data-state="error"] .save-text { color: var(--danger); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

/* ---------- sidebar ---------- */
.floating-sidebar {
  position: absolute;
  top: 84px;
  left: 16px;
  bottom: 16px;
  width: 300px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 25;
  transition: transform .18s ease, opacity .18s ease;
}
#app.sidebar-collapsed .floating-sidebar {
  transform: translateX(-110%);
  opacity: 0;
  pointer-events: none;
}
#app.sidebar-collapsed { --content-left: 32px; }

.sidebar-tabs {
  display: flex;
  gap: 4px;
  padding: 10px 10px 0 10px;
  flex: none;
}
.sidebar-tab {
  flex: 1;
  padding: 9px 0;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-faint);
  cursor: pointer;
}
.sidebar-tab:hover { color: var(--ink-soft); }
.sidebar-tab.active { background: var(--accent-soft); color: var(--accent-strong); }

.sidebar-panel {
  display: none;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  padding: 12px 10px 14px 10px;
}
.sidebar-panel.active { display: flex; }

/* -- library tab -- */
.library-search input {
  width: 100%;
  padding: 9px 12px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: rgba(0,0,0,0.03);
  font-family: inherit;
  font-size: 13.5px;
  color: var(--ink);
}
.library-search input:focus { outline: none; border-color: var(--accent-soft-border); background: #fff; }

.category-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 4px;
}
.chip {
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.plant-list {
  flex: 1;
  overflow-y: auto;
  margin: 6px -2px 0 -2px;
  padding: 2px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.plant-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 9px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: grab;
  background: rgba(255,255,255,0.5);
}
.plant-card:hover { background: #fff; border-color: var(--panel-border); }
.plant-card:active { cursor: grabbing; }
.plant-card.dragging { opacity: 0.4; }
.plant-card canvas { flex: none; display: block; }
.plant-card-info { min-width: 0; flex: 1; }
.plant-card-name { font-size: 13.5px; font-weight: 600; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plant-card-meta { font-size: 11.5px; color: var(--ink-faint); font-style: italic; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.plant-card-dims { font-size: 11px; color: var(--ink-faint); flex: none; text-align: right; }
.plant-card-delete {
  flex: none; width: 22px; height: 22px; border: none; background: transparent;
  color: var(--ink-faint); border-radius: 6px; cursor: pointer; font-size: 13px; display: none;
}
.plant-card:hover .plant-card-delete { display: block; }
.plant-card-delete:hover { background: var(--danger-soft); color: var(--danger); }

.empty-list-msg { color: var(--ink-faint); font-size: 13px; text-align: center; padding: 30px 10px; }

/* -- projects tab -- */
.project-list {
  flex: 1;
  overflow-y: auto;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.project-card {
  padding: 11px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--panel-border);
  cursor: pointer;
  background: rgba(255,255,255,0.5);
}
.project-card:hover { background: #fff; }
.project-card.active { background: var(--accent-soft); border-color: var(--accent-soft-border); }
.project-card-name { font-size: 14px; font-weight: 600; margin-bottom: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-card-meta { font-size: 11.5px; color: var(--ink-faint); display: flex; justify-content: space-between; gap: 8px; }
.project-card-actions { display: flex; gap: 6px; margin-top: 8px; }
.project-card-actions button {
  border: none; background: rgba(0,0,0,0.05); color: var(--ink-soft);
  font-size: 11px; font-weight: 600; padding: 4px 9px; border-radius: 999px; cursor: pointer;
}
.project-card-actions button:hover { background: rgba(0,0,0,0.1); }
.project-card-actions button.danger:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------- bottom mode toolbar ---------- */
.floating-toolbar {
  position: absolute;
  bottom: 16px;
  /* Centred in the free space between the sidebar and the view toolbar,
     not the full viewport — otherwise it collides with one or the other
     on narrower windows. */
  left: calc(50% + (var(--content-left) - var(--content-right)) / 2);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px;
  z-index: 25;
  transition: left .18s ease;
}

/* Only the centre (mode) toolbar needs to shrink/scroll on narrow windows —
   the view toolbar on the right keeps its own fixed compact size. */
#mode-toolbar {
  max-width: calc(100% - var(--content-left) - var(--content-right) - 16px);
  overflow-x: auto;
}

.mode-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
}
.mode-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.mode-btn:hover:not(:disabled) { background: rgba(0,0,0,0.05); }
.mode-btn.active { background: var(--accent); color: #fff; }
.mode-btn:disabled { opacity: .35; cursor: not-allowed; }
.mode-btn.danger:hover:not(:disabled) { background: var(--danger-soft); color: var(--danger); }

.toolbar-divider { width: 1px; height: 24px; background: var(--panel-border); margin: 0 3px; flex: none; }

/* ---------- view toolbar (zoom/rotate) ---------- */
.view-toolbar {
  left: auto;
  right: 16px;
  transform: none;
  width: 176px;
  flex-wrap: wrap;
  justify-content: center;
}
.zoom-label { width: auto; padding: 0 8px; font-size: 12px; font-weight: 700; }
.compass { font-size: 12px; font-weight: 700; color: var(--earth); }

/* ---------- scale widget, bottom-left ----------
   Shares one position between two mutually-exclusive elements: the
   "Set Scale" button (basemap uploaded, not calibrated yet) and the
   scale-bar + reset link (calibrated). */
.scale-widget-pos {
  position: absolute;
  bottom: 16px;
  left: calc(var(--content-left) + 8px);
  z-index: 20;
  transition: left .18s ease;
}
.scale-widget-pos.hidden { display: none; }

/* .btn's pill radius/transparent border win over .panel's by source order
   (desired — it should still look like a button) except the border colour,
   which we want back so it reads as a floating panel, not a bare button. */
#btn-set-scale.scale-widget-pos { border-color: var(--panel-border); }

.scale-bar {
  padding: 6px 10px 6px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-soft);
}
.scale-bar-line { width: 90px; height: 10px; display: flex; align-items: flex-end; }
#scale-bar-fill {
  display: block;
  height: 4px;
  width: 100%;
  background: var(--ink-soft);
  border-left: 2px solid var(--ink-soft);
  border-right: 2px solid var(--ink-soft);
}
.reset-scale-link {
  border: none;
  background: transparent;
  padding: 2px 0 2px 6px;
  margin-left: 2px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-faint);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.reset-scale-link:hover { color: var(--danger); }

/* ---------- context / inspector panel ---------- */
.floating-context {
  position: absolute;
  top: 84px;
  right: 16px;
  width: 250px;
  padding: 16px;
  z-index: 28;
}
.floating-context.hidden { display: none; }
.ctx-title { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-faint); font-weight: 700; margin: 0 0 10px; }
.ctx-field { margin-bottom: 12px; }
.ctx-field label { display: block; font-size: 11.5px; color: var(--ink-faint); font-weight: 600; margin-bottom: 4px; }
.ctx-field input[type="text"], .ctx-field input[type="number"] {
  width: 100%; padding: 7px 9px; border-radius: var(--radius-sm); border: 1px solid var(--panel-border);
  font-family: inherit; font-size: 13px; background: #fff;
}
.ctx-row { display: flex; gap: 8px; }
.ctx-row .ctx-field { flex: 1; }
.ctx-swatches { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.ctx-swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.ctx-swatch.selected { border-color: var(--ink); }
.ctx-actions { display: flex; gap: 8px; margin-top: 14px; }
.ctx-actions .btn { flex: 1; justify-content: center; padding: 8px; }

/* ---------- modal ---------- */
.modal-root {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(30, 35, 22, 0.28);
  z-index: 100;
}
.modal-root.hidden { display: none; }
.modal-card {
  background: var(--panel-bg-solid);
  border-radius: var(--radius-lg);
  box-shadow: var(--panel-shadow);
  width: 380px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  padding: 22px;
}
.modal-card h2 { font-family: 'Fraunces', serif; font-size: 20px; margin: 0 0 16px; }
.modal-field { margin-bottom: 14px; }
.modal-field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); margin-bottom: 5px; }
.modal-field input[type="text"], .modal-field input[type="number"], .modal-field select, .modal-field textarea {
  width: 100%; padding: 9px 11px; border-radius: var(--radius-sm); border: 1px solid var(--panel-border);
  font-family: inherit; font-size: 13.5px; background: #fbfaf6;
}
.modal-field textarea { resize: vertical; min-height: 60px; }
.modal-hint { font-size: 12px; color: var(--ink-faint); margin: -8px 0 14px; line-height: 1.5; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.modal-actions .btn { padding: 9px 18px; }
.modal-row { display: flex; gap: 10px; }
.modal-row .modal-field { flex: 1; }
.color-swatch-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.color-swatch-picker .ctx-swatch { width: 26px; height: 26px; }

/* ---------- toast ---------- */
.toast {
  position: absolute;
  bottom: 76px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fdfcf8;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--panel-shadow);
  z-index: 200;
  transition: opacity .2s ease, transform .2s ease;
}
.toast.hidden { display: none; opacity: 0; }

/* scrollbars, subtle */
.plant-list::-webkit-scrollbar, .project-list::-webkit-scrollbar, .modal-card::-webkit-scrollbar { width: 8px; }
.plant-list::-webkit-scrollbar-thumb, .project-list::-webkit-scrollbar-thumb, .modal-card::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.12); border-radius: 8px;
}

@media (max-width: 860px) {
  .floating-sidebar { width: 260px; }
  .floating-context { width: 220px; }
}
