/* GTech Business Manager — the one stylesheet for the whole app.
 *
 * The palette and the type are the desktop app's design tokens
 * (app/ui/theme.py), carried across so the two products look like one:
 * electric blue and teal on a light canvas, navy sidebar, IBM Plex throughout
 * — Sans for the UI, Mono for every figure so amounts align in a column.
 *
 * Reuse these classes; do not hand-roll one-off colours or card markup.
 *
 * **Phone first.** The base rules below assume a narrow screen and a thumb;
 * the desktop rail, the wider padding and the multi-column tables are added at
 * the breakpoints at the bottom. Any control a user taps is at least 40px
 * high, and every input is 16px so iOS does not zoom the page when it focuses
 * one — a zoom the user then has to pinch back out of on every single field.
 *
 * **One verb, one control.** Editing is a pencil and removing is a bin
 * wherever they appear; the page's own actions sit at the top right on every
 * screen; the primary button is the rightmost one in any row of buttons. A
 * user who has learned one screen has learned all of them.
 */

/* ---- bundled type ------------------------------------------------------ */
/* A font must be bundled before it may be named: naming a family the machine
 * does not have makes the browser fall back silently, so the product stops
 * looking like itself with nothing to say so. Every face below ships in
 * static/fonts/. */
@font-face { font-family: 'IBM Plex Sans'; src: url('../fonts/IBMPlexSans-Regular.ttf') format('truetype'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'IBM Plex Sans'; src: url('../fonts/IBMPlexSans-Medium.ttf') format('truetype'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'IBM Plex Sans'; src: url('../fonts/IBMPlexSans-SemiBold.ttf') format('truetype'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'IBM Plex Sans'; src: url('../fonts/IBMPlexSans-Bold.ttf') format('truetype'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'IBM Plex Sans'; src: url('../fonts/IBMPlexSans-Italic.ttf') format('truetype'); font-style: italic; font-display: swap; }
@font-face { font-family: 'IBM Plex Mono'; src: url('../fonts/IBMPlexMono-Regular.ttf') format('truetype'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'IBM Plex Mono'; src: url('../fonts/IBMPlexMono-Medium.ttf') format('truetype'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'IBM Plex Mono'; src: url('../fonts/IBMPlexMono-Bold.ttf') format('truetype'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'IBM Plex Serif'; src: url('../fonts/IBMPlexSerif-SemiBold.ttf') format('truetype'); font-weight: 600; font-display: swap; }
@font-face { font-family: 'IBM Plex Serif'; src: url('../fonts/IBMPlexSerif-Bold.ttf') format('truetype'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Carlito'; src: url('../fonts/Carlito-Regular.ttf') format('truetype'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Carlito'; src: url('../fonts/Carlito-Bold.ttf') format('truetype'); font-weight: 700; font-display: swap; }

:root {
  --navy: #0D1B2E;
  --blue: #1E6BFF;
  --blue-dk: #1552CC;
  --blue-bg: #E9F0FF;
  --blue-border: #D3E1FF;
  --teal: #0FB5A6;
  --teal-dk: #0F766E;
  --teal-bg: #E5F6F4;
  --bg: #F3F6FB;
  --card: #FFFFFF;
  --border: #E4E9F2;
  --line: #EEF2F8;
  --rule: #B9C6D9;
  --total-bg: #EEF3FA;
  --text: #0D1B2E;
  --muted: #55657C;
  --disabled: #93A1B5;
  --green: #12A150; --green-bg: #E7F6EE;
  --orange: #E8973A; --orange-bg: #FFF1E6;
  --red: #E5484D; --red-bg: #FDECEC; --red-border: #F4C7C8;
  /* The mark's own two colours — sampled from the logo artwork, so the brand
   * bar and the mark beside it cannot drift apart. */
  --brand: #2E309B;
  --accent: #7923FF;
  --sidebar-w: 232px;
  --topbar-h: 58px;
  /* One radius scale and one shadow scale. A card, a button and a field that
   * each round by a different amount is the commonest way a screen stops
   * looking designed. */
  --r-sm: 8px;
  --r-md: 10px;
  --r-lg: 13px;
  --shadow-sm: 0 1px 2px rgba(13,27,46,.05);
  --shadow-md: 0 4px 16px rgba(13,27,46,.08);
  --shadow-pop: 0 10px 30px rgba(13,27,46,.14);
  /* Kept clear of a phone's rounded corners and home indicator. */
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { -webkit-font-smoothing: antialiased; }

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'IBM Plex Sans', -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  overflow-x: hidden;
}
/* While the navigation panel is open the page behind it must not scroll. */
body.nav-open { overflow: hidden; }

/* Every figure is mono, so columns of money align down the page. */
.num, .table td.num, .table th.num, .kpi-value, .money {
  font-family: 'IBM Plex Mono', Consolas, Menlo, monospace;
  font-variant-numeric: tabular-nums;
}
.num { text-align: right; white-space: nowrap; }

a { color: var(--blue-dk); text-decoration: none; }
a:hover { color: var(--blue); text-decoration: underline; }

/* One focus ring, on everything. A desk in this office is worked from a
 * keyboard as much as a mouse, and a control that takes focus invisibly is a
 * control nobody can find. */
a:focus-visible, button:focus-visible, .btn:focus-visible,
.act:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
  box-shadow: none;
}

/* The first thing a keyboard lands on, invisible until it is. */
.skip-link {
  position: absolute; left: -9999px; top: 8px; z-index: 2000;
  background: var(--navy); color: #fff; padding: 10px 16px; border-radius: var(--r-md);
}
.skip-link:focus { left: 12px; color: #fff; text-decoration: none; }

/* ---- shell ------------------------------------------------------------- */
.layout { display: flex; min-height: 100vh; min-height: 100dvh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--navy);
  color: #fff;
  display: flex; flex-direction: column;
  overflow-y: auto;
  padding-left: var(--safe-l);
  /* Phone: a panel that slides in over the page. The desktop rail is set up
   * at the breakpoint below. */
  position: fixed; inset: 0 auto 0 0; z-index: 1045;
  transform: translateX(-100%);
  transition: transform .22s ease;
  will-change: transform;
}
.sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.35); }

.nav-backdrop {
  position: fixed; inset: 0; z-index: 1040;
  background: rgba(13, 27, 46, .45);
}

.sidebar .brand { padding: 16px 16px 14px; display: flex; gap: 10px; align-items: center; }
.sidebar .brand img { width: 38px; height: 38px; background: #fff; border-radius: 9px; padding: 4px; }
.sidebar .brand-line { font-weight: 700; font-size: 17px; line-height: 1.1; }
.sidebar .brand-sub { font-size: 10.5px; letter-spacing: .13em; text-transform: uppercase; color: #9FB2CC; }
.sidebar-close {
  margin-left: auto; background: none; border: 0; color: #9FB2CC;
  font-size: 30px; line-height: 1; width: 44px; height: 44px; border-radius: var(--r-md);
}
.sidebar-close:active { background: rgba(255,255,255,.08); }

.sidebar nav { padding: 6px 10px 14px; flex: 1; }
.sidebar nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 12px; margin-bottom: 2px;
  border-radius: var(--r-md); color: #C7D4E6; font-weight: 500; font-size: 15px;
  transition: background .12s ease, color .12s ease;
}
.sidebar nav a:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
/* Where you are, said twice — filled, and marked down its leading edge — so it
 * survives being glanced at rather than read. */
.sidebar nav a.active { background: var(--blue); color: #fff; box-shadow: inset 3px 0 0 var(--teal); }
.sidebar nav a svg { width: 18px; height: 18px; flex: 0 0 18px; }
.sidebar .chip {
  margin: 0 14px calc(16px + var(--safe-b)); padding: 12px; border-radius: var(--r-md);
  background: rgba(15,181,166,.14); border: 1px solid rgba(15,181,166,.3);
}
.sidebar .chip:hover { background: rgba(15,181,166,.22); }
.sidebar .chip-title { font-size: 12.5px; font-weight: 600; color: #7EEBDF; }
.sidebar .chip-sub { font-size: 11.5px; color: #9FB2CC; }

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

/* ---- the top bar ------------------------------------------------------- */
/* Reading order, tab order and visual order are the same: the hamburger, what
 * page this is, what you can do to it, who you are. A page's own actions are
 * the last thing before the account menu on every single screen — the right
 * of the bar is where the eye goes back to. */
.topbar {
  background: #fff; border-bottom: 1px solid var(--border);
  padding: 10px 14px; padding-left: calc(14px + var(--safe-l));
  padding-right: calc(14px + var(--safe-r));
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
  position: sticky; top: 0; z-index: 1030;
}
.topbar-heading { flex: 1 1 0; min-width: 0; }
.topbar .page-title {
  font-size: 16px; font-weight: 600; margin: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar .page-sub {
  font-size: 12px; color: var(--muted); margin: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* The page's own actions get their own full-width row on a phone rather than
 * being crushed beside the title — and they still end at the right.
 *
 * `order` puts that row *below* the avatar on a phone while the markup keeps
 * the order the page reads in: heading, what you can do here, who you are. */
.topbar-actions {
  flex: 1 0 100%; order: 3;
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  justify-content: flex-end;
}
.topbar-actions:empty { display: none; }
.topbar-actions > form { margin: 0; display: flex; gap: 8px; }
.topbar-actions .btn, .topbar-actions .form-select { min-height: 40px; }
/* Anything that is context rather than a control — a status pill, an unsaved
 * warning — sits at the left of the group, away from the buttons. */
.topbar-actions .tb-context {
  margin-right: auto; display: flex; align-items: center; gap: 8px;
  min-width: 0;
}

.nav-toggle {
  width: 42px; height: 42px; flex: 0 0 42px;
  border: 1px solid var(--border); border-radius: var(--r-md); background: #fff;
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 4px;
}
.nav-toggle span { display: block; width: 18px; height: 2px; background: var(--text); border-radius: 2px; }

.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), var(--teal));
  color: #fff; font-weight: 600; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}

.content {
  padding: 14px; padding-left: calc(14px + var(--safe-l));
  padding-right: calc(14px + var(--safe-r));
  padding-bottom: calc(40px + var(--safe-b));
}

/* ---- what the app says back -------------------------------------------- */
/* Django's messages, drawn as the app's own notice rather than Bootstrap's, so
 * "saved" looks the same on every screen. */
.alert { border-radius: var(--r-md); border-width: 1px; font-size: 13.5px; }
.notice {
  display: flex; align-items: flex-start; gap: 10px;
  border: 1px solid var(--border); border-left: 3px solid var(--blue);
  background: #fff; box-shadow: var(--shadow-sm);
  border-radius: var(--r-md); padding: 11px 12px 11px 14px; margin-bottom: 12px;
  font-size: 13.5px;
}
.notice-success { border-left-color: var(--green); }
.notice-error, .notice-danger { border-left-color: var(--red); }
.notice-warning { border-left-color: var(--orange); }
.notice-body { flex: 1 1 auto; min-width: 0; }
.notice .btn-close { flex: 0 0 auto; padding: .4rem; }

/* ---- cards ------------------------------------------------------------- */
.card-g {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-sm);
  margin-bottom: 14px;
}
.card-g > .card-head {
  padding: 12px 14px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 8px;
}
.card-g > .card-head h2, .card-g > .card-head h3 {
  font-size: 14px; font-weight: 600; margin: 0; letter-spacing: .01em;
}
.card-g > .card-body { padding: 14px; }
/* Where a table lives. It scrolls sideways inside the card instead of pushing
 * the whole page wider — a page that scrolls horizontally as a whole loses the
 * navigation and the headings off the side of the screen. */
.card-g > .card-body.tight {
  padding: 0; overflow-x: auto; -webkit-overflow-scrolling: touch;
}
/* A note about a card's figures, inside the same box, so the explanation
 * belongs to them rather than floating loose on the page. */
.card-foot {
  padding: 10px 14px; border-top: 1px solid var(--line);
  font-size: 12.5px; color: var(--muted); background: #FCFDFF;
  border-radius: 0 0 var(--r-lg) var(--r-lg);
}

/* The page links under a long list. They sit inside the card but outside the
 * scrolling .card-body.tight, so a wide table slides sideways underneath them
 * while Previous and Next stay where the thumb last found them. On a phone the
 * count wraps above the links and each link is a full 40px target. */
.pager {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  justify-content: space-between; padding: 10px 14px;
  border-top: 1px solid var(--line);
}
.pager .page-link {
  display: flex; align-items: center; min-height: 40px; padding: 0 14px;
  font-size: 13px; color: var(--blue); border-color: var(--border);
  background: var(--card);
}
.pager .page-link:hover { background: var(--blue-bg); color: var(--blue-dk); }
.pager .page-item.disabled .page-link { color: var(--disabled); background: var(--card); }

.kpi { padding: 14px; }
.kpi-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; font-weight: 600; color: var(--muted); }
.kpi-value { font-size: 20px; font-weight: 600; margin: 5px 0 2px; overflow-wrap: anywhere; }
.kpi-delta { font-size: 11.5px; }

/* ---- tables ------------------------------------------------------------ */
.table-g { width: 100%; margin: 0; }
.table-g thead th {
  background: #F7F9FC; border-bottom: 1px solid var(--border);
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  font-weight: 600; color: var(--muted); padding: 9px 12px; white-space: nowrap;
}
.table-g tbody td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table-g tbody tr:hover { background: #FAFCFF; }
.table-g tbody tr:last-child td { border-bottom: 0; }
/* The first cell says what the row is, and opens it. */
.table-g tbody td .row-link { font-weight: 600; }
/* The column that carries a name. Every other column in a list holds a figure
 * or a date and never wraps, so without a floor here the name is the only
 * thing the table can squeeze -- and it squeezes it to one word a line. */
@media (min-width: 768px) {
  .table-g th.cell-name, .table-g td.cell-name { min-width: 12rem; }
}
/* The line a phone folds under a document's number: who it is for and where it
 * has got to. It reads left, like the words it is, not right like the number
 * above it. */
.table-g td .d-md-none { text-align: left; white-space: normal; font-family: 'IBM Plex Sans', sans-serif; margin-top: 3px; }
.table-g td .d-md-none .hint { display: block; }
/* ...and the cell it sits in stops being a column of figures the moment it
 * carries words, so on a phone it reads from the left like the rest of them. */
@media (max-width: 767.98px) {
  .table-g tbody td.num:first-child { text-align: left; }
}

/* The actions column: always last, always hard right, always the same order —
 * what this screen is for, then edit, then remove.
 *
 * It is pinned to the right edge of the card it scrolls inside, at every
 * width: a table wide enough to scroll is exactly the table whose last column
 * would otherwise be the one nobody can reach. The shadow says the rest of the
 * row carries on underneath it. */
.table-g .row-actions { white-space: nowrap; text-align: right; width: 1%; }
.table th.row-actions, .table td.row-actions {
  position: sticky; right: 0; z-index: 2;
  background: #fff; box-shadow: -7px 0 8px -7px rgba(13,27,46,.22);
}
.table th.row-actions { background: #F7F9FC; }
.table tbody tr:hover td.row-actions { background: #FAFCFF; }
/* The passbook is a ruled document that is wider than any phone, so this is
 * the screen the pinned column was worth writing for: correcting an entry
 * never means swiping to the far end of the row first. */
.table-ruled th.row-actions, .table-ruled td.row-actions { background: #fff; }
.row-actions form { display: inline-block; margin: 0; }
.act-group { display: inline-flex; gap: 6px; align-items: center; justify-content: flex-end; }

/* The printed grid on screen: every row *and* column ruled. For a screen that
 * stands in for a document (a ledger) — never for an ordinary list, where
 * ruling everything makes it mean nothing. */
.table-ruled { border: 1px solid var(--rule); min-width: 44rem; }
.table-ruled th, .table-ruled td { border: 1px solid var(--rule) !important; padding: 7px 10px !important; font-size: 13px; }
.table-ruled tbody tr:hover { background: transparent; }
.table-ruled tr.closing td { background: var(--total-bg); font-weight: 600; }

/* ---- empty states ------------------------------------------------------ */
/* Never a blank box: what is missing, and the one button that fixes it. */
.empty { padding: 30px 16px; text-align: center; color: var(--muted); }
.empty .empty-title { font-weight: 600; margin-bottom: 4px; color: var(--text); }
.empty .empty-mark {
  width: 42px; height: 42px; margin: 0 auto 10px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; background: var(--blue-bg); color: var(--blue-dk);
}
.empty .empty-mark svg { width: 20px; height: 20px; }
.empty .btn { margin-top: 12px; }

/* A hint that a table has more to the right, shown only where it is true. */
.scroll-hint { font-size: 11.5px; color: var(--muted); padding: 6px 14px 0; }

/* ---- pills / badges ---------------------------------------------------- */
.pill {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; line-height: 1.5; white-space: nowrap;
}
.pill-secondary { background: #EDF1F7; color: var(--muted); }
.pill-info      { background: var(--teal-bg); color: var(--teal-dk); }
.pill-primary   { background: var(--blue-bg); color: var(--blue-dk); }
.pill-warning   { background: var(--orange-bg); color: #A5601A; }
.pill-success   { background: var(--green-bg); color: #0B6B36; }
.pill-danger    { background: var(--red-bg); color: #A32126; }

/* ---- buttons ----------------------------------------------------------- */
/* One scale, one radius, one weight. A button is a box with an optional glyph
 * and a word; the glyph never appears without the word except in a table row,
 * where the column cannot afford both and the tooltip carries the word. */
.btn {
  min-height: 40px; border-radius: var(--r-md); font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.btn svg { width: 16px; height: 16px; flex: 0 0 16px; }
.btn-primary { background: var(--blue); border-color: var(--blue); font-weight: 600; }
.btn-primary:hover, .btn-primary:focus { background: var(--blue-dk); border-color: var(--blue-dk); }
.btn-outline-secondary { border-color: #D8E0EC; color: #33475F; background: #fff; }
.btn-outline-secondary:hover { background: #F4F7FC; border-color: #C4D0E2; color: var(--navy); }
.btn-outline-primary { border-color: var(--blue-border); color: var(--blue-dk); background: #fff; }
.btn-outline-primary:hover { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-outline-danger { border-color: var(--red-border); color: #B4292E; background: #fff; }
.btn-outline-danger:hover { background: var(--red); border-color: var(--red); color: #fff; }
.btn-sm { font-size: 13px; min-height: 36px; border-radius: var(--r-sm); }
.btn-sm svg { width: 15px; height: 15px; flex: 0 0 15px; }
/* A control that is off because of the state of the record, not because it is
 * broken. It keeps its shape and loses its colour, and its title says why. */
.btn:disabled, .btn.disabled {
  opacity: 1; background: #F2F5FA; border-color: var(--border); color: var(--disabled);
}
.btn-primary:disabled { background: #A9C4FF; border-color: #A9C4FF; color: #fff; }

/* A row action. Icon-only where the column is narrow, icon and word once the
 * screen can afford it — the same control either way, so the tooltip and the
 * label always say the same word. */
.act {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; min-width: 34px; padding: 0 8px;
  border: 1px solid var(--border); border-radius: var(--r-sm);
  background: #fff; color: var(--muted);
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.act:hover { background: #F4F7FC; border-color: #C4D0E2; color: var(--navy); text-decoration: none; }
.act svg { width: 16px; height: 16px; flex: 0 0 16px; }
.act .lbl { display: none; }
/* A row action that is not Edit or Delete. It stands down on a phone, where
 * the column it lives in is pinned over the row's own words. */
.act-extra { display: none; }
@media (min-width: 768px) { .act-extra { display: inline-flex; } }
.act-primary { color: var(--blue-dk); border-color: var(--blue-border); }
.act-primary:hover { background: var(--blue-bg); border-color: var(--blue); color: var(--blue-dk); }
.act-danger:hover { background: var(--red-bg); border-color: var(--red-border); color: #B4292E; }

/* ---- forms ------------------------------------------------------------- */
.field-label { font-size: 12px; font-weight: 600; color: #33475F; margin-bottom: 4px; display: block; }
.field-label .req { color: var(--red); margin-left: 2px; }
/* 16px, not 14: anything smaller makes iOS Safari zoom the page in when the
 * field takes focus, and the user has to pinch back out after every field. */
.form-control, .form-select {
  border-color: #D8E0EC; font-size: 16px; min-height: 44px;
  border-radius: var(--r-sm);
  transition: border-color .12s ease, box-shadow .12s ease;
}
textarea.form-control { min-height: 0; }
.form-control-sm, .form-select-sm { font-size: 16px; min-height: 40px; border-radius: var(--r-sm); }
.form-control:focus, .form-select:focus { border-color: var(--blue); box-shadow: 0 0 0 .18rem rgba(30,107,255,.12); }
.form-control::placeholder { color: #A5B2C6; }
.form-control.is-invalid, .form-select.is-invalid { border-color: var(--red); background-image: none; }
/* A field the server refused. The wrapper carries the state so the widget can
 * stay whatever Django rendered it as. */
.field-invalid .form-control, .field-invalid .form-select { border-color: var(--red); }
.field-invalid .field-label { color: #B4292E; }
.form-check-input { width: 1.2em; height: 1.2em; }
.form-check-input:checked { background-color: var(--blue); border-color: var(--blue); }
/* A 17px box is a 17px target. On a phone it grows, and the row it sits in is
 * given the height of everything else a thumb has to hit. */
@media (max-width: 767.98px) {
  .form-check { display: flex; align-items: center; gap: 4px; min-height: 40px; }
  .form-check-input { width: 1.45em; height: 1.45em; margin-top: 0; }
  .form-check-label { line-height: 1.3; }
}
input.num-input { font-family: 'IBM Plex Mono', monospace; text-align: right; }
.hint { font-size: 12.5px; color: var(--muted); }
.field-error { font-size: 12.5px; color: #B4292E; margin-top: 4px; }
.section-title {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .09em;
  font-weight: 600; color: var(--muted); margin: 20px 0 8px;
}

/* A search field wearing its glyph. The glyph is decoration; the label above
 * it is what is read out. */
.input-icon { position: relative; }
.input-icon > svg {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: #93A1B5; pointer-events: none;
}
.input-icon .form-control { padding-left: 34px; }

/* ---- filters bar ------------------------------------------------------- */
/* One field per row on a phone, side by side once there is room. */
.filters { display: grid; grid-template-columns: 1fr; gap: 10px; align-items: end; }
.filters > div { min-width: 0; }
.filters .form-control, .filters .form-select { width: 100%; }
.filters .btn { width: 100%; }
.filter-actions { display: flex; gap: 8px; align-items: center; }
.filter-actions .btn { flex: 1 1 auto; }
/* The figure a filtered list adds up to. It answers the question the filter
 * was asked, so it sits with the filter rather than under the table. */
.filter-total {
  text-align: right; padding: 8px 12px; border-radius: var(--r-sm);
  background: var(--blue-bg); border: 1px solid var(--blue-border);
}
.filter-total .field-label { color: var(--blue-dk); margin-bottom: 2px; }
.filter-total .figure { font-size: 15px; font-weight: 700; color: var(--blue-dk); }

/* ---- the document toolbar --------------------------------------------- */
/* Save, Preview, Print, Delete — the same four, in the same order, on every
 * document the app produces. They live in the sticky top bar, so Save is
 * reachable from anywhere down a long list of priced lines rather than only
 * from the foot of the form. */
.doc-toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.doc-toolbar .sep { width: 1px; height: 24px; background: var(--border); margin: 0 2px; }
@media (max-width: 575.98px) {
  .doc-toolbar { width: 100%; }
  .doc-toolbar .btn { flex: 1 1 0; min-width: 0; padding-left: 6px; padding-right: 6px; }
  .doc-toolbar .sep { display: none; }
}
/* Said once, quietly: a preview and a print are of the *saved* document.
 * static/js/app.js shows this only once something has actually changed. */
.dirty-flag {
  display: none; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; color: #A5601A;
  background: var(--orange-bg); border-radius: 999px; padding: 4px 11px;
}
.dirty-flag svg { width: 14px; height: 14px; flex: 0 0 14px; }
body.form-dirty .dirty-flag { display: inline-flex; }

/* ---- line-item editor -------------------------------------------------- */
/* The tools in the card head: the catalog picker and the blank-line button.
 * They take the right of the head on a desktop and wrap under the heading on a
 * phone, where a select squeezed beside a title is unusable. */
.line-tools {
  display: flex; gap: 8px; align-items: center;
  flex: 1 1 240px; justify-content: flex-end; min-width: 0;
}
.line-tools .form-select { flex: 1 1 auto; max-width: 340px; min-width: 0; }
.line-tools .btn { white-space: nowrap; }

/* Narrow enough that the grid fits the editor column on any desktop and
 * on a tablet held wide -- below that it scrolls inside its own card,
 * and below 768px it stops being a grid at all. */
.items-table { min-width: 36rem; }
.items-table td { padding: 5px 6px !important; vertical-align: top; }
.items-table thead th { padding: 8px 6px; }
.items-table input, .items-table textarea { font-size: 16px; }
/* A service is a phrase, not a paragraph. The description starts one line high
 * and grows only as far as what is typed needs it to — a two-row box on every
 * line pushes the fourth line of the document off the screen. app.js does the
 * growing; this is the floor it grows from. */
.items-table textarea.line-description {
  min-height: 40px; resize: vertical; overflow: hidden; line-height: 1.45;
}
.items-table .line-total { font-family: 'IBM Plex Mono', monospace; text-align: right; padding-top: 9px; display: block; }
.items-table td.line-number { padding-top: 14px !important; color: var(--muted); font-weight: 600; }
/* With nothing standing the header would rule off an empty strip, so it goes
 * and the note below takes its place. */
.items-table.is-empty thead { display: none; }
.lines-empty { border-top: 1px solid var(--line); padding: 26px 16px; }
/* A second Add line, at the foot of the grid beside the last row. Reaching
 * back up to the card head to add the ninth line is a scroll every time. */
.lines-foot {
  border-top: 1px solid var(--line); padding: 10px 12px;
  display: flex; gap: 10px; align-items: center; justify-content: space-between;
  flex-wrap: wrap;
}
.lines-foot .hint { margin: 0; }

/* Removing a line stays a checkbox — the formset needs one, and it has to
 * survive a save that comes back with errors — but it is drawn as the control
 * it is rather than as a bare box beside a price. The input keeps its place in
 * the tab order and simply wears the icon. */
.remove-toggle { position: relative; display: flex; justify-content: center; }
.remove-toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.remove-toggle label {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  width: 36px; height: 36px; border-radius: var(--r-sm); cursor: pointer;
  color: #8494AB; border: 1px solid transparent;
}
.remove-toggle label svg { width: 17px; height: 17px; flex: 0 0 17px; }
.remove-toggle .remove-word { display: none; }
.remove-toggle label:hover { color: var(--red); background: var(--red-bg); }
.remove-toggle input:focus-visible + label { outline: 2px solid var(--blue); outline-offset: 1px; }
.remove-toggle input:checked + label { color: var(--red); background: var(--red-bg); }

/* A line marked for removal has to stay readable — the tick is undone by
 * ticking it again — while no longer reading as part of the document. */
.items-table tbody tr.line-removed,
.items-table tbody tr.line-removed:hover { background: #FCFDFE; }
tr.line-removed td:not(.line-remove) { opacity: .45; }
tr.line-removed .line-total { text-decoration: line-through; }

/* ---- the summary card -------------------------------------------------- */
.totals-card dt { font-weight: 500; color: #33475F; }
.totals-card dd { font-family: 'IBM Plex Mono', monospace; text-align: right; margin: 0; }
.totals-card .grand { font-size: 18px; font-weight: 700; color: var(--blue-dk); }
/* A label and its figure, the figure hard against the right so a column of
 * them lines up on the decimal point. */
.sum-line {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 16px; padding: 5px 0;
}
.sum-line > span { color: #33475F; font-weight: 500; }
.sum-line > b { font-family: 'IBM Plex Mono', monospace; font-weight: 500; white-space: nowrap; }
.sum-line.sum-grand {
  margin-top: 6px; padding-top: 11px; border-top: 1px solid var(--border);
}
.sum-line.sum-grand > span { color: var(--text); font-weight: 600; }
.sum-line.sum-grand > b { font-size: 19px; font-weight: 700; color: var(--blue-dk); }
.sum-line.sum-paid > b { color: var(--green); }
.sum-note { font-size: 12.5px; color: var(--muted); margin: 12px 0 0; }
.sum-divider { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }

/* On a phone the grid restacks into one card per line. A seven-column editor
 * scrolled sideways with a thumb is how a price gets typed into the wrong
 * row; each field gets its own labelled line instead. `data-label` comes from
 * documents/_lines.html. */
@media (max-width: 767.98px) {
  .items-table { min-width: 0; }
  .items-table thead { display: none; }
  .items-table tbody tr.line-row {
    display: block; margin: 12px; padding: 6px 10px 10px;
    border: 1px solid var(--border); border-radius: var(--r-md); background: #FCFDFF;
  }
  .items-table tbody tr.line-row:hover { background: #FCFDFF; }
  .items-table tbody td {
    display: block; border: 0; padding: 5px 0 !important; text-align: left;
  }
  .items-table tbody td::before {
    content: attr(data-label);
    display: block; margin-bottom: 3px;
    font-size: 11px; font-weight: 600; letter-spacing: .06em;
    text-transform: uppercase; color: var(--muted);
  }
  /* Quantity, unit and price are short fields that belong together. A line
   * each is three screens of thumb travel for what is one row of a form. */
  .items-table tbody td[data-label="Qty"],
  .items-table tbody td[data-label="Unit"] {
    display: inline-block; width: 32%; padding-right: 8px !important; vertical-align: top;
  }
  .items-table tbody td[data-label="Unit price"] { display: inline-block; width: 36%; vertical-align: top; }
  /* The line number and the total read as a header and a footer for the card,
   * so they keep their label inline rather than stacked above. */
  .items-table td.line-number { font-weight: 600; color: var(--muted); padding-top: 5px !important; }
  .items-table td.line-number::before { display: inline; margin-right: 4px; }
  .items-table td[data-label="Line total"] { border-top: 1px solid var(--line) !important; }
  .items-table td[data-label="Line total"]::before { display: inline; }
  .items-table td[data-label="Line total"] .line-total { display: inline; }
  .items-table .line-total { text-align: left; padding-top: 0; }
  /* Removing wants a thumb and a word, not a 17px glyph: the icon alone in a
   * stacked card gives no clue what it does to the card it sits in. */
  .items-table td.line-remove::before { display: none; }
  .remove-toggle { justify-content: flex-start; }
  .remove-toggle label {
    width: auto; height: 40px; padding: 0 14px; border-color: var(--border);
  }
  .remove-toggle .remove-word { display: inline; font-size: 13px; font-weight: 600; }

  /* Row actions on a phone: icon-only and tappable. Two full-size labelled
   * buttons in the last column are what makes an otherwise narrow list scroll
   * sideways in the first place. */
  .act { height: 36px; min-width: 36px; padding: 0 7px; }

}

/* Action rows at the foot of an editor: full-width buttons on a phone, and a
 * surface of their own so Save reads as the end of the form rather than as
 * something dropped below it. */
.form-actions {
  display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 40px;
  padding: 12px; border-radius: var(--r-lg);
  background: var(--card); border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}
.form-actions .btn { flex: 1 1 100%; }
/* Delete is held at the other end of the bar from Save by the whole width of
 * the card, so a thumb reaching for one cannot land on the other. */
.form-actions .btn-danger-slot { margin-left: 0; }

/* ---- the lead board ----------------------------------------------------- */
/* A column per stage, side by side. The board is its own scroller: the page
 * itself must never scroll sideways, so the overflow lives here and the
 * navigation and the headings stay put while the columns move.
 *
 * On a phone a column is most of the screen wide, with the next one showing at
 * the edge — a strip of the neighbour is what tells you there is more board. */
.board {
  display: flex; gap: 12px; overflow-x: auto; overflow-y: visible;
  padding-bottom: 10px; margin-bottom: 12px;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}
.board-col {
  flex: 0 0 min(80vw, 300px); min-width: 0;
  background: #EDF2F9; border: 1px solid var(--border);
  border-radius: var(--r-lg); scroll-snap-align: start;
  display: flex; flex-direction: column;
}
.board-col-head { padding: 12px 12px 10px; }
.board-col-title { display: flex; align-items: center; gap: 8px; }
.board-col-name { font-weight: 600; font-size: 14px; }
.board-count {
  font-family: 'IBM Plex Mono', monospace; font-size: 11.5px; font-weight: 600;
  color: var(--muted); background: #fff; border: 1px solid var(--border);
  border-radius: 20px; padding: 1px 8px;
}
/* Adding a lead straight into the column you are looking at, the way the
 * column heading is where you are already pointing. */
.board-add {
  margin-left: auto; width: 30px; height: 30px; border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center; color: var(--muted);
}
.board-add:hover { background: #fff; color: var(--blue-dk); text-decoration: none; }
.board-add svg { width: 16px; height: 16px; }

/* The column's value, split by priority. Colour carries the same meaning it
 * does in a priority pill, so nothing new has to be learned to read it. */
.board-bar {
  display: flex; gap: 2px; height: 4px; margin: 9px 0 7px;
  background: #DCE4EF; border-radius: 3px; overflow: hidden;
}
.board-seg { display: block; height: 100%; }
.board-seg-danger    { background: var(--red); }
.board-seg-warning   { background: var(--orange); }
.board-seg-secondary { background: #9FB0C6; }
.board-total { font-size: 13px; font-weight: 600; color: var(--blue-dk); text-align: left; }

.board-drop {
  flex: 1 1 auto; min-height: 90px; padding: 0 8px 8px;
  display: flex; flex-direction: column; gap: 8px;
  border-radius: 0 0 var(--r-lg) var(--r-lg);
}
.board-drop.over { background: var(--blue-bg); outline: 2px dashed var(--blue); outline-offset: -4px; }
.board-empty { margin: 0; padding: 18px 8px; text-align: center; font-size: 12.5px; color: var(--disabled); }

/* ---- a card on it ------------------------------------------------------- */
.lead-card {
  position: relative; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 10px 44px 10px 12px;
  box-shadow: var(--shadow-sm);
}
.lead-card:hover { border-color: #C9D6E8; }
/* Not moved in a fortnight. A quiet flag down the edge rather than a colour
 * over the whole card: it is a nudge, not an error. */
.lead-stalled { border-left: 3px solid var(--orange); }
.lead-name { display: block; font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.lead-name:hover { color: var(--blue-dk); }
.lead-value { text-align: left; font-size: 13.5px; font-weight: 600; color: var(--blue-dk); margin-top: 2px; }
.lead-op { font-size: 12.5px; color: var(--muted); margin-top: 4px; overflow-wrap: anywhere; }
.lead-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.lead-phone { font-family: 'IBM Plex Mono', monospace; font-size: 11.5px; color: var(--muted); }

.lead-stars { display: inline-flex; gap: 1px; }
.star svg { width: 14px; height: 14px; color: #C9D2DF; }
.star-on svg { color: var(--orange); fill: var(--orange); }

/* The follow-up clock: the one thing on a card that says do something today. */
.lead-clock { margin-left: auto; display: inline-flex; }
.lead-clock svg { width: 15px; height: 15px; }
.lead-clock-overdue { color: var(--red); }
.lead-clock-today   { color: var(--orange); }
.lead-clock-due     { color: var(--green); }

/* The grip is the only drag surface, so a thumb can still scroll the column
 * past a card. `touch-action: none` on the handle alone is what buys that. */
.lead-grip {
  position: absolute; top: 4px; right: 2px;
  width: 40px; height: 40px; padding: 0; border: 0; background: none;
  color: var(--disabled); cursor: grab; touch-action: none;
  display: flex; align-items: center; justify-content: center;
}
.lead-grip:hover { color: var(--muted); }
.lead-grip svg { width: 16px; height: 16px; }

.lead-card.dragging {
  position: fixed; z-index: 1200; margin: 0; pointer-events: none;
  box-shadow: var(--shadow-pop); transform: rotate(1.5deg);
  border-color: var(--blue);
}
/* While a card is in the air, nothing else on the page should take a tap or
 * start selecting text under the thumb. */
body.board-dragging { user-select: none; cursor: grabbing; }
/* Saving. It has landed and the server has not answered yet. */
.lead-saving { opacity: .55; }

/* Changing a stage from the list, without opening the lead. Wide enough
 * that "First Meeting" does not sit truncated in a column of pills. */
.stage-select { min-width: 138px; }

/* ---- login ------------------------------------------------------------- */
.login-shell {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 20% -10%, #16305A 0%, var(--navy) 60%);
  padding: 20px calc(16px + var(--safe-l)) calc(20px + var(--safe-b)) calc(16px + var(--safe-r));
}
.login-card {
  width: 100%; max-width: 400px; background: #fff;
  border-radius: 18px; padding: 28px 24px; box-shadow: var(--shadow-pop);
}
.login-card img { width: 54px; height: 54px; }
.login-card code { font-size: 12px; overflow-wrap: anywhere; }
/* Typing a password blind on a phone keyboard is how people get locked out of
 * their own office. The eye is inside the field and off by default. */
.pw-wrap { position: relative; }
.pw-wrap .form-control { padding-right: 46px; }
.pw-toggle {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  width: 40px; height: 40px; border: 0; background: none; color: var(--muted);
  display: flex; align-items: center; justify-content: center; border-radius: var(--r-sm);
}
.pw-toggle svg { width: 18px; height: 18px; }
.pw-toggle:hover { color: var(--navy); background: #F4F7FC; }

/* ======================================================================== */
/* Tablet and up                                                            */
/* ======================================================================== */
@media (min-width: 576px) {
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters .btn { width: auto; }
  /* The primary button is the rightmost thing in the bar, as it is at the top
   * of the page and in every dialog the browser itself draws. */
  .form-actions { justify-content: flex-end; }
  .form-actions .btn { flex: 0 0 auto; }
  .form-actions .btn-danger-slot { margin-right: auto; }
}

@media (min-width: 768px) {
  body { font-size: 14px; }
  .filters { display: flex; flex-wrap: wrap; gap: 10px; }
  .filters > div { flex: 0 1 auto; }
  .filters .form-control, .filters .form-select { min-width: 150px; width: auto; }
  .filter-actions .btn { flex: 0 0 auto; }
  .kpi-value { font-size: 25px; }
  .content { padding: 18px; padding-bottom: calc(40px + var(--safe-b)); }
  .form-control, .form-select { font-size: 14px; }
  .form-control-sm, .form-select-sm { font-size: 13px; min-height: 34px; }
  /* Compact enough that a ten-line quotation is one screenful, tall enough to
   * still be a 34px target. */
  .items-table input, .items-table textarea { font-size: 13.5px; padding: 5px 8px; min-height: 34px; }
  .items-table textarea.line-description { min-height: 34px; }
  .items-table td.line-number { padding-top: 12px !important; }
  .items-table .line-total { padding-top: 8px; }
}

/* ======================================================================== */
/* Desktop: the sidebar becomes a fixed rail again                          */
/* ======================================================================== */
@media (min-width: 992px) {
  .sidebar {
    /* `inset` first, then `top`: the shorthand would otherwise reset the
     * offset the sticky rail needs and quietly stop it sticking. */
    inset: auto;
    position: sticky; top: 0; height: 100vh; height: 100dvh;
    transform: none; box-shadow: none;
    /* No slide on a desktop — the rail is simply there. */
    transition: none;
  }
  .nav-backdrop { display: none !important; }
  .sidebar .brand { padding: 18px 18px 14px; }
  .sidebar nav a { padding: 9px 12px; font-size: 13.5px; }
  body.nav-open { overflow: auto; }

  .topbar { padding: 12px 22px; flex-wrap: nowrap; gap: 16px; }
  .topbar .page-title { font-size: 17px; }
  /* Between the heading and the account menu, pushed right by the heading —
   * which is the flexible one. One row, so the markup order is the layout. */
  .topbar-actions { flex: 0 0 auto; order: 0; }
  .content { padding: 20px 22px 40px; }

  .board-col { flex: 0 0 272px; }

  .card-g { margin-bottom: 16px; }
  .card-g > .card-head { padding: 13px 18px; }
  .card-g > .card-body { padding: 16px 18px; }
  .card-foot { padding: 10px 18px; }
  .pager { padding: 10px 18px; }
  .kpi { padding: 16px 18px; }
  .table-g thead th { padding: 9px 14px; }
  .table-g tbody td { padding: 10px 14px; }
}

/* ======================================================================== */
/* Wide desktop: a summary that follows the page down                        */
/* ======================================================================== */
@media (min-width: 1200px) {
  /* Pricing a long list of services means scrolling past the running total.
   * The offset clears the sticky topbar, which is the only thing above it. */
  .editor-side { position: sticky; top: calc(var(--topbar-h) + 22px); }
}

/* ======================================================================== */
/* Very wide: the words on a row action                                      */
/* ======================================================================== */
/* Not a pixel sooner. A row can carry four actions, and four words is 240px
 * taken from the column that holds the client's name -- which then wraps into
 * a stack while the columns of figures beside it sit half empty. */
@media (min-width: 1400px) {
  .act .lbl { display: inline; }
  .act { padding: 0 10px; }
}

/* Someone who has asked their machine for less movement gets less of it. */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
