:root {
  --bg: #f0f2f5;
  --sidebar: #eceef1;
  --card: #ffffff;
  --border: #e4e7ec;
  --text: #1a1d26;
  --muted: #6b7280;
  --accent: #6d28d9;
  --accent-soft: #ede9fe;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

/* Login */
#loginView {
  max-width: 400px;
  margin: 80px auto;
  padding: 28px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

#loginView h2 {
  margin: 0 0 8px;
}

#loginView label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin: 12px 0 4px;
}

#loginView input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.95rem;
}

#loginView button {
  width: 100%;
  margin-top: 16px;
  padding: 10px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  cursor: pointer;
}

.error {
  color: #dc2626;
  font-size: 0.85rem;
  margin-top: 8px;
}

/* Layout */
.layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px 24px;
}

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
}

.brand-title {
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.3;
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--muted);
}

.nav-group-label {
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 8px 12px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  margin-bottom: 4px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  text-align: left;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.6);
}

.nav-item.active {
  background: var(--card);
  box-shadow: var(--shadow);
  font-weight: 600;
}

.nav-icon {
  width: 20px;
  text-align: center;
  opacity: 0.7;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 24px 32px 16px;
  background: var(--bg);
}

.page-title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
}

.page-sub {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

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

.admin-name {
  font-size: 0.9rem;
  color: var(--muted);
}

.btn-outline {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}

.btn-outline:hover {
  border-color: var(--accent);
}

.content {
  padding: 0 32px 32px;
  flex: 1;
}

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 22px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 22px;
  box-shadow: var(--shadow);
}

.stat-label {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
}

/* Filters */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 16px;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-group label {
  font-size: 0.8rem;
  color: var(--muted);
}

.filter-group input,
.filter-group select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.9rem;
  min-width: 140px;
}

.btn-primary {
  padding: 8px 18px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn-primary:hover {
  filter: brightness(1.05);
}

/* Metric tabs */
.metric-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.metric-tab {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--card);
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--muted);
}

.metric-tab.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.chart-wrap {
  position: relative;
  height: 280px;
}

.card h3 {
  margin: 0 0 16px;
  font-size: 1rem;
  font-weight: 600;
}

/* Tables */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

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

th {
  color: var(--muted);
  font-weight: 500;
  font-size: 0.8rem;
}

tbody tr:hover {
  background: #fafafa;
}

.empty-row td {
  text-align: center;
  color: var(--muted);
  padding: 32px;
}

a.user-link {
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
}

a.user-link:hover {
  text-decoration: underline;
}

.tier-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.78rem;
  font-weight: 600;
}

.tier-trial {
  background: #fef3c7;
  color: #92400e;
}

.tier-paid {
  background: #d1fae5;
  color: #065f46;
}

.tier-disabled {
  background: #fee2e2;
  color: #991b1b;
}

.actions-cell {
  white-space: nowrap;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.78rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  cursor: pointer;
  margin-right: 4px;
}

.btn-sm.primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-sm:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-sm.danger {
  color: #dc2626;
  border-color: #fecaca;
}

.btn-sm.danger:hover {
  background: #fef2f2;
}

#userDetailCard {
  margin-top: 16px;
}

@media (max-width: 768px) {
  .layout {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    padding: 12px;
  }
  .sidebar-brand {
    padding-bottom: 8px;
  }
  .content,
  .topbar {
    padding-left: 16px;
    padding-right: 16px;
  }
}
