:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-glow: rgba(37, 99, 235, 0.35);
  --success: #10b981;
  --success-light: #ecfdf5;
  --warning: #f59e0b;
  --error: #ef4444;
  --accent-purple: #8b5cf6;
  --accent-purple-light: #f5f3ff;
  --bg-main: #f1f5f9;
  --bg-card: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --border-focus: #93c5fd;
  --radius: 10px;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.07);
  --shadow-lg: 0 10px 25px -3px rgb(0 0 0 / 0.12), 0 4px 6px -4px rgb(0 0 0 / 0.08);
}

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

html {
  -webkit-text-size-adjust: 100%;
  box-sizing: border-box;
  overflow-x: hidden;
}

body {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.45;
  -webkit-tap-highlight-color: rgba(37, 99, 235, 0.15);
  -webkit-overflow-scrolling: touch;
}

.app-viewport {
  width: 100%;
  max-width: 1500px;
  margin: 0 auto;
  padding: 16px;
  padding-top: calc(env(safe-area-inset-top, 0px) + 20px);
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 120px);
  padding-left: calc(env(safe-area-inset-left, 0px) + 16px);
  padding-right: calc(env(safe-area-inset-right, 0px) + 16px);
  box-sizing: border-box;
}

/* ==========================================================
   アニメーション定義
   ========================================================== */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes scaleUp {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes pulseGlow {
  0% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.4); }
  70% { box-shadow: 0 0 0 8px rgba(37, 99, 235, 0); }
  100% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0); }
}

@keyframes pulseDemo {
  0%, 100% { transform: scale(1); box-shadow: 0 2px 8px rgba(139, 92, 246, 0.3); }
  50% { transform: scale(1.02); box-shadow: 0 4px 14px rgba(139, 92, 246, 0.45); }
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

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

.animate-fade-in { animation: fadeIn 0.3s ease-out forwards; }
.animate-fade-in-up { animation: fadeInUp 0.35s ease-out forwards; }
.animate-scale-up { animation: scaleUp 0.2s ease-out forwards; }
.pulse-glow { animation: pulseGlow 2.5s infinite; }
.pulse-animation { animation: pulseDemo 2s infinite ease-in-out; }

/* ==========================================================
   ヘッダー
   ========================================================== */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  background: linear-gradient(135deg, #2563eb, #3b82f6);
  color: #ffffff;
  padding: 7px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-header h1 {
  font-size: 16px;
  font-weight: 700;
  color: #0f172a;
}

.app-header .subtitle {
  font-size: 11px;
  color: var(--text-muted);
}

.security-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  background-color: var(--success-light);
  color: #065f46;
  padding: 5px 10px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid #a7f3d0;
}

.test-mode-toggle {
  background-color: #ffffff;
  border: 1px solid #cbd5e1;
  padding: 3px 8px;
  border-radius: 999px;
  transition: all 0.2s ease;
}

.test-mode-toggle:hover {
  border-color: var(--accent-purple);
  background-color: var(--accent-purple-light);
}

.demo-switch-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}

.demo-switch-label input { display: none; }

.demo-switch-slider {
  width: 28px;
  height: 16px;
  background-color: #94a3b8;
  border-radius: 16px;
  position: relative;
  transition: background-color 0.2s ease;
}

.demo-switch-slider::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  background-color: #ffffff;
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.demo-switch-label input:checked + .demo-switch-slider {
  background-color: var(--accent-purple);
}

.demo-switch-label input:checked + .demo-switch-slider::after {
  transform: translateX(12px);
}

.demo-switch-text {
  font-size: 11px;
  font-weight: 700;
  color: #334155;
}

