:root {
  color-scheme: light;
  --bg-primary: #f5f5f7;
  --bg-secondary: #ffffff;
  --bg-tertiary: #eef1f5;
  --border: rgba(0, 0, 0, 0.10);
  --border-hover: rgba(0, 0, 0, 0.16);
  --text-primary: #1d1d1f;
  --text-secondary: #3f3f46;
  --text-muted: #6e6e73;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --success: #157f3b;
  --warning: #b45309;
  --danger: #d70015;
  --gradient-1: linear-gradient(135deg, #0071e3 0%, #8b5cf6 100%);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

/* Generic helpers (also used by portal pages) */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
}
.grid { display: grid; gap: 16px; }
.row { display: flex; gap: 12px; align-items: center; }
.h1 { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.4px; }
.h2 { font-size: 1.05rem; font-weight: 650; letter-spacing: -0.2px; }
.muted { color: var(--text-muted); }

/* Sidebar */
.sidebar {
  width: 260px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  margin-bottom: 32px;
}

.logo-icon {
  width: 36px;
  height: 36px;
  background: var(--gradient-1);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-text {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.5px;
}

.nav-section { margin-bottom: 24px; }
.nav-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 0 12px;
  margin-bottom: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s ease;
  margin-bottom: 2px;
}

.nav-item:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.nav-item.active { background: rgba(0, 113, 227, 0.14); color: var(--accent); }
.nav-item svg { opacity: 0.7; }
.nav-item.active svg { opacity: 1; }

.nav-badge {
  margin-left: auto;
  background: var(--bg-tertiary);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 10px;
  background: var(--bg-tertiary);
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--gradient-1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.85rem;
}

.user-info { flex: 1; overflow: hidden; }
.user-name { font-size: 0.85rem; font-weight: 600; }
.user-email { font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: var(--bg-secondary); color: var(--danger); }

/* Main Content */
.main {
  flex: 1;
  margin-left: 260px;
  padding: 32px 48px;
  min-height: 100vh;
}

/* Header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 32px;
  gap: 16px;
}

.page-title {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
}

.page-subtitle { color: var(--text-secondary); font-size: 0.9rem; }
.header-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  border: none;
  text-decoration: none;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 113, 227, 0.28);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-secondary); border-color: var(--border-hover); }

/* Form inputs */
.input {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text-primary);
  font-size: 0.9rem;
  width: 100%;
}
.input:focus { outline: none; border-color: var(--accent); }
.input::placeholder { color: var(--text-muted); }

/* Flash */
.flash { margin-bottom: 18px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); background: rgba(255,255,255,.70); }
.flash.ok { border-color: rgba(34,197,94,.25); background: rgba(34,197,94,.06); color: var(--success); }
.flash.err { border-color: rgba(239,68,68,.25); background: rgba(239,68,68,.06); color: var(--danger); }

/* Stats Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  transition: all 0.2s ease;
}

.stat-card:hover { border-color: var(--border-hover); transform: translateY(-2px); }
.stat-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.stat-label { font-size: 0.8rem; color: var(--text-muted); font-weight: 500; }

.stat-icon {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stat-icon.blue { background: rgba(0, 113, 227, 0.12); color: var(--accent); }
.stat-icon.green { background: rgba(34, 197, 94, 0.15); color: #22c55e; }
.stat-icon.purple { background: rgba(139, 92, 246, 0.15); color: #8b5cf6; }
.stat-icon.orange { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }

.stat-value { font-size: 1.75rem; font-weight: 700; letter-spacing: -1px; margin-bottom: 4px; }
.stat-change { font-size: 0.75rem; color: var(--success); display: flex; align-items: center; gap: 6px; }

/* Table Card */
.table-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
}
.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.table-title { font-size: 1rem; font-weight: 600; }
.table-filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.search-wrapper { position: relative; }
.search-wrapper svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}
.search-input { padding-left: 36px; width: 240px; }

/* Table */
table { width: 100%; border-collapse: collapse; }
th {
  padding: 14px 24px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.03);
}
th:last-child { text-align: right; }
td { padding: 16px 24px; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
tr:last-child td { border-bottom: none; }
tr { transition: background 0.15s ease; }
tr:hover td { background: rgba(0, 0, 0, 0.02); }

/* Plan Name Cell */
.plan-cell { display: flex; align-items: center; gap: 14px; }
.plan-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
}
.plan-icon.free { background: linear-gradient(135deg, #6b7280, #4b5563); }
.plan-icon.starter { background: linear-gradient(135deg, #3b82f6, #1d4ed8); }
.plan-icon.pro { background: linear-gradient(135deg, #8b5cf6, #6d28d9); }
.plan-icon.enterprise { background: linear-gradient(135deg, #f59e0b, #d97706); }
.plan-info h4 { font-size: 0.95rem; font-weight: 600; margin-bottom: 2px; }
.plan-info span { font-size: 0.8rem; color: var(--text-muted); }

/* Limit Pill */
.limit-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-tertiary);
  padding: 6px 12px;
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}
.limit-pill svg { opacity: 0.6; }
.limit-pill.unlimited { background: rgba(34, 197, 94, 0.15); color: var(--success); }

/* Price */
.price { font-weight: 600; color: var(--text-primary); }
.price span { color: var(--text-muted); font-weight: 400; }

/* Status Badge */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}
.status-badge.active { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.status-badge.inactive { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* Actions */
.actions-cell { display: flex; gap: 6px; justify-content: flex-end; }
.btn-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
}
.btn-icon:hover { background: var(--bg-tertiary); border-color: var(--border); color: var(--text-primary); }
.btn-icon.danger:hover { background: rgba(239, 68, 68, 0.1); border-color: rgba(239, 68, 68, 0.3); color: var(--danger); }

/* Dropdown (CSS only) */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  right: 0;
  top: 100%;
  margin-top: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 6px;
  min-width: 180px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-10px);
  transition: all 0.2s ease;
  z-index: 50;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.12);
}
.dropdown:focus-within .dropdown-menu,
.dropdown:hover .dropdown-menu { opacity: 1; visibility: visible; transform: translateY(0); }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.15s;
}
.dropdown-item:hover { background: var(--bg-secondary); color: var(--text-primary); }
.dropdown-item.danger:hover { background: rgba(239, 68, 68, 0.1); color: var(--danger); }
.dropdown-divider { height: 1px; background: var(--border); margin: 6px 0; }

@media (max-width: 1200px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 880px) {
  .sidebar { display: none; }
  .main { margin-left: 0; padding: 24px; }
  .stats-grid { grid-template-columns: 1fr; }
  .search-input { width: 100%; }
}
