@font-face {
  font-family: "Marck Script";
  src: url("../assets/fonts/MarckScript-Regular.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

:root {
  color-scheme: light;
  --bg: #f5f5f7;
  --bg-gradient:
    radial-gradient(circle at 16% 8%, rgba(111, 224, 165, 0.38) 0, transparent 34%),
    radial-gradient(circle at 88% 18%, rgba(82, 188, 226, 0.34) 0, transparent 36%),
    linear-gradient(135deg, #d4f4e4 0%, #cceef5 48%, #f7f4ff 100%);
  --text: #1d1d1f;
  --muted: #6e6e73;
  --panel: #ffffff;
  --field: #f5f5f7;
  --control: #e8e8ed;
  --line: rgba(0, 0, 0, 0.1);
  --accent: #0071e3;
  --accent-strong: #0066cc;
  --positive: #248a3d;
  --warning: #b25000;
  --danger: #d70015;
  --shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
  --card-shadow:
    0 14px 34px rgba(21, 45, 38, 0.16),
    0 4px 10px rgba(21, 45, 38, 0.10),
    inset 0 1px 0 rgba(255, 255, 255, 0.78);
  --card-shadow-hover:
    0 20px 44px rgba(21, 45, 38, 0.22),
    0 7px 16px rgba(21, 45, 38, 0.14),
    inset 0 1px 0 rgba(255, 255, 255, 0.84);
  --card-line: rgba(30, 75, 61, 0.16);
}

:root.dark {
  color-scheme: dark;
  --bg: #000000;
  --bg-gradient:
    radial-gradient(circle at 16% 8%, rgba(33, 132, 86, 0.36) 0, transparent 36%),
    radial-gradient(circle at 88% 18%, rgba(30, 103, 145, 0.32) 0, transparent 38%),
    linear-gradient(135deg, #061c13 0%, #071b22 48%, #02030a 100%);
  --text: #f5f5f7;
  --muted: #98989d;
  --panel: #1c1c1e;
  --field: #2c2c2e;
  --control: #2c2c2e;
  --line: rgba(255, 255, 255, 0.14);
  --accent: #0a84ff;
  --accent-strong: #64d2ff;
  --positive: #30d158;
  --warning: #ff9f0a;
  --danger: #ff453a;
  --shadow: 0 2px 14px rgba(0, 0, 0, 0.3);
  --card-shadow:
    0 16px 38px rgba(0, 0, 0, 0.62),
    0 5px 14px rgba(0, 0, 0, 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.07);
  --card-shadow-hover:
    0 22px 50px rgba(0, 0, 0, 0.72),
    0 8px 20px rgba(0, 0, 0, 0.50),
    inset 0 1px 0 rgba(255, 255, 255, 0.10);
  --card-line: rgba(255, 255, 255, 0.18);
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: var(--app-viewport-height, 100dvh);
  background: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#app {
  min-height: var(--app-viewport-height, 100dvh);
}

body.modal-open,
body:has(#plantDetailModal:not([hidden])),
body:has(#deleteConfirmModal:not([hidden])),
body:has(#entityFormModal:not([hidden])) {
  overflow: hidden;
  overscroll-behavior: none;
}

main,
section,
form,
fieldset,
article,
div,
dl,
button,
input,
select,
textarea {
  min-width: 0;
}

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

a {
  color: inherit;
  text-decoration: none;
}

#app {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 14px max(28px, env(safe-area-inset-bottom));
}

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 68px;
  padding: 10px 54px 18px;
}

.topbar > .icon-button {
  position: absolute;
  top: 10px;
  right: 2px;
}

.card-kicker {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-family: "Marck Script", cursive;
  font-size: 3.45rem;
  font-weight: 400;
  line-height: 1;
  letter-spacing: 0;
}

.brand-lockup {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 9px;
  min-width: 0;
  text-align: center;
}

.brand-signature {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}

h2 {
  margin-bottom: 0;
  font-size: 1.03rem;
  line-height: 1.2;
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 4px;
  margin-bottom: 14px;
  border: 0;
  border-radius: 8px;
  background: color-mix(in srgb, var(--control) 88%, transparent);
  backdrop-filter: blur(20px);
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.tab,
.icon-button,
.secondary,
.primary,
.action {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  transition:
    transform 0.18s ease,
    background 0.18s ease,
    border-color 0.18s ease;
}

.tab {
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  min-width: 0;
  padding-inline: 6px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab.is-active {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.icon-button {
  width: 44px;
  background: var(--panel);
  border: 1px solid var(--line);
  color: var(--text);
  box-shadow: none;
}

.add-plant-button {
  flex: 0 0 46px;
  margin-top: 27px;
  font-size: 1.45rem;
  font-weight: 800;
  line-height: 1;
}

/* Анимация появления разделов */
.view {
  display: none;
  opacity: 0;
  animation: fadeIn 0.25s ease-out both;
}

.view.is-active {
  display: block;
  animation: fadeIn 0.25s ease-out both;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

[hidden] {
  display: none !important;
}

.panel,
.result-card,
.plant-card,
.farmer-card,
.history-card,
.empty-state,
.summary {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.load-form,
.plant-form,
.farmer-form {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.plant-form,
.farmer-form {
  margin-bottom: 14px;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.field {
  position: relative;
  display: grid;
  gap: 7px;
}

label {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--text);
  padding: 0 12px;
  outline: none;
  overflow-wrap: anywhere;
  font-size: 16px;
}

textarea {
  min-height: 82px;
  padding-block: 12px;
  resize: vertical;
}

/* Сегментированный контрол */
.input-with-segments {
  display: flex;
  align-items: stretch;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  overflow: hidden;
}

.input-with-segments input {
  flex: 1;
  min-width: 72px;
  border: none;
  background: transparent;
  min-height: 46px;
  padding: 0 12px;
  outline: none;
}

.segmented-control {
  flex: 0 0 auto;
  display: flex;
  background: var(--control);
  border-radius: 0 8px 8px 0;
  padding: 3px;
  gap: 2px;
  align-items: center;
}

.segment {
  min-width: 0;
  min-height: 34px;
  padding: 6px 10px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.82rem;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}

.segment.active {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.address-source-segmented {
  border-radius: 8px;
  background: var(--control);
  padding: 3px;
  gap: 2px;
  align-items: center;
  display: flex;
}

.address-source-segmented .segment {
  flex: 1;
  text-align: center;
}

.address-suggestions {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 20;
  display: grid;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.address-suggestion {
  display: grid;
  gap: 4px;
  width: 100%;
  min-height: 58px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  padding: 10px 12px;
  text-align: left;
  cursor: pointer;
}

.address-suggestion:last-child {
  border-bottom: 0;
}

.address-suggestion:hover,
.address-suggestion.is-active {
  background: color-mix(in srgb, var(--accent) 12%, var(--panel));
}

.address-suggestion strong,
.address-suggestion span {
  overflow-wrap: anywhere;
}

.address-suggestion span {
  color: var(--muted);
  font-size: 0.86rem;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.culture-picker,
.unloading-picker {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.culture-picker legend,
.unloading-picker legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

.culture-picker .culture-toggle,
.unloading-picker label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  min-width: 0;
  color: var(--text);
  overflow-wrap: anywhere;
}

.culture-price-row {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--field) 70%, var(--panel));
  transition: border-color 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}

.culture-price-row.is-selected {
  border-color: color-mix(in srgb, var(--accent) 38%, var(--line));
  background: color-mix(in srgb, var(--accent) 7%, var(--panel));
  box-shadow: 0 6px 16px rgba(0, 113, 227, 0.08);
}

.culture-toggle {
  font-size: 0.88rem;
  font-weight: 850;
  line-height: 1.15;
}

.culture-toggle span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.culture-value-fields {
  display: none;
  grid-template-columns: repeat(2, minmax(0, 104px));
  gap: 6px;
  align-items: end;
}

.culture-price-row.is-selected .culture-value-fields {
  display: grid;
}

.plant-form .culture-value-fields {
  grid-template-columns: minmax(0, 108px);
}

.culture-mini-field {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 850;
  line-height: 1.05;
}

.culture-mini-field span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.culture-picker input[type="checkbox"],
.unloading-picker input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  min-height: 18px;
  margin: 0;
  accent-color: var(--accent);
}

.culture-price-row input[data-culture-price],
.culture-price-row input[data-culture-quantity] {
  width: 100%;
  min-height: 34px;
  padding-inline: 7px;
  font-size: 0.86rem;
  font-weight: 800;
}

.primary {
  width: 100%;
  background: var(--accent);
  color: white;
  font-weight: 700;
}

.primary,
.secondary,
.action {
  min-width: 0;
  min-height: 48px;
  padding-block: 8px;
  line-height: 1.15;
  white-space: normal;
  overflow-wrap: anywhere;
}

.primary:disabled {
  cursor: wait;
  opacity: 0.72;
}

.secondary {
  padding: 0 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-weight: 600;
}

.primary:active,
.secondary:active,
.action:active,
.icon-button:active {
  transform: translateY(1px);
}

.form-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(112px, auto);
  gap: 8px;
}

.summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 14px 0;
  padding: 14px;
}

.summary span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.summary strong {
  display: block;
  margin-top: 4px;
  font-size: 1.1rem;
}

.status-line {
  grid-column: 1 / -1;
}

.results,
.plant-list,
.farmer-list,
.history-list {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.history-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.danger-button {
  color: #c83d3d;
}

.history-content,
.history-result {
  min-width: 0;
  overflow-wrap: anywhere;
}

/* ─── Компактные карточки ────────── */
.result-card,
.plant-card,
.farmer-card,
.history-card {
  padding: 12px;
  position: relative;
  border-color: var(--card-line);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--panel) 98%, white) 0%, var(--panel) 100%);
  box-shadow: var(--card-shadow);
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease,
    border-color 0.2s ease;
}

.result-card::before,
.plant-card::before,
.farmer-card::before,
.history-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 3px;
  border-radius: 8px 8px 0 0;
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 50%, transparent), transparent 72%);
  opacity: 0.55;
  pointer-events: none;
}

.result-card:hover,
.plant-card:hover,
.farmer-card:hover,
.history-card:hover {
  border-color: color-mix(in srgb, var(--accent) 34%, var(--card-line));
  box-shadow: var(--card-shadow-hover);
  transform: translateY(-2px);
}

.result-card.is-best {
  border-color: color-mix(in srgb, var(--accent) 72%, var(--line));
  box-shadow: 0 4px 20px color-mix(in srgb, var(--accent) 22%, transparent), var(--card-shadow);
}

/* ─── Анимация появления карточек результатов ────────── */
.result-card.slide-in {
  opacity: 0;
  transform: translateX(-120%);
  animation: slideIn 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-120%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.card-head,
.toolbar,
.history-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  cursor: pointer;
}

.card-head > div,
.toolbar > div,
.history-card > div {
  min-width: 0;
}

.history-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.history-detail-section + .history-detail-section {
  margin-top: 18px;
}

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

.history-source-grid > div {
  padding: 8px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--bg) 72%, var(--panel));
}

.history-source-wide {
  grid-column: 1 / -1;
}

.history-detail-results {
  display: grid;
  gap: 12px;
}

.history-detail-card {
  box-shadow: none;
}

.toolbar {
  align-items: flex-end;
  margin-bottom: 12px;
}

.search-field {
  flex: 1;
}

.badge {
  flex: 0 0 auto;
  max-width: 100%;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 13%, var(--panel));
  color: var(--accent-strong);
  padding: 5px 7px;
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

/* Эмодзи рейтинга */
.rank-emoji {
  display: inline-block;
  font-size: 1.2rem;
  line-height: 1;
  vertical-align: baseline;
  position: relative;
  top: -0.15em;
  margin-left: 6px;
}

.price-editor {
  display: grid;
  gap: 5px;
}

.plant-prices,
.farmer-prices {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
}

.price-editor span {
  color: var(--muted);
  font-size: 0.72rem;
}

.price-editor .price-value {
  font-weight: 800;
  color: var(--text);
}

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

.metrics div {
  min-width: 0;
  border-radius: 8px;
  background: color-mix(in srgb, var(--bg) 72%, var(--panel));
  padding: 6px;
}

dt {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
}

dd {
  margin: 3px 0 0;
  font-weight: 800;
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}

.profit-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding-top: 2px;
  font-size: 0.95rem;
  min-width: 0;
}

