/* 文庫屋大関 発注ツール — 共通UI */
:root {
  --primary: #B1063A;
  --primary-hover: #8e052e;
  --primary-light: rgba(177, 6, 58, 0.06);
  --primary-border: rgba(177, 6, 58, 0.2);
  --white: #ffffff;
  --bg: #f7f7f8;
  --text: #1c1c1e;
  --text-muted: #6e6e73;
  --border: #e5e5ea;
  --border-light: #f0f0f2;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 12px rgba(0, 0, 0, 0.04);
  --radius: 10px;
  --radius-sm: 6px;
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.65;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ── ヘッダー ── */
.app-header {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.app-header-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 56px;
}

.app-logo {
  text-decoration: none;
  color: var(--primary);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.app-logo span {
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 8px;
  font-size: 13px;
}

.app-nav {
  display: flex;
  gap: 4px;
}

.nav-item {
  text-decoration: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
}

.nav-item:hover {
  color: var(--primary);
  background: var(--primary-light);
}

.nav-item.active {
  color: var(--primary);
  background: var(--primary-light);
  font-weight: 600;
}

/* ── メイン ── */
.app-main {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 24px 48px;
}

.app-main--narrow {
  max-width: 720px;
}

/* ── 更新履歴 ── */
.changelog-page-header {
  margin-bottom: 24px;
}

.changelog-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.changelog-title-row .page-title {
  margin: 0;
}

.btn-inline {
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
}

.changelog-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.changelog-card {
  margin: 0;
}

.changelog-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.changelog-card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.changelog-version {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
}

.changelog-date {
  font-weight: 600;
  color: var(--text);
  margin-left: 4px;
}

.changelog-body {
  font-size: 13px;
  line-height: 1.65;
  color: var(--text);
}

.changelog-body ul,
.changelog-body ol {
  margin: 0;
  padding-left: 1.25em;
}

.changelog-body li + li {
  margin-top: 4px;
}

.changelog-body p {
  margin: 0 0 6px;
}

.changelog-body p:last-child {
  margin-bottom: 0;
}

.changelog-no-content,
.changelog-empty-state {
  color: var(--text-muted);
  font-size: 13px;
}

.changelog-no-content {
  margin: 0;
  font-style: italic;
}

.changelog-empty-state {
  text-align: center;
  padding: 32px 16px;
}

.modal--changelog {
  max-width: 560px;
}

.modal--changelog .modal-close {
  float: right;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--radius-sm);
  font-size: 18px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal--changelog h3 {
  clear: both;
  padding-right: 40px;
}

.modal .field {
  margin-bottom: 16px;
}

.modal .field label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.modal--changelog textarea {
  width: 100%;
  min-height: 180px;
  padding: 10px 12px;
  font-size: 13px;
  font-family: inherit;
  line-height: 1.6;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  resize: vertical;
}

.modal--changelog textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.field-hint {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.page-header {
  margin-bottom: 24px;
}

.page-title {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.01em;
}

.page-desc {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
}

/* ── カード ── */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 16px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-light);
}

.card h2.no-border {
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 8px;
}

.card-divider {
  margin: 24px 0;
  border: none;
  border-top: 1px solid var(--border-light);
}

/* ── ステップ（発注画面） ── */
.step {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.step-num {
  background: var(--primary);
  color: var(--white);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.step h2 {
  margin: 0;
  border: none;
  padding: 0;
  font-size: 15px;
}

/* ── テーブル ── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  border-bottom: 1px solid var(--border-light);
  padding: 10px 12px;
  text-align: left;
}

th {
  background: var(--white);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  white-space: nowrap;
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}

td.num { text-align: right; font-variant-numeric: tabular-nums; }

th.item-col, td.item-col { text-align: left; min-width: 140px; }

.card table th:not(.item-col),
.card table td:not(.item-col) { text-align: center; }

td.na {
  color: #c7c7cc;
  background: #fafafa;
  text-align: center;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  max-height: 60vh;
}

.table-wrap table { margin: 0; }

.table-wrap th:first-child,
.table-wrap td:first-child { padding-left: 16px; }

.ec-row td { color: var(--text-muted); font-style: italic; }

/* ── 折りたたみテーブル ── */
.table-reveal {
  margin-top: 4px;
}

.table-reveal-viewport {
  position: relative;
  overflow: hidden;
  transition: max-height 0.35s ease;
}

.table-reveal .table-wrap {
  max-height: none;
  overflow: visible;
  border: 1px solid var(--border-light);
}

.table-reveal.is-expanded .table-reveal-viewport {
  overflow: visible;
}

.table-reveal-fade {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 80px;
  background: linear-gradient(to bottom, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.88) 55%, var(--white) 100%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.table-reveal.is-collapsed.has-more .table-reveal-fade {
  opacity: 1;
}

.table-reveal-btn {
  width: 100%;
  margin-top: 12px;
}

/* ── フォーム ── */
input[type="text"],
input[type="number"],
input[type="file"],
select {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--white);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

input.num-cell,
input.num-sm {
  width: 64px;
  padding: 8px 6px;
  text-align: center;
}

input.num-sm { width: 80px; }

.store-select { max-width: 360px; }

label.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 16px;
}

.form-row .field { flex: 1; min-width: 140px; }

.form-row label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

/* ── ボタン ── */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--primary);
  color: var(--white);
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}

button:hover, .btn:hover { background: var(--primary-hover); }

button:disabled {
  background: #d1d1d6;
  cursor: not-allowed;
}

button.secondary {
  background: var(--white);
  color: var(--primary);
  border: 1px solid var(--primary-border);
  box-shadow: none;
}

button.secondary:hover {
  background: var(--primary-light);
  border-color: var(--primary);
}

button.danger {
  background: var(--white);
  color: var(--primary);
  border: 1px solid var(--primary-border);
  padding: 6px 12px;
  font-size: 12px;
}

button.danger:hover {
  background: var(--primary);
  color: var(--white);
  border-color: var(--primary);
}

button.lg { padding: 12px 28px; font-size: 15px; }

.card-actions { margin-top: 20px; }

/* ── メッセージ ── */
.msg {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  margin: 12px 0;
  font-size: 13px;
  border: 1px solid transparent;
}

.msg.ok {
  background: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary-border);
}

