:root {
  --background: #080c14;
  --panel: #0f1726;
  --panel-secondary: #131d2e;
  --border: #223047;
  --border-strong: #30425e;
  --text: #edf3fb;
  --muted: #91a0b7;
  --success: #34d399;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  font-family: Inter, system-ui, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(circle at 50% -20%, rgba(59, 130, 246, 0.14), transparent 38rem), var(--background);
}

button {
  font: inherit;
}

.page {
  width: min(1805px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.brand {
  min-width: 0;
}

h1 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: clamp(1.35rem, 2vw, 1.75rem);
  line-height: 1.15;
  letter-spacing: -0.03em;
}

.brand-icon {
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
}

.subtitle {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
}

.protocol-switcher {
  display: inline-flex;
  flex: 0 0 auto;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(15, 23, 38, 0.92);
}

.protocol-badge {
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  color: #ffffff;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--panel-secondary);
}

.dashboard {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 14px;
  align-items: stretch;
}

.panel {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(15, 23, 38, 0.92);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.26);
}

.sidebar {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 18px;
}

.target-group + .target-group {
  margin-top: 23px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.target-group h2 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.target-list {
  display: grid;
  gap: 6px;
}

.target-button,
.period-button,
.retry-button {
  border: 1px solid transparent;
  color: #c9d4e4;
  cursor: pointer;
}

.target-button {
  width: 100%;
  padding: 10px 12px;
  border-radius: 9px;
  font-size: 0.91rem;
  font-weight: 600;
  text-align: left;
  background: transparent;
  transition: color 140ms ease, border-color 140ms ease, background-color 140ms ease;
}

.target-button:hover {
  color: var(--text);
  background: var(--panel-secondary);
}

.target-button.active {
  border-color: rgba(59, 130, 246, 0.35);
  color: #dbeafe;
  background: rgba(59, 130, 246, 0.14);
}

.target-button:focus-visible,
.period-button:focus-visible,
.retry-button:focus-visible {
  outline: 3px solid rgba(96, 165, 250, 0.5);
  outline-offset: 2px;
}

.content {
  min-width: 0;
}

.chart-panel {
  overflow: hidden;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  gap: 16px;
  padding: 8px 12px 8px 16px;
  border-bottom: 1px solid var(--border);
}

.chart-title {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 2px;
}

.chart-title small {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.chart-title strong {
  overflow: hidden;
  font-size: 0.94rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.period-switcher {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--background);
}

.period-button {
  min-width: 74px;
  padding: 8px 12px;
  border-radius: 7px;
  font-size: 0.84rem;
  font-weight: 700;
  background: transparent;
  transition: color 140ms ease, border-color 140ms ease, background-color 140ms ease;
}

.period-button:hover {
  color: var(--text);
}

.period-button.active {
  border-color: var(--border-strong);
  color: #ffffff;
  background: var(--panel-secondary);
}

.chart-stage {
  position: relative;
  display: grid;
  min-height: clamp(260px, 44vw, 520px);
  padding: 8px;
  place-items: center;
  background: #0a101b;
}

#chart-container {
  display: flex;
  justify-content: center;
  width: 100%;
  min-width: 0;
}

.chart-image {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  opacity: 1;
  transition: opacity 160ms ease;
}

.chart-stage.loading .chart-image {
  opacity: 0.28;
}

.state-overlay {
  position: absolute;
  inset: 8px;
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 11px;
  padding: 16px;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  background: rgba(8, 12, 20, 0.72);
  backdrop-filter: blur(2px);
}

.chart-stage.loading .loading-state,
.chart-stage.error .error-state {
  display: flex;
}

.spinner {
  width: 26px;
  height: 26px;
  border: 3px solid var(--border-strong);
  border-top-color: #60a5fa;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.error-state strong {
  color: var(--text);
}

.retry-button {
  padding: 8px 13px;
  border-color: var(--border-strong);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 700;
  background: var(--panel-secondary);
}

.page-footer {
  margin-top: 18px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
  text-align: center;
}

@media (max-width: 900px) {
  .dashboard {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: block;
    height: auto;
    padding: 10px 14px;
  }

  .target-group {
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .target-group + .target-group {
    margin-top: 8px;
    padding-top: 8px;
  }

  .target-group h2 {
    flex: 0 0 auto;
    min-width: 112px;
    margin: 0;
    font-size: 0.68rem;
  }

  .target-list {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    gap: 4px;
    overflow-x: auto;
    scrollbar-width: thin;
  }

  .target-button {
    width: auto;
    flex: 0 0 auto;
    padding: 6px 10px;
    font-size: 0.85rem;
    white-space: nowrap;
  }
}

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

  .page-header {
    align-items: flex-start;
  }

  .target-group {
    display: block;
  }

  .target-group h2 {
    margin-bottom: 6px;
  }

  .chart-header {
    align-items: stretch;
    flex-direction: column;
    min-height: 0;
    padding: 12px;
  }

  .period-switcher {
    width: 100%;
  }

  .period-button {
    min-width: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}