.profit-line strong {
  font-size: 1.15rem;
  text-align: right;
  overflow-wrap: anywhere;
}

.positive {
  color: var(--positive);
}

.negative {
  color: var(--danger);
}

.address {
  margin: 6px 0;
  font-size: 0.88rem;
  color: var(--muted);
}

.plant-detail {
  margin: 4px 0 0;
  font-size: 0.88rem;
  color: var(--muted);
}

.actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  margin-top: 8px;
}

.action {
  display: inline-grid;
  place-items: center;
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--field);
  color: var(--text);
  padding: 0 6px;
  font-size: 0.88rem;
  font-weight: 700;
  text-align: center;
}

.danger-action {
  color: var(--danger);
}

.plant-card .actions,
.farmer-card .actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 4px;
}

.plant-card .action,
.farmer-card .action {
  flex: 1 1 max-content;
  min-height: 34px;
  padding: 0 4px;
  line-height: 1.05;
  white-space: nowrap;
  overflow-wrap: normal;
}

.plant-card p:not(.card-kicker):not(.address),
.farmer-card p:not(.card-kicker):not(.address) {
  margin-bottom: 0;
  color: var(--muted);
}

/* Крестик удаления */
.delete-cross {
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  width: auto;
  height: auto;
}

/* Кнопка редактирования (карандаш) */
.edit-pencil {
  position: absolute;
  top: 6px;
  right: 32px;
  font-size: 1.2rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
  width: auto;
  height: auto;
}

