:root {
  --bg: #12161c;
  --bg-soft: #1a2028;
  --panel: #1c232d;
  --inset: #151a22;
  --ink: #e8edf4;
  --ink-soft: #a8b3c4;
  --mute: #7b8798;
  --line: #2c3542;
  --line-strong: #3a4656;
  --accent: #5fa8b5;
  --accent-soft: rgba(95, 168, 181, 0.14);
  --accent-2: #7eb6d4;
  --sauron: #5fa8b5;
  --chimera: #7a9fd0;
  --chimera-soft: rgba(122, 159, 208, 0.14);
  --warn: #e07a6c;
  --warn-soft: rgba(224, 122, 108, 0.12);
  --ok: #6fbf95;
  --ok-soft: rgba(111, 191, 149, 0.12);
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.25);
  --radius: 14px;
  --font: "Manrope", sans-serif;
  --display: "Source Serif 4", Georgia, serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
}

.fx {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}

.fx-glow {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 12% 0%, rgba(95, 168, 181, 0.1), transparent 42%),
    radial-gradient(ellipse at 88% 8%, rgba(122, 159, 208, 0.08), transparent 40%),
    linear-gradient(180deg, #161b22 0%, #10141a 100%);
}

.fx-grid,
.fx-scan { display: none; }

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

.balance-badge {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 104px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(28, 35, 45, 0.92);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(8px);
}

.balance-kicker {
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--mute);
  font-weight: 700;
}

.balance-value {
  font-family: var(--display);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.1;
}

.balance-badge.is-low .balance-value { color: #b8860b; }
.balance-badge.is-empty .balance-value,
.balance-badge.is-error .balance-value { color: var(--warn); }

.stage {
  position: relative;
  z-index: 1;
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 72px 18px 48px;
}

.stage.stage-wide { width: min(1260px, 100%); }

.upload-layout {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.upload-main {
  min-width: 0;
  animation: fadeIn 0.35s ease;
}

.screen { display: none; width: 100%; }
.screen.active { display: block; animation: fadeIn 0.3s ease; }

#screen-loading.active,
#screen-report.active {
  display: flex;
  justify-content: center;
}

.prompt-panel {
  position: sticky;
  top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: calc(100vh - 32px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.prompt-panel .console-bar { margin: 0; }

.prompt-hint {
  margin: 0;
  padding: 0 14px;
  color: var(--mute);
  font-size: 0.8rem;
  line-height: 1.45;
}

.prompt-editor {
  flex: 1;
  min-height: 240px;
  margin: 0 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--inset);
  color: var(--ink-soft);
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.72rem;
  line-height: 1.5;
  resize: vertical;
}

.prompt-editor:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.prompt-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--line);
  background: var(--bg-soft);
}

.prompt-toolbar-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  min-width: 180px;
}

.prompt-btn { padding: 8px 10px; }

.hero { margin-bottom: 16px; }

.brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.brand {
  font-family: var(--display);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--ok);
}

.status-pill .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
}

.title {
  margin: 0 0 8px;
  font-family: var(--display);
  font-size: clamp(2.1rem, 5vw, 3rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.05;
  color: var(--ink);
}

.subtitle {
  margin: 0;
  max-width: 36rem;
  color: var(--ink-soft);
  font-size: 1.02rem;
  line-height: 1.55;
}

.subtitle b {
  color: var(--ink);
  font-weight: 700;
}

.steps {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0 14px;
}

.step {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--mute);
  font-size: 0.78rem;
  font-weight: 700;
}

.step span { color: var(--accent); }

.step.on {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--ink);
}

.step.on span { color: var(--accent); }

.console {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.console-bar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
  text-transform: uppercase;
}

.console-meta {
  color: var(--mute);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: none;
}

.section-head,
.console > .section-head,
.console .section-head {
  margin: 14px 16px 8px;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--mute);
}

.sources-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 16px;
}

.source-block { display: grid; gap: 8px; }

.source-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 800;
  color: var(--sauron);
  font-size: 0.92rem;
}

.source-name.chimera { color: var(--chimera); }

.source-name i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.dropzone {
  position: relative;
  display: grid;
  gap: 5px;
  min-height: 150px;
  padding: 18px 16px;
  border: 1.5px dashed var(--line-strong);
  border-radius: 12px;
  background: var(--inset);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}

.dropzone.chimera {
  background: #161c26;
}

.dropzone:hover,
.dropzone.dragover {
  border-color: var(--sauron);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(95, 168, 181, 0.18);
}

.dropzone.chimera:hover,
.dropzone.chimera.dragover {
  border-color: var(--chimera);
  background: var(--chimera-soft);
}

.dropzone.has-file {
  border-style: solid;
  border-color: var(--sauron);
  background: var(--accent-soft);
}

.dropzone.chimera.has-file {
  border-color: var(--chimera);
  background: var(--chimera-soft);
}

