/* FarmPlanner — desk-side planning app */

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ====== Auth cover (sign-in gate) ====== */
.auth-cover {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-6);
  background:
    radial-gradient(circle at 20% 10%, rgba(255,255,255,0.08), transparent 50%),
    radial-gradient(circle at 90% 90%, rgba(0,0,0,0.2), transparent 50%),
    linear-gradient(135deg, var(--c-primary-d), #14401a 80%);
  overflow: auto;
}

.auth-cover-card {
  width: 100%;
  max-width: 440px;
  background: var(--c-surface);
  border-radius: var(--r-lg);
  padding: var(--sp-8);
  box-shadow: 0 24px 64px rgba(0,0,0,0.32), 0 8px 16px rgba(0,0,0,0.18);
}

.auth-cover-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-6);
}

.auth-cover-brand .brand-mark { width: 28px; height: 28px; }
.auth-cover-brand .brand-name {
  font-weight: 700;
  font-size: var(--fs-lg);
}

.auth-cover-headline {
  margin: 0 0 var(--sp-2);
  font-size: var(--fs-2xl);
  letter-spacing: -0.02em;
}

.auth-cover-sub {
  margin: 0 0 var(--sp-6);
  color: var(--c-text-2);
  line-height: 1.5;
}

.auth-cover-form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  margin-bottom: var(--sp-3);
}

.auth-cover-form input[type="email"] {
  padding: var(--sp-3) var(--sp-4);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  font-size: var(--fs-md);
  font-family: inherit;
}

.auth-cover-form input:focus {
  outline: 2px solid var(--c-primary);
  outline-offset: -1px;
}

.auth-cover-form .btn-primary {
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-md);
  font-weight: 600;
  min-height: 48px;
  border-radius: var(--r-md);
}

.auth-cover-form .btn-primary[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
}

.auth-cover-hint {
  font-size: var(--fs-sm);
  color: var(--c-text-2);
  margin: 0 0 var(--sp-4);
  line-height: 1.5;
}

.auth-cover-foot {
  font-size: var(--fs-xs);
  color: var(--c-text-3);
  margin: 0;
  padding-top: var(--sp-4);
  border-top: 1px solid var(--c-border);
}

.auth-loading {
  position: fixed;
  inset: 0;
  z-index: 2001;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-3);
  background: var(--c-bg);
  color: var(--c-text-2);
}

.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--c-border);
  border-top-color: var(--c-primary);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Default: cover and loading hidden; shown only based on body class */
.auth-cover, .auth-loading { display: none; }

body.signed-out .auth-cover { display: flex; }
body.auth-loading-active .auth-loading { display: flex; }
body.auth-loading-active .auth-cover { display: none; }

body.signed-out .topbar,
body.signed-out .layout { display: none !important; }
body.auth-loading-active .topbar,
body.auth-loading-active .layout { display: none !important; }

/* ====== Topbar ====== */
.topbar {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-2) var(--sp-4);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
  z-index: 20;
  height: 52px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

.brand-mark {
  width: 22px;
  height: 22px;
  background:
    radial-gradient(circle at 30% 30%, var(--c-primary) 30%, transparent 31%),
    radial-gradient(circle at 70% 70%, var(--c-accent) 30%, transparent 31%),
    var(--c-primary-l);
  border-radius: 50%;
}

.brand-name {
  font-weight: 700;
  font-size: var(--fs-md);
  letter-spacing: -0.01em;
}

.scenario-control {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex: 1;
  max-width: 480px;
}

.scenario-control select {
  flex: 1;
  padding: var(--sp-2) var(--sp-3);
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  font-weight: 600;
  font-size: var(--fs-sm);
  cursor: pointer;
}

.scenario-actions {
  display: flex;
  gap: 2px;
}

.topbar-right {
  margin-left: auto;
  display: flex;
  gap: var(--sp-2);
}

.btn-icon-text {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  background: transparent;
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--c-text);
  min-height: 36px;
}

.btn-icon-text:hover { background: var(--c-surface-2); }

.icon-btn {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-sm);
  color: var(--c-text-2);
}

