/* ===== リセット・変数 ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --indigo-50:  #EEF2FF;
  --indigo-100: #E0E7FF;
  --indigo-400: #818CF8;
  --indigo-500: #6366F1;
  --indigo-600: #4F46E5;
  --indigo-700: #4338CA;
  --slate-50:   #F8FAFC;
  --slate-100:  #F1F5F9;
  --slate-200:  #E2E8F0;
  --slate-300:  #CBD5E1;
  --slate-400:  #94A3B8;
  --slate-500:  #64748B;
  --slate-600:  #475569;
  --slate-700:  #334155;
  --slate-800:  #1E293B;
  --slate-900:  #0F172A;
  --red-50:     #FFF1F2;
  --red-200:    #FECDD3;
  --red-500:    #EF4444;
  --green-50:   #F0FDF4;
  --green-200:  #BBF7D0;
  --green-600:  #16A34A;
  --white:      #FFFFFF;
  --radius-sm:  6px;
  --radius:     10px;
  --radius-lg:  14px;
}

body {
  font-family: 'Inter', 'Helvetica Neue', Arial, 'Hiragino Sans', sans-serif;
  background: var(--slate-100);
  color: var(--slate-800);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ===== ヘッダー ===== */
.site-header {
  background: linear-gradient(135deg, var(--slate-900) 0%, #1E1B4B 50%, var(--indigo-700) 100%);
  color: #fff;
  padding: 2.5rem 1.5rem 2rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.site-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 80% at 20% 50%, rgba(99,102,241,.25) 0%, transparent 60%),
    radial-gradient(ellipse 50% 60% at 80% 30%, rgba(139,92,246,.2) 0%, transparent 60%);
  pointer-events: none;
}
.header-inner { position: relative; }
.header-badge {
  display: inline-block;
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: .25rem .85rem;
  color: rgba(255,255,255,.8);
  margin-bottom: .85rem;
  backdrop-filter: blur(8px);
}
.site-title {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -.04em;
  line-height: 1.15;
  margin-bottom: .5rem;
}
.site-title span { color: var(--indigo-400); }
.site-desc {
  font-size: .9rem;
  color: rgba(255,255,255,.65);
  max-width: 420px;
  margin: 0 auto;
}

/* ===== メイン ===== */
.main-content {
  max-width: 820px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* ===== プライバシー通知 ===== */
.privacy-notice {
  display: flex;
  align-items: center;
  gap: .6rem;
  background: var(--indigo-50);
  border: 1px solid var(--indigo-100);
  border-radius: var(--radius);
  padding: .7rem 1rem;
  font-size: .82rem;
  color: var(--indigo-600);
  font-weight: 500;
}
.privacy-icon { font-size: 1rem; flex-shrink: 0; }

/* ===== 対応外PDF注意書き ===== */
.unsupported-notice {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: var(--radius);
  padding: .6rem 1rem;
  font-size: .82rem;
  color: #78350f;
}
.unsupported-notice summary {
  cursor: pointer;
  font-weight: 600;
  list-style: none;
  display: flex;
  align-items: center;
  gap: .4rem;
  user-select: none;
}
.unsupported-notice summary::before {
  content: '⚠️';
  font-size: .9rem;
}
.unsupported-notice[open] summary { margin-bottom: .5rem; }
.unsupported-notice ul {
  margin: 0 0 .4rem 1.2rem;
  padding: 0;
  line-height: 1.8;
}
.unsupported-notice p { margin: 0; color: #92400e; }

/* ===== カード ===== */
.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  border: 1px solid var(--slate-200);
  box-shadow: 0 1px 3px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  overflow: hidden;
}
.card-header {
  padding: 1rem 1.25rem .75rem;
  border-bottom: 1px solid var(--slate-100);
  display: flex;
  align-items: center;
  gap: .6rem;
}
.card-header-icon {
  width: 28px; height: 28px;
  background: var(--indigo-50);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .9rem;
}
.card-title { font-size: .875rem; font-weight: 700; color: var(--slate-700); }
.card-hint  { font-size: .75rem; color: var(--slate-400); margin-left: auto; }
.card-body  { padding: 1rem 1.25rem; }

/* ===== 列ヘッダー ===== */
.row-list-header {
  display: grid;
  grid-template-columns: 2rem 1fr 11rem 2.25rem;
  gap: .5rem;
  padding: 0 .25rem .4rem;
}
.col-label {
  font-size: .68rem;
  font-weight: 700;
  color: var(--slate-400);
  text-transform: uppercase;
  letter-spacing: .07em;
}

/* ===== 行リスト ===== */
.row-list { list-style: none; display: flex; flex-direction: column; gap: .5rem; }

/* ===== 個別行 ===== */
.pdf-row {
  display: grid;
  grid-template-columns: 2rem 1fr 11rem 2.25rem;
  gap: .5rem;
  align-items: center;
  background: var(--white);
  border: 1.5px solid var(--slate-200);
  border-radius: var(--radius);
  padding: .6rem .5rem;
  transition: box-shadow .15s, border-color .15s;
  position: relative;
}
.pdf-row::before {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 0;
  background: var(--indigo-500);
  border-radius: 0 2px 2px 0;
  transition: height .15s;
}
.pdf-row:hover::before { height: 60%; }
.pdf-row:hover { border-color: var(--slate-300); box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.pdf-row--drag-over {
  border-color: var(--indigo-500);
  box-shadow: 0 0 0 3px rgba(99,102,241,.15);
}
.pdf-row--drag-over::before { height: 70%; }
.pdf-row--dragging { opacity: .3; }
.pdf-row--error { border-color: var(--red-200); background: var(--red-50); }
.pdf-row--error::before { background: var(--red-500); height: 60%; }

/* 行番号バッジ */
.row-num {
  position: absolute;
  top: -8px; left: 12px;
  font-size: .6rem;
  font-weight: 700;
  color: var(--slate-400);
  background: var(--white);
  border: 1px solid var(--slate-200);
  border-radius: 99px;
  padding: .05rem .4rem;
  letter-spacing: .04em;
  line-height: 1.6;
}

/* ドラッグハンドル */
.row-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--slate-300);
  font-size: 1.1rem;
  cursor: grab;
  user-select: none;
  border-radius: var(--radius-sm);
  height: 2.25rem;
  transition: color .12s, background .12s;
}
.row-handle:hover { color: var(--slate-500); background: var(--slate-100); }
.row-handle:active { cursor: grabbing; }

