/* ═══════════════════════════════════════════════════════════════════════════
   SFC MOU Maker — colorful, large-type theme
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
  /* Palette — indigo/violet primary, pink accent, amber highlight, emerald success */
  --bg: #fbf9f3;                   /* warm cream */
  --bg-gradient: linear-gradient(135deg, #fef9f3 0%, #f3f0fe 50%, #fdf2f8 100%);
  --surface: #ffffff;
  --surface-alt: #fdfbf7;
  --border: #e5e1d5;
  --border-strong: #d4cfc0;

  --text: #1e1b2e;
  --text-muted: #635d72;

  --primary: #6366f1;              /* indigo-500 */
  --primary-hover: #4f46e5;        /* indigo-600 */
  --primary-soft: #eef2ff;

  --accent: #ec4899;               /* pink-500 */
  --accent-soft: #fdf2f8;

  --amber: #f59e0b;
  --amber-soft: #fef3c7;

  --emerald: #10b981;
  --emerald-hover: #059669;
  --emerald-soft: #d1fae5;

  --danger: #ef4444;
  --danger-soft: #fee2e2;

  --teal: #14b8a6;
  --teal-soft: #ccfbf1;

  --shadow-sm: 0 1px 3px rgba(99, 102, 241, 0.06), 0 2px 6px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(99, 102, 241, 0.08), 0 8px 24px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 12px 32px rgba(99, 102, 241, 0.12), 0 24px 48px rgba(0, 0, 0, 0.08);

  --radius: 10px;
  --radius-lg: 14px;
  --radius-sm: 6px;

  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", "PingFang HK", "Noto Sans CJK HK", sans-serif;
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --mono: "SF Mono", "Menlo", "Consolas", "Courier New", monospace;

  --text-size-base: 16px;
}

* { box-sizing: border-box; }

html {
  font-size: var(--text-size-base);
  scroll-behavior: smooth;
}
html, body {
  margin: 0;
  padding: 0;
  font-family: var(--sans);
  color: var(--text);
  background: var(--bg);
  background-image: var(--bg-gradient);
  background-attachment: fixed;
  line-height: 1.6;
  font-size: 1rem;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── Topbar ──────────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
  padding: 18px 28px;
  background: var(--surface);
  border-bottom: 3px solid transparent;
  border-image: linear-gradient(90deg, var(--primary), var(--accent), var(--amber)) 1;
  gap: 28px;
  flex-wrap: wrap;
  box-shadow: var(--shadow-sm);
  position: relative;
  z-index: 10;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
}
.brand-mark {
  font-size: 40px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 2px 4px rgba(99, 102, 241, 0.15));
}
.brand h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  line-height: 1.1;
}
.brand .tagline {
  margin: 3px 0 0;
  font-size: 14px;
  color: var(--text-muted);
  max-width: 520px;
}

.keybar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 400px;
}
.keybar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.keybar label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  min-width: 110px;
}
.keybar input,
.keybar select {
  padding: 8px 12px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--surface);
  font-family: var(--sans);
  color: var(--text);
  transition: all 0.15s;
}
.keybar input:focus,
.keybar select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.keybar input[type="password"] {
  flex: 1;
  min-width: 260px;
}
.keybar select {
  flex: 1;
  min-width: 180px;
  cursor: pointer;
}
.keybar #modelCustom {
  flex: 1;
  min-width: 160px;
}
.keybar-params label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  min-width: 0;
  cursor: help;
}
.keybar-params input[type="number"] {
  width: 92px;
  padding: 6px 8px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.keybar-params input[type="number"]#maxTokens {
  width: 110px;
}
.btn-refresh {
  padding: 8px 14px;
  border: 1.5px solid var(--primary);
  border-radius: var(--radius-sm);
  background: var(--primary-soft);
  color: var(--primary);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.15s;
}
.keybar-check {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12.5px;
  color: var(--text-muted);
  cursor: help;
  min-width: 0;
  padding: 6px 8px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
}
.keybar-check input[type="checkbox"] {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--primary);
  cursor: pointer;
}
.keybar-check:hover { border-color: var(--primary); }
#btnClearKey {
  border-color: var(--border);
  background: var(--surface-alt);
  color: var(--text-muted);
}
#btnClearKey:hover {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}
.btn-refresh:hover {
  background: var(--primary);
  color: white;
}
.model-status {
  font-size: 12.5px;
  color: var(--text-muted);
  min-height: 16px;
  padding-left: 120px;
}