.icon-btn:hover { background: var(--c-surface-2); color: var(--c-text); }
.icon-btn.danger:hover { background: #fee2e2; color: var(--c-danger); }

@media (prefers-color-scheme: dark) {
  .icon-btn.danger:hover { background: #3f1f1f; }
}

/* ====== Layout ====== */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 320px 1fr 0;
  min-height: 0;
  position: relative;
}

.layout.has-properties {
  grid-template-columns: 320px 1fr 340px;
}

/* When the left panel is collapsed, zero its column so the map reclaims it. */
.layout.left-collapsed { grid-template-columns: 0 1fr 0; }
.layout.left-collapsed.has-properties { grid-template-columns: 0 1fr 340px; }

/* Pin each area to its column so a hidden/collapsed sidebar can't cause grid
   auto-placement to shift the properties panel into the map's track. */
.sidebar-left { grid-column: 1; }
.map-wrap { grid-column: 2; }
.sidebar-right { grid-column: 3; }

/* Properties panel is truly removed when closed (overrides .sidebar display). */
.sidebar-right[hidden] { display: none; }

.sidebar {
  background: var(--c-surface);
  border-right: 1px solid var(--c-border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar-right {
  border-right: none;
  border-left: 1px solid var(--c-border);
}

.sidebar.collapsed {
  display: none;
}

.topbar-toggle { margin-right: var(--sp-2); flex: 0 0 auto; }

/* ====== Layers panel: system + custom groups ====== */
.layer-group { margin-bottom: var(--sp-4); }
.layer-group:last-child { margin-bottom: 0; }
.layer-group-title {
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--c-text, #223);
  margin-bottom: var(--sp-2);
}
.layer-subgroup-label {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--c-text-muted, #778);
  margin: var(--sp-3) 0 var(--sp-1);
}

.custom-layers { display: flex; flex-direction: column; gap: 4px; margin-bottom: var(--sp-2); }
.layer-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
}
.layer-row.active {
  border-color: #2e7d32;
  background: rgba(46, 125, 50, 0.08);
}
.layer-vis { margin: 0; cursor: pointer; flex: 0 0 auto; }
.layer-name {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  padding: 2px;
  min-width: 0;
}
.layer-name-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-row.active .layer-name { font-weight: 700; }
.layer-count {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--c-text-muted, #889);
  background: rgba(0, 0, 0, 0.08);
  border-radius: 10px;
  padding: 0 6px;
  min-width: 18px;
  text-align: center;
}
.layer-icon {
  flex: 0 0 auto;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--c-text-muted, #889);
  font-size: 13px;
  padding: 2px 4px;
  border-radius: 4px;
  line-height: 1;
}
.layer-icon:hover { background: rgba(0, 0, 0, 0.08); color: var(--c-text, #223); }
.layer-icon svg { display: block; }
.btn-block { width: 100%; }

/* ====== Members dialog ====== */
.members-dialog { min-width: 340px; max-width: 440px; border: none; border-radius: var(--r-md, 10px); padding: var(--sp-4, 16px); }
.members-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--sp-2, 8px); }
.members-head h3 { margin: 0; }
.members-list { margin: var(--sp-3, 12px) 0; display: flex; flex-direction: column; gap: 4px; max-height: 300px; overflow-y: auto; }
.member-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--c-border, #e2e6e3);
  border-radius: var(--r-sm, 6px);
}
.member-row.muted { color: var(--c-text-muted, #889); border-style: dashed; justify-content: center; }
.member-email { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-role { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: #2e7d32; font-weight: 700; }
.member-remove { color: #c62828; }
.member-add { display: flex; gap: 8px; }
.member-add input { flex: 1 1 auto; }

/* ====== Status as segmented buttons (properties panel) ====== */
.status-btns { display: flex; flex-wrap: wrap; gap: 6px; }
.status-btn {
  padding: 6px 10px;
  border: 1px solid var(--c-border, #ccc);
  background: var(--c-surface, #fff);
  color: var(--c-text, #223);
  border-radius: var(--r-sm);
  font-size: var(--fs-xs);
  font-weight: 600;
  cursor: pointer;
}
.status-btn:hover { border-color: #2e7d32; }
.status-btn.active {
  background: #2e7d32;
  border-color: #2e7d32;
  color: #fff;
}

.sidebar-toggle {
  display: none;
}

.sidebar-content {
  display: flex;
  flex-direction: column;
}

/* ====== Panel sections ====== */
.panel-section {
  padding: var(--sp-4);
  border-bottom: 1px solid var(--c-border);
}

.panel-section:last-child { border-bottom: none; }

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--sp-3);
}

.panel-title {
  margin: 0 0 var(--sp-2);
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--c-text-2);
}

.panel-hint {
  font-size: var(--fs-xs);
  color: var(--c-text-3);
  margin: 0 0 var(--sp-3);
}

/* ====== Palette ====== */
.palette {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
}

.palette-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: var(--fs-sm);
  color: var(--c-text);
  text-align: left;
  width: 100%;
  min-height: 36px;
}

.palette-item:hover {
  background: var(--c-surface-2);
}

.palette-item.active {
  background: var(--c-primary-l);
  border-color: var(--c-primary);
  font-weight: 600;
}

@media (prefers-color-scheme: dark) {
  .palette-item.active {
    background: rgba(102, 187, 106, 0.15);
  }
}

.palette-swatch {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.1) inset;
}

.palette-swatch.shape-line {
  height: 4px;
  border-radius: 2px;
}

.palette-swatch.shape-point {
  border-radius: 50%;
}

.palette-shape {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--c-text-3);
  margin-left: auto;
}

.palette-category {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--c-text-3);
  padding: 6px var(--sp-3);
  text-align: left;
}
.palette-category:hover { color: var(--c-text-2); }
.palette-cat-label { flex: 1 1 auto; }
.palette-cat-count { flex: 0 0 auto; opacity: 0.6; }
.palette-group { border-top: 1px solid var(--c-border); }
.palette-group:first-child { border-top: none; }
.palette-group.collapsed .palette-group-items { display: none; }
.caret {
  flex: 0 0 auto;
  width: 0; height: 0;
  border-left: 4px solid currentColor;
  border-top: 3px solid transparent;
  border-bottom: 3px solid transparent;
  transition: transform 0.15s ease;
}
.palette-group:not(.collapsed) .caret { transform: rotate(90deg); }

.palette-category:first-child { margin-top: 0; }

/* Collapsible left-sidebar panel sections (click the title to fold). */
.sidebar-left .panel-section > .panel-title {
  cursor: pointer;
  display: flex;
  align-items: center;
}
.sidebar-left .panel-section > .panel-title::after {
  content: '';
  margin-left: auto;
  width: 0; height: 0;
  border-left: 5px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 0.15s ease;
  opacity: 0.7;
}
.sidebar-left .panel-section:not(.collapsed) > .panel-title::after {
  transform: rotate(90deg);
}
.sidebar-left .panel-section.collapsed > *:not(.panel-title) {
  display: none;
}

/* ====== Tools ====== */
.tool-row {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-2) var(--sp-3);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  color: var(--c-text);
  flex: 1;
  justify-content: center;
}

.tool-btn:hover { background: var(--c-surface-2); }

.tool-btn.active {
  background: var(--c-primary);
  border-color: var(--c-primary);
  color: white;
}

/* ====== Layer toggles ====== */
.layer-toggles {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: var(--sp-3);
}

.layer-toggles:last-child { margin-bottom: 0; }

.layer-toggle {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-size: var(--fs-sm);
  cursor: pointer;
  padding: 4px 0;
}

.layer-toggle input { margin: 0; }

/* ====== Basemap ====== */
.basemap-row {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.basemap-btn {
  flex: 1;
  padding: var(--sp-2);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  font-size: var(--fs-xs);
  color: var(--c-text);
}

.basemap-btn.active {
  background: var(--c-primary);
  border-color: var(--c-primary);
  color: white;
}

/* ====== Summary ====== */
.scenario-summary {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  font-size: var(--fs-sm);
  padding: 4px 0;
}

.summary-row span:last-child {
  font-family: var(--font-mono);
  font-weight: 600;
}

/* ====== Map ====== */
.map-wrap {
  position: relative;
  min-width: 0;
}

#map {
  position: absolute;
  inset: 0;
  background: var(--c-surface-2);
}

.map-overlay {
  position: absolute;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--c-text);
  box-shadow: var(--shadow-sm);
  z-index: 500;
  pointer-events: none;
  max-width: 280px;
}

.map-overlay.top-left { top: 12px; left: 12px; }
.map-overlay.bottom-left { bottom: 12px; left: 12px; font-family: var(--font-mono); }
.map-overlay.bottom-right { bottom: 12px; right: 12px; }
.map-overlay:empty { display: none; }

@media (prefers-color-scheme: dark) {
  .map-overlay {
    background: rgba(28, 31, 23, 0.92);
    color: var(--c-text);
  }
}

/* Floating on-map controls (interactive, unlike .map-overlay which is inert) */
.map-controls {
  position: absolute;
  z-index: 500;
  display: flex;
  gap: 6px;
}
.map-controls.top-right { top: 12px; right: 12px; }

.map-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  padding: 8px 12px;
  border-radius: var(--r-sm);
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--c-text);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  user-select: none;
}
.map-toggle input { margin: 0; cursor: pointer; }

