:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-alt: #162033;
  --border: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --warn: #f59e0b;
  --radius: 10px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.error-text { color: #fca5a5; margin-top: 8px; font-size: 13px; }

/* Login */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}
.login-card h1 { margin: 12px 0 4px; font-size: 22px; }
.brand-badge {
  width: 42px; height: 42px; border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 16px; color: #fff;
}
.brand-badge.sm { width: 34px; height: 34px; font-size: 14px; }

/* Layout */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; flex-shrink: 0;
  background: var(--panel-alt);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 18px 14px;
}
.sidebar-header {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 6px 18px; border-bottom: 1px solid var(--border);
}
.brand-title { font-weight: 700; font-size: 15px; }
.brand-sub { color: var(--muted); font-size: 12px; }
.nav-list { display: flex; flex-direction: column; gap: 6px; margin-top: 16px; flex: 1; }
.nav-item {
  background: transparent; color: var(--muted); border: 0;
  text-align: left; padding: 10px 12px; border-radius: 8px;
  cursor: pointer; font-size: 14px; transition: all 0.15s;
}
.nav-item:hover { background: rgba(99, 102, 241, 0.12); color: var(--text); }
.nav-item.active { background: var(--primary); color: #fff; font-weight: 600; }
.sidebar-footer { padding-top: 12px; border-top: 1px solid var(--border); }

.main-content { flex: 1; padding: 24px 28px; max-width: 1400px; overflow-x: auto; }
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 20px; gap: 12px; flex-wrap: wrap;
}
.topbar h2 { margin: 0; font-size: 20px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

/* Cards & Stats */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.card-header {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; margin-bottom: 12px; flex-wrap: wrap;
}
.card-header h3 { margin: 0; font-size: 15px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px; margin-bottom: 18px;
}
.stat-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.stat-label { color: var(--muted); font-size: 12px; }
.stat-value { font-size: 26px; font-weight: 700; margin-top: 4px; }

/* Forms & Inputs */
label { display: block; font-size: 13px; color: #cbd5e1; margin: 10px 0 6px; }
input, select, textarea {
  width: 100%; background: #0b1220; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 11px; font-size: 13px; font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
}
textarea { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; resize: vertical; }

.form-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px; align-items: end;
}
.inline-form { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 200px; }
.toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar input { max-width: 280px; }
.toolbar select { max-width: 180px; }
.inline-check { display: inline-flex; align-items: center; gap: 6px; margin: 0; cursor: pointer; }
.inline-check input { width: auto; }
.form-actions { display: flex; gap: 10px; align-items: center; }
.quick-days { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }

/* Buttons */
.btn {
  border: 0; border-radius: 8px; padding: 9px 14px;
  cursor: pointer; font-size: 13px; font-weight: 600;
  transition: background 0.15s, opacity 0.15s;
}
.btn:hover { opacity: 0.92; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; margin-top: 14px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: #334155; color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td {
  text-align: left; padding: 10px 10px;
  border-bottom: 1px solid rgba(51, 65, 85, 0.7);
  vertical-align: middle;
}
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
td.mono, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.action-group { display: flex; gap: 6px; flex-wrap: wrap; }

/* Pills */
.pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.pill-active { background: rgba(34, 197, 94, 0.16); color: #4ade80; }
.pill-unactivated { background: rgba(148, 163, 184, 0.18); color: #cbd5e1; }
.pill-expired { background: rgba(245, 158, 11, 0.18); color: #fbbf24; }
.pill-banned { background: rgba(239, 68, 68, 0.2); color: #f87171; }
.pill-info { background: rgba(99, 102, 241, 0.2); color: #a5b4fc; }

.code-box {
  background: #0b1220; border: 1px solid var(--border);
  border-radius: 8px; padding: 12px; overflow-x: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px; color: #e2e8f0; margin: 8px 0 0;
}

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(2, 6, 23, 0.75);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; z-index: 100;
}
.modal-card {
  width: 100%; max-width: 480px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 22px;
}

/* Toast */
.toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 200;
  background: #0f172a; border: 1px solid var(--primary);
  color: #fff; padding: 10px 16px; border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
.toast.error { border-color: var(--danger); }

@media (max-width: 820px) {
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; border-right: 0; border-bottom: 1px solid var(--border); }
  .nav-list { flex-direction: row; flex-wrap: wrap; }
}
