:root {
  --brand: #cf1736;
  --brand-dark: #9b1026;
  --ink: #20252b;
  --muted: #64707d;
  --line: #d9dee5;
  --soft-line: #e9edf2;
  --panel: #ffffff;
  --page: #f5f6f8;
  --fit: #177245;
  --caution: #b36b00;
  --check: #2563a8;
  --reject: #7d8792;
  --danger: #bf1f35;
  --focus: #1f66cc;
  --shadow: 0 12px 30px rgba(24, 31, 42, 0.08);
  font-family: "Segoe UI", "Yu Gothic UI", "Meiryo", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--page);
  color: var(--ink);
}

body {
  margin: 0;
  min-width: 320px;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-header {
  position: relative;
  overflow: hidden;
  background: #12161b;
  border-bottom: 1px solid var(--line);
  color: #ffffff;
}

.app-header::before {
  content: "";
  position: absolute;
  inset: 0 0 0 32%;
  background: url("images/01_TungForceRec_Helical_m.jpg") 45% 62% / cover no-repeat;
}

.app-header::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(18, 22, 27, 1) 0%, rgba(18, 22, 27, 1) 30%, rgba(18, 22, 27, 0.82) 46%, rgba(18, 22, 27, 0.24) 68%, rgba(18, 22, 27, 0) 100%),
    linear-gradient(180deg, rgba(245, 246, 248, 0) 78%, rgba(245, 246, 248, 0.55) 100%);
}

.header-inner {
  position: relative;
  z-index: 1;
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  min-height: 330px;
  padding: 24px 0 36px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 34px;
}

.header-top {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
}

.hero-logo {
  display: block;
  width: 190px;
  height: auto;
  border-radius: 2px;
}

