:root {
  --bg: #f3efe7;
  --panel: #fffdf8;
  --panel-edge: #d8d0bf;
  --ink: #1d2d25;
  --ink-muted: #5b665b;
  --accent: #5d8454;
  --accent-soft: #e5efde;
  --alert: #a24732;
  --shadow: 0 14px 34px rgba(45, 51, 34, 0.09);
  --radius: 22px;
  --space-1: 10px;
  --space-2: 14px;
  --space-3: 18px;
  --space-4: 26px;
}

* {
  box-sizing: border-box;
}

html,
body {
  max-width: 100%;
  overflow-x: clip;
  overscroll-behavior-y: contain;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 4%, #ffffff 0%, rgba(255, 255, 255, 0.55) 34%, transparent 66%),
    linear-gradient(180deg, #f8f5ee 0%, var(--bg) 72%);
  color: var(--ink);
  font-family: "Source Sans 3", serif;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.backdrop-shape {
  position: fixed;
  width: 58vw;
  height: 58vw;
  max-width: 580px;
  max-height: 580px;
  background: linear-gradient(130deg, #e8dcc5, #f5f0e3 70%);
  border-radius: 47% 53% 60% 40% / 47% 36% 64% 53%;
  top: -210px;
  right: -120px;
  z-index: 0;
  opacity: 0.8;
}

.pull-refresh {
  --pull-offset: -76px;
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  left: 50%;
  transform: translate(-50%, var(--pull-offset));
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
  z-index: 12;
  pointer-events: none;
}

.pull-refresh.visible {
  opacity: 1;
}

.pull-refresh-inner {
  min-width: 150px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border-radius: 999px;
  border: 1px solid #d8c9ae;
  background: #f7f1e5;
  color: #3f4531;
  font-weight: 700;
  font-size: 0.86rem;
  padding: 8px 12px;
  box-shadow: 0 8px 18px rgba(44, 54, 40, 0.12);
}

.pull-spinner {
  width: 15px;
  height: 15px;
  border-radius: 999px;
  border: 2px solid #9a8f78;
  border-right-color: transparent;
  animation: spin 0.8s linear infinite;
  animation-play-state: paused;
}

.pull-refresh.refreshing .pull-spinner {
  animation-play-state: running;
}

.app-shell {
  max-width: 1060px;
  margin: 0 auto;
  padding: var(--space-3);
  position: relative;
  z-index: 1;
}

.topbar {
  display: flex;
  justify-content: flex-start;
  gap: var(--space-2);
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
  border: 1px solid #ded4c2;
  border-radius: 20px;
  background: linear-gradient(155deg, #fffdf8, #f8f2e6);
  padding: 14px 16px;
  box-shadow: 0 9px 24px rgba(58, 52, 35, 0.08);
}

main {
  display: grid;
  gap: var(--space-4);
}

h1,
h2,
h3 {
  font-family: "Fraunces", serif;
  margin: 0;
}

h1 {
  font-size: clamp(1.6rem, 4.6vw, 2.4rem);
  letter-spacing: -0.01em;
}

h2 {
  font-size: clamp(1.2rem, 3.8vw, 1.75rem);
  margin-bottom: var(--space-1);
}

h3 {
  font-size: clamp(1.05rem, 2.9vw, 1.3rem);
  margin-bottom: 9px;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 0.72rem;
  color: var(--ink-muted);
  margin: 0 0 4px;
}

.panel {
  background: linear-gradient(180deg, var(--panel), #faf7ef);
  border: 1px solid var(--panel-edge);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  animation: panel-enter 0.3s ease both;
}

.panel > h2 {
  margin-bottom: 6px;
  letter-spacing: -0.01em;
}

.quick-actions.panel {
  padding: 12px;
  position: sticky;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  z-index: 4;
  backdrop-filter: blur(12px);
  background: rgba(255, 252, 245, 0.9);
  margin-bottom: 14px;
}

.quick-actions.panel.compact {
  padding: 0;
  border: none;
  box-shadow: none;
  background: transparent;
  backdrop-filter: none;
  margin-bottom: 16px;
}

.quick-actions.panel.compact .quick-action-buttons {
  display: block;
}

.quick-actions.panel.compact .quick-action-buttons .btn {
  width: 100%;
}

.quick-action-buttons {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.status-banner {
  border-radius: 12px;
  border: 1px solid #d5c6a8;
  background: #f8f2e5;
  color: #4a513a;
  padding: 8px 10px;
  font-weight: 600;
  margin-bottom: 10px;
}

.status-banner.success {
  border-color: #b9cf9d;
  background: #ecf5df;
  color: #2d4b1e;
}

.status-banner.error {
  border-color: #e1b2a3;
  background: #faece8;
  color: #7a2f1f;
}

.subtle {
  margin: 0 0 var(--space-2);
  color: var(--ink-muted);
}

.hidden {
  display: none !important;
}

.form-grid {
  display: grid;
  gap: var(--space-2);
}

.form-grid.compact {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.sync-auth-grid {
  display: grid;
  gap: var(--space-2);
}

.sync-card {
  border: 1px solid #d8deca;
  border-radius: 16px;
  padding: 12px;
  background: linear-gradient(180deg, #fcfef9, #f4f8ef);
}

.sync-card h3 {
  margin-bottom: 4px;
}

.sync-connected {
  border: 1px solid #d8e0ca;
  border-radius: 16px;
  background: linear-gradient(180deg, #f8fcf5, #eef6e8);
  padding: 12px;
}

.sync-connected p {
  margin: 0;
}

.sync-kv {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.sync-kv span {
  font-weight: 700;
  color: #2f422d;
}

.sync-panel-compact {
  padding-top: 14px;
  padding-bottom: 14px;
}

.utility-panel {
  margin-top: 12px;
  border-top: 1px solid #e4dbc8;
  padding-top: 12px;
}

.utility-panel h3 {
  font-size: 1rem;
  margin-bottom: 8px;
}

.utility-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.utility-row .btn {
  flex: 1 1 180px;
}

label,
legend {
  display: block;
  font-weight: 600;
  font-size: 0.93rem;
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  margin-top: 6px;
  border: 1px solid #ccbfa5;
  border-radius: 12px;
  background: #fffefb;
  min-height: 48px;
  padding: 10px 12px;
}

input:focus-visible,
select:focus-visible,
button:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(122, 145, 95, 0.28);
  outline-offset: 1px;
}

fieldset {
  border: 1px dashed #baa986;
  border-radius: 12px;
  padding: var(--space-1) var(--space-2);
  margin: 0;
}

legend {
  padding: 0 6px;
}

.inline-check {
  display: flex;
  gap: 9px;
  align-items: center;
  font-weight: 500;
  margin-top: 8px;
}

.inline-check input {
  width: 1rem;
  height: 1rem;
  margin: 0;
  accent-color: var(--accent);
}

.btn {
  border: none;
  padding: 11px 16px;
  min-height: 46px;
  border-radius: 999px;
  background: linear-gradient(160deg, #678f5b, #4f7548);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.16s ease, filter 0.16s ease, box-shadow 0.16s ease;
  box-shadow: 0 6px 14px rgba(62, 95, 54, 0.24);
}

.btn:hover {
  filter: brightness(0.97);
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(62, 95, 54, 0.3);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn.ghost {
  background: linear-gradient(180deg, #f2ead9, #e9dec8);
  color: #3e432f;
  border: 1px solid #d8c9ae;
  box-shadow: none;
}

.btn.tiny {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 0.82rem;
}

#profileForm .btn,
#cropForm .btn {
  margin-top: 4px;
}

#cropForm {
  display: grid;
  gap: var(--space-2);
}

.crop-submit-sticky {
  position: sticky;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  z-index: 14;
  padding: 8px;
  border: 1px solid #d8ccb6;
  border-radius: 14px;
  background: rgba(252, 248, 239, 0.96);
  backdrop-filter: blur(6px);
}

.crop-submit-sticky .btn {
  width: 100%;
  margin-top: 0;
}

.crop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 10px;
  margin-bottom: var(--space-2);
}

.crop-sections {
  display: grid;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}

.crop-section {
  border: 1px solid #d8ccb6;
  border-radius: 16px;
  padding: 12px;
  background: linear-gradient(180deg, #fdf9f1, #f8f1e4);
}

.crop-section-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  cursor: pointer;
  list-style: none;
}

.crop-section-summary::-webkit-details-marker {
  display: none;
}

.crop-section-summary::after {
  content: "Open";
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: #5f6f52;
}

.crop-section[open] .crop-section-summary::after {
  content: "Close";
}

.crop-section h4 {
  margin: 0;
  font-family: "Fraunces", serif;
  font-size: 1rem;
}

.crop-section-count {
  border: 1px solid #cfbea1;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 0.74rem;
  font-weight: 700;
  color: #4c5a3e;
  background: #f7f1e5;
}

.crop-section .crop-grid {
  margin-top: 10px;
  margin-bottom: 0;
}

.crop-chip {
  border: 1px solid #cfbea1;
  border-radius: 15px;
  padding: 11px 12px;
  background: #fffdf9;
  display: grid;
  gap: 10px;
  align-items: stretch;
  transition: border-color 0.14s ease, background-color 0.14s ease, box-shadow 0.14s ease, transform 0.14s ease;
}

.crop-chip:hover {
  border-color: #b4a27d;
  transform: translateY(-1px);
}

.crop-chip.selected,
.crop-chip:has(.crop-pick input:checked) {
  border-color: #8ba26f;
  background: #f2f7ea;
  box-shadow: inset 0 0 0 1px #d4e3bd;
}

.crop-pick {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 0;
  font-weight: 600;
}

.crop-pick input {
  width: 1rem;
  height: 1rem;
  margin: 0;
  accent-color: var(--accent);
}

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

.placement-option {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  border: 1px solid #d3c6ae;
  border-radius: 12px;
  min-height: 40px;
  padding: 8px 10px;
  font-size: 0.84rem;
  font-weight: 600;
  background: #fff;
  color: #47513a;
  line-height: 1.2;
}

.placement-option.selected,
.placement-option:has(input:checked) {
  border-color: #8ba26f;
  background: #ecf4e4;
  color: #2f4929;
}

.placement-option input {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  margin: 0;
  pointer-events: none;
}

.dashboard-head {
  display: flex;
  justify-content: space-between;
  gap: var(--space-2);
  align-items: flex-start;
  flex-wrap: wrap;
}

#dashboard {
  display: grid;
  gap: 14px;
}

#dashboard > h2 {
  margin-bottom: 0;
}

#dashboard > article {
  background: linear-gradient(180deg, #fdf9f1, #f7f1e4);
  border: 1px solid #decfb4;
  border-radius: 16px;
  padding: 12px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.section-head h3 {
  margin-bottom: 0;
}

.weather-card {
  background: linear-gradient(155deg, #f9fcf7, #eaf3e5);
  border-radius: 16px;
  border: 1px solid #d7e4d1;
  padding: 14px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

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

.weather-summary span {
  display: block;
  font-size: 0.92rem;
}

.notice-list,
.task-list,
.plain-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 7px;
}

.notice-list li {
  color: #54381f;
}

.task-list li {
  color: #25381f;
}

.alert {
  color: var(--alert);
  font-weight: 700;
}

.watering-checklist-wrap {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid #e5dcc9;
}

.upcoming-tasks-wrap {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid #e5dcc9;
}

.upcoming-tasks-wrap h4 {
  margin: 0 0 8px;
  font-family: "Fraunces", serif;
  font-size: 1rem;
}

.upcoming-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.upcoming-task-item {
  border: 1px solid #ddd5c3;
  border-radius: 12px;
  background: #fbf7ee;
  padding: 8px 10px;
  display: grid;
  gap: 2px;
}

.upcoming-task-date {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #5f6b5b;
  font-weight: 700;
}

.upcoming-task-main {
  color: #253626;
  font-size: 0.95rem;
}

.upcoming-task-count {
  color: #5e6c59;
  font-size: 0.84rem;
}

.watering-checklist-wrap h4 {
  margin: 0 0 8px;
  font-family: "Fraunces", serif;
  font-size: 1rem;
}

.watering-checklist {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.watering-check-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  font-weight: 500;
}

.watering-check-item input {
  width: 1rem;
  height: 1rem;
  margin: 2px 0 0;
  accent-color: var(--accent);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid #e4e8dd;
  border-radius: 14px;
}

.schedule-cards {
  display: none;
  gap: 10px;
}

.schedule-card {
  border: 1px solid #d2dccb;
  border-radius: 16px;
  background: linear-gradient(170deg, #fcfef9, #eff5ea);
  padding: 14px;
  box-shadow: 0 8px 20px rgba(41, 57, 37, 0.07);
  overflow: hidden;
}

.schedule-card-summary {
  list-style: none;
  cursor: pointer;
  display: grid;
  gap: 8px;
}

.schedule-card-summary::-webkit-details-marker {
  display: none;
}

.schedule-card-summary::after {
  content: "Show details";
  font-size: 0.78rem;
  font-weight: 700;
  color: #51614d;
  justify-self: start;
}

.schedule-card[open] .schedule-card-summary::after {
  content: "Hide details";
}

.schedule-card-body {
  display: none;
  gap: 13px;
  margin-top: 10px;
}

.schedule-card[open] .schedule-card-body {
  display: grid;
}

.schedule-stages {
  display: grid;
  gap: 10px;
}

.schedule-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.schedule-card-head h4 {
  margin: 0;
  font-family: "Fraunces", serif;
  font-size: 1.05rem;
}

.schedule-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: var(--accent-soft);
  color: #345031;
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 700;
}

.schedule-next-action {
  margin: 0;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid #d7e2d1;
  background: #f8fcf6;
  display: grid;
  gap: 2px;
}

.schedule-next-action .schedule-next-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #5e6f5b;
  font-weight: 700;
}

.schedule-next-action strong {
  font-size: 0.95rem;
  color: #243324;
}

.schedule-next-action.warn {
  border-color: #decb8f;
  background: #f9f2d8;
}

.schedule-next-action.ok {
  border-color: #c8dcbe;
  background: #edf7e9;
}

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

.schedule-milestone {
  border: 1px solid #dce7d7;
  border-radius: 12px;
  background: #ffffff;
  padding: 8px 10px;
  display: grid;
  gap: 2px;
}

.schedule-milestone strong {
  font-size: 0.95rem;
  color: #253526;
}

.milestone-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #61715d;
}

.schedule-note-block {
  border: 1px dashed #d1dac7;
  border-radius: 12px;
  padding: 9px 10px;
  background: #f8fcf6;
  display: grid;
  gap: 6px;
}

.schedule-note {
  margin: 0;
  font-size: 0.89rem;
  color: #314032;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 700px;
}

th,
td {
  border-bottom: 1px solid #e3d7c1;
  text-align: left;
  padding: 9px 8px;
  font-size: 0.92rem;
  vertical-align: top;
}

.indoor-cell {
  display: grid;
  gap: 8px;
  min-width: 0;
  border: 1px solid #d8e2d3;
  border-radius: 12px;
  padding: 10px;
  background: #ffffff;
}

.indoor-cell-direct {
  background: #f8fbf6;
}

.indoor-primary {
  border: 1px solid #dce7d7;
  border-radius: 12px;
  background: #f9fcf7;
  padding: 9px 10px;
  display: grid;
  gap: 3px;
}

.indoor-primary-overdue {
  border-color: #decf95;
  background: #fbf4d9;
}

.indoor-primary-date {
  display: block;
  font-size: 1.03rem;
  color: #253526;
}

.indoor-primary-meta {
  font-size: 0.73rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #61715d;
  font-weight: 700;
}

.indoor-summary {
  margin: 0;
  font-size: 0.88rem;
  color: #3b4a3b;
}

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

.indoor-date-box {
  border: 1px solid #dce5d7;
  border-radius: 10px;
  background: #f7fbf4;
  padding: 7px 8px;
  display: grid;
  gap: 2px;
}

.indoor-date-box span {
  font-size: 0.73rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
  color: #63715f;
}

.indoor-date-box strong {
  font-size: 0.9rem;
  color: #29372b;
}

.inline-date-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-muted);
}

.inline-date-label input {
  min-height: 38px;
  padding: 6px 8px;
}

.inline-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.schedule-indoor .inline-actions .btn {
  flex: 1 1 auto;
}

.inline-actions .save-log-btn {
  border-color: #497041;
}

.inline-actions .clear-start-btn,
.inline-actions .clear-plant-btn,
.inline-actions .clear-harvest-btn {
  border-color: #dec6be;
  background: #f8efec;
  color: #6e3528;
}

.inline-actions .clear-start-btn:hover,
.inline-actions .clear-plant-btn:hover,
.inline-actions .clear-harvest-btn:hover {
  background: #f3e0dc;
}

.inline-actions .start-today-btn:hover {
  background: #e7f0df;
}

th {
  color: #536148;
  font-weight: 700;
}

.split {
  display: grid;
  gap: var(--space-2);
}

details {
  margin-top: var(--space-2);
}

summary {
  cursor: pointer;
  font-weight: 600;
  color: #38412b;
}

details[open] summary {
  margin-bottom: 10px;
}

@keyframes panel-enter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@media (min-width: 760px) {
  .app-shell {
    padding: 24px;
  }

  .topbar {
    align-items: center;
  }

  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #profileForm .btn {
    grid-column: 1 / -1;
    justify-self: start;
    min-width: 220px;
  }

  #cropForm .btn {
    min-width: 220px;
  }

  .split {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sync-auth-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 759px) {
  main {
    gap: 14px;
  }

  .app-shell {
    padding: 14px;
  }

  .panel {
    padding: 15px;
    border-radius: 17px;
  }

  .quick-action-buttons .btn {
    flex: 1 1 100%;
    text-align: center;
  }

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

  .weather-summary {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    display: none;
  }

  .schedule-cards {
    display: grid;
  }

  .schedule-milestones,
  .indoor-dates {
    grid-template-columns: 1fr;
  }

  #profileForm .btn,
  #cropForm .btn {
    width: 100%;
  }

  .utility-row .btn {
    flex: 1 1 calc(50% - 5px);
    min-width: 0;
  }

}