.test-banner {
  background: linear-gradient(135deg, #ede9fe, #e0e7ff);
  border: 1px solid #c4b5fd;
  border-radius: 8px;
  padding: 8px 14px;
  margin-bottom: 10px;
  flex-shrink: 0;
  animation: slideDown 0.25s ease-out;
}

.test-banner-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.banner-title-box {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #4338ca;
}

.live-dot {
  width: 8px;
  height: 8px;
  background-color: #10b981;
  border-radius: 50%;
  display: inline-block;
}

.banner-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-demo-play {
  background: linear-gradient(135deg, #7c3aed, #6366f1);
  color: #ffffff;
  border: none;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 700;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

/* ==========================================================
   メインレイアウト（デフォルト: iPad縦向き・モバイル自然スクロール）
   ========================================================== */
.main-layout {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
}

.panel {
  background-color: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
}

.input-panel {
  padding: 10px;
}

.preview-panel {
  display: flex;
  flex-direction: column;
}

/* アコーディオン */
.accordion-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.accordion-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  background-color: #ffffff;
  overflow: hidden;
  transition: all 0.2s ease;
}

.accordion-item.open {
  border-color: #93c5fd;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.08);
}

.accordion-item.completed {
  border-color: #a7f3d0;
}

.accordion-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  background: #f8fafc;
  border: none;
  cursor: pointer;
  text-align: left;
  user-select: none;
}

.accordion-header:hover {
  background-color: #f1f5f9;
}

.accordion-item.open .accordion-header {
  background-color: #eff6ff;
  border-bottom: 1px solid #bfdbfe;
}

.acc-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.step-num {
  background-color: #94a3b8;
  color: #ffffff;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
}

.accordion-item.open .step-num {
  background-color: var(--primary);
}

.accordion-item.completed .step-num {
  background-color: var(--success);
}

.acc-title {
  font-size: 12px;
  font-weight: 700;
  color: #1e293b;
}

.acc-status-badge {
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
  background-color: #e2e8f0;
  color: #64748b;
}

.acc-status-badge.completed {
  background-color: var(--success-light);
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.acc-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.acc-check-icon {
  display: none;
  color: var(--success);
  font-size: 13px;
  font-weight: 800;
}

.accordion-item.completed .acc-check-icon {
  display: inline;
}

.acc-arrow {
  color: var(--text-muted);
  transition: transform 0.25s ease;
}

.accordion-item.open .acc-arrow {
  transform: rotate(180deg);
  color: var(--primary);
}

.accordion-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.accordion-item.open .accordion-body {
  max-height: 600px;
}

.accordion-content {
  padding: 10px 12px;
}

/* ドロップゾーン */
.drop-zone {
  border: 2px dashed #cbd5e1;
  border-radius: 8px;
  padding: 12px;
  text-align: center;
  cursor: pointer;
  background-color: #f8fafc;
  transition: all 0.2s ease;
}

.drop-zone:hover {
  border-color: var(--primary);
  background-color: var(--primary-light);
}

.drop-zone.has-file {
  border-style: solid;
  border-color: #93c5fd;
  background-color: #f0f9ff;
  padding: 8px;
}

.drop-zone-prompt {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--text-muted);
}

.drop-zone-prompt p {
  font-size: 12px;
  font-weight: 600;
  color: #334155;
}

.drop-zone-prompt .sub-text {
  font-size: 10px;
}

.hidden-file-input { display: none; }

.file-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background-color: #ffffff;
  border: 1px solid #bfdbfe;
  padding: 6px 10px;
  border-radius: 6px;
}

.file-badge .file-name {
  font-size: 11px;
  font-weight: 600;
  color: #1e293b;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 2px;
}

.btn-icon:hover { color: var(--error); }

/* オプションボックス */
.options-box {
  background-color: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sub-config-box {
  background-color: #ffffff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.field-label {
  font-size: 11px;
  font-weight: 600;
  color: #334155;
}

.date-input-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.input-date, .input-select, .input-text, .input-text-sm, .input-num {
  padding: 4px 7px;
  border: 1px solid #cbd5e1;
  border-radius: 5px;
  font-size: 11px;
  outline: none;
}

.input-text {
  font-family: monospace;
  font-weight: 600;
  color: var(--primary);
  width: 130px;
}

.input-text-sm {
  width: 120px;
  font-family: monospace;
}

.input-num {
  width: 40px;
  text-align: center;
}

.cell-index-inputs {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
}

.radio-group {
  display: flex;
  gap: 10px;
}

.radio-label {
  font-size: 11px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 3px;
  cursor: pointer;
}

.toggle-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.toggle-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
}

