:root {
  --bg: #f4f6f4;
  --panel: #ffffff;
  --border: #e1e5e0;
  --text: #1f2a22;
  --muted: #667169;
  --green: #2f6b3c;
  --green-light: #e7f2e9;
  --red: #b3402e;
  --red-light: #fbeae7;
  --amber: #a8760b;
  --amber-light: #fdf3e0;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

.layout { display: flex; min-height: 100vh; }

nav.sidebar {
  width: 220px;
  background: #1f2a22;
  color: #e7f2e9;
  padding: 20px 14px;
  flex-shrink: 0;
}
nav.sidebar .brand {
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 4px;
}
nav.sidebar .brand-sub {
  font-size: 12px;
  color: #9db69f;
  margin-bottom: 24px;
}
nav.sidebar a {
  display: block;
  color: #dbe8dc;
  text-decoration: none;
  padding: 9px 10px;
  border-radius: 8px;
  margin-bottom: 2px;
  font-size: 14px;
}
nav.sidebar a:hover, nav.sidebar a.active {
  background: #33452f;
  color: #fff;
}

main { flex: 1; min-width: 0; padding: 26px 36px; max-width: 1720px; }

h1 { font-size: 22px; margin: 0 0 18px; }
h2 { font-size: 17px; margin: 28px 0 12px; }
h3 { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin: 0 0 8px;}

.cards { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  min-width: 180px;
  flex: 1;
}
.card .num { font-size: 24px; font-weight: 700; }
.card .label { color: var(--muted); font-size: 13px; margin-top: 2px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 20px;
}

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .02em; }
tr:hover td { background: #fafbf9; }
.table-scroll { overflow-x: auto; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge.haul { background: var(--green-light); color: var(--green); }
.badge.in { background: var(--amber-light); color: var(--amber); }
.badge.sale { background: var(--red-light); color: var(--red); }
.badge.transfer { background: #e3edf7; color: #2f5f8a; }
.badge.service_in { background: #ede3f7; color: #6a3f9e; }
.badge.service_out { background: #f7e3ef; color: #9e3f6a; }
.badge.writeoff { background: #f0e4d8; color: #8a5a2c; }
.badge.regrade { background: #dcecf7; color: #1f5f8a; }

.balance-pos { color: var(--green); font-weight: 700; }
.balance-neg { color: var(--red); font-weight: 700; }

form.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); }
.field input, .field select, .field textarea {
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 14px;
  min-width: 120px;
  font-family: inherit;
}
.field textarea { min-width: 220px; }

/* --- вибір типу операції (журнал) --- */
.op-picker { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.op-btn {
  flex: 1; min-width: 150px;
  padding: 16px 14px;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
  cursor: pointer;
  font-size: 15px; font-weight: 700; color: var(--text);
  transition: all .12s;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.op-btn .ic { font-size: 26px; line-height: 1; }
.op-btn .sub { font-size: 11.5px; font-weight: 500; color: var(--muted); }
.op-btn:hover { border-color: #b7c3b3; }
.op-btn[data-op="sale"].active { border-color: var(--red); background: var(--red-light); color: var(--red); }
.op-btn[data-op="in"].active { border-color: var(--amber); background: var(--amber-light); color: var(--amber); }
.op-btn[data-op="haul"].active { border-color: var(--green); background: var(--green-light); color: var(--green); }
.op-btn[data-op="transfer"].active { border-color: #2f5f8a; background: #e3edf7; color: #2f5f8a; }
.op-btn[data-op="service_in"].active { border-color: #6a3f9e; background: #ede3f7; color: #6a3f9e; }
.op-btn[data-op="sale"].active .sub,
.op-btn[data-op="in"].active .sub,
.op-btn[data-op="haul"].active .sub,
.op-btn[data-op="transfer"].active .sub,
.op-btn[data-op="service_in"].active .sub { color: inherit; opacity: .85; }

/* --- вертикальна форма запису --- */
.entry-col { display: flex; flex-direction: column; gap: 15px; max-width: 540px; }
.entry-col .field { gap: 6px; }
.entry-col .field label { font-size: 13px; font-weight: 600; color: var(--text); }
.entry-col .field input, .entry-col .field select, .entry-col .field textarea {
  width: 100%; min-width: 0; padding: 10px 12px; font-size: 15px; box-sizing: border-box;
}
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.entry-hint { color: var(--muted); font-size: 14px; padding: 28px 4px; }

.field-with-toggle { display: flex; gap: 8px; align-items: center; }
.field-with-toggle select { flex: 1; }
.manual-toggle-btn {
  white-space: nowrap; flex-shrink: 0;
  background: #eef1ee; border: 1px solid var(--border); color: var(--muted);
  padding: 9px 12px; border-radius: 7px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.manual-toggle-btn:hover { background: #e3e8e3; }
.manual-toggle-btn.active { background: var(--green); color: #fff; border-color: var(--green); }
.manual-block { padding: 12px; background: #f7f8f6; border: 1px dashed var(--border); border-radius: 8px; }

/* --- пошук у списках водія/авто (search-select) --- */
.search-select-wrap { position: relative; flex: 1; min-width: 0; }
.search-select-native { display: none; }
.search-select-list {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 20;
  background: var(--panel); border: 1px solid var(--border); border-radius: 7px;
  max-height: 220px; overflow-y: auto; margin-top: 4px;
  box-shadow: 0 4px 14px rgba(0,0,0,.12);
}
.search-select-item { padding: 8px 10px; font-size: 14px; cursor: pointer; }
.search-select-item:hover { background: var(--green-light); }
.search-select-empty { padding: 8px 10px; font-size: 13px; color: var(--muted); }

.net-price-display {
  padding: 10px 12px; background: var(--green-light); color: var(--green);
  border-radius: 7px; font-weight: 700; font-size: 15px;
}

.btn {
  background: var(--green);
  color: #fff;
  border: none;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: #23532c; }
.btn.secondary { background: #eef1ee; color: var(--text); }
.btn.secondary:hover { background: #e1e5e0; }

.flash {
  background: var(--green-light);
  color: var(--green);
  padding: 10px 16px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 14px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }

.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tabs a {
  padding: 8px 14px;
  text-decoration: none;
  color: var(--muted);
  font-size: 14px;
  border-bottom: 2px solid transparent;
}
.tabs a.active { color: var(--green); border-bottom-color: var(--green); font-weight: 600; }

a.link { color: var(--green); text-decoration: none; font-weight: 600; }
a.link:hover { text-decoration: underline; }

.muted { color: var(--muted); }
.filters-row { margin-bottom: 14px; }

/* Шаблони швидкого заповнення */
.template-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip-group { display: inline-flex; align-items: stretch; }
.chip {
  background: #eef1ee;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 14px;
  border-radius: 20px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.chip:hover { background: var(--green-light); border-color: var(--green); color: var(--green); }
.chip-accent { background: var(--green-light); color: var(--green); border-color: var(--green); }
.chip-x {
  border-radius: 0 20px 20px 0;
  border-left: none;
  padding: 7px 10px;
  margin-left: -20px;
  color: var(--muted);
}
.chip-group .chip:first-child { border-radius: 20px 0 0 20px; padding-right: 24px; }
.chip-x:hover { background: var(--red-light); color: var(--red); border-color: var(--red); }

/* Прогрес-шкали контрактів */
.progress {
  position: relative;
  background: #e9ece8;
  border-radius: 20px;
  height: 24px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.progress .bar {
  height: 100%;
  border-radius: 20px 0 0 20px;
  transition: width .4s ease;
}
.progress .bar.ship { background: linear-gradient(90deg, #4f9d5e, #2f6b3c); }
.progress .bar.pay { background: linear-gradient(90deg, #4a86c4, #2f5f8a); }
.progress .bar.full { border-radius: 20px; }
.progress .lbl {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12.5px;
  font-weight: 700;
  color: #1f2a22;
  text-shadow: 0 0 3px rgba(255,255,255,.6);
}
.prog-caption { font-size: 12px; color: var(--muted); margin: 4px 0 2px; }

/* Вкладки-таби контрактів */
.status-tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.status-tabs a {
  padding: 8px 18px; border-radius: 8px; text-decoration: none;
  background: #eef1ee; color: var(--text); font-weight: 600; font-size: 14px;
}
.status-tabs a.active { background: var(--green); color: #fff; }

.doc-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #eef1ee; border: 1px solid var(--border); border-radius: 8px;
  padding: 6px 10px; font-size: 13px; margin: 3px 4px 3px 0; text-decoration: none; color: var(--text);
}
.doc-chip:hover { background: var(--green-light); border-color: var(--green); }

/* Довідники: рядки з редагуванням/деактивацією */
.btn.small { padding: 5px 11px; font-size: 12.5px; }
tr.row-inactive td { color: var(--muted); opacity: .6; }
.row-mini-input { width: 100%; min-width: 60px; padding: 5px 7px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; font-family: inherit; }

/* Тарифні сезони */
.season-panel { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 16px; }
.season-panel.active { border-color: var(--green); background: var(--green-light); }
.season-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.season-head h4 { margin: 0; font-size: 16px; }
.season-badge { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; background: var(--green); color: #fff; }

/* Візуальна схема ферми */
.farm-svg { width: 100%; height: auto; display: block; }
.farm-svg .building { cursor: pointer; transition: filter .15s; }
.farm-svg .building:hover { filter: brightness(1.08) drop-shadow(0 4px 10px rgba(47,107,60,.35)); }
.stock-under { font-size: 13px; }
