:root {
  --primary: #3FA659; --primary-dark: #2E7D43; --primary-soft: #E5F2E9;
  --secondary: #78AC53; --tertiary: #409681; --tertiary-soft: #DDEEE9;
  --accent: #D79942; --accent-soft: #FBEDD3;
  --surface: #F4F6F4; --border: #DBE1DC; --muted: #657267; --text: #1E241F;
  --danger: #C0392B; --danger-soft: #FBE9E6;
  --card-shadow: 0 1px 0 rgba(30,36,31,.04), 0 1px 2px rgba(30,36,31,.04);
  --font-display: "Fraunces","Times New Roman",serif;
  --font-sans: "Inter",-apple-system,BlinkMacSystemFont,"Helvetica Neue",sans-serif;
  --font-mono: "JetBrains Mono",ui-monospace,monospace;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body { font-family: var(--font-sans); background: var(--surface); color: var(--text);
  -webkit-font-smoothing: antialiased; font-size: 14px; line-height: 1.5; }
button { font: inherit; cursor: pointer; border: none; background: none; }
a { color: inherit; text-decoration: none; }
table { border-collapse: collapse; width: 100%; }

/* ─── TOPBAR ──────────────────────────────────────────────────── */
.topbar { position: sticky; top: 0; z-index: 50; background: rgba(244,246,244,.92);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 20px; padding: 0 24px; height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.brand-mark { width: 32px; height: 32px; border-radius: 10px; flex-shrink: 0; }
.brand-text { display: flex; flex-direction: column; }
.brand-name { font-family: var(--font-display); font-size: 18px; font-weight: 500; line-height: 1; }
.brand-sub { font-size: 9px; letter-spacing: .2em; text-transform: uppercase;
  color: var(--muted); margin-top: 3px; }

.nav { flex: 1; display: flex; gap: 2px; overflow-x: auto; min-width: 0;
  scrollbar-width: none; -ms-overflow-style: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { padding: 6px 12px; border-radius: 6px; font-size: 13px; color: var(--muted);
  white-space: nowrap; transition: background .12s, color .12s; flex-shrink: 0; }
.nav a:hover { color: var(--text); background: rgba(30,36,31,.05); }
.nav a.active { color: var(--text); background: var(--primary-soft); font-weight: 500; }
.nav-badge { display: inline-block; margin-left: 4px; padding: 0 6px;
  border-radius: 999px; background: var(--accent); color: white;
  font-size: 10px; font-weight: 600; min-width: 16px; text-align: center; }

.auth-area { flex-shrink: 0; display: flex; align-items: center; gap: 10px; }
.auth-status { display: flex; align-items: center; gap: 6px; padding: 5px 10px;
  border: 1px solid var(--border); border-radius: 6px; background: white;
  font-size: 12px; color: var(--muted); max-width: 200px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.auth-status .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }
.auth-status.connected .dot { background: var(--primary); }
.auth-status.connected { color: var(--primary-dark); }

/* ─── BUTTONS ─────────────────────────────────────────────────── */
.btn { padding: 6px 12px; border-radius: 6px; font-size: 13px;
  border: 1px solid var(--border); background: white; color: var(--text);
  transition: background .15s, border-color .15s; }
.btn:hover { background: var(--surface); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: white; border-color: var(--danger); }
.btn-danger:hover { background: #962D22; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface); color: var(--text); border-color: var(--border); }

/* ─── MAIN / HERO ─────────────────────────────────────────────── */
main { max-width: 1600px; margin: 0 auto; padding: 32px 24px 80px; }
.hero { margin-bottom: 28px; }
.hero h1 { font-family: var(--font-display); font-weight: 400; font-size: 34px;
  line-height: 1.1; letter-spacing: -.025em; }
.hero h1 em { font-style: italic; color: var(--primary); }
.hero-sub { margin-top: 8px; color: var(--muted); font-size: 14px; max-width: 560px; }

/* ─── KPI GRID ────────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px;
  margin-bottom: 36px; }
.kpi-card { background: white; border: 1px solid var(--border); border-radius: 16px;
  padding: 20px; box-shadow: var(--card-shadow); }
.kpi-label { font-size: 10px; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
.kpi-value { margin-top: 6px; font-family: var(--font-display); font-weight: 400;
  font-size: 32px; letter-spacing: -.02em; font-feature-settings: "tnum"; }
.kpi-meta { margin-top: 4px; font-size: 12px; color: var(--muted); min-height: 1em; }

/* ─── SECTION HEADER ──────────────────────────────────────────── */
.section-header { display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 14px; gap: 12px; flex-wrap: wrap; }
.section-header h2 { font-family: var(--font-display); font-weight: 400; font-size: 26px;
  letter-spacing: -.02em; display: inline-flex; align-items: baseline; gap: 10px; }
.count-pill { font-family: var(--font-mono); font-size: 12px; font-weight: 400;
  color: var(--muted); padding: 2px 8px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 999px; }
.section-sub { margin-top: 6px; font-size: 12px; color: var(--muted); }
.section-sub code { font-family: var(--font-mono); font-size: 11px;
  background: var(--surface); padding: 1px 5px; border-radius: 3px; border: 1px solid var(--border); }
.section-sub .show-all { color: var(--tertiary); cursor: pointer; }
.section-sub .show-all:hover { text-decoration: underline; }
.section-controls { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* ─── VIEW TOGGLE ─────────────────────────────────────────────── */
.view-toggle { display: inline-flex; padding: 3px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; }
.view-toggle button { padding: 4px 11px; font-size: 13px; color: var(--muted);
  border-radius: 5px; transition: all .15s; }
.view-toggle button.active { background: white; color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,.05); font-weight: 500; }

/* ─── SCHEMA DRIFT BANNER ─────────────────────────────────────── */
.schema-drift { margin: 0 0 14px; padding: 10px 14px; font-size: 12px;
  background: var(--accent-soft); border: 1px solid var(--accent);
  border-radius: 10px; color: #8B5E1A; }
.schema-drift code { font-family: var(--font-mono); font-size: 11px;
  background: rgba(255,255,255,.6); padding: 1px 5px; border-radius: 3px; }

/* ─── DATA TABLE ──────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: 16px;
  background: white; border: 1px solid var(--border); box-shadow: var(--card-shadow); }
.data-table { width: 100%; font-size: 13px; }
.data-table thead th { padding: 10px 16px; text-align: left; font-size: 10px; font-weight: 500;
  letter-spacing: .14em; text-transform: uppercase; color: var(--muted);
  border-bottom: 1px solid var(--border); background: var(--surface);
  white-space: nowrap; position: sticky; top: 0; }
.data-table thead th.num { text-align: right; }
.data-table tbody td { padding: 12px 16px; border-bottom: 1px solid var(--border);
  vertical-align: middle; white-space: nowrap; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: rgba(63,166,89,.03); }
.data-table td.num, .data-table td.mono { font-family: var(--font-mono); font-feature-settings: "tnum"; }
.data-table td.num { text-align: right; }
.data-table td.id { font-family: var(--font-mono); font-size: 12px; color: var(--muted); }
.data-table td.email a { color: var(--tertiary); }
.data-table td.email a:hover { text-decoration: underline; }
.data-table td.money { color: var(--text); font-weight: 500; }
.data-table td.muted-cell { color: var(--muted); }
.data-table td.timestamp { color: var(--muted); font-family: var(--font-mono); font-size: 12px; }
.data-table td.long-text { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.data-table td .badge { display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 500; background: var(--surface); color: var(--muted); }
.data-table .empty-cell { color: var(--muted); }

/* column hide */
.col-header-inner { display: inline-flex; align-items: center; gap: 6px; }
.col-hide-btn { opacity: 0; border: none; background: none; cursor: pointer;
  color: var(--muted); padding: 0 4px; border-radius: 4px; font-size: 14px; line-height: 1;
  transition: opacity .15s, background .15s, color .15s; }
.data-table thead th:hover .col-hide-btn { opacity: 0.6; }
.col-hide-btn:hover { opacity: 1 !important; background: var(--accent-soft); color: var(--accent); }

/* editable cells */
.data-table td.editable-cell { cursor: text; }
.data-table td.editable-cell:hover { background: var(--primary-soft); }
.data-table td.editing-cell { padding: 6px 8px; background: var(--primary-soft); }
.data-table td.saving-cell { color: var(--muted); font-style: italic; }
.data-table td.cell-flash-ok { background: rgba(63,166,89,.18) !important; transition: background 1s; }
.inline-edit-input { width: 100%; min-width: 100px; padding: 6px 8px; border: 1px solid var(--primary);
  border-radius: 6px; font-family: inherit; font-size: 13px; outline: none;
  background: white; color: var(--text); }
.inline-edit-input:focus { border-color: var(--primary-dark); box-shadow: 0 0 0 3px rgba(63,166,89,.18); }

/* row delete */
.data-table thead th.col-actions { width: 1%; padding-left: 8px; padding-right: 8px; }
.data-table tbody td.cell-actions { width: 1%; padding-left: 8px; padding-right: 8px; text-align: center; }
.row-delete-btn { width: 26px; height: 26px; border-radius: 6px; background: transparent;
  color: var(--muted); border: 1px solid transparent; display: inline-flex;
  align-items: center; justify-content: center; font-size: 16px; line-height: 1;
  transition: all .15s; }
.row-delete-btn:hover { background: var(--danger-soft); color: var(--danger); border-color: rgba(192,57,43,.25); }
.data-table tbody tr.row-deleting { opacity: .5; pointer-events: none; }

/* FK links + row highlight */
.fk-link { font-family: var(--font-mono); font-size: 12px; color: var(--tertiary);
  background: none; border: none; cursor: pointer; padding: 2px 5px; border-radius: 4px;
  display: inline-flex; align-items: center; gap: 3px; transition: background .12s; }
.fk-link:hover { background: var(--tertiary-soft); }
.fk-arrow { font-size: 10px; opacity: 0.65; }
@keyframes fk-flash {
  0%   { background: var(--accent-soft); outline-color: var(--accent); }
  70%  { background: var(--accent-soft); outline-color: var(--accent); }
  100% { background: transparent; outline-color: transparent; }
}
.data-table tbody tr.row-fk-highlight {
  animation: fk-flash 2.4s ease-out forwards;
  outline: 2px solid var(--accent); outline-offset: -2px;
}

/* ─── STATE PANELS ────────────────────────────────────────────── */
.state-panel { padding: 48px 24px; text-align: center;
  background: white; border: 1px solid var(--border); border-radius: 16px; }
.state-panel .state-title { font-family: var(--font-display); font-size: 20px; margin-bottom: 6px; }
.state-panel .state-msg { color: var(--muted); font-size: 13px; max-width: 460px; margin: 0 auto 16px; }
.state-panel .state-msg code { font-family: var(--font-mono); font-size: 12px;
  background: var(--surface); padding: 2px 6px; border-radius: 4px; border: 1px solid var(--border); }
.state-panel.error .state-title { color: var(--accent); }
.spinner { width: 26px; height: 26px; border: 2.5px solid var(--border);
  border-top-color: var(--primary); border-radius: 50%; margin: 0 auto 14px;
  animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── MAP ─────────────────────────────────────────────────────── */
#garden-map { height: 580px; border-radius: 16px; border: 1px solid var(--border);
  overflow: hidden; z-index: 1; }
.leaflet-container { font: inherit; background: var(--primary-soft); }
.flhour-marker { position: relative; }
.flhour-marker .pulse { position: absolute; left: 50%; top: 50%; width: 32px; height: 32px;
  margin: -16px 0 0 -16px; border-radius: 50%; background: rgba(63,166,89,.35);
  animation: pulse 2.4s ease-out infinite; }
.flhour-marker .dot { position: absolute; left: 50%; top: 50%; width: 16px; height: 16px;
  margin: -8px 0 0 -8px; border-radius: 50%; background: var(--primary);
  border: 2px solid white; box-shadow: 0 2px 4px rgba(0,0,0,.25); }
@keyframes pulse { 0% { transform: scale(.6); opacity: 1; } 100% { transform: scale(2.2); opacity: 0; } }
.leaflet-popup-content-wrapper { border-radius: 10px; border: 1px solid var(--border);
  box-shadow: 0 4px 16px rgba(0,0,0,.08); }
.leaflet-popup-content { margin: 12px 14px; font-family: var(--font-sans); }
.leaflet-popup-content .pop-name { font-family: var(--font-display); font-size: 16px; font-weight: 500; }
.leaflet-popup-content .pop-meta { font-size: 11px; color: var(--muted); font-family: var(--font-mono); margin-top: 2px; }
.leaflet-popup-content .pop-desc { font-size: 13px; margin-top: 8px; }
.leaflet-popup-content .pop-coords { font-family: var(--font-mono); font-size: 11px;
  color: var(--muted); margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); }

/* ─── OVERLAYS + MODALS (unified) ─────────────────────────────── */
.overlay { position: fixed; inset: 0; background: rgba(30,36,31,.4);
  backdrop-filter: blur(4px); z-index: 100; display: none;
  align-items: center; justify-content: center; padding: 16px; }
/* JS toggles .open on auth-overlay and .show on db-wake-overlay/confirm-overlay */
.overlay.open, .overlay.show { display: flex; }

.modal { width: 420px; max-width: calc(100vw - 32px); background: white;
  border-radius: 16px; padding: 28px; box-shadow: 0 8px 32px rgba(30,36,31,.2); }
.modal-head { margin-bottom: 16px; }
.modal-head h3 { font-family: var(--font-display); font-size: 22px; font-weight: 400;
  letter-spacing: -.02em; margin-bottom: 6px; }
.modal-head p { color: var(--muted); font-size: 13px; line-height: 1.5; }
.modal-head p code { font-family: var(--font-mono); font-size: 12px;
  background: var(--surface); padding: 2px 6px; border-radius: 4px; }
.modal-body { display: flex; flex-direction: column; gap: 4px; }
.modal-actions { display: flex; gap: 10px; margin-top: 22px; }
.modal-actions .grow { flex: 1; }

/* auth modal */
.auth-modal label { display: block; font-size: 11px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--muted); margin-bottom: 6px; margin-top: 14px; }
.auth-modal label:first-of-type { margin-top: 0; }
.auth-modal input { width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-family: var(--font-sans); font-size: 14px;
  outline: none; transition: border-color .15s; margin-top: 4px; }
.auth-modal input:focus { border-color: var(--primary); }
.auth-error { margin-top: 16px; padding: 10px 12px;
  background: rgba(215,153,66,.1); border: 1px solid var(--accent);
  border-radius: 8px; color: #8B5E1A; font-size: 12px; display: none; }
.auth-error.show { display: block; }
.advanced-toggle { margin-top: 16px; padding: 4px 0; width: 100%; text-align: center;
  background: none; border: none; color: var(--tertiary); font-size: 12px; cursor: pointer; }
.advanced-toggle:hover { text-decoration: underline; }
.advanced { margin-top: 12px; padding-top: 12px;
  border-top: 1px solid var(--border); display: none; }
.advanced.open { display: block; }
.advanced input { font-family: var(--font-mono); font-size: 12px; }

/* db wake modal */
.db-wake-modal { text-align: center; padding: 36px 32px; }
.db-wake-body { margin-top: 4px; }
.db-wake-bar { height: 7px; background: var(--surface); border-radius: 999px;
  overflow: hidden; border: 1px solid var(--border); }
.db-wake-fill { height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--secondary)); border-radius: 999px; }
.db-wake-fill.animate { width: 100%; transition: width 10s linear; }
.db-wake-elapsed { margin-top: 10px; font-family: var(--font-mono); font-size: 11px; color: var(--muted); }

/* ─── REVIEW QUEUE ────────────────────────────────────────────── */
.review-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 16px; }
.review-card { background: white; border: 1px solid var(--border); border-radius: 16px;
  overflow: hidden; box-shadow: var(--card-shadow); display: flex; flex-direction: column; }
.review-card .photo { width: 100%; aspect-ratio: 16/10; background: var(--surface);
  background-size: cover; background-position: center; border-bottom: 1px solid var(--border); }
.review-card .photo.empty { display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 12px; font-style: italic; }
.review-card .body { padding: 16px 18px 8px; flex: 1; }
.review-card h3 { font-family: var(--font-display); font-size: 20px; font-weight: 400;
  letter-spacing: -.015em; margin-bottom: 4px; }
.review-card .owner { font-size: 12px; color: var(--muted); margin-bottom: 10px;
  display: flex; align-items: center; gap: 6px; }
.review-card .owner .label { letter-spacing: .14em; text-transform: uppercase; font-size: 10px; }
.review-card .desc { font-size: 13px; color: var(--text); line-height: 1.45;
  margin-bottom: 12px; display: -webkit-box; -webkit-line-clamp: 4;
  -webkit-box-orient: vertical; overflow: hidden; }
.review-card .meta { display: flex; flex-wrap: wrap; gap: 6px; font-size: 11px; color: var(--muted); }
.review-card .meta-chip { padding: 2px 8px; background: var(--surface);
  border-radius: 999px; font-family: var(--font-mono); }
.review-card .actions { display: flex; gap: 8px; padding: 12px 18px 16px;
  border-top: 1px solid var(--border); background: var(--surface); }
.review-card .actions .btn { flex: 1; }
.review-card.busy { opacity: 0.5; pointer-events: none; }

/* ─── FOOTER ──────────────────────────────────────────────────── */
.footer { max-width: 1600px; margin: 0 auto; padding: 20px 24px 40px;
  border-top: 1px solid var(--border); display: flex; justify-content: space-between;
  align-items: center; font-size: 12px; color: var(--muted); flex-wrap: wrap; gap: 8px; }

/* ─── VIEW SWITCHING ──────────────────────────────────────────── */
.view { display: none; }
.view.active { display: block; }

/* ─── RESPONSIVE ──────────────────────────────────────────────── */
@media (max-width: 980px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  .topbar { padding: 0 12px; }
  main { padding: 20px 12px 60px; }
  .hero h1 { font-size: 26px; }
  .auth-status { display: none; }
}