:root {
  --forest: #263f2b;
  --forest-2: #314b36;
  --moss: #6b8e23;
  --earth: #8b6f4e;
  --paper: #fbfaf4;
  --line: #d7d2c7;
  --danger: #b42318;
  --warning: #b7791f;
  --muted: #666b63;
  --white: #fff;
  --panel: rgba(255, 255, 255, 0.96);
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.16);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  font-family: Calibri, Arial, sans-serif;
  background: linear-gradient(135deg, #eef1e7, #d9dfcf);
  color: #222;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app {
  height: 100vh;
  padding: 12px;
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
}

.app-menu {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr) max-content;
  grid-template-rows: auto auto;
  align-items: center;
  column-gap: 18px;
  row-gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid rgba(0, 0, 0, 0.08);
  box-shadow: var(--shadow);
}

.app-brand {
  grid-column: 1;
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 292px;
}

.app-logo {
  display: block;
  width: auto;
  height: auto;
  max-width: 170px;
  max-height: 95px;
  object-fit: contain;
}

.app-brand h1 {
  margin: 0;
  color: var(--forest);
  font-size: 25px;
  line-height: 1.05;
}

.app-brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.app-menu-actions {
  grid-column: 3;
  grid-row: 1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: nowrap;
  gap: 8px;
}

.panel,
.workspace-panel {
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.left-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  color: var(--white);
  background: linear-gradient(160deg, var(--forest), var(--forest-2) 58%, #6d5b44);
}

.workspace-panel {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: var(--white);
}

.workspace-panel.map-editor-layout {
  grid-template-columns: minmax(0, 1fr) minmax(320px, 360px);
  grid-template-rows: auto minmax(0, 1fr);
}

.workspace-panel.map-editor-layout .map-statusbar {
  grid-column: 1 / -1;
}

.workspace-panel.map-editor-layout .map-workspace {
  grid-column: 1;
  grid-row: 2;
  min-width: 0;
}

.workspace-panel.map-editor-layout .right-body {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  border-left: 1px solid var(--line);
  background: #fbfaf5;
}

.brand {
  padding: 16px 18px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.16);
}

.brand h1 {
  margin: 0;
  font-size: 21px;
}

.brand p {
  margin: 7px 0 0;
  color: rgba(255, 255, 255, 0.75);
  font-size: 13px;
  line-height: 1.35;
}

.main-screen-tabs,
.sub-screen-tabs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  min-width: 0;
}

.main-screen-tabs {
  grid-column: 2;
  grid-row: 1;
}

.sub-screen-tabs {
  grid-column: 1 / -1;
  grid-row: 2;
}

.screen-tab,
.sub-tab {
  border: 1px solid rgba(38, 63, 43, 0.18);
  border-radius: 8px;
  padding: 8px 11px;
  cursor: pointer;
  color: var(--forest);
  background: #fff;
  font-weight: 700;
  white-space: nowrap;
}

.sub-tab {
  padding: 6px 10px;
  color: #344338;
  font-size: 13px;
  font-weight: 600;
  background: #f5f3eb;
}

.screen-tab.active,
.sub-tab.active {
  color: #fff;
  background: var(--forest);
}

.left-tools {
  min-height: 0;
}