/* ファイルゾーン */
.row-file-zone {
  border: 1.5px dashed var(--slate-300);
  border-radius: var(--radius-sm);
  padding: .5rem .75rem;
  font-size: .82rem;
  color: var(--slate-400);
  height: 2.4rem;
  display: flex;
  align-items: center;
  gap: .45rem;
  cursor: pointer;
  transition: border-color .15s, background .15s, color .15s;
  overflow: hidden;
}
.row-file-zone:hover {
  border-color: var(--indigo-400);
  background: var(--indigo-50);
  color: var(--indigo-600);
}
.row-file-zone--loaded {
  border-style: solid;
  border-color: var(--slate-200);
  background: var(--slate-50);
  color: var(--slate-700);
  cursor: default;
}
.row-file-zone--loaded:hover {
  border-color: var(--slate-200);
  background: var(--slate-50);
  color: var(--slate-700);
}
.row-file-zone--active {
  border-color: var(--indigo-500);
  background: var(--indigo-50);
  color: var(--indigo-600);
}
.row-file-zone__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-icon { font-size: .95rem; flex-shrink: 0; opacity: .75; }
.file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  font-weight: 600;
  font-size: .82rem;
  color: var(--slate-700);
}
.file-pages {
  font-size: .7rem;
  color: var(--slate-400);
  white-space: nowrap;
  flex-shrink: 0;
  background: var(--slate-200);
  padding: .1rem .4rem;
  border-radius: 99px;
  font-weight: 500;
}
.row-file-input { display: none; }

/* ページ指定入力 */
.row-spec-input {
  width: 100%;
  height: 2.4rem;
  padding: 0 .7rem;
  border: 1.5px solid var(--slate-200);
  border-radius: var(--radius-sm);
  font-size: .82rem;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  color: var(--slate-700);
  background: var(--slate-50);
  transition: border-color .15s, box-shadow .15s;
}
.row-spec-input:focus {
  outline: none;
  border-color: var(--indigo-500);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
  background: var(--white);
}
.row-spec-input::placeholder { color: var(--slate-300); }
.row-spec-input:disabled { opacity: .4; cursor: not-allowed; }
.row-spec-input--error {
  border-color: var(--red-500);
  background: var(--red-50);
  color: var(--red-500);
}

