* { box-sizing: border-box; }

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  margin: 0;
  padding: 20px;
  background: #020617;
  color: #e5e7eb;
}

h1 {
  margin-top: 0;
  margin-bottom: 0.25rem;
  font-size: 1.5rem;
}

.subtitle {
  margin-bottom: 1rem;
  font-size: 0.875rem;
  color: #9ca3af;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.1fr);
  gap: 20px;
  align-items: start;
}

textarea {
  width: 100%;
  height: 260px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid #4b5563;
  background: #020617;
  color: #e5e7eb;
  resize: vertical;
  font-size: 0.9rem;
  line-height: 1.4;
  outline: none;
}

textarea:focus {
  border-color: #22c55e;
  box-shadow: 0 0 0 1px rgba(34, 197, 94, 0.35);
}

button {
  margin-top: 10px;
  padding: 8px 18px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  background: linear-gradient(135deg, #22c55e, #06b6d4);
  color: #022c22;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

button:disabled {
  opacity: 0.55;
  cursor: wait;
}

button .loader {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  border: 2px solid rgba(15, 23, 42, 0.6);
  border-top-color: #022c22;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.totals {
  margin-top: 12px;
  font-size: 0.85rem;
}

.totals span {
  margin-right: 16px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(55, 65, 81, 0.9);
  font-size: 0.78rem;
}

.pill--ok {
  border-color: rgba(34, 197, 94, 0.8);
  background: rgba(22, 163, 74, 0.08);
  color: #bbf7d0;
}

.pill--warn {
  border-color: rgba(248, 250, 252, 0.7);
  background: rgba(15, 23, 42, 0.8);
  color: #fee2e2;
}

.grid-card {
  background: radial-gradient(circle at top, #0b1120 0, #020617 60%, #000 100%);
  border-radius: 18px;
  padding: 14px;
  border: 1px solid rgba(148, 163, 184, 0.3);
  box-shadow: 0 18px 45px rgba(15, 23, 42, 0.85);
}

.grid-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}

.grid-title {
  font-size: 0.95rem;
  font-weight: 600;
}

.grid-subtitle {
  font-size: 0.75rem;
  color: #9ca3af;
}

.number-grid {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 4px;
  font-size: 0.75rem;
}

.cell {
  position: relative;
  padding: 4px 4px 5px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(31, 41, 55, 0.9);
  min-height: 40px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}

.cell-num {
  font-size: 0.7rem;
  color: #9ca3af;
  text-align: left;
}

.cell-amt {
  font-size: 0.85rem;
  text-align: right;
}

.cell.zero .cell-amt {
  opacity: 0.18;
}

.cell.nonzero {
  border-color: rgba(34, 197, 94, 0.9);
  box-shadow:
    0 0 0 1px rgba(34, 197, 94, 0.3),
    0 0 20px rgba(34, 197, 94, 0.18);
  background: radial-gradient(circle at 20% 0, rgba(34, 197, 94, 0.25), #020617 55%);
}

.cell.nonzero .cell-num {
  color: #bbf7d0;
}

.cell.nonzero .cell-amt {
  color: #4ade80;
  font-weight: 600;
}

.cell-hint {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.08;
  background-image: radial-gradient(circle at 0 0, #22c55e 0, transparent 55%);
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

.report {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  font-size: 0.8rem;
}

.report-card {
  background: #020617;
  border-radius: 12px;
  padding: 8px 10px;
  border: 1px solid rgba(31, 41, 55, 0.9);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.7);
}

.report-label {
  color: #9ca3af;
  font-size: 0.75rem;
  margin-bottom: 2px;
}

.report-value {
  font-weight: 600;
  font-size: 0.9rem;
}

.report-highlight {
  color: #4ade80;
}

.report-warning {
  color: #f97373;
}

/* ==== BLOCK-DEBUG STYLES ==== */

.block-debug-card {
  margin-top: 12px; /* closer to totals */
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(55, 65, 81, 0.9);
  background: radial-gradient(circle at top left, #020617 0, #020617 40%, #000 100%);
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.8);
  max-height: 260px;
  overflow-y: auto;
  font-size: 0.78rem;
}

.block-debug-header {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.block-debug-subtitle {
  font-size: 0.72rem;
  font-weight: 400;
  color: #9ca3af;
}

.block-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Each block as a compact row */
.block-item {
  border-radius: 8px;
  border: 1px solid rgba(31, 41, 55, 0.8);
  background: rgba(15, 23, 42, 0.95);
  padding: 4px 6px;
  cursor: pointer;
}

.block-item:hover {
  background: rgba(30, 64, 175, 0.4);
}

.block-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1.4fr) minmax(0, 1.2fr) auto;
  align-items: center;
  gap: 4px;
}

.block-id {
  font-weight: 600;
  color: #e5e7eb;
}

.block-preview {
  color: #9ca3af;
  font-size: 0.75rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.block-pill {
  justify-self: flex-start;
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 0.7rem;
  white-space: nowrap;
}

.block-pill--neutral {
  background: rgba(31, 41, 55, 0.9);
  color: #e5e7eb;
}

.block-pill--ok {
  background: rgba(34, 197, 94, 0.18);
  color: #4ade80;
  border: 1px solid rgba(34, 197, 94, 0.6);
}

.block-pill--warn {
  background: rgba(239, 68, 68, 0.18);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.6);
}

.block-meta {
  font-size: 0.7rem;
  color: #9ca3af;
  text-align: right;
}

/* Hidden details section */
.block-detail {
  display: none;
  margin-top: 4px;
  border-top: 1px dashed rgba(55, 65, 81, 0.8);
  padding-top: 4px;
  gap: 4px;
}

.block-item--open .block-detail {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1.3fr);
}

.block-detail-section {
  min-width: 0;
}

.block-detail-label {
  font-size: 0.7rem;
  color: #9ca3af;
  margin-bottom: 2px;
}

.block-raw {
  margin: 0;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  font-size: 0.7rem;
  color: #e5e7eb;
  max-height: 120px;
  overflow-y: auto;
}

.block-detail-numbers {
  font-size: 0.7rem;
  color: #e5e7eb;
  max-height: 120px;
  overflow-y: auto;
}

@media (max-width: 900px) {
  .block-row {
    grid-template-columns: auto minmax(0, 1.6fr);
    grid-template-rows: auto auto;
  }

  .block-pill {
    justify-self: flex-start;
  }

  .block-meta {
    justify-self: flex-end;
  }

  .block-item--open .block-detail {
    grid-template-columns: minmax(0, 1fr);
  }
}
/* === Block debug side-by-side layout === */

.block-list {
  /* remove internal vertical scrollbar if previously set */
  max-height: none;
  overflow-y: visible;
}

/* Single block container */
.block-item {
  margin-bottom: 12px;
  padding: 10px;
  background: #ffffff;
  border-radius: 6px;
  border: 1px solid #ddd;
  font-size: 13px;
}

/* Optional small header line for each block */
.block-item-header {
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Two-column layout inside one block */
.block-two-col {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

/* Important so grid children wrap properly */
.block-col {
  min-width: 0;
}

.block-col-title {
  font-weight: 600;
  font-size: 12px;
  margin-bottom: 4px;
}

/* Raw + parsed boxes */
.block-raw-box,
.block-parsed-box {
  background: #fafafa;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  padding: 6px;
  white-space: pre-wrap;   /* preserve newlines, allow wrapping */
  word-wrap: break-word;   /* long runs wrap instead of scrolling */
  line-height: 1.4;
}

/* Parsed meta info (totals + status) */
.block-parsed-meta {
  font-size: 11px;
  color: #4b5563;
  margin-bottom: 4px;
}

/* Each parsed number line */
.block-parsed-line {
  font-family: monospace;
  font-size: 12px;
}

/* Warnings in block */
.block-warning {
  margin-top: 4px;
  font-size: 11px;
  color: #b45309;
}

/* Small badges for status */
.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10px;
  color: #fff;
  margin-left: 6px;
}

.badge-ok {
  background: #16a34a;
}

.badge-mismatch {
  background: #f97316;
}

.badge-mode-ok {
  background: #16a34a;
}

.badge-mode-mixed {
  background: #f97316;
}

.badge-mode-raw {
  background: #6b7280;
}
/* === Block debug side-by-side layout (RAW vs Parsed) === */

.block-list {
  /* Let blocks grow naturally; page scrolls instead */
  max-height: none;
  overflow-y: visible;
}

/* Outer card for each block */
.block-item {
  margin-bottom: 12px;
  padding: 10px;
  background: #ffffff;
  border-radius: 6px;
  border: 1px solid #ddd;
  font-size: 13px;
}

/* Header row inside block: "Block #1   nums: 7" */
.block-item-header {
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Two columns inside a block */
.block-two-col {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

/* Ensure content wraps correctly inside grid */
.block-col {
  min-width: 0;
}

.block-col-title {
  font-weight: 600;
  font-size: 12px;
  margin-bottom: 4px;
}

/* RAW + Parsed boxes */
.block-raw-box,
.block-parsed-box {
  background: #fafafa;
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  padding: 6px;
  white-space: pre-wrap;   /* preserve newlines, wrap long lines */
  word-wrap: break-word;
  line-height: 1.4;
}

/* Parsed meta info (totals) */
.block-parsed-meta {
  font-size: 11px;
  color: #4b5563;
  margin-bottom: 4px;
}

/* Each parsed number line */
.block-parsed-line {
  font-family: monospace;
  font-size: 12px;
}

/* Warnings in a block */
.block-warning {
  margin-top: 4px;
  font-size: 11px;
  color: #b45309;
}

/* Status badges */
.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10px;
  color: #fff;
  margin-left: 6px;
}

.badge-ok {
  background: #16a34a;
}

.badge-mismatch {
  background: #f97316;
}
