:root {
  --bg: #f6f4ee;
  --surface: #ffffff;
  --surface-2: #eeebe2;
  --text: #1f2a20;
  --muted: #5d665c;
  --border: #d9d4c7;
  --brand: #2f6b3a;
  --brand-strong: #245530;
  --brand-soft: #e3efe0;
  --accent: #c98a12;
  --warn-bg: #fdf0d5;
  --warn-text: #7a4b00;
  --bad-bg: #fbe1dd;
  --bad-text: #8a2116;
  --good-bg: #e2f1e0;
  --good-text: #23552c;
  --info-bg: #e3edf7;
  --info-text: #1d4467;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 2px 8px rgba(0, 0, 0, 0.05);
  --radius: 10px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, Ubuntu, 'Helvetica Neue', Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #141a15;
    --surface: #1d241e;
    --surface-2: #263027;
    --text: #e7ece4;
    --muted: #a5b0a3;
    --border: #36423a;
    --brand: #7cc287;
    --brand-strong: #9ad3a3;
    --brand-soft: #23382a;
    --accent: #e6b545;
    --warn-bg: #3a2f14;
    --warn-text: #f3d28d;
    --bad-bg: #3d1f1b;
    --bad-text: #f4b3a9;
    --good-bg: #1f3824;
    --good-text: #a8dcb0;
    --info-bg: #1b2c3d;
    --info-text: #a9cbec;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--brand); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 0.5rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 0.75rem; }
main { flex: 1; outline: none; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.app-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1000;
}
.brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; }
.app-nav { display: flex; gap: 0.25rem; overflow-x: auto; scrollbar-width: none; }
.app-nav a { padding: 0.4rem 0.7rem; border-radius: 999px; color: var(--muted); text-decoration: none; white-space: nowrap; }
.app-nav a:hover { background: var(--surface-2); color: var(--text); }
.app-nav a.active { background: var(--brand-soft); color: var(--brand-strong); font-weight: 600; }

.page { max-width: 1100px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.card h2 { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.stat-row { display: flex; flex-wrap: wrap; gap: 0.75rem 1.5rem; }
.stat { display: flex; flex-direction: column; }
.stat b { font-size: 1.25rem; }
.stat span { color: var(--muted); font-size: 0.8rem; }

button, .button {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 0.45rem 0.85rem;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}
button:hover, .button:hover { background: var(--surface-2); }
button.primary, .button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
button.primary:hover, .button.primary:hover { background: var(--brand-strong); }
button.danger { color: var(--bad-text); border-color: var(--bad-text); }
button.active { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-strong); font-weight: 600; }
button:disabled { opacity: 0.55; cursor: not-allowed; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) button.primary, :root:not([data-theme='light']) .button.primary { color: #10180f; }
}

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.55rem;
  max-width: 100%;
}
input[type='checkbox'] { width: 1.05rem; height: 1.05rem; accent-color: var(--brand); }
label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; }
label.inline { flex-direction: row; align-items: center; gap: 0.5rem; }
.form-row { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-end; margin-bottom: 0.75rem; }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 0.75rem; }

.notice { padding: 0.65rem 0.85rem; border-radius: 8px; margin: 0.5rem 0; font-size: 0.92rem; }
.notice.warn { background: var(--warn-bg); color: var(--warn-text); }
.notice.error { background: var(--bad-bg); color: var(--bad-text); }
.notice.good { background: var(--good-bg); color: var(--good-text); }
.notice.info { background: var(--info-bg); color: var(--info-text); }