/* ─── Layout ──────────────────────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 0;
  min-height: calc(100vh - 180px);
  background: transparent;
}

/* ─── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  align-self: flex-start;
  max-height: 100vh;
  overflow-y: auto;
}

.stage-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stage-nav button {
  text-align: left;
  padding: 12px 14px;
  border: 1.5px solid transparent;
  background: transparent;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14.5px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--sans);
  transition: all 0.15s;
  font-weight: 500;
}
.stage-nav button:hover {
  background: var(--primary-soft);
  border-color: var(--primary-soft);
}
.stage-nav button.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: white;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}
.stage-nav .stage-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  font-size: 12px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary-soft), var(--accent-soft));
  color: var(--primary);
  font-weight: 700;
  flex-shrink: 0;
  font-family: var(--serif);
}
.stage-nav button.active .stage-num {
  background: rgba(255, 255, 255, 0.25);
  color: white;
}
.stage-nav .stage-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.stage-nav .stage-count {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.stage-nav button.active .stage-count {
  color: rgba(255, 255, 255, 0.85);
}

.progress {
  font-size: 13px;
  padding: 14px;
  background: linear-gradient(135deg, var(--primary-soft), var(--accent-soft));
  border-radius: var(--radius);
}
.progress-label {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}
.progress-bar {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 4px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 0.3s ease;
  width: 0%;
  border-radius: 4px;
}

.sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border-top: 1px solid var(--border);
  padding-top: 18px;
}
.sidebar-actions .btn {
  width: 100%;
  text-align: center;
  font-size: 13.5px;
  padding: 10px 12px;
}
.sidebar-footer {
  font-size: 11.5px;
  color: var(--text-muted);
  padding-top: 12px;
  border-top: 1px solid var(--border);
  line-height: 1.5;
}
.sidebar-footer p { margin: 0; }

/* ─── Content ─────────────────────────────────────────────────────────────── */
.content {
  padding: 32px 40px 80px;
  max-width: 960px;
  width: 100%;
}

.stage-header {
  margin-bottom: 28px;
  padding-bottom: 20px;
  border-bottom: 2px solid var(--border);
}
.stage-header h2 {
  margin: 0 0 8px;
  font-family: var(--serif);
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  line-height: 1.15;
}
.stage-summary {
  margin: 0;
  color: var(--text-muted);
  font-size: 15.5px;
  line-height: 1.55;
}