/* Иконка сравнения показателей */
.compare-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  vertical-align: middle;
}

.compare-indicator .status-icon {
  font-size: 1.1rem;
}

.compare-indicator .compare-link {
  font-size: 0.8rem;
  color: var(--accent);
  cursor: pointer;
  border: none;
  background: none;
  text-decoration: underline;
  padding: 0;
}

/* ─── Модальное окно ───────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  z-index: 100;
}

.modal-overlay[hidden] {
  display: none;
}

.modal-content {
  background: var(--panel);
  border-radius: 16px;
  padding: 24px 20px 20px;
  width: min(300px, 100%);
  max-height: calc(100dvh - 28px);
  min-height: 0;
  margin: auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  text-align: center;
  overflow-wrap: anywhere;
  -webkit-overflow-scrolling: touch;
}

.modal-content p {
  font-size: 1rem;
  color: var(--text);
  margin: 0 0 8px;
}

.modal-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 20px;
}

.modal-actions .secondary {
  background: var(--field);
  color: var(--text);
  border: 1px solid var(--line);
  font-weight: 500;
  padding: 0 18px;
  min-height: 38px;
}

.modal-actions .primary.danger-action {
  background: rgba(215, 0, 21, 0.1);
  color: var(--danger);
  border: none;
  font-weight: 500;
  padding: 0 18px;
  min-height: 38px;
}

:root.dark .modal-actions .primary.danger-action {
  background: rgba(255, 69, 58, 0.15);
}

/* Детали */
.plant-detail-modal {
  width: min(720px, 100%);
  max-height: calc(100dvh - 28px);
  min-height: 0;
  margin: auto;
  overflow: hidden;
  overflow-y: hidden;
  overflow-x: hidden;
  text-align: left;
  padding: 20px;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
}