.drop-kicker {
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  font-weight: 800;
  color: var(--sauron);
  text-transform: uppercase;
}

.dropzone.chimera .drop-kicker { color: var(--chimera); }

.drop-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.25;
}

.drop-hint {
  color: var(--mute);
  font-size: 0.84rem;
}

.file-name {
  margin-top: 4px;
  color: var(--ink-soft);
  font-size: 0.8rem;
  font-weight: 600;
  word-break: break-all;
  min-height: 1.15em;
}

.drop-ready {
  display: none;
  position: absolute;
  top: 12px;
  right: 12px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--sauron);
  color: #0e1518;
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.dropzone.chimera .drop-ready {
  background: var(--chimera);
  color: #10151c;
}
.dropzone.has-file .drop-ready { display: inline-block; }

.fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 0 16px 4px;
}

.fields input {
  width: 100%;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--inset);
  color: var(--ink);
  font: inherit;
  font-size: 0.92rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.fields input::placeholder { color: #5f6b7c; }

.fields input:focus {
  outline: none;
  border-color: var(--accent);
  background: #1a2028;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.fields input:nth-child(5),
.fields input:nth-child(6) { grid-column: 1 / -1; }

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px 16px;
}

.source-btns { padding: 0; }

.main-actions {
  margin-top: 2px;
  grid-template-columns: 0.7fr 1.3fr;
  border-top: 1px solid var(--line);
  background: var(--bg-soft);
}

.queue-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.4em;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent);
  color: #0e1518;
  font-size: 0.72rem;
  font-weight: 800;
}

.queue-panel {
  margin: 0 16px 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--inset);
}

.queue-hint {
  margin: 0 0 10px;
  color: var(--mute);
  font-size: 0.84rem;
  line-height: 1.45;
}

.queue-list {
  list-style: none;
  margin: 0 0 10px;
  padding: 0;
  display: grid;
  gap: 8px;
}

.queue-item {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}

.queue-item-main { min-width: 0; }
.queue-item-main strong {
  display: block;
  font-size: 0.9rem;
  color: var(--ink);
}
.queue-item-main small {
  color: var(--mute);
  font-size: 0.75rem;
}

.queue-remove {
  border: 0;
  background: transparent;
  color: var(--warn);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.queue-actions { padding: 0; }

.btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  border: 0;
  border-radius: 11px;
  padding: 11px 14px;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.btn strong { font-weight: 800; font-size: 0.9rem; }
.btn small { opacity: 0.75; font-size: 0.74rem; }
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: 0.55; cursor: wait; transform: none; }

.btn-primary {
  color: #0e1518;
  background: var(--accent);
  box-shadow: 0 8px 20px rgba(95, 168, 181, 0.2);
}

.btn-primary:hover { background: #74b8c4; }

.btn-secondary {
  color: var(--ink);
  background: var(--inset);
  border: 1px solid var(--line);
}

.btn-secondary:hover { background: #1f2732; }

.btn-ghost {
  color: var(--ink-soft);
  background: transparent;
  border: 1px solid var(--line);
}

.btn-ghost:hover {
  color: var(--ink);
  background: var(--panel);
}

.btn-danger {
  color: var(--warn);
  background: var(--warn-soft);
  border: 1px solid rgba(224, 122, 108, 0.35);
}

.form-error {
  color: var(--warn);
  min-height: 1.15em;
  margin: 0 16px 14px;
  font-size: 0.88rem;
}

.loading-panel {
  width: min(500px, 94vw);
  margin: 48px auto;
  padding: 0 0 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  text-align: center;
}

.loading-bar { margin: 0 0 16px; text-align: left; }

.loading-label {
  font-family: var(--display);
  font-size: clamp(1.4rem, 3.5vw, 1.9rem);
  font-weight: 700;
  color: var(--ink);
  margin: 0 18px 14px;
}

.progress-shell {
  height: 10px;
  margin: 0 18px;
  border-radius: 999px;
  background: var(--inset);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.3s ease;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin: 10px 18px 0;
  color: var(--mute);
  font-size: 0.84rem;
}

#progress-pct {
  color: var(--accent);
  font-weight: 800;
}

#progress-detail {
  max-width: 75%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
}

.loading-section-head { text-align: left; }

.batch-progress {
  list-style: none;
  margin: 0 18px 8px;
  padding: 0;
  display: grid;
  gap: 8px;
  text-align: left;
}

.batch-row {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--inset);
}

.batch-row-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.batch-row-top strong { font-size: 0.88rem; }
.batch-row-top span { color: var(--mute); font-size: 0.78rem; }

.batch-row-bar {
  height: 5px;
  border-radius: 999px;
  background: #0f141a;
  overflow: hidden;
}

.batch-row-bar i {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--accent);
}

.batch-row small {
  display: block;
  margin-top: 6px;
  color: var(--mute);
  font-size: 0.74rem;
}

