:root {
  --bg: #f2efe8;
  --bg-deep: #e7e0d2;
  --panel: rgba(255, 252, 246, 0.82);
  --panel-strong: rgba(255, 250, 240, 0.96);
  --text: #1f1b16;
  --muted: #665d52;
  --line: rgba(67, 48, 29, 0.14);
  --accent: #0c7c59;
  --accent-strong: #074c39;
  --warning: #b35c1e;
  --shadow: 0 22px 70px rgba(57, 39, 20, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "IBM Plex Sans", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(240, 149, 75, 0.16), transparent 30%),
    radial-gradient(circle at top right, rgba(12, 124, 89, 0.16), transparent 30%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
}

.shell {
  width: min(1840px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 32px 0 48px;
}

.hero {
  display: grid;
  grid-template-columns: 1.4fr 0.8fr;
  gap: 24px;
  align-items: end;
  margin-bottom: 24px;
}

.hero-copy h1,
.panel h2,
.breakdown-card h3,
.formula h3 {
  font-family: "Space Grotesk", sans-serif;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 10px;
  color: var(--accent-strong);
  font-size: 0.92rem;
  font-weight: 700;
  text-transform: uppercase;
}

.hero-copy h1 {
  margin: 0;
  font-size: clamp(2.5rem, 5vw, 4.7rem);
  line-height: 0.95;
  max-width: 11ch;
}

.lede {
  max-width: 58ch;
  color: var(--muted);
  font-size: 1.02rem;
  line-height: 1.65;
}

.hero-stat,
.panel,
.breakdown-card,
.formula {
  backdrop-filter: blur(18px);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.hero-stat {
  padding: 24px;
  border-radius: 8px;
  background: linear-gradient(160deg, rgba(12, 124, 89, 0.95), rgba(7, 76, 57, 0.9));
  color: #f9f7f0;
}

.hero-stat span,
.hero-stat small {
  display: block;
}

.hero-stat strong {
  display: block;
  margin: 10px 0 8px;
  font-family: "Space Grotesk", sans-serif;
  font-size: clamp(2rem, 4vw, 3.4rem);
  line-height: 0.95;
}

.hero-stat small {
  color: rgba(249, 247, 240, 0.75);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(270px, 320px) minmax(0, 1fr);
  gap: 24px;
}

.panel {
  border-radius: 8px;
  background: var(--panel);
  padding: 22px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.panel-heading h2 {
  margin: 0;
  font-size: 1.2rem;
}

.panel-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.ghost-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.42);
  color: var(--text);
  padding: 10px 14px;
  font: inherit;
  cursor: pointer;
}

.field-grid {
  display: grid;
  gap: 14px;
}

.hf-row, .row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

.row-4 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 12px;
}

.fetch-status {
  color: var(--muted);
  font-size: 0.82rem;
  align-self: center;
}

.field {
  display: grid;
  gap: 8px;
}

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

.field small {
  color: var(--muted);
  font-size: 0.82rem;
}

.field input {
  width: 100%;
  border: 1px solid rgba(67, 48, 29, 0.18);
  border-radius: 8px;
  padding: 14px 15px;
  background: var(--panel-strong);
  color: var(--text);
  font: inherit;
}

.field input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.field input[type="number"]::-webkit-inner-spin-button,
.field input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.field select {
  width: 100%;
  border: 1px solid rgba(67, 48, 29, 0.18);
  border-radius: 8px;
  padding: 14px 15px;
  background: var(--panel-strong);
  color: var(--text);
  font: inherit;
}

.field input:focus,
.field select:focus {
  outline: 2px solid rgba(12, 124, 89, 0.24);
  border-color: rgba(12, 124, 89, 0.4);
}

.field.fetched input {
  background: rgba(12, 124, 89, 0.06);
  border-color: rgba(12, 124, 89, 0.18);
  cursor: default;
  color: var(--accent-strong);
  font-weight: 500;
}

.chain-tag {
  font-style: normal;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
  background: rgba(12, 124, 89, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 6px;
  vertical-align: middle;
}

.field.config input {
  background: rgba(179, 92, 30, 0.06);
  border-color: rgba(179, 92, 30, 0.18);
  cursor: default;
  color: #8b5e2f;
  font-weight: 500;
}

.config-tag {
  font-style: normal;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--warning);
  background: rgba(179, 92, 30, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 6px;
  vertical-align: middle;
}

.group-title {
  font-family: "Space Grotesk", sans-serif;
  font-size: 0.88rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 20px 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

.group-title:first-of-type {
  margin-top: 0;
}

.note {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.6;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.metric {
  min-height: 140px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 251, 246, 0.84);
}

.metric.accent {
  background: linear-gradient(160deg, rgba(255, 236, 214, 0.95), rgba(255, 248, 238, 0.92));
}

.metric span,
.metric small {
  display: block;
}

.metric span {
  color: var(--muted);
  font-size: 0.92rem;
}

.metric strong {
  display: block;
  margin: 16px 0 10px;
  font-family: "Space Grotesk", sans-serif;
  font-size: clamp(1.7rem, 3vw, 2.7rem);
  line-height: 1;
}

.metric small {
  color: var(--accent-strong);
  line-height: 1.5;
}

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

.breakdown-card {
  border-radius: 8px;
  background: rgba(255, 250, 242, 0.76);
  padding: 18px;
}

.breakdown-card h3 {
  margin: 0 0 14px;
  font-size: 1rem;
}

.breakdown-card dl {
  margin: 0;
  display: grid;
  gap: 12px;
}

.breakdown-card div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.breakdown-card div:last-child {
  border-bottom: 0;
  padding-bottom: 0;
}

.breakdown-card dt {
  color: var(--muted);
  font-size: 0.9rem;
}

.breakdown-card dd {
  margin: 0;
  font-weight: 600;
  text-align: right;
}

.formula {
  margin-top: 14px;
  border-radius: 8px;
  background: rgba(255, 247, 236, 0.75);
  padding: 18px;
}

.formula h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.formula p {
  margin: 0;
  color: var(--muted);
  line-height: 1.7;
}

code {
  font-family: "IBM Plex Sans", sans-serif;
  font-size: 0.95em;
  background: rgba(12, 124, 89, 0.08);
  border-radius: 6px;
  padding: 2px 6px;
}

.negative {
  color: var(--warning) !important;
}

.snapshot-panel {
  grid-column: 1 / -1;
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 250, 242, 0.78);
  padding: 18px;
}

.snapshot-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.snapshot-heading h3 {
  margin: 0 0 4px;
  font-family: "Space Grotesk", sans-serif;
  font-size: 1rem;
}

.snapshot-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

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

.snapshot-heading span {
  flex: 0 0 auto;
  border: 1px solid rgba(12, 124, 89, 0.18);
  border-radius: 999px;
  background: rgba(12, 124, 89, 0.08);
  color: var(--accent-strong);
  font-size: 0.8rem;
  font-weight: 700;
  padding: 6px 10px;
}

.snapshot-refresh {
  padding: 8px 12px;
  font-size: 0.85rem;
}

.snapshot-table-wrap {
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(67, 48, 29, 0.2) transparent;
}

.snapshot-table {
  width: 100%;
  min-width: 1200px;
  border-collapse: collapse;
  table-layout: fixed;
  font-variant-numeric: tabular-nums;
}

.snapshot-table th,
.snapshot-table td {
  border-bottom: 1px solid var(--line);
  padding: 8px 4px;
  text-align: right;
}

.snapshot-table th {
  color: var(--muted);
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: normal;
}

.snapshot-table td {
  font-size: 0.76rem;
  white-space: nowrap;
}

.snapshot-table th:nth-child(odd),
.snapshot-table .projected-cell {
  background: rgba(219, 39, 119, 0.075);
}

.snapshot-table th:nth-child(even),
.snapshot-table .real-cell {
  background: rgba(12, 124, 89, 0.075);
}

.snapshot-table .projected-cell {
  color: #8a124d;
}

.snapshot-table .real-cell {
  color: var(--accent-strong);
}

.snapshot-table .real-cell:empty {
  color: var(--muted);
}

.snapshot-table th:first-child,
.snapshot-table td:first-child,
.snapshot-table th:nth-child(2),
.snapshot-table td:nth-child(2) {
  text-align: left;
}

.snapshot-table tbody tr.current {
  background: rgba(12, 124, 89, 0.08);
}

.snapshot-table tbody tr.target {
  background: rgba(255, 236, 214, 0.6);
}

.snapshot-table tbody tr:last-child td {
  border-bottom: 0;
}

/* ── Tab bar ── */
.tab-bar {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  background: rgba(255, 252, 246, 0.6);
  backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px;
  width: fit-content;
}

.tab-btn {
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  padding: 10px 20px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.tab-btn:hover {
  background: rgba(12, 124, 89, 0.08);
  color: var(--text);
}

.tab-btn.active {
  background: var(--accent);
  color: #f9f7f0;
  box-shadow: 0 2px 8px rgba(12, 124, 89, 0.3);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: grid;
}

#tab-logs.active {
  display: grid;
}

/* ── Log panel ── */
.log-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  max-width: 100%;
  min-height: calc(100vh - 230px);
}

.log-controls {
  display: flex;
  gap: 8px;
  align-items: center;
}

.log-filter-select {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  padding: 8px 12px;
  cursor: pointer;
}

.log-filter-select:focus {
  outline: 2px solid rgba(12, 124, 89, 0.24);
  border-color: rgba(12, 124, 89, 0.4);
}

/* ── Log stats ── */
.log-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.log-stat-item {
  text-align: center;
  padding: 14px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 251, 246, 0.84);
  transition: transform 0.15s ease;
}

