/* ─── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --bg:          #0a0e1a;
  --surface:     #111827;
  --surface-2:   #1f2937;
  --surface-3:   #374151;
  --border:      #2d3748;
  --accent:      #10b981;
  --accent-dim:  #065f46;
  --accent-2:    #6366f1;
  --gold:        #f59e0b;
  --silver:      #9ca3af;
  --bronze:      #b45309;
  --danger:      #ef4444;
  --warn:        #f59e0b;
  --text:        #f1f5f9;
  --text-2:      #94a3b8;
  --text-3:      #64748b;
  --radius:      10px;
  --radius-sm:   6px;
  --shadow:      0 4px 24px rgba(0,0,0,.4);
  --sidebar-w:   220px;
  --font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ─── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: var(--font); background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; }
code { font-family: 'JetBrains Mono', 'Fira Code', monospace; }

/* ─── Auth screen ────────────────────────────────────────────────────────────── */
#auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: radial-gradient(ellipse at 50% 0%, #0d2040 0%, var(--bg) 60%);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px;
  box-shadow: var(--shadow);
}

.logo-block { text-align: center; margin-bottom: 28px; }
.logo-icon  { font-size: 40px; display: block; margin-bottom: 8px; }
.logo-text  { font-size: 28px; font-weight: 800; letter-spacing: -1px; color: var(--accent); }
.logo-sub   { color: var(--text-2); font-size: 13px; margin-top: 4px; }

.auth-tabs {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 24px;
}
.tab-btn {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: calc(var(--radius-sm) - 2px);
  background: transparent;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
  transition: .15s;
}
.tab-btn.active { background: var(--surface-3); color: var(--text); }

.auth-form { display: flex; flex-direction: column; gap: 16px; }

/* ─── Fields ─────────────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; min-width: 0; }

label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
}
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date],
select, textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}
textarea { resize: vertical; min-height: 64px; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M0 0l6 8 6-8z' fill='%2364748b'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 28px; }

.optional  { color: var(--text-3); font-weight: 400; }
.private-tag { font-size: 11px; background: rgba(239,68,68,.15); color: #f87171; border-radius: 4px; padding: 1px 5px; }
.shared-tag  { font-size: 11px; background: rgba(16,185,129,.12); color: var(--accent); border-radius: 4px; padding: 1px 5px; }

/* ─── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  transition: .15s;
  white-space: nowrap;
}
.btn-primary  { background: var(--accent);   color: #fff; border-color: var(--accent); }
.btn-primary:hover { filter: brightness(1.15); }
.btn-ghost    { background: transparent; color: var(--text-2); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger   { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: rgba(239,68,68,.12); }
.btn-full     { width: 100%; }
.btn-sm       { padding: 6px 12px; font-size: 13px; }
.btn-xs       { padding: 3px 8px;  font-size: 12px; }
.btn-fab      { padding: 12px 24px; font-size: 15px; border-radius: 24px; box-shadow: 0 4px 20px rgba(16,185,129,.3); }

/* ─── Messages ───────────────────────────────────────────────────────────────── */
.error-msg   { color: var(--danger); font-size: 13px; }
.success-msg { color: var(--accent); font-size: 13px; }
.loading     { color: var(--text-2); padding: 24px 0; text-align: center; }
.empty-state { color: var(--text-3); text-align: center; padding: 40px 0; font-size: 14px; }
.hidden      { display: none !important; }

/* ─── App layout ─────────────────────────────────────────────────────────────── */
#app-screen {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 10;
}

.sidebar-top   { flex: 1; padding: 24px 16px; }
.sidebar-bottom { padding: 16px; display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--border); }

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
  font-size: 18px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.5px;
}
.sidebar-logo .logo-icon { font-size: 22px; }

.nav-links     { display: flex; flex-direction: column; gap: 4px; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
  transition: .15s;
}
.nav-link:hover, .nav-link.active {
  background: var(--surface-2);
  color: var(--text);
}
.nav-link.active { color: var(--accent); }
.nav-icon  { font-size: 16px; }
.nav-username { font-size: 13px; color: var(--text-2); font-weight: 500; word-break: break-all; }

.bottom-tabs { display: none; }

.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 32px;
  max-width: 1100px;
}

.view { min-height: 60vh; }

/* ─── Season label ──────────────────────────────────────────────────────────── */
.season-label {
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 20px;
}

/* ─── Stats grid ─────────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 32px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 20px 16px;
}
.stat-card--accent { border-color: var(--accent-dim); background: rgba(16,185,129,.06); }
.stat-value { font-size: 28px; font-weight: 800; letter-spacing: -1px; color: var(--text); }
.stat-card--accent .stat-value { color: var(--accent); }
.stat-label { font-size: 12px; color: var(--text-3); margin-top: 4px; text-transform: uppercase; letter-spacing: .5px; }

/* ─── Section header ─────────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.section-title { font-size: 17px; font-weight: 700; }
.mt-6 { margin-top: 32px; }
.mt-8 { margin-top: 48px; }

/* ─── Leaderboard table ──────────────────────────────────────────────────────── */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.lb-table { width: 100%; border-collapse: collapse; }
.lb-table th {
  padding: 12px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-3);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.lb-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.lb-table tr:last-child td { border-bottom: none; }
.lb-table tr:hover td { background: rgba(255,255,255,.02); }
.lb-me td { background: rgba(16,185,129,.06); }
.lb-top .lb-name { font-weight: 700; }
.num { text-align: right; }
.pts-cell { font-weight: 700; color: var(--accent); }
.lb-rank { width: 40px; }
.lb-name { font-weight: 500; }

