/* ═══════════════════════════════════════════════════════════════
   SAVA Studio — Styles
   Modern dark UI with accent colors
   ═══════════════════════════════════════════════════════════════ */

:root {
  --bg: #0f0f1a;
  --bg-surface: #1a1a2e;
  --bg-card: #16213e;
  --bg-input: #1e2a45;
  --bg-hover: #243352;
  --border: #2a3a5c;
  --border-light: #3a4a6c;
  --text: #e2e8f0;
  --text-muted: #8892a8;
  --text-dim: #5a6478;
  --accent: #6c63ff;
  --accent-hover: #7c73ff;
  --accent-glow: rgba(108, 99, 255, 0.15);
  --green: #4ade80;
  --green-bg: rgba(74, 222, 128, 0.1);
  --red: #f87171;
  --red-bg: rgba(248, 113, 113, 0.1);
  --yellow: #fbbf24;
  --yellow-bg: rgba(251, 191, 36, 0.1);
  --cyan: #22d3ee;
  --cyan-bg: rgba(34, 211, 238, 0.1);
  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.4);
  --font: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', monospace;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

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

/* ── Layout ── */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.header .logo {
  font-size: 20px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent) 0%, var(--cyan) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.5px;
}
.header .subtitle {
  font-size: 12px;
  color: var(--text-muted);
}
.header .spacer { flex: 1; }
.header-nav {
  display: flex;
  gap: 4px;
  align-items: center;
  margin-left: 16px;
  background: var(--bg-card);
  border-radius: 10px;
  padding: 3px;
  border: 1px solid var(--border);
}
.header-nav-link {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  text-decoration: none;
  transition: all 0.2s;
}
.header-nav-link:hover {
  color: var(--text);
  background: rgba(108, 92, 231, 0.08);
}
.header-nav-link.active {
  color: #fff;
  background: var(--accent);
  box-shadow: 0 2px 8px rgba(108, 92, 231, 0.25);
}
.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ── Main content ── */
.main {
  flex: 1;
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* ── Views (shown/hidden) ── */
.view { display: none; }
.view.active { display: block; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); border-color: var(--border-light); }
.btn:disabled { opacity: 0.4; cursor: default; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-hover); }

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

.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
}

.btn-danger { border-color: var(--red); color: var(--red); }
.btn-danger:hover { background: var(--red-bg); }

.btn-success { border-color: var(--green); color: var(--green); }
.btn-success:hover { background: var(--green-bg); }

/* ── Cards ── */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  transition: all var(--transition);
}
.card:hover { border-color: var(--border-light); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}
.card-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── Form elements ── */
input, textarea, select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  padding: 10px 14px;
  outline: none;
  transition: border-color var(--transition);
  width: 100%;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
input::placeholder, textarea::placeholder { color: var(--text-dim); }
textarea { resize: vertical; min-height: 80px; line-height: 1.6; }
select { cursor: pointer; }

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-group { margin-bottom: 20px; }
.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.form-hint {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ── Tags / Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.badge-accent { background: var(--accent-glow); color: var(--accent); }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge-cyan { background: var(--cyan-bg); color: var(--cyan); }

/* ── Home view — type cards ── */
.home-hero {
  text-align: center;
  padding: 60px 20px 40px;
}
.home-hero h1 {
  font-size: 36px;
  font-weight: 800;
  margin-bottom: 12px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--cyan) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.home-hero p {
  font-size: 16px;
  color: var(--text-muted);
  max-width: 600px;
  margin: 0 auto;
  line-height: 1.6;
}

.type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
  margin-top: 32px;
}

