/* Shared design system for the Credit Score & Loan Offer console.
   Loaded by every page (auth screens + the sidebar app shell). Page-level
   <style> blocks should only contain rules that are genuinely unique to
   that page — anything reusable (buttons, inputs, alerts, tables, the
   accordion/factor-detail components, the sidebar) belongs here so all
   screens stay visually consistent. */

:root {
  --color-bg: #f4f6fb;
  --color-surface: #ffffff;
  --color-border: #e3e6ee;
  --color-border-strong: #cdd3e0;
  --color-text: #171b26;
  --color-text-muted: #5b6478;
  --color-text-subtle: #8890a3;

  --color-primary: #2954e0;
  --color-primary-dark: #1f42b8;
  --color-primary-light: #eaf0ff;

  --color-success: #1a7a1a;
  --color-success-bg: #eaf7ea;
  --color-success-border: #bcd9bc;

  --color-danger: #b32424;
  --color-danger-bg: #fdf0f0;
  --color-danger-border: #e0b4b4;

  --color-warning: #8a6300;
  --color-warning-bg: #fff8e1;
  --color-warning-border: #d9a441;

  --sidebar-width: 252px;
  --topbar-height: 62px;
  --sidebar-bg: #10142a;
  --sidebar-bg-active: #1c2350;
  --sidebar-border: #262c4c;
  --sidebar-text: #a7aec7;
  --sidebar-text-muted: #6e7594;
  --sidebar-text-active: #ffffff;
  --sidebar-accent: #6c8bff;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow-md: 0 8px 24px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 16px 40px rgba(16, 24, 40, 0.14);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--color-primary); }
a:hover { color: var(--color-primary-dark); }

h1, h2, h3 { font-weight: 650; letter-spacing: -0.01em; }

code {
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  background: var(--color-primary-light);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
}

.hint {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-top: 4px;
}

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

button, .btn {
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-primary);
  background: var(--color-primary);
  color: #fff;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, opacity 0.15s ease, box-shadow 0.15s ease;
  box-shadow: var(--shadow-sm);
}

button:hover, .btn:hover { background: var(--color-primary-dark); border-color: var(--color-primary-dark); }
button:focus-visible, .btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--sidebar-accent);
  outline-offset: 2px;
}
button:disabled, .btn:disabled { cursor: not-allowed; opacity: 0.5; box-shadow: none; }

button.btn-secondary, .btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border-strong);
}
button.btn-secondary:hover, .btn-secondary:hover { background: #f6f7fb; border-color: var(--color-text-subtle); }

button.remove-btn, button.delete-btn, .actions button.delete-btn, .actions .toggle-active-btn {
  background: var(--color-surface);
  color: var(--color-danger);
  border: 1px solid var(--color-danger-border);
  box-shadow: none;
  font-weight: 600;
  padding: 6px 12px;
}
button.remove-btn:hover, button.delete-btn:hover, .actions button.delete-btn:hover, .actions .toggle-active-btn:hover {
  background: var(--color-danger-bg);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.actions button {
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border-strong);
  box-shadow: none;
  font-weight: 600;
  padding: 6px 12px;
  white-space: nowrap;
}
.actions button:hover { background: #f6f7fb; }

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

label { display: block; margin-top: 12px; font-weight: 600; font-size: 0.88rem; }

input, select, textarea {
  font-family: inherit;
  font-size: 0.92rem;
  padding: 9px 11px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text);
  width: 100%;
  box-sizing: border-box;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

input[type="checkbox"] { width: auto; }

/* ---------- Alerts / status banners ---------- */

#error, #success, #message, .status,
.alert {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  display: none;
}

#error, .alert-error, .status.error { background: var(--color-danger-bg); border: 1px solid var(--color-danger-border); color: #7a1d1d; }
#success, #message, .alert-success, .status.success { background: var(--color-success-bg); border: 1px solid var(--color-success-border); color: #145c14; }
.alert-warning, .status.warning { background: var(--color-warning-bg); border: 1px solid var(--color-warning-border); color: #6b4b00; }

.status-badge {
  font-size: 0.74rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 10px;
  display: inline-block;
  letter-spacing: 0.01em;
}
.status-badge.success { background: #e3f5e3; color: #1a7a1a; }
.status-badge.error { background: #fbdcdc; color: #b32424; }

/* ---------- Cards / tables ---------- */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

table {
  border-collapse: collapse;
  width: 100%;
  margin-top: 12px;
  font-size: 0.88rem;
}
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--color-border); vertical-align: middle; }
th { background: #f7f8fc; font-weight: 650; color: var(--color-text-muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
tbody tr:hover { background: #fafbfe; }

/* ---------- Auth screens (login / forgot / reset / force-change) ---------- */

body.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background:
    radial-gradient(1100px 480px at 12% -10%, #eef2ff 0%, transparent 60%),
    radial-gradient(900px 460px at 110% 10%, #eef6ff 0%, transparent 55%),
    var(--color-bg);
}

.auth-shell { width: 100%; max-width: 380px; }

.auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 22px;
}
.auth-brand .brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--color-primary), #5c7cf0);
  color: #fff; font-weight: 800; font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm);
}
.auth-brand .brand-name { font-weight: 700; font-size: 1.02rem; color: var(--color-text); }

.auth-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 30px 28px 26px;
}

.auth-card h1 { font-size: 1.2rem; text-align: center; margin: 0 0 6px; }
.auth-card p.intro, .auth-card .context-message {
  font-size: 0.86rem; color: var(--color-text-muted); text-align: center; margin: 0 0 20px;
}

.auth-card button[type="submit"] { width: 100%; margin-top: 22px; padding: 10px 16px; }

.back-link, .forgot-link { text-align: center; margin-top: 18px; font-size: 0.84rem; }
.back-link a, .forgot-link a { color: var(--color-primary); text-decoration: none; }
.back-link a:hover, .forgot-link a:hover { text-decoration: underline; }

/* ---------- App shell (sidebar + topbar) ---------- */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 40;
  transition: transform 0.2s ease;
}

.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--sidebar-border);
}
.sidebar-brand .brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--color-primary), #5c7cf0);
  color: #fff; font-weight: 800; font-size: 0.9rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sidebar-brand .brand-name { font-weight: 700; font-size: 0.96rem; color: #fff; letter-spacing: -0.01em; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 14px 10px; }