.toggle-item input { display: none; }

.toggle-slider {
  width: 28px;
  height: 16px;
  background-color: #cbd5e1;
  border-radius: 16px;
  position: relative;
  transition: background-color 0.2s;
  flex-shrink: 0;
  margin-top: 1px;
}

.toggle-slider::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  background-color: #ffffff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle-item input:checked + .toggle-slider {
  background-color: var(--primary);
}

.toggle-item input:checked + .toggle-slider::after {
  transform: translateX(12px);
}

.toggle-label {
  display: flex;
  flex-direction: column;
}

.toggle-label strong {
  font-size: 11px;
  color: #1e293b;
}

.toggle-label small {
  font-size: 10px;
  color: var(--text-muted);
}

/* ==========================================================
   プレビューパネル（右カラム）
   ========================================================== */
.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
  background-color: #f8fafc;
  flex-shrink: 0;
}

.preview-tabs {
  display: flex;
  gap: 4px;
}

.tab-btn {
  background: none;
  border: 1px solid transparent;
  padding: 5px 10px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.tab-btn:hover {
  background-color: #f1f5f9;
}

.tab-btn.active {
  background-color: #ffffff;
  color: var(--primary);
  border-color: var(--border);
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.range-control-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px;
  background-color: #f1f5f9;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  flex-shrink: 0;
}

.range-selector {
  display: flex;
  align-items: center;
  gap: 8px;
}

.range-title {
  font-weight: 700;
  color: #334155;
}

.range-inputs {
  display: flex;
  align-items: center;
  gap: 4px;
}

.range-actions {
  display: flex;
  gap: 4px;
}

.preview-body {
  position: relative;
  background-color: #e2e8f0;
  border-radius: 0 0 8px 8px;
}

.preview-scroll-area {
  padding: 14px;
}

/* ==========================================================
   1. Word完成プレビュー（A4用紙風リアルWord表示）
   ========================================================== */
.word-sheet-container {
  display: flex;
  justify-content: center;
  padding-bottom: 20px;
}

.word-sheet {
  background-color: #ffffff;
  width: 100%;
  max-width: 800px;
  min-height: 560px;
  padding: 32px 38px;
  border-radius: 4px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  position: relative;
}

.word-doc-header {
  border-bottom: 2px solid #0f172a;
  padding-bottom: 10px;
  margin-bottom: 16px;
}

.word-doc-title {
  font-size: 17px;
  font-weight: 800;
  text-align: center;
  color: #0f172a;
  margin-bottom: 4px;
  letter-spacing: 0.05em;
}

.word-doc-meta {
  font-size: 11px;
  text-align: right;
  color: #475569;
  font-weight: 500;
}

.word-table-wrapper {
  flex: 1;
  margin-bottom: 16px;
}

.word-table {
  width: 100%;
  border-collapse: collapse;
  border: 1px solid #94a3b8;
  font-size: 11.5px;
}

.word-table th, .word-table td {
  border: 1px solid #cbd5e1;
  padding: 9px 11px;
  vertical-align: top;
}

.cell-header {
  background-color: #f1f5f9;
  font-weight: 700;
  color: #334155;
  text-align: left;
}

.cell-title { width: 25%; }
.cell-desc { width: 75%; }

.cell-label {
  background-color: #f8fafc;
  font-weight: 600;
  color: #475569;
}

.cell-content {
  background-color: #ffffff;
  line-height: 1.6;
  color: #1e293b;
}

.empty-cell-hint {
  padding: 20px;
  text-align: center;
  color: #94a3b8;
}

.hint-tag {
  display: inline-block;
  background-color: #eff6ff;
  color: var(--primary);
  font-family: monospace;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px dashed var(--primary);
  margin-bottom: 6px;
}

.word-sheet-p {
  margin-bottom: 5px;
  position: relative;
  font-family: "Meiryo", "Hiragino Kaku Gothic ProN", sans-serif;
  font-size: 11.5px;
}

.word-sheet-p.is-bullet {
  color: #0f172a;
}

.word-sheet-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px dashed #cbd5e1;
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: #94a3b8;
}