.path-banner {
  margin-top: 14px;
  background: linear-gradient(135deg, var(--amber-soft), #fde68a);
  border: 1.5px solid var(--amber);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 14px;
  color: #78350f;
}
.path-banner strong { color: #92400e; }
.path-banner-sub {
  display: block;
  margin-top: 4px;
  font-size: 12.5px;
  color: #78350f;
  opacity: 0.8;
}

/* ─── Wizard / Questions ──────────────────────────────────────────────────── */
.wizard {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.q-group {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}
.q-group::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: linear-gradient(180deg, var(--primary), var(--accent));
  opacity: 0.85;
}
.q-optional-group::before {
  background: linear-gradient(180deg, var(--border-strong), var(--border));
  opacity: 0.5;
}
.q-group:focus-within {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.q-group-flash {
  animation: flash-warning 1s ease-out 2;
  border-color: var(--danger) !important;
}
@keyframes flash-warning {
  0%, 100% { box-shadow: var(--shadow-sm); }
  50% { box-shadow: 0 0 0 4px var(--danger-soft); }
}

.q-label {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.q-id {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 2px 8px;
  border-radius: 4px;
  flex-shrink: 0;
  font-weight: 600;
}
.q-text {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.005em;
  flex: 1;
}
.q-tag {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.q-tag-required {
  background: var(--accent-soft);
  color: var(--accent);
}
.q-tag-optional {
  background: var(--surface-alt);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.q-description {
  font-size: 14.5px;
  color: var(--text-muted);
  margin: 0 0 12px;
  line-height: 1.55;
}

.q-example {
  background: linear-gradient(135deg, var(--amber-soft), #fff8e1);
  border-left: 3px solid var(--amber);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 9px 14px;
  margin: 0 0 14px;
  font-size: 13.5px;
  line-height: 1.5;
  color: #78350f;
}
.q-example-label {
  font-weight: 700;
  color: #92400e;
  margin-right: 4px;
}
.q-example-text {
  color: #78350f;
  font-style: italic;
}

.q-chips {
  margin-bottom: 14px;
}
.q-chips-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 500;
}
.q-chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  background: linear-gradient(135deg, var(--teal-soft), var(--primary-soft));
  color: var(--text);
  border: 1.5px solid transparent;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  font-family: var(--sans);
  transition: all 0.15s;
  font-weight: 500;
  text-align: left;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip:hover {
  border-color: var(--primary);
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: white;
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(99, 102, 241, 0.2);
}
.chip:active {
  transform: translateY(0);
}

.q-input input[type="text"],
.q-input textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  font-size: 15px;
  font-family: var(--sans);
  background: var(--surface);
  color: var(--text);
  transition: all 0.15s;
  line-height: 1.5;
}
.q-input textarea {
  min-height: 80px;
  resize: vertical;
  font-family: var(--sans);
}
.q-input input:focus,
.q-input textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
  background: var(--surface);
}
.q-input-flash {
  animation: input-flash 0.4s ease-out;
}
@keyframes input-flash {
  0% { background: var(--emerald-soft); border-color: var(--emerald); }
  100% { background: var(--surface); border-color: var(--border-strong); }
}

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  padding: 10px 18px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 14.5px;
  font-family: var(--sans);
  font-weight: 500;
  transition: all 0.15s;
}
.btn:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: white;
  border-color: transparent;
  box-shadow: 0 2px 6px rgba(99, 102, 241, 0.25);
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--primary-hover), #3730a3);
  color: white;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
  transform: translateY(-1px);
}
.btn-ghost {
  background: transparent;
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}
.btn-danger-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
  padding: 10px 12px;
  font-size: 13.5px;
  margin-top: 8px;
}
.btn-danger-ghost:hover:not(:disabled) {
  background: var(--danger-soft);
  border-color: var(--danger);
  color: var(--danger);
}
.btn-generate {
  background: linear-gradient(135deg, var(--emerald), #059669);
  color: white;
  border-color: transparent;
  font-weight: 600;
  font-size: 15.5px;
  padding: 12px 24px;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
  position: relative;
}
.btn-generate:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--emerald-hover), #047857);
  color: white;
  box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4);
  transform: translateY(-1px);
}

.nav-actions {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 32px;
  padding: 24px 0 0;
  border-top: 2px solid var(--border);
  flex-wrap: wrap;
}

/* ─── Output ──────────────────────────────────────────────────────────────── */
.output-panel {
  margin-top: 36px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}
.output-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 22px;
  background: linear-gradient(135deg, var(--primary-soft), var(--accent-soft));
  border-bottom: 1.5px solid var(--border);
  flex-wrap: wrap;
  gap: 10px;
}
.output-header h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 700;
  color: var(--primary-hover);
}
.output-actions { display: flex; gap: 8px; }
.gen-status {
  padding: 12px 22px;
  font-size: 13.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
}
.gen-status.error {
  color: var(--danger);
  background: var(--danger-soft);
  font-weight: 500;
}
.gen-status.success {
  color: var(--emerald-hover);
  background: var(--emerald-soft);
  font-weight: 500;
}
.output {
  margin: 0;
  padding: 24px 28px;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.7;
  max-height: 75vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--surface);
  color: var(--text);
}

/* ─── Footer ──────────────────────────────────────────────────────────────── */
.footer {
  padding: 18px 28px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--text-muted);
  text-align: center;
}
.footer code {
  font-family: var(--mono);
  font-size: 11.5px;
  background: var(--primary-soft);
  color: var(--primary-hover);
  padding: 1px 6px;
  border-radius: 3px;
}

/* ─── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .content { padding: 24px 20px; max-width: 100%; }
}
@media (max-width: 720px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
    padding: 16px 20px;
  }
  .keybar { min-width: 0; }
  .brand h1 { font-size: 24px; }
  .stage-header h2 { font-size: 26px; }
  .q-group { padding: 18px 16px; }
  .q-text { font-size: 16px; }
  .chip { font-size: 12px; padding: 5px 10px; }
  .model-status { padding-left: 0; }
}

/* Utility */
.hidden { display: none !important; }