.log-stat-item:hover {
  transform: translateY(-2px);
}

.log-stat-item.up {
  background: linear-gradient(160deg, rgba(16, 185, 129, 0.12), rgba(16, 185, 129, 0.04));
  border-color: rgba(16, 185, 129, 0.2);
}

.log-stat-item.down {
  background: linear-gradient(160deg, rgba(239, 68, 68, 0.1), rgba(239, 68, 68, 0.03));
  border-color: rgba(239, 68, 68, 0.18);
}

.log-stat-item.buffer {
  background: linear-gradient(160deg, rgba(59, 130, 246, 0.1), rgba(59, 130, 246, 0.03));
  border-color: rgba(59, 130, 246, 0.18);
}

.log-stat-item.total {
  background: linear-gradient(160deg, rgba(168, 128, 84, 0.12), rgba(168, 128, 84, 0.04));
  border-color: rgba(168, 128, 84, 0.18);
}

.fee-stats {
  display: grid;
  grid-template-columns: 1.35fr repeat(3, 1fr);
  gap: 12px;
  margin: -4px 0 20px;
}

.fee-stat-item {
  padding: 16px;
  border: 1px solid rgba(67, 48, 29, 0.12);
  border-radius: 10px;
  background: rgba(255, 251, 246, 0.72);
}

