/* MSTRPay Microfinance — design system. Palette validated (dataviz six checks, light+dark). */

:root {
  color-scheme: light;
  --page:           #f9f9f7;
  --surface-1:      #fcfcfb;
  --surface-2:      #ffffff;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --grid:           #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11,11,11,0.10);
  --border-strong:  rgba(11,11,11,0.18);
  --series-1:       #2a78d6;
  --series-2:       #008300;
  --series-3:       #e87ba4;
  --series-4:       #eda100;
  --status-good:    #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical:#d03b3b;
  --delta-good:     #006300;
  --accent:         var(--series-1);
  --shadow-1: 0 1px 2px rgba(11,11,11,0.05);
  --shadow-2: 0 6px 24px rgba(11,11,11,0.10);
  --shadow-3: 0 16px 48px rgba(11,11,11,0.18);
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d; --surface-1: #1a1a19; --surface-2: #222221;
    --text-primary: #ffffff; --text-secondary: #c3c2b7; --text-muted: #898781;
    --grid: #2c2c2a; --baseline: #383835;
    --border: rgba(255,255,255,0.10); --border-strong: rgba(255,255,255,0.20);
    --series-1: #3987e5; --series-2: #008300; --series-3: #d55181; --series-4: #c98500;
    --delta-good: #0ca30c;
    --shadow-1: 0 1px 2px rgba(0,0,0,0.4); --shadow-2: 0 6px 24px rgba(0,0,0,0.45);
    --shadow-3: 0 16px 48px rgba(0,0,0,0.6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface-1: #1a1a19; --surface-2: #222221;
  --text-primary: #ffffff; --text-secondary: #c3c2b7; --text-muted: #898781;
  --grid: #2c2c2a; --baseline: #383835;
  --border: rgba(255,255,255,0.10); --border-strong: rgba(255,255,255,0.20);
  --series-1: #3987e5; --series-2: #008300; --series-3: #d55181; --series-4: #c98500;
  --delta-good: #0ca30c;
  --shadow-1: 0 1px 2px rgba(0,0,0,0.4); --shadow-2: 0 6px 24px rgba(0,0,0,0.45);
  --shadow-3: 0 16px 48px rgba(0,0,0,0.6);
}

* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  background: var(--page); color: var(--text-primary);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; }
a { color: var(--accent); text-decoration: none; }
::selection { background: color-mix(in srgb, var(--accent) 25%, transparent); }