.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.87rem; font-weight: 550;
}
.nav-link:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav-link.active { background: var(--sidebar-bg-active); color: var(--sidebar-text-active); box-shadow: inset 3px 0 0 var(--sidebar-accent); }
.nav-link .nav-icon { width: 17px; text-align: center; flex-shrink: 0; opacity: 0.9; }

.nav-group { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--sidebar-border); }
.nav-group-label {
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--sidebar-text-muted); padding: 0 12px 8px;
}

.sidebar-footer { border-top: 1px solid var(--sidebar-border); padding: 14px; }
.sidebar-user { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--sidebar-bg-active); color: #fff; font-weight: 700; font-size: 0.82rem;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  border: 1px solid var(--sidebar-border);
}
.user-meta { min-width: 0; }
.user-name { font-size: 0.84rem; font-weight: 650; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 0.72rem; color: var(--sidebar-text-muted); text-transform: capitalize; }

.sidebar-footer .logout-btn {
  width: 100%;
  background: transparent;
  color: var(--sidebar-text);
  border: 1px solid var(--sidebar-border);
  box-shadow: none;
  font-size: 0.82rem;
  padding: 7px 10px;
  text-decoration: none;
  display: block;
  text-align: center;
}
.sidebar-footer .logout-btn:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }

.main-wrap { flex: 1; margin-left: var(--sidebar-width); display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: var(--topbar-height);
  display: flex; align-items: center; gap: 14px;
  padding: 0 28px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-size: 1.08rem; margin: 0; font-weight: 650; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 14px; }

.sidebar-toggle {
  display: none;
  background: transparent; border: none; box-shadow: none;
  color: var(--color-text); font-size: 1.2rem; padding: 4px 6px; cursor: pointer;
}

.sidebar-backdrop { display: none; }

.main-content {
  flex: 1;
  padding: 28px 32px 48px;
  max-width: 980px;
  width: 100%;
}

@media (max-width: 880px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  .app-shell.sidebar-open .sidebar { transform: translateX(0); }
  .main-wrap { margin-left: 0; }
  .sidebar-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .app-shell.sidebar-open .sidebar-backdrop {
    display: block; position: fixed; inset: 0; background: rgba(10, 12, 24, 0.45); z-index: 30;
  }
  .main-content { padding: 22px 18px 40px; }
}

/* ---------- Dashboard ---------- */

.dashboard-hero { margin-bottom: 26px; }
.dashboard-hero h1 { font-size: 1.5rem; margin: 0 0 4px; }
.dashboard-hero p { color: var(--color-text-muted); margin: 0; font-size: 0.94rem; }