.fee-stat-item.total-fees {
  background: linear-gradient(135deg, rgba(7, 76, 57, 0.95), rgba(12, 124, 89, 0.9));
  color: #f9f7f0;
  box-shadow: 0 14px 34px rgba(7, 76, 57, 0.16);
}

.fee-stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.fee-stat-item.total-fees .fee-stat-label {
  color: rgba(249, 247, 240, 0.72);
}

.fee-stat-item strong {
  display: block;
  font-family: "Space Grotesk", sans-serif;
  font-size: clamp(1.35rem, 2.4vw, 2.15rem);
  line-height: 1;
}

.log-stat-value {
  display: block;
  font-family: "Space Grotesk", sans-serif;
  font-size: 1.8rem;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 4px;
}

.log-stat-item.up .log-stat-value { color: #059669; }
.log-stat-item.down .log-stat-value { color: #dc2626; }
.log-stat-item.buffer .log-stat-value { color: #2563eb; }
.log-stat-item.total .log-stat-value { color: var(--text); }

.log-stat-label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 500;
}

/* ── Log timeline ── */
.log-timeline {
  min-height: calc(100vh - 430px);
  max-height: none;
  overflow: visible;
  display: flex;
  flex-direction: column;
  gap: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(67, 48, 29, 0.18) transparent;
}

.log-timeline::-webkit-scrollbar {
  width: 6px;
}
.log-timeline::-webkit-scrollbar-track {
  background: transparent;
}
.log-timeline::-webkit-scrollbar-thumb {
  background: rgba(67, 48, 29, 0.18);
  border-radius: 3px;
}

.log-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.log-page-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  text-align: center;
}

.log-loading {
  color: var(--muted);
  text-align: center;
  padding: 48px 0;
  font-style: italic;
}

.log-empty {
  color: var(--muted);
  text-align: center;
  padding: 48px 0;
}

/* ── Log entry (paired trigger + complete) ── */
.log-entry {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
  animation: logFadeIn 0.3s ease;
}

.log-entry:last-child {
  border-bottom: none;
}

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

.log-time {
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 500;
  padding-top: 2px;
  font-variant-numeric: tabular-nums;
}

.log-time .log-date {
  display: block;
  font-size: 0.74rem;
  color: rgba(102, 93, 82, 0.6);
}

.log-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.log-action-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.log-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 10px;
  border-radius: 6px;
  white-space: nowrap;
}

