/* Lending tracker. Builds on /style.css (colours, glass, topbar). */
a.brand { color: inherit; text-decoration: none; }
.crumb { color: var(--muted); font-weight: 500; }

.lend { max-width: 980px; margin: 0 auto; padding: 28px 16px 64px; animation: rise 0.5s cubic-bezier(.2,.8,.2,1); }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.head h2 { margin: 0; }
.sub { color: var(--muted); font-size: 14px; margin: 4px 0 0; line-height: 1.5; }
.sub b { color: var(--fg); font-weight: 600; }
.actions, .row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.btn {
  font: inherit; font-size: 14px; font-weight: 600; color: #fff; cursor: pointer;
  border: 0; border-radius: 12px; padding: 10px 16px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 8px 20px -10px var(--accent); transition: filter 0.15s;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.6; cursor: wait; }
.btn.sm { font-size: 13px; padding: 7px 12px; border-radius: 10px; }
.btn.ghost { color: var(--fg); background: var(--card); border: 1px solid var(--border); box-shadow: none; }
.ghost.danger, .link.danger { color: var(--error); }
.link { font: inherit; font-size: 13px; background: none; border: 0; padding: 2px 4px; color: var(--accent); cursor: pointer; }

.panel {
  background: var(--card); border: 1px solid var(--border); border-radius: 20px;
  box-shadow: var(--shadow); padding: 20px;
  backdrop-filter: blur(24px) saturate(1.4); -webkit-backdrop-filter: blur(24px) saturate(1.4);
  margin-bottom: 16px;
}

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.stats .stat { background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 14px 16px;
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px); }
.stat span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.stat b { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.stat.hi b { color: var(--accent); }
.stat.small b { font-size: 14px; font-weight: 500; }

.person-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.person h3 { margin: 0; font-size: 19px; }
.note { margin: 2px 0 0; font-size: 14px; }

.loan { border-top: 1px solid var(--border); padding: 14px 0 4px; }
.loan.closed { opacity: 0.7; }
.loan-title { font-size: 15px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--border); color: var(--muted); }
.chip.on { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.loan-stats { display: flex; flex-wrap: wrap; gap: 8px 24px; margin: 10px 0 12px; }
.loan-stats .stat b { font-size: 16px; }
.loan .error { margin: 0 0 10px; }

.timeline { overflow-x: auto; margin: 12px 0 6px; border: 1px solid var(--border); border-radius: 12px; }
.timeline table { border-collapse: collapse; width: 100%; font-size: 13px; min-width: 760px; }
.timeline th, .timeline td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.timeline th { font-weight: 600; color: var(--muted); font-size: 12px; }
.timeline tr:last-child td { border-bottom: 0; }
.timeline .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.timeline .b { font-weight: 600; }
.timeline td small { display: block; color: var(--muted); }
.timeline tr.today td, .timeline tr.closed td { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.timeline tr.compound td { color: var(--muted); }
.timeline .act { white-space: nowrap; }

.empty-state { text-align: center; }
.empty-state p { color: var(--muted); }

.help summary { cursor: pointer; font-weight: 600; }
.help ul { padding-left: 20px; line-height: 1.6; font-size: 14px; }
.help li { margin: 6px 0; }
.help code { font-size: 13px; background: var(--border); padding: 1px 6px; border-radius: 6px; }

dialog {
  width: min(440px, calc(100vw - 32px)); border: 1px solid var(--border); border-radius: 20px; padding: 24px;
  background: var(--bg); color: var(--fg); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(10, 10, 20, 0.45); backdrop-filter: blur(4px); }
dialog h3 { margin: 0 0 16px; }
.field { display: block; margin-bottom: 12px; font-size: 13px; font-weight: 500; }
.field span { display: block; margin-bottom: 4px; }
.field small { display: block; color: var(--muted); font-weight: 400; margin-top: 4px; }
.field input, .field select, .field textarea {
  width: 100%; font: inherit; font-size: 15px; color: var(--fg); background: var(--card);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 10;
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  max-width: calc(100vw - 32px);
}

@media (max-width: 720px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .crumb { display: none; }
}
@media (max-width: 520px) {
  .panel { padding: 16px; }
  .stat b { font-size: 17px; }
}

/* ---- v2 ---- */
:root { --s1: #2a78d6; --s2: #eb6834; --warn: #b4501b; --grid: rgba(20, 20, 40, 0.08); }
@media (prefers-color-scheme: dark) {
  :root { --s1: #3987e5; --s2: #d95926; --warn: #ff9a5c; --grid: rgba(255, 255, 255, 0.08); }
}
a.btn { display: inline-block; text-decoration: none; }
.center-text { text-align: center; }
.stat.warn b { color: var(--warn); }

.reminders h3 { margin: 0 0 8px; font-size: 15px; }
.reminders ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.reminders li { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.reminders .link { text-align: left; font-size: 14px; color: var(--fg); padding: 0; }
.reminders .link:hover { text-decoration: underline; }
.chip.overdue { background: color-mix(in srgb, var(--error) 15%, transparent); color: var(--error); }
.chip.soon { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.chip.dir.lent { background: color-mix(in srgb, var(--s1) 14%, transparent); color: var(--fg); }
.chip.dir.borrowed { background: color-mix(in srgb, var(--s2) 16%, transparent); color: var(--fg); }

.tabs { display: flex; gap: 4px; margin: 4px 0 14px; border-bottom: 1px solid var(--border); }
.tabs button {
  font: inherit; font-size: 14px; font-weight: 600; color: var(--muted); background: none; border: 0;
  padding: 10px 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tabs button[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); }

.loan.flash { animation: flash 1.6s ease; }
@keyframes flash { 0%, 60% { background: color-mix(in srgb, var(--accent) 12%, transparent); } }

details.more { margin: 4px 0 12px; border: 1px solid var(--border); border-radius: 12px; padding: 8px 12px; }
details.more summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
details.more[open] summary { margin-bottom: 12px; }
dialog { max-height: calc(100vh - 32px); overflow-y: auto; }
#dlg-error.info { color: var(--fg); background: var(--border); padding: 10px 12px; border-radius: 10px; }

.chart-card .chart-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.chart-card h3 { margin: 0; font-size: 16px; }
.chart { width: 100%; height: auto; display: block; margin-top: 10px; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--border); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .mark.s1 { fill: var(--s1); }
.chart .mark.s2 { fill: var(--s2); }
.chart .hit { fill: transparent; }
.chart .hit:hover { fill: var(--grid); }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.key.s1 { background: var(--s1); }
.key.s2 { background: var(--s2); }

.bars { display: grid; gap: 8px; margin-top: 12px; }
.bar-row { display: grid; grid-template-columns: minmax(70px, 160px) 1fr auto; gap: 10px; align-items: center; font-size: 13px; }
.bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 14px; }
.bar { display: block; height: 100%; border-radius: 0 4px 4px 0; }
.bar.s1 { background: var(--s1); }
.bar-val { font-variant-numeric: tabular-nums; font-weight: 600; }

.tip {
  position: fixed; z-index: 20; pointer-events: none; background: var(--bg); color: var(--fg);
  border: 1px solid var(--border); box-shadow: var(--shadow); border-radius: 10px; padding: 8px 10px;
  font-size: 12px; display: grid; gap: 4px; min-width: 140px;
}
.tip div { display: flex; align-items: center; gap: 6px; }
.tip b { margin-left: auto; padding-left: 12px; font-variant-numeric: tabular-nums; }
.tip div:first-child span { font-weight: 600; }

@media (max-width: 520px) {
  .actions { width: 100%; }
  .actions .btn { flex: 1 1 auto; text-align: center; font-size: 13px; padding: 9px 10px; }
}

/* ---- v3: contacts, documents, UPI request ---- */
.contact { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 2px 0 0; font-size: 14px; }
.contact a { color: var(--accent); text-decoration: none; }
a.ghost { display: inline-block; text-decoration: none; }
.files { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; margin: 0 0 10px; font-size: 13px; }
.file { display: inline-flex; align-items: center; gap: 2px; }
.file a { color: var(--accent); text-decoration: none; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timeline small.files { display: flex; margin: 2px 0 0; }
.request { text-align: center; }
.qr-box { display: grid; place-items: center; min-height: 200px; margin: 4px auto 8px; }
.qr { width: 200px; height: 200px; background: #fff; border-radius: 12px; padding: 4px; }
.upi-id { font-weight: 600; color: var(--fg); }
.request .row-actions { justify-content: center; margin-top: 8px; }

/* ---- v4: menu, trust, collateral, history, undo toast ---- */
.menu { position: relative; }
.menu summary { list-style: none; cursor: pointer; }
.menu summary::-webkit-details-marker { display: none; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 5; min-width: 210px; display: grid; padding: 6px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow);
}
.menu-list button, .menu-list a {
  font: inherit; font-size: 14px; text-align: left; color: var(--fg); background: none; border: 0;
  padding: 9px 10px; border-radius: 8px; cursor: pointer; text-decoration: none;
}
.menu-list button:hover, .menu-list a:hover { background: var(--border); }

.person h3 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chip.trust { border: 0; cursor: pointer; font-family: inherit; }
.chip.trust.good { background: color-mix(in srgb, var(--s1) 15%, transparent); color: var(--fg); }
.chip.trust.fair { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.chip.trust.risky { background: color-mix(in srgb, var(--error) 15%, transparent); color: var(--error); }
.chip.todo { background: var(--border); color: var(--fg); }

.collateral { display: grid; gap: 6px; margin: 0 0 12px; font-size: 13px; }
.dues-label { color: var(--muted); font-weight: 600; font-size: 12px; }
.coll-item { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; align-items: flex-start;
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.coll-item small { display: block; color: var(--muted); }
.coll-item.returned { opacity: 0.65; }
.coll-item .row-actions { gap: 2px; }

.history { list-style: none; margin: 0; padding: 0; max-height: 60vh; overflow-y: auto; display: grid; gap: 2px; }
.history li { display: grid; grid-template-columns: 92px 1fr auto; gap: 8px; align-items: baseline; font-size: 13px;
  padding: 7px 4px; border-bottom: 1px solid var(--border); }
.history .when { color: var(--muted); font-size: 12px; }
.history li.undone .what { text-decoration: line-through; color: var(--muted); }

.toast { display: flex; align-items: center; gap: 12px; }
.toast-btn { font: inherit; font-size: 14px; font-weight: 700; color: inherit; background: none; border: 0;
  padding: 0 2px; cursor: pointer; text-decoration: underline; }