/* 削除ボタン */
.row-remove-btn {
  width: 2.1rem; height: 2.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--slate-300);
  font-size: 1rem;
  transition: background .12s, color .12s;
}
.row-remove-btn:hover { background: var(--red-50); color: var(--red-500); }

/* ===== コントロールバー ===== */
.control-bar {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
}
.control-bar--right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: .75rem;
}
.file-count-label {
  font-size: .8rem;
  color: var(--slate-400);
  font-weight: 500;
  white-space: nowrap;
}

/* ===== ボタン ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .6rem 1.25rem;
  border-radius: var(--radius);
  border: none;
  font-size: .875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn--primary {
  background: linear-gradient(135deg, var(--indigo-500), var(--indigo-700));
  color: #fff;
  box-shadow: 0 2px 6px rgba(99,102,241,.4), 0 1px 2px rgba(0,0,0,.1);
}
.btn--primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--indigo-600), var(--indigo-700));
  box-shadow: 0 4px 12px rgba(99,102,241,.45), 0 1px 3px rgba(0,0,0,.12);
  transform: translateY(-1px);
}
.btn--primary:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; transform: none; }
.btn--ghost {
  background: var(--white);
  color: var(--slate-600);
  border: 1.5px solid var(--slate-200);
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.btn--ghost:hover:not(:disabled) {
  border-color: var(--slate-300);
  background: var(--slate-50);
  color: var(--slate-700);
}
.btn--ghost:disabled { opacity: .4; cursor: not-allowed; }
.btn--danger-ghost {
  background: var(--white);
  color: var(--red-500);
  border: 1.5px solid var(--red-200);
  box-shadow: 0 1px 2px rgba(0,0,0,.04);
}
.btn--danger-ghost:hover:not(:disabled) {
  border-color: var(--red-500);
  background: var(--red-50);
}
.btn--danger-ghost:disabled { opacity: .4; cursor: not-allowed; }

/* ===== ローディング ===== */
.loading-area {
  display: flex;
  align-items: center;
  gap: .75rem;
  font-size: .875rem;
  color: var(--slate-500);
  padding: .5rem 0;
}
.loading-area[hidden] { display: none; }
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--slate-200);
  border-top-color: var(--indigo-500);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== ステータスメッセージ ===== */
.status-msg {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  font-size: .85rem;
  font-weight: 500;
  min-height: 1.25rem;
}
.status-msg:empty { display: none; }
.status-msg--error {
  background: var(--red-50);
  color: var(--red-500);
  border: 1px solid var(--red-200);
  border-radius: var(--radius);
  padding: .75rem 1rem;
}
.status-msg--success {
  background: var(--green-50);
  color: var(--green-600);
  border: 1px solid var(--green-200);
  border-radius: var(--radius);
  padding: .75rem 1rem;
}

/* ===== アフィリエイト ===== */
.affiliate-section { margin-top: .5rem; }
.pr-label {
  font-size: .65rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--slate-400);
  margin-bottom: .75rem;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.pr-label::before, .pr-label::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--slate-200);
}
.affiliate-cards { display: flex; flex-direction: column; gap: .75rem; }
.affiliate-card {
  border: 1.5px solid var(--slate-200);
  border-radius: var(--radius);
  padding: .875rem 1rem;
  text-decoration: none;
  color: var(--slate-700);
  font-size: .85rem;
  transition: all .15s;
  display: block;
}
.affiliate-card:hover {
  border-color: var(--indigo-400);
  box-shadow: 0 4px 12px rgba(99,102,241,.12);
  transform: translateY(-1px);
}
.affiliate-card__title { font-weight: 700; display: block; margin-bottom: .2rem; font-size: .875rem; }
.affiliate-card__desc  { color: var(--slate-400); font-size: .75rem; line-height: 1.4; }

/* ===== フッター ===== */
.site-footer {
  text-align: center;
  padding: 2rem 1rem;
  font-size: .78rem;
  color: var(--slate-400);
}

/* ===== レスポンシブ（タブレット以上） ===== */
@media (min-width: 768px) {
  .site-header { padding: 3rem 1.5rem 2.5rem; }
  .site-title   { font-size: 2.25rem; }
  .main-content { padding: 1.75rem 1.5rem 3rem; }
  .row-list-header,
  .pdf-row { grid-template-columns: 2rem 1fr 14rem 2.25rem; }
  .affiliate-cards { flex-direction: row; }
  .affiliate-card { flex: 1; min-width: 0; }
}

@media (min-width: 1280px) {
  .main-content { padding: 2rem 0; }
}
