/* CredFlow — design system das páginas internas (não usado no Início) */
:root {
  --bg-primary: #0b0e11;
  --bg-secondary: #12161c;
  --bg-card: #161b22;
  --bg-elevated: #1a2029;
  --bg-input: #0f1318;
  --accent: #b5ff41;
  --accent-dim: rgba(181, 255, 65, 0.12);
  --accent-border: rgba(181, 255, 65, 0.28);
  --text-primary: #f0f4fa;
  --text-secondary: #9aa4b8;
  --text-muted: #6b7588;
  --border: rgba(255, 255, 255, 0.07);
  --success: #4cdf80;
  --warning: #ffb443;
  --danger: #ff5e5e;
  --radius: 14px;
  --radius-lg: 18px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
  --sidebar-w: 270px;
  --font: "Inter", system-ui, sans-serif;
  --font-display: "Poppins", "Inter", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  display: flex;
  min-height: 100vh;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  padding: 1.4rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.25rem 0.4rem 0.5rem;
}
.sidebar-logo img {
  width: 46px;
  height: 46px;
  object-fit: contain;
  border-radius: 12px;
  background: #000;
}
.logo-text {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.28rem;
  letter-spacing: -0.02em;
}
.logo-text span { color: var(--accent); }
.sidebar-nav { display: flex; flex-direction: column; gap: 0.3rem; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  padding: 0.78rem 0.95rem;
  border-radius: 12px;
  color: var(--text-secondary);
  transition: 0.18s ease;
  border: 1px solid transparent;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,0.04); color: var(--text-primary); }
.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent-border);
  box-shadow: inset 3px 0 0 var(--accent);
}
.nav-badge {
  margin-left: auto;
  background: var(--accent);
  color: #0b0e11;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.15rem 0.48rem;
  border-radius: 999px;
  min-width: 1.4rem;
  text-align: center;
}
.sidebar-footer { margin-top: auto; padding-top: 1rem; border-top: 1px solid var(--border); }
.user-profile {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem;
  border-radius: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
}
.user-avatar {
  width: 40px; height: 40px; border-radius: 10px;
  display: grid; place-items: center; font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #8bc92e); color: #0b0e11;
}
.user-name { display: block; font-weight: 600; }
.user-role { font-size: 0.78rem; color: var(--text-muted); }

/* Main */
.main-content { flex: 1; padding: 1.35rem 1.5rem; overflow: auto; min-width: 0; }
.main-scroll { display: flex; flex-direction: column; gap: 1.1rem; max-width: 1400px; }

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}
.page-header h1 {
  margin: 0 0 0.25rem;
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.page-subtitle { color: var(--text-secondary); font-size: 0.92rem; }

.header-actions { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }

.btn-primary {
  border: none;
  border-radius: 999px;
  padding: 0.72rem 1.1rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #9fe34f);
  color: #0b0e11;
  box-shadow: 0 0 0 1px rgba(181,255,65,0.2), 0 8px 24px rgba(181,255,65,0.15);
  display: inline-flex; align-items: center; gap: 0.4rem;
}
.btn-primary:hover { filter: brightness(1.05); }
.btn-secondary {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.65rem 0.95rem;
  background: transparent;
  color: var(--text-primary);
  display: inline-flex; align-items: center; gap: 0.4rem;
}
.btn-secondary:hover { background: rgba(255,255,255,0.04); }
.btn-ghost {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  border-radius: 10px;
  padding: 0.45rem 0.7rem;
  font-size: 0.82rem;
}
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.78rem; border-radius: 999px; }
.btn-icon {
  width: 34px; height: 34px; border-radius: 10px;
  border: 1px solid var(--border); background: transparent; color: var(--text-secondary);
  display: grid; place-items: center;
}

