:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --line: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #10b981;
  --success-hover: #059669;
  --danger: #dc2626;
  --soft: #f9fafb;
  --shadow: 0 12px 32px rgba(17, 24, 39, 0.08);
  --radius: 18px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
}
.hidden { display: none !important; }
img { max-width: 100%; display: block; }

.login-screen {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
.login-card {
  width: 100%; max-width: 440px; background: var(--card); border: 1px solid var(--line);
  border-radius: 28px; box-shadow: var(--shadow); padding: 32px;
}
.brand-title { margin: 0 0 8px; font-size: 28px; font-weight: 800; }
.brand-subtitle { margin: 0 0 24px; color: var(--muted); font-size: 14px; line-height: 1.6; }

.topbar {
  position: sticky; top: 0; z-index: 20; backdrop-filter: blur(12px);
  background: rgba(245,247,251,.92); border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1400px; margin: 0 auto; padding: 16px 20px;
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
}
.topbar-title { margin: 0; font-size: 22px; font-weight: 800; }
.topbar-subtitle { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.current-user { color: var(--muted); font-size: 14px; }

.container { max-width: 1400px; margin: 0 auto; padding: 24px 20px 48px; }
.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px;
}
.panel-title { margin: 0 0 16px; font-size: 18px; font-weight: 800; }

.tabs { display: flex; gap: 10px; flex-wrap: wrap; }
.tab-btn {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  border-radius: 999px; padding: 10px 16px; font-size: 14px; font-weight: 800; cursor: pointer;
}
.tab-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.form-group { margin-top: 16px; }
label { display: block; margin-bottom: 8px; font-size: 14px; font-weight: 700; }
input[type="text"], input[type="password"], textarea, select {
  width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 14px;
  padding: 13px 14px; font-size: 14px; outline: none;
}
textarea { min-height: 110px; resize: vertical; line-height: 1.6; }
.select { max-width: 180px; }

.upload-area {
  border: 2px dashed #bfdbfe; background: #eff6ff; border-radius: 18px;
  padding: 28px; text-align: center; cursor: pointer;
}
.upload-area.dragover { background: #dbeafe; border-color: var(--primary); }
.upload-icon {
  width: 56px; height: 56px; margin: 0 auto 12px; border-radius: 50%;
  background: #fff; display: grid; place-items: center; font-size: 28px; color: var(--primary);
}
.upload-title { font-size: 18px; font-weight: 800; margin-bottom: 6px; }
.upload-desc { color: var(--muted); font-size: 14px; line-height: 1.6; }

.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-top: 16px; }
.summary { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 16px; }
.summary-chip {
  padding: 8px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--soft); font-size: 13px; color: var(--muted);
}
.status-text, .error-text {
  margin-top: 12px; min-height: 20px; font-size: 13px; white-space: pre-line; line-height: 1.6;
}
.status-text { color: var(--muted); }
.error-text { color: var(--danger); }

.empty-state, .file-list {
  padding: 18px; border: 1px dashed var(--line); border-radius: 16px; background: #fafafa;
}
.file-list-item {
  padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px;
}
.file-list-item:last-child { border-bottom: none; }