/* ---------- app shell ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
@media (max-width: 900px) { .shell { grid-template-columns: 64px 1fr; } .side .label, .side .sec { display: none; } }

.side {
  background: var(--surface-1); border-right: 1px solid var(--border);
  padding: 18px 12px; display: flex; flex-direction: column; gap: 2px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.side .logo { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; }
.side .logo .mark {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  background: var(--text-primary); color: var(--page);
  display: grid; place-items: center; font-weight: 800; font-size: 15px; letter-spacing: -0.02em;
}
.side .logo .word { font-weight: 700; font-size: 15px; letter-spacing: -0.01em; }
.side .logo .word small { display: block; font-weight: 500; font-size: 11px; color: var(--text-muted); letter-spacing: 0.02em; }
.side .sec {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--text-muted); padding: 14px 10px 5px;
}
.side nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--r-sm);
  color: var(--text-secondary); font-weight: 500; font-size: 13.5px; position: relative;
  transition: background 0.12s, color 0.12s;
}
.side nav a:hover { background: color-mix(in srgb, var(--text-primary) 5%, transparent); color: var(--text-primary); }
.side nav a.active { background: color-mix(in srgb, var(--accent) 11%, transparent); color: var(--text-primary); font-weight: 650; }
.side nav a.active::before {
  content: ''; position: absolute; left: -12px; top: 7px; bottom: 7px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--accent);
}
.side nav a svg { flex: none; opacity: 0.85; }
.side .spacer { flex: 1; }
.side .foot { padding: 10px; font-size: 11px; color: var(--text-muted); line-height: 1.5; }

.maincol { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 14px clamp(14px, 3vw, 28px);
  border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--page) 82%, transparent);
  backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.topbar .crumb { color: var(--text-muted); font-size: 13px; }
.topbar .spacer { flex: 1; }
.content { padding: 20px clamp(14px, 3vw, 28px) 56px; }

/* ---------- badges / pills / status ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase; padding: 3px 10px; border-radius: 99px;
  border: 1px solid var(--border); color: var(--text-secondary); background: var(--surface-1);
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--status-good); animation: pulse 2s infinite; }
.badge.demo .dot { background: var(--status-warning); }
@keyframes pulse { 50% { opacity: 0.35; } }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.status .ic { font-size: 10px; line-height: 1; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 99px;
  font-size: 11.5px; font-weight: 600; border: 1px solid var(--border); color: var(--text-secondary);
  background: var(--surface-1);
}

/* ---------- tiles / cards ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(172px, 1fr)); gap: 12px; margin-bottom: 14px; }
.tile {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 15px 17px; box-shadow: var(--shadow-1); min-width: 0;
}
.tile .label { color: var(--text-secondary); font-size: 12.5px; margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }
.tile .value { font-size: 26px; font-weight: 700; letter-spacing: -0.015em; font-variant-numeric: tabular-nums; }
.tile.hero .value { font-size: 40px; line-height: 1.08; }
.tile .note { font-size: 12px; margin-top: 4px; color: var(--text-muted); }
.tile .spark { margin-top: 8px; }

.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 18px; min-width: 0; box-shadow: var(--shadow-1);
}
.card h2 { font-size: 14.5px; font-weight: 700; margin-bottom: 2px; letter-spacing: -0.01em; }
.card .hint { color: var(--text-muted); font-size: 12.5px; margin-bottom: 12px; }
.card + .card { margin-top: 12px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1.9fr) minmax(0, 1fr); gap: 12px; margin-bottom: 12px; }
.grid2e { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; margin-bottom: 12px; }
@media (max-width: 1000px) { .grid2, .grid2e, .grid3 { grid-template-columns: 1fr; } }

/* ---------- tables ---------- */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left; color: var(--text-muted); font-size: 11.5px; font-weight: 650; letter-spacing: 0.04em;
  text-transform: uppercase; padding: 7px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap;
}
td { padding: 9px 10px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tr.click { cursor: pointer; }
tr.click:hover td { background: color-mix(in srgb, var(--text-primary) 4%, transparent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.mono { font-variant-numeric: tabular-nums; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; flex: none;
  display: inline-grid; place-items: center; font-size: 11px; font-weight: 700;
  background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent);
}
.name-cell { display: flex; align-items: center; gap: 10px; }

/* ---------- buttons / forms ---------- */
.btn {
  all: unset; cursor: pointer; font-size: 13px; font-weight: 600; padding: 7px 14px;
  border-radius: var(--r-sm); border: 1px solid var(--border-strong); background: var(--surface-1);
  color: var(--text-primary); display: inline-flex; align-items: center; gap: 7px;
  transition: background 0.12s, transform 0.05s; white-space: nowrap;
}
.btn:hover { background: color-mix(in srgb, var(--text-primary) 6%, var(--surface-1)); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--text-primary); color: var(--page); border-color: transparent; }
.btn.primary:hover { opacity: 0.86; background: var(--text-primary); }
.btn.danger { color: var(--status-critical); border-color: color-mix(in srgb, var(--status-critical) 40%, transparent); }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }
.btn.ghost { border-color: transparent; color: var(--text-secondary); }
.btn.ghost:hover { color: var(--text-primary); }

.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--text-secondary); min-width: 0; }
.field b { font-weight: 600; }
.field input, .field select, .field textarea {
  font: inherit; font-size: 13.5px; padding: 8px 11px; border-radius: var(--r-sm);
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text-primary);
  min-width: 0; transition: border-color 0.12s, box-shadow 0.12s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .wide { grid-column: 1 / -1; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--r-sm); overflow: hidden; background: var(--surface-1); }
.seg button { all: unset; cursor: pointer; padding: 6px 13px; font-size: 12.5px; color: var(--text-secondary); }
.seg button:hover { background: color-mix(in srgb, var(--text-primary) 5%, transparent); }
.seg button[aria-pressed="true"] { color: var(--text-primary); font-weight: 650; background: color-mix(in srgb, var(--text-primary) 7%, transparent); }

.iconbtn { all: unset; cursor: pointer; padding: 7px; border-radius: var(--r-sm); color: var(--text-secondary); border: 1px solid transparent; display: inline-flex; }
.iconbtn:hover { background: color-mix(in srgb, var(--text-primary) 6%, transparent); color: var(--text-primary); }