.entity-form-modal {
  width: min(820px, 100%);
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
}

.entity-form-modal .plant-detail-body {
  display: block;
  overflow: visible;
  min-height: auto;
}

.entity-form-modal .plant-form,
.entity-form-modal .farmer-form {
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  gap: 10px;
}

.entity-form-modal .culture-picker,
.entity-form-modal .unloading-picker {
  gap: 6px;
  padding: 8px;
}

.entity-form-modal .culture-picker .culture-price-row {
  gap: 7px;
  padding: 7px;
}

.entity-form-modal .culture-toggle {
  min-height: 24px;
  font-size: 0.78rem;
  line-height: 1.1;
}

.entity-form-modal .culture-value-fields {
  grid-template-columns: repeat(2, minmax(0, 92px));
}

.entity-form-modal .plant-form .culture-value-fields {
  grid-template-columns: minmax(0, 96px);
}

.entity-form-modal .culture-mini-field {
  font-size: 0.64rem;
}

.entity-form-modal .culture-price-row input[data-culture-price],
.entity-form-modal .culture-price-row input[data-culture-quantity] {
  min-height: 32px;
  padding-inline: 6px;
  font-size: 0.82rem;
}

.plant-detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex: 0 0 auto;
}

.plant-detail-header h2 {
  margin: 0;
  overflow-wrap: anywhere;
}

