:root {
  color-scheme: light;
  --page-bg: #eef2f7;
  --panel-bg: #ffffff;
  --panel-soft: #f8fafc;
  --text-main: #111827;
  --text-secondary: #64748b;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-soft: #eff6ff;
  --warning: #ef4444;
  --border: #dbe3ef;
  --shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text-main);
  background: linear-gradient(180deg, #f7f9fc 0%, #edf2f7 100%);
}

/* Phase 1.17.1 vertical scrolling fix:
 * 原旧单期规则 height:100vh + overflow:hidden 会完全截断双期 dp-root 内超过视口高度的内容，
 * 导致 participant 无法滚动访问底部商品。改为 min-height 允许自然撑开、overflow-y:auto 允许
 * 纵向滚动、overflow-x:hidden 保留横向溢出保护（避免横向滚动条，符合§二-10条）。
 * 本规则仅作用于 candidate 双期页面，不影响根目录 frozen baseline。
 */
body[data-page="experiment"] {
  min-height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  border: none;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.page-tag,
.nutrition-dialog-tag {
  display: inline-block;
  margin: 0 0 8px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.page-description {
  margin: 0;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.5;
}

.screen-warning {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(238, 242, 247, 0.96);
}

.screen-warning-card,
.category-section,
.order-summary-panel,
.nutrition-dialog,
.debug-panel,
.admin-card {
  background: var(--panel-bg);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.screen-warning-card {
  width: min(560px, 100%);
  padding: 32px;
  text-align: center;
}

.screen-warning-card h1 {
  margin: 0 0 10px;
  font-size: 30px;
  line-height: 1.3;
}

.app-shell {
  width: min(1200px, calc(100vw - 24px));
  height: min(744px, calc(100vh - 16px));
  margin: 8px auto;
  padding: 14px 16px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.7);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.12);
  backdrop-filter: blur(14px);
}

.app-shell.is-debug-mode {
  width: min(900px, calc(100vw - 356px));
  margin: 8px 340px 8px auto;
}

.page-header {
  height: 64px;
  margin-bottom: 10px;
}

.page-header h1 {
  margin: 0 0 8px;
  font-size: 26px;
  line-height: 1.2;
}

.page-layout {
  height: calc(100% - 74px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 272px;
  gap: 12px;
}

.menu-sections {
  height: 100%;
  display: grid;
  grid-template-rows: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.category-section {
  min-height: 0;
  padding: 10px 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.category-title-wrap h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.35;
}

.none-option-button,
.nutrition-trigger-line,
.secondary-button,
.outside-option-button,
.danger-button {
  border: 1px solid var(--border);
  background: var(--panel-soft);
  color: #334155;
}

.none-option-button {
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.none-option-button.is-active,
.outside-option-button.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.product-list {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.product-card {
  position: relative;
  min-height: 0;
  height: 100%;
  padding: 8px 10px 8px 8px;
  border: 2px solid transparent;
  border-radius: 16px;
  background: var(--panel-bg);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.05);
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 8px;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.product-card:hover {
  transform: translateY(-1px);
}

.product-card.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.product-card-clickable {
  cursor: pointer;
}

.product-image {
  width: 64px;
  height: 64px;
  border-radius: 14px;
  object-fit: cover;
  display: block;
  background: #e5e7eb;
}

.product-content {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  justify-content: space-between;
}

.product-line {
  margin: 0;
  min-width: 0;
  color: var(--text-main);
  font-size: 12px;
  line-height: 1.3;
}

.product-name-line {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.25;
}

.product-line-label {
  color: var(--text-secondary);
}

.product-line-value {
  color: var(--text-main);
}

.product-name-line {
  display: -webkit-box;
  line-clamp: 2;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-meta-line {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.product-empty-line {
  visibility: hidden;
}

.nutrition-trigger-line {
  width: 100%;
  min-width: 0;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--accent-strong);
  text-align: left;
  font-size: 12px;
  line-height: 1.3;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nutrition-trigger-line .product-line-value {
  color: var(--accent-strong);
}

.nutrition-trigger-tip {
  color: var(--text-secondary);
  font-size: 11px;
  text-decoration: none;
}

.product-status {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #64748b;
  font-size: 13px;
  font-weight: 700;
}

.product-status.is-selected {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

.order-summary-panel {
  height: 100%;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
}

.summary-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.summary-text h2,
.summary-text p,
.summary-price span,
.summary-price strong,
.summary-item span,
.summary-item strong,
.nutrition-dialog-body p,
.completion-card h2,
.completion-card p {
  margin: 0;
}

.summary-text h2 {
  margin-bottom: 4px;
  font-size: 18px;
}

.summary-text p {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.45;
}

.summary-price {
  text-align: right;
}

.summary-price span {
  font-size: 12px;
  color: var(--text-secondary);
}

.summary-price strong {
  display: block;
  margin-top: 4px;
  color: var(--warning);
  font-size: 18px;
}

.summary-list {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.summary-item {
  padding: 9px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-soft);
}

.summary-item span {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
  color: var(--text-secondary);
}

.summary-item strong {
  font-size: 13px;
  line-height: 1.4;
}

.submit-hint {
  margin: 0 0 10px;
  padding: 8px 10px;
  border-radius: 12px;
  background: #fff7ed;
  color: #c2410c;
  font-size: 11px;
  line-height: 1.5;
}

.summary-actions {
  margin-top: auto;
  display: grid;
  gap: 8px;
}

.primary-button,
.secondary-button,
.outside-option-button,
.danger-button,
.modal-close-button {
  width: 100%;
  padding: 9px 12px;
  border-radius: 12px;
  font-size: 12.5px;
  font-weight: 600;
}

.primary-button {
  background: var(--accent);
  color: #ffffff;
}

.secondary-button {
  background: #eef2ff;
  color: #3730a3;
}

.outside-option-button {
  background: var(--panel-soft);
  color: #334155;
}

.danger-button {
  background: #fef2f2;
  color: #b91c1c;
}

.primary-button:disabled,
.secondary-button:disabled,
.danger-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.debug-panel {
  position: fixed;
  top: 8px;
  right: 8px;
  z-index: 22;
  width: 320px;
  max-height: calc(100vh - 16px);
  padding: 14px;
  overflow: auto;
}

.debug-panel h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.debug-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 12px;
  margin-bottom: 12px;
}

.participant-label {
  display: block;
  margin-bottom: 4px;
  color: var(--text-secondary);
  font-size: 12px;
}

.debug-actions {
  display: grid;
  gap: 8px;
}

.debug-actions .secondary-button {
  text-align: left;
}

.nutrition-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.42);
}

.nutrition-dialog {
  width: min(360px, 100%);
  padding: 20px;
}

.nutrition-dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.nutrition-dialog-header h2 {
  margin: 0;
  font-size: 22px;
}

.modal-close-button {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  background: #f3f4f6;
  color: var(--text-main);
  font-size: 22px;
  line-height: 1;
}

.nutrition-dialog-body {
  display: grid;
  gap: 10px;
  padding: 14px;
  border-radius: 16px;
  background: var(--panel-soft);
}

.nutrition-dialog-body p {
  font-size: 15px;
  line-height: 1.5;
}

.nutrition-dialog-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.unsupported-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.completion-card {
  grid-column: 1 / -1;
  width: 100%;
  height: 100%;
  padding: 24px;
  border-radius: 20px;
  background: var(--panel-bg);
  box-shadow: var(--shadow);
}

.completion-card h2 {
  margin-bottom: 8px;
  font-size: 24px;
}

.completion-card p {
  margin-bottom: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.completion-json {
  height: calc(100% - 90px);
  padding: 14px;
  border-radius: 16px;
  background: #111827;
  color: #f9fafb;
  overflow: auto;
  font-size: 12px;
  line-height: 1.6;
}

.admin-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 20px auto 28px;
}

.admin-header {
  margin-bottom: 18px;
}

.admin-header h1 {
  margin: 0 0 8px;
  font-size: 30px;
}

.admin-layout {
  display: grid;
  gap: 16px;
}

.admin-card {
  padding: 20px;
}

.admin-card h2 {
  margin: 0 0 14px;
  font-size: 20px;
}

.admin-history-status {
  margin: 0 0 14px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.admin-form-grid,
.admin-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.admin-field {
  display: grid;
  gap: 6px;
}

.admin-field span,
.admin-summary-grid span {
  color: var(--text-secondary);
  font-size: 12px;
}

.admin-field input,
.admin-field select {
  width: 100%;
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #ffffff;
}

.admin-actions {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.admin-summary-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.admin-summary-grid div {
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--panel-soft);
}

.admin-summary-grid strong {
  display: block;
  margin-top: 6px;
  font-size: 15px;
}

.admin-note-list {
  display: grid;
  gap: 10px;
}

.admin-note-list p {
  margin: 0;
  color: var(--text-secondary);
  line-height: 1.6;
}

@media (max-width: 1320px) {
  .app-shell.is-debug-mode {
    width: min(864px, calc(100vw - 340px));
    margin-right: 324px;
  }

  .debug-panel {
    width: 304px;
  }
}
