/* ========================================
   Bad Debt Solutions - Admin Portal
   ======================================== */

:root {
  --navy: #1a2332;
  --navy-light: #2d3e54;
  --navy-dark: #0f1721;
  --gold: #c9a55a;
  --gold-light: #d4b574;
  --gold-dark: #b5944d;
  --text: #1a2332;
  --text-secondary: #4a5568;
  --text-light: #718096;
  --bg: #f8f9fb;
  --white: #ffffff;
  --success: #059669;
  --error: #dc2626;
  --border: #e2e8f0;
  --radius: 12px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 3px rgba(26, 35, 50, 0.08);
  --shadow-md: 0 4px 12px rgba(26, 35, 50, 0.1);
  --shadow-lg: 0 12px 32px rgba(26, 35, 50, 0.16);
  --font-heading: 'Crimson Pro', Georgia, serif;
  --font-body: 'Work Sans', -apple-system, system-ui, sans-serif;
}

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

html, body { height: 100%; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 15px;
}

a { color: var(--navy-light); text-decoration: none; }
a:hover { color: var(--gold-dark); }

/* ---------- Topbar ---------- */

.topbar {
  background: var(--navy);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-md);
}

.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  min-height: 64px;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-heading);
  font-size: 1.15rem;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
}

.topbar-brand img {
  height: 34px;
  width: 34px;
  object-fit: contain;
  filter: brightness(0) invert(1);
}

.topbar-brand .brand-sub {
  display: block;
  font-family: var(--font-body);
  font-size: 0.65rem;
  font-weight: 500;
  color: var(--gold);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.topbar-nav {
  display: flex;
  gap: 0.25rem;
  flex: 1;
}

.topbar-nav a {
  color: #cbd5e1;
  padding: 0.45rem 0.9rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.2s, color 0.2s;
}

.topbar-nav a:hover { color: #fff; background: rgba(255, 255, 255, 0.08); }

.topbar-nav a.active {
  color: #fff;
  background: rgba(201, 165, 90, 0.22);
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: rgba(255, 255, 255, 0.08);
  padding: 0.35rem 0.8rem 0.35rem 0.45rem;
  border-radius: 999px;
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--navy);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.85rem;
}

.user-info {
  line-height: 1.2;
}

.user-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: #fff;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-role {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--gold);
  font-weight: 600;
}

