/* ── PCN CRM — Shared Styles ──────────────────────────────────────────── */
:root {
  --bg:       #080316;
  --card:     rgba(20, 8, 45, 0.88);
  --sidebar:  rgba(8, 3, 22, 0.98);
  --gold:     #e8c97a;
  --gold2:    #f5e0a0;
  --purple:   #b388ff;
  --green:    #69f0ae;
  --red:      #ff5252;
  --blue:     #64b5f6;
  --orange:   #ffb74d;
  --white:    #f0eaf8;
  --muted:    rgba(240,234,248,.48);
  --border:   rgba(255,255,255,.08);
  --bgold:    rgba(232,201,122,.16);
  --rainbow:  linear-gradient(90deg,#FF0018,#FFA52C,#FFFF41,#008018,#0000F9,#8B00FF);
}

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

body {
  background: var(--bg);
  color: var(--white);
  font-family: 'Inter', sans-serif;
  min-height: 100vh;
  display: flex;
}

a { color: var(--gold); text-decoration: none; }
a:hover { color: var(--gold2); }

/* ── LAYOUT ────────────────────────────────────────────────────────────── */
.crm-sidebar {
  width: 250px;
  min-height: 100vh;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  padding: 0 0 24px;
}

.crm-main {
  margin-left: 250px;
  flex: 1;
  min-height: 100vh;
  padding: 32px 36px 60px;
  max-width: 1100px;
}

/* ── SIDEBAR ───────────────────────────────────────────────────────────── */
.sidebar-brand {
  padding: 22px 20px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-brand-text {
  font-family: 'Nunito', sans-serif;
  font-size: 10px;
  font-weight: 900;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: .08em;
  line-height: 1.3;
}

.sidebar-rainbow {
  height: 3px;
  background: var(--rainbow);
}

.sidebar-user,
.sidebar-member {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-user-name,
.sidebar-name {
  font-family: 'Nunito', sans-serif;
  font-size: 13px;
  font-weight: 800;
  color: var(--white);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role,
.sidebar-role {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 20px;
  display: inline-block;
}

/* ── SIDEBAR LOGO BLOCK ─────────────────────────────────────────────────── */
.sidebar-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px 16px 16px;
  text-align: center;
  text-decoration: none;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo img {
  width: 66px !important;
  height: 66px !important;
  max-width: 66px !important;
  max-height: 66px !important;
  object-fit: contain;
  border-radius: 50%;
  flex-shrink: 0;
}
.role-admin  { background: rgba(232,201,122,.15); color: var(--gold); border: 1px solid rgba(232,201,122,.3); }
.role-member { background: rgba(179,136,255,.12); color: var(--purple); border: 1px solid rgba(179,136,255,.25); }

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
}

.sidebar-section {
  padding: 8px 20px 4px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: rgba(240,234,248,.28);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  font-size: 13px;
  color: var(--muted);
  transition: all .18s;
  border-left: 3px solid transparent;
}
.sidebar-link:hover { color: var(--white); background: rgba(255,255,255,.04); }
.sidebar-link.active {
  color: var(--gold);
  border-left-color: var(--gold);
  background: rgba(232,201,122,.07);
}

.sidebar-link .icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-logout {
  padding: 0 16px;
  margin-top: 8px;
}
.sidebar-logout a {
  display: block;
  text-align: center;
  padding: 9px;
  border: 1px solid rgba(255,82,82,.25);
  border-radius: 10px;
  color: rgba(255,82,82,.7);
  font-size: 12px;
  font-weight: 600;
  transition: all .2s;
}
.sidebar-logout a:hover { background: rgba(255,82,82,.1); color: var(--red); border-color: var(--red); }

/* ── PAGE HEADER ───────────────────────────────────────────────────────── */
.page-header {
  margin-bottom: 28px;
}
.page-title {
  font-family: 'Nunito', sans-serif;
  font-size: 26px;
  font-weight: 900;
  color: var(--gold2);
  margin-bottom: 4px;
}
.page-sub {
  font-size: 13px;
  color: var(--muted);
}

/* ── STAT CARDS ────────────────────────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--accent, var(--gold));
}
.stat-card-icon { font-size: 24px; margin-bottom: 10px; }
.stat-card-num  {
  font-family: 'Nunito', sans-serif;
  font-size: 32px;
  font-weight: 900;
  color: var(--white);
  line-height: 1;
  margin-bottom: 4px;
}
.stat-card-label { font-size: 12px; color: var(--muted); }

/* ── CARDS ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 20px;
}
.card-title {
  font-family: 'Nunito', sans-serif;
  font-size: 15px;
  font-weight: 800;
  color: var(--gold);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── TABLES ────────────────────────────────────────────────────────────── */
.crm-table {
  width: 100%;
  border-collapse: collapse;
}
.crm-table th {
  text-align: left;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 8px 12px 12px;
  border-bottom: 1px solid var(--border);
}
.crm-table td {
  padding: 12px 12px;
  font-size: 13px;
  border-bottom: 1px solid rgba(255,255,255,.04);
  vertical-align: middle;
}
.crm-table tr:hover td { background: rgba(255,255,255,.02); }
.crm-table tr:last-child td { border-bottom: none; }

/* ── BADGES ────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  color: var(--bc, #aaa);
  background: color-mix(in srgb, var(--bc, #aaa) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--bc, #aaa) 30%, transparent);
}

/* ── FORMS ─────────────────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.form-group.full { grid-column: 1 / -1; }
.form-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.form-input, .form-select, .form-textarea {
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--white);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  padding: 11px 14px;
  outline: none;
  transition: border-color .2s;
  width: 100%;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: rgba(232,201,122,.45);
}
.form-select option { background: #140828; }
.form-textarea { resize: vertical; min-height: 90px; }

/* ── BUTTONS ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 11px 22px;
  border-radius: 40px;
  font-family: 'Nunito', sans-serif;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  border: none;
  transition: all .2s;
  text-decoration: none;
}
.btn-gold {
  background: linear-gradient(135deg, #c49a30, #f5e0a0);
  color: #140828;
}
.btn-gold:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(212,168,67,.3); color: #140828; }
.btn-purple {
  background: linear-gradient(135deg, #7c3aed, #a855f7);
  color: #fff;
}
.btn-ghost {
  background: rgba(255,255,255,.06);
  border: 1px solid var(--border);
  color: var(--muted);
}
.btn-ghost:hover { background: rgba(255,255,255,.1); color: var(--white); }
.btn-sm { padding: 6px 14px; font-size: 11px; }
.btn-danger { background: rgba(255,82,82,.15); border: 1px solid rgba(255,82,82,.3); color: var(--red); }
.btn-danger:hover { background: rgba(255,82,82,.25); }

/* ── REFERRAL LINK BOX ─────────────────────────────────────────────────── */
.ref-link-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
}
.ref-link-url {
  flex: 1;
  font-size: 13px;
  color: var(--gold);
  font-family: 'Inter', monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.copy-btn {
  background: rgba(232,201,122,.12);
  border: 1px solid rgba(232,201,122,.25);
  color: var(--gold);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  font-family: 'Nunito', sans-serif;
  transition: all .2s;
  white-space: nowrap;
}
.copy-btn:hover { background: rgba(232,201,122,.22); }

/* ── ALERTS ────────────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 18px;
}
.alert-success { background: rgba(105,240,174,.1); border: 1px solid rgba(105,240,174,.25); color: var(--green); }
.alert-error   { background: rgba(255,82,82,.1); border: 1px solid rgba(255,82,82,.25); color: var(--red); }
.alert-info    { background: rgba(100,181,246,.1); border: 1px solid rgba(100,181,246,.25); color: var(--blue); }

/* ── EMPTY STATE ───────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}
.empty-state-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state-text { font-size: 14px; line-height: 1.6; }

/* ── LOGIN PAGE ────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(ellipse at 20% 20%, rgba(124,58,237,.22) 0%,transparent 55%),
    radial-gradient(ellipse at 80% 80%, rgba(179,136,255,.12) 0%,transparent 55%),
    var(--bg);
}
.login-card {
  background: var(--card);
  border: 1px solid rgba(232,201,122,.18);
  border-radius: 24px;
  padding: 44px 40px;
  max-width: 420px;
  width: 100%;
}
.login-logo-text {
  font-family: 'Nunito', sans-serif;
  font-size: 11px;
  font-weight: 900;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: .08em;
  line-height: 1.3;
}
.login-title {
  font-family: 'Nunito', sans-serif;
  font-size: 24px;
  font-weight: 900;
  color: var(--gold2);
  margin-bottom: 4px;
}
.login-sub { font-size: 13px; color: var(--muted); margin-bottom: 28px; }

/* ── MODAL ─────────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  z-index: 9000;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: #130826;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px;
  max-width: 560px;
  width: 100%;
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-close {
  position: absolute;
  top: 14px; right: 16px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
}
.modal-title {
  font-family: 'Nunito', sans-serif;
  font-size: 19px;
  font-weight: 900;
  color: var(--gold);
  margin-bottom: 20px;
}

/* ── STATUS SELECT INLINE ──────────────────────────────────────────────── */
.status-select {
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--white);
  font-size: 12px;
  padding: 5px 8px;
  cursor: pointer;
}

/* ── PILL FILTER BUTTONS ───────────────────────────────────────────────── */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: rgba(255,255,255,.05);
  border: 1px solid var(--border);
  text-decoration: none;
  transition: all .18s;
  white-space: nowrap;
}
.pill:hover { color: var(--white); background: rgba(255,255,255,.09); }
.pill-active {
  color: var(--gold);
  background: rgba(232,201,122,.10);
  border-color: rgba(232,201,122,.35);
}

/* ── SELECT DARK THEME ─────────────────────────────────────────────────── */
.form-select,
select.form-input {
  color-scheme: dark;
  background: rgba(20,8,45,0.95);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--white);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  padding: 11px 14px;
  outline: none;
  width: 100%;
  cursor: pointer;
  transition: border-color .2s;
}
.form-select:focus,
select.form-input:focus { border-color: rgba(232,201,122,.45); }
.form-select option,
select.form-input option {
  background: #140828;
  color: var(--white);
}

