:root {
  --tool-switcher-height: 46px;
}

.tool-switcher {
  height: var(--tool-switcher-height);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 5px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-raised);
}

.tool-tab {
  min-width: 150px;
  min-height: 34px;
  padding: 6px 18px;
  border: 1px solid transparent;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

.tool-tab:hover {
  color: var(--text);
  background: var(--surface-muted);
}

.tool-tab.is-active {
  border-color: color-mix(in srgb, var(--accent) 65%, var(--line));
  background: var(--accent);
  color: var(--accent-text);
}

.tool-tab:active,
.weight-actions button:active,
.detected-count-box button:active {
  transform: translateY(1px);
}

.workbench {
  height: calc(100dvh - var(--header-height) - var(--tool-switcher-height));
}

.weight-workbench {
  height: calc(100dvh - var(--header-height) - var(--tool-switcher-height));
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  min-width: 0;
  background: var(--page);
}

.weight-summary,
.weight-editor {
  min-width: 0;
  overflow-y: auto;
}

.weight-summary {
  padding: 26px 24px max(32px, env(safe-area-inset-bottom));
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.weight-summary h2,
.weight-editor-header h2,
.weight-caveat h3,
.weight-summary p,
.weight-editor-header p,
.weight-caveat p {
  margin: 0;
}

.weight-kicker {
  margin-bottom: 6px !important;
  color: var(--accent-readable);
  font-size: 12px;
  font-weight: 800;
}

.weight-summary h2 {
  font-size: 20px;
  letter-spacing: -0.02em;
}

.weight-total-block {
  display: grid;
  gap: 4px;
  padding: 24px 0;
  border-bottom: 1px solid var(--line);
}

.weight-total-block span {
  color: var(--text-muted);
  font-size: 12px;
}

.weight-total-block strong {
  color: var(--accent-readable);
  font-family: var(--font-number);
  font-size: clamp(34px, 4vw, 54px);
  line-height: 1;
  letter-spacing: -0.055em;
  overflow-wrap: anywhere;
}

.weight-total-block output {
  color: var(--text);
  font-family: var(--font-number);
  font-size: 18px;
  font-weight: 800;
}

.detected-count-box {
  display: grid;
  gap: 10px;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

.detected-count-box > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}

.detected-count-box span,
.detected-count-box p,
.weight-action-status,
.part-hint {
  color: var(--text-muted);
  font-size: 11px;
  line-height: 1.6;
}

.detected-count-box strong {
  font-family: var(--font-number);
  font-size: 18px;
}

.detected-count-box p {
  margin: 0;
}

.weight-breakdown {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.weight-breakdown > div {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  font-size: 12px;
}

.weight-breakdown span {
  color: var(--text-muted);
}

.weight-breakdown strong {
  font-family: var(--font-number);
  font-size: 12px;
}

.weight-actions {
  display: grid;
  gap: 9px;
  padding-top: 18px;
}

.weight-reset {
  justify-self: start;
  padding: 7px 0;
  color: var(--danger);
}

.weight-action-status {
  min-height: 36px;
  margin: 0;
}

.weight-editor {
  padding: 30px max(24px, 4vw) 72px;
}

.weight-editor-inner {
  width: min(980px, 100%);
  margin: 0 auto;
}

.weight-editor-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 22px;
}

.weight-editor-header h2 {
  font-size: clamp(24px, 3vw, 36px);
  letter-spacing: -0.04em;
}

.weight-editor-header > div > p {
  margin-top: 7px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.6;
}

.weight-live-note {
  flex: 0 0 auto;
  color: var(--success);
  font-size: 12px;
  font-weight: 800;
}

.weight-parts {
  border-top: 1px solid var(--line-strong);
}

.weight-part {
  border-bottom: 1px solid var(--line-strong);
}

.weight-part > summary {
  min-height: 72px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 22px;
  padding: 13px 4px;
  list-style: none;
  cursor: pointer;
}

.weight-part > summary::-webkit-details-marker {
  display: none;
}

.weight-part > summary:hover {
  background: color-mix(in srgb, var(--surface-muted) 55%, transparent);
}

.weight-part > summary:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 72%, transparent);
  outline-offset: 2px;
}