@media (prefers-color-scheme: dark) {
  .map-toggle { background: rgba(28, 31, 23, 0.92); }
}

/* Custom shape labels */
.structure-label {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(0, 0, 0, 0.08);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--c-text);
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.structure-label .area {
  font-weight: 400;
  color: var(--c-text-2);
  margin-left: 4px;
  font-family: var(--font-mono);
}

@media (prefers-color-scheme: dark) {
  .structure-label {
    background: rgba(28, 31, 23, 0.92);
    border-color: rgba(255, 255, 255, 0.1);
    color: var(--c-text);
  }
}

/* Structure label overlay (Google Maps custom OverlayView) */
.structure-label { z-index: 1; }

/* ====== Properties panel ====== */
.prop-row {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  margin-bottom: var(--sp-3);
}

.prop-row > span {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--c-text-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.prop-row input[type="text"],
.prop-row textarea,
.prop-row select {
  padding: var(--sp-2) var(--sp-3);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  font-size: var(--fs-sm);
  font-family: inherit;
  resize: vertical;
}

.prop-row input:focus,
.prop-row textarea:focus,
.prop-row select:focus {
  outline: 2px solid var(--c-primary);
  outline-offset: -1px;
}

.prop-measurements {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  background: var(--c-surface-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
}

.prop-measurements .measure-row {
  display: flex;
  justify-content: space-between;
}

.prop-measurements .measure-row span:first-child {
  font-family: var(--font-body);
  font-size: var(--fs-xs);
  color: var(--c-text-3);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.prop-photos {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--sp-2);
}

.empty-photos {
  grid-column: 1 / -1;
  font-size: var(--fs-xs);
  color: var(--c-text-3);
  background: var(--c-surface-2);
  padding: var(--sp-3);
  border-radius: var(--r-sm);
  border: 1px dashed var(--c-border);
}

.prop-actions {
  display: flex;
  gap: var(--sp-2);
  margin-top: var(--sp-4);
}

.btn-primary, .btn-secondary, .btn-text, .btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
  font-weight: 500;
  font-size: var(--fs-sm);
  min-height: 36px;
}

.btn-primary { background: var(--c-primary); color: white; }
.btn-primary:hover { background: var(--c-primary-d); }
.btn-secondary { background: var(--c-surface-2); color: var(--c-text); border: 1px solid var(--c-border); }
.btn-secondary:hover { background: var(--c-border); }
.btn-text { background: transparent; color: var(--c-text-2); }
.btn-text:hover { background: var(--c-surface-2); }
.btn-danger { background: var(--c-danger); color: white; }
.btn-danger:hover { filter: brightness(0.92); }

/* ====== Modal ====== */
dialog {
  border: none;
  padding: 0;
  background: var(--c-surface);
  color: var(--c-text);
  border-radius: var(--r-lg);
  max-width: 92vw;
  width: 420px;
  box-shadow: var(--shadow-lg);
}

dialog::backdrop { background: rgba(0,0,0,0.5); }

dialog form {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-4);
}

