:root {
  color-scheme: dark;
  --bg: #101416;
  --surface: #171d20;
  --surface-2: #1e262a;
  --line: #2d383d;
  --text: #f2f5f4;
  --muted: #97a5a8;
  --green: #43d18c;
  --green-soft: #173b2c;
  --amber: #f0b84b;
  --amber-soft: #433419;
  --red: #f06a6a;
  --red-soft: #442323;
  --cyan: #57b8c8;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.2);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef2f1;
  --surface: #ffffff;
  --surface-2: #f4f7f6;
  --line: #d4ddda;
  --text: #17201f;
  --muted: #657473;
  --green: #16865a;
  --green-soft: #dff4e9;
  --amber: #a66500;
  --amber-soft: #fff0cf;
  --red: #c23e44;
  --red-soft: #fde5e5;
  --cyan: #197b8b;
  --shadow: 0 10px 28px rgba(34, 50, 46, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 76px;
  padding: 14px max(20px, calc((100vw - 1180px) / 2));
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(14px);
}

.brand,
.top-actions,
.live-state,
.status-strip,
.legend,
.section-heading,
.account-identity,
.account-meta,
.quota-heading,
footer {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid var(--green);
  border-radius: 6px;
  color: var(--green);
  background: var(--green-soft);
  font-size: 14px;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.2;
}

.brand p,
.section-heading p,
.summary-note {
  color: var(--muted);
  font-size: 12px;
}

.brand p {
  margin-top: 3px;
}

.top-actions {
  gap: 10px;
}

.live-state {
  gap: 7px;
  margin-right: 4px;
  color: var(--muted);
  font-size: 12px;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 4px var(--amber-soft);
}

.live-state.online .live-dot {
  background: var(--green);
  box-shadow: 0 0 0 4px var(--green-soft);
}

.live-state.offline .live-dot {
  background: var(--red);
  box-shadow: 0 0 0 4px var(--red-soft);
}

.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  font-size: 19px;
}

.icon-button:hover,
.icon-button:focus-visible {
  border-color: var(--cyan);
  outline: none;
}

.icon-button.spinning {
  animation: spin 0.8s linear infinite;
}