.weight-part > summary > span {
  display: grid;
  gap: 3px;
}

.weight-part > summary strong {
  font-size: 15px;
}

.weight-part > summary small {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 400;
}

.weight-part > summary output {
  color: var(--accent-readable);
  font-family: var(--font-number);
  font-size: 15px;
  font-weight: 800;
  white-space: nowrap;
}

.weight-part.has-error > summary output {
  color: var(--danger);
}

.weight-part-body {
  padding: 4px 4px 22px;
}

.weight-fields {
  display: grid;
  grid-template-columns: repeat(4, minmax(110px, 1fr));
  gap: 12px;
}

.weight-fields > label,
.material-row > label {
  min-width: 0;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 5px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
}

.weight-fields label > span,
.material-row label > span {
  color: var(--text-muted);
  font-family: var(--font-number);
  font-size: 10px;
  font-weight: 400;
}

.weight-fields input,
.weight-fields select,
.material-row input,
.material-row select {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  grid-column: 1 / -1;
  padding: 9px 10px;
  border: 1px solid var(--line-strong);
  border-radius: calc(var(--radius) - 2px);
  background: var(--surface-raised);
  color: var(--text);
  font-family: var(--font-number);
  font-size: 14px;
}

.weight-fields select,
.material-row select {
  font-family: var(--font-ui);
}

.weight-fields input:focus-visible,
.weight-fields select:focus-visible,
.material-row input:focus-visible,
.material-row select:focus-visible {
  border-color: var(--accent-strong);
  outline: 3px solid color-mix(in srgb, var(--accent) 32%, transparent);
  outline-offset: 1px;
}

.material-row {
  display: grid;
  grid-template-columns: minmax(180px, 240px) minmax(160px, 220px);
  gap: 12px;
  margin-top: 12px;
}

.part-hint {
  margin: 10px 0 0;
}

.part-error {
  min-height: 18px;
  margin: 8px 0 0;
  color: var(--danger);
  font-size: 11px;
  font-weight: 700;
}

.weight-caveat {
  margin-top: 28px;
  padding: 20px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.weight-caveat h3 {
  margin-bottom: 7px;
  font-size: 13px;
}

.weight-caveat p {
  max-width: 76ch;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.75;
}

@media (max-width: 1050px) {
  .workbench {
    min-height: calc(100dvh - var(--header-height) - var(--tool-switcher-height));
  }

  .weight-workbench {
    grid-template-columns: minmax(270px, 320px) minmax(0, 1fr);
  }

  .weight-fields {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}

@media (max-width: 760px) {
  :root {
    --tool-switcher-height: 48px;
  }

  .tool-switcher {
    position: sticky;
    top: 0;
    z-index: 12;
    padding-inline: 10px;
  }

  .tool-tab {
    min-width: 0;
    flex: 1;
  }

  .workbench {
    min-height: calc(100dvh - var(--header-height) - var(--tool-switcher-height));
  }

  .weight-workbench {
    height: auto;
    min-height: calc(100dvh - var(--header-height) - var(--tool-switcher-height));
    display: flex;
    flex-direction: column;
  }

  .weight-summary,
  .weight-editor {
    overflow: visible;
  }

  .weight-summary {
    padding: 22px 16px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .weight-total-block strong {
    font-size: clamp(40px, 13vw, 58px);
  }

  .weight-editor {
    padding: 24px 16px max(72px, env(safe-area-inset-bottom));
  }

  .weight-editor-header {
    display: grid;
    gap: 9px;
  }

  .weight-editor-header h2 {
    font-size: 28px;
  }

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

  .material-row {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  .weight-part > summary {
    min-height: 68px;
  }
}

@media (max-width: 390px) {
  .weight-summary,
  .weight-editor {
    padding-inline: 12px;
  }

  .weight-fields,
  .material-row {
    grid-template-columns: 1fr;
  }
}
