:root {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --teal: #14b8a6;
  --blue: #3b82f6;
  --amber: #f59e0b;
  --purple: #a855f7;
  --up: #10b981;
  --down: #f43f5e;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
}

.container {
  max-width: 1360px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 2.5rem;
}

.topbar {
  background: rgba(17, 24, 39, 0.92);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(8px);
}

.topbar-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 0.9rem 1.5rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 12px var(--teal);
}

.brand h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 0.15rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.topbar-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.status-pill {
  font-size: 0.78rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: rgba(20, 184, 166, 0.14);
  border: 1px solid rgba(20, 184, 166, 0.4);
  color: #5eead4;
  font-weight: 600;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.78rem;
  color: var(--muted);
  background: var(--surface-2);
  padding: 0.3rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
}

select,
input[type="number"] {
  background: #0f172a;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.55rem;
  font-size: 0.82rem;
  font-family: inherit;
}

.error-banner {
  background: rgba(244, 63, 94, 0.15);
  border: 1px solid var(--down);
  color: #fda4af;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.kpi-header {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.grade-badge {
  width: 96px;
  height: 36px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
}

.exchange-tag {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.kpi-header h2 {
  margin: 0.1rem 0 0;
  font-size: 0.98rem;
  font-weight: 600;
}

.kpi-price-row {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.kpi-price {
  font-size: 1.85rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.kpi-unit {
  font-size: 0.82rem;
  color: var(--muted);
}

.kpi-deltas {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.delta-pill {
  font-size: 0.76rem;
  font-weight: 600;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  background: var(--surface-2);
}

.delta-up {
  color: #34d399;
  background: rgba(16, 185, 129, 0.14);
}

.delta-down {
  color: #fb7185;
  background: rgba(244, 63, 94, 0.14);
}

.kpi-meta {
  font-size: 0.76rem;
  color: var(--muted);
  border-top: 1px solid rgba(51, 65, 85, 0.6);
  padding-top: 0.5rem;
  display: flex;
  justify-content: space-between;
}

.metrics-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.25rem;
}

.metric-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.metric-label {
  font-size: 0.75rem;
  color: var(--muted);
}

.metric-value {
  font-size: 1.25rem;
  font-weight: 700;
  color: #e2e8f0;
}

.metric-sub {
  font-size: 0.74rem;
  color: var(--muted);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.15rem 1.25rem;
  margin-bottom: 1.25rem;
}

.panel-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.9rem;
}

.panel-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.panel-desc {
  margin: 0.2rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

.legend-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.78rem;
  color: var(--text);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
}

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}

.swatch-ru0 { background: var(--teal); }
.swatch-nr0 { background: var(--blue); }
.swatch-br0 { background: var(--amber); }
.swatch-ma30 { background: var(--purple); }
.swatch-ma90 { background: #ec4899; }

.chart-wrap {
  position: relative;
  width: 100%;
  height: 360px;
  background: #090e1a;
  border: 1px solid rgba(51, 65, 85, 0.7);
  border-radius: 8px;
  overflow: hidden;
}

.chart-wrap-sm {
  height: 230px;
}

.chart-wrap svg {
  width: 100%;
  height: 100%;
  display: block;
}

.chart-tooltip {
  position: absolute;
  top: 12px;
  left: 16px;
  background: rgba(15, 23, 42, 0.94);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
  font-size: 0.76rem;
  pointer-events: none;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(460px, 1fr));
  gap: 1.25rem;
}

.inline-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.btn-primary,
.btn-secondary {
  border: none;
  border-radius: 6px;
  padding: 0.42rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

.btn-primary {
  background: var(--teal);
  color: #042f2e;
}

.btn-primary:hover {
  background: #2dd4bf;
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.sim-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.9rem;
}

.sim-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.sim-submit {
  display: flex;
  align-items: flex-end;
}

.api-result-box {
  background: #090e1a;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  margin-top: 0.75rem;
  font-size: 0.82rem;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.65rem;
  margin-top: 0.5rem;
}

.result-cell {
  background: var(--surface-2);
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
}

.result-cell span {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
}

.result-cell strong {
  font-size: 0.96rem;
  color: var(--text);
}

.table-scroll {
  overflow-x: auto;
  max-height: 420px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.data-table th,
.data-table td {
  padding: 0.55rem 0.75rem;
  text-align: right;
  border-bottom: 1px solid rgba(51, 65, 85, 0.5);
  white-space: nowrap;
}

.data-table th:first-child,
.data-table td:first-child {
  text-align: left;
}

.data-table thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
}

.footer {
  border-top: 1px solid var(--border);
  padding: 1rem 0;
  font-size: 0.78rem;
  color: var(--muted);
}

.footer-inner {
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding-top: 0;
  padding-bottom: 0;
}

.muted {
  color: var(--muted);
  margin: 0;
}
