:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #f0f5f3;
  --ink: #17201b;
  --muted: #66746d;
  --line: #d7ddd9;
  --accent: #176b5b;
  --accent-2: #214f86;
  --warn: #9f5b18;
  --danger: #aa3434;
  --shadow: 0 12px 28px rgba(24, 35, 31, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 14px;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: 12px;
}

.topbar,
.toolbar,
.notice,
.product-tabs,
.empty-state,
.table-wrap {
  width: 100%;
  max-width: none;
  margin: 0 auto;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 20px;
  height: 86px;
  padding: 4px 0 12px;
}

.topbar > div:first-child {
  display: grid;
  align-content: center;
  height: 58px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  line-height: 14px;
}

h1 {
  margin: 0;
  font-size: 28px;
  line-height: 32px;
}

.actions {
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-end;
  gap: 8px;
  height: 39px;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 38px;
  padding: 8px 12px;
  cursor: pointer;
  background: var(--panel);
  color: var(--ink);
}

button:hover {
  border-color: var(--accent);
}

.primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 700;
  width: 160px;
  justify-content: center;
}

.primary span:first-child {
  font-size: 20px;
  line-height: 0;
}

.ghost {
  color: var(--danger);
  background: transparent;
}

#clearButton {
  width: 190px;
}

.segmented {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  padding: 3px;
  width: 112px;
}

.segmented span {
  border-radius: 4px;
  padding: 6px 8px;
  text-align: center;
  color: var(--muted);
}

body[data-lang="zh"] .segmented [data-lang="zh"],
body[data-lang="en"] .segmented [data-lang="en"] {
  background: var(--accent-2);
  color: #fff;
}

body[data-unit-basis="per100kj"] .unit-basis-toggle [data-unit-basis="per100kj"],
body[data-unit-basis="per100g"] .unit-basis-toggle [data-unit-basis="per100g"] {
  background: var(--accent-2);
  color: #fff;
}

.unit-basis-toggle {
  width: 150px;
}

.file-input {
  display: none;
}

.notice {
  border: 1px solid #cddfd7;
  background: #eef7f2;
  color: #244d42;
  padding: 10px 12px;
  border-radius: 6px;
  min-height: 42px;
  line-height: 20px;
}

.product-tabs {
  display: flex;
  gap: 4px;
  height: 52px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 8px 0 6px;
  border-bottom: 1px solid var(--line);
}

.product-tab {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  flex: 0 0 320px;
  width: 320px;
  height: 38px;
  min-height: 38px;
  padding: 6px 10px;
  border-radius: 4px 4px 0 0;
  border-bottom: 3px solid transparent;
  text-align: left;
}

.product-tab span {
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.product-tab strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.product-tab.active {
  border-color: var(--line) var(--line) var(--accent);
  background: #eaf3ef;
  color: var(--accent);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  padding: 16px 0;
  height: 86px;
}

.toolbar label {
  display: grid;
  grid-template-rows: 14px 38px;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 14px;
}

.toolbar input,
.toolbar select {
  min-height: 38px;
  width: 260px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: var(--panel);
  color: var(--ink);
}

.empty-state {
  display: grid;
  place-items: center;
  align-content: center;
  min-height: 360px;
  border: 1px dashed #b9c4bf;
  border-radius: 8px;
  background: var(--panel);
  text-align: center;
  padding: 36px;
}

.empty-state h2 {
  margin: 0 0 8px;
  font-size: 22px;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
}

.table-wrap {
  overflow: auto;
  height: calc(100vh - 278px);
  min-height: 360px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.hidden {
  display: none;
}

table {
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

th,
td {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  vertical-align: top;
  overflow: hidden;
}

thead tr,
thead th {
  height: 104px;
}

tbody tr,
tbody td {
  height: 58px;
  max-height: 58px;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 4;
  background: #ecf1ef;
  text-align: left;
}

.item-col,
.unit-col,
.category-col {
  position: sticky;
  z-index: 3;
  background: var(--panel);
}

.item-col {
  left: 0;
}

.category-col {
  left: var(--item-width, 280px);
}

.unit-col {
  left: calc(var(--item-width, 280px) + var(--category-width, 150px));
}

thead .item-col,
thead .category-col,
thead .unit-col {
  z-index: 5;
  background: #e2ebe7;
}

.batch-head {
  display: grid;
  grid-template-rows: 24px 55px;
  gap: 5px;
  height: 84px;
  overflow: hidden;
  padding-right: 2px;
}

.batch-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.batch-title strong {
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.batch-meta {
  display: grid;
  gap: 3px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
  overflow: hidden;
}

.batch-meta > div {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-item {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-sub {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.category-col,
.unit-col {
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-cell {
  white-space: normal;
  line-height: 1.35;
}

.result-values {
  display: grid;
  gap: 5px;
}

.result-value {
  width: fit-content;
  max-width: 100%;
  cursor: help;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.result-value .editable-input {
  text-decoration: none;
}

.result-value:has(.editable-input) {
  width: 100%;
  text-decoration: none;
}

.result-value.calculated {
  color: #175f96;
  font-weight: 700;
}

.result-value.selectable {
  cursor: pointer;
}

.result-method {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.batch-tools {
  display: flex;
  gap: 5px;
  flex: 0 0 65px;
}

.icon-button {
  min-height: 28px;
  height: 28px;
  width: 30px;
  padding: 0;
  border-radius: 5px;
  color: var(--muted);
}

.column-resizer {
  position: absolute;
  top: 0;
  right: -3px;
  z-index: 8;
  width: 7px;
  height: 100%;
  cursor: col-resize;
  touch-action: none;
}

.column-resizer:hover,
.column-resizer.active {
  background: rgba(23, 107, 91, 0.35);
}

.icon-button:hover {
  color: var(--ink);
}

.editable-badge {
  display: inline-block;
  width: fit-content;
  padding: 2px 6px;
  border-radius: 4px;
  background: #fff3d9;
  color: var(--warn);
  font-size: 11px;
  font-weight: 700;
}

.editable-input {
  width: 100%;
  min-height: 34px;
  border: 1px solid #c8d7d1;
  border-radius: 5px;
  padding: 6px 8px;
}

.tooltip-panel {
  position: fixed;
  z-index: 20;
  max-width: 440px;
  background: #17201b;
  color: #fff;
  padding: 12px;
  border-radius: 6px;
  box-shadow: var(--shadow);
  font-size: 12px;
  line-height: 1.45;
  pointer-events: none;
}

.tooltip-panel dl {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 6px 10px;
  margin: 0;
}

.tooltip-panel dt {
  color: #a9c5bc;
}

.tooltip-panel dd {
  margin: 0;
  word-break: break-word;
}

@media (max-width: 760px) {
  .app-shell {
    padding: 14px;
  }

  .topbar {
    align-items: stretch;
    grid-template-columns: 1fr;
    height: auto;
  }

  .actions {
    justify-content: stretch;
  }

  .toolbar input,
  .toolbar select {
    min-width: min(100%, 280px);
  }

  .toolbar {
    height: auto;
  }

  .table-wrap {
    height: calc(100vh - 322px);
  }
}