.userchip { display: flex; align-items: center; gap: 9px; padding: 4px 6px 4px 4px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface-1); }
.userchip .who { font-size: 12.5px; font-weight: 600; line-height: 1.15; }
.userchip .who small { display: block; font-weight: 400; color: var(--text-muted); font-size: 11px; }

/* ---------- feed ---------- */
.feed { list-style: none; padding: 0; max-height: 356px; overflow-y: auto; }
.feed li { padding: 8px 2px; border-bottom: 1px solid var(--grid); font-size: 13px; display: flex; gap: 9px; }
.feed li:last-child { border-bottom: none; }
.feed .k {
  flex: none; font-size: 10px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--text-muted); width: 76px; padding-top: 3px;
}
.feed li.fresh { animation: flash 1.8s ease-out; }
@keyframes flash { 0% { background: color-mix(in srgb, var(--series-2) 16%, transparent); } 100% { background: transparent; } }

/* ---------- progress ---------- */
.progress { height: 7px; border-radius: 99px; background: var(--grid); overflow: hidden; }
.progress > div { height: 100%; border-radius: 99px; background: var(--series-2); transition: width 0.4s ease; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.38); z-index: 40;
  display: grid; place-items: center; animation: fadein 0.15s ease;
}
@keyframes fadein { from { opacity: 0; } }
.modal {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-3); width: min(520px, calc(100vw - 32px));
  max-height: calc(100vh - 64px); overflow-y: auto; padding: 22px;
  animation: rise 0.18s ease;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(0.985); } }
.modal h3 { font-size: 16px; font-weight: 700; margin-bottom: 4px; letter-spacing: -0.01em; }
.modal .sub { color: var(--text-muted); font-size: 13px; margin-bottom: 16px; }
.modal .actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; }

.drawer-veil { position: fixed; inset: 0; background: rgba(0,0,0,0.3); z-index: 30; animation: fadein 0.15s ease; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 31;
  width: min(660px, 94vw); background: var(--surface-1); border-left: 1px solid var(--border);
  box-shadow: var(--shadow-3); overflow-y: auto; padding: 22px 24px;
  animation: slidein 0.2s ease;
}
@keyframes slidein { from { transform: translateX(30px); opacity: 0.4; } }
.drawer .d-head { display: flex; align-items: start; gap: 10px; margin-bottom: 14px; }
.drawer .d-head h3 { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.drawer .d-head .sub { color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }
.drawer .d-head .close { margin-left: auto; }

/* ---------- toasts ---------- */
#toasts { position: fixed; bottom: 18px; right: 18px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--surface-2); border: 1px solid var(--border); border-left: 3px solid var(--status-good);
  border-radius: var(--r-sm); box-shadow: var(--shadow-2); padding: 11px 15px; font-size: 13px;
  max-width: 360px; animation: rise 0.18s ease; display: flex; gap: 9px; align-items: start;
}
.toast.err { border-left-color: var(--status-critical); }
.toast.info { border-left-color: var(--series-1); }

/* ---------- charts ---------- */
svg text { font: 11.5px system-ui, sans-serif; fill: var(--text-muted); }
svg .tick-num { font-variant-numeric: tabular-nums; }
.legend { display: flex; gap: 14px; margin: 2px 0 10px; font-size: 12.5px; color: var(--text-secondary); flex-wrap: wrap; }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
#tooltip {
  position: fixed; pointer-events: none; z-index: 70; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--r-sm); padding: 9px 11px; font-size: 12.5px;
  box-shadow: var(--shadow-2); display: none; min-width: 150px;
}
#tooltip .row { display: flex; gap: 12px; justify-content: space-between; padding: 1px 0; }
#tooltip .sw { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; }