.app-controls {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.control-group {
  display: grid;
  gap: 5px;
  justify-items: end;
}

.control-group > span {
  color: rgba(255, 255, 255, 0.75);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.segmented-control {
  display: inline-flex;
  padding: 3px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 999px;
  background: rgba(18, 22, 27, 0.55);
  backdrop-filter: blur(8px);
}

.segmented-control button {
  min-height: 28px;
  padding: 5px 10px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: rgba(255, 255, 255, 0.78);
  font-size: 12px;
  font-weight: 800;
}

.segmented-control button.is-active {
  background: #ffffff;
  color: var(--brand);
}

.segmented-control button:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 2px;
}

.hero-copy {
  align-self: center;
  max-width: 560px;
}

.eyebrow,
.step-label {
  margin: 0 0 8px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
  line-height: 1.25;
}

h1 {
  font-size: clamp(28px, 4vw, 44px);
}

h2 {
  font-size: 22px;
}

h3 {
  font-size: 18px;
}

.header-copy {
  max-width: 600px;
  margin: 10px 0 0;
  color: rgba(255, 255, 255, 0.86);
  font-size: 15px;
  line-height: 1.7;
}

.app-main {
  width: min(1180px, calc(100% - 32px));
  margin: 24px auto 48px;
  display: grid;
  grid-template-columns: minmax(330px, 420px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

.input-panel,
.results-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 48px);
  min-height: 0;
  overflow: hidden;
}

.input-panel {
  position: sticky;
  top: 16px;
}

.section-heading {
  padding: 22px 22px 14px;
  border-bottom: 1px solid var(--soft-line);
}

.results-heading {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
}

.data-status {
  margin: 3px 0 0;
  padding: 6px 9px;
  border-radius: 999px;
  background: #f0f3f6;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.data-status.is-ready {
  background: #e8f5ee;
  color: var(--fit);
}

.data-status.is-error {
  background: #fff0f2;
  color: var(--danger);
}

.tool-form {
  flex: 1 1 auto;
  padding: 20px 22px 22px;
  min-height: 0;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

.results-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

.field-grid {
  display: grid;
  gap: 14px;
  margin-bottom: 16px;
}

.field-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: #34404c;
  font-size: 13px;
  font-weight: 700;
}

.field small {
  color: var(--muted);
  font-weight: 500;
}

.field input,
.field select {
  width: 100%;
  min-height: 42px;
  padding: 9px 10px;
  border: 1px solid #c8d0d9;
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
}

.field input:focus,
.field select:focus,
.mode-option:has(input:focus-visible) {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.strategy-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 16px;
  padding: 0;
  border: 0;
}

.strategy-group legend {
  grid-column: 1 / -1;
  margin-bottom: 2px;
  color: #34404c;
  font-size: 13px;
  font-weight: 800;
}

.strategy-option {
  position: relative;
  display: grid;
  min-height: 210px;
  border: 1px solid #cdd5de;
  border-radius: 8px;
  background: #fbfcfd;
}

.strategy-option input {
  position: absolute;
  opacity: 0;
}

.strategy-option > span {
  display: grid;
  gap: 10px;
  place-content: center;
  height: 100%;
  padding: 12px;
  text-align: center;
}

.strategy-icon {
  width: 96px;
  height: 112px;
  justify-self: center;
  border-radius: 6px;
  background: #fff;
  object-fit: contain;
}

@media (max-width: 560px) {
  .strategy-icon {
    width: 84px;
    height: 98px;
  }
}

.strategy-copy {
  display: grid;
  gap: 5px;
}

.strategy-option strong {
  font-size: 14px;
  line-height: 1.35;
}

.strategy-option small {
  color: var(--muted);
  font-size: 11px;
}

.strategy-option:has(input:focus-visible) {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.strategy-option:has(input:checked) {
  border-color: var(--brand);
  background: #fff4f6;
  box-shadow: inset 0 0 0 1px var(--brand);
}

.input-guide {
  margin: 0 0 18px;
  padding: 14px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: #fbfcfd;
}

.input-guide-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  margin-bottom: 12px;
}

.input-guide-header .step-label {
  margin: 0;
  font-size: 11px;
}

.input-guide h3 {
  font-size: 15px;
}

.strategy-guide-panel {
  display: grid;
  gap: 12px;
}

.strategy-guide-panel[hidden] {
  display: none;
}

.guide-visual {
  display: grid;
  min-height: 0;
  overflow: hidden;
  border: 1px solid #dfe4ea;
  border-radius: 8px;
  background: #ffffff;
}

.guide-visual img {
  display: block;
  width: 100%;
  max-height: 360px;
  padding: 8px;
  object-fit: contain;
}

.guide-notes {
  display: grid;
  gap: 9px;
}

.guide-title {
  margin: 0;
  color: #20252b;
  font-size: 13px;
  font-weight: 800;
}

.guide-notes ul {
  display: grid;
  gap: 7px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.guide-notes li {
  display: grid;
  grid-template-columns: 78px 1fr;
  gap: 8px;
  align-items: start;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.guide-notes li strong {
  color: var(--brand);
  font-size: 12px;
}

.mode-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0 0 16px;
  padding: 0;
  border: 0;
}

.mode-group legend {
  grid-column: 1 / -1;
  margin-bottom: 2px;
  color: #34404c;
  font-size: 13px;
  font-weight: 700;
}

.mode-option {
  position: relative;
  display: grid;
  min-height: 74px;
  border: 1px solid #cdd5de;
  border-radius: 8px;
  background: #fbfcfd;
}

.mode-option-primary {
  grid-column: 1 / -1;
  min-height: 92px;
  border-color: #f0b5bf;
  background: #fff8f9;
}

.mode-option-primary::before {
  content: var(--standard-label, "標準");
  position: absolute;
  top: 10px;
  right: 12px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--brand);
  color: #ffffff;
  font-size: 11px;
  font-weight: 800;
}

.mode-option input {
  position: absolute;
  opacity: 0;
}

.mode-option span {
  display: grid;
  gap: 4px;
  place-content: center;
  height: 100%;
  padding: 10px;
  text-align: center;
}

.mode-option strong {
  font-size: 13px;
}

.mode-option-primary strong {
  font-size: 17px;
}

.mode-option small {
  color: var(--muted);
  font-size: 11px;
}

.mode-option-primary small {
  font-size: 12px;
}

.mode-option:has(input:checked) {
  border-color: var(--brand);
  background: #fff4f6;
  box-shadow: inset 0 0 0 1px var(--brand);
}

.is-hidden {
  display: none !important;
}

.advanced {
  margin: 0 0 16px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: #fafbfc;
}

.advanced summary {
  padding: 12px 14px;
  color: #34404c;
  font-size: 13px;
  font-weight: 700;
}

.advanced .field-grid {
  padding: 0 14px 14px;
}

.form-errors {
  min-height: 0;
  margin-bottom: 14px;
  color: var(--danger);
  font-size: 13px;
  line-height: 1.6;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.primary-button,
.secondary-button {
  min-height: 42px;
  padding: 9px 16px;
  border-radius: 6px;
  font-weight: 700;
}

.primary-button {
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--brand-dark);
}

.secondary-button {
  border: 1px solid #c7d0da;
  background: #ffffff;
  color: #34404c;
}

.condition-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 20px;
  padding: 16px 22px 0;
}

.condition-chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 9px;
  border: 1px solid #d9e0e8;
  border-radius: 999px;
  background: #f8fafc;
  color: #33404b;
  font-size: 12px;
  font-weight: 700;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 16px 22px 6px;
}

.summary-item {
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
}

.summary-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.summary-item strong {
  display: block;
  margin-top: 4px;
  font-size: 24px;
}