.section {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.section h2 {
  margin: 0 0 9px;
  font-size: 15px;
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn {
  border: 0;
  border-radius: 8px;
  padding: 9px 10px;
  cursor: pointer;
  color: var(--white);
  background: rgba(255, 255, 255, 0.14);
  transition: background 0.12s ease, transform 0.12s ease;
}

.btn:hover {
  background: rgba(255, 255, 255, 0.24);
}

.btn:active {
  transform: translateY(1px);
}

.btn.active,
.btn.run {
  background: var(--moss);
  font-weight: 700;
}

.btn.danger,
.btn.menu-btn.danger {
  background: var(--danger);
}

.btn.secondary {
  background: rgba(0, 0, 0, 0.22);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.btn.full {
  grid-column: 1 / -1;
}

.btn.menu-btn {
  padding: 8px 10px;
  color: var(--white);
  background: var(--forest);
  white-space: nowrap;
}

.btn.compact {
  padding: 8px 9px;
  white-space: nowrap;
}

.menu-dropdown {
  position: relative;
  display: inline-flex;
  align-items: stretch;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 1000;
  min-width: 220px;
  display: none;
  padding: 6px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(0, 0, 0, 0.12);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
}

.menu-dropdown:hover .dropdown-menu,
.menu-dropdown:focus-within .dropdown-menu {
  display: grid;
  gap: 4px;
}

.dropdown-menu button {
  width: 100%;
  border: 0;
  border-radius: 7px;
  padding: 9px 10px;
  background: transparent;
  color: var(--forest);
  font: inherit;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.dropdown-menu button:hover,
.dropdown-menu button:focus {
  outline: none;
  background: rgba(38, 63, 43, 0.1);
}

.field {
  display: grid;
  gap: 5px;
  margin-bottom: 8px;
}

.field label {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.8);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.12);
  color: var(--white);
  border-radius: 8px;
  padding: 8px;
  outline: none;
}

.field option {
  color: #222;
}

.field input[readonly] {
  opacity: 0.74;
}

.formula-input {
  min-height: 72px;
  resize: vertical;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.4;
}

.formula-status {
  min-height: 18px;
  color: rgba(255, 255, 255, 0.82);
  font-size: 12px;
  line-height: 1.35;
}

.formula-status.bad {
  color: #ffd7d7;
}

.volume-formula-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.formula-box {
  min-width: 0;
}

.readonly-col input {
  background: #ecefe8;
  color: #3f4a40;
}

.species-input-wrap {
  position: relative;
  min-width: 0;
  border-radius: 6px;
  background: #fff;
}

.species-input-wrap input {
  position: relative;
  z-index: 1;
  background: transparent;
}

.species-suggestion-ghost {
  position: absolute;
  inset: 0;
  overflow: hidden;
  padding: 5px;
  color: #9ca3af;
  line-height: 1.35;
  white-space: nowrap;
  pointer-events: none;
}

.sinaflor-name-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 18px;
  align-items: center;
  gap: 4px;
}

.sinaflor-toggle {
  width: 14px;
  height: 14px;
  padding: 0;
  border: 1px solid #aeb6aa;
  border-radius: 999px;
  background: #a5acaa;
  cursor: pointer;
}

.sinaflor-toggle.active {
  border-color: #2f7d4f;
  background: #2f7d4f;
}

.species-match-exact .species-input-wrap {
  background: #e4f5df;
}

.species-match-exact input {
  border-color: #67a55b;
}

.species-match-near .species-input-wrap {
  background: #fff4bd;
}

.species-match-near input {
  border-color: #d5a11e;
}

.species-match-bad .species-input-wrap,
.species-unmatched .species-input-wrap {
  background: #ffe2e2;
}

.species-match-bad input,
.species-unmatched input {
  border-color: #b91c1c;
}

.warning-card {
  border-color: rgba(183, 121, 31, 0.35);
  background: #fff8e8;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  color: rgba(255, 255, 255, 0.88);
  font-size: 13px;
}

.checkline input {
  width: auto;
  margin: 0;
  accent-color: var(--moss);
}

.scale-control-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
}

.scale-control-row span {
  color: rgba(255, 255, 255, 0.88);
  font-weight: 700;
}

.layer-checklist {
  display: grid;
  gap: 7px;
}

.layer-checklist label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.92);
  font-size: 13px;
  cursor: pointer;
}

.layer-checklist input[type="checkbox"] {
  width: auto;
  margin: 0;
  accent-color: var(--moss);
}

.layer-row {
  display: grid;
  grid-template-columns: 1fr 34px;
  gap: 6px;
  align-items: stretch;
}

.layer-more {
  border: 0;
  border-radius: 8px;
  color: rgba(255, 255, 255, 0.94);
  background: rgba(255, 255, 255, 0.16);
  cursor: pointer;
  font-weight: 800;
  line-height: 1;
}

.map-statusbar {
  height: 58px;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid var(--line);
}

.status {
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status strong {
  color: var(--forest);
}

#mapCanvas {
  display: block;
  width: 100%;
  height: 100%;
  background: var(--paper);
  cursor: crosshair;
}

.map-workspace,
.workspace-body {
  min-height: 0;
}

.map-workspace {
  height: 100%;
}

.workspace-body {
  overflow: auto;
}

