/* ============================================================
   CPA Tracker & Affiliate Panel - Styles
   Dark modern admin theme. No external dependencies.
   ============================================================ */
* { box-sizing: border-box; }
:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --border: #334155;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --purple: #a855f7;
}
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: #8b8ff5; }
h1, h2, h3 { margin: 0 0 12px; font-weight: 600; }
h1 { font-size: 22px; }
h3 { font-size: 16px; }
code {
  background: #0b1220;
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 12px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px;
  min-height: 100vh;
  background: #16213e;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  padding: 20px 18px;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-nav { flex: 1; padding: 12px 0; }
.nav-link {
  display: block;
  padding: 10px 18px;
  color: var(--muted);
  border-left: 3px solid transparent;
  font-weight: 500;
}
.nav-link:hover { color: #fff; background: rgba(99,102,241,.08); }
.nav-link.active { color: #fff; border-left-color: var(--primary); background: rgba(99,102,241,.12); }
.sidebar-footer { padding: 14px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.chip-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}
.chip-name { font-weight: 600; font-size: 13px; }
.chip-role { font-size: 12px; color: var(--muted); }
.content { flex: 1; padding: 24px 28px; max-width: 1200px; }
.page-head { margin-bottom: 20px; }
.page-head h1 { color: #fff; }

/* ---------- Cards & stats ---------- */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-head h3 { margin: 0; }
.stats-grid { display: grid; gap: 16px; }
.top-cards { grid-template-columns: repeat(4, 1fr); }
.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px 20px;
}
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 26px; font-weight: 700; margin-top: 6px; color: #fff; }
.stat-card-accent { border-color: rgba(99,102,241,.5); background: rgba(99,102,241,.08); }
.stat-card-accent .stat-value { color: #a5b4fc; }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; padding: 10px 12px;
  color: var(--muted); font-size: 12px;
  text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table td { padding: 12px; border-bottom: 1px solid #26324a; vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: rgba(99,102,241,.04); }
.cell-title { font-weight: 600; }
.cell-sub { font-size: 12px; color: var(--muted); margin-top: 2px; max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-desc { max-width: 220px; }
.empty { text-align: center; color: var(--muted); padding: 30px !important; }
.muted { color: var(--muted); }
.truncate { max-width: 200px; display: inline-block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge-green { background: rgba(34,197,94,.15); color: #4ade80; border: 1px solid rgba(34,197,94,.3); }
.badge-red { background: rgba(239,68,68,.15); color: #f87171; border: 1px solid rgba(239,68,68,.3); }
.badge-yellow { background: rgba(234,179,8,.15); color: #facc15; border: 1px solid rgba(234,179,8,.3); }
.badge-gray { background: rgba(148,163,184,.15); color: #94a3b8; border: 1px solid rgba(148,163,184,.3); }
.badge-blue { background: rgba(59,130,246,.15); color: #60a5fa; border: 1px solid rgba(59,130,246,.3); }
.badge-purple { background: rgba(168,85,247,.15); color: #c084fc; border: 1px solid rgba(168,85,247,.3); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 14px; font-weight: 600;
  cursor: pointer; text-decoration: none;
  transition: background .15s, border-color .15s;
}
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-outline { background: transparent; color: var(--text); border-color: var(--border); }
.btn-outline:hover { border-color: var(--primary); color: #a5b4fc; }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-danger { background: transparent; color: var(--red); border-color: rgba(239,68,68,.4); }
.btn-danger:hover { background: rgba(239,68,68,.15); }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: #cbd5e1; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=date], select, textarea {
  width: 100%; padding: 9px 12px;
  border-radius: 8px; border: 1px solid var(--border);
  background: #0b1220; color: var(--text); font-size: 14px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); border-color: transparent; }
textarea { resize: vertical; font-family: inherit; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.field-full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.check-item {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 8px; cursor: pointer;
}
.check-item:hover { border-color: var(--primary); }
.check-item input { width: auto; }
.inline-form { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { flex: 1; min-width: 180px; margin-bottom: 0; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }
.toolbar-form { display: flex; gap: 10px; align-items: center; }
.toolbar-form input[type=text], .toolbar-form select { width: auto; min-width: 180px; }

/* ---------- Alerts ---------- */
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.alert-success { background: rgba(34,197,94,.12); border: 1px solid rgba(34,197,94,.35); color: #4ade80; }
.alert-error { background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.35); color: #f87171; }

/* ---------- Range buttons ---------- */
.range { display: flex; gap: 6px; }
.range-btn { padding: 5px 10px; border-radius: 6px; border: 1px solid var(--border); color: var(--muted); font-size: 12px; font-weight: 600; }
.range-btn:hover { border-color: var(--primary); color: #a5b4fc; }
.range-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- Link rows ---------- */
.link-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.link-code { flex: 1; padding: 8px 12px; overflow-x: auto; white-space: nowrap; }
.code-block { display: block; padding: 10px 12px; margin: 6px 0; overflow-x: auto; white-space: nowrap; }

/* ---------- Auth page ---------- */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-wrap { width: 100%; max-width: 400px; padding: 20px; }
.auth-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 32px;
  box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.auth-logo {
  width: 52px; height: 52px; border-radius: 14px;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; font-weight: 800; margin-bottom: 18px;
}
.auth-card h1 { font-size: 22px; }
.auth-sub { color: var(--muted); margin-bottom: 20px; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .sidebar { width: 70px; }
  .sidebar-brand { font-size: 0; padding: 20px 0; text-align: center; }
  .sidebar-brand::first-letter { font-size: 18px; color: #fff; }
  .nav-link { padding: 10px 0; text-align: center; font-size: 0; }
  .nav-link::first-letter { font-size: 14px; }
  .sidebar-footer { padding: 10px 6px; }
  .chip-name, .chip-role { display: none; }
  .top-cards { grid-template-columns: repeat(2, 1fr); }
  .content { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; align-items: stretch; }
}