main {
  width: min(1180px, calc(100% - 40px));
  margin: 28px auto 36px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.summary-item {
  display: grid;
  min-height: 124px;
  padding: 22px;
  align-content: space-between;
  border-right: 1px solid var(--line);
}

.summary-item:last-child {
  border-right: 0;
}

.summary-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.summary-item strong {
  font-size: 30px;
  line-height: 1;
}

.summary-alert strong {
  color: var(--amber);
}

.status-strip {
  justify-content: space-between;
  gap: 24px;
  margin: 18px 0 28px;
  padding: 0 2px;
  color: var(--muted);
  font-size: 12px;
}

.status-strip > div:not(.legend) {
  display: grid;
  gap: 4px;
}

.status-strip strong {
  color: var(--text);
  font-size: 13px;
}

.legend {
  gap: 16px;
  margin-left: auto;
}

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

.legend-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.healthy {
  background: var(--green);
}

.warning {
  background: var(--amber);
}

.danger {
  background: var(--red);
}

.accounts-section {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.section-heading {
  justify-content: space-between;
  min-height: 78px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

h2 {
  margin-bottom: 5px;
  font-size: 17px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, auto);
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
}

.segment {
  min-height: 30px;
  padding: 0 12px;
  border: 0;
  border-radius: 4px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 12px;
}

.segment.active {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.16);
}

.account-list {
  min-height: 130px;
}

.account-row {
  display: grid;
  grid-template-columns: minmax(190px, 0.8fr) minmax(330px, 1.6fr) 92px;
  gap: 28px;
  align-items: center;
  min-height: 112px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.account-row:last-child {
  border-bottom: 0;
}

.account-row:hover {
  background: var(--surface-2);
}

.account-identity {
  min-width: 0;
  gap: 12px;
}

.account-initial {
  display: grid;
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--cyan);
  background: var(--surface-2);
  font-size: 13px;
  font-weight: 800;
}

.account-name {
  overflow: hidden;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-meta {
  gap: 7px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
}

.status-chip {
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--green);
  background: var(--green-soft);
  text-transform: none;
}

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

.quota-stack {
  display: grid;
  gap: 11px;
}

.quota-window {
  display: grid;
  gap: 6px;
}

.quota-heading {
  justify-content: space-between;
  color: var(--muted);
  font-size: 11px;
}

.quota-heading strong {
  color: var(--text);
  font-size: 12px;
}

.quota-progress {
  display: block;
  width: 100%;
  height: 6px;
  overflow: hidden;
  border: 0;
  border-radius: 3px;
  background: var(--line);
  appearance: none;
  -webkit-appearance: none;
}

.quota-progress::-webkit-progress-bar {
  border-radius: 3px;
  background: var(--line);
}

.quota-progress::-webkit-progress-value {
  border-radius: 3px;
  background: var(--green);
}

.quota-progress::-moz-progress-bar {
  border-radius: 3px;
  background: var(--green);
}

.quota-progress.low::-webkit-progress-value,
.quota-progress.low::-moz-progress-bar {
  background: var(--amber);
}

.quota-progress.empty::-webkit-progress-value,
.quota-progress.empty::-moz-progress-bar {
  background: var(--red);
}

.quota-empty {
  color: var(--muted);
  font-size: 12px;
}

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

.remaining {
  text-align: right;
}

.remaining strong {
  display: block;
  font-size: 20px;
}

.remaining span {
  color: var(--muted);
  font-size: 11px;
}

.remaining.low strong {
  color: var(--amber);
}

.remaining.empty strong,
.remaining.error strong {
  color: var(--red);
}

.loading-row {
  display: grid;
  gap: 12px;
  padding: 28px 20px;
}

.loading-bar {
  display: block;
  width: 58%;
  height: 10px;
  border-radius: 4px;
  background: var(--line);
  animation: pulse 1.2s ease-in-out infinite;
}

.loading-bar.short {
  width: 34%;
}

.empty-filter {
  padding: 44px 20px;
  color: var(--muted);
  text-align: center;
}

.error-panel {
  margin-top: 18px;
  padding: 16px 18px;
  border: 1px solid var(--red);
  border-radius: 7px;
  color: var(--red);
  background: var(--red-soft);
}

.error-panel p {
  margin-top: 5px;
  font-size: 12px;
}

footer {
  justify-content: space-between;
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 0 0 28px;
  color: var(--muted);
  font-size: 11px;
}

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

@keyframes pulse {
  50% {
    opacity: 0.45;
  }
}

@media (max-width: 820px) {
  .summary-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .summary-item:nth-child(2) {
    border-right: 0;
  }

  .summary-item:nth-child(-n + 2) {
    border-bottom: 1px solid var(--line);
  }

  .account-row {
    grid-template-columns: minmax(150px, 0.7fr) minmax(260px, 1.3fr) 76px;
    gap: 18px;
  }
}

@media (max-width: 640px) {
  .topbar {
    min-height: 68px;
    padding: 12px 16px;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
  }

  h1 {
    font-size: 16px;
  }

  .live-state span:last-child,
  .brand p,
  .legend {
    display: none;
  }

  main,
  footer {
    width: calc(100% - 24px);
  }

  main {
    margin-top: 16px;
  }

  .summary-item {
    min-height: 108px;
    padding: 16px;
  }

  .summary-item strong {
    font-size: 25px;
  }

  .status-strip {
    margin: 14px 0 20px;
  }

  .section-heading {
    align-items: flex-start;
    gap: 14px;
    flex-direction: column;
  }

  .segmented {
    width: 100%;
    grid-template-columns: repeat(3, 1fr);
  }

  .account-row {
    grid-template-columns: 1fr auto;
    gap: 16px;
    min-height: 0;
    padding: 18px 16px;
  }

  .quota-stack {
    grid-column: 1 / -1;
    grid-row: 2;
  }

  .remaining {
    grid-column: 2;
    grid-row: 1;
  }
}

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