:root {
  color-scheme: dark;
  --bg: #080a0f;
  --panel: #11151d;
  --panel-2: #171c26;
  --text: #e8edf5;
  --muted: #8993a5;
  --line: #242b38;
  --nav: #0d1018;
  --nav-soft: #171c28;
  --primary: #7c6cff;
  --primary-dark: #6658e8;
  --teal: #20c7c9;
  --green: #35c979;
  --red: #ff6b6b;
  --amber: #f5b84b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", Arial, Helvetica, sans-serif;
}

button,
input,
textarea,
select {
  font: inherit;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  width: 288px;
  padding: 24px;
  background: var(--nav);
  color: var(--text);
  transform: translateX(0);
  transition: transform .18s ease;
}

.sidebar.hidden {
  transform: translateX(-100%);
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(0, 0, 0, .58);
}

.sidebar-backdrop.hidden {
  display: none;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}

.sidebar-brand span {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
}

.sidebar-brand strong,
.sidebar-brand small {
  display: block;
}

.sidebar-brand small {
  color: var(--muted);
}

.side-nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 0 12px;
  text-align: left;
  font-weight: 800;
}

.nav-item:hover,
.nav-item.active {
  background: var(--nav-soft);
  color: #fff;
}

.main {
  min-width: 0;
}

.appbar {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 64px;
  padding: 0 22px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.menu-toggle {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  font-size: 22px;
}

.appbar strong,
.appbar span {
  display: block;
}

.appbar span {
  color: var(--muted);
  font-size: 13px;
}

.content {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

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

.title-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.source-switcher {
  position: relative;
}

.source-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 10;
  width: min(360px, 86vw);
  max-height: 320px;
  overflow-y: auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 20px 54px rgba(0, 0, 0, .45);
}

.source-dropdown.hidden {
  display: none;
}

.source-dropdown button {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  padding: 10px 12px;
  text-align: left;
}

.source-dropdown button:hover,
.source-dropdown button.selected {
  background: var(--panel-2);
}

.source-dropdown strong,
.source-dropdown span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-dropdown strong {
  font-size: 14px;
}

.source-dropdown span {
  margin-top: 4px;
  color: var(--muted);
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 12px;
}

.source-dropdown .dropdown-manage,
.source-dropdown .dropdown-empty {
  margin-top: 6px;
  border-top: 1px solid var(--line);
  color: var(--primary);
  font-weight: 800;
}

.page-title p {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 11px;
  font-weight: 800;
}

h1,
h2 {
  margin: 0;
}

h1 {
  overflow-wrap: anywhere;
  font-size: clamp(24px, 3.1vw, 34px);
  line-height: 1.08;
}

h2 {
  font-size: 18px;
}

.panel,
.metric {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 30px rgba(0, 0, 0, .2);
}

.panel {
  padding: 18px;
  margin-bottom: 12px;
}

.source-panel {
  display: grid;
  gap: 14px;
}

.source-meta,
.section-title,
.chart-legend,
.form-actions,
.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.source-meta span,
.status {
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
}

.source-meta strong {
  color: var(--text);
}

.status.ok {
  color: var(--green);
}

.status.error {
  color: var(--red);
}

.primary-button,
.secondary-button,
.import-button {
  min-height: 40px;
  border-radius: 8px;
  cursor: pointer;
  padding: 0 14px;
  font-weight: 800;
}

.compact-button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 12px;
}

.primary-button {
  border: 0;
  background: var(--primary);
  color: #fff;
}

.primary-button:hover {
  background: var(--primary-dark);
}

.secondary-button,
.import-button {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
}

.import-button input {
  display: none;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.metric {
  min-height: 92px;
  padding: 14px;
}

.metric span {
  display: block;
  min-height: 28px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.metric strong {
  display: block;
  color: var(--primary);
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: clamp(22px, 2.5vw, 32px);
  line-height: 1;
}

.usage-ranking {
  display: grid;
  gap: 10px;
}

.usage-row {
  display: grid;
  gap: 9px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  padding: 12px;
  text-align: left;
}

.usage-row:hover {
  border-color: var(--primary);
}

.usage-row.error {
  border-color: rgba(255, 107, 107, .45);
}

.usage-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.usage-row-head strong,
.usage-row-head span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.usage-row-head strong {
  min-width: 0;
  font-size: 13px;
}

.usage-row-head span {
  flex: 0 0 auto;
  color: var(--muted);
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 12px;
}

.usage-track {
  height: 20px;
  overflow: hidden;
  border-radius: 6px;
  background: #0c0f16;
}

.usage-fill {
  height: 100%;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--primary), var(--teal));
}