.section-label {
  font-size: 0.74rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--color-text-subtle); margin: 28px 0 10px;
}
.section-label:first-of-type { margin-top: 0; }

.menu { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.menu-card {
  display: block; padding: 18px; border: 1px solid var(--color-border); border-radius: var(--radius-md);
  text-decoration: none; color: inherit; background: var(--color-surface);
  box-shadow: var(--shadow-sm); transition: transform 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}
.menu-card:hover { border-color: var(--color-primary); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.menu-card .menu-icon {
  width: 36px; height: 36px; border-radius: 9px; background: var(--color-primary-light); color: var(--color-primary);
  display: flex; align-items: center; justify-content: center; font-size: 1.05rem; margin-bottom: 12px;
}
.menu-card h2 { margin: 0 0 4px; font-size: 1rem; color: var(--color-text); }
.menu-card p { margin: 0; font-size: 0.84rem; color: var(--color-text-muted); line-height: 1.4; }

/* ---------- Shared accordion / factor-detail components
   (index.html, bulk_upload.html, multi_customer_upload.html) ---------- */

.row { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--color-border); }
.row:last-child { border-bottom: none; }
.factor-positive { color: var(--color-success); }
.factor-negative { color: var(--color-danger); }

.factor-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 6px; border-bottom: 1px solid var(--color-border); cursor: pointer; user-select: none;
}
.factor-row:hover { background: #f7f8fc; }
.factor-name { word-break: break-word; padding-right: 8px; }
.chevron { display: inline-block; margin-left: 8px; font-size: 0.7em; transition: transform 0.2s ease; transform: rotate(0deg); }
.factor-row.expanded .chevron, .chevron.expanded { transform: rotate(90deg); }

.factor-detail {
  max-height: 0; overflow: hidden; background: #f7f8fc;
  border-bottom: 1px solid var(--color-border);
  transition: max-height 0.25s ease, padding 0.25s ease;
  padding: 0 12px; box-sizing: border-box;
}
.factor-detail.expanded { max-height: 900px; padding: 12px; }

.detail-line { margin: 6px 0; font-size: 0.85rem; line-height: 1.4; overflow-wrap: break-word; }
.detail-line .label { font-weight: 600; }

.bar-track { background: #e2e5ee; border-radius: 4px; height: 10px; overflow: hidden; margin: 4px 0; }
.bar-fill { background: var(--color-primary); height: 100%; }
.bar-label { font-size: 0.78rem; color: var(--color-text-muted); }

.formula {
  font-family: ui-monospace, monospace; font-size: 0.82rem;
  background: #fff; border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  padding: 6px 8px; margin: 6px 0; white-space: normal;
  overflow-wrap: break-word; word-break: break-word;
}

.explanation { font-style: italic; color: var(--color-text-muted); }

.view-raw-data-btn {
  background: none; border: none; padding: 4px 0; margin-top: 8px;
  color: var(--color-primary); font-size: 0.78rem; cursor: pointer; font-weight: 600;
  text-decoration: underline; display: inline-flex; align-items: center; box-shadow: none;
}
.view-raw-data-btn:hover { color: var(--color-primary-dark); background: none; }
.view-raw-data-btn.expanded .chevron { transform: rotate(90deg); }

.nested-detail {
  max-height: 0; overflow: hidden; background: #fff;
  border: 1px solid var(--color-border); border-radius: var(--radius-sm); box-sizing: border-box;
  transition: max-height 0.25s ease, padding 0.25s ease;
  padding: 0 8px; margin-top: 4px;
}
.nested-detail.expanded { max-height: 420px; padding: 8px; overflow-y: auto; }

.table-scroll { overflow-x: auto; max-width: 100%; }
.supporting-data-table { border-collapse: collapse; width: 100%; font-size: 0.78rem; margin-top: 0; }
.supporting-data-table th, .supporting-data-table td {
  padding: 4px 8px; border-bottom: 1px solid #ebedf3; text-align: left; white-space: nowrap; font-size: 0.78rem;
}
.supporting-data-table th { text-transform: none; letter-spacing: normal; font-weight: 600; color: #444; background: transparent; }
.supporting-data-table.compact th { font-weight: 600; color: #444; }
.supporting-data-table tr.highlight-row { background: #fff3cd; font-weight: 600; }

.no-data-message { font-size: 0.8rem; color: var(--color-text-subtle); font-style: italic; margin: 6px 0; }

.result-header-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.report-link { font-size: 0.85rem; color: var(--color-primary); text-decoration: none; white-space: nowrap; font-weight: 600; }
.report-link:hover { text-decoration: underline; }
