/* ЗААН ГАРЬД — Барьцаат зээлийн бүртгэл · Брэнд системд суурилсан загвар
   Өнгө: Цаас 60% · Заан хар 30% · Гарьд алт 10% (алт зөвхөн онцлолд)
   Фонт: Manrope (гарчиг), Golos Text (их бие), JetBrains Mono (тоо) */
:root {
  --paper: #F6F2E9;
  --card: #FDFBF6;
  --card-tint: #FBF7EE;
  --ink: #191510;
  --ink-soft: #3A342A;
  --ink-2: #544F46;
  --muted: #8C8578;
  --muted-2: #6A655B;
  --line: #E7E0CF;
  --line-soft: #EFE9DC;
  --gold: #C9922E;
  --gold-dark: #A9761E;
  --gold-tint: #F5EBD3;

  --green: #4b7a35; --green-bg: #eaf0df;
  --amber: #A9761E; --amber-bg: #f6ecd4;
  --red: #B23B2E; --red-bg: #f7e3df;
  --gray: #6A655B; --gray-bg: #ece6d8;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(25,21,16,.05), 0 6px 20px rgba(25,21,16,.05);
  --shadow-lg: 0 20px 60px rgba(25,21,16,.22);

  --font: 'Golos Text', -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  --head: 'Manrope', var(--font);
  --mono: 'JetBrains Mono', ui-monospace, "SF Mono", Menlo, monospace;

  --nav-h: 62px; /* mobile bottom nav */
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--paper); color: var(--ink);
  font-family: var(--font); font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--gold-dark); text-decoration: none; }