dialog form h3 { margin: 0; }

dialog label {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  font-size: var(--fs-sm);
  font-weight: 500;
}

dialog input[type="text"] {
  padding: var(--sp-2) var(--sp-3);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  font-size: var(--fs-md);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--sp-2);
}

/* ====== Toast ====== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--c-text);
  color: var(--c-bg);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md);
  font-size: var(--fs-sm);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 1000;
  box-shadow: var(--shadow-md);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ====== Mobile / iPad ====== */
@media (max-width: 768px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .layout.has-properties {
    grid-template-columns: 1fr;
  }

  /* On mobile the sidebars are absolute overlays; undo desktop column pinning. */
  .sidebar-left,
  .map-wrap,
  .sidebar-right { grid-column: auto; }

  .sidebar-left,
  .sidebar-right {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 320px;
    z-index: 15;
    box-shadow: var(--shadow-md);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

  .sidebar-right {
    right: 0;
    transform: translateX(100%);
    border-left: 1px solid var(--c-border);
  }

  .sidebar-left.open,
  .sidebar-left:not(.collapsed) { transform: translateX(0); }
  .sidebar-right:not([hidden]) { transform: translateX(0); }

  .sidebar-toggle {
    display: flex;
    position: absolute;
    top: 50%;
    right: -32px;
    width: 32px;
    height: 56px;
    align-items: center;
    justify-content: center;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-left: none;
    border-radius: 0 var(--r-md) var(--r-md) 0;
  }

  .scenario-control { max-width: 200px; }
  .topbar-right .btn-icon-text span { display: none; }
  .btn-icon-text { padding: var(--sp-2); }
  .btn-icon-text { gap: 0; }
}

/* iPad / touch — bigger targets in draw mode */
@media (pointer: coarse) {
  .palette-item, .tool-btn { min-height: 44px; }
}

/* Drawing mode — disable map gesture conflict feedback */
body.draw-mode #map {
  cursor: crosshair;
}