.map-editor-card {
  border-radius: 0;
  border-left: 0;
  border-right: 0;
  box-shadow: none;
}

.selected-feature-summary {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
}

.selected-feature-summary strong {
  min-width: 0;
  overflow: hidden;
  color: var(--forest);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selected-feature-summary span {
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--paper);
  color: var(--forest);
  font-size: 12px;
  font-weight: 700;
}

.right-header {
  padding: 14px 16px;
  background: linear-gradient(140deg, #fff, #f1efe7);
  border-bottom: 1px solid var(--line);
}

.right-header h2 {
  margin: 0;
  color: var(--forest);
  font-size: 18px;
}

.right-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px;
  background: #f8f6ef;
  border-bottom: 1px solid var(--line);
}

.tab {
  border: 1px solid var(--line);
  background: var(--white);
  border-radius: 8px;
  padding: 7px 10px;
  cursor: pointer;
  font-size: 13px;
  color: #222;
}

.tab.active {
  color: var(--white);
  background: var(--forest);
}

.right-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 12px;
}

.card {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
  padding: 10px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.card h3 {
  margin: 0;
  color: var(--forest);
  font-size: 15px;
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.card label {
  display: grid;
  gap: 3px;
  color: var(--muted);
  font-size: 12px;
}

.card input,
.card select,
.card textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid #d8d6ca;
  border-radius: 7px;
  padding: 7px;
  color: #222;
  background: var(--white);
}

.card textarea {
  min-height: 72px;
  resize: vertical;
}

.card .formula-status {
  color: #4f5a51;
}

.card .formula-status.bad {
  color: var(--danger);
}

.card-actions,
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.toolbar {
  margin-bottom: 10px;
}

.toolbar input,
.toolbar select {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px;
}

.table-pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 8px 0 10px;
  color: #596659;
  font-size: 12px;
}

.table-pager span {
  margin-right: 4px;
  font-weight: 600;
}

.table-wrap {
  overflow: auto;
  border: 1px solid #eee;
  border-radius: 8px;
  background: var(--white);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  background: var(--white);
}

th,
td {
  border-bottom: 1px solid #eee;
  padding: 7px 6px;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--forest);
  background: #f0f2eb;
}

td input,
td select {
  width: 100%;
  min-width: 70px;
  border: 1px solid #d8d6ca;
  border-radius: 6px;
  padding: 5px;
  background: #fff;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 3px 7px;
  color: var(--white);
  background: var(--forest);
  font-size: 11px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
}

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

.metric {
  min-height: 72px;
  border: 1px solid #dce3dc;
  border-radius: 8px;
  padding: 9px;
  background: #fbfcfe;
}

.metric span,
.metric strong {
  display: block;
}

.metric span {
  color: #667266;
  font-size: 11px;
}

.metric strong {
  margin-top: 3px;
  color: #1f2937;
  font-size: 15px;
  line-height: 1.25;
}

.progress-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
}

.progress-track {
  height: 12px;
  overflow: hidden;
  border: 1px solid #d6ddcf;
  border-radius: 999px;
  background: #eef2e8;
}

.progress-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--forest);
  transition: width 120ms ease;
}

.project-loading-card {
  max-width: 560px;
  margin: 18px auto;
}

.project-loading-status {
  margin-top: 8px;
  font-size: 11px;
}

