/* ===== CSS Variables & Reset ===== */
:root {
  --bg-primary: #0a0b14;
  --bg-secondary: #12131f;
  --bg-card: #1a1b2e;
  --bg-card-hover: #222340;
  --bg-glass: rgba(26, 27, 46, 0.7);
  --border-color: rgba(99, 102, 241, 0.15);
  --border-hover: rgba(99, 102, 241, 0.35);
  --text-primary: #e8e9f3;
  --text-secondary: #9394a5;
  --text-muted: #6b6c7e;
  --accent-1: #6366f1;
  --accent-2: #a855f7;
  --accent-3: #3b82f6;
  --gradient-main: linear-gradient(135deg, #6366f1, #a855f7);
  --gradient-hover: linear-gradient(135deg, #7c7ff7, #b96df9);
  --success: #22c55e;
  --warning: #f59e0b;
  --error: #ef4444;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 24px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 48px rgba(0,0,0,0.5);
  --shadow-glow: 0 0 30px rgba(99, 102, 241, 0.15);
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --font-main: 'Inter', 'Noto Sans JP', -apple-system, sans-serif;
}

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

html { scroll-behavior: smooth; }

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

/* ===== Background Particles ===== */
.bg-particles {
  position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden;
}
.bg-particles .particle {
  position: absolute; border-radius: 50%; opacity: 0.12;
  animation: particleFloat 20s infinite ease-in-out;
}
@keyframes particleFloat {
  0%, 100% { transform: translate(0, 0) scale(1); }
  25% { transform: translate(30px, -50px) scale(1.1); }
  50% { transform: translate(-20px, 20px) scale(0.9); }
  75% { transform: translate(40px, 40px) scale(1.05); }
}

/* ===== Header ===== */
.app-header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(10, 11, 20, 0.85);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-color);
}
.header-inner {
  max-width: 1200px; margin: 0 auto; padding: 12px 24px;
  display: flex; align-items: center; justify-content: space-between;
}
.logo-section { display: flex; align-items: center; gap: 12px; }
.logo-icon { flex-shrink: 0; }
.logo-text h1 {
  font-size: 1.3rem; font-weight: 700; letter-spacing: -0.02em;
  background: var(--gradient-main); -webkit-background-clip: text;
  -webkit-text-fill-color: transparent; background-clip: text;
  line-height: 1.2;
}
.logo-ai {
  font-size: 0.7em; padding: 2px 6px; border-radius: 4px;
  background: var(--gradient-main); -webkit-text-fill-color: white; color: white;
  vertical-align: super;
}
.logo-subtitle { font-size: 0.75rem; color: var(--text-muted); }

.btn-ghost {
  background: none; border: 1px solid transparent; color: var(--text-secondary);
  padding: 8px; border-radius: var(--radius-sm); cursor: pointer;
  transition: var(--transition);
}
.btn-ghost:hover { background: var(--bg-card); color: var(--text-primary); border-color: var(--border-color); }

/* ===== Main Content ===== */
.main-content {
  position: relative; z-index: 1;
  max-width: 1200px; margin: 0 auto; padding: 32px 24px 80px;
}

/* ===== Steps Indicator ===== */
.steps-indicator {
  display: flex; align-items: center; justify-content: center;
  gap: 0; margin-bottom: 40px;
}
.step {
  display: flex; align-items: center; gap: 8px; padding: 8px 16px;
  border-radius: 100px; transition: var(--transition);
}
.step.active .step-number {
  background: var(--gradient-main); color: white; box-shadow: 0 0 16px rgba(99, 102, 241, 0.4);
}
.step.completed .step-number { background: var(--success); color: white; }
.step-number {
  width: 28px; height: 28px; border-radius: 50%; display: flex;
  align-items: center; justify-content: center; font-size: 0.8rem;
  font-weight: 600; background: var(--bg-card); color: var(--text-muted);
  transition: var(--transition); flex-shrink: 0;
}
.step-label { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; }
.step.active .step-label { color: var(--text-primary); }
.step.completed .step-label { color: var(--success); }
.step-connector {
  width: 40px; height: 2px; background: var(--bg-card); flex-shrink: 0;
  transition: var(--transition);
}
.step-connector.completed { background: var(--success); }

/* ===== Section ===== */
.section {
  background: var(--bg-glass);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 32px; margin-bottom: 24px;
  backdrop-filter: blur(12px);
  transition: var(--transition);
  animation: fadeSlideUp 0.5s ease-out;
}
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
.section-header { margin-bottom: 24px; }
.section-header h2 {
  font-size: 1.25rem; font-weight: 600; display: flex;
  align-items: center; gap: 10px; margin-bottom: 8px;
}
.section-header h2 svg { color: var(--accent-1); flex-shrink: 0; }
.section-desc { font-size: 0.9rem; color: var(--text-secondary); }