.pill-tabs { display: flex; gap: 0.45rem; flex-wrap: wrap; margin-top: 0.85rem; }
.pill-tab {
  padding: 0.42rem 0.85rem;
  border-radius: 999px;
  background: rgba(255,255,255,0.04);
  color: var(--text-secondary);
  border: 1px solid transparent;
  font-size: 0.84rem;
  font-weight: 600;
}
.pill-tab.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent-border);
}
.pill-tab .count {
  margin-left: 0.35rem;
  opacity: 0.85;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}
.metrics-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.05rem 1.15rem;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.metric-card .metric-icon {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--accent-dim); color: var(--accent);
  margin-bottom: 0.75rem;
}
.metric-card .metric-icon.danger { background: rgba(255,94,94,0.12); color: var(--danger); }
.metric-card .metric-icon.warning { background: rgba(255,180,67,0.12); color: var(--warning); }
.metric-label { color: var(--text-secondary); font-size: 0.84rem; margin-bottom: 0.35rem; }
.metric-value { font-size: 1.45rem; font-weight: 700; letter-spacing: -0.02em; }
.metric-value.danger { color: var(--danger); }
.metric-trend { margin-top: 0.45rem; font-size: 0.8rem; color: var(--success); }
.metric-trend.danger { color: var(--danger); }
.metric-trend.warning { color: var(--warning); }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.1rem;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.card-title {
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-secondary);
}

.toolbar {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
  align-items: center;
}
.search-input, .select-input, .text-input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text-primary);
  padding: 0.65rem 0.85rem;
  outline: none;
}
.search-input { min-width: 220px; flex: 1; }
.search-input:focus, .select-input:focus, .text-input:focus {
  border-color: var(--accent-border);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.select-input { color: var(--text-secondary); }

.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0.65rem 0.5rem;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.data-table td {
  padding: 0.95rem 0.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  vertical-align: middle;
  font-size: 0.9rem;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(255,255,255,0.015); }

.entity {
  display: flex; align-items: center; gap: 0.7rem;
}
.entity-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 0.75rem;
  background: var(--accent-dim); color: var(--accent); flex-shrink: 0;
}
.entity-avatar.square { border-radius: 10px; }
.entity-title { font-weight: 600; }
.entity-sub { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.12rem; }

.status-pill {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.28rem 0.65rem; border-radius: 999px;
  font-size: 0.75rem; font-weight: 700;
}
.status-pill.active, .status-pill.good { background: rgba(76,223,128,0.14); color: var(--success); }
.status-pill.pending, .status-pill.warn { background: rgba(255,180,67,0.14); color: var(--warning); }
.status-pill.overdue, .status-pill.danger, .status-pill.blocked { background: rgba(255,94,94,0.14); color: var(--danger); }
.status-pill.inactive { background: rgba(255,255,255,0.06); color: var(--text-muted); }

.progress-wrap { min-width: 110px; }
.progress-label { font-size: 0.8rem; margin-bottom: 0.3rem; color: var(--text-secondary); }
.progress-bar {
  height: 6px; border-radius: 999px; background: rgba(255,255,255,0.06); overflow: hidden;
}
.progress-bar > span {
  display: block; height: 100%; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), #8bc92e);
}

.row-actions { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }

.table-footer {
  display: flex; justify-content: space-between; align-items: center;
  gap: 0.75rem; flex-wrap: wrap;
  margin-top: 1rem; padding-top: 0.85rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted); font-size: 0.82rem;
}
.pager { display: flex; align-items: center; gap: 0.4rem; }

.layout-split {
  display: grid;
  grid-template-columns: 1.45fr 0.7fr;
  gap: 1rem;
  align-items: start;
}
.layout-split.narrow-side { grid-template-columns: 1.55fr 0.65fr; }

.summary-stat { margin-bottom: 1.1rem; }
.summary-stat .label { color: var(--text-secondary); font-size: 0.82rem; margin-bottom: 0.25rem; }
.summary-stat .value { font-size: 1.5rem; font-weight: 700; }
.summary-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.55rem 0; border-bottom: 1px solid rgba(255,255,255,0.04);
  font-size: 0.88rem;
}
.summary-row:last-child { border-bottom: none; }
.summary-row .muted { color: var(--text-muted); }

