:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;       /* disbursed / primary series */
  --accent-soft: #b7d3f6;  /* sanctioned track */
  --brand: #0d6e3f;        /* NABARD-style green, used for chrome only */
  --ramp: #86b6ef, #5598e7, #2a78d6, #1c5cab, #104281;
  /* Map classes, low -> high. Light: darker = more. Dark: brighter = more. */
  --seq: #cde2fb, #86b6ef, #3987e5, #1c5cab, #0d366b;
  --no-data: #e9e8e3;
  --logo-bg: transparent; /* dark themes switch this to white so the green wordmark stays legible */
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --ink: #ffffff; --ink-2: #c3c2b7;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5; --accent-soft: #184f95; --brand: #3fb27a;
    --seq: #184f95, #256abf, #3987e5, #6da7ec, #b7d3f6; --no-data: #2c2c2a; --logo-bg: #fff;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --ink: #ffffff; --ink-2: #c3c2b7;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5; --accent-soft: #184f95; --brand: #3fb27a;
  --seq: #184f95, #256abf, #3987e5, #6da7ec, #b7d3f6; --no-data: #2c2c2a; --logo-bg: #fff;
}

* { box-sizing: border-box; }
body {
  margin: 0; padding: 24px clamp(16px, 3vw, 40px) 40px;
  background: var(--page); color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  max-width: 1400px; margin-inline: auto;
}
h1 { font-size: 24px; margin: 2px 0 4px; font-weight: 650; }
h2 { font-size: 14px; margin: 0 0 8px; font-weight: 600; }
.eyebrow { margin: 0; color: var(--brand); font-weight: 600; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; }
.sub, .muted { color: var(--ink-2); margin: 0; font-weight: 400; }

button.ghost, select, input[type=search] {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px;
}
button.ghost { cursor: pointer; white-space: nowrap; }
button.ghost:hover { background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
button:disabled { opacity: .4; cursor: default; }


.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile, .card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }
.tile { display: flex; flex-direction: column; gap: 2px; }
.tile .lbl { font-size: 12px; color: var(--ink-2); }
.tile .val { font-size: 28px; font-weight: 650; }
.tile .note { font-size: 12px; color: var(--muted); }
.meter { height: 6px; border-radius: 3px; background: var(--grid); overflow: hidden; margin-top: 6px; }
.meter i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width .3s; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 12px; }
.card.wide { grid-column: 1 / -1; }
.chart { height: 280px; width: 100%; }
.chart.tall { height: 420px; }

