:root {
  --bg: #0f172a;
  --panel: #111827;
  --panel-alt: #1f2937;
  --card: #0b1220;
  --border: rgba(148, 163, 184, 0.18);
  --text: #e5e7eb;
  --muted: #94a3b8;
  --primary: #7c3aed;
  --primary-strong: #6d28d9;
  --positive: #22c55e;
  --negative: #ef4444;
  --shadow: rgba(15, 23, 42, 0.5);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: Inter, 'Segoe UI', sans-serif;
  background: linear-gradient(180deg, #020817 0%, #0f172a 100%);
  color: var(--text);
}

body {
  display: flex;
  justify-content: center;
  padding: 32px 16px;
}

button,
input {
  font: inherit;
}

.app {
  width: min(100%, 780px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.72rem;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 3vw, 3rem);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card,
.panel {
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 18px 30px var(--shadow);
}

.stat-card {
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  min-height: 116px;
  justify-content: space-between;
}

.stat-card.accent {
  background: linear-gradient(
    135deg,
    rgba(124, 58, 237, 0.3),
    rgba(15, 23, 42, 0.9)
  );
}

.label {
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.stat-card strong {
  font-size: clamp(2rem, 5vw, 2.8rem);
  line-height: 1;
}

.stat-card strong[data-state='positive'] {
  color: var(--positive);
}

.stat-card strong[data-state='negative'] {
  color: var(--negative);
}

.panel {
  padding: 16px;
}

.input-panel {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  margin-bottom: 12px;
  align-items: center;
}

.base-control {
  display: flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  max-width: 100%;
  min-width: 0;
  padding: 4px 8px;
  border: 1px solid rgba(148, 163, 184, 0.15);
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.5);
  flex-wrap: wrap;
}

.baseline-label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

.base-input {
  width: 72px;
  min-width: 72px;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 8px 0;
  font-size: 0.95rem;
  text-align: center;
}

.base-input:focus {
  outline: none;
}

input {
  width: 100%;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.9);
  color: var(--text);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 1.05rem;
}

input:focus {
  outline: 2px solid rgba(124, 58, 237, 0.8);
  border-color: transparent;
}

.button {
  border: none;
  border-radius: 12px;
  padding: 12px 18px;
  cursor: pointer;
  transition:
    transform 0.15s ease,
    opacity 0.15s ease;
  font-weight: 600;
}

.button:hover {
  transform: translateY(-1px);
}

.button-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: white;
}

.button-secondary {
  background: rgba(148, 163, 184, 0.12);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 9px 12px;
  font-size: 0.82rem;
  flex-shrink: 0;
  max-width: 100%;
}

.button-danger {
  background: rgba(239, 68, 68, 0.12);
  color: #fecaca;
  border: 1px solid rgba(239, 68, 68, 0.5);
  padding: 8px 12px;
  font-size: 0.82rem;
}

.quick-values {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 0 12px;
}

.quick-values-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.quick-value {
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.72);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  font-weight: 700;
  min-width: 54px;
}

.quick-value.positive {
  border-color: rgba(34, 197, 94, 0.5);
  color: var(--positive);
}

.quick-value.negative {
  border-color: rgba(239, 68, 68, 0.5);
  color: var(--negative);
}

.quick-value:hover {
  transform: translateY(-1px);
}

.status {
  min-height: 24px;
  color: #ffffff;
  margin: 0 0 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.2;
}

.status > span:last-child {
  display: inline-flex;
  align-items: center;
  line-height: 1.2;
}

.status-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  color: #ffffff;
  line-height: 1;
  font-size: 0.9rem;
}

.status-delta {
  font-weight: 700;
  display: inline-block;
  margin-left: 0.35em;
  margin-right: 0.35em;
}

.status-delta[data-sign='positive'] {
  color: var(--positive);
}

.status-delta[data-sign='negative'] {
  color: var(--negative);
}

.status.error {
  color: #ffffff;
}

.status.success {
  color: #ffffff;
}

.success-icon {
  color: var(--positive);
}

.error-icon {
  color: var(--negative);
}

.history-panel {
  display: flex;
  flex-direction: column;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.history-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 440px;
  overflow: auto;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: rgba(15, 23, 42, 0.78);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.history-meta {
  display: flex;
  align-items: center;
  gap: 12px;
}

.delta {
  font-weight: 700;
  font-size: 1.2rem;
}

.delta.positive {
  color: var(--positive);
}

.delta.negative {
  color: var(--negative);
}

.time {
  color: var(--muted);
  font-size: 0.85rem;
}

.delete-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 1px solid rgba(239, 68, 68, 0.5);
  background: rgba(239, 68, 68, 0.12);
  color: #fecaca;
  border-radius: 8px;
  padding: 0;
  cursor: pointer;
  font-weight: 600;
}

.delete-button:hover {
  background: rgba(239, 68, 68, 0.18);
}

.delete-button i {
  font-size: 0.8rem;
}

.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 20px 12px;
}

.chart-panel {
  margin-top: 18px;
}

.chart-svg {
  width: 100%;
  height: 220px;
  background: rgba(15, 23, 42, 0.78);
  border-radius: 12px;
  border: 1px solid var(--border);
  display: block;
}

.chart-point {
  cursor: pointer;
}

.chart-point circle {
  transition:
    r 0.15s ease,
    fill 0.15s ease;
}

.chart-point:hover circle,
.chart-point:focus circle {
  fill: #ddd6fe;
}

.chart-tooltip {
  position: fixed;
  z-index: 1000;
  pointer-events: none;
  opacity: 0;
  transform: translateY(6px);
  transition:
    opacity 0.12s ease,
    transform 0.12s ease;
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.5);
  padding: 8px 10px;
  color: var(--text);
  min-width: 120px;
}

.chart-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.chart-tooltip strong {
  display: block;
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.chart-tooltip span {
  display: block;
  font-weight: 700;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 620px) {
  .summary-grid {
    grid-template-columns: 1fr 1fr;
  }

  .topbar,
  .input-panel {
    grid-template-columns: 1fr;
    display: grid;
  }

  .base-control {
    width: 100%;
    justify-content: space-between;
  }

  .button {
    width: 100%;
  }
}

@media (max-width: 420px) {
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .base-control {
    display: grid;
    grid-template-columns: 1fr auto;
    width: 100%;
    justify-content: stretch;
  }

  .baseline-label {
    grid-column: 1 / -1;
  }

  .base-input {
    width: 100%;
    min-width: 0;
  }

  .button-secondary {
    width: 100%;
  }
}