/* ===== Drop Zone ===== */
.drop-zone {
  border: 2px dashed var(--border-color); border-radius: var(--radius-lg);
  padding: 48px 24px; text-align: center; cursor: pointer;
  transition: var(--transition); position: relative; overflow: hidden;
}
.drop-zone::before {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(circle at center, rgba(99,102,241,0.05) 0%, transparent 70%);
  opacity: 0; transition: var(--transition);
}
.drop-zone:hover, .drop-zone.drag-over {
  border-color: var(--accent-1); background: rgba(99, 102, 241, 0.05);
}
.drop-zone:hover::before, .drop-zone.drag-over::before { opacity: 1; }
.drop-zone-content { position: relative; z-index: 1; }
.drop-icon { margin-bottom: 16px; animation: float 3s ease-in-out infinite; }
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
.drop-text { font-size: 1.1rem; font-weight: 500; margin-bottom: 8px; }
.drop-subtext { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 16px; }

/* Buttons */
.btn-primary {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 24px; border: none; border-radius: var(--radius-sm);
  background: var(--gradient-main); color: white; font-family: var(--font-main);
  font-size: 0.9rem; font-weight: 500; cursor: pointer;
  transition: var(--transition); box-shadow: 0 4px 16px rgba(99, 102, 241, 0.3);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 24px rgba(99, 102, 241, 0.4); }

