/* ============================================================
   쇼츠 라이터 — 자가면역 의학 대본 생성기
   Theme: Red (#dc2626)
   ============================================================ */

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

:root {
  --primary: #dc2626;
  --primary-dark: #b91c1c;
  --primary-light: #fee2e2;
  --accent: #f59e0b;
  --bg: #ffffff;
  --bg-sidebar: #1f2937;
  --bg-soft: #f9fafb;
  --bg-card: #ffffff;
  --text: #111827;
  --text-muted: #6b7280;
  --text-light: #9ca3af;
  --sidebar-text: #e5e7eb;
  --sidebar-muted: #9ca3af;
  --sidebar-hover: #374151;
  --border: #e5e7eb;
  --border-soft: #f3f4f6;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 40px rgba(0,0,0,0.1);
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
}

html, body {
  height: 100%;
  font-family: 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  background: var(--bg-soft);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.85em;
  font-family: 'Menlo', 'Consolas', monospace;
  color: var(--primary-dark);
}

/* ------------------------------------------------------------
   App Layout
   ------------------------------------------------------------ */
.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ------------------------------------------------------------
   Sidebar
   ------------------------------------------------------------ */
.sidebar {
  background: var(--bg-sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  border-right: 1px solid #0f172a;
}

.sidebar-header {
  padding: 18px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #374151;
  position: sticky;
  top: 0;
  background: var(--bg-sidebar);
  z-index: 10;
}

.logo {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #fff;
}

.sidebar-section {
  padding: 16px 20px;
  border-bottom: 1px solid #374151;
}

.sidebar-footer {
  margin-top: auto;
  border-bottom: none;
  border-top: 1px solid #374151;
}

.section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--sidebar-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 12px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--sidebar-text);
  font-size: 13px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.sidebar-link:hover {
  background: var(--sidebar-hover);
  text-decoration: none;
}

/* Workflow Steps */
.workflow-steps {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.workflow-step {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
  color: var(--sidebar-muted);
  font-size: 13px;
}
.workflow-step:hover { background: var(--sidebar-hover); color: var(--sidebar-text); }
.workflow-step.active {
  background: rgba(220, 38, 38, 0.15);
  color: #fff;
  border-left: 3px solid var(--primary);
  padding-left: 9px;
}
.workflow-step.completed { color: var(--sidebar-text); }
.workflow-step.completed .step-num {
  background: var(--success);
  color: #fff;
}
.step-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--sidebar-hover);
  color: var(--sidebar-text);
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}
.workflow-step.active .step-num {
  background: var(--primary);
  color: #fff;
}
.step-label { font-weight: 500; }

/* History */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 280px;
  overflow-y: auto;
}
.history-item {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--sidebar-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background 0.15s;
}
.history-item:hover { background: var(--sidebar-hover); }
.history-item .history-date {
  display: block;
  font-size: 10px;
  color: var(--sidebar-muted);
  margin-top: 2px;
}
.empty-hint {
  font-size: 12px;
  color: var(--sidebar-muted);
  padding: 6px 0;
}

/* ------------------------------------------------------------
   Main Content
   ------------------------------------------------------------ */
.main-content {
  overflow-y: auto;
  padding: 32px 48px 64px;
  position: relative;
  background: var(--bg);
}

.step-section { display: none; max-width: 900px; margin: 0 auto; }
.step-section.active { display: block; }

.step-header { margin-bottom: 24px; }
.step-header h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
  letter-spacing: -0.01em;
}
.step-desc { color: var(--text-muted); font-size: 14px; }

/* ------------------------------------------------------------
   Input Tabs
   ------------------------------------------------------------ */
.input-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.input-tab {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  font-weight: 500;
  margin-bottom: -1px;
}
.input-tab:hover { color: var(--text); }
.input-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.input-panel { display: none; }
.input-panel.active { display: block; }

.input-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 8px;
}
.input-label-inline {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  flex: 1;
}
.required { color: var(--danger); }

.input-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
}

/* URL input */
.url-input-row {
  display: flex;
  gap: 8px;
}
.url-input-row input { flex: 1; }

input[type="url"],
input[type="text"],
input[type="password"],
input[type="email"],
select,
textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}
textarea {
  resize: vertical;
  font-family: inherit;
  line-height: 1.6;
  min-height: 120px;
}