.msg.err {
  background: #fff5f7;
  color: var(--primary);
  border-color: var(--primary-border);
}

.msg.warn {
  background: #fffbf0;
  color: #8a6d00;
  border-color: #f0e6c0;
}

.msg.info {
  background: var(--primary-light);
  color: var(--text);
  border-color: var(--primary-border);
}

.note {
  font-size: 12px;
  color: var(--text-muted);
  margin: 8px 0 0;
  line-height: 1.6;
}

.empty-hint {
  font-size: 12px;
  color: var(--text-muted);
}

.csv-instruction {
  font-size: 13px;
  color: var(--text);
  line-height: 1.7;
  margin: 0;
}

.dropzone-wrap--spaced {
  margin-top: 20px;
}

/* ── ヘルプツールチップ ── */
.heading-with-tip {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.step h2.heading-with-tip {
  border: none;
  padding: 0;
  margin: 0;
}

.help-tip {
  position: relative;
  display: inline-flex;
  flex-shrink: 0;
}

button.help-tip-btn {
  width: 20px;
  height: 20px;
  min-width: 20px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--white);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  cursor: help;
  line-height: 1;
  box-shadow: none;
}

button.help-tip-btn:hover {
  background: var(--primary-light);
  border-color: var(--primary-border);
  color: var(--primary);
}

.help-tip-panel {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  width: max-content;
  max-width: min(300px, 80vw);
  padding: 10px 12px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.55;
  color: var(--text);
  text-align: left;
  white-space: normal;
  z-index: 60;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.15s, visibility 0.15s;
}

.help-tip:hover .help-tip-panel,
.help-tip:focus-within .help-tip-panel {
  opacity: 1;
  visibility: visible;
}

.help-tip-panel strong { font-weight: 600; }

.summary {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 12px;
}

/* ── チェックボックス ── */
.chk {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
  font-size: 13px;
  cursor: pointer;
}

.chk input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* ── キーワードタグ ── */
.kw-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }

.kw-tag {
  background: var(--primary-light);
  border: 1px solid var(--primary-border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.kw-add {
  display: flex;
  gap: 10px;
  margin-top: 12px;
  align-items: stretch;
}

.kw-add input { flex: 1; }

/* ── マトリクスヘッダ ── */
.matrix-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.matrix-head h2 {
  margin: 0;
  flex: 1;
  min-width: 200px;
  border: none;
  padding: 0;
}

.matrix-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── トグルスイッチ ── */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 8px 0 12px;
  flex-wrap: wrap;
}

.toggle-label { font-size: 14px; font-weight: 600; }

.switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 26px;
  flex-shrink: 0;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: #d1d1d6;
  border-radius: 26px;
  transition: 0.2s;
}

