:root {
  --green-950: #0a2f22;
  --green-900: #103f2c;
  --green-800: #145536;
  --green-700: #1f6d43;
  --green-600: #2d8654;
  --green-500: #43a56a;
  --green-100: #e9f6ee;
  --gold-500: #d5a62e;
  --gold-100: #fbf3d8;
  --ink: #1c2b24;
  --muted: #6d7a73;
  --surface: #ffffff;
  --page: #f4f7f5;
  --border: #dfe7e2;
  --shadow: 0 12px 32px rgba(16, 63, 44, .08);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--page);
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; }
.min-width-0 { min-width: 0; }

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 1040;
  height: 82px;
  color: #fff;
  background:
    radial-gradient(circle at 80% 0%, rgba(213,166,46,.24), transparent 28%),
    linear-gradient(115deg, var(--green-950), var(--green-700));
  display: flex;
  align-items: center;
  box-shadow: 0 8px 24px rgba(10, 47, 34, .18);
}
.brand-logos {
  width: 144px;
  height: 58px;
  object-fit: contain;
  background: #fff;
  border-radius: 9px;
  padding: 4px;
}
.brand-kicker { font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: #e8d69b; font-weight: 700; }
.brand-title { font-size: 1rem; font-weight: 800; max-width: 650px; }
.btn-icon { color: white; border: 1px solid rgba(255,255,255,.3); }
.connection-badge {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  padding: .52rem .8rem;
  border-radius: 999px;
  background: rgba(255,255,255,.12);
  border: 1px solid rgba(255,255,255,.16);
  font-size: .78rem;
  font-weight: 700;
  white-space: nowrap;
}
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #f0c35a; box-shadow: 0 0 0 4px rgba(240,195,90,.14); }
.connection-badge.connected .status-dot { background: #70e19b; box-shadow: 0 0 0 4px rgba(112,225,155,.14); }
.connection-badge.error .status-dot { background: #ff8c8c; box-shadow: 0 0 0 4px rgba(255,140,140,.14); }

.app-shell { display: flex; padding-top: 82px; min-height: 100vh; }
.sidebar {
  position: fixed;
  top: 82px;
  bottom: 0;
  left: 0;
  width: 250px;
  background: #fff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 1030;
  transition: transform .25s ease;
}
.sidebar-nav { padding: 1rem; display: grid; gap: .4rem; }
.nav-item {
  width: 100%;
  border: 0;
  background: transparent;
  color: #506158;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: .85rem;
  padding: .86rem .95rem;
  text-align: left;
  font-weight: 700;
  transition: .2s ease;
}
.nav-item i { width: 20px; color: var(--green-600); }
.nav-item:hover { background: var(--green-100); color: var(--green-900); transform: translateX(2px); }
.nav-item.active { background: linear-gradient(135deg, var(--green-800), var(--green-600)); color: #fff; box-shadow: 0 10px 20px rgba(31,109,67,.2); }
.nav-item.active i { color: #fff; }
.sidebar-footer { margin-top: auto; padding: 1.25rem; color: #dce9e1; background: var(--green-950); line-height: 1.5; }
.main-content { margin-left: 250px; width: calc(100% - 250px); padding: 28px; }
.app-section { display: none; animation: fadeIn .25s ease; }
.app-section.active { display: block; }
@keyframes fadeIn { from { opacity: .25; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.hero-panel {
  background:
    radial-gradient(circle at 95% 15%, rgba(255,255,255,.14), transparent 24%),
    radial-gradient(circle at 75% 100%, rgba(213,166,46,.24), transparent 30%),
    linear-gradient(125deg, var(--green-950), var(--green-700));
  color: #fff;
  border-radius: 24px;
  padding: clamp(1.4rem, 4vw, 2.6rem);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2rem;
  box-shadow: var(--shadow);
  overflow: hidden;
  position: relative;
}
.hero-panel h1 { font-family: "Playfair Display", Georgia, serif; font-size: clamp(2rem, 4vw, 3.2rem); margin: .3rem 0 .55rem; }
.hero-panel p { margin: 0; max-width: 760px; color: rgba(255,255,255,.82); font-size: 1rem; line-height: 1.7; }
.hero-actions { display: flex; flex-direction: column; gap: .7rem; min-width: 205px; }
.eyebrow { font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--green-600); font-weight: 800; }
.hero-panel .eyebrow { color: #e8d69b; }

.kpi-card {
  height: 100%;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: 0 8px 24px rgba(16,63,44,.05);
}
.kpi-icon {
  width: 52px; height: 52px; flex: 0 0 52px;
  border-radius: 15px;
  display: grid; place-items: center;
  color: var(--green-800);
  background: var(--green-100);
  font-size: 1.2rem;
}
.kpi-card span { display: block; color: var(--muted); font-size: .78rem; font-weight: 700; }
.kpi-card strong { display: block; font-size: clamp(1.25rem,2vw,1.65rem); line-height: 1.25; }
.kpi-card small { color: var(--green-700); font-weight: 700; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  box-shadow: 0 8px 24px rgba(16,63,44,.05);
}
.panel-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: .8rem; }
.panel-header h3 { font-size: 1rem; margin: 0 0 .22rem; font-weight: 800; }
.panel-header p { margin: 0; color: var(--muted); font-size: .8rem; }
.chart-wrap { height: 300px; position: relative; }
.chart-wrap.chart-lg { height: 330px; }

.section-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.3rem; }
.section-heading h2 { margin: .25rem 0; font-size: clamp(1.65rem,3vw,2.25rem); font-weight: 800; }
.section-heading p { margin: 0; color: var(--muted); }

.baseline-accordion { display: grid; gap: .85rem; }
.baseline-accordion .accordion-item { border: 1px solid var(--border); border-radius: 16px !important; overflow: hidden; box-shadow: 0 8px 20px rgba(16,63,44,.035); }
.baseline-accordion .accordion-button { font-weight: 800; color: var(--ink); padding: 1rem 1.2rem; box-shadow: none; }
.baseline-accordion .accordion-button:not(.collapsed) { background: var(--green-100); color: var(--green-900); }
.baseline-accordion .accordion-body { padding: 1.35rem; }
.step-no { width: 30px; height: 30px; border-radius: 50%; display: inline-grid; place-items: center; margin-right: .75rem; background: var(--green-700); color: white; font-size: .8rem; }
.form-label { font-size: .8rem; font-weight: 700; color: #3e5047; }
.form-control, .form-select { border-color: #ccd9d1; border-radius: 10px; min-height: 44px; }
.form-control:focus, .form-select:focus { border-color: var(--green-500); box-shadow: 0 0 0 .22rem rgba(67,165,106,.15); }
.form-subtitle { font-size: .9rem; font-weight: 800; color: var(--green-800); padding-bottom: .5rem; border-bottom: 1px dashed var(--border); }
.interest-card { height: 100%; border: 1px solid #cfe2d6; background: #f5fbf7; border-radius: 14px; padding: 1rem; }
.interest-card small { display: block; color: var(--muted); line-height: 1.5; margin-top: .5rem; }
.form-actions { display: flex; justify-content: flex-end; gap: .75rem; padding: 1.25rem 0 2rem; position: sticky; bottom: 0; background: linear-gradient(180deg, rgba(244,247,245,0), var(--page) 22%); z-index: 10; }

.table-toolbar { display: grid; grid-template-columns: minmax(220px,1.8fr) minmax(160px,.8fr) minmax(170px,.8fr) 90px; gap: .75rem; margin-bottom: 1rem; }
.search-box { position: relative; }
.search-box i { position: absolute; left: .9rem; top: 50%; transform: translateY(-50%); color: #809087; }
.search-box input { width: 100%; height: 44px; border: 1px solid #ccd9d1; border-radius: 10px; padding: 0 .9rem 0 2.55rem; outline: none; }
.search-box input:focus { border-color: var(--green-500); box-shadow: 0 0 0 .22rem rgba(67,165,106,.15); }
.data-table thead th { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: #69776f; white-space: nowrap; border-bottom-width: 1px; background: #f7faf8; }
.data-table td { font-size: .84rem; vertical-align: middle; }
.org-name { font-weight: 800; color: var(--green-900); }
.org-meta { color: var(--muted); font-size: .72rem; margin-top: .2rem; }
.badge-soft { display: inline-flex; align-items: center; border-radius: 999px; padding: .35rem .55rem; font-size: .68rem; font-weight: 800; background: var(--green-100); color: var(--green-800); margin: .12rem; }
.badge-soft.gold { background: var(--gold-100); color: #856713; }
.badge-soft.gray { background: #eef1ef; color: #67736d; }
.action-buttons { display: flex; gap: .3rem; }
.action-buttons .btn { width: 34px; height: 34px; padding: 0; display: grid; place-items: center; border-radius: 9px; }
.table-footer { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding-top: 1rem; color: var(--muted); font-size: .8rem; }
.page-link { color: var(--green-700); }
.active>.page-link { background: var(--green-700); border-color: var(--green-700); }
.empty-state { text-align: center; padding: 3rem !important; color: var(--muted); }
.empty-state i { display: block; font-size: 2rem; color: #aebbb4; margin-bottom: .65rem; }

.organization-map { height: calc(100vh - 190px); min-height: 560px; }
.map-count { text-align: right; display: flex; flex-direction: column; }
.map-count strong { font-size: 1.5rem; color: var(--green-800); }
.map-count span { color: var(--muted); font-size: .75rem; }
.leaflet-popup-content-wrapper { border-radius: 13px; }
.map-popup h4 { font-size: .9rem; color: var(--green-900); margin: 0 0 .35rem; font-weight: 800; }
.map-popup p { margin: .18rem 0; font-size: .76rem; }

.tool-card { height: 100%; display: flex; gap: 1rem; padding: 1.3rem; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; box-shadow: 0 8px 24px rgba(16,63,44,.05); }
.tool-icon { width: 52px; height: 52px; flex: 0 0 52px; display: grid; place-items: center; border-radius: 14px; background: var(--green-100); color: var(--green-800); font-size: 1.2rem; }
.tool-card h3 { font-size: 1rem; font-weight: 800; }
.tool-card p { color: var(--muted); font-size: .84rem; line-height: 1.55; }
.connection-details { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 1rem; }
.connection-detail { background: #f7faf8; border-radius: 12px; padding: 1rem; }
.connection-detail span { display: block; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 800; }
.connection-detail strong { display: block; margin-top: .3rem; overflow-wrap: anywhere; }

.detail-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: .8rem; }
.detail-section { border: 1px solid var(--border); border-radius: 14px; padding: 1rem; background: #fbfdfc; }
.detail-section h4 { font-size: .85rem; font-weight: 800; color: var(--green-800); border-bottom: 1px dashed var(--border); padding-bottom: .55rem; margin-bottom: .75rem; }
.detail-item { display: flex; justify-content: space-between; gap: 1rem; font-size: .77rem; padding: .28rem 0; }
.detail-item span { color: var(--muted); }
.detail-item strong { text-align: right; overflow-wrap: anywhere; }

.toast { border: 0; box-shadow: 0 12px 30px rgba(0,0,0,.15); }
.toast-header.success { background: var(--green-700); color: white; }
.toast-header.error { background: #a93636; color: white; }
.toast-header.warning { background: #9b7318; color: white; }

@media (max-width: 1199.98px) {
  .brand-title { max-width: 430px; }
  .table-toolbar { grid-template-columns: 1fr 1fr; }
  .detail-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); box-shadow: 14px 0 28px rgba(0,0,0,.12); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; width: 100%; padding: 20px; }
  .hero-panel { align-items: flex-start; }
  .brand-logos { width: 112px; height: 50px; }
}
@media (max-width: 767.98px) {
  .topbar { height: 72px; }
  .app-shell { padding-top: 72px; }
  .sidebar { top: 72px; width: 280px; }
  .brand-kicker { display: none; }
  .brand-title { max-width: 190px; font-size: .8rem; }
  .brand-logos { width: 88px; height: 42px; }
  .connection-badge { padding: .45rem; }
  .connection-badge span:last-child { display: none; }
  .main-content { padding: 14px; }
  .hero-panel { flex-direction: column; }
  .hero-actions { width: 100%; min-width: 0; }
  .section-heading { flex-direction: column; }
  .table-toolbar { grid-template-columns: 1fr; }
  .table-footer { flex-direction: column; align-items: flex-start; }
  .organization-map { min-height: 500px; height: calc(100vh - 170px); }
  .connection-details, .detail-grid { grid-template-columns: 1fr; }
  .tool-card { flex-direction: column; }
  .form-actions { justify-content: stretch; }
  .form-actions .btn { flex: 1; }
}

/* --------------------------------------------------------------------------
   Google Earth farm mapping and record modal
   -------------------------------------------------------------------------- */
.topbar { height: 70px; }
.app-shell { padding-top: 70px; }
.sidebar { top: 70px; width: 222px; }
.main-content { margin-left: 222px; width: calc(100% - 222px); padding: 26px 28px; }
.brand-logos { width: 136px; height: 52px; }
.sidebar-nav { padding: 1rem .55rem; gap: .32rem; }
.nav-item { border-radius: 11px; padding: .82rem .85rem; font-size: .86rem; }

.mapping-form-grid { display: grid; grid-template-columns: 260px minmax(0,1fr); gap: 1rem; align-items: stretch; }
.variety-panel, .farm-map-panel { border: 1px solid var(--border); border-radius: 15px; background: #fbfdfc; padding: 1rem; }
.helper-copy { color: var(--muted); font-size: .75rem; margin: .35rem 0 .75rem; }
.variety-list { display: grid; gap: .48rem; }
.variety-list.compact { gap: .36rem; }
.variety-check { display: flex; align-items: center; gap: .58rem; min-height: 31px; margin: 0; font-size: .78rem; color: #33463d; cursor: pointer; }
.variety-check .form-check-input, .variety-check input[type="checkbox"] { margin: 0; width: 17px; height: 17px; accent-color: var(--green-700); }
.variety-check.readonly { cursor: default; opacity: .88; }
.variety-check.readonly.selected { color: var(--green-900); font-weight: 700; }
.other-variety-readout { margin-top: .8rem; padding: .55rem .65rem; border: 1px solid var(--border); border-radius: 9px; font-size: .74rem; color: var(--muted); background: #fff; }
.mapping-note { display: flex; gap: .6rem; align-items: flex-start; padding: .75rem; border-radius: 10px; background: var(--green-100); color: var(--green-800); font-size: .73rem; line-height: 1.45; }

.map-panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: .75rem; }
.map-panel-heading h4 { margin: 0 0 .22rem; font-size: .92rem; color: var(--green-800); font-weight: 800; }
.map-panel-heading p { margin: 0; color: var(--muted); font-size: .73rem; line-height: 1.45; }
.earth-badge { display: inline-flex; align-items: center; gap: .42rem; padding: .42rem .62rem; border-radius: 999px; background: #123f2e; color: #fff; white-space: nowrap; font-size: .68rem; font-weight: 700; }
.farm-map-layout { display: grid; grid-template-columns: minmax(0,1fr) 200px; gap: .7rem; }
.farm-map-canvas { position: relative; min-height: 390px; border-radius: 11px; overflow: hidden; border: 1px solid #cbd8d0; background: #e5ece8; }
.gps-control-panel { border: 1px solid var(--border); background: #fff; border-radius: 11px; padding: .75rem; display: flex; flex-direction: column; gap: .38rem; }
.gps-control-panel h5 { font-size: .75rem; color: var(--green-800); font-weight: 800; margin: 0; }
.gps-control-panel small { color: var(--muted); font-size: .65rem; margin-bottom: .25rem; }
.gps-control-panel label { color: #68766f; font-size: .63rem; margin-top: .2rem; }
.gps-control-panel .form-control { min-height: 34px; font-size: .71rem; padding: .35rem .5rem; }
.map-status { display: flex; align-items: flex-start; gap: .4rem; border-radius: 8px; padding: .55rem; margin-top: .35rem; font-size: .66rem; line-height: 1.35; }
.map-status.neutral { background: #eef3f0; color: #5f7067; }
.map-status.success { background: #e6f6ec; color: #1c7044; }
.map-status.drawing { background: #fff6d8; color: #7f6113; }
.map-status.error { background: #fce9e9; color: #a33838; }
.map-summary-card { border: 1px solid var(--border); border-radius: 9px; padding: .62rem; margin-top: .25rem; background: #f9fbfa; }
.map-summary-card h6 { margin: 0 0 .45rem; color: var(--green-800); font-size: .66rem; font-weight: 800; }
.map-summary-card div { display: flex; justify-content: space-between; gap: .6rem; padding: .22rem 0; font-size: .61rem; }
.map-summary-card span { color: var(--muted); }
.map-summary-card strong { text-align: right; }
.map-action-row { display: flex; align-items: center; flex-wrap: wrap; gap: .5rem; margin-top: .65rem; }
.map-action-row .btn { font-size: .72rem; padding: .48rem .72rem; }
.map-loading, .map-error { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: .6rem; color: #5d6e65; background: linear-gradient(135deg,#edf2ef,#dfe9e3); font-size: .8rem; z-index: 1; }
.map-error { padding: 2rem; color: #8f3434; }
.map-error i { font-size: 1.5rem; }
.map-error h3 { margin: 0; font-size: 1rem; }
.map-error p { margin: 0; max-width: 480px; }
.map-error.compact { position: absolute; }
.polygon-map-label { position: absolute; transform: translate(-50%,-50%); display: flex; flex-direction: column; align-items: center; color: white; text-shadow: 0 1px 4px rgba(0,0,0,.9); font-size: .72rem; white-space: nowrap; pointer-events: none; z-index: 20; }
.polygon-map-label strong { font-size: .82rem; }
.polygon-map-label span { font-size: .64rem; }

.map-panel-shell { border-radius: 16px; }
.organization-map { position: relative; height: calc(100vh - 180px); min-height: 590px; }
.overview-info { max-width: 260px; }
.overview-info h4 { margin: 0 0 .45rem; font-size: .86rem; color: var(--green-900); font-weight: 800; }
.overview-info p { margin: .2rem 0; font-size: .72rem; }

.record-modal-dialog { max-width: 1080px; }
.record-modal-dialog .modal-content { border: 0; border-radius: 13px; overflow: hidden; box-shadow: 0 24px 65px rgba(0,0,0,.28); }
.record-modal-dialog .modal-header { padding: .9rem 1rem .75rem; border-bottom: 1px solid var(--border); }
.record-modal-dialog .modal-title { font-size: 1.18rem; margin-top: .1rem; }
.record-modal-dialog .modal-body { padding: .85rem; background: #fff; }
.record-modal-dialog .modal-footer { padding: .7rem .9rem; background: #fff; }
.record-detail-layout { display: grid; gap: .75rem; }
.detail-top-grid { display: grid; grid-template-columns: 1.08fr 1fr 1fr; gap: .75rem; }
.detail-middle-grid { display: grid; grid-template-columns: 250px minmax(0,1fr); gap: .75rem; }
.detail-bottom-grid, .detail-support-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: .75rem; }
.detail-section { padding: .85rem; border-radius: 12px; }
.detail-section h4 { font-size: .76rem; margin-bottom: .55rem; padding-bottom: .45rem; }
.detail-item { font-size: .69rem; padding: .23rem 0; line-height: 1.25; }
.detail-item strong { max-width: 60%; }
.variety-detail-section { min-height: 330px; }
.modal-map-section { min-width: 0; }
.modal-map-layout { grid-template-columns: minmax(0,1fr) 180px; }
.modal-map-canvas { min-height: 310px; }

.empty-module { min-height: 360px; display: grid; place-content: center; justify-items: center; text-align: center; color: var(--muted); }
.empty-module > i { font-size: 3rem; color: var(--green-600); margin-bottom: 1rem; }
.empty-module h3 { color: var(--green-900); font-size: 1.15rem; }
.empty-module p { max-width: 560px; }

@media (max-width: 1199.98px) {
  .mapping-form-grid { grid-template-columns: 220px minmax(0,1fr); }
  .farm-map-layout { grid-template-columns: minmax(0,1fr) 180px; }
  .record-modal-dialog { max-width: calc(100vw - 32px); }
}
@media (max-width: 991.98px) {
  .topbar { height: 72px; }
  .app-shell { padding-top: 72px; }
  .sidebar { top: 72px; width: 280px; }
  .main-content { margin-left: 0; width: 100%; }
  .mapping-form-grid, .detail-middle-grid { grid-template-columns: 1fr; }
  .detail-top-grid, .detail-bottom-grid, .detail-support-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .variety-detail-section { min-height: 0; }
}
@media (max-width: 767.98px) {
  .farm-map-layout, .modal-map-layout { grid-template-columns: 1fr; }
  .farm-map-canvas, .modal-map-canvas { min-height: 350px; }
  .detail-top-grid, .detail-bottom-grid, .detail-support-grid { grid-template-columns: 1fr; }
  .record-modal-dialog { margin: .5rem; max-width: calc(100vw - 1rem); }
  .modal-map-section { padding: .65rem; }
  .map-action-row .btn { flex: 1 1 auto; }
}

@media print {
  .topbar, .sidebar, .table-toolbar, .section-heading .btn, .action-buttons, .table-footer { display: none !important; }
  .app-shell { padding: 0; }
  .main-content { margin: 0; width: 100%; padding: 0; }
  .app-section { display: none !important; }
  #section-records { display: block !important; }
  #section-records .section-heading { display: block !important; }
  .panel { box-shadow: none; border: 0; padding: 0; }
  .data-table { font-size: 9pt; }
}
.farm-map-canvas {
  background-image: linear-gradient(rgba(13,45,31,.08),rgba(13,45,31,.08)), url('assets/map-fallback.jpg');
  background-size: cover;
  background-position: center;
}