/* File Drop Area */
.file-drop-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 36px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  background: var(--bg-soft);
}
.file-drop-area:hover,
.file-drop-area.dragover {
  border-color: var(--primary);
  background: var(--primary-light);
}
.file-drop-area p {
  margin-top: 10px;
  color: var(--text-muted);
  font-size: 13px;
}

.selected-files {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 12px 0;
}
.selected-files:empty { display: none; }
.file-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text);
}
.file-item .file-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-item .file-size { color: var(--text-muted); font-size: 12px; }
.file-item .file-remove {
  background: none;
  border: none;
  color: var(--text-light);
  cursor: pointer;
  padding: 2px 6px;
  font-size: 14px;
}
.file-item .file-remove:hover { color: var(--danger); }

/* ------------------------------------------------------------
   Content Panel (Step 2)
   ------------------------------------------------------------ */
.content-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.content-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}
.content-sources:empty { display: none; }
.source-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--primary-light);
  color: var(--primary-dark);
  border-radius: 100px;
  font-size: 12px;
  font-weight: 500;
}

.char-counter {
  font-size: 12px;
  color: var(--text-muted);
  text-align: right;
  margin-top: 4px;
}

.options-row {
  display: flex;
  gap: 16px;
  margin-top: 20px;
}

/* ------------------------------------------------------------
   Script Result (Step 3)
   ------------------------------------------------------------ */
.script-result {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.script-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-soft);
}
.meta-item {
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-soft);
  padding: 4px 12px;
  border-radius: 100px;
}

#generatedScript {
  min-height: 480px;
  font-family: 'Noto Sans KR', -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.8;
}

/* ------------------------------------------------------------
   Step Actions
   ------------------------------------------------------------ */
.step-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
}

/* ------------------------------------------------------------
   Buttons
   ------------------------------------------------------------ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  background: #fff;
  color: var(--text);
  white-space: nowrap;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-outline {
  background: #fff;
  color: var(--text);
  border-color: var(--border);
}
.btn-outline:hover:not(:disabled) {
  border-color: var(--text-muted);
  background: var(--bg-soft);
}

.btn-sm { padding: 6px 12px; font-size: 12px; }

.icon-btn {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
  transition: opacity 0.15s, background 0.15s;
}
.icon-btn:hover { opacity: 1; background: rgba(255, 255, 255, 0.08); }
.sidebar .icon-btn { color: var(--sidebar-text); }
.main-content .icon-btn { color: var(--text-muted); }
.main-content .icon-btn:hover { background: var(--bg-soft); }

/* ------------------------------------------------------------
   Modal
   ------------------------------------------------------------ */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.modal.active { display: flex; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: #fff;
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.2s ease-out;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-header .icon-btn { color: var(--text-muted); }

.modal-body { padding: 20px 24px; }

.form-group { margin-bottom: 18px; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 8px;
  color: var(--text);
}

.input-with-btn {
  display: flex;
  gap: 6px;
}
.input-with-btn input { flex: 1; }

.form-actions {
  display: flex;
  justify-content: flex-end;
  padding-top: 8px;
  border-top: 1px solid var(--border-soft);
  margin-top: 8px;
}

.api-status {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  display: none;
}
.api-status.success { display: block; background: #d1fae5; color: #065f46; }
.api-status.error { display: block; background: #fee2e2; color: #991b1b; }

/* ------------------------------------------------------------
   Loading Overlay
   ------------------------------------------------------------ */
.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(4px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
}
.loading-overlay.active { display: flex; }

.loading-spinner {
  width: 44px;
  height: 44px;
  border: 3px solid var(--primary-light);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.loading-subtext {
  font-size: 12px;
  color: var(--text-muted);
  max-width: 400px;
  text-align: center;
}

/* ------------------------------------------------------------
   Toast
   ------------------------------------------------------------ */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #111827;
  color: #fff;
  padding: 12px 22px;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 300;
  max-width: 400px;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* ------------------------------------------------------------
   Responsive
   ------------------------------------------------------------ */
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: -260px;
    top: 0;
    bottom: 0;
    width: 260px;
    z-index: 50;
    transition: left 0.25s;
  }
  .sidebar.open { left: 0; }
  .main-content { padding: 24px 20px 60px; }
  .step-header h2 { font-size: 20px; }
  .options-row { flex-direction: column; }
  .url-input-row { flex-direction: column; }
  .step-actions .btn { flex: 1; justify-content: center; }
}