.card-grid {
  margin-top: 16px; display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 18px;
}
.card {
  overflow: hidden; border: 1px solid var(--line); border-radius: 18px; background: #fff;
  box-shadow: 0 8px 20px rgba(17,24,39,.05);
}
.card-header {
  padding: 14px 16px; border-bottom: 1px solid var(--line); background: #fcfcfd;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.card-file-name { font-size: 14px; font-weight: 800; }
.card-file-sub { margin-top: 4px; color: var(--muted); font-size: 12px; }
.badge { padding: 6px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge-wait { background: #f3f4f6; color: #6b7280; }
.badge-run { background: #dbeafe; color: #1d4ed8; }
.badge-ok { background: #dcfce7; color: #047857; }
.badge-fail { background: #fee2e2; color: #b91c1c; }

.compare-grid { display: grid; grid-template-columns: 1fr 1fr; }
.compare-col { border-right: 1px solid var(--line); }
.compare-col:last-child { border-right: none; }
.compare-label {
  padding: 10px 12px; border-bottom: 1px solid var(--line); background: #fcfcfd;
  color: var(--muted); font-size: 12px; font-weight: 800;
}
.compare-image-wrap {
  aspect-ratio: 4 / 3; background: #f3f4f6; display: flex; align-items: center; justify-content: center;
}
.compare-image {
  width: 100%; height: 100%; object-fit: contain; background: #fff; cursor: pointer;
}
.compare-placeholder { color: #9ca3af; font-size: 13px; text-align: center; padding: 16px; }
.card-body { padding: 14px 16px 16px; }
.prompt-box {
  border: 1px solid var(--line); background: #fafafa; border-radius: 12px; padding: 10px 12px; margin-bottom: 12px;
}
.prompt-title { margin-bottom: 6px; color: var(--muted); font-size: 11px; font-weight: 800; }
.prompt-text { font-size: 12px; line-height: 1.6; white-space: pre-line; }
.card-actions { display: flex; flex-wrap: wrap; gap: 10px; }

.result-block {
  margin-top: 18px; border: 1px solid var(--line); border-radius: 16px; padding: 16px; background: #fff;
}
.result-head {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px;
}
.result-head h3 { margin: 0; font-size: 16px; }
.result-textarea {
  min-height: 260px; width: 100%; resize: vertical; border: 1px solid var(--line);
  border-radius: 12px; padding: 14px; line-height: 1.8; font-size: 14px; background: #fafafa;
}
.references-box {
  border: 1px solid var(--line); border-radius: 12px; background: #fafafa; padding: 14px;
  white-space: pre-line; line-height: 1.8; font-size: 14px;
}
.question-block {
  border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 14px; background: #fafafa;
}
.question-title { font-weight: 800; margin-bottom: 12px; }
.option-label {
  display: flex; gap: 10px; align-items: flex-start; margin-bottom: 10px; font-weight: 400;
}

.btn {
  appearance: none; border: none; border-radius: 14px; padding: 12px 18px;
  cursor: pointer; font-size: 14px; font-weight: 800; display: inline-flex;
  align-items: center; justify-content: center; gap: 8px;
}
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: #fff; color: var(--text); border: 1px solid var(--line); }
.btn-success { background: var(--success); color: #fff; }

.spinner, .spinner-dark, .global-spinner {
  border-radius: 50%; animation: spin .8s linear infinite;
}
.spinner {
  width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.35); border-top-color: #fff;
}
.spinner-dark {
  width: 14px; height: 14px; border: 2px solid rgba(37,99,235,.18); border-top-color: var(--primary);
}
.global-loading {
  position: fixed; inset: 0; z-index: 100; background: rgba(17,24,39,.36);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.global-loading-card {
  width: 100%; max-width: 360px; background: #fff; border-radius: 22px;
  box-shadow: 0 20px 50px rgba(17,24,39,.22); padding: 24px; text-align: center;
}
.global-spinner {
  width: 44px; height: 44px; margin: 0 auto 14px; border: 4px solid rgba(37,99,235,.15); border-top-color: var(--primary);
}
.global-loading-title { font-size: 16px; font-weight: 800; margin-bottom: 6px; }
.global-loading-text { color: var(--muted); font-size: 13px; line-height: 1.6; }

.modal { position: fixed; inset: 0; z-index: 120; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(17,24,39,.65); }
.modal-content {
  position: relative; z-index: 1; width: min(92vw, 960px); max-height: 90vh; overflow: auto;
  margin: 5vh auto; background: #fff; border-radius: 22px; padding: 20px;
}
.modal-header, .modal-toolbar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.modal-header { margin-bottom: 12px; }
.modal-toolbar { margin-bottom: 14px; justify-content: flex-start; }
.modal-title { font-size: 18px; font-weight: 800; }
.modal-subtitle { margin-top: 4px; color: var(--muted); font-size: 13px; }
.modal-image-wrap { background: #f3f4f6; border-radius: 16px; overflow: hidden; }
.modal-image { width: 100%; max-height: 70vh; object-fit: contain; background: #fff; }

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

@media (max-width: 900px) {
  .compare-grid { grid-template-columns: 1fr; }
  .compare-col { border-right: none; border-bottom: 1px solid var(--line); }
  .compare-col:last-child { border-bottom: none; }
  .card-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .container { padding: 16px 14px 36px; }
  .panel { padding: 16px; }
  .topbar-inner { padding: 14px; flex-direction: column; align-items: stretch; }
  .topbar-actions { justify-content: space-between; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .card-actions .btn { width: 100%; }
}

/* =========================
   Notion風アップグレード
========================= */

/* レイアウト余白 */
.container {
  max-width: 1600px;
}

/* カード感を弱めてフラットに */
.panel {
  border: none;
  box-shadow: none;
  background: transparent;
  padding: 0;
}

/* 左カラム */
.editor-layout {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 32px;
}

/* 入力側をカード化 */
.editor-layout > div:first-child {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 20px;
  box-shadow: var(--shadow);
}

/* プレビュー（Notion風） */
.editor-preview {
  background: transparent;
  padding: 10px 0;
  max-width: 720px;
}

/* タイトル（Notion風） */
.editor-preview h1 {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.02em;
  margin-bottom: 20px;
}

/* 見出し */
.editor-preview h2 {
  font-size: 18px;
  font-weight: 800;
  margin-top: 28px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

/* 本文 */
.editor-preview p {
  font-size: 15px;
  line-height: 1.9;
  color: #374151;
}

/* ボタン（Notion風） */
.result-actions button {
  background: #f3f4f6;
  border: none;
  color: #111827;
  border-radius: 10px;
  padding: 8px 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}

.result-actions button:hover {
  background: #e5e7eb;
}

/* ステップ感を出す */
.panel h2 {
  font-size: 14px;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 10px;
}

/* 入力ボタン強調 */
.btn-primary {
  width: 100%;
  border-radius: 12px;
  font-size: 15px;
}

/* モバイル */
@media (max-width: 900px) {
  .editor-layout {
    grid-template-columns: 1fr;
  }

  .editor-preview {
    max-width: 100%;
  }
}