* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", Arial, sans-serif; font-size: 14px;
       color: #26282a; background: #f4f5f8; }
a { color: #0077c5; text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar { display: flex; align-items: center; gap: 12px; background: #282a2e;
          color: #fff; padding: 8px 16px; position: sticky; top: 0; z-index: 10; }
.topbar .brand { font-weight: 600; font-size: 16px; }
.topbar .spacer { flex: 1; }
.topbar select { padding: 5px 8px; border-radius: 4px; border: none; }
.nav-toggle { display: none; background: none; border: none; color: #fff;
  font-size: 21px; line-height: 1; padding: 2px 8px; cursor: pointer; }
.nav-backdrop { display: none; }

.layout { display: flex; min-height: calc(100vh - 44px); }
.sidebar { width: 208px; background: #3d4045; padding: 12px 0 26px; flex-shrink: 0; }
.sidebar a { display: block; color: #e8eaed; padding: 9px 18px; }
.sidebar a:hover { background: #2ca01c; color: #fff; text-decoration: none; }
/* grouped navigation: section titles (larger) + page links (small, indented) */
.sidebar .navsec { padding: 14px 18px 4px; font-size: 13.5px; font-weight: 700;
  color: #fff; letter-spacing: .6px; text-transform: uppercase;
  border-top: 1px solid #4a4d52; margin-top: 8px; }
.sidebar a.navitem { font-size: 12.5px; padding: 6px 18px 6px 30px; opacity: .92; }

/* phones: the fixed 208px sidebar would block most of the page width, so it
   becomes a slide-in drawer behind a hamburger button in the top bar */
@media (max-width: 760px) {
  .nav-toggle { display: block; }
  .layout { display: block; }
  .sidebar { position: fixed; top: 0; bottom: 0; left: 0; z-index: 60;
    width: 232px; max-width: 82vw; overflow-y: auto;
    transform: translateX(-105%); transition: transform .18s ease;
    box-shadow: 2px 0 14px rgba(0, 0, 0, .4); }
  .sidebar.open { transform: translateX(0); }
  .nav-backdrop.show { display: block; position: fixed; inset: 0;
    z-index: 55; background: rgba(0, 0, 0, .45); }
  .content { padding: 14px 12px; max-width: none; }
  .topbar { flex-wrap: wrap; gap: 8px; padding: 8px 10px; }
  .topbar .brand { font-size: 14px; }
  .topbar select { max-width: 46vw; }
}
/* unread developer-reply counter on the Feedback nav item */
.navbadge { display: inline-block; background: #2ca01c; color: #fff;
  border-radius: 9px; padding: 0 7px; font-size: 11px; font-weight: 700;
  margin-left: 6px; line-height: 16px; vertical-align: 1px; }
.sidebar a:hover .navbadge { background: #fff; color: #2ca01c; }

/* tabbed sections (developer backend) */
.tabbar { display: flex; gap: 2px; border-bottom: 2px solid #dfe3e8;
  margin: 14px 0 18px; flex-wrap: wrap; }
.tabbtn { border: none; background: none; padding: 9px 16px;
  font-size: 13.5px; cursor: pointer; color: #5f6368; font-weight: 600;
  border-bottom: 3px solid transparent; margin-bottom: -2px;
  font-family: inherit; }
.tabbtn:hover { color: #2ca01c; }
.tabbtn.active { color: #2ca01c; border-bottom-color: #2ca01c; }

/* Import-from-Excel sections — deliberately a different colour (blue vs the
   app's green) so every "upload a listing + download its template" zone
   stands out on the page */
form.filters.import-zone, .card.import-zone, .import-zone {
  background: #eef5fd;
  border: 1px solid #b9d3ef;
  border-left: 5px solid #1e6bb8;
  border-radius: 8px;
}
.import-zone > label, .import-zone > div > b, .import-zone h2 {
  color: #17497f;
}
/* (import-zone button colours live below the .btn definitions so they win
   the cascade for every button variant used inside a zone) */

/* KPI cards (subscriptions money view) */
.kpis { display: flex; gap: 12px; flex-wrap: wrap; margin: 0 0 16px; }
.kpi { background: #fff; border: 1px solid #dfe3e8; border-radius: 8px;
  padding: 12px 18px; min-width: 140px; flex: 0 1 auto; }
.kpi .v { font-size: 20px; font-weight: 700; }
.kpi.green .v { color: #2ca01c; }
.kpi .l { font-size: 11.5px; color: #6b7075; margin-top: 2px;
  max-width: 190px; }
.content { flex: 1; padding: 20px 26px; max-width: 1300px; }

h1 { font-size: 21px; margin: 0 0 14px; font-weight: 600; }
h2 { font-size: 16px; margin: 18px 0 8px; }

.flash { padding: 9px 14px; border-radius: 4px; margin-bottom: 12px; }
.flash.ok { background: #e4f3e1; border: 1px solid #2ca01c; }
.flash.error { background: #fdeaea; border: 1px solid #d52b1e; }

.btn { display: inline-block; background: #2ca01c; color: #fff; border: none;
       padding: 7px 14px; border-radius: 4px; cursor: pointer; font-size: 14px; }
.btn:hover { background: #248a16; color: #fff; text-decoration: none; }
.btn.ghost { background: transparent; border: 1px solid #9aa0a6; color: #e8eaed; }
.btn.secondary { background: #fff; border: 1px solid #babec5; color: #26282a; }
.btn.secondary:hover { background: #eef0f3; }
.btn.danger { background: #d52b1e; }
.btn.small { padding: 3px 9px; font-size: 12.5px; }
/* coloured action pills */
.btn.edit { background: #e8f0fe; border: 1px solid #a7c3f4; color: #185abc; }
.btn.edit:hover { background: #d2e3fc; color: #174ea6; }
.btn.warn { background: #fef3e0; border: 1px solid #f2c37d; color: #9a5b00; }
.btn.warn:hover { background: #fce8c8; color: #7a4900; }
.btn.ok { background: #e6f4ea; border: 1px solid #9fd3ac; color: #1e7e34; }
.btn.ok:hover { background: #d4ecdb; color: #176127; }
.btn.template { background: #f3e8fd; border: 1px solid #cfa8f0; color: #6a1b9a; }
.btn.template:hover { background: #ead6fb; color: #571580; }

/* inside an import zone every button is the same size and the same blue
   family — the action (upload/import) darkest, template downloads and
   sidekick actions one step lighter */
.import-zone .btn {
  background: #1e6bb8; border: 1px solid #1e6bb8; color: #fff;
  padding: 7px 14px; font-size: 13.5px;
}
.import-zone .btn:hover {
  background: #17497f; border-color: #17497f; color: #fff;
}
.import-zone .btn.template, .import-zone .btn.secondary {
  background: #5b9bd5; border-color: #5b9bd5; color: #fff;
}
.import-zone .btn.template:hover, .import-zone .btn.secondary:hover {
  background: #4285c4; border-color: #4285c4; color: #fff;
}
/* dropdowns in import zones (e.g. the bank-account picker on Bank
   matching) size to their shortest option and end up too narrow */
.import-zone select { min-width: 240px; max-width: 100%; padding: 6px 8px; }
/* numbered sequence inside import zones: ① choose the file ② import
   (Bank matching: ① bank account ② statement CSV ③ import) */
.step-no { display: inline-flex; align-items: center;
  justify-content: center; width: 24px; height: 24px; border-radius: 50%;
  background: #17497f; color: #fff; font-size: 15px; font-weight: 700;
  line-height: 1; margin-right: 6px; flex-shrink: 0;
  vertical-align: middle; }
.btn .btn-step { font-size: 17px; font-weight: 800; margin-right: 7px;
  vertical-align: -1px; }
/* sidebar sub-items (Invoices / POs / DOs / Receipts under Sales & purchases) */
.sidebar a.subnav { font-size: 12px; padding-left: 30px; opacity: .85; }
.sidebar a.subnav::before { content: "› "; opacity: .6; }
/* template download table */
.tpl-table td { vertical-align: middle; }
.tpl-table tr:nth-child(even) td { background: #faf7fd; }
a.tpl-file { color: #6a1b9a; font-weight: 600; text-decoration: none;
             white-space: nowrap; }
a.tpl-file:hover { text-decoration: underline; color: #571580; }
/* selected-AI-model badge */
.model-badge { display: inline-block; padding: 3px 12px; border-radius: 14px;
               font-weight: 700; font-size: 12.5px; }
.model-badge.opus { background: #f3e8fd; border: 1.5px solid #cfa8f0; color: #6a1b9a; }
.model-badge.sonnet { background: #e8f0fe; border: 1.5px solid #a7c3f4; color: #185abc; }
.model-badge.haiku { background: #e6f4ea; border: 1.5px solid #9fd3ac; color: #1e7e34; }
.model-badge.other { background: #eef0f3; border: 1.5px solid #babec5; color: #26282a; }
/* pretty file inputs: the browser's "Choose file" button becomes a teal pill */
input[type="file"]::file-selector-button {
  background: #e0f2f1; border: 1px solid #7fcbc4; color: #00695c;
  padding: 5px 12px; border-radius: 4px; cursor: pointer; font-size: 13px;
  margin-right: 10px;
}
input[type="file"]::file-selector-button:hover { background: #c8e8e5; }
/* printable trade documents */
@media print {
  .topbar, .sidebar, .no-print, .flash { display: none !important; }
  .layout { display: block; }
  .content { padding: 0; }
  .docsheet { border: none; box-shadow: none; }
  /* batch print: one document per page */
  .batch-doc { page-break-after: always; break-after: page; }
  .batch-doc:last-child { page-break-after: auto; break-after: auto; }
}

/* list pagination bar */
.pager { display: flex; align-items: center; gap: 8px; margin: 12px 0 4px;
         flex-wrap: wrap; font-size: 13px; }
.pager .perpage { display: inline-block; padding: 2px 8px; border-radius: 10px;
                  border: 1px solid #d5d8dd; color: #2d6a64; text-decoration: none; }
.pager .perpage.active { background: #d9efec;
                         border-color: #7fcbc4; color: #00695c; font-weight: 700; }
.btn.small.disabled { opacity: .4; pointer-events: none; }

table.grid { border-collapse: collapse; width: 100%; background: #fff;
             border: 1px solid #dfe1e5; }
table.grid th { text-align: left; background: #f0f1f4; border-bottom: 2px solid #d5d8dd;
                padding: 7px 10px; font-weight: 600; white-space: nowrap; }
table.grid td { padding: 6px 10px; border-bottom: 1px solid #eceef1; }
table.grid tr:hover td { background: #f7f9fb; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums;
                 white-space: nowrap; }
.muted { color: #6b7075; }
.tag { display: inline-block; background: #eef0f3; border-radius: 10px;
       padding: 1px 9px; font-size: 12px; }

/* Scrollable list of tickboxes — the replacement for a <select multiple> when
   the user must SEE which options are on. A multi-select shows the chosen rows
   as highlights only, hides most of them behind a tiny viewport, and wipes the
   whole selection on one stray click. Used for company access on /dev. */
.tickbox-list { max-height: 122px; overflow-y: auto; background: #fff;
                border: 1px solid #dfe1e5; border-radius: 6px;
                padding: 4px 6px; }
.tickbox-list label { display: flex; align-items: center; gap: 6px;
                      font-size: 11.5px; color: #202124; line-height: 1.7;
                      white-space: nowrap; cursor: pointer; }
.tickbox-list label:hover { background: #f2f6fc; }
/* The box lives inside form.filters, whose `label` rule would otherwise stack
   these vertically and grey them out. It is also kept shorter there: that row
   is `align-items:end`, so a tall box bottom-aligns the one-line inputs beside
   it and opens a band of dead space above them. */
form.filters .tickbox-list label { flex-direction: row; color: #202124; }
form.filters .tickbox-list { max-height: 88px; }
.tickbox-list input { margin: 0; flex: none; }

form.filters { display: flex; gap: 10px; align-items: end; flex-wrap: wrap;
               margin-bottom: 14px; background: #fff; padding: 12px 14px;
               border: 1px solid #dfe1e5; border-radius: 6px; }
form.filters label { display: flex; flex-direction: column; gap: 3px;
                     font-size: 12.5px; color: #5f6368; }
input[type=text], input[type=date], input[type=number], input[type=email],
select, textarea {
  padding: 6px 8px; border: 1px solid #babec5; border-radius: 4px;
  font-size: 14px; font-family: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid #2ca01c33;
  border-color: #2ca01c; }

/* A wide table scrolls inside its own container instead of the page
   (used on the Rules pages; harmless anywhere). */
.tablewrap { overflow-x: auto; }

/* Rules pages: roomier inputs (add `rules-wide` to a form.filters). A .grow
   label stretches its input to fill the remaining row width. */
form.filters.rules-wide { gap: 12px; }
form.filters.rules-wide input[type=text] { min-width: 300px; }
form.filters.rules-wide input[type=number] { min-width: 140px; }
form.filters.rules-wide label.grow { flex: 1 1 340px; }
form.filters.rules-wide label.grow input { width: 100%; box-sizing: border-box;
  min-width: 0; }
@media (max-width: 760px) {
  form.filters.rules-wide label, form.filters.rules-wide label.grow {
    flex: 1 1 100%; }
  form.filters.rules-wide input[type=text],
  form.filters.rules-wide input[type=number], form.filters.rules-wide select {
    width: 100%; box-sizing: border-box; min-width: 0; }
}

.card { background: #fff; border: 1px solid #dfe1e5; border-radius: 6px;
        padding: 16px 18px; margin-bottom: 16px; }
.cards { display: flex; gap: 14px; flex-wrap: wrap; }
.cards .stat { flex: 1; min-width: 160px; text-align: center; }
.cards .stat .n { font-size: 26px; font-weight: 700; color: #2ca01c; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
             gap: 12px; max-width: 900px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px;
                   font-size: 12.5px; color: #5f6368; }
.actions { margin-top: 16px; display: flex; gap: 10px; }

/* report styles */
.report { background: #fff; border: 1px solid #dfe1e5; padding: 24px 30px; }
.report .rhead { text-align: center; margin-bottom: 14px; }
.report .rhead .co { font-weight: 700; }
.report .rhead .title { font-size: 19px; font-weight: 700; }
.report table { border-collapse: collapse; width: 100%; }
.report th { border-bottom: 2px solid #26282a; padding: 4px 8px; }
.report td { padding: 3px 8px; }
.report tr.header td { font-weight: 700; padding-top: 8px; }
.report tr.total td { font-weight: 700; border-top: 1px solid #26282a; }
.report tr.grand td { font-weight: 700; border-top: 3px double #26282a; }
.report tr.alert td { color: #b3261e; font-weight: 700; background: #fdeaea; }
.report .ind1 { padding-left: 24px; } .report .ind2 { padding-left: 44px; }
.report .ind3 { padding-left: 64px; } .report .ind4 { padding-left: 84px; }
.report td.num { font-variant-numeric: tabular-nums; }
.neg { color: #c62828; }

/* journal entry form */
table.je td { padding: 3px 4px; }
table.je input, table.je select { width: 100%; }
table.je .amt { width: 110px; }
tfoot td { font-weight: 700; }
.imbalance { color: #c62828; font-weight: 700; }
.balanced { color: #2ca01c; font-weight: 700; }

/* indeterminate "working" bar (AI agents, while the model reads a document) */
.proc { margin-top: 12px; }
.proc-bar { height: 8px; background: #e6f0ff; border-radius: 6px; overflow: hidden; }
.proc-bar > span { display: block; height: 100%; width: 40%; border-radius: 6px;
  background: #2ca01c; animation: proc 1.1s ease-in-out infinite; }
@keyframes proc { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }

/* ---------------------------------------------------------------------------
   Global "the system is working" affordance. Two parts, both driven by
   window.Progress (base.html): a page-top bar for the whole request, and a
   spinner on the control that started it.

   The bar sits above the mobile sidebar (z-index 60) and its backdrop (55),
   so it stays visible with the drawer open. --------------------------------- */
#gp-bar {
  position: fixed; top: 0; left: 0; right: 0; height: 3px;
  background: rgba(44, 160, 28, .18); z-index: 200; overflow: hidden;
  display: none;
}
#gp-bar.on { display: block; }
#gp-bar > span {
  display: block; height: 100%; width: 35%; background: #2ca01c;
  animation: gp-slide 1.1s ease-in-out infinite;
}
@keyframes gp-slide { 0% { margin-left: -35%; } 100% { margin-left: 100%; } }

/* Busy control. Deliberately NOT `disabled`: 13 buttons in this app carry a
   name/value that the server reads (report `format=xlsx`, the `toggle=1`
   rows, trade `status=paid`), and a disabled button is omitted from the
   submission entirely. pointer-events blocks the double-click without
   touching what gets posted. */
.is-busy {
  position: relative; pointer-events: none; opacity: .85;
  padding-left: 30px !important;
}
.is-busy::before {
  content: ''; position: absolute; left: 10px; top: 50%;
  width: 12px; height: 12px; margin-top: -7px; box-sizing: border-box;
  border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; animation: gp-spin .7s linear infinite;
}
.btn.small.is-busy { padding-left: 24px !important; }
.btn.small.is-busy::before { left: 7px; width: 10px; height: 10px; margin-top: -6px; }
@keyframes gp-spin { to { transform: rotate(360deg); } }

/* Respect the OS "reduce motion" setting — keep the state visible, drop the
   spin. The bar becomes a static filled strip rather than nothing, so the
   signal survives. */
@media (prefers-reduced-motion: reduce) {
  #gp-bar > span { animation: none; width: 100%; }
  .is-busy::before { animation: none; border-right-color: currentColor; opacity: .5; }
  .proc-bar > span { animation: none; width: 100%; }
}
/* review layout: original document beside the extracted fields */
.doc-review { display: flex; flex-wrap: wrap; gap: 18px; align-items: flex-start; }
.doc-pane { flex: 1 1 320px; min-width: 280px; position: sticky; top: 12px; }
.doc-pane iframe, .doc-pane img { width: 100%; border: 1px solid #dfe1e5;
  border-radius: 6px; background: #fff; }
.doc-pane iframe { height: calc(100vh - 240px); min-height: 420px; }
.doc-fields { flex: 2 1 380px; min-width: 300px; }

/* Flash messages are dismissible, and the Progress layer clears them when a
   new action starts (base.html) — a slow POST leaves the old page up for its
   whole duration, so the previous result must not linger as if it were the
   answer to the click that just happened. */
.flash { position: relative; padding-right: 34px; }
.flash-x {
  position: absolute; top: 4px; right: 8px; border: none; background: none;
  color: inherit; opacity: .5; cursor: pointer; font-size: 19px; line-height: 1;
  padding: 0 4px;
}
.flash-x:hover { opacity: 1; }
/* per-branch run progress (Expense auto-processing) */
.run-out { margin-left: 6px; }
.run-out.ok { color: #1e7e34; font-weight: 600; }
.run-out.err { color: #a01109; font-weight: 600; }
