:root {
  --bg: #f8f3e8;
  --panel: #fffaf0;
  --ink: #192b2f;
  --muted: #5f6e73;
  --accent: #0f766e;
  --accent-2: #c2410c;
  --line: #d9d2c2;
  --shadow: rgba(25, 43, 47, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 20%, #fff2b5 0%, transparent 40%),
    radial-gradient(circle at 80% 30%, #d7f4f0 0%, transparent 45%),
    var(--bg);
  min-height: 100vh;
}

.bg-shape {
  position: fixed;
  border-radius: 999px;
  filter: blur(36px);
  opacity: 0.45;
  z-index: 0;
}

.bg-shape-1 {
  width: 240px;
  height: 240px;
  background: #f97316;
  top: -80px;
  left: -60px;
}

.bg-shape-2 {
  width: 320px;
  height: 320px;
  background: #0891b2;
  bottom: -120px;
  right: -90px;
}

.container {
  position: relative;
  z-index: 1;
  width: min(1180px, 92vw);
  margin: 2rem auto 3rem;
  display: grid;
  gap: 1rem;
}

.hero {
  background: linear-gradient(130deg, #11323a, #1d4c55);
  color: #f8f8f8;
  border-radius: 18px;
  padding: 1.4rem 1.5rem;
  box-shadow: 0 18px 30px var(--shadow);
  animation: reveal 0.5s ease;
}

.hero-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.8rem;
}

.logout-link {
  color: #d8f2ec;
  text-decoration: none;
  font-size: 0.85rem;
  border: 1px solid rgba(216, 242, 236, 0.35);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
}

.logout-link:hover {
  background: rgba(216, 242, 236, 0.14);
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-size: 0.75rem;
  opacity: 0.85;
}

h1,
h2,
h3 {
  font-family: "Space Grotesk", "IBM Plex Sans", sans-serif;
  margin: 0.3rem 0;
}

.subtitle {
  margin: 0.4rem 0 0;
  max-width: 72ch;
  color: #d5e7e8;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1rem;
  box-shadow: 0 8px 14px var(--shadow);
  animation: reveal 0.5s ease;
}

.field {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.8rem;
}

.field span {
  color: var(--muted);
  font-size: 0.9rem;
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  background: #fff;
  border: 1px solid #bfc8c9;
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  color: var(--ink);
}

textarea {
  min-height: 280px;
  width: 100%;
  resize: vertical;
}

.checkbox-field {
  grid-auto-flow: column;
  align-items: center;
  justify-content: start;
  gap: 0.5rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.8rem;
}

.output-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 0.62rem 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.btn:hover {
  transform: translateY(-1px);
  opacity: 0.95;
}

.btn-primary {
  background: var(--accent);
  color: #f3fffe;
}

.btn-accent {
  background: var(--accent-2);
  color: #fff8f4;
}

.status-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 0.45rem;
}

.live-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
  margin-bottom: 0.8rem;
}

.live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: #e7efed;
  color: #1f3a3d;
  border: 1px solid #b8c8c4;
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  font-weight: 600;
  font-size: 0.85rem;
}

.live-indicator .dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #7b8790;
}

.live-indicator.running .dot {
  background: #0f766e;
  box-shadow: 0 0 0 0 rgba(15, 118, 110, 0.7);
  animation: pulse 1.2s infinite;
}

.live-indicator.failed .dot {
  background: #b91c1c;
}

.live-indicator.completed .dot {
  background: #166534;
}

.heartbeat {
  font-size: 0.84rem;
  color: var(--muted);
}

.phase-track {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}

.phase-item {
  background: #f4eee0;
  border: 1px solid #d7ceb7;
  border-radius: 10px;
  padding: 0.45rem 0.55rem;
  min-height: 64px;
  display: grid;
  align-content: start;
}

.phase-item .phase-kicker {
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #6f7f84;
}

.phase-item .phase-title {
  font-size: 0.88rem;
  font-weight: 700;
}

.phase-item.done {
  background: #dff5ee;
  border-color: #8ecfbb;
}

.phase-item.active {
  background: #fff0cf;
  border-color: #e5b34c;
}

.phase-item.failed {
  background: #ffe1e1;
  border-color: #d98b8b;
}

.progress-bar {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  overflow: hidden;
  background: #d5e1de;
  margin-bottom: 0.35rem;
}

#progress-fill {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #0f766e, #0ea5a0);
  transition: width 0.25s ease;
}

.progress-bar.running #progress-fill {
  background:
    linear-gradient(90deg, #0f766e, #0ea5a0, #14b8a6, #0f766e);
  background-size: 240% 100%;
  animation: glide 1.8s linear infinite;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.84rem;
  margin: 0.2rem 0 0;
}