.empty-state {
  margin: 16px 22px 22px;
  padding: 28px;
  display: grid;
  gap: 8px;
  border: 1px dashed #cbd4df;
  border-radius: 8px;
  background: #fafbfc;
  color: var(--muted);
}

.empty-state strong {
  color: var(--ink);
}

.candidate-list {
  display: grid;
  gap: 14px;
  padding: 16px 22px 22px;
}

.candidate-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  overflow: hidden;
}

.candidate-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 12px;
  padding: 16px;
  border-left: 5px solid var(--check);
}

.candidate-card[data-status="fit"] .candidate-top {
  border-left-color: var(--fit);
}

.candidate-card[data-status="caution"] .candidate-top {
  border-left-color: var(--caution);
}

.candidate-card[data-status="check"] .candidate-top {
  border-left-color: var(--check);
}

.candidate-title {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.status-badge,
.category-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.status-badge.fit {
  background: #e8f5ee;
  color: var(--fit);
}

.status-badge.caution {
  background: #fff5df;
  color: var(--caution);
}

.status-badge.check {
  background: #edf5ff;
  color: var(--check);
}

.category-badge {
  background: #f0f3f6;
  color: #33404b;
}

.adjustment-badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #eef8f3;
  color: #0f7a45;
  font-size: 12px;
  font-weight: 800;
}

.adjustment-badge.unresolved {
  background: #fff5df;
  color: var(--caution);
}

.candidate-name {
  margin: 0;
  font-size: 18px;
}

.candidate-sub {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.product-image {
  grid-column: 2;
  grid-row: 1;
  width: 96px;
  height: 72px;
  margin: 0;
  align-self: start;
  overflow: hidden;
  border: 1px solid var(--soft-line);
  border-radius: 6px;
  background: #ffffff;
}

.product-image img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.rank {
  grid-column: 3;
  grid-row: 1;
  min-width: 58px;
  text-align: right;
  color: var(--brand);
  font-size: 13px;
  font-weight: 800;
}

.spec-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  background: var(--soft-line);
  border-top: 1px solid var(--soft-line);
  border-bottom: 1px solid var(--soft-line);
}

.spec {
  min-height: 70px;
  padding: 11px 12px;
  background: #ffffff;
}

.spec span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.help-popover {
  position: relative;
  display: inline-block;
  border-bottom: 1px dotted var(--brand);
  color: var(--brand);
  font: inherit;
  font-weight: 700;
  line-height: 1.25;
  vertical-align: middle;
  cursor: help;
}

.help-popover:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.help-popover-text {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  z-index: 30;
  width: min(320px, 78vw);
  padding: 9px 10px;
  border: 1px solid #f0b5bf;
  border-radius: 6px;
  background: #ffffff;
  color: #34404c;
  box-shadow: 0 10px 24px rgba(24, 31, 42, 0.16);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.55;
  text-align: left;
  text-transform: none;
  transform: translate(-50%, 4px);
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.help-popover-text::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 100%;
  width: 8px;
  height: 8px;
  border-right: 1px solid #f0b5bf;
  border-bottom: 1px solid #f0b5bf;
  background: #ffffff;
  transform: translate(-50%, -4px) rotate(45deg);
}

.help-popover:hover .help-popover-text,
.help-popover:focus .help-popover-text,
.help-popover:focus-within .help-popover-text {
  opacity: 1;
  transform: translate(-50%, 0);
  visibility: visible;
}

.spec strong {
  display: block;
  margin-top: 5px;
  font-size: 15px;
  overflow-wrap: anywhere;
}

.stage-load-summary {
  padding: 15px 16px 16px;
  border-bottom: 1px solid var(--soft-line);
  background: #fbfcfd;
}

.stage-load-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.stage-load-card {
  display: grid;
  gap: 10px;
  align-content: start;
  padding: 12px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: #ffffff;
}

.stage-load-card.is-adjusted {
  border-color: #a8d9bf;
  background: #fbfffd;
}

.stage-load-card.is-unresolved {
  border-color: #f0c36a;
  background: #fffdf7;
}

.stage-card-head {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}

.stage-card-head span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.critical-pill {
  padding: 2px 7px;
  border-radius: 999px;
  background: #fff0f3;
  color: var(--brand);
  font-size: 11px;
  font-style: normal;
  font-weight: 800;
}

.stage-param-list {
  display: grid;
  gap: 1px;
  margin: 0;
  background: var(--soft-line);
  border: 1px solid var(--soft-line);
}

.stage-param {
  display: grid;
  grid-template-columns: minmax(120px, 0.9fr) minmax(0, 1.1fr);
  gap: 8px;
  padding: 8px 9px;
  background: #ffffff;
}

.stage-param dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stage-param dd {
  margin: 0;
}

.stage-param strong {
  color: #111827;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.stage-param small {
  display: block;
  margin-top: 2px;
  color: #34404c;
  font-size: 11px;
  line-height: 1.45;
}

