:root {
  --bg: #f5f6fa; --card: #ffffff; --text: #151a23; --muted: #667085; --line: #e6e8ee; --soft: #f9fafc;
  --accent: #2f5bea; --accent-2: #1d3fb8; --accent-soft: #e7edfd;
  --good: #12805c; --good-soft: #dcf5ea; --bad: #c0362c; --bad-soft: #fde7e4; --warn: #8a5a00; --warn-soft: #fff3d6;
  --radius: 12px; --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --sidebar: 236px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 Inter, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
a { color: var(--accent); }
.center { text-align: center; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 13px; padding: 8px 10px; background: var(--soft); border-radius: 8px; word-break: break-all; }
.grow { flex: 1; }

/* ── Login ── */
#login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-hero { background: linear-gradient(150deg, #1d3fb8 0%, #2f5bea 55%, #0f9b8e 130%); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; }
.login-hero h1 { font-size: 34px; line-height: 1.15; margin: 0 0 14px; max-width: 460px; }
.login-hero p { opacity: .85; max-width: 440px; margin: 0; }
.login-hero ul { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 10px; }
.login-hero li::before { content: "✓"; margin-right: 10px; opacity: .8; }
.login-hero a { color: inherit; }
.sub.light { color: rgba(255,255,255,.7); }
.login-pane { display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 360px; }
.login-card h2 { margin: 0 0 4px; font-size: 22px; }
.login-card .btn.primary { margin-top: 8px; }
@media (max-width: 860px) { #login { grid-template-columns: 1fr; } .login-hero { display: none; } }

/* ── Controls ── */
label.field { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 4px; }
input[type=email], input[type=password], input[type=text], input[type=date], input[type=number], select, textarea {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; min-height: 36px; }
textarea { resize: vertical; }
.w-full { width: 100%; }
input:focus, select:focus, textarea:focus { outline: 3px solid var(--accent-soft); border-color: var(--accent); }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer; white-space: nowrap; min-height: 36px; text-decoration: none; color: inherit; }
.btn:hover { background: #f2f4f8; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 3px 10px; min-height: 28px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 12px; cursor: pointer; min-height: 34px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent-soft); color: var(--accent-2); font-weight: 600; }
.seg button .n { color: var(--muted); font-weight: 400; margin-left: 4px; }
.error { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 10px; }
.status { font-size: 13px; color: var(--muted); }
.status.ok { color: var(--good); } .status.err { color: var(--bad); }
.sub { color: var(--muted); font-size: 12.5px; }
.radio { display: block; margin: 6px 0; cursor: pointer; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ── Shell ── */
#app { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
#app > main, .page > *, .doc-form > * { min-width: 0; }
.mono, .alert, .card p, .cell-sub { overflow-wrap: anywhere; }
.card.flush { overflow-x: auto; }
#loan-table, #l-entries { min-width: 640px; }
#loan-table td, #l-entries td { white-space: nowrap; }
.sidebar { background: #0f1729; color: #c8d0e0; padding: 18px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 6px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; color: #fff; padding: 4px 8px 14px; }
.logo { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(140deg, #2f5bea, #0f9b8e); display: grid; place-items: center; flex: none; font-size: 15px; }
.org-select { background: #1a2338; color: #fff; border-color: #2a3550; margin: 0 4px 10px; }
.nav a { display: flex; align-items: center; justify-content: space-between; padding: 9px 10px; border-radius: 8px; color: inherit; text-decoration: none; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.on { background: rgba(47,91,234,.28); color: #fff; }
.pill { background: var(--accent); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 7px; font-weight: 600; }
.pill:empty { display: none; }
.sidebar .spacer { flex: 1; }
.sidebar .seg { background: transparent; border-color: #2a3550; align-self: flex-start; margin: 0 8px; }
.sidebar .seg button { color: #c8d0e0; } .sidebar .seg button + button { border-left-color: #2a3550; }
.sidebar .seg button.on { background: rgba(47,91,234,.35); color: #fff; }
.side-user { font-size: 12.5px; padding: 10px 8px 0; color: #8d99b3; word-break: break-all; }
.side-user a { color: #aebbe0; }

.topbar { position: sticky; top: 0; z-index: 5; background: rgba(245,246,250,.92); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); }
.topbar-in { padding: 12px 28px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.topbar h1 { font-size: 20px; margin: 0; font-weight: 650; }
.page { padding: 20px 28px 48px; display: grid; gap: 16px; }
.page.narrow { max-width: 820px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.card.flush { padding: 0; overflow: hidden; }
.card h3 { margin: 0 0 8px; font-size: 15px; }
.row2, .row3 { display: grid; gap: 0 12px; grid-template-columns: 1fr 1fr; }
.row3 { grid-template-columns: 1fr 1fr 1fr; }
.add-member { margin: 12px 0 8px; gap: 8px; }

/* ── Documents list ── */
.drop { border: 2px dashed #c9d2e6; border-radius: var(--radius); padding: 18px; text-align: center; color: var(--muted); background: #fbfcff; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-2); }
.filters { justify-self: start; }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 9px 12px; border-bottom: 1px solid var(--line); background: var(--soft); }
table.grid td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grid tr:last-child td { border-bottom: 0; }
#doc-table tbody tr { cursor: pointer; }
#doc-table tbody tr:hover { background: #f7f9ff; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.empty { padding: 28px; text-align: center; color: var(--muted); }
.badge { display: inline-block; font-size: 12px; padding: 1px 9px; border-radius: 10px; background: #eef0f4; color: #475066; white-space: nowrap; }
.badge.processing { background: var(--accent-soft); color: var(--accent-2); }
.badge.review { background: var(--warn-soft); color: var(--warn); }
.badge.approved, .badge.sent { background: #e9e3fb; color: #5b3cc4; }
.badge.posted { background: var(--good-soft); color: var(--good); }
.badge.failed, .badge.rejected { background: var(--bad-soft); color: var(--bad); }
.cell-sub { display: block; font-size: 12px; color: var(--muted); }

/* ── One document ── */
.doc-page { grid-template-columns: minmax(320px, 1fr) minmax(420px, 1.1fr); align-items: start; }
.preview { position: sticky; top: 76px; height: calc(100vh - 100px); background: #e9ecf2; }
.preview iframe, .preview img { width: 100%; height: 100%; border: 0; object-fit: contain; display: block; }
.doc-form { display: grid; gap: 16px; }
.alert { border-radius: 10px; padding: 10px 14px; font-size: 13.5px; }
.alert + .alert { margin-top: 8px; }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.bad { background: var(--bad-soft); color: var(--bad); }
.alert.info { background: var(--accent-soft); color: var(--accent-2); }
.alert ul { margin: 4px 0 0; padding-left: 18px; }
table.lines { table-layout: fixed; }
table.lines td { padding: 3px 4px; border-bottom: 0; }
table.lines tbody.line tr:last-child td { padding-bottom: 10px; border-bottom: 1px solid var(--line); }
table.lines tbody.line tr:first-child td { padding-top: 10px; }
table.lines input, table.lines select { width: 100%; min-height: 32px; padding: 4px 6px; }
table.lines th:nth-child(1) { width: 15%; } table.lines th:nth-child(2), table.lines th:nth-child(5) { width: 18%; }
table.lines th:nth-child(3) { width: 25%; } table.lines th:nth-child(4) { width: 18%; } table.lines th:last-child { width: 36px; }
.totals { display: grid; justify-content: end; gap: 6px; margin-top: 10px; }
.totals div { display: flex; gap: 10px; align-items: center; justify-content: end; }
.totals input { width: 130px; text-align: right; }
.history { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.history li { padding: 4px 0; border-bottom: 1px dashed var(--line); }
.history li:last-child { border: 0; }

.pill.warn { background: var(--bad); }
.tag { display: inline-block; font-size: 11px; padding: 0 7px; border-radius: 8px; background: #eef0f4; color: #475066; white-space: nowrap; vertical-align: 1px; }
.tag.bad { background: var(--bad-soft); color: var(--bad); font-weight: 600; }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.info { background: var(--accent-soft); color: var(--accent-2); }
.alert.info div + div, .alert.bad div + div, .alert.warn div + div { margin-top: 4px; }
.line-note { font-size: 12px; color: var(--muted); padding: 3px 2px 0; }
.usage-bar { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.meter { flex: 1; max-width: 240px; height: 6px; background: #e6e8ee; border-radius: 3px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent); }
.meter i.hot { background: var(--bad); }
.plan-line { margin-bottom: 8px; }
#v-loans .topbar input[type=date] { min-height: 34px; }
#loan-table tbody tr { cursor: pointer; }
#loan-table tbody tr:hover { background: #f7f9ff; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #151a23; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.18); z-index: 50; max-width: 90vw; }
.toast.err { background: var(--bad); }

@media (max-width: 1100px) { .doc-page { grid-template-columns: 1fr; } .preview { position: static; height: 70vh; } }
@media (max-width: 760px) {
  #app { grid-template-columns: minmax(0, 1fr); }
  .org-select { max-width: 100%; }
  .usage-bar { flex-wrap: wrap; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .sidebar .spacer, .side-user { display: none; }
  .page, .topbar-in { padding-left: 16px; padding-right: 16px; }
  .row2, .row3 { grid-template-columns: 1fr; }
  #doc-table th:nth-child(4), #doc-table td:nth-child(4), #doc-table th:nth-child(5), #doc-table td:nth-child(5) { display: none; }
}
.fee-list { columns: 2 260px; margin-top: 8px; }
.fee-list label { display: block; break-inside: avoid; }
.mark-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; position: sticky; top: 64px; z-index: 2; }
