/* ページ基盤とデザイントークン */
body.barcode-page {
  color-scheme: light;
  --barcode-background: #f4f6f8;
  --barcode-surface: #ffffff;
  --barcode-surface-subtle: #f6f8fa;
  --barcode-border: #d0d7de;
  --barcode-text: #1f2328;
  --barcode-muted: #57606a;
  --barcode-accent: #0969da;
  --barcode-accent-hover: #0757b5;
  --barcode-success: #1a7f37;
  --barcode-warning: #9a6700;
  --barcode-danger: #cf222e;
  --barcode-notice-text: #0550ae;
  --barcode-notice-background: #ddf4ff;
  --barcode-notice-border: #b6e3ff;
  --barcode-interactive-border: #8c959f;
  --barcode-focus-ring: rgba(9, 105, 218, .28);
  --barcode-camera-background: #17202a;
  --barcode-camera-placeholder: #d0d7de;
  --barcode-canvas-background: #fff;
  --barcode-shadow: 0 14px 36px rgba(31, 35, 40, .08);
  --barcode-canvas-shadow: 0 8px 24px rgba(31, 35, 40, .14);
  --barcode-radius: 12px;
  --barcode-control-radius: 8px;
  --barcode-stage-radius: 10px;
  --barcode-stage-min-height: 280px;
  --barcode-camera-min-height: 320px;
  --barcode-reader-preview-max-height: 380px;
  --barcode-camera-video-max-height: 460px;
  --barcode-content-width: 1180px;
  margin: 0;
  min-height: 100vh;
  color: var(--barcode-text);
  background: var(--barcode-background);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.barcode-tool,
.barcode-tool * {
  box-sizing: border-box;
}

.barcode-tool {
  width: min(var(--barcode-content-width), calc(100% - 40px));
  margin-block: 0;
  margin-inline: auto;
  padding: 40px 0;
}

/* ヘッダーとパンくずリスト */
.barcode-header {
  margin-bottom: 18px;
}

.barcode-header h1 {
  margin: 0;
  font-size: clamp(1.7rem, 3vw, 2.2rem);
}

.barcode-header p {
  margin: 8px 0 0;
  color: var(--barcode-muted);
  line-height: 1.7;
}

.barcode-breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  color: var(--barcode-muted);
  font-size: .9rem;
}

.barcode-tool a {
  color: var(--barcode-accent);
  font-weight: 700;
  text-decoration: none;
}

.barcode-tool a:hover,
.barcode-tool a:focus-visible {
  text-decoration: underline;
}

/* パネルと主要レイアウト */
.barcode-notice,
.barcode-panel {
  margin-bottom: 16px;
  background: var(--barcode-surface);
  border: 1px solid var(--barcode-border);
  border-radius: var(--barcode-radius);
  box-shadow: var(--barcode-shadow);
}

.barcode-notice {
  padding: 12px 14px;
  color: var(--barcode-notice-text);
  background: var(--barcode-notice-background);
  border-color: var(--barcode-notice-border);
  line-height: 1.65;
}

.barcode-panel {
  padding: 18px;
}

.barcode-panel h2,
.barcode-panel h3 {
  margin: 0 0 14px;
}

.barcode-panel h2 {
  font-size: 1.1rem;
}

.barcode-panel h3 {
  font-size: 1rem;
}

.barcode-main-grid,
.barcode-reader-grid,
.barcode-camera-grid,
.barcode-form-stack,
.barcode-field,
.barcode-settings-grid,
.barcode-summary {
  display: grid;
}

.barcode-main-grid {
  grid-template-columns: minmax(330px, .85fr) minmax(420px, 1.15fr);
  gap: 16px;
}

.barcode-reader-grid,
.barcode-camera-grid {
  grid-template-columns: minmax(320px, .9fr) minmax(380px, 1.1fr);
  gap: 16px;
}

.barcode-form-stack,
.barcode-reader-output {
  display: grid;
  align-content: start;
  gap: 14px;
}

.barcode-field {
  gap: 6px;
}

.barcode-field label {
  color: var(--barcode-muted);
  font-weight: 700;
}

.barcode-settings-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

/* フォームコントロール共通 */
.barcode-tool input,
.barcode-tool select,
.barcode-tool button {
  min-height: 40px;
  color: var(--barcode-text);
  background: var(--barcode-surface);
  border: 1px solid var(--barcode-border);
  border-radius: var(--barcode-control-radius);
  font: inherit;
}

.barcode-tool input,
.barcode-tool select {
  width: 100%;
  padding: 7px 10px;
}

.barcode-tool input[type="color"] {
  padding: 4px;
  cursor: pointer;
}

.barcode-tool input[type="checkbox"] {
  width: 17px;
  min-height: 17px;
  margin: 0;
  padding: 0;
  accent-color: var(--barcode-accent);
}

.barcode-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  font-weight: 650;
}

/* ボタンと操作状態 */
.barcode-tool button {
  padding: 7px 14px;
  background: var(--barcode-surface-subtle);
  font-weight: 700;
  cursor: pointer;
}

.barcode-tool button:hover:not(:disabled) {
  border-color: var(--barcode-interactive-border);
}