.batch-row-tag {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--mute);
}

.batch-row.status-done {
  border-color: rgba(111, 191, 149, 0.35);
  background: var(--ok-soft);
}
.batch-row.status-done .batch-row-tag { color: var(--ok); }
.batch-row.status-error {
  border-color: rgba(224, 122, 108, 0.35);
  background: var(--warn-soft);
}
.batch-row.status-error .batch-row-tag { color: var(--warn); }

.mascot {
  width: min(220px, 52vw);
  margin: 14px auto 0;
  display: block;
  opacity: 0.92;
}

.mascot-sm { width: min(150px, 40vw); }

.loading-actions {
  width: min(260px, 100%);
  margin: 14px auto 0;
  padding: 0 18px;
  grid-template-columns: 1fr;
}

#screen-report.active {
  align-items: stretch;
  padding: 18px 0 28px;
}

.report-shell {
  width: min(900px, 96vw);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 48px);
}

.report-chrome {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 8px 4px 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}

.report-chrome-left {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  min-width: 0;
}

.report-status-dot {
  width: 9px;
  height: 9px;
  margin-top: 10px;
  border-radius: 50%;
  background: var(--ok);
  flex-shrink: 0;
}

.path {
  margin: 4px 0 0;
  color: var(--mute);
  font-size: 0.8rem;
  word-break: break-all;
  max-width: min(520px, 70vw);
}

.report-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.report-chip {
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  font-size: 0.66rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}

.report-actions {
  padding: 0;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 0 0 14px;
}

.roster-panel {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.roster-panel .console-bar { margin: 0; }

.roster-hint {
  margin: 10px 16px;
  color: var(--mute);
  font-size: 0.84rem;
}

.roster-list {
  list-style: none;
  margin: 0 16px 16px;
  padding: 0;
  display: grid;
  gap: 8px;
}

.roster-card {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--inset);
}

.roster-card.on {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.roster-card.error {
  border-color: rgba(224, 122, 108, 0.35);
  background: var(--warn-soft);
}

.roster-select {
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font: inherit;
  min-width: 0;
  flex: 1;
  color: inherit;
}

.roster-select strong {
  display: block;
  color: var(--ink);
  font-size: 0.9rem;
}

.roster-select small {
  color: var(--mute);
  font-size: 0.75rem;
}

.roster-actions { display: flex; gap: 6px; }

.roster-dl {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 8px 10px;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}

.roster-dl:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.roster-dl:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.report-frame {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.report-frame-bar {
  display: flex;
  justify-content: space-between;
  padding: 11px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.report-scroll-hint {
  color: var(--mute);
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
}

.report-body {
  flex: 1;
  overflow: auto;
  padding: 24px 26px 40px;
  color: var(--ink-soft);
  font-size: 0.95rem;
  line-height: 1.65;
  background: var(--panel);
}

.report-body h1,
.report-body h2,
.report-body h3 {
  font-family: var(--display);
  line-height: 1.25;
  color: var(--ink);
}

.report-body h1 { font-size: 1.55rem; margin: 0 0 14px; }
.report-body h2 {
  font-size: 1.2rem;
  margin: 26px 0 10px;
  color: var(--accent);
}
.report-body h3 { font-size: 1.05rem; margin: 18px 0 8px; }

.report-body p { margin: 0 0 12px; }
.report-body ul,
.report-body ol {
  margin: 0 0 14px;
  padding-left: 1.2rem;
}
.report-body li { margin: 0 0 4px; }

.report-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0 18px;
  font-size: 0.88rem;
}

.report-body th,
.report-body td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  vertical-align: top;
  text-align: left;
}

.report-body th {
  background: var(--bg-soft);
  font-weight: 800;
  color: var(--ink);
}

.report-body a { color: var(--accent-2); }

.report-body code,
.report-body pre {
  font-family: ui-monospace, "Cascadia Code", monospace;
  font-size: 0.86em;
  background: var(--inset);
}

.report-body pre {
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.report-body blockquote {
  margin: 12px 0;
  padding: 8px 14px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  color: var(--ink-soft);
  border-radius: 0 8px 8px 0;
}

@media (max-width: 980px) {
  .upload-layout { grid-template-columns: 1fr; }
  .prompt-panel {
    position: relative;
    top: 0;
    max-height: none;
  }
  .prompt-editor { min-height: 170px; }
}

@media (max-width: 720px) {
  .stage { padding: 64px 12px 36px; }
  .balance-badge {
    top: 10px;
    left: 10px;
    padding: 8px 10px;
  }
  .balance-value { font-size: 1.1rem; }
  .sources-grid,
  .fields,
  .report-actions,
  .main-actions,
  .btn-row {
    grid-template-columns: 1fr;
  }
  .title { font-size: 2rem; }
  .dropzone { min-height: 130px; }
}