.supported-formats { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 20px; }
.format-badge {
  padding: 4px 12px; border-radius: 100px; font-size: 0.75rem;
  font-weight: 500; background: var(--bg-card); color: var(--text-secondary);
  border: 1px solid var(--border-color);
}
.format-badge.docx { color: #3b82f6; border-color: rgba(59,130,246,0.3); }
.format-badge.xlsx { color: #22c55e; border-color: rgba(34,197,94,0.3); }
.format-badge.pptx { color: #f59e0b; border-color: rgba(245,158,11,0.3); }
.format-badge.txt { color: #9394a5; border-color: rgba(147,148,165,0.3); }
.format-badge.html { color: #ef4444; border-color: rgba(239,68,68,0.3); }
.format-badge.md { color: #a855f7; border-color: rgba(168,85,247,0.3); }

/* ===== Uploaded Files ===== */
.uploaded-files { margin-top: 24px; }
.uploaded-files h3 {
  font-size: 0.95rem; font-weight: 600; margin-bottom: 12px;
  color: var(--text-secondary);
}
.file-list { display: flex; flex-direction: column; gap: 8px; }
.file-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: var(--radius-sm);
  background: var(--bg-card); border: 1px solid var(--border-color);
  transition: var(--transition); animation: fadeSlideUp 0.3s ease-out;
}
.file-item:hover { border-color: var(--border-hover); }
.file-icon {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem; font-weight: 700; flex-shrink: 0;
}
.file-icon.docx { background: rgba(59,130,246,0.15); color: #3b82f6; }
.file-icon.xlsx { background: rgba(34,197,94,0.15); color: #22c55e; }
.file-icon.pptx { background: rgba(245,158,11,0.15); color: #f59e0b; }
.file-icon.txt { background: rgba(147,148,165,0.15); color: #9394a5; }
.file-icon.html { background: rgba(239,68,68,0.15); color: #ef4444; }
.file-icon.md { background: rgba(168,85,247,0.15); color: #a855f7; }
.file-info { flex: 1; min-width: 0; }
.file-name { font-size: 0.9rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-size { font-size: 0.75rem; color: var(--text-muted); }
.file-remove {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  padding: 4px; border-radius: 4px; transition: var(--transition);
}
.file-remove:hover { color: var(--error); background: rgba(239,68,68,0.1); }
.file-preview-container { margin-top: 16px; }
.file-preview-container h4 { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 8px; }
.file-preview {
  background: var(--bg-secondary); border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); padding: 16px; max-height: 200px;
  overflow-y: auto; font-size: 0.8rem; line-height: 1.5;
  color: var(--text-secondary); white-space: pre-wrap; word-break: break-word;
}

/* ===== AI Agent Cards ===== */
.agent-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.agent-card {
  position: relative; padding: 20px; border-radius: var(--radius-md);
  background: var(--bg-card); border: 2px solid var(--border-color);
  cursor: pointer; transition: var(--transition); overflow: hidden;
}
.agent-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--gradient-main); opacity: 0; transition: var(--transition);
}
.agent-card:hover { border-color: var(--border-hover); transform: translateY(-2px); box-shadow: var(--shadow-glow); }
.agent-card:hover::before { opacity: 1; }
.agent-card.selected { border-color: var(--accent-1); background: rgba(99, 102, 241, 0.08); }
.agent-card.selected::before { opacity: 1; }
.agent-card-header { display: flex; align-items: start; justify-content: space-between; margin-bottom: 12px; }
.agent-logo {
  width: 44px; height: 44px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; flex-shrink: 0;
}
.agent-badge {
  padding: 3px 10px; border-radius: 100px; font-size: 0.65rem;
  font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
}
.agent-badge.free { background: rgba(34,197,94,0.15); color: #22c55e; }
.agent-badge.not-free { background: rgba(245,158,11,0.15); color: #f59e0b; }
.agent-name { font-size: 1rem; font-weight: 600; margin-bottom: 4px; }
.agent-desc { font-size: 0.8rem; color: var(--text-secondary); line-height: 1.4; margin-bottom: 12px; }
.agent-features { display: flex; flex-wrap: wrap; gap: 6px; }
.agent-feature {
  padding: 3px 8px; border-radius: 4px; font-size: 0.7rem;
  background: var(--bg-secondary); color: var(--text-muted);
}
.agent-check {
  position: absolute; top: 12px; right: 12px; width: 24px; height: 24px;
  border-radius: 50%; background: var(--accent-1); color: white;
  display: none; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 700;
}
.agent-card.selected .agent-check { display: flex; }

/* ===== Generate Button ===== */
.generate-section { text-align: center; margin: 32px 0; }
.btn-generate {
  position: relative; display: inline-flex; align-items: center;
  padding: 16px 40px; border: none; border-radius: var(--radius-md);
  background: var(--gradient-main); color: white; font-family: var(--font-main);
  font-size: 1.1rem; font-weight: 600; cursor: pointer;
  transition: var(--transition); overflow: hidden;
  box-shadow: 0 4px 24px rgba(99, 102, 241, 0.3);
}
.btn-generate:not(:disabled):hover { transform: translateY(-2px); box-shadow: 0 8px 32px rgba(99, 102, 241, 0.45); }
.btn-generate:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-generate-inner { display: flex; align-items: center; gap: 10px; position: relative; z-index: 1; }
.btn-shimmer {
  position: absolute; top: 0; left: -100%; width: 100%; height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.15), transparent);
  animation: shimmer 3s infinite;
}
.btn-generate:disabled .btn-shimmer { animation: none; }
@keyframes shimmer { 0% { left: -100%; } 100% { left: 200%; } }
.generate-hint { font-size: 0.8rem; color: var(--text-muted); margin-top: 12px; }

/* ===== Loading ===== */
.loading-section { text-align: center; padding: 60px 32px; }
.loading-content { max-width: 400px; margin: 0 auto; }
.loading-orb { position: relative; width: 120px; height: 120px; margin: 0 auto 32px; }
.orb-ring {
  position: absolute; inset: 0; border-radius: 50%;
  border: 2px solid transparent; border-top-color: var(--accent-1);
}
.ring-1 { animation: spin 2s linear infinite; }
.ring-2 { inset: 10px; border-top-color: var(--accent-2); animation: spin 3s linear infinite reverse; }
.ring-3 { inset: 20px; border-top-color: var(--accent-3); animation: spin 1.5s linear infinite; }
.orb-core {
  position: absolute; inset: 30px; border-radius: 50%;
  background: var(--bg-card); display: flex;
  align-items: center; justify-content: center;
  color: var(--accent-1); animation: pulse 2s ease-in-out infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 0.7; } 50% { opacity: 1; } }
.loading-title { font-size: 1.3rem; font-weight: 600; margin-bottom: 8px; }
.loading-desc { font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 24px; }
.loading-steps { text-align: left; max-width: 280px; margin: 0 auto; }
.loading-step {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 0; font-size: 0.85rem; color: var(--text-muted);
  transition: var(--transition);
}
.loading-step.active { color: var(--text-primary); }
.loading-step.done { color: var(--success); }
.ls-icon { width: 20px; text-align: center; font-size: 0.9rem; }

/* ===== Result Section ===== */
.result-section { animation: fadeSlideUp 0.6s ease-out; }
.result-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.btn-outline {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); background: transparent;
  color: var(--text-secondary); font-family: var(--font-main);
  font-size: 0.8rem; cursor: pointer; transition: var(--transition);
}
.btn-outline:hover { border-color: var(--accent-1); color: var(--accent-1); background: rgba(99,102,241,0.05); }

/* Diagram Container */
.diagram-container {
  background: var(--bg-secondary); border: 1px solid var(--border-color);
  border-radius: var(--radius-md); overflow: hidden; margin-bottom: 20px;
}
.diagram-toolbar {
  display: flex; align-items: center; gap: 4px;
  padding: 8px 12px; border-bottom: 1px solid var(--border-color);
  background: var(--bg-card);
}
.diagram-tool {
  background: none; border: 1px solid transparent; color: var(--text-muted);
  padding: 6px; border-radius: 4px; cursor: pointer; transition: var(--transition);
  display: flex; align-items: center; justify-content: center;
}
.diagram-tool:hover { background: var(--bg-secondary); color: var(--text-primary); border-color: var(--border-color); }
.zoom-level { font-size: 0.75rem; color: var(--text-muted); margin-left: 8px; }
.diagram-viewport {
  overflow: auto; padding: 24px; min-height: 400px;
  display: flex; align-items: center; justify-content: center;
}
.diagram-content { transition: transform 0.2s ease; transform-origin: center center; }
.diagram-content svg { max-width: 100%; height: auto; }

/* Mermaid Source */
.mermaid-source { margin-bottom: 20px; }
.mermaid-source summary {
  display: flex; align-items: center; gap: 8px; padding: 12px 16px;
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); cursor: pointer; font-size: 0.85rem;
  color: var(--text-secondary); transition: var(--transition);
  list-style: none;
}
.mermaid-source summary::-webkit-details-marker { display: none; }
.mermaid-source summary:hover { border-color: var(--border-hover); color: var(--text-primary); }
.mermaid-source pre {
  margin-top: 8px; padding: 16px; background: var(--bg-secondary);
  border: 1px solid var(--border-color); border-radius: var(--radius-sm);
  overflow-x: auto; font-size: 0.8rem; line-height: 1.6;
}
.mermaid-source code { color: var(--accent-2); font-family: 'JetBrains Mono', monospace; }

/* Analysis Summary */
.analysis-summary {
  padding: 20px; background: var(--bg-card);
  border: 1px solid var(--border-color); border-radius: var(--radius-md);
}
.analysis-summary h3 {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.95rem; margin-bottom: 12px; color: var(--accent-1);
}
.summary-content { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.7; }
.summary-content p { margin-bottom: 8px; }
.summary-content ul { padding-left: 20px; margin-bottom: 8px; }
.summary-content li { margin-bottom: 4px; }
.summary-content strong { color: var(--text-primary); }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0,0,0,0.7); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal {
  background: var(--bg-secondary); border: 1px solid var(--border-color);
  border-radius: var(--radius-lg); max-width: 560px; width: 100%;
  max-height: 80vh; overflow-y: auto; animation: modalIn 0.3s ease-out;
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.95) translateY(10px); } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px; border-bottom: 1px solid var(--border-color);
}
.modal-header h2 { font-size: 1.1rem; }
.modal-close {
  background: none; border: none; color: var(--text-muted);
  font-size: 1.5rem; cursor: pointer; padding: 4px 8px; border-radius: 4px;
  transition: var(--transition);
}
.modal-close:hover { color: var(--text-primary); background: var(--bg-card); }
.modal-body { padding: 24px; }
.help-step { display: flex; gap: 16px; margin-bottom: 20px; }
.help-step-num {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  background: var(--gradient-main); color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 700;
}
.help-step h4 { font-size: 0.95rem; margin-bottom: 4px; }
.help-step p { font-size: 0.85rem; color: var(--text-secondary); }
.help-note {
  padding: 16px; background: rgba(99,102,241,0.08);
  border: 1px solid rgba(99,102,241,0.2); border-radius: var(--radius-sm);
  font-size: 0.85rem; color: var(--text-secondary);
}

/* ===== Toast ===== */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 2000; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 20px; border-radius: var(--radius-sm);
  background: var(--bg-card); border: 1px solid var(--border-color);
  color: var(--text-primary); font-size: 0.85rem;
  box-shadow: var(--shadow-md); animation: toastIn 0.3s ease-out;
  display: flex; align-items: center; gap: 8px; min-width: 280px;
}
.toast.success { border-color: rgba(34,197,94,0.4); }
.toast.error { border-color: rgba(239,68,68,0.4); }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(20px); } }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-card); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .main-content { padding: 20px 16px 60px; }
  .section { padding: 20px; }
  .steps-indicator { flex-wrap: wrap; gap: 4px; }
  .step-connector { width: 20px; }
  .step-label { font-size: 0.7rem; }
  .agent-grid { grid-template-columns: 1fr; }
  .result-actions { flex-wrap: wrap; }
  .drop-zone { padding: 32px 16px; }
  .btn-generate { padding: 14px 28px; font-size: 1rem; }
}
