:root {
  color-scheme: light;
  --bg: #f4f6f4;
  --panel: #ffffff;
  --line: #d9ded8;
  --text: #17201b;
  --muted: #657268;
  --accent: #1f6f5b;
  --accent-2: #b84c34;
  --soft: #e8f2ee;
  --warn: #fff2d8;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
a { color: inherit; }
button, input, select, textarea {
  font: inherit;
}
button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 8px;
  padding: 9px 13px;
  cursor: pointer;
}
button:hover { border-color: #9db0a6; }
button.primary, .primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
button.danger { color: #9a2f20; border-color: #e0b7ae; }
button.ghost { background: transparent; }
button.icon {
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-grid;
  place-items: center;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 22px;
  background: rgba(255,255,255,.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}
.brand {
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}
#nav {
  display: flex;
  flex: 1;
  gap: 6px;
  overflow-x: auto;
}
#nav a {
  text-decoration: none;
  color: var(--muted);
  padding: 8px 10px;
  border-radius: 8px;
  white-space: nowrap;
}
#nav a.active { background: var(--soft); color: var(--accent); }
#app {
  width: min(1480px, calc(100% - 28px));
  margin: 18px auto 44px;
}
.hero, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.hero {
  min-height: 70vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 520px);
  gap: 32px;
  align-items: center;
  padding: 42px;
}
.hero h1 {
  font-size: clamp(34px, 5vw, 68px);
  line-height: 1;
  margin: 0 0 18px;
  letter-spacing: 0;
}
.hero p {
  color: var(--muted);
  font-size: 18px;
  max-width: 720px;
}
.hero-art {
  aspect-ratio: 1.15;
  background:
    linear-gradient(90deg, transparent 19px, rgba(31,111,91,.15) 20px),
    linear-gradient(0deg, transparent 19px, rgba(31,111,91,.12) 20px),
    #eef4f1;
  background-size: 20px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  position: relative;
  overflow: hidden;
}
.hero-board {
  position: absolute;
  background: #cfb98f;
  border: 2px solid #8f7350;
  box-shadow: 0 16px 34px rgba(31, 38, 33, .16);
}
.hero-board:nth-child(1) { inset: 12% 48% 45% 8%; }
.hero-board:nth-child(2) { inset: 24% 10% 18% 55%; background: #b6c5bc; }
.hero-board:nth-child(3) { inset: 58% 35% 10% 14%; background: #e1d7c5; }
.grid {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.panel { padding: 16px; }
.panel h2, .panel h3 { margin: 0 0 12px; }
.stack { display: grid; gap: 12px; }
.row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.field {
  display: grid;
  gap: 5px;
  min-width: 120px;
  flex: 1;
}
label { color: var(--muted); font-size: 13px; }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: #fff;
  color: var(--text);
}
textarea { min-height: 78px; resize: vertical; }
.list { display: grid; gap: 8px; }
.item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}
.item.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--soft); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}
.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.tabs button.active, .seg.active {
  background: var(--soft);
  border-color: #aacabd;
  color: var(--accent);
}
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: top;
}
th { color: var(--muted); font-size: 13px; font-weight: 650; }
td input, td select { min-width: 82px; }
.board-combo { min-width: 220px; }
.grain-select { min-width: 128px; }
.detail-options {
  display: flex;
  gap: 18px;
  align-items: flex-start;
  flex-wrap: wrap;
}
.edge-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  min-width: 210px;
}
.compact-actions {
  gap: 6px;
  min-width: 92px;
}
.compact-actions button {
  padding: 6px 8px;
}
tr.invalid-row td { background: #ffe8e6; }
.error-note {
  color: #9a2f20;
  font-size: 12px;
  margin-top: 5px;
}
.group-note {
  font-weight: 650;
  color: #664d03;
  margin-bottom: 8px;
}
.group-color-0 td { background: #fff4d8; }
.group-color-1 td { background: #e7f3ff; }
.group-color-2 td { background: #edf7df; }
.group-color-3 td { background: #f3e9ff; }
.group-color-4 td { background: #e7f7f4; }
.group-color-5 td { background: #ffecef; }
.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 10px;
}
.kpi {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.kpi strong { display: block; font-size: 23px; margin-top: 6px; }
.layout-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.sheet {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
}
.sheet svg {
  width: 100%;
  height: 260px;
  display: block;
  background: #fbfaf6;
  border: 1px solid #d9c8a8;
}
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--accent);
  font-size: 12px;
}
.notice {
  background: var(--warn);
  border: 1px solid #ead3a4;
  padding: 12px;
  border-radius: 8px;
}
dialog {
  border: 0;
  border-radius: 8px;
  padding: 0;
  width: min(460px, calc(100% - 24px));
}
dialog::backdrop { background: rgba(23,32,27,.46); }
.modal { padding: 18px; position: relative; }
.modal .close { position: absolute; right: 12px; top: 12px; }
#toastHost {
  position: fixed;
  right: 14px;
  bottom: 14px;
  display: grid;
  gap: 8px;
  z-index: 20;
}
.toast {
  background: #17201b;
  color: #fff;
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: 0 12px 28px rgba(0,0,0,.18);
}
.product-img {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
}
@media (max-width: 920px) {
  .hero, .grid { grid-template-columns: 1fr; }
  .hero { padding: 28px 18px; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .layout-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { flex-wrap: wrap; }
  #authButton { margin-left: auto; }
}
@media (max-width: 560px) {
  #app { width: min(100% - 16px, 1480px); }
  .kpis { grid-template-columns: 1fr; }
  .layout-grid { grid-template-columns: 1fr; }
  th, td { padding: 6px; }
}