#settings-msg {
  margin-left: 0.6rem;
}

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

.logs {
  margin-top: 0.5rem;
  background: #0e2024;
  color: #d7fef8;
  border-radius: 10px;
  border: 1px solid #244047;
  padding: 0.65rem;
  min-height: 160px;
  max-height: 260px;
  overflow: auto;
  white-space: pre-wrap;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(15, 118, 110, 0.7);
  }
  70% {
    box-shadow: 0 0 0 7px rgba(15, 118, 110, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(15, 118, 110, 0);
  }
}

@keyframes glide {
  0% {
    background-position: 0% 50%;
  }
  100% {
    background-position: 100% 50%;
  }
}

@keyframes reveal {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 980px) {
  .grid-3,
  .output-grid,
  .phase-track {
    grid-template-columns: 1fr;
  }

  .container {
    width: min(1180px, 95vw);
    margin-top: 1rem;
  }

  textarea {
    min-height: 220px;
  }

  .questions-layout {
    grid-template-columns: 1fr !important;
  }

  .questions-list {
    max-height: 300px;
  }
}

/* ── Per-question panel ── */
.questions-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 0.8rem;
  margin-top: 0.5rem;
}

.questions-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  max-height: 600px;
  overflow-y: auto;
  padding-right: 0.3rem;
}

.question-item {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.65rem;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.question-item:hover {
  border-color: var(--accent);
  background: #f0faf8;
}

.question-item.active {
  border-color: var(--accent);
  background: #e0f5f0;
  box-shadow: 0 0 0 2px rgba(15, 118, 110, 0.15);
}

.q-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.2rem;
}

.q-num {
  font-weight: 700;
  font-size: 0.82rem;
  color: var(--accent);
}

.q-status {
  font-size: 0.78rem;
  font-weight: 600;
}

.q-complete {
  color: #166534;
}

.q-progress {
  color: #b45309;
}

.q-text {
  font-size: 0.82rem;
  line-height: 1.35;
  color: var(--ink);
}

.q-meta {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.question-detail {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.8rem 1rem;
  max-height: 600px;
  overflow-y: auto;
}

.question-detail-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

.q-detail-inner {
  animation: reveal 0.3s ease;
}

.q-detail-title {
  font-size: 1rem;
  margin: 0 0 0.4rem;
  color: var(--ink);
}

.q-detail-meta {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.7rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--line);
}

.q-section {
  margin-bottom: 0.7rem;
}

.q-section h4 {
  font-size: 0.9rem;
  margin: 0.5rem 0 0.3rem;
  color: var(--accent);
}

.q-content {
  font-size: 0.84rem;
  line-height: 1.5;
  color: var(--ink);
}

.q-kb-list {
  font-size: 0.8rem;
  line-height: 1.4;
}

.q-kb-entry {
  padding: 0.3rem 0;
  border-bottom: 1px solid #f0ece3;
}

.q-kb-src {
  font-weight: 600;
  color: var(--accent);
  font-size: 0.75rem;
}

/* ── File list + main file selector ── */
.file-list-container {
  margin-bottom: 0.8rem;
  padding: 0.6rem;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.file-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.file-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s;
}

.file-row:hover {
  background: #f0faf8;
}

.file-row input[type="radio"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

.file-row-name {
  flex: 1;
  font-size: 0.88rem;
  color: var(--ink);
  word-break: break-all;
}

.file-row-badge {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  background: #e7efed;
  color: var(--accent);
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
}

/* ── History ── */
.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 400px;
  overflow-y: auto;
}

.history-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
}

.h-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.2rem;
}

.h-date {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink);
}

.h-status {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.1rem 0.4rem;
  border-radius: 6px;
}

.h-ok {
  background: #dff5ee;
  color: #166534;
}

.h-fail {
  background: #ffe1e1;
  color: #b91c1c;
}

.h-meta {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.h-actions {
  display: flex;
  gap: 0.4rem;
}

.btn-small {
  font-size: 0.78rem;
  padding: 0.3rem 0.6rem;
  background: var(--accent);
  color: #f3fffe;
  border-radius: 8px;
}

.btn-small.btn-accent {
  background: var(--accent-2);
  color: #fff8f4;
}

.history-viewer {
  margin-top: 0.8rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.8rem;
  background: #fff;
}

.history-viewer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.history-viewer-header h3 {
  margin: 0;
}

#history-viewer-content {
  min-height: 300px;
  width: 100%;
}
