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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  background: #f0f2f5;
  color: #1a1a1a;
  line-height: 1.6;
}

.app {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── カード ── */
.card {
  background: #fff;
  border-radius: 10px;
  padding: 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.card h1 { font-size: 20px; font-weight: 700; margin-bottom: 16px; color: #111; }
.card h2 { font-size: 16px; font-weight: 600; color: #111; }

.hidden { display: none !important; }

/* ── 入力エリア ── */
.input-row {
  display: flex;
  gap: 8px;
}
#number-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid #d0d5dd;
  border-radius: 8px;
  font-size: 15px;
  outline: none;
  transition: border-color .15s;
}
#number-input:focus { border-color: #2563eb; }

.hint { margin-top: 6px; color: #888; font-size: 12px; }

.error {
  margin-top: 10px;
  padding: 10px 14px;
  background: #fff1f0;
  border: 1px solid #ffa39e;
  border-radius: 6px;
  color: #cf1322;
  font-size: 13px;
}

/* ── ボタン ── */
.btn-primary {
  padding: 10px 20px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
.btn-primary:hover { background: #1d4ed8; }
.btn-primary:disabled { background: #93c5fd; cursor: not-allowed; }

.btn-secondary {
  padding: 8px 16px;
  background: #f3f4f6;
  color: #374151;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  transition: background .15s;
}
.btn-secondary:hover { background: #e5e7eb; }

.btn-copy {
  padding: 4px 10px;
  background: #f0f9ff;
  color: #0369a1;
  border: 1px solid #bae6fd;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
}
.btn-copy:hover { background: #e0f2fe; }
.btn-copy.copied { background: #f0fdf4; color: #16a34a; border-color: #bbf7d0; }

/* ── バッジ ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  vertical-align: middle;
  margin-left: 6px;
}
.badge-latest  { background: #dcfce7; color: #15803d; }
.badge-process { background: #eff6ff; color: #1d4ed8; }
.badge-seq     { background: #f3f4f6; color: #6b7280; }

/* ── 基本情報グリッド ── */
.info-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 0;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
}
.info-grid .ig-label {
  padding: 8px 12px;
  background: #f9fafb;
  color: #6b7280;
  font-size: 12px;
  font-weight: 500;
  border-bottom: 1px solid #e5e7eb;
}
.info-grid .ig-value {
  padding: 8px 12px;
  border-bottom: 1px solid #e5e7eb;
  word-break: break-all;
}
.info-grid .ig-label:last-of-type,
.info-grid .ig-value:last-of-type { border-bottom: none; }

/* ── 変更履歴 ── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}
.filter-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.filter-group label { color: #6b7280; font-size: 12px; }
.filter-btn {
  padding: 4px 12px;
  border: 1px solid #d1d5db;
  border-radius: 99px;
  background: #fff;
  color: #374151;
  font-size: 12px;
  cursor: pointer;
  transition: all .15s;
}
.filter-btn.active { background: #2563eb; color: #fff; border-color: #2563eb; }
.filter-btn:hover:not(.active) { background: #f3f4f6; }

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.history-item {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 12px 14px;
  transition: border-color .15s;
}
.history-item.is-latest { border-color: #86efac; background: #f0fdf4; }
.history-item.hidden-item { display: none; }

.history-item-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.history-item-body {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 4px 16px;
  font-size: 13px;
  color: #374151;
}
.history-item-body span { color: #9ca3af; font-size: 11px; margin-right: 4px; }

/* ── リネームブロック ── */
.template-editor { margin-bottom: 20px; }
.template-editor label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 6px;
}
#tmpl-editor {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid #d0d5dd;
  border-radius: 8px;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 13px;
  line-height: 1.7;
  resize: vertical;
  outline: none;
  transition: border-color .15s;
}
#tmpl-editor:focus { border-color: #2563eb; }
.tmpl-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  justify-content: flex-end;
}

.rename-group { margin-bottom: 40px; }
.rename-group-header {
  font-size: 12px;
  color: #9ca3af;
  font-family: monospace;
  margin-bottom: 8px;
  padding: 4px 8px;
  background: #f9fafb;
  border-radius: 4px;
}

/* 書類タイプ境界（ループ変わり目）*/
.rename-block { margin-bottom: 20px; }
.rename-block-label {
  font-size: 11px;
  font-weight: 600;
  color: #6b7280;
  margin-bottom: 4px;
  padding: 2px 6px;
  border-left: 3px solid #d1d5db;
}

/* 商号境界（大きめ区切り）*/
.rename-name-block { margin-bottom: 32px; }
.rename-name-label {
  font-size: 12px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 6px;
  padding: 4px 10px;
  background: #eff6ff;
  border-left: 3px solid #3b82f6;
  border-radius: 0 4px 4px 0;
}

.rename-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 10px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  margin-bottom: 3px;
  cursor: pointer;
  transition: background .12s, border-color .12s, transform .1s;
  user-select: none;
}
.rename-line:hover {
  background: #eff6ff;
  border-color: #93c5fd;
  transform: translateX(2px);
}
.rename-line.flash {
  background: #dcfce7;
  border-color: #86efac;
  transition: none;
}
.rename-line code {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 13px;
  word-break: break-all;
  pointer-events: none;
}

code {
  background: #f3f4f6;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 12px;
  font-family: "SF Mono", "Fira Code", monospace;
}

/* ── 共有URL行 ── */
.share-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 8px 12px;
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 8px;
  flex-wrap: wrap;
}
.share-label {
  font-size: 12px;
  font-weight: 600;
  color: #0369a1;
  white-space: nowrap;
}
.share-url-text {
  flex: 1;
  font-size: 12px;
  word-break: break-all;
  background: transparent;
  padding: 0;
  color: #0c4a6e;
}

/* ── レイアウト並び替えモーダル ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-box {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  width: 320px;
  box-shadow: 0 8px 32px rgba(0,0,0,.15);
}
.modal-box h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
}
.layout-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 20px;
}
.layout-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #f9fafb;
}
.layout-item-label { font-size: 14px; font-weight: 500; }
.layout-item-btns  { display: flex; gap: 4px; }
.layout-arrow {
  width: 28px;
  height: 28px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.layout-arrow:hover:not(:disabled) { background: #f3f4f6; }
.layout-arrow:disabled { opacity: .35; cursor: not-allowed; }
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ── 折りたたみ ── */
.rename-block-label.collapsible {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}
.rename-block-label.collapsible:hover { color: #2563eb; }
.block-toggle { font-size: 10px; color: #9ca3af; width: 12px; }
.rename-block-lines { display: flex; flex-direction: column; gap: 0; }
.rename-block-lines.collapsed { display: none; }

/* ── フロートナビ ── */
.float-nav {
  position: fixed;
  right: 16px;
  top: 50%;
  transform: translateY(-50%);
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 10px 0;
  box-shadow: 0 4px 16px rgba(0,0,0,.10);
  min-width: 140px;
  max-width: 200px;
  max-height: 80vh;
  overflow-y: auto;
  z-index: 50;
}
.fnav-section {
  padding: 5px 14px;
  font-size: 11px;
  font-weight: 600;
  color: #6b7280;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background .1s;
  letter-spacing: .02em;
}
.fnav-section:hover { background: #f3f4f6; color: #111; }
.fnav-top {
  font-size: 12px;
  font-weight: 700;
  color: #374151;
  padding: 8px 14px 6px;
  border-bottom: 1px solid #f3f4f6;
  margin-bottom: 2px;
}
.fnav-top:hover { background: #f9fafb; }
.fnav-sep {
  margin: 6px 14px;
  border-top: 1px solid #e5e7eb;
}
.fnav-name {
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 700;
  color: #1d4ed8;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background .1s;
}
.fnav-name:hover { background: #eff6ff; }
.fnav-child {
  padding: 4px 14px 4px 22px;
  font-size: 11px;
  color: #374151;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background .1s;
}
.fnav-child:hover { background: #f9fafb; color: #2563eb; }
.fnav-collapsed { color: #9ca3af; font-style: italic; }
.fnav-collapsed::before { content: "▶ "; font-size: 9px; }

@media (max-width: 1100px) {
  .float-nav { display: none; }
}