/* ==========================================================
   2. 元PDFビュアー & 範囲選択UI
   ========================================================== */
.pdf-selection-toolbar {
  background: #ffffff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 8px 14px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
  position: sticky;
  top: 0;
  z-index: 10;
}

.pdf-selection-info {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: #1e40af;
}

.pdf-selection-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-confirm-selection {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
  border: none;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.btn-confirm-selection:hover:not(:disabled) {
  background: linear-gradient(135deg, #059669, #047857);
  transform: translateY(-1px);
}

.btn-confirm-selection:disabled {
  background: #cbd5e1;
  color: #94a3b8;
  cursor: not-allowed;
  box-shadow: none;
}

.char-count-badge {
  background: rgba(255, 255, 255, 0.25);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 10px;
}

.pdf-paper-container {
  display: flex;
  justify-content: center;
  padding-bottom: 20px;
}

.pdf-paper {
  background-color: #ffffff;
  border-radius: 4px;
  position: relative;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  overflow: hidden;
}

.pdf-canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

.pdf-selectable-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  user-select: text;
  -webkit-user-select: text;
  background: transparent;
}

.pdf-selectable-content {
  width: 100%;
  height: 100%;
  padding: 40px;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Segoe UI", Roboto, "Helvetica Neue", Meiryo, sans-serif;
  font-size: 13px;
  line-height: 1.8;
  color: #1e293b;
  white-space: pre-wrap;
  cursor: text;
}

.pdf-selectable-content::selection {
  background-color: rgba(37, 99, 235, 0.35);
  color: #0f172a;
}

/* ==========================================================
   段落インデント解析リスト & スケルトン
   ========================================================== */
.formatted-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: #ffffff;
  padding: 12px;
  border-radius: 6px;
}

.preview-paragraph-item {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 3px 6px;
  border-radius: 4px;
  line-height: 1.5;
}