.type-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.type-card:hover {
  border-color: var(--accent);
  background: var(--bg-card);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.type-card-featured {
  grid-column: 1 / -1;
  border-color: var(--yellow);
  background: linear-gradient(135deg, rgba(251,191,36,0.04) 0%, rgba(245,158,11,0.02) 100%);
}
.type-card-featured:hover {
  border-color: var(--yellow);
  box-shadow: 0 4px 24px rgba(251,191,36,0.15);
}
.type-card-icon {
  width: 56px;
  height: 56px;
  margin-bottom: 12px;
}
.type-card-icon svg {
  width: 100%;
  height: 100%;
}
.type-card h3 {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 6px;
}
.type-card p {
  font-size: 13.5px;
  color: var(--text-muted);
  line-height: 1.55;
}
.type-card-deliverable {
  margin-top: 10px;
  padding: 10px 14px;
  background: rgba(108,99,255,0.06);
  border: 1px solid rgba(108,99,255,0.12);
  border-radius: var(--radius);
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.55;
}
.type-card-featured .type-card-deliverable {
  background: rgba(251,191,36,0.06);
  border-color: rgba(251,191,36,0.15);
}
.deliverable-label {
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.5px;
}
.type-card-featured .deliverable-label {
  color: var(--yellow);
}

/* ── Projects list ── */
.projects-section { margin-top: 48px; }
.projects-section h2 {
  font-size: 18px;
  margin-bottom: 16px;
  color: var(--text-muted);
}
.project-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.project-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
}
.project-item:hover {
  border-color: var(--accent);
  background: var(--bg-card);
}
.project-item .pi-icon { font-size: 24px; }
.project-item .pi-info { flex: 1; }
.project-item .pi-title { font-weight: 600; font-size: 14px; }
.project-item .pi-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.project-item .pi-date { font-size: 11px; color: var(--text-dim); }

.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--text-dim);
  font-size: 14px;
}

/* ── Brief wizard ── */
.wizard {
  max-width: 720px;
  margin: 0 auto;
}
.wizard-header {
  text-align: center;
  margin-bottom: 32px;
}
.wizard-header h2 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 8px;
}
.wizard-header p { color: var(--text-muted); }

/* ── Mode selector ── */
.mode-selector {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}
.mode-btn {
  flex: 1;
  padding: 16px;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  cursor: pointer;
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  transition: all var(--transition);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.mode-btn small {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-dim);
}
.mode-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}
.mode-btn.active {
  border-color: var(--accent);
  background: var(--accent-glow);
  color: var(--text);
}
.mode-btn.active small { color: var(--text-muted); }

/* ── Step wizard ── */
.step-container {
  min-height: 180px;
}
.step-question {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
  line-height: 1.4;
}
.step-hint {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 16px;
  line-height: 1.5;
}
.step-input input,
.step-input textarea,
.step-input select {
  width: 100%;
  font-size: 16px;
}
.step-input textarea {
  min-height: 100px;
}
.step-examples {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.step-example {
  padding: 5px 14px;
  border-radius: 20px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}
.step-example:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}
.step-progress {
  height: 4px;
  background: var(--bg-input);
  border-radius: 2px;
  margin-top: 20px;
  overflow: hidden;
}
.step-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  border-radius: 2px;
  transition: width 0.4s ease;
}
.step-counter {
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 8px;
}

.wizard-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* ── Editor view ── */
.editor-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 20px;
  min-height: calc(100vh - 140px);
}

.editor-sidebar {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  position: sticky;
  top: 80px;
  height: fit-content;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
}
.editor-sidebar h3 {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.section-nav { list-style: none; }
.section-nav li {
  padding: 8px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-nav li:hover { background: var(--bg-hover); color: var(--text); }
.section-nav li.active {
  background: var(--accent-glow);
  color: var(--accent);
  font-weight: 600;
}
.section-nav li .nav-num {
  font-size: 10px;
  font-weight: 700;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--bg-input);
  flex-shrink: 0;
}
.section-nav li.active .nav-num {
  background: var(--accent);
  color: white;
}

.editor-content { min-width: 0; }

.section-editor {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 16px;
}
.section-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.section-editor-header h2 {
  font-size: 20px;
  font-weight: 700;
}

.section-editor-body {
  min-height: 200px;
}

.section-editor textarea {
  font-size: 14px;
  line-height: 1.8;
  min-height: 300px;
  font-family: var(--font);
}

/* ── AI Rewrite panel ── */
.rewrite-panel {
  background: var(--bg-card);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 16px;
  display: none;
}
.rewrite-panel.visible { display: block; }
.rewrite-panel h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 8px;
}
.rewrite-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.rewrite-chip {
  padding: 4px 12px;
  border-radius: 20px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}
