:root {
  color-scheme: dark;
  --bg: #0f1418;
  --bg-soft: #151b21;
  --panel: #1a2129;
  --panel-strong: #202932;
  --line: #2b3642;
  --text: #edf2f6;
  --muted: #8b9aa8;
  --teal: #2dd4bf;
  --teal-soft: rgba(45, 212, 191, 0.14);
  --amber: #f59e0b;
  --amber-soft: rgba(245, 158, 11, 0.14);
  --red: #ef4444;
  --red-soft: rgba(239, 68, 68, 0.14);
  --green: #34d399;
  --radius: 8px;
  --shadow: 0 12px 36px rgba(0, 0, 0, 0.24);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), transparent 320px),
    var(--bg);
  color: var(--text);
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    "PingFang SC",
    "Microsoft YaHei",
    sans-serif;
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
}

.view {
  min-height: 100vh;
}

.auth-view {
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 26px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 8px;
  background: var(--teal);
  color: #062b27;
  font-weight: 800;
  font-size: 22px;
}

.brand-mark.small {
  width: 34px;
  height: 34px;
  flex-basis: 34px;
  font-size: 17px;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.form-stack {
  display: grid;
  gap: 14px;
}

.form-stack label {
  display: grid;
  gap: 6px;
}

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

input,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: none;
}

input:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px var(--teal-soft);
}

textarea {
  min-height: 220px;
  resize: vertical;
  line-height: 1.6;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.button {
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--text);
  background: var(--panel-strong);
  transition:
    transform 120ms ease,
    background 120ms ease,
    border-color 120ms ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button.primary {
  background: var(--teal);
  border-color: var(--teal);
  color: #052e2a;
  font-weight: 700;
}

.button.secondary {
  background: var(--bg-soft);
  border-color: var(--line);
}

.button.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
}

.button.danger {
  background: var(--red-soft);
  border-color: rgba(239, 68, 68, 0.3);
  color: #ffb4b4;
}

.button.success {
  background: rgba(52, 211, 153, 0.14);
  border-color: rgba(52, 211, 153, 0.3);
  color: #a7f3d0;
}

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

.button.full {
  width: 100%;
}

.form-error {
  min-height: 20px;
  margin: 0;
  color: #fca5a5;
}

.form-message {
  min-height: 20px;
  margin: 0;
  color: #a7f3d0;
}

.app-view {
  padding: 0 28px 48px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 68px;
  margin: 0 -28px 22px;
  padding: 0 28px;
  background: rgba(15, 20, 24, 0.9);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.topbar-title strong {
  display: block;
  line-height: 1.2;
}

.topbar-title span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

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

.stat {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stat strong {
  display: block;
  margin-top: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 22px;
  line-height: 1.1;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.tab {
  min-height: 40px;
  padding: 0 16px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.tab.active {
  color: var(--text);
  border-bottom-color: var(--teal);
}

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

.panel-head h2 {
  margin: 0;
  font-size: 17px;
}

.panel-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
}

th,
td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  background: var(--bg-soft);
}

tbody tr:last-child td {
  border-bottom: 0;
}

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

.align-right {
  text-align: right;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.status-pill.active {
  background: rgba(52, 211, 153, 0.14);
  color: #a7f3d0;
}

.status-pill.pending {
  background: var(--amber-soft);
  color: #fcd34d;
}

.status-pill.blocked {
  background: var(--red-soft);
  color: #fca5a5;
}

.status-pill.online {
  background: var(--teal-soft);
  color: #99f6e4;
}

.status-pill.offline {
  background: rgba(139, 154, 168, 0.12);
  color: var(--muted);
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
}

.user-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 16px;
  max-width: 1080px;
}

.panel {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
}

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

.settings-grid .panel {
  align-self: start;
}

.subscription-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.subscription-row input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

.config-list {
  display: grid;
  gap: 8px;
}

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

.config-item strong {
  display: block;
  margin-bottom: 2px;
  font-size: 13px;
}

.config-item code {
  display: block;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
}

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

.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.session-item strong {
  display: block;
}

.session-item span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.user-status {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  max-width: 1080px;
  margin-bottom: 18px;
  padding: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.user-status h1 {
  margin: 12px 0 6px;
  font-size: 24px;
}

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

.traffic-box {
  min-width: 180px;
  text-align: right;
}

.traffic-box span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.traffic-box strong {
  display: block;
  margin-top: 6px;
  font-size: 22px;
}

.code-area {
  background: var(--bg-soft);
  border: 1px solid var(--line);
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  max-width: min(360px, calc(100vw - 40px));
  padding: 12px 16px;
  background: #e8fff7;
  color: #062b27;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transform: translateY(24px);
  opacity: 0;
  pointer-events: none;
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

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

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

@media (max-width: 620px) {
  .app-view {
    padding: 0 14px 32px;
  }

  .topbar {
    margin: 0 -14px 16px;
    padding: 0 14px;
  }

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

  .identity {
    display: none;
  }

  .user-status {
    display: block;
  }

  .traffic-box {
    margin-top: 18px;
    text-align: left;
  }

  .subscription-row {
    grid-template-columns: minmax(0, 1fr);
  }

  .config-item,
  .session-item {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .row-actions {
    justify-content: flex-start;
  }
}