.radial-pass-details {
  display: grid;
  gap: 7px;
  padding: 9px 10px;
  border: 1px solid #dce7e0;
  border-radius: 7px;
  background: #ffffff;
}

.radial-pass-details > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.radial-pass-details ol {
  display: grid;
  gap: 5px;
  margin: 0;
  padding-left: 1.25rem;
}

.radial-pass-details li {
  line-height: 1.35;
}

.radial-pass-details strong {
  color: #111827;
  font-size: 12px;
}

.radial-pass-details small {
  display: block;
  color: #34404c;
  font-size: 11px;
}

.stage-load-metrics {
  display: grid;
  gap: 4px;
  padding: 9px 10px;
  border: 1px solid #d8e6f3;
  border-radius: 7px;
  background: #f8fbff;
}

.stage-load-metrics span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.stage-load-metrics strong {
  color: #111827;
  font-size: 14px;
  overflow-wrap: anywhere;
}

.stage-load-metrics small {
  color: #34404c;
  font-size: 12px;
}

.candidate-body {
  padding: 14px 16px 16px;
  display: grid;
  gap: 12px;
}

.reason-list,
.warning-list,
.variant-list,
.insert-list,
.reject-list ul {
  margin: 0;
  padding-left: 1.15rem;
}

.reason-list li,
.warning-list li,
.variant-list li,
.insert-list li,
.reject-list li {
  margin: 4px 0;
  line-height: 1.55;
}

.candidate-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}

.mini-heading {
  margin: 0 0 6px;
  color: #34404c;
  font-size: 13px;
  font-weight: 800;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.link-button {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 7px 12px;
  border: 1px solid #c7d0da;
  border-radius: 6px;
  color: #243549;
  background: #ffffff;
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  line-height: 1.25;
}

.pdf-button {
  border-color: var(--brand);
  color: #ffffff;
  background: var(--brand);
}

.pdf-button:hover {
  background: #b9151b;
  border-color: #b9151b;
}

.pdf-button:disabled {
  cursor: progress;
  opacity: 0.72;
}

.detail-toggle {
  border: 0;
  background: transparent;
  color: var(--brand);
  font-weight: 800;
  padding: 7px 0;
}

.detail-panel {
  display: none;
  padding: 0 16px 16px;
}

.candidate-card.is-open .detail-panel {
  display: block;
}

.detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.detail-table th,
.detail-table td {
  padding: 8px 9px;
  border: 1px solid var(--soft-line);
  text-align: left;
  vertical-align: top;
}

.detail-table th {
  width: 38%;
  background: #f8fafc;
  color: #34404c;
}

.reject-details {
  margin: 0 22px 22px;
  border: 1px solid var(--soft-line);
  border-radius: 8px;
  background: #fbfcfd;
}

.reject-details summary {
  padding: 12px 14px;
  font-weight: 800;
}

.reject-list {
  padding: 0 14px 14px;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 980px) {
  .app-main {
    grid-template-columns: 1fr;
  }

  .input-panel,
  .results-panel {
    max-height: none;
    overflow: visible;
  }

  .input-panel {
    position: static;
  }

  .tool-form,
  .results-scroll {
    overflow: visible;
  }
}

@media (max-width: 680px) {
  .app-header::before {
    inset: 0;
    background: url("images/01_TungForceRec_Helical_m.jpg") 45% 62% / cover no-repeat;
  }

  .app-header::after {
    background:
      linear-gradient(180deg, rgba(8, 11, 15, 0.86) 0%, rgba(8, 11, 15, 0.64) 56%, rgba(8, 11, 15, 0.26) 100%),
      linear-gradient(180deg, rgba(245, 246, 248, 0) 80%, rgba(245, 246, 248, 0.45) 100%);
  }

  .header-inner,
  .app-main {
    width: min(100% - 20px, 1180px);
  }

  .header-inner {
    min-height: 260px;
    padding: 18px 0 28px;
    gap: 24px;
  }

  .hero-logo {
    width: 154px;
  }

  .header-top {
    display: grid;
    gap: 16px;
  }

  .app-controls {
    justify-content: flex-start;
  }

  .control-group {
    justify-items: start;
  }

  .hero-copy {
    max-width: 100%;
  }

  .header-copy {
    font-size: 14px;
  }

  .field-grid.two,
  .strategy-group,
  .mode-group,
  .summary-grid,
  .spec-grid,
  .stage-load-grid,
  .stage-param,
  .candidate-columns {
    grid-template-columns: 1fr;
  }

  .candidate-top {
    grid-template-columns: 1fr;
  }

  .product-image,
  .rank {
    grid-column: auto;
    grid-row: auto;
    text-align: left;
  }

  .product-image {
    width: min(180px, 100%);
    height: 96px;
  }
}