.empty-state {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.result-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.sortable-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.sort-mini-buttons {
  display: inline-flex;
  flex: 0 0 auto;
  gap: 2px;
}

.sort-mini {
  min-width: 16px;
  width: 16px;
  height: 18px;
  padding: 0;
  border: 1px solid rgba(31, 59, 40, 0.22);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.7);
  color: #38533f;
  font-size: 9px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.sort-mini.active {
  border-color: #1f5c38;
  background: #2f7d4f;
  color: #fff;
}

.spreadsheet-wrap {
  max-height: 58vh;
}

.spreadsheet {
  width: max-content;
  min-width: 100%;
  table-layout: fixed;
}

.spreadsheet th,
.spreadsheet td {
  min-width: 96px;
  padding: 4px;
}

.spreadsheet th {
  position: sticky;
  overflow: visible;
  user-select: none;
}

.spreadsheet td {
  overflow: hidden;
}

.col-resizer {
  position: absolute;
  top: 0;
  right: -4px;
  z-index: 4;
  width: 8px;
  height: 100%;
  cursor: col-resize;
}

.col-resizer:hover,
.resizing-column .col-resizer {
  background: rgba(46, 84, 47, 0.18);
}

.resizing-column {
  cursor: col-resize;
  user-select: none;
}

.spreadsheet .row-head {
  min-width: 42px;
  width: 42px;
  color: #536153;
  text-align: center;
  background: #eef2e8;
}

.sheet-col {
  display: block;
  color: #7a8677;
  font-size: 10px;
  font-weight: 600;
}

.blank-row td {
  height: 12px;
  background: #fafafa;
}

.btn.mini {
  padding: 4px 7px;
  font-size: 11px;
}

.checkline.in-card {
  align-content: center;
  padding-top: 18px;
}

.sampling-results-layout {
  display: grid;
  grid-template-columns: minmax(260px, 2fr) minmax(360px, 3fr);
  gap: 12px;
  align-items: start;
}

.sampling-results-layout > .card {
  min-width: 0;
}

.sampling-results-layout .table-wrap {
  max-height: 58vh;
}

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

.distribution-table-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.distribution-table-grid > .card {
  min-width: 0;
}

.floristics-table-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.8fr) minmax(420px, 1.2fr);
  gap: 12px;
  align-items: start;
}

.floristics-table-grid > .card {
  min-width: 0;
  align-content: start;
}

.chart-card {
  align-content: start;
}

.chart-card .result-chart {
  width: min(100%, 600px);
}

.result-chart {
  display: block;
  width: 100%;
  aspect-ratio: 12 / 7;
  border: 1px solid #d6ddcf;
  border-radius: 8px;
  background: #ffffff;
}

.small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.38;
}

.pdf-preview-modal {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.58);
}

.pdf-preview-modal.open {
  display: flex;
}

.pdf-preview-window {
  width: 95vw;
  height: 95vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  border-radius: 8px;
  background: #e7e7e7;
  box-shadow: 0 18px 55px rgba(0, 0, 0, 0.45);
}

.pdf-preview-toolbar {
  min-height: 54px;
  padding: 9px 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  background: #ffffff;
  border-bottom: 1px solid #cfcfcf;
}

.pdf-preview-toolbar strong {
  color: var(--forest);
  font-size: 16px;
}

.pdf-preview-hint {
  margin-right: auto;
  color: #666;
  font-size: 12px;
}

@media (max-width: 1050px) {
  .sampling-results-layout,
  .chart-grid,
  .distribution-table-grid,
  .floristics-table-grid {
    grid-template-columns: 1fr;
  }
}

.pdf-preview-body {
  min-width: 0;
  min-height: 0;
  background: #555;
}

.pdf-preview-frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #555;
}

.left-panel::-webkit-scrollbar,
.right-body::-webkit-scrollbar {
  width: 10px;
}

.left-panel::-webkit-scrollbar-thumb,
.right-body::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.25);
  border-radius: 999px;
}

.left-panel::-webkit-scrollbar-track,
.right-body::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.12);
}

@media (max-width: 1220px) {
  .app {
    grid-template-columns: 300px minmax(0, 1fr);
  }

  .app-menu {
    grid-template-columns: 1fr;
  }

  .app-brand,
  .main-screen-tabs,
  .sub-screen-tabs,
  .app-menu-actions {
    grid-column: 1;
    grid-row: auto;
    justify-content: flex-start;
  }
}

@media (max-width: 780px) {
  body {
    overflow: auto;
  }

  .app {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
    grid-template-rows: auto;
  }

  .app-brand {
    min-width: 0;
  }

  .app-brand h1 {
    font-size: 21px;
  }

  .left-panel,
  .workspace-panel {
    min-height: 420px;
  }

  .workspace-panel.map-editor-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(420px, 1fr) auto;
  }

  .workspace-panel.map-editor-layout .map-workspace {
    grid-column: 1;
    grid-row: 2;
  }

  .workspace-panel.map-editor-layout .right-body {
    grid-column: 1;
    grid-row: 3;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  #mapCanvas {
    height: 520px;
  }

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

  .volume-formula-grid {
    grid-template-columns: 1fr;
  }
}
