:root {
  --navy: #0a1628;
  --navy-mid: #112244;
  --blue: #2563eb;
  --blue-hover: #1d4ed8;
  --blue-light: #eff6ff;
  --green: #059669;
  --green-light: #ecfdf5;
  --red: #dc2626;
  --red-light: #fef2f2;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;
  --border: #e2e8f0;
  --bg: #f8fafc;
  --white: #ffffff;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -2px rgba(0,0,0,.05);
}

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

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ---------- LAYOUT ---------- */

.container {
  max-width: 860px;
  margin: 0 auto;
  padding: 0 24px;
}

header {
  background: var(--navy);
  padding: 18px 0;
  position: sticky;
  top: 0;
  z-index: 10;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 16px;
}

.logo {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: .12em;
  color: var(--white);
}

.logo span { color: #60a5fa; }

.header-sub {
  font-size: 13px;
  color: #94a3b8;
  border-left: 1px solid #1e3a5f;
  padding-left: 16px;
}

main { padding: 40px 24px 80px; }

/* ---------- FORM ---------- */

#form-section {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px;
  box-shadow: var(--shadow);
}

.section-intro { margin-bottom: 28px; }

.section-intro h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.section-intro p {
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.6;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-bottom: 24px;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }

label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.req { color: var(--red); margin-left: 2px; }

input, textarea {
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  resize: vertical;
}

input::placeholder, textarea::placeholder { color: var(--text-3); }

input:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

input.invalid, textarea.invalid {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(220,38,38,.1);
}

.form-error {
  background: var(--red-light);
  border: 1px solid #fca5a5;
  border-radius: var(--radius-sm);
  color: var(--red);
  font-size: 13px;
  padding: 10px 14px;
  margin-bottom: 16px;
}

#generate-btn {
  width: 100%;
  padding: 13px;
  background: var(--blue);
  color: var(--white);
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}

#generate-btn:hover { background: var(--blue-hover); }

#generate-btn:disabled {
  opacity: .55;
  cursor: not-allowed;
}

/* ---------- PROGRESS ---------- */

#progress-section { padding: 32px 0 0; }

.progress-wrap { display: flex; flex-direction: column; gap: 10px; }

.progress-bar {
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--blue);
  border-radius: 99px;
  transition: width .5s ease;
  width: 0%;
}

.progress-label {
  font-size: 13px;
  color: var(--text-2);
}

/* ---------- RESULTS ---------- */

#results-section { padding-top: 32px; }

.results-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.results-header h2 {
  font-size: 20px;
  font-weight: 700;
}

.results-sub {
  font-size: 13px;
  color: var(--text-2);
  margin-top: 4px;
}

.results-actions { display: flex; gap: 10px; align-items: center; flex-shrink: 0; }

.btn-secondary {
  padding: 8px 16px;
  border: 1px solid var(--blue);
  color: var(--blue);
  background: var(--white);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.btn-secondary:hover:not(:disabled) {
  background: var(--blue-light);
}

.btn-secondary:disabled { opacity: .4; cursor: not-allowed; }

.btn-ghost {
  padding: 8px 14px;
  border: 1px solid var(--border);
  color: var(--text-2);
  background: var(--white);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}

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

/* ---------- SECTION CARDS ---------- */

#sections-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.kit-section {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.kit-section.loading .section-body { display: none; }
.kit-section.loading .section-skeleton { display: block; }
.kit-section.done .section-skeleton { display: none; }
.kit-section.done .section-body { display: block; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  cursor: pointer;
  user-select: none;
  gap: 12px;
}

.section-head:hover { background: var(--bg); }

.section-head-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.section-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--blue);
  color: var(--white);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.kit-section.loading .section-num {
  background: var(--border);
  color: transparent;
  position: relative;
  overflow: hidden;
}

.kit-section.loading .section-num::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 25%, rgba(255,255,255,.6) 50%, transparent 75%);
  animation: shimmer 1.4s infinite;
}

.section-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kit-section.loading .section-title { color: var(--text-3); }

.section-status {
  font-size: 12px;
  color: var(--text-3);
  flex-shrink: 0;
}

.kit-section.done .section-status { color: var(--green); }

.section-chevron {
  width: 16px;
  height: 16px;
  color: var(--text-3);
  transition: transform .2s;
  flex-shrink: 0;
}

.kit-section.open .section-chevron { transform: rotate(180deg); }

.section-body {
  padding: 0 20px 20px;
  border-top: 1px solid var(--border);
}

.section-body.collapsed { display: none; }

.section-actions {
  display: flex;
  gap: 8px;
  padding: 12px 0 16px;
}

.btn-action {
  padding: 6px 12px;
  border: 1px solid var(--border);
  color: var(--text-2);
  background: var(--white);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color .15s, color .15s, background .15s;
}

.btn-action:hover { border-color: var(--blue); color: var(--blue); background: var(--blue-light); }
.btn-action.copied { border-color: var(--green); color: var(--green); background: var(--green-light); }

.section-skeleton {
  display: none;
  padding: 20px;
}

.skeleton-line {
  height: 12px;
  background: var(--border);
  border-radius: 4px;
  margin-bottom: 10px;
  overflow: hidden;
  position: relative;
}

.skeleton-line::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 25%, rgba(255,255,255,.7) 50%, transparent 75%);
  animation: shimmer 1.4s infinite;
}

.skeleton-line:nth-child(2) { width: 85%; }
.skeleton-line:nth-child(3) { width: 92%; }
.skeleton-line:nth-child(4) { width: 70%; }

@keyframes shimmer {
  from { transform: translateX(-100%); }
  to   { transform: translateX(100%); }
}

/* ---------- MARKDOWN CONTENT ---------- */

.md-content {
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
}

.md-content h1,
.md-content h2,
.md-content h3 {
  font-weight: 600;
  margin: 20px 0 8px;
  color: var(--text);
}

.md-content h1 { font-size: 17px; }
.md-content h2 { font-size: 15px; }
.md-content h3 { font-size: 14px; color: var(--text-2); }

.md-content p { margin: 0 0 12px; }

.md-content ul,
.md-content ol {
  padding-left: 20px;
  margin: 0 0 12px;
}

.md-content li { margin-bottom: 4px; }

.md-content strong { font-weight: 600; }
.md-content em { font-style: italic; }

.md-content code {
  font-family: 'Courier New', monospace;
  font-size: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 5px;
}

.md-content pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  overflow-x: auto;
  margin: 0 0 12px;
}

.md-content pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 13px;
}

.md-content blockquote {
  border-left: 3px solid var(--blue);
  padding-left: 14px;
  color: var(--text-2);
  margin: 0 0 12px;
}

.md-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

.md-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin-bottom: 12px;
}

.md-content th,
.md-content td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}

.md-content th {
  background: var(--bg);
  font-weight: 600;
}

/* ---------- ERROR STATE ---------- */

.error-card {
  background: var(--red-light);
  border: 1px solid #fca5a5;
  border-radius: var(--radius);
  padding: 20px 24px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.error-card p {
  font-size: 14px;
  color: var(--red);
  line-height: 1.5;
}

.error-card strong { font-weight: 600; }

/* ---------- RESPONSIVE ---------- */

@media (max-width: 600px) {
  #form-section { padding: 24px 20px; }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: 1; }
  .results-header { flex-direction: column; }
  .results-actions { width: 100%; justify-content: flex-start; }
}