.barcode-tool button.barcode-button-primary {
  color: #fff;
  background: var(--barcode-accent);
  border-color: var(--barcode-accent);
}

.barcode-tool button.barcode-button-primary:hover:not(:disabled) {
  background: var(--barcode-accent-hover);
}

.barcode-tool button.barcode-button-danger {
  color: var(--barcode-danger);
}

.barcode-tool button:disabled {
  cursor: not-allowed;
  opacity: .5;
}

.barcode-tool input:focus-visible,
.barcode-tool select:focus-visible,
.barcode-tool button:focus-visible,
.barcode-drop-zone:focus-visible {
  outline: 3px solid var(--barcode-focus-ring);
  outline-offset: 2px;
}

/* 操作列と状態メッセージ */
.barcode-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.barcode-hint,
.barcode-message {
  margin: 0;
  color: var(--barcode-muted);
  font-size: .86rem;
  line-height: 1.55;
}

.barcode-message {
  min-height: 22px;
}

.barcode-message--success {
  color: var(--barcode-success);
}

.barcode-message--warning {
  color: var(--barcode-warning);
}

.barcode-message--error {
  color: var(--barcode-danger);
}

/* 生成結果 */
.barcode-preview-panel {
  display: flex;
  flex-direction: column;
}

.barcode-media-stage {
  display: grid;
  place-items: center;
  overflow: auto;
  min-height: var(--barcode-stage-min-height);
  padding: 18px;
  background: var(--barcode-surface-subtle);
  border: 1px solid var(--barcode-border);
  border-radius: var(--barcode-stage-radius);
}

.barcode-canvas {
  display: block;
  max-width: 100%;
  height: auto;
  background: var(--barcode-canvas-background);
  box-shadow: var(--barcode-canvas-shadow);
}

.barcode-empty {
  max-width: 330px;
  margin: 0;
  color: var(--barcode-muted);
  line-height: 1.7;
  text-align: center;
}

.barcode-summary {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0;
}

.barcode-summary div {
  min-width: 0;
  padding: 9px 10px;
  background: var(--barcode-surface-subtle);
  border: 1px solid var(--barcode-border);
  border-radius: var(--barcode-control-radius);
}

.barcode-summary dt {
  color: var(--barcode-muted);
  font-size: .76rem;
}

.barcode-summary dd {
  margin: 4px 0 0;
  font-weight: 700;
  overflow-wrap: anywhere;
}

/* 画像読取 */
.barcode-drop-zone {
  display: grid;
  place-items: center;
  overflow: hidden;
  min-height: var(--barcode-stage-min-height);
  padding: 18px;
  color: var(--barcode-muted);
  background: var(--barcode-surface-subtle);
  border: 2px dashed var(--barcode-interactive-border);
  border-radius: var(--barcode-stage-radius);
  cursor: pointer;
  text-align: center;
}

.barcode-drop-zone strong {
  display: block;
  margin-bottom: 7px;
  color: var(--barcode-text);
}

.barcode-drop-zone--dragging {
  color: var(--barcode-accent);
  background: var(--barcode-notice-background);
  border-color: var(--barcode-accent);
}

.barcode-reader-preview {
  display: block;
  max-width: 100%;
  max-height: var(--barcode-reader-preview-max-height);
  object-fit: contain;
}

.barcode-result-box {
  min-height: 190px;
  padding: 14px;
  background: var(--barcode-surface-subtle);
  border: 1px solid var(--barcode-border);
  border-radius: var(--barcode-stage-radius);
}

.barcode-results-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-inline-start: 26px;
}

.barcode-results-list li {
  padding: 9px;
  background: var(--barcode-surface);
  border: 1px solid var(--barcode-border);
  border-radius: var(--barcode-control-radius);
}

.barcode-result-format {
  display: block;
  margin-bottom: 4px;
  color: var(--barcode-muted);
  font-size: .78rem;
  font-weight: 700;
}

.barcode-result-value {
  font-family: "Cascadia Code", Consolas, monospace;
  overflow-wrap: anywhere;
  user-select: all;
}

/* カメラ読取 */
.barcode-camera-stage {
  min-height: var(--barcode-camera-min-height);
  padding: 0;
  background: var(--barcode-camera-background);
}

.barcode-camera-video {
  display: block;
  width: 100%;
  max-height: var(--barcode-camera-video-max-height);
  object-fit: contain;
}

.barcode-camera-stage .barcode-empty {
  color: var(--barcode-camera-placeholder);
}

.barcode-info-list {
  margin: 0;
  padding-inline-start: 22px;
  color: var(--barcode-muted);
  line-height: 1.75;
}

.barcode-tool [hidden] {
  display: none !important;
}

/* レスポンシブレイアウト */
@media (max-width: 860px) {
  .barcode-tool {
    width: min(100% - 24px, var(--barcode-content-width));
    padding: 24px 0;
  }

  .barcode-main-grid,
  .barcode-reader-grid,
  .barcode-camera-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .barcode-panel {
    padding: 14px;
  }

  .barcode-settings-grid,
  .barcode-summary {
    grid-template-columns: 1fr;
  }

  .barcode-actions button {
    flex: 1 1 140px;
  }
}