.rewrite-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Output toolbar ── */
.output-toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  padding: 16px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  align-items: center;
}
.output-toolbar .toolbar-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-right: 8px;
}

.output-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  transition: all var(--transition);
  font-size: 13px;
  font-weight: 500;
}
.output-btn:hover {
  border-color: var(--accent);
  background: var(--accent-glow);
}
.output-btn .ob-icon { font-size: 18px; }
.output-btn.generating {
  opacity: 0.6;
  pointer-events: none;
}
.output-btn.export-btn {
  border-color: var(--text-dim);
  background: transparent;
  font-size: 12px;
  padding: 6px 12px;
}
.output-btn.export-btn:hover {
  border-color: var(--accent);
  background: var(--accent-glow);
}
.toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 8px;
  align-self: center;
}

/* ── Preview panel ── */
.preview-container {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}
.preview-header h3 { font-size: 14px; font-weight: 600; }
.preview-actions { display: flex; gap: 8px; }

.preview-iframe {
  width: 100%;
  height: 70vh;
  border: none;
  background: white;
}

/* ── Loading / Generating states ── */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(8px);
}
.loading-overlay.hidden { display: none; }

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

.loading-text {
  margin-top: 16px;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.loading-detail {
  margin-top: 6px;
  font-size: 13px;
  color: var(--text-muted);
}

/* ── Toast notifications ── */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  animation: slideIn 0.3s ease-out;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}
.toast-success { background: var(--green-bg); color: var(--green); border: 1px solid var(--green); }
.toast-error { background: var(--red-bg); color: var(--red); border: 1px solid var(--red); }
.toast-info { background: var(--cyan-bg); color: var(--cyan); border: 1px solid var(--cyan); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ── Key metrics cards ── */
.metrics-strip {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.metric-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 160px;
}
.metric-card .mc-icon { font-size: 24px; }
.metric-card .mc-value { font-size: 18px; font-weight: 700; }
.metric-card .mc-label { font-size: 11px; color: var(--text-muted); }

/* ── Markdown rendered content ── */
.md-content { line-height: 1.8; font-size: 14px; }
.md-content h1, .md-content h2, .md-content h3 { margin: 16px 0 8px; color: var(--accent); }
.md-content h1 { font-size: 22px; }
.md-content h2 { font-size: 18px; }
.md-content h3 { font-size: 15px; }
.md-content p { margin-bottom: 10px; }
.md-content ul, .md-content ol { margin: 8px 0 8px 24px; }
.md-content li { margin-bottom: 4px; }
.md-content strong { color: var(--text); }
.md-content table { width: 100%; border-collapse: collapse; margin: 12px 0; }
.md-content th, .md-content td {
  padding: 8px 12px;
  border: 1px solid var(--border);
  text-align: left;
  font-size: 13px;
}
.md-content th { background: var(--bg-input); font-weight: 600; }
.md-content code {
  font-family: var(--mono);
  background: var(--bg-input);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
}
.md-content blockquote {
  border-left: 3px solid var(--accent);
  padding: 8px 16px;
  margin: 12px 0;
  background: var(--accent-glow);
  border-radius: 0 var(--radius) var(--radius) 0;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .header { padding: 10px 16px; }
  .main { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .editor-layout { grid-template-columns: 1fr; }
  .editor-sidebar { position: static; }
  .type-grid { grid-template-columns: 1fr; }
  .home-hero h1 { font-size: 28px; }
}
