:root {
  --bg: #f3efe7;
  --panel: rgba(255, 252, 247, 0.88);
  --panel-strong: #fffaf1;
  --text: #11211f;
  --muted: #516160;
  --line: rgba(17, 33, 31, 0.1);
  --accent: #007f73;
  --accent-soft: rgba(0, 127, 115, 0.12);
  --danger: #b4432f;
  --danger-soft: rgba(180, 67, 47, 0.12);
  --shadow: 0 24px 80px rgba(26, 35, 33, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(0, 127, 115, 0.14), transparent 28%),
    radial-gradient(circle at top right, rgba(255, 166, 0, 0.12), transparent 24%),
    linear-gradient(180deg, #f8f4ec 0%, var(--bg) 100%);
}

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

.hero,
.controls,
.table-shell,
.stats {
  animation: rise 0.45s ease both;
}

.hero {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.eyebrow,
.label {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 12px;
  color: var(--muted);
}

h1 {
  margin: 8px 0 10px;
  font-size: clamp(34px, 6vw, 64px);
  line-height: 0.98;
  max-width: 10ch;
}

.sub {
  margin: 0;
  max-width: 52ch;
  color: var(--muted);
  font-size: 16px;
}

.status-card,
.controls,
.table-shell,
.stat-card {
  background: var(--panel);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.7);
  box-shadow: var(--shadow);
}

.status-card {
  display: flex;
  gap: 12px;
  align-items: center;
  border-radius: 22px;
  padding: 16px 18px;
  min-width: 220px;
}

.status-dot {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  background: #d4a519;
  box-shadow: 0 0 0 6px rgba(212, 165, 25, 0.14);
}

.status-dot.live {
  background: var(--accent);
  box-shadow: 0 0 0 6px rgba(0, 127, 115, 0.14);
}

.status-dot.reconnecting {
  background: #d27b20;
  box-shadow: 0 0 0 6px rgba(210, 123, 32, 0.14);
}

.status-text {
  margin: 4px 0 0;
  font-size: 20px;
  font-weight: 700;
}

.controls {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) auto auto;
  gap: 16px;
  align-items: end;
  border-radius: 28px;
  padding: 18px;
}

.search,
.toggle,
.updated {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

input[type="search"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  font: inherit;
  background: rgba(255, 255, 255, 0.75);
}

.toggle {
  flex-direction: row;
  align-items: center;
  align-self: center;
  gap: 10px;
}

.toggle span {
  font-size: 14px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin: 18px 0;
}

.stat-card {
  border-radius: 24px;
  padding: 18px;
}

.stat-card strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.table-shell {
  overflow: auto;
  border-radius: 28px;
  padding: 12px;
}

.drawer-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 18px;
}

.drawer-head h2 {
  margin: 6px 0 0;
  font-size: clamp(24px, 3vw, 36px);
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17, 33, 31, 0.28);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
}

.drawer-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.history-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(760px, 100vw);
  height: 100vh;
  overflow: auto;
  padding: 24px;
  background: rgba(255, 252, 247, 0.96);
  backdrop-filter: blur(24px);
  box-shadow: -24px 0 80px rgba(26, 35, 33, 0.18);
  border-left: 1px solid rgba(255, 255, 255, 0.7);
  transform: translateX(100%);
  transition: transform 0.22s ease;
  z-index: 20;
}

.history-drawer.open {
  transform: translateX(0);
}

.drawer-close {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--text);
  font: inherit;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
}

.range-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

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

.range-tabs button.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.estimator-card {
  margin-bottom: 16px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--line);
  border-radius: 22px;
}

.estimator-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

.estimator-head h3 {
  margin: 6px 0 0;
  font-size: 22px;
}

.estimator-note {
  margin: 0;
  max-width: 26ch;
  color: var(--muted);
  font-size: 13px;
}

.estimator-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.estimator-controls label {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.estimator-controls input,
.estimator-controls select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
  font: inherit;
  background: rgba(255, 255, 255, 0.82);
}

.estimator-results {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.estimator-result {
  padding: 14px;
  border-radius: 18px;
  background: rgba(255, 250, 241, 0.9);
  border: 1px solid var(--line);
}

.estimator-result strong {
  display: block;
  margin-top: 8px;
  font-size: 22px;
}

.history-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(280px, 0.9fr);
  gap: 16px;
}

.chart-card,
.history-stat {
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--line);
  border-radius: 22px;
}

.chart-card {
  padding: 12px;
  position: relative;
}

#historyChart {
  width: 100%;
  height: 280px;
  display: block;
  cursor: crosshair;
}

.chart-tooltip {
  position: absolute;
  min-width: 170px;
  max-width: 220px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(17, 33, 31, 0.92);
  color: #f8f4ec;
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 12px));
  box-shadow: 0 16px 36px rgba(17, 33, 31, 0.22);
}

.chart-tooltip p {
  margin: 0;
}

.chart-tooltip-time {
  font-size: 12px;
  letter-spacing: 0.04em;
  color: rgba(248, 244, 236, 0.72);
}

.chart-tooltip-value,
.chart-tooltip-premium {
  margin-top: 6px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 14px;
}

.history-stats {
  display: grid;
  gap: 12px;
}

.history-stat {
  padding: 16px;
}

.history-stat strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

.empty-state {
  color: var(--muted);
  padding: 32px 10px;
  text-align: center;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  text-align: left;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 14px 16px;
}

tbody td {
  padding: 14px 16px;
  border-top: 1px solid var(--line);
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.48);
}

tbody tr.selected {
  background: rgba(0, 127, 115, 0.09);
}

.mono {
  font-family: "IBM Plex Mono", monospace;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.pill.negative {
  background: var(--danger-soft);
  color: var(--danger);
}

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

@media (max-width: 900px) {
  .hero,
  .controls {
    grid-template-columns: 1fr;
    display: grid;
  }

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

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

  .estimator-controls,
  .estimator-results {
    grid-template-columns: 1fr;
  }
}

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

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

  h1 {
    max-width: none;
  }

  thead th,
  tbody td {
    padding: 12px 10px;
  }

  .history-drawer {
    padding: 18px;
  }
}