.table-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.table-head input { min-width: 260px; flex: 0 1 360px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
th { color: var(--ink-2); font-weight: 600; cursor: pointer; user-select: none; white-space: nowrap; }
th.sorted::after { content: " ▾"; } th.sorted.asc::after { content: " ▴"; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.name { max-width: 460px; }
td .pic { display: block; color: var(--muted); font-size: 11px; }
.bar { display: inline-block; width: 48px; height: 6px; border-radius: 3px; background: var(--grid); margin-right: 6px; vertical-align: middle; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; color: var(--ink-2); }
.pager div { display: flex; gap: 6px; }



/* ---- Sticky header + filters ---- */
.sticky {
  position: sticky; top: 0; z-index: 20;
  margin: -24px calc(-1 * clamp(16px, 3vw, 40px)) 16px;
  padding: 16px clamp(16px, 3vw, 40px) 12px;
  background: var(--page);
  border-bottom: 1px solid transparent;
  transition: box-shadow .2s, border-color .2s;
}
.sticky.stuck { border-bottom-color: var(--border); box-shadow: 0 6px 16px -12px rgba(0, 0, 0, .35); }
.top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 12px; }
.top-actions { display: flex; gap: 8px; }
/* Once scrolled, collapse the header to one line to leave room for the data. */
.sticky.stuck .sub, .sticky.stuck .eyebrow { display: none; }
.sticky.stuck h1 { font-size: 18px; margin: 0; }
.sticky.stuck .top { align-items: center; margin-bottom: 10px; }

.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filter-toggle { display: none; }

.ms { position: relative; }
.ms-btn {
  display: inline-flex; align-items: center; gap: 6px; font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 12px; cursor: pointer; white-space: nowrap;
}
.ms-btn:hover { background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.ms-btn .k { color: var(--ink-2); }
.ms-btn .v { font-weight: 600; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.ms-btn::after { content: "▾"; color: var(--muted); font-size: 11px; }
.ms.active .ms-btn { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.count[hidden] { display: none; }
.count {
  display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; line-height: 1;
}
.ms-panel {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 30; width: 280px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 12px 32px -8px rgba(0, 0, 0, .3); padding: 8px;
}
.ms-panel[hidden] { display: none; }
.ms-panel input[type=search] { width: 100%; margin-bottom: 6px; }
.ms-list { max-height: 280px; overflow-y: auto; }
.ms-opt { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.ms-opt:hover { background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.ms-opt input { accent-color: var(--accent); margin: 0; }
.ms-opt .n { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.ms-foot { display: flex; justify-content: space-between; border-top: 1px solid var(--grid); margin-top: 6px; padding-top: 6px; }

button.link { font: inherit; font-size: 13px; background: none; border: 0; color: var(--accent); cursor: pointer; padding: 4px 6px; border-radius: 6px; }
button.link:hover { text-decoration: underline; }

.applied { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; font-size: 13px; }
.applied[hidden] { display: none; }
.applied-label { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; padding: 3px 4px 3px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  max-width: 100%;
}
.chip .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }
.chip .t b { font-weight: 600; }
.chip button { font: inherit; border: 0; background: none; color: var(--ink-2); cursor: pointer; width: 20px; height: 20px; border-radius: 50%; line-height: 1; }
.chip button:hover { background: color-mix(in srgb, var(--ink) 12%, transparent); color: var(--ink); }

@media (max-width: 760px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .top { align-items: center; }
  .top .sub, .top .eyebrow, .user-btn .uname { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile .val { font-size: 22px; }
  h1 { font-size: 17px; margin: 0; }
  .filter-toggle { display: inline-flex; align-items: center; gap: 6px; }
  .filters .filter-bar { display: none; }
  .filters.open .filter-bar { display: grid; grid-template-columns: 1fr; gap: 6px; }
  .filters.open .ms-btn { width: 100%; justify-content: space-between; }
  .ms-panel { position: static; width: 100%; margin-top: 6px; box-shadow: none; }
  .table-head input { min-width: 0; width: 100%; }
  .sticky { max-height: 85vh; overflow-y: auto; }
}

/* ---- Buttons, forms, badges (shared by login / password / admin) ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; border-radius: 8px; padding: 8px 14px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink); text-decoration: none;
}
.btn:hover { background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: color-mix(in srgb, var(--brand) 88%, #000); }
.btn.danger { color: #d03b3b; }
.btn.small { padding: 4px 10px; font-size: 12px; font-weight: 500; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:focus-visible, button:focus-visible, .ms-btn:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field input:not([type=radio]):not([type=checkbox]), .field select {
  font: inherit; color: var(--ink); background: var(--page); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 12px; width: 100%;
}
.field .hint { font-size: 12px; color: var(--muted); font-weight: 400; }
.pw-wrap { position: relative; display: flex; }
.pw-wrap input { padding-right: 64px; }
.pw-wrap button { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); }
.form-error {
  background: color-mix(in srgb, #d03b3b 12%, var(--surface)); border: 1px solid color-mix(in srgb, #d03b3b 40%, transparent);
  color: var(--ink); border-radius: 8px; padding: 8px 12px; margin-bottom: 14px; font-size: 13px;
}
.form-error[hidden], .form-ok[hidden] { display: none; }
.form-ok {
  background: color-mix(in srgb, #0ca30c 12%, var(--surface)); border: 1px solid color-mix(in srgb, #0ca30c 40%, transparent);
  border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; font-size: 13px;
}

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--ink-2); white-space: nowrap; }
.badge.admin { color: var(--brand); border-color: color-mix(in srgb, var(--brand) 45%, transparent); }
.badge.good::before { content: "●"; color: #0ca30c; }
.badge.warn::before { content: "●"; color: #fab219; }
.badge.bad::before { content: "●"; color: #d03b3b; }

/* ---- Auth pages ---- */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; max-width: none; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px 28px 24px; }
.auth-card h1 { font-size: 22px; margin: 4px 0 4px; }
.auth-card .sub { margin-bottom: 20px; }
.auth-card .btn.primary { width: 100%; padding: 10px; margin-top: 4px; }
.auth-foot { margin-top: 16px; font-size: 12px; color: var(--muted); text-align: center; }

/* ---- User menu ---- */
.user-menu { position: relative; }
.user-btn { display: inline-flex; align-items: center; gap: 8px; }
.avatar {
  display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--brand); color: #fff; font-size: 11px; font-weight: 700;
}
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 40; min-width: 240px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 12px 32px -8px rgba(0, 0, 0, .3); padding: 6px;
}
.menu-panel[hidden] { display: none; }
.menu-who { padding: 8px 10px 10px; border-bottom: 1px solid var(--grid); margin-bottom: 4px; }
.menu-who b { display: block; }
.menu-who span { color: var(--ink-2); font-size: 12px; word-break: break-all; }
.menu-panel a, .menu-panel button {
  display: block; width: 100%; text-align: left; font: inherit; color: var(--ink); background: none; border: 0;
  padding: 8px 10px; border-radius: 6px; cursor: pointer; text-decoration: none;
}
.menu-panel a:hover, .menu-panel button:hover { background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }

/* ---- Admin ---- */
.admin-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.admin-head h2 { margin: 0; font-size: 16px; }
td.actions { text-align: right; }
td.actions > div { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }

td .email { display: block; color: var(--ink-2); font-size: 12px; }
dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 24px; width: min(440px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h3 { margin: 0 0 16px; font-size: 17px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.secret { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.secret code { flex: 1; font-size: 14px; padding: 8px 10px; border-radius: 8px; background: var(--page); border: 1px solid var(--border); word-break: break-all; }
.role-pick { display: flex; gap: 8px; }
.role-pick label { flex: 1; display: flex; gap: 10px; align-items: flex-start; font-weight: 600; color: var(--ink); border: 1px solid var(--border); border-radius: 8px; padding: 10px; cursor: pointer; font-size: 13px; }
.role-pick label:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.role-pick small { display: block; color: var(--muted); font-weight: 400; }
.role-pick input { accent-color: var(--accent); margin: 3px 0 0; }
dialog .sub { margin-bottom: 14px; }

/* ---- District map ---- */
.map-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.map-head h2 { margin: 0; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; padding: 2px; background: var(--page); }
.seg button { font: inherit; font-size: 12px; border: 0; background: none; color: var(--ink-2); padding: 5px 10px; border-radius: 6px; cursor: pointer; }
.seg button[aria-checked="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, .15); }
.map-body { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; }
.chart.map { height: 460px; }
.map-hint { margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.map-panel { border-left: 1px solid var(--grid); padding-left: 16px; min-width: 0; }
.map-panel h3 { font-size: 16px; margin: 0 0 2px; }
.map-panel .muted { font-size: 12px; }
.mp-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; margin: 12px 0 14px; }
.mp-stats div { display: flex; flex-direction: column; }
.mp-stats span { font-size: 11px; color: var(--ink-2); }
.mp-stats b { font-size: 18px; font-weight: 650; }
.mp-sec { font-size: 12px; font-weight: 600; color: var(--ink-2); margin: 12px 0 6px; text-transform: uppercase; letter-spacing: .03em; }
.mp-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 8px; font-size: 12px; margin-bottom: 7px; }
.mp-row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mp-row .vl { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.mp-row .bar { grid-column: 1 / -1; width: 100%; margin: 0; height: 5px; }
.mp-list { list-style: none; padding: 0; margin: 0; }
.mp-list li button {
  display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; gap: 6px; width: 100%; text-align: left;
  font: inherit; font-size: 13px; color: var(--ink); background: none; border: 0; border-radius: 6px; padding: 6px; cursor: pointer;
}
.mp-list li button:hover { background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.mp-list .rk { color: var(--muted); font-variant-numeric: tabular-nums; }
.mp-list .vl { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.mp-actions { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
@media (max-width: 900px) {
  .map-body { grid-template-columns: minmax(0, 1fr); }
  .map-panel { border-left: 0; border-top: 1px solid var(--grid); padding: 12px 0 0; }
  .chart.map { height: 380px; }
}

/* ---- NABARD logo ---- */
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
/* White tile so the green wordmark stays legible in dark mode too. */
.logo-tile {
  flex: none; display: inline-grid; place-items: center; background: var(--logo-bg);
  border-radius: 10px; padding: 4px 10px;
}
.logo-tile img { display: block; height: auto; }
.logo-full { width: 174px; }
.logo-mark { width: 26px; display: none !important; }
/* Pinned header and phones: emblem only, the full name would be too small to read. */
.sticky.stuck .logo-tile { padding: 2px 5px; border-radius: 8px; }
.sticky.stuck .logo-full { display: none; }
.sticky.stuck .logo-mark { display: block !important; }

.auth-logo { display: flex; justify-content: center; margin: 0 -8px 18px; }
.auth-logo img { width: 100%; max-width: 261px; height: auto; }
:root[data-theme="dark"] .auth-logo { background: #fff; border-radius: 10px; padding: 10px 12px; margin: 0 0 18px; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .auth-logo { background: #fff; border-radius: 10px; padding: 10px 12px; margin: 0 0 18px; }
}
.auth-card > .eyebrow, .auth-card > h1, .auth-card > .sub { text-align: center; }

@media (max-width: 760px) {
  .brand { gap: 10px; }
  .top .logo-tile { padding: 2px 5px; border-radius: 8px; }
  .top .logo-full { display: none; }
  .top .logo-mark { display: block !important; }
}

/* ---- Footer ---- */
.site-footer {
  margin-top: 28px; padding-top: 14px; border-top: 1px solid var(--grid);
  text-align: center; font-size: 12px; color: var(--muted);
}
.site-footer .sep { margin: 0 6px; }
.nowrap { white-space: nowrap; }
.auth-page { grid-template-rows: 1fr auto; }
.auth-page .site-footer { border-top: 0; margin-top: 16px; padding-top: 0; }
@media (max-width: 760px) {
  .site-footer .sep { display: none; }
  .site-footer .nowrap { display: block; margin-top: 2px; }
}

/* ---- Sticky project register header ----
   --sticky-h (main header height) and --reg-h (register title bar height)
   are measured in app.js, since both change with filters and screen size. */
.table-card .table-head {
  position: sticky; top: var(--sticky-h, 0px); z-index: 12;
  background: var(--surface);
  margin: -14px -16px 0; padding: 12px 16px 10px;
  border-radius: 12px 12px 0 0;
}
.table-card thead th {
  position: sticky; top: calc(var(--sticky-h, 0px) + var(--reg-h, 0px)); z-index: 11;
  background: var(--surface);
  box-shadow: inset 0 -1px 0 var(--axis); /* keeps the rule visible while stuck */
}
@media (min-width: 761px) {
  /* A scrolling wrapper would stop the column headings sticking, so let the table fit instead. */
  .table-card .table-wrap { overflow: visible; }
  .table-card td.name { max-width: none; min-width: 220px; }
}
@media (max-width: 760px) {
  .table-card thead th { position: static; }
}
