/* Lending Manager — clean, professional, mobile-first UI */
:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e3e8f0;
  --text: #1f2733;
  --muted: #6b7688;
  --primary: #2b4eff;
  --primary-dark: #1f3bd1;
  --primary-soft: #e9edff;
  --green: #15803d;
  --green-soft: #dcfce7;
  --red: #be123c;
  --red-soft: #ffe4e6;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }

/* ---------- App shell ---------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: .65rem 1rem;
  display: flex; align-items: center; gap: .75rem;
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; color: var(--text); font-size: 1.05rem; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), #6d8bff);
  color: #fff; display: grid; place-items: center; font-weight: 800; font-size: .95rem;
}
.brand:hover { text-decoration: none; }
.topbar .spacer { flex: 1; }
.user-chip { color: var(--muted); font-size: .85rem; display: flex; align-items: center; gap: .5rem; }

.layout { flex: 1; display: flex; }
.sidebar {
  width: 230px; background: var(--surface); border-right: 1px solid var(--border);
  padding: 1rem .6rem; flex-shrink: 0;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: .6rem;
  padding: .6rem .7rem; border-radius: var(--radius-sm);
  color: var(--text); font-weight: 500; font-size: .92rem;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.nav a .ic { width: 18px; text-align: center; opacity: .85; }

.content { flex: 1; padding: 1.25rem; min-width: 0; }
.content-head { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.content-head .spacer { flex: 1; }
.breadcrumb { color: var(--muted); font-size: .85rem; margin-bottom: .15rem; }
.breadcrumb a { color: var(--muted); }

/* ---------- Cards / grid ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .9rem; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem 1.1rem; box-shadow: var(--shadow-sm);
}
.stat .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.stat .value { font-size: 1.5rem; font-weight: 700; margin-top: .25rem; }
.stat .value.money { font-variant-numeric: tabular-nums; }
.stat.accent { background: linear-gradient(135deg, var(--primary), #4d6bff); color: #fff; border: none; }
.stat.accent .label { color: rgba(255,255,255,.85); }
.stat.green .value { color: var(--green); }
.stat.red .value { color: var(--red); }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); margin-bottom: 1.1rem; overflow: hidden;
}
.panel > .panel-head {
  padding: .85rem 1.1rem; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: .6rem; background: var(--surface);
}
.panel > .panel-head h2 { margin: 0; font-size: 1rem; }
.panel > .panel-head .spacer { flex: 1; }
.panel .panel-body { padding: 1.1rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.1rem; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .45rem; justify-content: center;
  padding: .55rem .95rem; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-weight: 600; font-size: .9rem;
  cursor: pointer; transition: background .12s, border-color .12s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; }
.btn.sm { padding: .4rem .65rem; font-size: .82rem; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { padding: .65rem .8rem; text-align: left; border-bottom: 1px solid var(--border); }
table.data th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data .muted { color: var(--muted); }
.row-link { cursor: pointer; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; padding: .2rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge.active { background: var(--green-soft); color: var(--green); }
.badge.closed { background: var(--surface-2); color: var(--muted); }
.badge.due { background: var(--red-soft); color: var(--red); }
.badge.gold { background: #fff7e0; color: #92660b; }
.badge.silver { background: #eef1f6; color: #5b6573; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem 1.1rem; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: .82rem; font-weight: 600; color: var(--muted); }
.input, input[type=text], input[type=number], input[type=date], input[type=password],
input[type=email], select, textarea {
  width: 100%; padding: .55rem .65rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: .92rem; font-family: inherit; background: var(--surface); color: var(--text);
}
.input:focus, input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
.help { font-size: .78rem; color: var(--muted); }
.errorlist { list-style: none; padding: 0; margin: .2rem 0 0; color: var(--red); font-size: .8rem; }
.fieldset-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; margin: .4rem 0; grid-column: 1 / -1; border-bottom: 1px solid var(--border); padding-bottom: .35rem; }

.searchbar { display: flex; gap: .5rem; align-items: center; }
.searchbar input { max-width: 360px; }

/* ---------- Messages ---------- */
.messages { list-style: none; padding: 0; margin: 0 0 1rem; display: flex; flex-direction: column; gap: .5rem; }
.messages li { padding: .65rem .9rem; border-radius: var(--radius-sm); font-size: .9rem; border: 1px solid; }
.messages li.success { background: var(--green-soft); border-color: #bbf7d0; color: var(--green); }
.messages li.error { background: var(--red-soft); border-color: #fecdd3; color: var(--red); }
.messages li.info { background: var(--primary-soft); border-color: #c7d2fe; color: var(--primary-dark); }
.messages li.warning { background: var(--amber-soft); border-color: #fde68a; color: var(--amber); }

/* ---------- Misc ---------- */
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1rem; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }
.avatar { width: 56px; height: 56px; border-radius: 12px; object-fit: cover; background: var(--surface-2); border: 1px solid var(--border); display: grid; place-items: center; color: var(--muted); font-weight: 700; }
.tag-due { color: var(--red); font-weight: 700; }
.tag-ok { color: var(--green); font-weight: 700; }
.note { background: var(--amber-soft); border: 1px solid #fde68a; color: var(--amber); padding: .6rem .8rem; border-radius: var(--radius-sm); font-size: .85rem; }

/* mobile bottom nav (hidden on desktop) */
.bottom-nav { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .sidebar { display: none; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .content { padding: 1rem .85rem 5rem; }
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: .35rem .25rem; justify-content: space-around;
    padding-bottom: calc(.35rem + env(safe-area-inset-bottom));
  }
  .bottom-nav a { flex: 1; text-align: center; color: var(--muted); font-size: .68rem; padding: .35rem 0; display: flex; flex-direction: column; gap: 2px; }
  .bottom-nav a.active { color: var(--primary); }
  .bottom-nav a .ic { font-size: 1.15rem; }
}

/* ---------- Print (receipts, ledger, statement) ---------- */
@media print {
  .topbar, .sidebar, .bottom-nav, .btn-row, .no-print { display: none !important; }
  body { background: #fff; }
  .content { padding: 0; }
  .panel { box-shadow: none; border: 1px solid #ccc; }
  .print-sheet { max-width: 720px; margin: 0 auto; }
}
.receipt {
  max-width: 480px; margin: 0 auto; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow-sm);
}
.receipt h2 { text-align: center; }
.receipt .rcpt-head { text-align: center; border-bottom: 1px dashed var(--border); padding-bottom: .8rem; margin-bottom: .8rem; }
.receipt .total-row { border-top: 1px solid var(--border); margin-top: .5rem; padding-top: .5rem; font-weight: 700; }
