:root {
  --ll-navy: #172554;
  --ll-blue: #2563eb;
  --ll-blue-dark: #1d4ed8;
  --ll-ink: #172033;
  --ll-muted: #667085;
  --ll-border: #e4e7ec;
  --ll-surface: #ffffff;
  --ll-canvas: #f7f8fb;
  --ll-success: #15803d;
  --ll-warning: #b45309;
  --ll-radius: .75rem;
  --ll-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 4px 14px rgba(16, 24, 40, .04);
}

html, body { min-height: 100%; }
body {
  margin: 0;
  color: var(--ll-ink);
  background: var(--ll-canvas);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: .9375rem;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--ll-blue); text-underline-offset: 2px; }
a:hover { color: var(--ll-blue-dark); }

.app-topbar {
  position: fixed;
  inset: 0 0 auto;
  z-index: 1040;
  height: 64px;
  color: #fff;
  background: var(--ll-navy);
  border-bottom: 1px solid rgba(255,255,255,.1);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: .65rem;
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
  text-decoration: none;
  letter-spacing: -.02em;
}
.brand:hover { color: #fff; }
.brand-mark {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  color: var(--ll-navy);
  background: #fff;
  border-radius: 9px;
  font-size: 1.25rem;
}
.account-menu { display: flex; align-items: center; gap: .55rem; color: #fff; border: 0; }
.account-menu:hover, .account-menu:focus { color: #fff; background: rgba(255,255,255,.1); }
.avatar {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  background: #dbeafe;
  color: var(--ll-navy);
  border-radius: 50%;
  font-weight: 700;
}
.btn-icon { color: #fff; font-size: 1.25rem; }
.app-layout { min-height: 100vh; padding-top: 64px; }
.app-sidebar {
  position: fixed;
  top: 64px;
  bottom: 0;
  width: 248px;
  background: var(--ll-surface);
  border-right: 1px solid var(--ll-border);
}
.app-sidebar .offcanvas-body { height: 100%; }
.nav-section-label {
  padding: .5rem .75rem;
  color: #98a2b3;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.app-sidebar .nav-link {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .68rem .78rem;
  color: #475467;
  border-radius: .55rem;
  font-weight: 600;
}
.app-sidebar .nav-link i { font-size: 1.05rem; }
.app-sidebar .nav-link:hover { color: var(--ll-ink); background: #f2f4f7; }
.app-sidebar .nav-link.active { color: var(--ll-blue-dark); background: #eff6ff; }
.sidebar-help {
  display: flex;
  gap: .7rem;
  padding: .85rem;
  color: var(--ll-muted);
  background: #f8fafc;
  border: 1px solid var(--ll-border);
  border-radius: var(--ll-radius);
  font-size: .8rem;
}
.sidebar-help i { font-size: 1.1rem; }
.sidebar-help strong, .sidebar-help a { display: block; }
.app-main { min-width: 0; }
.content-container { max-width: 1240px; margin: 0 auto; padding: 2.25rem clamp(1rem, 3vw, 3rem) 4rem; }

.page-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 1.5rem; margin-bottom: 1.75rem; }
.page-title { margin: 0; font-size: clamp(1.6rem, 3vw, 2rem); font-weight: 750; letter-spacing: -.035em; }
.page-description { max-width: 700px; margin: .45rem 0 0; color: var(--ll-muted); line-height: 1.6; }
.eyebrow { margin-bottom: .35rem; color: var(--ll-blue); font-size: .75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }

.btn { border-radius: .55rem; font-weight: 650; }
.btn-primary { background: var(--ll-blue); border-color: var(--ll-blue); }
.btn-primary:hover { background: var(--ll-blue-dark); border-color: var(--ll-blue-dark); }
.btn-light { background: #fff; border-color: var(--ll-border); }
.btn-light:hover { background: #f9fafb; border-color: #d0d5dd; }
.card, .surface {
  background: var(--ll-surface);
  border: 1px solid var(--ll-border);
  border-radius: var(--ll-radius);
  box-shadow: var(--ll-shadow);
}
.card-header { padding: 1rem 1.25rem; background: transparent; border-bottom-color: var(--ll-border); font-weight: 700; }
.card-body { padding: 1.25rem; }

.status-badge { display: inline-flex; align-items: center; gap: .35rem; padding: .28rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 700; text-transform: capitalize; }
.status-badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-linked { color: var(--ll-success); background: #ecfdf3; }
.status-pending { color: var(--ll-warning); background: #fff7ed; }
.status-closed { color: var(--ll-muted); background: #f2f4f7; }
.muted { color: var(--ll-muted); }

.connection-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 1rem; }
.connection-card { display: flex; flex-direction: column; min-height: 220px; padding: 1.25rem; color: inherit; text-decoration: none; transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease; }
.connection-card:hover { color: inherit; transform: translateY(-2px); border-color: #bfdbfe; box-shadow: 0 10px 24px rgba(16,24,40,.08); }
.institution-icon { display: grid; width: 42px; height: 42px; place-items: center; color: var(--ll-blue-dark); background: #eff6ff; border-radius: .7rem; font-size: 1.15rem; }
.connection-card h2 { margin: 1rem 0 .25rem; font-size: 1.05rem; font-weight: 700; }
.account-list { margin: .85rem 0 0; padding: .85rem 0 0; border-top: 1px solid var(--ll-border); list-style: none; }
.account-list li { display: flex; justify-content: space-between; gap: 1rem; padding: .25rem 0; color: var(--ll-muted); font-size: .85rem; }

.empty-state { padding: 4rem 1.5rem; text-align: center; }
.empty-state-icon { display: grid; width: 58px; height: 58px; margin: 0 auto 1rem; place-items: center; color: var(--ll-blue); background: #eff6ff; border-radius: 1rem; font-size: 1.5rem; }
.empty-state h2 { font-size: 1.15rem; }
.empty-state p { max-width: 460px; margin: .5rem auto 1.25rem; color: var(--ll-muted); }

.data-table { margin: 0; }
.data-table thead th { padding: .75rem 1rem; color: var(--ll-muted); background: #f9fafb; border-bottom: 1px solid var(--ll-border); font-size: .72rem; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }
.data-table tbody td { padding: .9rem 1rem; border-color: #eef0f3; vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.table-responsive { border-radius: var(--ll-radius); }
.code-pill { display: inline-flex; padding: .25rem .5rem; color: #344054; background: #f2f4f7; border-radius: .35rem; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem; }

.form-card { max-width: 720px; }
.form-card form > p { margin-bottom: 1.15rem; }
.form-card label, form > p > label { display: block; margin-bottom: .4rem; font-weight: 650; }
input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select, textarea {
  display: block;
  width: 100%;
  padding: .65rem .75rem;
  color: var(--ll-ink);
  background: #fff;
  border: 1px solid #d0d5dd;
  border-radius: .5rem;
}
input:focus, select:focus, textarea:focus { border-color: #84adff; outline: 0; box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.helptext { display: block; margin-top: .35rem; color: var(--ll-muted); font-size: .8rem; line-height: 1.45; }
.errorlist { margin: 0 0 .4rem; padding: .55rem .75rem; color: #b42318; background: #fef3f2; border-radius: .45rem; list-style: none; font-size: .82rem; }
#id_account_types { display: grid; gap: .35rem; padding: 0; list-style: none; }
#id_account_types label { display: flex; align-items: center; gap: .5rem; font-weight: 500; text-transform: capitalize; }

.detail-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(250px, 1fr); gap: 1rem; }
.metric-list { margin: 0; }
.metric-row { display: flex; justify-content: space-between; gap: 1rem; padding: .8rem 0; border-bottom: 1px solid var(--ll-border); }
.metric-row:last-child { border-bottom: 0; }
.metric-row dt { color: var(--ll-muted); font-weight: 500; }
.metric-row dd { margin: 0; font-weight: 650; text-align: right; }
.download-option { display: flex; align-items: center; gap: .8rem; padding: .85rem; color: inherit; border: 1px solid var(--ll-border); border-radius: .6rem; text-decoration: none; }
.download-option:hover { color: inherit; border-color: #93c5fd; background: #f8fbff; }
.download-icon { display: grid; width: 38px; height: 38px; place-items: center; color: var(--ll-blue); background: #eff6ff; border-radius: .55rem; }

.auth-shell { min-height: calc(100vh - 64px); display: grid; place-items: center; padding: 2rem 1rem; }
.auth-card { width: 100%; max-width: 460px; padding: 2rem; }
.auth-card h1 { font-size: 1.6rem; font-weight: 750; letter-spacing: -.03em; }
.auth-card form button[type="submit"], .auth-card form input[type="submit"] { width: 100%; margin-top: .5rem; padding: .7rem; color: #fff; background: var(--ll-blue); border: 1px solid var(--ll-blue); border-radius: .55rem; font-weight: 700; }

.error-shell {
  min-height: calc(100vh - 64px);
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
  background:
    radial-gradient(circle at 50% 30%, rgba(37, 99, 235, .08), transparent 34rem),
    var(--ll-canvas);
}
.error-card {
  position: relative;
  overflow: hidden;
  width: 100%;
  max-width: 620px;
  padding: clamp(2rem, 6vw, 3.5rem);
  text-align: center;
}
.error-code {
  position: absolute;
  top: -2.25rem;
  right: -1rem;
  color: #f2f4f7;
  font-size: 9rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.08em;
  user-select: none;
}
.error-icon {
  position: relative;
  display: grid;
  width: 64px;
  height: 64px;
  margin: 0 auto 1.5rem;
  place-items: center;
  color: var(--ll-blue);
  background: #eff6ff;
  border: 1px solid #dbeafe;
  border-radius: 1rem;
  font-size: 1.65rem;
}
.error-card h1 {
  position: relative;
  margin: .4rem 0 .75rem;
  font-size: clamp(2rem, 5vw, 2.75rem);
  font-weight: 750;
  letter-spacing: -.045em;
}
.error-message {
  position: relative;
  max-width: 470px;
  margin: 0 auto;
  color: var(--ll-muted);
  font-size: 1rem;
  line-height: 1.65;
}
.error-actions {
  position: relative;
  display: flex;
  justify-content: center;
  gap: .65rem;
  margin-top: 1.75rem;
}
.error-support {
  position: relative;
  margin: 1.5rem 0 0;
  color: var(--ll-muted);
  font-size: .82rem;
}

pre.config-preview { margin: 0; padding: 1.25rem; color: #d1e7ff; background: #101828; border-radius: var(--ll-radius); font-size: .82rem; white-space: pre-wrap; }

@media (min-width: 768px) {
  .app-main { margin-left: 248px; }
}
@media (max-width: 767.98px) {
  .app-sidebar { top: 0; width: min(300px, 86vw); }
  .page-header { flex-direction: column; }
  .page-header .btn { width: 100%; }
  .detail-grid { grid-template-columns: 1fr; }
  .content-container { padding-top: 1.5rem; }
  .error-actions { flex-direction: column; }
  .error-actions .btn { width: 100%; }
}