/* ── LEADERBOARD ───────────────────────────────────────────────────────── */
.lb-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,.04);
}
.lb-row:last-child { border-bottom: none; }
.lb-rank { font-family:'Nunito',sans-serif; font-size:14px; font-weight:900; width:24px; color:var(--muted); }
.lb-rank.gold { color: var(--gold); }
.lb-rank.silver { color: #aaa; }
.lb-rank.bronze { color: #cd7f32; }
.lb-name { flex:1; font-size:13px; font-weight:600; }
.lb-bar-wrap { width: 120px; height: 6px; background: rgba(255,255,255,.08); border-radius:3px; }
.lb-bar { height:100%; border-radius:3px; background: var(--rainbow); }
.lb-count { font-family:'Nunito',sans-serif; font-size:14px; font-weight:800; color:var(--gold); min-width:28px; text-align:right; }

/* ── HISTORY TIMELINE ──────────────────────────────────────────────────── */
.timeline { padding: 0 0 0 16px; border-left: 2px solid var(--border); }
.timeline-item { position: relative; padding: 0 0 16px 20px; }
.timeline-item::before {
  content: '';
  position: absolute;
  left: -9px;
  top: 4px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--gold);
  border: 2px solid var(--bg);
}
.timeline-time { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.timeline-text { font-size: 13px; }

/* ── IMAGE SAFETY — prevent unconstrained images from breaking layout ───── */
.crm-main img {
  max-width: 100%;
  height: auto;
}
/* Nuclear lock on pcn-logo — wins over inline styles and specificity wars */
img[src*="pcn-logo"] {
  max-width: 220px !important;
  max-height: 220px !important;
  object-fit: contain !important;
}
.crm-sidebar img[src*="pcn-logo"],
.sidebar-logo img[src*="pcn-logo"] {
  max-width: 66px !important;
  max-height: 66px !important;
}
.mobile-topbar-logo img {
  width: 32px !important;
  height: 32px !important;
  max-width: 32px !important;
  max-height: 32px !important;
}

/* ── MOBILE TOPBAR ──────────────────────────────────────────────────────── */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 58px;
  background: rgba(8,3,22,0.97);
  border-bottom: 1px solid var(--border);
  z-index: 150;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
}
.mobile-topbar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  flex: 1;
  justify-content: center;
}
.mobile-topbar-logo img {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: contain;
}
.mobile-topbar-logo span {
  font-family: 'Nunito', sans-serif;
  font-size: 10px;
  font-weight: 900;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: .08em;
  line-height: 1.3;
}
.hamburger-btn {
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4.5px;
  padding: 6px;
  flex-shrink: 0;
}
.hamburger-btn span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--gold);
  border-radius: 2px;
  transition: all .25s;
}
.sidebar-close-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  background: rgba(255,255,255,.07);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 18px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 149;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.open { display: block; }