.log-badge.up {
  background: rgba(16, 185, 129, 0.14);
  color: #059669;
}

.log-badge.down {
  background: rgba(239, 68, 68, 0.12);
  color: #dc2626;
}

.log-badge.buffer {
  background: rgba(59, 130, 246, 0.12);
  color: #2563eb;
}

.log-badge-type {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--muted);
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(67, 48, 29, 0.06);
}

.log-details {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 0.85rem;
  color: var(--muted);
}

.log-detail-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.log-detail-item strong {
  color: var(--text);
  font-weight: 600;
}

.log-result {
  font-size: 0.85rem;
  color: var(--accent-strong);
  font-weight: 500;
  margin-top: 2px;
}

.log-result.pending {
  color: var(--muted);
  font-style: italic;
}

@media (max-width: 980px) {
  .hero,
  .workspace,
  .breakdown {
    grid-template-columns: 1fr;
  }

  .hero-copy h1 {
    max-width: 14ch;
  }

  .log-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .fee-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .log-entry {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .log-panel {
    min-height: calc(100vh - 260px);
  }

  .log-timeline {
    min-height: calc(100vh - 500px);
  }
}

@media (max-width: 640px) {
  .shell {
    width: min(100vw - 20px, 1180px);
    padding-top: 20px;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .panel,
  .hero-stat,
  .breakdown-card,
  .formula,
  .snapshot-panel {
    padding: 18px;
  }

  .snapshot-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .snapshot-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .snapshot-heading span {
    width: fit-content;
  }

  .snapshot-table {
    min-width: 0;
  }

  .snapshot-table thead {
    display: none;
  }

  .snapshot-table,
  .snapshot-table tbody,
  .snapshot-table tr,
  .snapshot-table td {
    display: block;
    width: 100%;
  }

  .snapshot-table tr {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 251, 246, 0.72);
    margin-bottom: 10px;
    padding: 8px 10px;
  }

  .snapshot-table th,
  .snapshot-table td {
    white-space: normal;
  }

  .snapshot-table td {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    border-bottom: 1px solid rgba(67, 48, 29, 0.1);
    padding: 9px 0;
    text-align: right;
  }

  .snapshot-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 600;
    text-align: left;
  }

  .snapshot-table td:last-child {
    border-bottom: 0;
  }

  .hero-copy h1 {
    font-size: clamp(2rem, 12vw, 3.2rem);
  }

  .log-stats {
    grid-template-columns: 1fr 1fr;
  }

  .fee-stats {
    grid-template-columns: 1fr;
  }

  .log-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .log-panel {
    min-height: calc(100vh - 220px);
  }

  .log-timeline {
    min-height: 55vh;
  }
}
