:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #faf9f6;
  --ink: #1b2430;
  --ink-2: #4a5462;
  --muted: #7a828e;
  --line: #e4e1d9;
  --accent: #1f5c4a;
  --accent-ink: #ffffff;
  --accent-soft: #e5efe9;
  --danger: #a33a2c;
  --danger-soft: #f8e7e3;
  --warn-soft: #fbf1dc;
  --warn: #8a5a00;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 24, 30, 0.05), 0 4px 16px rgba(20, 24, 30, 0.04);
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181d; --surface: #1c2128; --surface-2: #20262e; --ink: #e8eaed; --ink-2: #b9c0c8;
    --muted: #8b939d; --line: #2e353e; --accent: #5fb393; --accent-ink: #0f1a15; --accent-soft: #1f3129;
    --danger: #e0806f; --danger-soft: #3a2420; --warn-soft: #3a3020; --warn: #e6b65c;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.01em; }
h1 { font-size: 24px; font-weight: 650; }
h2 { font-size: 18px; font-weight: 650; }
h3 { font-size: 15px; font-weight: 650; }
p { margin: 0; }
small, .muted { color: var(--muted); }
[hidden] { display: none !important; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 550; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.link { background: none; border: 0; color: var(--accent); font: inherit; font-weight: 600; cursor: pointer; padding: 0; }
label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; width: 100%; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.checks { display: grid; gap: 6px; max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.checks label { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); }
.checks input { width: auto; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.stack { display: grid; gap: 16px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 640px) { .grid2 { grid-template-columns: 1fr; } }

.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }
.pill.green { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill.red { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.pill.amber { background: var(--warn-soft); color: var(--warn); border-color: transparent; }

/* ---------- layout ---------- */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 24px; background: var(--topbar-bg, var(--surface)); color: var(--topbar-ink, var(--ink)); border-bottom: 1px solid var(--topbar-line, var(--line)); }
.topbar .muted, .topbar .readonly-badge { color: var(--topbar-muted, var(--muted)); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: inherit; text-decoration: none; }
/* Brand logo (set by brand/<name>/ via BRAND_DIR) replaces the letter mark and company name. */
.brand-logo { display: none; height: 34px; width: auto; }
.brand-label { display: none; font-size: 12px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--topbar-muted, var(--muted));
  padding-left: 12px; border-left: 1px solid var(--topbar-line, var(--line)); }
.branded .brand-logo, .branded .brand-label { display: inline-block; }
.branded .brand .brand-mark, .branded .brand #company { display: none; }
@media (max-width: 640px) {
  .topbar #me, .topbar .brand-label, .topbar #pw, .topbar #email { display: none !important; }
  .brand-logo { height: 28px; }
}
h1, h2, h3, .brand-label { font-family: var(--font-head, var(--font)); }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-size: 14px; font-weight: 800; }
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: calc(100vh - 55px); }
.sidenav { border-right: 1px solid var(--line); padding: 16px 12px; display: flex; flex-direction: column; gap: 2px; }
.sidenav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--ink-2); text-decoration: none; font-weight: 550; }
.sidenav a:hover { background: var(--surface); }
.sidenav a.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.sidenav .sep { margin: 12px 12px 4px; font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.main { padding: 28px 32px 60px; max-width: 1100px; width: 100%; }
.page-head { margin-bottom: 20px; display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.page-head p { color: var(--muted); margin-top: 4px; }
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidenav { flex-direction: row; align-items: center; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px 16px; }
  .sidenav a { white-space: nowrap; flex: none; }
  .sidenav a.active { box-shadow: var(--shadow); }
  .sidenav .sep { display: none; }
  .main { padding: 20px 16px 48px; }
  .topbar { padding: 10px 16px; }
}

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line); }
td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td .actions { display: flex; gap: 4px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- project chooser ---------- */
.project-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.project-tab { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 7px 14px; font: inherit; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.project-tab.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.project-header { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 16px; }
.project-header .meta { color: var(--muted); margin-top: 4px; display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.stats { display: flex; gap: 22px; }
.stat b { display: block; font-size: 20px; }
.stat span { font-size: 12px; color: var(--muted); }

/* ---------- document browser ---------- */
.doc-toolbar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.doc-toolbar input[type=search] { flex: 1; min-width: 200px; }
.doc-toolbar select { width: auto; }
.folder { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.folder-head { width: 100%; display: flex; align-items: center; gap: 10px; padding: 13px 16px; background: none; border: 0; font: inherit; color: var(--ink); cursor: pointer; text-align: left; }
.folder-head:hover { background: var(--surface-2); }
.folder-head .chev { transition: transform 0.15s; color: var(--muted); }
.folder.collapsed .chev { transform: rotate(-90deg); }
.folder.collapsed .files { display: none; }
.folder-head .name { font-weight: 650; flex: 1; }
.files { border-top: 1px solid var(--line); }
.file { display: grid; grid-template-columns: 38px 1fr auto auto auto; gap: 14px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.file:last-child { border-bottom: 0; }
.file:hover { background: var(--surface-2); }
.file .fname { min-width: 0; }
.file .fname button { all: unset; cursor: pointer; font-weight: 550; overflow-wrap: anywhere; }
.file .fname button:hover { color: var(--accent); text-decoration: underline; }
.file .sub { font-size: 12px; color: var(--muted); }
.file .size, .file .date { font-size: 13px; color: var(--muted); white-space: nowrap; }
.empty { padding: 14px 16px; color: var(--muted); font-size: 14px; }
.ficon { width: 38px; height: 44px; border-radius: 6px; display: grid; place-items: end center; padding-bottom: 6px; font-size: 9.5px; font-weight: 800; letter-spacing: 0.03em;
  background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); }
.ficon.pdf { background: #fbe9e6; color: #b23a2a; border-color: #f0cfc8; }
.ficon.doc { background: #e7eefb; color: #2b5cb8; border-color: #cddcf5; }
.ficon.xls { background: #e5f3ea; color: #23784a; border-color: #c8e6d3; }
.ficon.img { background: #f4ecfa; color: #7a43a8; border-color: #e3d3f0; }
@media (prefers-color-scheme: dark) {
  .ficon.pdf { background: #3a2422; border-color: #4d2f2b; color: #f0a092; }
  .ficon.doc { background: #1f2a3d; border-color: #2a3a55; color: #94b5f0; }
  .ficon.xls { background: #1d3226; border-color: #284433; color: #8fd3aa; }
  .ficon.img { background: #2e2338; border-color: #3e2f4b; color: #c9a3ea; }
}
@media (max-width: 640px) {
  .file { grid-template-columns: 34px 1fr auto; }
  .file .size, .file .date { display: none; }
}

/* ---------- upload ---------- */
.dropzone { border: 2px dashed var(--line); border-radius: var(--radius); padding: 34px 20px; text-align: center; background: var(--surface-2); transition: 0.15s; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .big { font-weight: 600; font-size: 16px; margin-bottom: 4px; }
.queue { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.queue li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }
.queue li .n { flex: 1; overflow-wrap: anywhere; }
.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }
.notice { padding: 12px 14px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-size: 14px; }

/* ---------- modal / toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10, 14, 20, 0.55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 12px; width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal .body { padding: 20px; display: grid; gap: 14px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); }
.modal.wide { width: min(1100px, 100%); height: calc(100vh - 32px); display: flex; flex-direction: column; }
.modal.wide .viewer { flex: 1; background: var(--surface-2); display: grid; place-items: center; overflow: auto; }
.modal.wide iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.modal.wide img { max-width: 100%; max-height: 100%; object-fit: contain; }
.toast-host { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 60; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 14px; box-shadow: var(--shadow); }
.toast.error { background: var(--danger); color: #fff; }
.copybox { display: flex; gap: 8px; }
.copybox input { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.drive-id { max-width: 180px; overflow: hidden; text-overflow: ellipsis; font-family: ui-monospace, Consolas, monospace; font-size: 11px; }

/* ---------- auth pages ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: min(400px, 100%); }
.auth-card .brand { margin-bottom: 20px; }
.auth-hero { display: none; }

/* ---------- lender ---------- */
.lender-hero { padding: 28px 0 8px; }
.lender-main { max-width: 1040px; margin: 0 auto; padding: 0 24px 60px; }
@media (max-width: 640px) { .lender-main { padding: 0 16px 48px; } }
.readonly-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }

/* ---------- step-by-step folder browser ---------- */
.field-label { font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.folder-picker { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--surface); }
.fp-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 10px 12px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; min-width: 0; }
.crumb { background: none; border: 0; padding: 2px 4px; border-radius: 4px; font: inherit; font-weight: 600; color: var(--accent); cursor: pointer; overflow-wrap: anywhere; text-align: left; }
.crumb:hover { background: var(--accent-soft); }
.crumb:last-child { color: var(--ink); cursor: default; }
.crumb:last-child:hover { background: none; }
.crumb-sep { color: var(--muted); padding: 0 2px; }
.fp-list { max-height: 440px; overflow-y: auto; }
.fp-row { width: 100%; display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: none; border: 0; border-bottom: 1px solid var(--line); font: inherit; color: var(--ink); cursor: pointer; text-align: left; }
.fp-row:last-child { border-bottom: 0; }
.fp-row:hover { background: var(--surface-2); }
.fp-row .fp-name { flex: 1; overflow-wrap: anywhere; }
.fp-row .fp-chev { color: var(--muted); font-size: 18px; line-height: 1; }
.fp-up { color: var(--ink-2); font-weight: 600; }
.fp-icon { width: 18px; height: 15px; flex: none; color: var(--gold, #c9a85a); }
.fp-empty { padding: 14px; font-size: 14px; }
.fp-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 10px 12px; border-top: 1px solid var(--line); background: var(--surface-2); font-size: 14px; }

/* ---------- Documents: project dropdown + Add folder ---------- */
.doc-controls { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.project-pick { flex: 1; max-width: 460px; }
.project-pick select { font-size: 15px; font-weight: 600; }
.fp-count { font-size: 12px; color: var(--muted); white-space: nowrap; }
.fp-file { display: flex; align-items: center; gap: 10px; padding: 8px 14px; border-bottom: 1px solid var(--line); font-size: 14px; }
.fp-file:last-child { border-bottom: 0; }
.fp-file .ficon { width: 30px; height: 34px; font-size: 8px; padding-bottom: 4px; }
.fp-file .fp-name { flex: 1; overflow-wrap: anywhere; }
@media (max-width: 640px) { .fp-file .fp-count { display: none; } }
@media (max-width: 640px) {
  .readonly-badge #who { display: none; }
  .readonly-badge { white-space: nowrap; }
}