.donut-wrap { display: flex; gap: 1rem; align-items: center; margin: 1rem 0; }
.donut-legend { display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.8rem; color: var(--text-secondary); }
.legend-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 0.4rem; }

.setting-group { margin-bottom: 0.9rem; }
.setting-group label {
  display: block; color: var(--text-secondary); margin-bottom: 0.35rem; font-size: 0.86rem;
}
.toggle-row {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: 0.75rem 0; border-bottom: 1px solid rgba(255,255,255,0.04);
}
.toggle-row:last-child { border-bottom: none; }
.toggle-copy .title { font-weight: 600; font-size: 0.9rem; }
.toggle-copy .desc { font-size: 0.78rem; color: var(--text-muted); margin-top: 0.15rem; }
.switch {
  position: relative; width: 44px; height: 24px; flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch span {
  position: absolute; inset: 0; border-radius: 999px;
  background: rgba(255,255,255,0.12); transition: 0.2s;
}
.switch span::before {
  content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; top: 3px; left: 3px; transition: 0.2s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(20px); background: #0b0e11; }

.badge-online {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.25rem 0.6rem; border-radius: 999px;
  background: rgba(76,223,128,0.12); color: var(--success);
  font-size: 0.75rem; font-weight: 700;
}
.badge-online::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--success);
}

.security-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.8rem 0; border-bottom: 1px solid rgba(255,255,255,0.04);
  color: var(--text-secondary); font-size: 0.9rem;
}
.security-item:last-child { border-bottom: none; }
.security-banner {
  margin-top: 0.85rem; padding: 0.75rem 0.9rem; border-radius: 12px;
  border: 1px solid var(--accent-border); color: var(--accent);
  display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; font-weight: 600;
}

.risk-row {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.75rem 0; border-bottom: 1px solid rgba(255,255,255,0.04);
}
.risk-row:last-child { border-bottom: none; }
.risk-bar { flex: 1; height: 8px; border-radius: 999px; background: rgba(255,255,255,0.06); overflow: hidden; }
.risk-bar > span { display: block; height: 100%; border-radius: 999px; }

.affiliate-cards {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem;
}
.aff-stats {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.65rem;
  margin: 0.9rem 0;
}
.aff-stat {
  background: rgba(255,255,255,0.03); border: 1px solid var(--border);
  border-radius: 12px; padding: 0.65rem;
}
.aff-stat .k { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.aff-stat .v { font-weight: 700; margin-top: 0.2rem; font-size: 0.95rem; }
.borrower-mini {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.45rem 0; font-size: 0.84rem; border-bottom: 1px solid rgba(255,255,255,0.04);
}
.borrower-mini:last-child { border-bottom: none; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.65);
  display: none; align-items: center; justify-content: center; z-index: 100; padding: 1rem;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); width: min(520px, 100%);
  padding: 1.25rem; box-shadow: var(--shadow);
}
.modal h3 { margin: 0 0 1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }

.toast-wrap {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 200;
  display: flex; flex-direction: column; gap: 0.5rem;
}
.toast {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 12px; padding: 0.75rem 1rem; min-width: 240px;
  box-shadow: var(--shadow); font-size: 0.88rem;
}
.toast.success { border-color: rgba(76,223,128,0.35); }
.toast.error { border-color: rgba(255,94,94,0.35); }

.empty-state {
  text-align: center; padding: 2rem 1rem; color: var(--text-muted);
}

@media (max-width: 1100px) {
  .metrics-grid, .metrics-grid.cols-4 { grid-template-columns: 1fr 1fr; }
  .layout-split, .layout-split.narrow-side, .affiliate-cards { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  body { flex-direction: column; }
  .sidebar { width: 100%; min-width: 0; height: auto; position: static; }
  .metrics-grid, .metrics-grid.cols-4 { grid-template-columns: 1fr; }
  .data-table { display: block; overflow-x: auto; }
}