.plant-detail-body {
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Анализ связки фермер ↔ завод */
.deal-map-modal { width: min(1040px, 100%); }
.deal-map-body { min-height: 0; flex: 1 1 auto; overflow-y: auto; padding-right: 2px; }
.deal-map-toolbar, .deal-list-head { display: flex; gap: 10px; align-items: end; justify-content: space-between; margin-bottom: 10px; }
.deal-map-toolbar label, .deal-list-head label { display: grid; grid-template-columns: auto minmax(92px, 1fr) auto; align-items: center; gap: 6px; color: var(--muted); font-size: .8rem; }
.deal-map-toolbar select, .deal-map-toolbar input, .deal-list-head select { min-height: 36px; padding-inline: 8px; }
.deal-map-status { font-size: .82rem !important; color: var(--muted) !important; }
.deal-map-canvas { height: min(42vh, 390px); min-height: 250px; flex: 0 0 250px; border-radius: 12px; overflow: hidden; background: var(--field); margin: 10px 0; }
.deal-map-canvas .empty-state { padding: 20px; }
.deal-map-summary { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 16px; }
.deal-map-summary span { background: var(--field); border: 1px solid var(--line); border-radius: 999px; padding: 5px 9px; color: var(--text); font-size: .8rem; }
.deal-detail-panel { background: var(--field); border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 16px; }
.deal-detail-panel h3 { margin: 0; font-size: 1rem; }
.deal-status { margin: 10px 0 !important; font-weight: 700; }
.deal-list-head h3 { margin: 0; }
.deal-list { display: grid; gap: 8px; padding-bottom: 4px; }
.deal-list-item { width: 100%; display: grid; grid-template-columns: 1.3fr repeat(6, minmax(95px, .9fr)); align-items: center; gap: 8px; text-align: left; background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 10px; padding: 10px; cursor: pointer; font-size: .78rem; }
.deal-list-item:hover, .deal-list-item.is-selected { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--panel)); }
.deal-list-item span { color: var(--muted); }
.deal-list-item .positive { color: var(--success); font-weight: 700; }
.deal-list-item .negative { color: var(--danger); font-weight: 700; }

.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  flex: 0 0 auto;
  background: none;
  border: none;
  border-radius: 999px;
  font-size: 1.8rem;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}

.detail-section {
  margin-bottom: 16px;
}

.detail-section h3 {
  margin: 0 0 8px;
  font-size: 0.9rem;
  color: var(--muted);
}

.indicator-toolbar {
  margin-bottom: 14px;
}

.indicator-culture-field {
  display: grid;
  gap: 7px;
}

.indicator-panel {
  display: grid;
  gap: 12px;
  max-height: min(54vh, 440px);
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 2px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  flex: 1 1 auto;
}

.indicator-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--field) 72%, var(--panel));
  padding: 10px;
}

