:root {
  --red: #D12026;
  --navy: #113460;
  --deep-red: #AE2A30;
  --soft-blue: #4A6A89;
  --bg: #F5F7FA;
  --text: #101828;
  --muted: #667085;
  --border: #E4E7EC;
  --white: #FFFFFF;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  letter-spacing: 0;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
.logo { width: 190px; height: auto; object-fit: contain; display: block; }
.auth-page { min-height: 100vh; display: grid; grid-template-columns: 1fr 1.05fr; }
.auth-panel { padding: 44px; background: var(--white); display: flex; flex-direction: column; justify-content: center; }
.auth-aside { padding: 44px; color: white; background: var(--navy); display: flex; flex-direction: column; justify-content: space-between; }
.auth-card { max-width: 620px; width: 100%; margin: 0 auto; }
.eyebrow { color: var(--red); font-size: 11px; text-transform: uppercase; font-weight: 900; letter-spacing: .08em; }
.h1 { font-size: 28px; line-height: 1.15; margin: 12px 0 8px; color: var(--navy); font-weight: 900; }
.muted { color: var(--muted); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.field { display: grid; gap: 7px; margin-bottom: 14px; }
.field label { font-size: 12px; font-weight: 800; color: #344054; }
.input, .select, .textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: white;
  border-radius: 10px;
  padding: 12px 13px;
  color: var(--text);
  outline: none;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--navy); box-shadow: 0 0 0 4px rgba(17,52,96,.08); }
.textarea { min-height: 96px; resize: vertical; }
.btn {
  border: 0;
  border-radius: 10px;
  min-height: 42px;
  padding: 11px 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 850;
  cursor: pointer;
}
.btn-primary { color: white; background: var(--red); box-shadow: 0 12px 28px rgba(209,32,38,.22); }
.btn-navy { color: white; background: var(--navy); }
.btn-soft { color: var(--navy); background: #EEF3F8; }
.btn-line { color: var(--navy); background: white; border: 1px solid var(--border); }
.btn-danger { color: white; background: var(--deep-red); }
.app { min-height: 100vh; display: grid; grid-template-columns: 276px 1fr; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 22px; background: var(--navy); color: white; overflow: auto; }
.side-logo { padding: 12px; background: white; border-radius: 12px; margin-bottom: 22px; }
.side-logo .logo { width: 206px; }
.nav-section { margin-top: 20px; color: rgba(255,255,255,.55); font-size: 11px; font-weight: 900; text-transform: uppercase; letter-spacing: .08em; }
.nav-link { margin-top: 7px; display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-radius: 10px; color: rgba(255,255,255,.78); font-size: 14px; font-weight: 750; }
.nav-link.active, .nav-link:hover { background: rgba(255,255,255,.1); color: white; }
.nav-link.active { box-shadow: inset 3px 0 0 var(--red); }
.main { min-width: 0; }
.topbar { height: 76px; padding: 0 30px; display: flex; align-items: center; justify-content: space-between; background: rgba(255,255,255,.88); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; backdrop-filter: blur(16px); }
.content { padding: 30px; }
.page-title { font-size: 26px; font-weight: 900; color: var(--navy); margin: 0; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card { background: white; border: 1px solid var(--border); border-radius: 12px; padding: 18px; box-shadow: 0 14px 36px rgba(16,24,40,.05); }
.metric { min-height: 128px; display: flex; flex-direction: column; justify-content: space-between; }
.metric small { color: var(--muted); font-weight: 800; }
.metric strong { color: var(--navy); font-size: 28px; font-weight: 950; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 10px; font-size: 11px; font-weight: 900; text-transform: uppercase; }
.badge.approved, .badge.active, .badge.paid, .badge.earned { color: var(--navy); background: #EEF3F8; }
.badge.pending { color: var(--deep-red); background: #FFF1F1; }
.badge.rejected, .badge.suspended { color: white; background: var(--deep-red); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
.wide-table { min-width: 1480px; }
th { text-align: left; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
td, th { padding: 13px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.cell-long { min-width: 220px; max-width: 320px; white-space: normal; line-height: 1.45; }
.downline-link {
  display: inline-flex;
  min-width: 48px;
  justify-content: center;
  border-radius: 999px;
  padding: 7px 11px;
  background: #FFF1F1;
  color: var(--deep-red);
  font-weight: 950;
}
.downline-link:hover { background: var(--red); color: white; }
.flash { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; font-weight: 750; }
.flash.error { color: var(--deep-red); background: #FFF1F1; }
.flash.success { color: var(--navy); background: #EEF3F8; }
.toast {
  position: relative;
  margin: 16px 0 0;
  border-radius: 10px;
  padding: 13px 14px 13px 42px;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.45;
  box-shadow: 0 12px 28px rgba(16,24,40,.08);
}
.toast::before {
  position: absolute;
  left: 14px;
  top: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  color: white;
  font-size: 12px;
  font-weight: 950;
}
.toast-error { border: 1px solid #FFD5D7; background: #FFF1F1; color: var(--deep-red); }
.toast-error::before { content: "!"; background: var(--deep-red); }
.toast-success { border: 1px solid #D7E3EF; background: #EEF3F8; color: var(--navy); }
.toast-success::before { content: "✓"; background: var(--navy); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.copy-row { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; }
.empty { padding: 28px; text-align: center; border: 1px dashed var(--border); border-radius: 12px; color: var(--muted); }
.tree { display: grid; gap: 12px; }
.tree-node { border: 1px solid var(--border); background: white; border-radius: 12px; padding: 14px; }
.tree-children { margin: 12px 0 0 20px; display: grid; gap: 10px; }
.chart-box { height: 260px; }
.mobile-records { display: none; }
.record-card { border: 1px solid var(--border); border-radius: 12px; padding: 14px; margin-top: 12px; background: white; }
.record-card h3 { margin: 4px 0; color: var(--navy); }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 14px 0 0; }
.detail-grid dt { color: var(--muted); font-size: 11px; font-weight: 900; text-transform: uppercase; }
.detail-grid dd { margin: 4px 0 0; font-size: 13px; overflow-wrap: anywhere; }
.btn-whatsapp { color: white; background: var(--navy); }
.btn-whatsapp svg { flex-shrink: 0; }
.datatable-controls {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin: 16px 0 12px;
}
.datatable-search { flex: 1; min-width: 220px; }
.datatable-size { width: 120px; flex: 0 0 auto; }
.datatable-controls label {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.datatable-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}
.datatable-pages { display: flex; align-items: center; gap: 8px; }
.datatable-page-label { min-width: 92px; text-align: center; color: var(--text); }
.datatable-pages .btn { min-height: 36px; padding: 8px 12px; }
.datatable-pages .btn:disabled { opacity: .45; cursor: not-allowed; }

@media (max-width: 980px) {
  .auth-page, .app { grid-template-columns: 1fr; }
  .auth-aside { display: none; }
  .sidebar { position: relative; height: auto; }
  .topbar { position: static; padding: 18px; height: auto; align-items: flex-start; gap: 12px; flex-direction: column; }
  .content { padding: 18px; }
  .grid-2, .grid-3, .grid-4, .form-grid { grid-template-columns: 1fr; }
  .copy-row { grid-template-columns: 1fr; }
  .desktop-table { display: none; }
  .mobile-records { display: block; }
  .detail-grid { grid-template-columns: 1fr; }
  .datatable-controls, .datatable-footer { align-items: stretch; flex-direction: column; }
  .datatable-search, .datatable-size { width: 100%; }
  .datatable-pages { width: 100%; justify-content: space-between; }
}