.section-title {
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-title span {
  color: var(--muted);
  font-size: 12px;
}

.chart-legend {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.active-dot {
  background: var(--primary);
}

.traffic-dot {
  background: var(--teal);
}

.chart-wrap {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0b0e14;
}

canvas {
  display: block;
  width: 100%;
  height: 260px;
}

.bar-wrap {
  height: 14px;
  margin-bottom: 18px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--panel-2);
}

.bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--teal));
  transition: width .25s ease;
}

.details {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin: 0;
}

.details div {
  min-width: 0;
  padding: 12px;
  border-radius: 8px;
  background: var(--panel-2);
}

dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  margin-bottom: 8px;
}

dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-weight: 800;
}

.source-form {
  display: grid;
  grid-template-columns: minmax(180px, 280px) minmax(0, 1fr);
  gap: 14px;
}

.source-proxy {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.source-proxy input {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
}

.source-proxy strong,
.source-proxy small {
  display: block;
}

.source-proxy small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.source-form label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.source-form input,
.source-form textarea,
.setting-row select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0c0f16;
  color: var(--text);
  outline: none;
}

.source-form input,
.setting-row select {
  min-height: 40px;
  padding: 0 12px;
}

.source-form textarea {
  min-height: 96px;
  padding: 12px;
  resize: vertical;
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
}

.source-form .source-proxy {
  display: flex;
  grid-column: 1 / -1;
  margin: 0;
}

.source-form .source-proxy input {
  width: 18px;
  min-height: 18px;
  height: 18px;
  padding: 0;
}

.form-actions {
  grid-column: 1 / -1;
}

.saved-counter {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.saved-counter strong {
  display: grid;
  place-items: center;
  min-width: 28px;
  height: 26px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
}

.saved-list {
  display: grid;
  gap: 10px;
}

.saved-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.saved-item.selected {
  border-color: var(--primary);
  background: #141927;
}

.saved-info {
  min-width: 0;
}

.saved-info strong,
.saved-info span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.saved-info span {
  margin-top: 4px;
  color: var(--muted);
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 11px;
}

.saved-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.saved-actions button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
}

.saved-actions .danger {
  color: var(--red);
}

.empty {
  margin: 0;
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
}

.settings-panel {
  display: grid;
  gap: 10px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.setting-row strong,
.setting-row small {
  display: block;
}

.setting-row small {
  margin-top: 4px;
  color: var(--muted);
}

.setting-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
}

.setting-row select {
  width: 180px;
}

.settings-actions {
  margin-top: 8px;
}

@media (max-width: 1180px) {
  .metrics {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  body {
    overflow-x: hidden;
  }

  .appbar {
    height: 58px;
    padding: 0 12px;
  }

  .appbar strong {
    font-size: 14px;
  }

  .appbar span {
    font-size: 11px;
  }

  .menu-toggle {
    width: 38px;
    height: 38px;
    font-size: 20px;
  }

  .content {
    width: min(100% - 16px, 1180px);
    padding-top: 16px;
    padding-bottom: 28px;
  }

  .page-title,
  .section-title,
  .setting-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .page-title {
    gap: 12px;
  }

  h1 {
    font-size: clamp(21px, 6.3vw, 26px);
  }

  h2 {
    font-size: 16px;
  }

  .title-actions,
  .primary-button,
  .secondary-button,
  .import-button {
    width: 100%;
  }

  .title-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .source-switcher {
    min-width: 0;
  }

  .source-dropdown {
    left: 0;
    right: auto;
    width: min(92vw, 360px);
  }

  .metrics,
  .source-form,
  .saved-item {
    grid-template-columns: 1fr;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .metric {
    min-height: 70px;
    padding: 10px;
  }

  .metric span {
    min-height: 0;
    margin-bottom: 7px;
    font-size: 11px;
  }

  .metric strong {
    font-size: clamp(19px, 6vw, 24px);
  }

  .panel {
    padding: 14px;
  }

  canvas {
    height: 220px;
  }

  .saved-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
  }

  .usage-row {
    padding: 10px;
  }

  .usage-row-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .usage-row-head span {
    max-width: 100%;
  }

  .usage-track {
    height: 18px;
  }

  .setting-row select {
    width: 100%;
  }
}

@media (max-width: 430px) {
  .title-actions {
    grid-template-columns: 1fr;
  }

  .source-meta {
    display: grid;
  }

  .saved-actions button {
    min-height: 32px;
    padding: 0 8px;
    font-size: 11px;
  }

  .sidebar {
    width: min(86vw, 288px);
  }
}