.indicator-section h3 {
  margin: 0 0 10px;
  color: var(--text);
  font-size: 0.92rem;
  line-height: 1.2;
}

.indicator-grid {
  display: grid;
  gap: 8px;
}

.indicator-row {
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(16px, 1fr) minmax(0, auto);
  align-items: baseline;
  gap: 6px;
  min-height: 26px;
  color: var(--text);
  font-size: 0.88rem;
}

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

.indicator-name,
.indicator-value {
  min-width: 0;
  overflow-wrap: anywhere;
}

.indicator-value {
  font-weight: 800;
  text-align: right;
}

.indicator-dots {
  min-width: 16px;
  border-bottom: 1px dotted color-mix(in srgb, var(--muted) 55%, transparent);
  transform: translateY(-3px);
}

.indicator-input-field {
  display: grid;
  gap: 6px;
  color: var(--text);
}

.indicator-input-field span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.indicator-input-field input,
.indicator-input-field select {
  min-height: 40px;
  padding-inline: 10px;
  font-size: 0.9rem;
}

.indicator-actions {
  margin-top: 14px;
}

.detail-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.detail-table th,
.detail-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  font-size: 0.88rem;
  overflow-wrap: anywhere;
  vertical-align: top;
}

.detail-table th {
  text-align: left;
  font-weight: 700;
  color: var(--text);
}

.detail-table td {
  color: var(--muted);
}

.history-result {
  display: grid;
  gap: 4px;
  text-align: right;
  min-width: 0;
}

.history-result span {
  color: var(--muted);
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}

.empty-state {
  display: grid;
  gap: 6px;
  padding: 18px;
  color: var(--muted);
}

.empty-state strong {
  color: var(--text);
}

/* ─── Loading Animation ────────────────────── */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 24px 16px;
}

.loading-dots {
  display: flex;
  gap: 6px;
}

.loading-dots span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0;
  animation: dotPulse 1.4s infinite ease-in-out;
}

.loading-dots span:nth-child(1) { animation-delay: 0s; }
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
  0%, 80%, 100% {
    opacity: 0;
    transform: scale(0.8);
  }
  40% {
    opacity: 1;
    transform: scale(1);
  }
}

