/* ===== リセット & ベース ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-bg: #0f1117;
  --color-surface: #1a1d27;
  --color-surface-2: #22263a;
  --color-border: #2e3350;
  --color-primary: #6c8ff8;
  --color-primary-hover: #8aaeff;
  --color-text: #e8eaf6;
  --color-text-muted: #8891b8;
  --color-error: #f87171;
  --color-error-bg: #2d1515;
  --color-success: #4ade80;
  --radius: 12px;
  --radius-sm: 6px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

html { font-size: 16px; }

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font);
  min-height: 100vh;
  line-height: 1.6;
}

/* ===== レイアウト ===== */
.app {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

/* ===== ヘッダー ===== */
.header { text-align: center; padding: 1.5rem 0; }

.header__title {
  font-size: 2.2rem;
  font-weight: 700;
  background: linear-gradient(135deg, #6c8ff8 0%, #a78bfa 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.03em;
}

.header__subtitle {
  color: var(--color-text-muted);
  margin-top: 0.4rem;
  font-size: 1rem;
}

/* ===== アップロードセクション ===== */
.upload-section {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
}

/* ===== ドロップゾーン ===== */
.dropzone {
  width: 100%;
  border: 2px dashed var(--color-border);
  border-radius: var(--radius);
  padding: 3rem 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  background: var(--color-surface);
  position: relative;
  outline: none;
}

.dropzone:hover,
.dropzone:focus-visible {
  border-color: var(--color-primary);
  background: var(--color-surface-2);
}

.dropzone--active {
  border-color: var(--color-primary);
  background: rgba(108, 143, 248, 0.08);
}

.dropzone__icon {
  width: 52px;
  height: 52px;
  margin: 0 auto 1rem;
  color: var(--color-primary);
}

.dropzone__icon svg { width: 100%; height: 100%; }

.dropzone__primary {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--color-text);
}

.dropzone__secondary {
  font-size: 0.9rem;
  color: var(--color-text-muted);
  margin-top: 0.25rem;
}

.dropzone__formats {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-top: 1rem;
  opacity: 0.7;
}

.dropzone__input {
  display: none;
}

/* ===== ファイル情報 ===== */
.file-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
}

.file-info__name {
  font-weight: 500;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 400px;
}

.file-info__size {
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* ===== ボタン ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.4rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.15s, color 0.15s, opacity 0.15s;
}

.btn--primary {
  background: var(--color-primary);
  color: #fff;
  padding: 0.75rem 2.5rem;
  font-size: 1rem;
}

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

.btn--secondary {
  background: var(--color-surface-2);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn--secondary:hover { border-color: var(--color-primary); color: var(--color-primary); }

.btn--ghost {
  background: transparent;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}

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

/* ===== タブボタン ===== */
.tab-btn {
  padding: 0.4rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--color-border);
  background: transparent;
  color: var(--color-text-muted);
  transition: background 0.15s, color 0.15s;
}

.tab-btn--active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}

/* ===== 進捗スピナー + バー ===== */
.progress {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  justify-content: center;
  padding: 1.5rem;
}

.progress__spinner {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  margin-top: 2px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.progress__info {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  min-width: 220px;
}

.progress__text {
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

.progress__bar {
  width: 100%;
  height: 6px;
  background: var(--color-border);
  border-radius: 999px;
  overflow: hidden;
}

.progress__fill {
  height: 100%;
  width: 0%;
  background: var(--color-primary);
  border-radius: 999px;
  transition: width 0.35s ease;
}

.progress__count {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}

/* ===== エラー ===== */
.error {
  background: var(--color-error-bg);
  border: 1px solid var(--color-error);
  color: var(--color-error);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1.2rem;
  font-size: 0.9rem;
}

/* ===== OCR オプション ===== */
.ocr-options {
  width: 100%;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.ocr-options__header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-muted);
}

.ocr-options__badge {
  background: #2a3a6e;
  color: var(--color-primary);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.1em 0.5em;
  border-radius: 4px;
  letter-spacing: 0.04em;
}

.ocr-options__row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.ocr-options__field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1;
  min-width: 160px;
}