body.draw-mode #map * {
  cursor: crosshair !important;
}

/* ====== Print ====== */
@media print {
  body {
    height: auto;
    overflow: visible;
  }
  .topbar, .sidebar-left, .sidebar-right, .map-overlay, .toast { display: none !important; }
  .layout { display: block; }
  .map-wrap { position: static; height: 80vh; }
  #map { position: relative; height: 100%; }

  .print-table {
    display: block !important;
    page-break-before: always;
    padding: var(--sp-6);
  }
}

.print-table {
  display: none;
}

.print-table table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
}

.print-table th,
.print-table td {
  text-align: left;
  padding: var(--sp-2) var(--sp-3);
  border-bottom: 1px solid var(--c-border);
}

.print-table th {
  background: var(--c-surface-2);
  font-weight: 600;
}

/* Auth bar in topbar */
.auth-bar {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  margin-left: var(--sp-2);
  padding-left: var(--sp-3);
  border-left: 1px solid var(--c-border);
}
.auth-bar-status {
  font-size: var(--fs-sm);
  color: var(--c-text-2);
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
}
.auth-bar-status.muted { color: var(--c-text-3); }
.auth-bar-status.online::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #2e7d32;
  display: inline-block;
}
.auth-bar .farm-tag {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: var(--fs-xs);
  background: var(--c-surface-2);
  padding: 2px 6px;
  border-radius: var(--r-sm);
}

.auth-dialog {
  border: none;
  border-radius: var(--r-md);
  padding: var(--sp-5);
  max-width: 420px;
  width: calc(100vw - 32px);
  background: var(--c-surface);
  color: var(--c-text-1);
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
}
.auth-dialog::backdrop { background: rgba(0,0,0,0.4); }
.auth-dialog h3 { margin: 0 0 var(--sp-2); }
.auth-dialog form { display: flex; flex-direction: column; gap: var(--sp-3); }
.auth-dialog label { display: flex; flex-direction: column; gap: var(--sp-1); font-size: var(--fs-sm); font-weight: 600; }
.auth-dialog input[type="email"],
.auth-dialog input[type="text"] {
  padding: var(--sp-3);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  font-size: var(--fs-md);
  width: 100%;
  box-sizing: border-box;
}
.auth-dialog input:focus { outline: 2px solid var(--c-primary); outline-offset: -1px; }
.auth-feedback { font-size: var(--fs-sm); color: var(--c-text-2); margin: 0; min-height: 1.2em; }
.auth-actions { display: flex; gap: var(--sp-2); justify-content: flex-end; }

@media (max-width: 720px) {
  .auth-bar { display: none; }
}