.skeleton-list {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.skeleton-card {
  width: 100%;
  height: 80px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(30px);
  animation: slideUpFade 0.5s ease forwards;
}

.skeleton-card:nth-child(1) { animation-delay: 0.3s; }
.skeleton-card:nth-child(2) { animation-delay: 0.5s; }
.skeleton-card:nth-child(3) { animation-delay: 0.7s; }
.skeleton-card:nth-child(4) { animation-delay: 0.9s; }

@keyframes slideUpFade {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 560px) {
  .modal-overlay {
    padding: max(10px, env(safe-area-inset-top)) 10px max(12px, env(safe-area-inset-bottom));
    align-items: center;
    justify-content: center;
  }

  .modal-content,
  .plant-detail-modal {
    width: 100%;
    max-height: calc(100dvh - 20px);
    border-radius: 14px;
    min-height: 0;
    margin: 0 auto;
  }

  .deal-map-modal { padding: 14px 12px; }
  .deal-map-toolbar { display: grid; grid-template-columns: 1fr; align-items: stretch; }
  .deal-map-toolbar label { grid-template-columns: 1fr minmax(110px, 1fr) auto; }
  .deal-map-canvas { min-height: 220px; height: 34dvh; flex-basis: 220px; }
  .deal-list-head { align-items: center; }
  .deal-list-head label { grid-template-columns: 1fr; justify-items: end; }
  .deal-list-item { grid-template-columns: repeat(2, minmax(0, 1fr)); font-size: .76rem; }
  .deal-list-item strong { grid-column: 1 / -1; }

  .plant-detail-modal {
    padding: 16px;
  }

  .topbar {
    min-height: 56px;
    padding: 8px 44px 12px;
  }

  h1 {
    font-size: 2.7rem;
  }

  .load-form,
  .plant-form,
  .farmer-form {
    gap: 10px;
    padding: 10px;
  }

  .field-grid,
  .summary,
  .toolbar {
    grid-template-columns: 1fr;
  }

  .form-actions,
  .modal-actions {
    grid-template-columns: 1fr;
  }

  input,
  select,
  textarea {
    min-height: 42px;
    padding: 0 10px;
    font-size: 16px;
  }

  textarea {
    min-height: 72px;
  }

  .tab,
  .icon-button,
  .secondary,
  .primary,
  .action {
    min-height: 38px;
  }

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

  .plant-card .actions,
  .farmer-card .actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
  }

  #app {
    padding-inline: 10px;
    overflow-x: clip;
  }

  .tabs {
    gap: 2px;
    padding: 3px;
  }

  .tab {
    min-height: 38px;
    padding-inline: 3px;
    font-size: 0.78rem;
  }

  h1 {
    font-size: 2.85rem;
  }

  .brand-lockup {
    align-items: flex-end;
    gap: 7px;
  }

  .brand-signature {
    padding-bottom: 3px;
    font-size: 0.66rem;
  }

  .field-grid,
  .summary,
  .toolbar {
    grid-template-columns: 1fr;
  }

  .toolbar {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: end;
  }

  .add-plant-button {
    margin-top: 0;
  }

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

  .plant-card,
  .farmer-card {
    padding: 8px;
  }

  .plant-card .actions,
  .farmer-card .actions {
    gap: 4px;
  }

  .plant-card .action,
  .farmer-card .action {
    min-height: 32px;
    padding-inline: 3px;
  }

  .plant-prices,
  .farmer-prices {
    gap: 5px;
    margin: 7px 0;
  }

  .plant-prices .badge,
  .farmer-prices .badge {
    padding: 4px 6px;
  }

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

  .culture-picker,
  .unloading-picker {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .culture-price-row {
    gap: 6px;
    padding: 8px;
  }

  .culture-toggle {
    min-height: 28px;
    font-size: 0.82rem;
    line-height: 1.1;
  }

  .culture-value-fields {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .plant-form .culture-value-fields {
    grid-template-columns: minmax(0, 112px);
  }

  .culture-mini-field {
    font-size: 0.66rem;
  }

  .culture-price-row input[data-culture-price],
  .culture-price-row input[data-culture-quantity] {
    min-height: 36px;
    padding-inline: 7px;
    font-size: 0.86rem;
  }

  .input-with-segments {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .segment {
    padding-inline: 8px;
    font-size: 0.78rem;
  }

  .badge {
    white-space: normal;
  }

  .profit-line {
    align-items: flex-start;
    flex-direction: column;
  }

  .profit-line strong {
    text-align: left;
  }

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

  .card-head,
  .history-card {
    align-items: stretch;
    flex-direction: column;
  }

  .history-result {
    text-align: left;
  }

  .history-source-grid {
    grid-template-columns: 1fr;
  }

  .history-source-wide {
    grid-column: auto;
  }
}

@media (max-width: 390px) {
  #app {
    padding-inline: 8px;
  }

  .load-form,
  .plant-form,
  .farmer-form {
    padding: 10px;
  }

  .topbar {
    padding-inline: 44px;
  }

  h1 {
    font-size: 2.45rem;
  }

  .brand-lockup {
    flex-direction: column;
    align-items: center;
    gap: 0;
  }

  .brand-signature {
    padding-bottom: 0;
    white-space: normal;
  }

  .input-with-segments {
    grid-template-columns: 1fr;
  }

  .segmented-control {
    border-radius: 0 0 8px 8px;
    justify-content: stretch;
  }

  .input-with-segments input {
    min-height: 44px;
  }

  .segment {
    flex: 1 1 0;
  }

  .form-actions,
  .actions,
  .modal-actions {
    grid-template-columns: 1fr;
  }

  .plant-card .actions,
  .farmer-card .actions {
    display: flex;
    flex-wrap: nowrap;
  }

  .plant-card .action,
  .farmer-card .action {
    min-height: 30px;
    padding-inline: 2px;
  }

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