.btn-signout {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: #cbd5e1;
  padding: 0.4rem 0.85rem;
  border-radius: 6px;
  font-family: var(--font-body);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-signout:hover { background: var(--error); border-color: var(--error); color: #fff; }

/* ---------- Layout ---------- */

.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

.page-header {
  margin-bottom: 1.75rem;
}

.page-header h1 {
  font-family: var(--font-heading);
  font-size: 1.9rem;
  color: var(--text);
}

.page-header p {
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

/* ---------- Cards & stats ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  box-shadow: var(--shadow-sm);
  border-top: 3px solid var(--gold);
}

.stat-card .stat-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-light);
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.stat-card .stat-value {
  font-family: var(--font-heading);
  font-size: 2rem;
  font-weight: 700;
  color: var(--navy);
}

.stat-card .stat-hint {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-top: 0.2rem;
}

/* ---------- Panels ---------- */

.panel {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
  margin-bottom: 1.75rem;
}

.panel-title {
  font-family: var(--font-heading);
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.75rem; }

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
}

.chart-wrap { position: relative; height: 320px; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; }

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th {
  text-align: left;
  padding: 0.7rem 0.9rem;
  color: var(--text-light);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 0.8rem 0.9rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tr:hover td { background: #fafbfd; }

.badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge.green { background: #e7f6ee; color: var(--success); }
.badge.gray { background: #eef1f5; color: var(--text-secondary); }
.badge.gold { background: #f7efdd; color: var(--gold-dark); }
.badge.red { background: #fdecec; color: var(--error); }

.status-pill {
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.status-pill.active { background: #e7f6ee; color: var(--success); }
.status-pill.inactive { background: #fdecec; color: var(--error); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 1.15rem;
  border-radius: 8px;
  border: none;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary { background: var(--gold); color: var(--navy); }
.btn-primary:hover { background: var(--gold-light); }

.btn-navy { background: var(--navy); color: #fff; }
.btn-navy:hover { background: var(--navy-light); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.btn-outline:hover { border-color: var(--navy-light); color: var(--navy); }

.btn-danger { background: #fdecec; color: var(--error); border: 1px solid #f5c6c6; }
.btn-danger:hover { background: var(--error); color: #fff; }

.btn-sm { padding: 0.35rem 0.8rem; font-size: 0.8rem; }

.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 33, 0.55);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 4vh 1rem 1rem;
  z-index: 100;
  overflow-y: auto;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.15rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-family: var(--font-heading);
  font-size: 1.25rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--text-light);
  cursor: pointer;
  line-height: 1;
}

.modal-close:hover { color: var(--error); }

.modal-body { padding: 1.5rem; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
}

/* ---------- Forms ---------- */

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }

.form-field { display: flex; flex-direction: column; gap: 0.35rem; }
.form-field.full { grid-column: 1 / -1; }

.form-field label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.form-field input,
.form-field textarea,
.form-field select {
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--text);
  background: var(--white);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-field input:focus,
.form-field textarea:focus,
.form-field select:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201, 165, 90, 0.18);
}

.form-field textarea { resize: vertical; min-height: 90px; }

.form-field .hint { font-size: 0.75rem; color: var(--text-light); }

/* ---------- Login page ---------- */

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-dark) 100%);
  padding: 2rem 1rem;
  position: relative;
  overflow: hidden;
}

.auth-wrap::before,
.auth-wrap::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  opacity: 0.12;
}
.auth-wrap::before { width: 340px; height: 340px; background: var(--gold); top: -120px; right: -80px; }
.auth-wrap::after { width: 260px; height: 260px; background: var(--gold); bottom: -100px; left: -60px; }

.auth-card {
  background: var(--white);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 420px;
  padding: 2.4rem 2.2rem;
  position: relative;
  z-index: 1;
}

.auth-logo {
  text-align: center;
  margin-bottom: 1.5rem;
}

.auth-logo img {
  height: 60px;
  width: 60px;
  object-fit: contain;
}

.auth-logo h1 {
  font-family: var(--font-heading);
  font-size: 1.5rem;
  margin-top: 0.7rem;
}

.auth-logo p {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-top: 0.2rem;
}

.auth-form { display: flex; flex-direction: column; gap: 1rem; }

.auth-error {
  background: #fdecec;
  border: 1px solid #f5c6c6;
  color: var(--error);
  font-size: 0.85rem;
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
  display: none;
}

.auth-error.show { display: block; }

.auth-footer {
  text-align: center;
  margin-top: 1.5rem;
  font-size: 0.82rem;
  color: var(--text-light);
}

.auth-hint {
  margin-top: 1rem;
  background: #fafbfd;
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  font-size: 0.76rem;
  color: var(--text-light);
  line-height: 1.5;
}

/* ---------- Alerts ---------- */

.alert {
  padding: 0.85rem 1.1rem;
  border-radius: 8px;
  font-size: 0.9rem;
  margin-bottom: 1rem;
  display: none;
}
.alert.show { display: block; }
.alert.success { background: #e7f6ee; color: var(--success); border: 1px solid #b7e3c9; }
.alert.error { background: #fdecec; color: var(--error); border: 1px solid #f5c6c6; }

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-light);
}
.empty-state i { font-size: 2.2rem; margin-bottom: 0.6rem; color: var(--border); }
.empty-state p { font-size: 0.9rem; }

/* ---------- Filter bar ---------- */

.filter-bar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  padding: 1.1rem 1.5rem;
  margin-bottom: 1.25rem;
}

.filter-bar label {
  display: inline-block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-right: 0.5rem;
}

.filter-bar select,
.filter-bar input[type='search'] {
  padding: 0.5rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--text);
  background: var(--white);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.filter-bar select:focus,
.filter-bar input[type='search']:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(201, 165, 90, 0.18);
}

.filter-bar input[type='search'] { width: 260px; }

.filter-spacer { margin-left: auto; }

@media (max-width: 700px) {
  .filter-bar { gap: 1rem; }
  .filter-bar input[type='search'] { width: 100%; }
  .filter-spacer { margin-left: 0; }
}

/* ---------- Misc ---------- */

.loading {
  padding: 2rem;
  text-align: center;
  color: var(--text-light);
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--gold);
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.muted { color: var(--text-light); }
.mono { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; font-size: 0.8rem; }

@media (max-width: 760px) {
  .topbar-inner { flex-wrap: wrap; padding: 0.5rem 1rem; }
  .topbar-nav { order: 3; flex-basis: 100%; gap: 0.15rem; }
  .topbar-nav a { font-size: 0.8rem; padding: 0.35rem 0.65rem; }
  .user-name { display: none; }
  .main { padding: 1.25rem 1rem 3rem; }
  .page-header h1 { font-size: 1.5rem; }
}