/* ── RESPONSIVE ────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .mobile-topbar { display: flex; }

  .crm-sidebar {
    transform: translateX(-100%);
    transition: transform .28s cubic-bezier(.4,0,.2,1);
    z-index: 200;
  }
  .crm-sidebar.drawer-open { transform: translateX(0); }
  .sidebar-close-btn { display: flex; }

  .crm-main {
    margin-left: 0;
    padding: 78px 16px 80px;
    max-width: 100%;
  }

  .stats-row { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .form-grid  { grid-template-columns: 1fr; }

  .page-title { font-size: 20px; }

  /* Prevent large decorative images from dominating on tablet */
  img[src*="pcn-logo"] { max-width: 160px !important; max-height: 160px !important; }
  .crm-sidebar img[src*="pcn-logo"],
  .sidebar-logo img[src*="pcn-logo"] { max-width: 60px !important; max-height: 60px !important; }

  /* Table scroll — works with or without .crm-table-wrap wrapper */
  .crm-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 12px;
    margin: 0 -4px;
  }
  /* Global fallback: any .crm-table directly in a .card also scrolls */
  .crm-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    min-width: 480px;
    width: 100%;
  }
  /* Restore table layout inside wrapper (wrapper provides the scroll) */
  .crm-table-wrap .crm-table { display: table; }

  /* Leaderboard bar narrower */
  .lb-bar-wrap { width: 70px; }

  /* Modal full-width on mobile */
  .modal-box { padding: 24px 18px; border-radius: 16px; }

  /* Ref link box wrap */
  .ref-link-box { flex-wrap: wrap; }
}

@media (max-width: 560px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 14px; }
  .stat-card-num { font-size: 26px; }
  .login-card { padding: 28px 18px; }
  .card { padding: 16px; }
  .btn { padding: 10px 16px; font-size: 12px; }
}