.medal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px; height: 26px;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 800;
}
.medal.gold   { background: var(--gold);   color: #000; }
.medal.silver { background: var(--silver); color: #000; }
.medal.bronze { background: var(--bronze); color: #fff; }

/* ─── Tier badges ────────────────────────────────────────────────────────────── */
.tier-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
  letter-spacing: .3px;
}
.tier-t1 { background: var(--surface-3); color: var(--text-2); }
.tier-t2 { background: rgba(16,185,129,.15); color: var(--accent); }
.tier-t3 { background: rgba(99,102,241,.2); color: #818cf8; }
.tier-t4 { background: rgba(245,158,11,.2); color: var(--gold); }

/* ─── Status badges ──────────────────────────────────────────────────────────── */
.status-badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 4px;
  font-weight: 500;
}
.status-active  { background: rgba(16,185,129,.12); color: var(--accent); }
.status-won     { background: rgba(245,158,11,.15); color: var(--gold); }
.status-lost    { background: rgba(239,68,68,.12);  color: var(--danger); }
.status-stalled { background: var(--surface-3); color: var(--text-3); }

/* ─── Activity feed ──────────────────────────────────────────────────────────── */
.activity-feed { display: flex; flex-direction: column; gap: 8px; }
.activity-item {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.act-icon {
  width: 38px; height: 38px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  background: var(--surface-2);
}
.act-icon.outreach    { background: rgba(99,102,241,.12); }
.act-icon.call        { background: rgba(16,185,129,.12); }
.act-icon.meeting     { background: rgba(245,158,11,.12); }
.act-icon.proposal    { background: rgba(59,130,246,.12); }
.act-icon.deal_closed { background: rgba(245,158,11,.18); }

.act-body  { flex: 1; min-width: 0; }
.act-top   { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 2px; }
.act-type  { font-weight: 600; font-size: 14px; }
.act-lead  { font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.act-notes { font-size: 13px; color: var(--text-2); margin: 4px 0; }
.act-meta  { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.act-pts   { font-size: 12px; font-weight: 700; color: var(--accent); }
.act-chf   { font-size: 12px; color: var(--gold); font-weight: 600; }
.act-time  { font-size: 12px; color: var(--text-3); }
.source-badge { font-size: 11px; background: var(--surface-3); color: var(--text-3); border-radius: 4px; padding: 1px 6px; }

.act-delete {
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 13px;
  padding: 4px;
  opacity: 0;
  transition: opacity .15s;
  flex-shrink: 0;
}
.activity-item:hover .act-delete { opacity: 1; }
.act-delete:hover { color: var(--danger); }

/* ─── Leads grid ─────────────────────────────────────────────────────────────── */
.leads-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.lead-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.lead-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.lead-name   { font-weight: 700; font-size: 15px; }
.lead-meta   { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.lead-actions { display: flex; gap: 4px; flex-shrink: 0; }
.lead-notes  { font-size: 13px; color: var(--text-2); }
.lead-contact,.lead-source { font-size: 12px; color: var(--text-3); }
.lead-date   { font-size: 11px; color: var(--text-3); }

/* ─── FAB ────────────────────────────────────────────────────────────────────── */
.fab-area { position: fixed; bottom: 32px; right: 32px; }

/* ─── Modal ──────────────────────────────────────────────────────────────────── */
#modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 16px;
  backdrop-filter: blur(4px);
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 28px 24px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ─── Profile ────────────────────────────────────────────────────────────────── */
.profile-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 8px;
}
.profile-row { display: flex; align-items: center; gap: 12px; }
.profile-label { font-size: 13px; color: var(--text-3); width: 120px; flex-shrink: 0; }
.profile-value { font-size: 14px; font-weight: 500; }
.admin-badge { display: inline-block; font-size: 12px; font-weight: 700; color: var(--gold); background: rgba(245,158,11,.12); border-radius: 4px; padding: 3px 8px; }

.webhook-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}
.webhook-desc { font-size: 13px; color: var(--text-2); margin-bottom: 10px; }
.webhook-url  { display: flex; align-items: center; gap: 10px; background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; }
.webhook-url code { flex: 1; font-size: 12px; color: var(--accent); word-break: break-all; }
.webhook-hint { font-size: 12px; color: var(--text-3); margin-top: 8px; }

.inline-form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.inline-form input, .inline-form select { flex: 1; min-width: 160px; }

.invites-list { display: flex; flex-direction: column; gap: 8px; }
.invite-row   { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.invite-token { font-size: 12px; color: var(--text-2); flex: 1; word-break: break-all; }
.invite-status { font-size: 12px; font-weight: 500; white-space: nowrap; }
.invite-status.used { color: var(--text-3); }
.invite-status.open { color: var(--accent); }

.invite-created {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  flex-wrap: wrap;
}
.invite-created code { color: var(--accent); word-break: break-all; }

.season-form { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; display: flex; flex-direction: column; gap: 12px; }
.seasons-list { display: flex; flex-direction: column; gap: 6px; }
.season-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; }
.season-row.active { border-color: var(--accent-dim); }
.season-dates { color: var(--text-3); flex: 1; }
.active-badge { font-size: 11px; font-weight: 700; color: var(--accent); background: rgba(16,185,129,.12); border-radius: 4px; padding: 2px 7px; }

.checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-2); cursor: pointer; }

/* ─── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .bottom-tabs {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 10;
  }
  .tab-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px 4px;
    font-size: 11px;
    color: var(--text-3);
    gap: 3px;
  }
  .tab-item.active { color: var(--accent); }
  .tab-item span   { font-size: 10px; }
  .main-content { margin-left: 0; padding: 20px 16px 80px; }
  .stats-grid   { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-value   { font-size: 22px; }
  .hide-sm      { display: none; }
  .fab-area     { bottom: 76px; right: 20px; }
  .leads-grid   { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
