/* ProtoBooks UI */
:root {
  --green: #2ca01c;
  --green-dark: #248a15;
  --navy: #282a2e;
  --navy-2: #33363c;
  --ink: #393a3d;
  --muted: #6b6c72;
  --line: #d4d7dc;
  --line-soft: #e3e5e8;
  --bg: #f4f5f8;
  --card: #ffffff;
  --red: #d52b1e;
  --amber: #b36a00;
  --blue: #0077c5;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(30, 35, 40, .1), 0 1px 2px rgba(30, 35, 40, .06);
  font-size: 15px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
button { font: inherit; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.app { display: flex; min-height: 100vh; }

/* ---- sidebar ---- */
.sidebar {
  width: 232px; flex: 0 0 232px;
  background: var(--navy);
  color: #cfd2d8;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 20px 14px;
  color: #fff; font-weight: 700; font-size: 18px; letter-spacing: .2px;
}
.brand .logo {
  width: 30px; height: 30px; border-radius: 8px;
  background: var(--green);
  display: grid; place-items: center;
  color: #fff; font-size: 16px; font-weight: 800;
}
.company {
  padding: 0 20px 6px;
  font-size: 12.5px; color: #9a9ea8;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.company-tools { padding: 0 20px 12px; border-bottom: 1px solid #3d4047; display: flex; flex-direction: column; gap: 7px; }
.company-tools select {
  width: 100%; font-size: 12.5px; padding: 5px 6px;
  background: var(--navy-2); color: #cfd2d8; border: 1px solid #3d4047; border-radius: 6px;
}
.company-tools .row2 { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; }
.company-tools a { color: #9a9ea8; cursor: pointer; }
.company-tools a:hover { color: #fff; text-decoration: none; }

/* ---- QuickBooks import ---- */
.imp-paste {
  width: 100%; margin-top: 10px; font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 10px; border: 1px solid var(--line); border-radius: 6px;
}
.imp-result { margin-top: 12px; font-size: 13.5px; border-top: 1px solid var(--line-soft); padding-top: 10px; }
.imp-result .pos { color: var(--green-dark); }
.imp-result .err { color: var(--red); margin-top: 6px; }
.imp-result .muted { margin-top: 4px; }

/* ---- auth screens ---- */
.auth-wrap {
  min-height: 100vh; display: grid; place-items: center;
  background: var(--navy); padding: 24px;
}
.auth-card {
  background: var(--card); border-radius: 12px; box-shadow: 0 16px 48px rgba(0,0,0,.35);
  width: 100%; max-width: 420px; padding: 32px;
}
.auth-card .brand { color: var(--ink); padding: 0 0 4px; font-size: 20px; }
.auth-card .sub { color: var(--muted); font-size: 13.5px; margin-bottom: 20px; }
.auth-card .field { margin-bottom: 12px; }
.auth-card .btn-primary { width: 100%; justify-content: center; margin-top: 6px; }
.auth-err { color: var(--red); font-size: 13px; margin: 8px 0 0; min-height: 17px; }
.auth-ok { background: #e4f3e1; color: #19731a; font-size: 13.5px; padding: 9px 12px; border-radius: 6px; margin-bottom: 14px; }
.auth-link { display: block; margin: 10px auto 0; background: none; border: none; color: var(--blue); font-size: 13.5px; cursor: pointer; padding: 4px 8px; }
.auth-link:hover { text-decoration: underline; }
.nav { flex: 1; overflow-y: auto; padding: 10px 0 20px; }
.nav-section { margin-top: 10px; }
.nav-section > .nav-label {
  padding: 8px 20px 4px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: #85888f;
}
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 20px;
  color: #cfd2d8; font-size: 14px;
  border-left: 3px solid transparent;
}
.nav a:hover { background: var(--navy-2); text-decoration: none; color: #fff; }
.nav a.active { background: var(--navy-2); color: #fff; border-left-color: var(--green); }
.nav a .icon { width: 18px; display: flex; align-items: center; justify-content: center; opacity: .9; }
.nav a .icon svg, .btn-icon {
  width: 16px; height: 16px; fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

/* ---- main ---- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--card); border-bottom: 1px solid var(--line-soft);
  padding: 10px 28px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  position: sticky; top: 0; z-index: 20;
}
.topbar .page-crumb { font-size: 13px; color: var(--muted); }
.content { padding: 24px 28px 60px; max-width: 1160px; width: 100%; margin: 0 auto; }

h1.page-title { font-size: 24px; font-weight: 700; margin: 0 0 4px; }
.page-sub { color: var(--muted); font-size: 13.5px; margin-bottom: 20px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---- buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid transparent; border-radius: 6px;
  padding: 8px 16px; font-size: 14px; font-weight: 600;
  cursor: pointer; background: transparent; color: var(--ink);
  transition: background .12s, border-color .12s;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--green-dark); }
.btn-outline { border-color: var(--muted); color: var(--ink); background: var(--card); }
.btn-outline:hover:not(:disabled) { border-color: var(--ink); background: #fafbfc; }
.btn-ghost { color: var(--blue); padding: 8px 10px; }
.btn-ghost:hover { background: #eef6fc; }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: #fdf0ef; }
.btn-sm { padding: 5px 10px; font-size: 13px; }

/* ---- cards / stats ---- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { padding: 16px 18px; }
.stat .label { font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat .hint { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.stat .value.pos { color: var(--green-dark); }
.stat .value.neg { color: var(--red); }
.stat .value.warn { color: var(--amber); }

.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 980px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---- tables ---- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); font-weight: 600;
  padding: 10px 12px; border-bottom: 2px solid var(--line);
  white-space: nowrap;
}
table.data td { padding: 11px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
table.data tr:hover td { background: #f8f9fb; }
table.data tr.clickable { cursor: pointer; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data tr.total td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: none; background: none; }
table.data tr.section td { font-weight: 700; padding-top: 16px; background: none; }
table.data tr.subtotal td { font-weight: 600; border-bottom: 1px solid var(--line); }
.indent-1 { padding-left: 26px !important; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* ---- badges ---- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 20px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge.paid { background: #e4f3e1; color: #19731a; }
.badge.open { background: #e5f1fa; color: #045d8c; }
.badge.partial { background: #fdf3e0; color: #8c5c04; }
.badge.overdue { background: #fbe8e6; color: #ab2015; }
.badge.type { background: #eceef1; color: #55575c; font-weight: 500; }

/* ---- forms ---- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px 16px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea {
  font: inherit; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 6px;
  background: #fff; color: var(--ink); width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid rgba(44, 160, 28, .35); border-color: var(--green);
}
.field.span-2 { grid-column: span 2; }
.field-error { color: var(--red); font-size: 12.5px; }
.field input.invalid { border-color: var(--red); }
.field input.invalid:focus { outline-color: rgba(213, 43, 30, .35); border-color: var(--red); }
.form-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: flex-end; }
.checkbox-line { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.checkbox-line input { width: auto; }

/* line editor (invoice/bill/journal lines) */
table.lines { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 6px; }
table.lines th {
  text-align: left; font-size: 12px; color: var(--muted); font-weight: 600;
  padding: 6px 8px; border-bottom: 1px solid var(--line);
}
table.lines td { padding: 6px 6px; border-bottom: 1px solid var(--line-soft); }
table.lines input, table.lines select {
  font: inherit; padding: 7px 8px; border: 1px solid var(--line); border-radius: 5px; width: 100%;
  background: #fff;
}
table.lines input.num { text-align: right; font-variant-numeric: tabular-nums; }
table.lines .rm { color: var(--red); background: none; border: none; cursor: pointer; font-size: 16px; padding: 4px 8px; }
.totals-box { margin-top: 14px; margin-left: auto; width: 280px; font-size: 14px; }
.totals-box .row { display: flex; justify-content: space-between; padding: 5px 0; }
.totals-box .row.grand { font-weight: 700; font-size: 17px; border-top: 2px solid var(--line); padding-top: 9px; margin-top: 5px; }

/* ---- modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(20, 24, 28, .5);
  display: grid; place-items: center; z-index: 100; padding: 24px;
}
.modal {
  background: #fff; border-radius: 10px; box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
  width: 100%; max-width: 680px; max-height: 90vh; overflow-y: auto;
  padding: 24px;
}
.modal.wide { max-width: 860px; }
.modal h2 { margin: 0 0 16px; font-size: 19px; }

/* ---- toast ---- */
.toast-host { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--navy); color: #fff; padding: 11px 20px;
  border-radius: 8px; box-shadow: var(--shadow); font-size: 14px;
  animation: toast-in .18s ease-out;
}
.toast.error { background: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---- misc ---- */
.filter-bar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.filter-bar .field { min-width: 140px; }
.filter-bar .grow { flex: 1; }
.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.mt { margin-top: 16px; }
.report-head { text-align: center; margin-bottom: 18px; }
.report-head .co { font-size: 13px; color: var(--muted); }
.report-head h2 { margin: 2px 0; font-size: 20px; }
.report-head .range { font-size: 13px; color: var(--muted); }
.chart-bars { display: flex; align-items: flex-end; gap: 14px; height: 180px; padding: 10px 4px 0; }
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 0; }
.chart-col .bars { display: flex; align-items: flex-end; gap: 4px; height: 150px; }
.chart-col .bar { width: 22px; border-radius: 3px 3px 0 0; min-height: 2px; }
.chart-col .bar.income { background: var(--green); }
.chart-col .bar.expense { background: #9aa0a9; }
.chart-col .lbl { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

.detail-list { font-size: 14px; }
.detail-list .row { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line-soft); }
.detail-list .row:last-child { border-bottom: none; }

/* ---- basis chip (what period a number is derived from) ---- */
.basis { font-size: 11.5px; color: var(--muted); background: #eef0f3; border-radius: 10px; padding: 2px 8px; white-space: nowrap; }

/* ---- money bar (A/R health, segments are filters) ---- */
.money-bar { margin-bottom: 16px; }
.money-bar .bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--line-soft); }
.money-bar .seg { cursor: pointer; transition: filter .12s; min-width: 0; }
.money-bar .seg:hover { filter: brightness(.9); }
.money-bar .seg.overdue { background: var(--red); }
.money-bar .seg.current { background: var(--blue); }
.money-bar .seg.paid { background: var(--green); }
.money-bar .caption { display: flex; justify-content: space-between; gap: 12px; font-size: 12.5px; color: var(--muted); margin-top: 6px; flex-wrap: wrap; }
.money-bar .caption b { color: var(--ink); }
.money-bar .cap-link { cursor: pointer; }
.money-bar .cap-link:hover { text-decoration: underline; }

/* ---- aging mini-bar ---- */
.aging-bar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--line-soft); min-width: 90px; }
.aging-bar span { display: block; }
.aging-bar .b-current { background: var(--green); }
.aging-bar .b-d1_30 { background: #e0a10b; }
.aging-bar .b-d31_60 { background: #d97706; }
.aging-bar .b-d61_90 { background: #ea5b0c; }
.aging-bar .b-d90_plus { background: var(--red); }
.aging-legend { display: flex; gap: 10px; font-size: 11.5px; color: var(--muted); margin-top: 6px; flex-wrap: wrap; }

/* ---- tabs ---- */
.tabs { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; margin-bottom: 14px; }
.tabs button { border: none; background: var(--card); padding: 7px 16px; font-size: 13.5px; font-weight: 600; cursor: pointer; color: var(--muted); }
.tabs button + button { border-left: 1px solid var(--line); }
.tabs button.active { background: var(--navy); color: #fff; }

/* ---- collections (grouped A/R) ---- */
tr.coll-expand td { background: #f8f9fb; padding: 0 12px 12px 40px; }
.coll-toggle { cursor: pointer; border: none; background: none; font-size: 13px; color: var(--muted); width: 24px; }

/* ---- posting preview ---- */
.posting-preview { margin-top: 16px; border: 1px dashed var(--line); border-radius: var(--radius); padding: 12px 14px; background: #fafbfd; }
.posting-preview .pp-title { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); font-weight: 600; margin-bottom: 6px; }
.posting-preview table { width: 100%; border-collapse: collapse; font-size: 13px; }
.posting-preview td { padding: 3px 6px; }
.posting-preview td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.posting-preview tr.pp-total td { border-top: 1px solid var(--line); font-weight: 600; }

/* ---- command palette ---- */
.palette-btn { padding: 7px 12px; font-weight: 500; color: var(--muted); }
.palette-btn kbd { font: 11px/1 inherit; background: #eef0f3; border: 1px solid var(--line); border-radius: 4px; padding: 2px 5px; color: var(--muted); }
.modal.palette { max-width: 560px; padding: 0; overflow: hidden; align-self: start; margin-top: 8vh; }
.modal-backdrop.top { align-items: start; display: flex; justify-content: center; }
.palette input.pal-input { width: 100%; border: none; outline: none; font: inherit; font-size: 16px; padding: 16px 18px; border-bottom: 1px solid var(--line-soft); }
.pal-results { max-height: 50vh; overflow-y: auto; padding: 6px; }
.pal-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.pal-item .hint { margin-left: auto; font-size: 12px; color: var(--muted); }
.pal-item.sel, .pal-item:hover { background: #eef6ee; }
.pal-empty { padding: 18px; text-align: center; color: var(--muted); font-size: 13.5px; }

/* ---- scanned documents ---- */
.notice { background: #fdf6e7; border: 1px solid #f0d9a8; border-radius: var(--radius); padding: 12px 14px; margin-bottom: 14px; font-size: 14px; }
.notice.info { background: #eef5fb; border-color: #c8def0; }
.notice ul { margin: 6px 0 0; padding-left: 20px; }
.notice .btn { margin-left: 6px; }
.dropzone { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 36px 20px; border: 2px dashed var(--line); box-shadow: none; cursor: pointer; text-align: center; }
.dropzone:hover, .dropzone.over { border-color: var(--green); background: #f6fbf5; }
.dropzone.busy { opacity: .6; pointer-events: none; }
.dropzone .dz-icon { width: 36px; height: 36px; fill: none; stroke: var(--green); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.dropzone .dz-title { font-weight: 600; font-size: 16px; }
.scan-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 18px; align-items: start; }
.scan-doc { position: sticky; top: 16px; padding: 12px; }
.scan-doc iframe { width: 100%; height: 76vh; border: 1px solid var(--line-soft); border-radius: 6px; }
.scan-doc img { display: block; max-width: 100%; max-height: 76vh; margin: 0 auto; border-radius: 6px; }
.scan-wait { display: flex; gap: 14px; align-items: center; }
.spinner { width: 26px; height: 26px; flex: 0 0 26px; border: 3px solid var(--line-soft); border-top-color: var(--green); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.kind-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 12px; background: var(--card); }
.kind-toggle button { border: none; background: none; padding: 7px 14px; cursor: pointer; color: var(--ink); font-size: 13.5px; }
.kind-toggle button + button { border-left: 1px solid var(--line); }
.kind-toggle button.on { background: var(--green); color: #fff; }
.doc-diff { color: var(--red); }
.vendor-new { margin-top: 4px; color: var(--muted); }
.vendor-new .btn { padding: 2px 6px; }
select.l-acct:invalid { border-color: var(--amber); color: var(--amber); }
@media (max-width: 1200px) {
  .scan-layout { grid-template-columns: 1fr; }
  .scan-doc { position: static; }
  .scan-doc iframe { height: 50vh; }
  .scan-doc img { max-height: 45vh; }
}

@media (max-width: 800px) {
  .sidebar { display: none; }
  .content { padding: 16px; }
  /* One column on phones; a two-column field would push the page wider than the screen. */
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .field.span-2 { grid-column: auto; }
}
