:root {
  --bg: #f5f7f3;
  --surface: #ffffff;
  --surface-2: #eef3ed;
  --border: #d8dfd4;
  --text: #172016;
  --muted: #66705f;
  --green: #236b3b;
  --green-2: #dcefe3;
  --amber: #a36216;
  --amber-2: #fff1d8;
  --red: #a33c35;
  --red-2: #fde3de;
  --blue: #345a86;
  --blue-2: #e0ecf8;
  --shadow: 0 10px 30px rgba(34, 49, 30, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  overflow-x: hidden;
}

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

button {
  cursor: pointer;
}

.is-hidden {
  display: none !important;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid #345a86;
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: 244px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px 18px;
  background: #172016;
  color: #f8fbf4;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 8px;
  background: #e8f2db;
  color: #172016;
  font-size: 13px;
  font-weight: 800;
}

.brand strong,
.brand small,
.client-note strong,
.client-note small {
  display: block;
}

.brand small,
.client-note small {
  margin-top: 2px;
  color: #b5c1ae;
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-item {
  height: 38px;
  padding: 0 12px;
  border: 0;
  border-radius: 7px;
  color: #dce7d5;
  background: transparent;
  text-align: left;
  font-size: 14px;
  font-weight: 600;
}

.nav-item.active,
.nav-item:hover {
  color: #172016;
  background: #e8f2db;
}

.client-note {
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(232, 242, 219, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
}

.label {
  display: block;
  margin-bottom: 8px;
  color: #b5c1ae;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.workspace {
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
  font-weight: 800;
}

h2 {
  font-size: 16px;
  line-height: 1.25;
  font-weight: 800;
}

p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.topbar-actions,
.panel-actions,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.organization-select {
  max-width: min(260px, 42vw);
}

.panel-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.field-profile-status {
  margin: 10px 14px 14px;
}

.user-management-list {
  max-height: 280px;
  overflow-y: auto;
  padding: 0;
}

.access-audit {
  display: grid;
  gap: 8px;
}

.access-audit h3 {
  margin: 4px 0 0;
  font-size: 14px;
}

.user-management-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.login-mode {
  display: inline-flex;
  align-self: flex-start;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
}

.login-mode .secondary-button {
  border: 0;
  border-radius: 0;
}

.login-mode .secondary-button + .secondary-button {
  border-left: 1px solid var(--line);
}

.login-mode .secondary-button.is-active {
  background: var(--green);
  color: #fff;
}

.credential-result {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--amber);
  border-radius: 7px;
  background: var(--amber-2);
}

.credential-result[hidden] {
  display: none;
}

.credential-result code {
  overflow-wrap: anywhere;
  color: var(--text);
  font-size: 12px;
}

.sync-status {
  margin: -8px 0 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

select,
input,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  outline: none;
}

select,
input {
  height: 38px;
  padding: 0 10px;
}

textarea {
  resize: vertical;
  padding: 10px;
}

.primary-button,
.secondary-button,
.icon-button {
  height: 38px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 800;
}

.primary-button {
  border: 1px solid var(--green);
  background: var(--green);
  color: #fff;
  padding: 0 16px;
}

.secondary-button {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 0 14px;
}

.icon-button {
  display: grid;
  width: 38px;
  place-items: center;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.kpi,
.map-panel,
.risk-panel,
.table-panel {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.kpi {
  padding: 14px;
}

.kpi span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.kpi strong {
  display: block;
  margin-top: 7px;
  font-size: 26px;
  line-height: 1;
}

.kpi-note {
  display: block;
  margin-top: 6px;
  color: var(--red);
  font-size: 11px;
  font-weight: 800;
}

.main-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(320px, 0.75fr);
  gap: 14px;
  margin-bottom: 14px;
  align-items: start;
}

.data-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
}

.intelligence-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-top: 14px;
}

.table-panel-wide {
  grid-column: span 2;
}

.main-grid > *,
.data-grid > * {
  min-width: 0;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.panel-heading.compact {
  padding: 13px 14px;
}

.map-canvas {
  position: relative;
  min-height: 430px;
  padding: 14px;
  background:
    linear-gradient(rgba(35, 107, 59, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(35, 107, 59, 0.06) 1px, transparent 1px),
    #f7faf4;
  background-size: 36px 36px;
}

.map-canvas.no-field-data #fieldShapes,
.map-canvas.no-field-data #riskPins {
  display: none;
}

.map-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.map-canvas svg {
  width: 100%;
  height: 100%;
  min-height: 392px;
}

.parcel {
  fill: #dfead8;
  stroke: #9caf94;
  stroke-width: 2;
}

.parcel-tone-1 {
  fill: #e9edd7;
}

.parcel-tone-2 {
  fill: #dce9e9;
}

.parcel-tone-3 {
  fill: #eee5d4;
}

.pin {
  stroke: #fff;
  stroke-width: 3;
}

.risk-list {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.mini-list {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.mini-item {
  display: grid;
  gap: 6px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 12px;
}

.mini-item strong {
  font-size: 13px;
}

.mini-item span {
  color: var(--muted);
}

.mini-item div {
  line-height: 1.45;
}

.readiness-action {
  justify-self: start;
}

.catalog-list .mini-item {
  min-height: 96px;
}

.catalog-search {
  display: grid;
  grid-template-columns: minmax(180px, 0.7fr) minmax(240px, 1.3fr) auto;
  align-items: end;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--border);
}

.catalog-search .primary-button {
  min-width: 92px;
}

.catalog-candidates {
  border-top: 1px solid var(--border);
  background: #fafbf8;
}

.catalog-import-preview {
  display: grid;
  gap: 8px;
  margin: 0 16px 16px;
  padding: 12px;
  border: 1px solid var(--blue);
  border-radius: 8px;
  background: var(--blue-2);
  color: var(--text);
  font-size: 12px;
  line-height: 1.45;
}

.catalog-import-preview[hidden] {
  display: none;
}

.catalog-import-preview span {
  color: var(--muted);
}

.catalog-import-preview code {
  overflow-wrap: anywhere;
  font-size: 11px;
}

.catalog-import-preview ul {
  display: grid;
  gap: 4px;
  max-height: 140px;
  margin: 0;
  padding-left: 18px;
  overflow-y: auto;
}

.subsection-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 14px 0;
}

.subsection-heading strong {
  font-size: 13px;
}

.subsection-heading span {
  color: var(--muted);
  font-size: 11px;
}

.registry-item b {
  font-weight: 800;
}

.risk-item {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.risk-item header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.risk-item strong {
  font-size: 14px;
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 900;
}

.badge-низкий {
  color: var(--blue);
  background: var(--blue-2);
}

.badge-средний {
  color: var(--amber);
  background: var(--amber-2);
}

.badge-высокий,
.badge-критический {
  color: var(--red);
  background: var(--red-2);
}

.risk-action {
  color: var(--text);
  font-size: 12px;
  line-height: 1.45;
}

.link-button {
  border: 0;
  padding: 0;
  color: var(--green);
  background: transparent;
  font-size: 12px;
  font-weight: 800;
}

.link-button:disabled {
  cursor: wait;
  opacity: 0.55;
}

.task-status {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.task-status-в-работе {
  border-color: #d4a64d;
  background: var(--amber-2);
  color: var(--amber);
}

.task-status-выполнена {
  border-color: #9caf94;
  background: var(--green-2);
  color: var(--green);
}

.task-status-отменена {
  background: #f2f2f2;
}

.task-assignee {
  min-width: 170px;
}

.task-due-date {
  min-width: 138px;
}

.task-deadline {
  display: grid;
  gap: 3px;
}

.deadline-status {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.deadline-status-overdue {
  color: var(--red);
}

.deadline-status-today {
  color: var(--amber);
}

.task-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 38px;
}

.treatment-status {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #f2f2f2;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.treatment-pending_approval {
  border-color: #d4a64d;
  background: var(--amber-2);
  color: var(--amber);
}

.treatment-approved,
.treatment-in_progress,
.treatment-completed {
  border-color: #9caf94;
  background: var(--green-2);
  color: var(--green);
}

.form-note {
  min-height: 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  color: var(--text);
  line-height: 1.45;
}

.check-row input {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  margin: 1px 0 0;
}

.treatment-safety-checklist {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.treatment-safety-checklist legend {
  padding: 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

#treatmentFormStatus,
#approvalTreatmentStatus,
#completeTreatmentStatus,
#outcomeFormStatus,
#treatmentHistoryImportStatus,
#inventoryImportStatus {
  margin-right: auto;
  color: var(--muted);
  font-size: 12px;
}

.report-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: 18px 0;
  padding: 16px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.report-toolbar h2 {
  margin: 0 0 4px;
  font-size: 18px;
}

.report-toolbar p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.report-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.table-wrap {
  max-width: 100%;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

#scoutingView table,
#tasksView table,
.treatments-table,
.treatment-history-table {
  min-width: 760px;
}

.treatments-table {
  min-width: 1040px;
}

.treatment-history-table {
  min-width: 900px;
}

#tasksView th:nth-child(4),
#tasksView td:nth-child(4),
#tasksView th:nth-child(5),
#tasksView td:nth-child(5),
#tasksView th:nth-child(6),
#tasksView td:nth-child(6) {
  white-space: nowrap;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  background: #fafbf8;
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

td small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}

.empty-row {
  color: var(--muted);
}

.visit-dialog {
  width: min(620px, calc(100vw - 28px));
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 30px 80px rgba(23, 32, 22, 0.24);
}

.visit-dialog::backdrop {
  background: rgba(23, 32, 22, 0.42);
}

.visit-dialog form {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.boundary-import-dialog {
  width: min(880px, calc(100vw - 28px));
}

.boundary-preview {
  display: grid;
  gap: 12px;
}

.boundary-preview-summary {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.boundary-mappings {
  display: grid;
  gap: 10px;
  max-height: 46vh;
  overflow-y: auto;
  padding-right: 2px;
}

.boundary-feature {
  display: grid;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfa;
}

.boundary-feature header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.boundary-feature strong {
  color: var(--text);
}

.boundary-preview .dialog-actions > span {
  margin-right: auto;
  color: var(--muted);
  font-size: 12px;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.observation-dialog {
  width: min(820px, calc(100vw - 32px));
}

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

.observation-summary > div {
  display: grid;
  gap: 3px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
}

.observation-summary span,
.observation-summary small {
  color: var(--muted);
  font-size: 12px;
}

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

.observation-photo {
  display: grid;
  gap: 7px;
  margin: 0;
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.observation-photo img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 5px;
  background: var(--surface-2);
}

.observation-photo figcaption {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

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

.crop-coverage-notice {
  margin: -6px 0 0;
  color: #855119;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.45;
}

#formStatus {
  margin-right: auto;
  color: var(--muted);
  font-size: 13px;
}

.location-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

#loginStatus {
  margin-right: auto;
  color: var(--red);
  font-size: 13px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    flex-direction: row;
    align-items: center;
    max-width: 100vw;
    gap: 12px;
    overflow: hidden;
  }

  .brand {
    flex: 0 0 auto;
  }

  .nav-list {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .nav-list::-webkit-scrollbar {
    display: none;
  }

  .nav-item {
    flex: 0 0 auto;
  }

  .client-note {
    display: none;
  }

  .topbar,
  .data-grid,
  .main-grid,
  .intelligence-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .table-panel-wide {
    grid-column: auto;
  }

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

  .catalog-search {
    grid-template-columns: 1fr 1fr;
  }

  .catalog-search .primary-button {
    grid-column: span 2;
  }
}

@media (max-width: 620px) {
  .workspace {
    padding: 14px;
  }

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

  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .dialog-actions {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .dialog-actions > span {
    flex: 1 0 100%;
    margin-right: 0;
  }

  .dialog-actions button {
    flex: 1 1 auto;
  }

  .report-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .report-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .catalog-search {
    grid-template-columns: 1fr;
  }

  .catalog-search .primary-button {
    grid-column: auto;
  }

  .subsection-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .observation-summary,
  .observation-photo-grid {
    grid-template-columns: 1fr;
  }
}