.chip { display: inline-flex; align-items: center; gap: 0.3rem; padding: 0.1rem 0.55rem; border-radius: 999px; font-size: 0.78rem; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.chip.full { background: #fff1c2; color: #6b4e00; }
.chip.part-sun { background: #fde6b3; color: #6a4300; }
.chip.part-shade { background: #dbe7f3; color: #24496b; }
.chip.shade { background: #d9dcef; color: #2f3566; }
.grade { font-weight: 700; font-size: 0.72rem; padding: 0.05rem 0.4rem; border-radius: 4px; }
.grade.A { background: var(--good-bg); color: var(--good-text); }
.grade.B { background: var(--info-bg); color: var(--info-text); }
.grade.C { background: var(--surface-2); color: var(--muted); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 0.5rem 0; border-bottom: 1px solid var(--border); display: flex; gap: 0.5rem; align-items: flex-start; }
.list li:last-child { border-bottom: none; }
.finding { display: flex; gap: 0.5rem; align-items: flex-start; padding: 0.45rem 0.6rem; border-radius: 8px; margin: 0.35rem 0; font-size: 0.9rem; }
.finding.warn { background: var(--warn-bg); color: var(--warn-text); }
.finding.good { background: var(--good-bg); color: var(--good-text); }
.finding.info { background: var(--info-bg); color: var(--info-text); }

table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 0.82rem; }
.table-wrap { overflow-x: auto; }

/* Map editor */
.map-layout { display: grid; grid-template-columns: 1fr 360px; grid-template-rows: auto 1fr; height: calc(100vh - 57px); }
.toolbar { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; padding: 0.5rem 0.75rem; background: var(--surface); border-bottom: 1px solid var(--border); }
.toolbar .sep { width: 1px; align-self: stretch; background: var(--border); margin: 0 0.25rem; }
.map-wrap { position: relative; min-height: 300px; }
.map { position: absolute; inset: 0; }
.map-hint { position: absolute; top: 0.6rem; left: 50%; transform: translateX(-50%); z-index: 500; background: rgba(20, 28, 21, 0.85); color: #fff; padding: 0.4rem 0.8rem; border-radius: 999px; font-size: 0.85rem; pointer-events: none; max-width: 90%; text-align: center; }
.map-hint:empty { display: none; }
.legend { position: absolute; bottom: 1.4rem; left: 0.6rem; z-index: 500; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 0.4rem 0.6rem; font-size: 0.78rem; box-shadow: var(--shadow); }
.legend-row { display: flex; align-items: center; gap: 0.4rem; }
.swatch { width: 14px; height: 10px; border-radius: 2px; display: inline-block; }
.panel { background: var(--surface); border-left: 1px solid var(--border); overflow-y: auto; padding: 1rem; }
.panel h2 input { font-size: 1.1rem; font-weight: 700; width: 100%; }
.panel section { margin: 1rem 0; }
.panel section h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.bars { width: 100%; height: 110px; }
.capacity { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.capacity > div { height: 100%; background: var(--brand); }
.capacity.over > div { background: #c0392b; }
.suggest { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.suggest button { font-size: 0.82rem; padding: 0.25rem 0.6rem; }
.planting { display: grid; grid-template-columns: 1fr 70px auto auto; gap: 0.35rem; align-items: center; }
.planting input { width: 70px; }
.vertex-handle { width: 12px; height: 12px; background: #fff; border: 2px solid #f9a825; border-radius: 3px; }
.slope-marker svg { overflow: visible; }

/* Measure */
.viewfinder { position: relative; background: #000; border-radius: var(--radius); overflow: hidden; aspect-ratio: 3 / 4; max-height: 60vh; }
.viewfinder video { width: 100%; height: 100%; object-fit: cover; }
.crosshair { position: absolute; inset: 0; pointer-events: none; }
.crosshair::before, .crosshair::after { content: ''; position: absolute; background: #ffeb3b; }
.crosshair::before { left: 0; right: 0; top: 50%; height: 2px; }
.crosshair::after { top: 0; bottom: 0; left: 50%; width: 2px; }
.angle-readout { font-size: 2.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.mini-map { height: 260px; border-radius: var(--radius); border: 1px solid var(--border); }
.tabs { display: flex; gap: 0.35rem; margin-bottom: 1rem; }

/* Calendar */
.month-group h3 { margin-top: 1.25rem; }
.task { display: flex; gap: 0.6rem; align-items: center; padding: 0.4rem 0; border-bottom: 1px solid var(--border); }
.task.done span.title { text-decoration: line-through; color: var(--muted); }
.task .date { width: 4.5rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.task .tag { margin-left: auto; }

/* Plants */
.plant-card summary { cursor: pointer; display: flex; justify-content: space-between; gap: 0.5rem; align-items: center; list-style: none; }
.plant-card summary::-webkit-details-marker { display: none; }
.plant-card { padding: 0.75rem 1rem; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0.2rem 1rem; font-size: 0.9rem; margin: 0.5rem 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.weather { display: flex; gap: 0.5rem; overflow-x: auto; padding-bottom: 0.25rem; }
.weather div { min-width: 92px; background: var(--surface-2); border-radius: 8px; padding: 0.45rem; font-size: 0.8rem; }
.weather b { display: block; font-size: 1.05rem; }
.checklist li { align-items: center; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--brand); border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 860px) {
  .app-header { flex-direction: column; align-items: stretch; gap: 0.4rem; padding: 0.5rem 0.75rem; }
  .app-nav { margin: 0 -0.75rem; padding: 0 0.75rem; }
  .map-layout { grid-template-columns: 1fr; grid-template-rows: auto 55vh auto; height: auto; }
  .panel { border-left: none; border-top: 1px solid var(--border); }
  .page { padding: 1rem 0.75rem 3rem; }
}

/* Bed View */
.bedview { max-width: 1240px; }
.bedview-head { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: flex-end; margin-bottom: 0.75rem; }
.bedview-head h1 { margin: 0 1rem 0 0; }
.bedview-body { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1rem; align-items: start; }
.bed-stage { padding: 0.75rem; }
.bed-svg { width: 100%; height: auto; max-height: 62vh; display: block; touch-action: none; user-select: none; }
.bed-soil { fill: #e8dcc4; }
.bed-outline { fill: none; stroke: #6d4c2f; stroke-width: 0.06; }
.edge-blocked { stroke: #c0392b; stroke-width: 0.12; stroke-dasharray: 0.25 0.15; }
.cell-selected { stroke: #111; stroke-width: 0.05; fill: none; pointer-events: none; }
.plant { cursor: grab; }
.plant:active { cursor: grabbing; }
.plant-mature { stroke-width: 0.04; stroke-dasharray: 0.12 0.08; opacity: 0.8; }
.plant-now { stroke: #fff; stroke-width: 0.03; opacity: 0.92; }
.plant-label { fill: #fff; font-weight: 700; pointer-events: none; paint-order: stroke; stroke: rgba(0, 0, 0, 0.35); stroke-width: 0.03; }
.plant.ghost .plant-now { opacity: 0.25; }
.plant.ghost .plant-label { fill: #333; stroke: none; }
.plant:focus-visible .plant-mature { stroke-width: 0.1; }
.compass path, .scalebar line { stroke: var(--text); stroke-width: 0.05; fill: none; }
.compass text, .scalebar text { font-size: 0.3px; fill: var(--text); font-weight: 700; }
.season-bar { display: flex; gap: 0.6rem; align-items: center; margin-top: 0.6rem; flex-wrap: wrap; }
.season-bar input[type='range'] { flex: 1; min-width: 160px; accent-color: var(--brand); }
.arrange-row { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; margin-top: 0.6rem; }
.plant-key { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; margin-top: 0.75rem; }
.key-row { display: flex; gap: 0.4rem; align-items: center; font-size: 0.88rem; }
.key-dot { min-width: 1.9rem; height: 1.4rem; border-radius: 999px; color: #fff; font-size: 0.72rem; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; padding: 0 0.3rem; }
.bed-side { position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow-y: auto; }
.bed-side h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 0.75rem 0 0.35rem; }
.layer-picker label { padding: 0.15rem 0; }
.heat-legend .legend-row { font-size: 0.85rem; padding: 0.1rem 0; }
.heat-legend .swatch { width: 22px; height: 12px; border: 1px solid var(--border); }
@media (max-width: 860px) {
  .bedview-body { grid-template-columns: 1fr; }
  .bed-side { position: static; max-height: none; }
}