.hidden { display: none !important; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.right { text-align: right; }
h1, h2, h3, h4 { font-family: var(--head); font-weight: 700; letter-spacing: -.01em; }

/* Гарьд лого */
.wordmark { font-family: var(--head); font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.monogram {
  font-family: var(--head); font-weight: 800; letter-spacing: .02em;
  display: inline-grid; place-items: center; background: var(--gold); color: var(--ink);
  border-radius: 9px;
}

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(120% 120% at 50% 0%, #241d14 0%, #191510 60%); position: relative; overflow: hidden; }
.login-wrap::before { content: ''; position: absolute; inset: 0;
  background-image: repeating-linear-gradient(115deg, transparent 0 22px, rgba(201,146,46,.06) 22px 23px); }
.login-card { position: relative; background: var(--card); border-radius: 22px; padding: 40px 34px; width: 380px; max-width: 100%; box-shadow: var(--shadow-lg); }
.login-card .brandrow { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-card .monogram { width: 46px; height: 46px; font-size: 18px; }
.login-card .wordmark { font-size: 20px; }
.login-card .sub { color: var(--muted); font-size: 13px; margin-top: 1px; letter-spacing: 0; text-transform: none; font-family: var(--font); font-weight: 500; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 244px 1fr; min-height: 100vh; min-height: 100dvh; }
.sidebar { background: var(--ink); color: #b7b0a2; padding: 22px 14px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; height: 100dvh; }
.sidebar .brandrow { display: flex; align-items: center; gap: 11px; padding: 4px 8px 22px; }
.sidebar .monogram { width: 38px; height: 38px; font-size: 15px; }
.sidebar .wordmark { color: var(--paper); font-size: 16px; line-height: 1.05; }
.sidebar .wordmark small { display: block; font-family: var(--font); font-weight: 500; font-size: 10px; letter-spacing: .02em; text-transform: none; color: var(--muted); margin-top: 2px; }
.nav-item { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: var(--radius-sm); cursor: pointer; color: #a49d8e; font-weight: 600; font-size: 14px; margin-bottom: 2px; transition: .14s; }
.nav-item svg { width: 21px; height: 21px; flex: none; }
.nav-item:hover { background: rgba(255,255,255,.05); color: var(--paper); }
.nav-item.active { background: rgba(201,146,46,.14); color: var(--gold); }
.nav-item .badge { margin-left: auto; background: var(--gold); color: var(--ink); border-radius: 20px; padding: 1px 8px; font-size: 11px; font-weight: 800; font-family: var(--mono); }
.sidebar .spacer { flex: 1; }
.sidebar .foot { border-top: 1px solid rgba(255,255,255,.08); padding-top: 14px; font-size: 12px; color: #8a8477; }
.sidebar .foot b { color: #d8d1c1; font-weight: 600; }
.sidebar .logout { display: inline-flex; align-items: center; gap: 7px; color: #8a8477; cursor: pointer; margin-top: 10px; }
.sidebar .logout:hover { color: var(--gold); }

.main { padding: 30px 36px 48px; overflow-y: auto; max-height: 100vh; max-height: 100dvh; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 24px; }
.page-head h1 { font-size: 28px; font-weight: 800; }
.page-head .sub { color: var(--muted); font-size: 14px; margin-top: 4px; }

/* mobile chrome */
.topbar, .bottomnav { display: none; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: var(--ink); color: var(--paper);
  border: none; padding: 12px 18px; border-radius: var(--radius-sm); font-family: var(--head); font-weight: 700; font-size: 14px; cursor: pointer; transition: .14s; min-height: 44px; }
.btn:hover { background: var(--ink-soft); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 18px; height: 18px; }
.btn.gold { background: var(--gold); color: var(--ink); }
.btn.gold:hover { background: var(--gold-dark); color: #fff; }
.btn.ghost { background: var(--card); color: var(--ink); border: 1px solid var(--line); }
.btn.ghost:hover { background: var(--card-tint); border-color: var(--muted); }
.btn.danger { background: var(--red); color: #fff; }
.btn.danger:hover { background: #922f24; }
.btn.sm { padding: 8px 13px; font-size: 13px; min-height: 38px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- Cards ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; border: 1px solid var(--line-soft); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 16px; margin-bottom: 26px; }
.stat { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; border: 1px solid var(--line-soft); }
.stat .label { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.stat .value { font-family: var(--head); font-size: 27px; font-weight: 800; margin-top: 7px; font-variant-numeric: tabular-nums; }
.stat .value.sm { font-size: 21px; }
.stat.accent { background: linear-gradient(150deg, #201a11, var(--ink)); color: var(--paper); border: none; position: relative; overflow: hidden; }
.stat.accent::after { content: ''; position: absolute; inset: 0; background: repeating-linear-gradient(115deg, transparent 0 20px, rgba(201,146,46,.07) 20px 21px); }
.stat.accent .label { color: var(--gold); }
.stat.accent .value { color: var(--paper); font-size: 23px; }
@media (min-width: 761px) { .stat.wide { grid-column: span 2; } }

/* ---------- Data list (хүснэгт → карт) ---------- */
.dlist { background: var(--card); border-radius: var(--radius); border: 1px solid var(--line-soft); box-shadow: var(--shadow); overflow: hidden; }
.drow { display: grid; gap: 14px; align-items: center; padding: 14px 18px; }
.dhead { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; background: var(--card-tint); border-bottom: 1px solid var(--line-soft); }
.ditem { border-top: 1px solid var(--line-soft); cursor: pointer; transition: .1s; }
.ditem:first-child { border-top: none; }
.ditem:hover { background: var(--card-tint); }
.dcell { min-width: 0; }
.dcell.num { text-align: right; }
.dcell .lbl { display: none; }
.dcell b { font-weight: 600; }
.dname { font-weight: 600; }
.dsub { color: var(--muted); font-size: 12px; margin-top: 1px; }

/* ---------- Tags ---------- */
.tag { display: inline-flex; align-items: center; gap: 5px; padding: 4px 11px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.tag::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
.tag.active { background: var(--green-bg); color: var(--green); }
.tag.overdue { background: var(--amber-bg); color: var(--amber); }
.tag.defaulted { background: var(--red-bg); color: var(--red); }
.tag.closed { background: var(--gray-bg); color: var(--gray); }
.tag.seized { background: var(--ink); color: var(--gold); }

/* ---------- Filter tabs ---------- */
.tabs { display: flex; gap: 8px; margin-bottom: 18px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { padding: 8px 15px; border-radius: 20px; background: var(--card); border: 1px solid var(--line); cursor: pointer; font-weight: 600; font-size: 13px; color: var(--muted-2); white-space: nowrap; flex: none; }
.tab.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }

/* ---------- Forms ---------- */
.field { margin-bottom: 15px; }
.field label { display: block; font-size: 12px; font-weight: 700; color: var(--muted-2); margin-bottom: 6px; letter-spacing: .01em; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  background: var(--card); outline: none; min-height: 46px; transition: .14s; font-family: var(--font); }
.field input.mono, .field .mono input { font-family: var(--mono); }
.field input:focus, .field textarea:focus, .field select:focus { border-color: var(--gold); box-shadow: 0 0 0 3.5px var(--gold-tint); background: #fff; }
.field input::placeholder { color: #b6ad9c; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 5px; }
.hint.gold { color: var(--gold-dark); font-weight: 600; }
hr.sep { border: none; border-top: 1px solid var(--line-soft); margin: 20px 0; }

/* ---------- Photos ---------- */
.photo-grid { display: flex; gap: 10px; flex-wrap: wrap; }
.photo-grid img { width: 88px; height: 88px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--line); }
.photo-drop { border: 2px dashed var(--line); border-radius: var(--radius-sm); padding: 22px; text-align: center; color: var(--muted); cursor: pointer; font-weight: 600; transition: .14s; }
.photo-drop:hover { border-color: var(--gold); color: var(--gold-dark); background: var(--gold-tint); }

/* ---------- Detail ---------- */
.detail-grid { display: grid; grid-template-columns: 1fr 340px; gap: 20px; align-items: start; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 9px 14px; }
.kv .k { color: var(--muted); font-size: 13px; }
.kv .v { font-weight: 500; }
.payoff-box { background: linear-gradient(150deg, #201a11, var(--ink)); color: var(--paper); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; position: relative; overflow: hidden; }
.payoff-box::after { content: ''; position: absolute; inset: 0; background: repeating-linear-gradient(115deg, transparent 0 18px, rgba(201,146,46,.08) 18px 19px); pointer-events: none; }
.payoff-box .plabel { color: var(--gold); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }
.payoff-box .total { font-family: var(--head); font-size: 30px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }
.payoff-box .pnote { color: #b7b0a2; font-size: 13px; margin-top: 4px; }
.event { padding: 11px 0; border-bottom: 1px solid var(--line-soft); font-size: 14px; display: flex; gap: 10px; }
.event:last-child { border-bottom: none; }
.event .ic { width: 30px; height: 30px; border-radius: 8px; background: var(--card-tint); display: grid; place-items: center; flex: none; color: var(--gold-dark); }
.event .t { color: var(--muted); font-size: 12px; margin-top: 1px; }

/* ---------- Notifications ---------- */
.notif { display: flex; align-items: center; gap: 13px; padding: 15px 4px; border-bottom: 1px solid var(--line-soft); }
.notif:last-child { border-bottom: none; }
.notif .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.notif .msg { flex: 1; min-width: 0; font-size: 14px; }

/* ---------- Search results ---------- */
.search-result { padding: 13px 15px; border: 1px solid var(--line); border-radius: var(--radius-sm); margin-bottom: 9px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 12px; transition: .12s; }
.search-result:hover { border-color: var(--gold); background: var(--gold-tint); }

/* ---------- Modal / toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(25,21,16,.55); display: grid; place-items: center; z-index: 60; padding: 20px; backdrop-filter: blur(2px); }
.modal { background: var(--card); border-radius: 18px; padding: 26px; width: 440px; max-width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); }
.modal h3 { margin-bottom: 12px; font-size: 19px; }
.modal p { color: var(--muted-2); }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 13px 22px; border-radius: var(--radius-sm); z-index: 100; box-shadow: var(--shadow-lg); font-weight: 600; max-width: 90%; }
.toast.err { background: var(--red); }
.empty { text-align: center; color: var(--muted); padding: 48px 20px; }
.err-msg { color: var(--red); font-size: 13px; margin-top: 10px; font-weight: 600; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 20px; color: var(--muted); font-size: 13px; }

/* ---------- Лимит зурвас ---------- */
.limitbar { display: flex; gap: 10px; margin-bottom: 14px; }
.limitbar > div { flex: 1; background: var(--card-tint); border: 1px solid var(--line-soft); border-radius: 10px; padding: 9px 11px; }
.limitbar span { display: block; color: var(--muted); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.limitbar b { font-family: var(--head); font-size: 15px; }

/* ---------- Мөнгө оруулах блок + дэвсгэрт ---------- */
.moneyblk { background: var(--card-tint); border: 1px solid var(--line-soft); border-radius: 12px; padding: 14px; }
.mquick { display: flex; gap: 8px; margin-bottom: 12px; }
.mrow { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.mrow span { font-size: 13px; font-weight: 600; color: var(--muted-2); }
.mrow input { max-width: 160px; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; text-align: right; }
.mlabel { font-size: 12px; font-weight: 700; color: var(--muted-2); margin-bottom: 8px; }
.denoms { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 10px; }
.denom { display: flex; flex-direction: column; gap: 6px; }
.bnote { height: 38px; border-radius: 7px; background: linear-gradient(135deg, var(--dc), color-mix(in srgb, var(--dc) 72%, #000)); color: #fff;
  display: flex; align-items: center; justify-content: center; gap: 2px; box-shadow: inset 0 0 0 1px rgba(255,255,255,.18), 0 1px 2px rgba(0,0,0,.14); position: relative; overflow: hidden; }
.bnote::after { content: ''; position: absolute; right: -8px; top: -8px; width: 34px; height: 34px; border-radius: 50%; background: rgba(255,255,255,.1); }
.bnote .bval { font-weight: 700; font-size: 15px; letter-spacing: -.02em; }
.bnote .bt { font-size: 12px; opacity: .85; }
.stepper { display: flex; align-items: center; gap: 0; }
.dstep { width: 34px; height: 34px; border: 1.5px solid var(--line); background: #fff; font-size: 18px; font-weight: 700; cursor: pointer; color: var(--ink); display: grid; place-items: center; }
.dstep:first-of-type { border-radius: 9px 0 0 9px; }
.dstep:last-of-type { border-radius: 0 9px 9px 0; }
.dstep:active { background: var(--gold-tint); }
.dcount { width: 100%; min-width: 0; height: 34px; border: 1.5px solid var(--line); border-left: none; border-right: none; text-align: center; background: #fff; padding: 0 2px; }
.msum { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line-soft); font-size: 13px; }
.msum .mrem { margin-left: auto; font-weight: 700; }
.bchip { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 6px; font-family: var(--mono); font-weight: 600; font-size: 12px; color: #fff;
  background: linear-gradient(135deg, var(--dc), color-mix(in srgb, var(--dc) 72%, #000)); }
.pos { color: var(--green); } .neg { color: var(--red); }
.modal .moneyblk { background: var(--card-tint); }

/* ---------- Агуулах чипүүд ---------- */
.chiplist { display: flex; flex-wrap: wrap; gap: 8px; }
.editchip { display: inline-flex; align-items: center; gap: 6px; background: var(--card-tint); border: 1px solid var(--line); border-radius: 20px; padding: 5px 8px 5px 13px; font-size: 13px; font-weight: 600; }
.editchip button { border: none; background: var(--line-soft); color: var(--muted-2); width: 20px; height: 20px; border-radius: 50%; cursor: pointer; font-size: 15px; line-height: 1; display: grid; place-items: center; }
.editchip button:hover { background: var(--red); color: #fff; }

/* ================= RESPONSIVE ================= */
@media (max-width: 900px) {
  .detail-grid { grid-template-columns: 1fr; }
  .detail-grid > div:last-child { order: -1; } /* payoff/үйлдэл дээр */
}

@media (max-width: 760px) {
  body { font-size: 15px; }
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }

  /* Дээд бар */
  .topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px;
    position: sticky; top: 0; z-index: 40; background: var(--ink); color: var(--paper);
    padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); }
  .topbar .brandrow { display: flex; align-items: center; gap: 10px; }
  .topbar .monogram { width: 34px; height: 34px; font-size: 14px; }
  .topbar .wordmark { color: var(--paper); font-size: 15px; }
  .topbar .tbtn { color: var(--paper); background: rgba(255,255,255,.08); border: none; width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; cursor: pointer; position: relative; }
  .topbar .tbtn svg { width: 21px; height: 21px; }
  .topbar .tbtn .badge { position: absolute; top: -4px; right: -4px; background: var(--gold); color: var(--ink); font-family: var(--mono); font-weight: 800; font-size: 10px; border-radius: 20px; padding: 0 5px; }

  .main { padding: 18px 16px calc(var(--nav-h) + 24px); max-height: none; overflow: visible; }
  .page-head { margin-bottom: 18px; }
  .page-head h1 { font-size: 23px; }
  .page-head .headbtn { display: none; } /* доод FAB эсвэл nav ашиглана */

  /* Доод навигаци */
  .bottomnav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 45;
    background: var(--card); border-top: 1px solid var(--line); height: var(--nav-h);
    padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -4px 20px rgba(25,21,16,.06); }
  .bottomnav .nav-item { flex: 1; flex-direction: column; gap: 3px; padding: 8px 2px; border-radius: 0; margin: 0;
    color: var(--muted); font-size: 10.5px; font-weight: 600; justify-content: center; }
  .bottomnav .nav-item svg { width: 23px; height: 23px; }
  .bottomnav .nav-item.active { background: transparent; color: var(--gold-dark); }
  .bottomnav .nav-item .badge { position: absolute; top: 6px; margin-left: 16px; }
  .bottomnav .nav-item.fab { color: var(--ink); }
  .bottomnav .nav-item.fab .fabic { background: var(--gold); color: var(--ink); width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; margin-top: -18px; box-shadow: var(--shadow); }
  .bottomnav .nav-item.fab .fabic svg { width: 24px; height: 24px; }

  /* Хүснэгт → карт */
  .drow { display: block; padding: 14px 16px; }
  .drow.dhead { display: none; }
  .dcell { display: flex; align-items: baseline; gap: 10px; padding: 4px 0; text-align: left; }
  .dcell.num { text-align: left; }
  .dcell .lbl { display: inline-block; color: var(--muted); font-size: 12px; font-weight: 600; min-width: 92px; flex: none; }
  .dcell.dmain { padding-bottom: 8px; margin-bottom: 6px; border-bottom: 1px dashed var(--line-soft); }
  .dcell.dmain b { font-size: 16px; }
  .dcell.dmain .lbl { display: none; }

  .row, .row-3 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 130px 1fr; }
  .modal { border-radius: 18px 18px 0 0; align-self: flex-end; width: 100%; }
  .modal-bg { place-items: end center; padding: 0; }
  .stat-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .stat.wide { grid-column: 1 / -1; }
}
@media (max-width: 330px) {
  .stat-grid { grid-template-columns: 1fr; }
}