.slider::before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background: var(--white);
  border-radius: 50%;
  transition: 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(22px); }

.pattern-table-wrap { max-height: 400px; overflow-y: auto; border: 1px solid var(--border-light); border-radius: var(--radius-sm); }

/* ── モーダル ── */
.modal-bg {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  z-index: 200;
  justify-content: center;
  align-items: center;
  padding: 16px;
}

.modal-bg.show { display: flex; }

.modal {
  background: var(--white);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 520px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

.modal h3 {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 700;
}

.modal-close {
  float: right;
  background: var(--white);
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 6px 14px;
  font-size: 12px;
}

.modal-close:hover { background: var(--bg); color: var(--text); }

.err-list {
  margin: 12px 0 0;
  padding-left: 20px;
  color: var(--primary);
  font-size: 13px;
}

.err-list li { margin-bottom: 6px; }

/* ── ローディング ── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.85);
  z-index: 300;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  gap: 14px;
}

.overlay.show { display: flex; }

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.overlay span { font-size: 13px; color: var(--text-muted); }

@keyframes spin { to { transform: rotate(360deg); } }

/* ── details ── */
details { margin-top: 12px; }

details summary {
  font-size: 13px;
  color: var(--primary);
  cursor: pointer;
  font-weight: 500;
}

details summary:hover { text-decoration: underline; }

/* ── CSVドロップゾーン ── */
.dropzone {
  position: relative;
  width: 100%;
  max-width: 240px;
  min-height: 168px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px 16px;
  text-align: center;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.dropzone.has-file {
  border-color: var(--primary-border);
  background: var(--primary-light);
}

.dropzone input[type="file"] {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

.dropzone-body { pointer-events: none; }

.dropzone-icon {
  width: 44px;
  height: 52px;
  margin: 0 auto 12px;
  border: 2px solid var(--primary-border);
  border-radius: 6px;
  background: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.05em;
}

.dropzone-icon::before { content: "CSV"; }

.dropzone-text {
  font-size: 13px;
  color: var(--text);
  margin: 0;
  line-height: 1.55;
}

.dropzone-text span {
  display: block;
  margin-top: 4px;
  color: var(--text-muted);
  font-size: 12px;
}

.dropzone-filename {
  font-size: 12px;
  color: var(--primary);
  font-weight: 600;
  margin: 10px 0 0;
  word-break: break-all;
  min-height: 1.2em;
}

.dropzone-wrap {
  display: flex;
  justify-content: center;
  width: 100%;
}

.dropzone-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: 12px;
  width: 100%;
}

.dropzone-row .dropzone { flex-shrink: 0; }

/* ── トースト ── */
#toast-container {
  position: fixed;
  bottom: 28px;
  left: 50%;
  right: auto;
  transform: translateX(-50%);
  z-index: 400;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 32px);
}

.toast {
  pointer-events: auto;
  background: var(--white);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
  animation: toast-in 0.28s ease;
  max-width: min(360px, calc(100vw - 48px));
}

.toast-err {
  border-left-color: var(--primary);
  background: #fff8f9;
}

.toast-info {
  border-left-color: var(--primary);
}

.toast-warn {
  border-left-color: #e8a317;
  background: #fffbf0;
}

.toast-ok {
  border-left-color: #2d8a4e;
  background: #f6fff9;
}

.toast-hide {
  animation: toast-out 0.22s ease forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
  to { opacity: 0; transform: translateY(10px); }
}

@media (max-width: 640px) {
  #toast-container {
    left: 50%;
    right: auto;
    bottom: 20px;
    width: calc(100vw - 32px);
    max-width: none;
    align-items: center;
  }
  .toast { max-width: none; width: 100%; text-align: center; }
}

/* ── レスポンシブ ── */
@media (max-width: 640px) {
  .app-header-inner { padding: 0 16px; flex-wrap: wrap; min-height: auto; padding-top: 12px; padding-bottom: 12px; }
  .app-main { padding: 20px 16px 40px; }
  .app-nav { width: 100%; overflow-x: auto; }
  .card { padding: 18px; }
}