.ocr-options__label {
  font-size: 0.78rem;
  color: var(--color-text-muted);
  font-weight: 500;
}

.ocr-options__select {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  color: var(--color-text);
  font-size: 0.88rem;
  padding: 0.4rem 0.7rem;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
}

.ocr-options__select:focus { border-color: var(--color-primary); }

/* ===== バッジ ===== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2em 0.6em;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge--ocr {
  background: rgba(108, 143, 248, 0.15);
  color: var(--color-primary);
  border: 1px solid rgba(108, 143, 248, 0.3);
}

/* ===== 結果ヘッダー左側 ===== */
.result__header-left {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

/* ===== 結果 ===== */
.result {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.result__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface-2);
}

.result__title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.8rem;
}

.result__actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.result__pane { display: block; }
.result__pane.hidden { display: none; }

.result__textarea {
  width: 100%;
  min-height: 420px;
  background: transparent;
  border: none;
  color: var(--color-text);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.7;
  padding: 1.25rem;
  resize: vertical;
  outline: none;
}

/* ===== Markdownプレビュー ===== */
.result__preview {
  padding: 1.5rem;
  min-height: 420px;
  overflow-x: auto;
}

.markdown-body {
  color: var(--color-text);
  font-family: var(--font);
  font-size: 0.95rem;
  line-height: 1.75;
}

.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
  color: var(--color-text);
  margin: 1.5em 0 0.5em;
  font-weight: 700;
  line-height: 1.3;
}

.markdown-body h1 { font-size: 1.75rem; border-bottom: 1px solid var(--color-border); padding-bottom: 0.4em; }
.markdown-body h2 { font-size: 1.4rem; border-bottom: 1px solid var(--color-border); padding-bottom: 0.3em; }
.markdown-body h3 { font-size: 1.15rem; }

.markdown-body p { margin: 0.75em 0; }

.markdown-body a { color: var(--color-primary); text-decoration: none; }
.markdown-body a:hover { text-decoration: underline; }

.markdown-body code {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 0.15em 0.4em;
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: #e06c75;
}

.markdown-body pre {
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  overflow-x: auto;
  margin: 1em 0;
}

.markdown-body pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--color-text);
  font-size: 0.85rem;
}

.markdown-body blockquote {
  border-left: 3px solid var(--color-primary);
  margin: 1em 0;
  padding: 0.5em 1em;
  color: var(--color-text-muted);
  background: var(--color-surface-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.markdown-body ul, .markdown-body ol { margin: 0.5em 0; padding-left: 1.75em; }
.markdown-body li { margin: 0.25em 0; }

.markdown-body table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
  font-size: 0.9em;
}

.markdown-body th, .markdown-body td {
  border: 1px solid var(--color-border);
  padding: 0.5em 0.8em;
  text-align: left;
}

.markdown-body th {
  background: var(--color-surface-2);
  font-weight: 600;
}

.markdown-body tr:nth-child(even) td {
  background: rgba(255,255,255,0.02);
}

.markdown-body img {
  max-width: 100%;
  border-radius: var(--radius-sm);
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 1.5em 0;
}

/* ===== フッター ===== */
.footer {
  text-align: center;
  padding: 1rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.footer__link {
  color: var(--color-text-muted);
  text-decoration: none;
  transition: color 0.15s;
}

.footer__link:hover { color: var(--color-primary); }
.footer__sep { margin: 0 0.5rem; }

/* ===== ユーティリティ ===== */
.hidden { display: none !important; }

/* ===== レスポンシブ ===== */
@media (max-width: 600px) {
  .app { padding: 1rem; gap: 1.25rem; }
  .header__title { font-size: 1.6rem; }
  .result__header { flex-direction: column; align-items: flex-start; }
  .result__actions { width: 100%; }
  .file-info__name { max-width: 200px; }
}