/* ---------- misc ---------- */
.empty { text-align: center; color: var(--text-muted); padding: 34px 10px; font-size: 13.5px; }
.empty svg { opacity: 0.4; margin-bottom: 8px; }
.skel { border-radius: var(--r-md); background: linear-gradient(100deg, var(--grid) 40%, color-mix(in srgb, var(--grid) 50%, transparent) 50%, var(--grid) 60%); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { to { background-position: -200% 0; } }
.kv { font-size: 13px; } .kv > div { padding: 4px 0; display: flex; gap: 8px; } .kv b { font-weight: 650; min-width: 150px; color: var(--text-secondary); font-weight: 600; }
.note-card {
  border-left: 3px solid var(--series-1); padding: 11px 14px; border-radius: 0 var(--r-sm) var(--r-sm) 0;
  background: color-mix(in srgb, var(--series-1) 6%, transparent); font-size: 13px; color: var(--text-secondary);
  margin-bottom: 14px;
}
.kanban { display: grid; grid-template-columns: repeat(3, minmax(240px, 1fr)); gap: 12px; overflow-x: auto; }
@media (max-width: 1000px) { .kanban { grid-template-columns: 1fr; } }
.kanban .col { background: color-mix(in srgb, var(--text-primary) 3%, var(--page)); border: 1px solid var(--border); border-radius: var(--r-md); padding: 12px; min-width: 0; }
.kanban .col > h3 { font-size: 12px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 10px; display: flex; align-items: center; gap: 7px; }
.kanban .kcard { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 11px 13px; margin-bottom: 9px; box-shadow: var(--shadow-1); }

/* ---------- virtual cards ---------- */
.vcards { display: flex; gap: 14px; overflow-x: auto; padding: 4px 2px 10px; }
.vcard-wrap { flex: none; width: 258px; }
.vcard {
  width: 258px; height: 156px; border-radius: 14px; padding: 16px 18px; position: relative;
  background: linear-gradient(135deg, #17171c 0%, #23232e 55%, #2c2438 100%);
  color: #f4f4f6; box-shadow: var(--shadow-2); display: flex; flex-direction: column;
}
.vcard.frozen { filter: grayscale(0.75); }
.vcard.canceled { opacity: 0.45; filter: grayscale(1); }
.vcard .top { display: flex; align-items: center; justify-content: space-between; }
.vcard .issuer { font-size: 12px; font-weight: 700; letter-spacing: 0.04em; }
.vcard .chip-ic { width: 30px; height: 22px; border-radius: 4px;
  background: linear-gradient(135deg, #d8b45a, #b28a2e); margin-top: 8px; }
.vcard .num { font: 15.5px/1 ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: 0.14em; margin-top: 14px; }
.vcard .bottom { margin-top: auto; display: flex; align-items: flex-end; justify-content: space-between; }
.vcard .holder { font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; opacity: 0.85; }
.vcard .exp { font-size: 11px; opacity: 0.85; }
.vcard .brand { font-size: 15px; font-weight: 800; font-style: italic; letter-spacing: -0.02em; }
.vcard .brand.mc { display: inline-flex; align-items: center; gap: 0; font-style: normal; }
.vcard .brand.mc i { width: 17px; height: 17px; border-radius: 50%; display: inline-block; }
.vcard .brand.mc i:first-child { background: #eb001b; }
.vcard .brand.mc i:last-child { background: #f79e1b; margin-left: -7px; mix-blend-mode: screen; }
.vcard .state-flag { position: absolute; top: 12px; right: 14px; font-size: 10px; font-weight: 700;
  letter-spacing: 0.08em; text-transform: uppercase; padding: 2px 8px; border-radius: 99px;
  background: rgba(255,255,255,0.16); }
.vcard-meta { padding: 8px 2px 0; }
.vcard-meta .row { display: flex; align-items: center; gap: 6px; margin-top: 6px; flex-wrap: wrap; }

/* ---------- login ---------- */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background:
    radial-gradient(1100px 500px at 12% -10%, color-mix(in srgb, var(--series-1) 13%, transparent), transparent 60%),
    radial-gradient(900px 500px at 105% 110%, color-mix(in srgb, var(--series-2) 10%, transparent), transparent 60%),
    var(--page);
}
.login-card {
  width: min(400px, 100%); background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-2); padding: 30px 30px 24px;
}
.login-card .logo { display: flex; align-items: center; gap: 11px; margin-bottom: 20px; }
.login-card .mark {
  width: 40px; height: 40px; border-radius: 12px; background: var(--text-primary); color: var(--page);
  display: grid; place-items: center; font-weight: 800; font-size: 19px;
}
.login-card h1 { font-size: 19px; font-weight: 750; letter-spacing: -0.01em; }
.login-card .tag { color: var(--text-muted); font-size: 12.5px; }
.login-card form { display: flex; flex-direction: column; gap: 13px; margin-top: 6px; }
.login-card .demo-note { margin-top: 16px; font-size: 12px; color: var(--text-muted); text-align: center; }