.preview-paragraph-item:hover { background-color: #f8fafc; }
.preview-paragraph-item.is-bullet { background-color: #f0fdf4; }

.p-number {
  font-size: 10px;
  font-weight: 700;
  color: #94a3b8;
  width: 22px;
}

.p-content-box { flex: 1; font-size: 12px; }

.bullet-tag {
  display: inline-block;
  background-color: #bbf7d0;
  color: #166534;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 3px;
  margin-right: 5px;
}

.empty-line-marker {
  color: #cbd5e1;
  font-style: italic;
  font-size: 10px;
}

.raw-textarea {
  width: 100%;
  height: 100%;
  border: none;
  outline: none;
  resize: none;
  font-family: inherit;
  font-size: 12px;
  line-height: 1.6;
  color: #334155;
  background: #ffffff;
  padding: 12px;
  border-radius: 6px;
}

.skeleton-container {
  height: 100%;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background-color: #ffffff;
}

.skeleton-status-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background-color: #eff6ff;
  border-radius: 6px;
  border: 1px solid #bfdbfe;
}

.skeleton-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #bfdbfe;
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.skeleton-status-text {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
}

.skeleton-paragraph {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.skeleton-paragraph.indent-1 { padding-left: 24px; }
.skeleton-line { height: 10px; border-radius: 4px; background: #e2e8f0; }

.shimmer {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite ease-in-out;
}

/* ==========================================================
   アクションバー
   ========================================================== */
.action-bar {
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background-color: #f8fafc;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.progress-container {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.progress-track {
  width: 100%;
  height: 5px;
  background-color: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #10b981);
  transition: width 0.3s ease;
}

.status-label { font-size: 11px; color: var(--text-muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.btn-primary {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.2);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #1d4ed8, #1e40af);
  transform: translateY(-1px);
}

.btn-primary:disabled {
  background: #cbd5e1;
  color: #94a3b8;
  cursor: not-allowed;
  opacity: 0.8;
}

.btn-secondary {
  background-color: #ffffff;
  color: #1e293b;
  border-color: #cbd5e1;
}

.btn-secondary:hover { background-color: #f8fafc; }
.btn-text { background: none; color: var(--primary); border: none; text-decoration: underline; }

.btn-xs { padding: 3px 6px; font-size: 11px; }
.btn-sm { padding: 5px 10px; font-size: 11px; }
.btn-lg { padding: 10px 16px; font-size: 13px; }
.badge { background-color: #e2e8f0; color: #475569; font-size: 10px; font-weight: 600; padding: 2px 6px; border-radius: 999px; }

/* トースト */
.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background-color: #1e293b;
  color: #ffffff;
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  font-size: 12px;
  font-weight: 600;
  opacity: 0;
  transform: translateY(16px);
  transition: all 0.25s ease;
  pointer-events: none;
  z-index: 1000;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: linear-gradient(135deg, #065f46, #047857); border: 1px solid #10b981; }
.toast.error { background: linear-gradient(135deg, #991b1b, #b91c1c); border: 1px solid #ef4444; }
.toast.warning { background: linear-gradient(135deg, #92400e, #b45309); border: 1px solid #f59e0b; }
.hidden { display: none !important; }

/* ==========================================================
   🤖 AI操作バー & クイックコマンド
   ========================================================== */
.btn-ai-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: linear-gradient(135deg, #8b5cf6, #6366f1);
  color: #ffffff;
  border: none;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(99, 102, 241, 0.25);
  transition: all 0.2s ease;
}

.btn-ai-toggle:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px rgba(99, 102, 241, 0.35);
}

.ai-command-bar {
  background: linear-gradient(90deg, #f5f3ff, #eef2ff);
  border-bottom: 1px solid #c7d2fe;
  padding: 6px 20px;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.ai-bar-inner {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 1400px;
  margin: 0 auto;
}

.ai-bar-left {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  color: #4338ca;
}

.ai-input-wrapper {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 280px;
}

.ai-input-text {
  flex: 1;
  padding: 4px 10px;
  border: 1px solid #a5b4fc;
  border-radius: 6px;
  font-size: 11px;
  outline: none;
  background: #ffffff;
}

.ai-input-text:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.ai-quick-chips {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.chip-label {
  font-size: 10px;
  color: #6366f1;
  font-weight: 600;
}

.ai-chip {
  background: #ffffff;
  border: 1px solid #c7d2fe;
  color: #4338ca;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.ai-chip:hover {
  background: #6366f1;
  color: #ffffff;
  border-color: #6366f1;
  transform: translateY(-1px);
}

.ai-api-badge {
  font-size: 10px;
  background: rgba(99, 102, 241, 0.1);
  color: #4338ca;
  padding: 2px 6px;
  border-radius: 4px;
}

.ai-api-badge code {
  font-family: monospace;
}

/* ==========================================================
   📌 範囲記憶＆微調整ツールUI
   ========================================================== */
.persist-range-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  color: #3b82f6;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  background-color: #eff6ff;
  border: 1px solid #bfdbfe;
  margin-left: 8px;
}

.persist-range-toggle input {
  cursor: pointer;
}

.pdf-selection-toolbar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 8px;
}

.pdf-selection-toolbar-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 8px;
  border-top: 1px dashed #bfdbfe;
  padding-top: 6px;
  margin-top: 4px;
}

.pdf-range-preset-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #eff6ff;
  border: 1px solid #93c5fd;
  color: #1d4ed8;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 12px;
}

.pdf-adjust-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

.adjust-label {
  font-size: 10px;
  font-weight: 700;
  color: #475569;
}

.btn-group-sm {
  display: inline-flex;
  gap: 3px;
}

/* ==========================================================
   📱 iPad & タブレット最適化（タッチUI / 自然スクロール）
   ========================================================== */

/* 1. iPad 縦向き & モバイル全般（〜1024px、または縦向き） */
@media (max-width: 1024px), screen and (orientation: portrait) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 10px;
  }

  .header-right {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 8px;
  }

  .main-layout {
    display: flex;
    flex-direction: column;
    gap: 14px;
    width: 100%;
  }

  .panel {
    border-radius: 10px;
    width: 100%;
  }

  .input-panel {
    padding: 10px;
  }

  .preview-panel {
    width: 100%;
  }

  .preview-body {
    background-color: transparent;
  }

  .preview-scroll-area {
    padding: 10px 2px;
  }

  /* 下部アクションバーを画面下部に吸着（スティッキー固定） */
  .action-bar {
    position: sticky;
    bottom: max(10px, env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    padding: 10px 14px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 100;
    margin-top: 14px;
  }

  .word-sheet-container {
    padding: 10px 2px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .word-sheet {
    width: 100%;
    min-width: 500px; /* 表のレイアウト崩れ防止 */
    padding: 18px 20px;
  }

  .pdf-paper-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .pdf-paper {
    min-width: 500px;
  }
}

/* ==========================================================
   🖥️ PCデスクトップ・大画面横向き専用（1画面100vhフィット）
   ========================================================== */
@media (min-width: 1025px) and (orientation: landscape) {
  html, body {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  .app-viewport {
    height: 100vh;
    height: 100dvh;
    padding: 10px 16px 12px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
  }

  .main-layout {
    display: grid;
    grid-template-columns: 440px 1fr;
    gap: 14px;
    flex: 1;
    min-height: 0;
  }

  .panel {
    min-height: 0;
    display: flex;
    flex-direction: column;
  }

  .input-panel {
    overflow-y: auto;
  }

  .preview-panel {
    overflow: hidden;
    height: 100%;
    min-height: 0;
  }

  .preview-body {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    background-color: #e2e8f0;
  }

  .preview-scroll-area {
    height: 100%;
    overflow-y: auto;
    padding: 14px;
  }

  .floating-scroll-top-btn {
    display: none; /* デスクトップでは非表示 */
  }
}

/* フローティング「最上部へ戻る」ボタン（iPad/モバイル用） */
.floating-scroll-top-btn {
  position: fixed;
  right: 18px;
  bottom: 85px;
  background: rgba(30, 41, 59, 0.88);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: all 0.2s ease;
  z-index: 99;
}

.floating-scroll-top-btn:active {
  transform: scale(0.92);
  background: #2563eb;
}

/* 3. タッチデバイス（iPadOS / タッチスクリーン）操作性向上 */
@media (hover: none) and (pointer: coarse) {
  /* タップ領域を Apple HIG（44px）に準拠して拡大 */
  .btn {
    min-height: 38px;
    padding: 8px 14px;
    font-size: 13px;
  }

  .btn-xs {
    min-height: 32px;
    padding: 5px 10px;
    font-size: 11px;
  }

  .accordion-header {
    min-height: 46px;
    padding: 12px 14px;
  }

  .tab-btn {
    min-height: 40px;
    padding: 8px 14px;
    font-size: 12px;
  }

  .drop-zone {
    padding: 20px 14px;
    min-height: 110px;
  }

  .drop-zone:active {
    background-color: var(--primary-light);
    border-color: var(--primary);
  }

  /* 段落チェックボックスを押しやすく拡大 */
  .p-checkbox {
    width: 20px;
    height: 20px;
    cursor: pointer;
  }

  .p-check-label {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
  }

  .preview-paragraph-item {
    padding: 8px 6px;
  }

  .ai-chip {
    min-height: 28px;
    padding: 4px 10px;
    font-size: 11px;
  }

  .btn-ai-toggle {
    min-height: 34px;
    padding: 6px 14px;
  }

  .demo-switch-label {
    min-height: 34px;
    padding: 6px 12px;
  }

  /* フォーム入力欄のオートズーム抑止 */
  .input-text, .input-text-sm, .input-date, .input-select, .ai-input-text {
    font-size: 16px !important;
    min-height: 36px;
  }
}

