/* Appcies "Steel / Blueprint" design system: one stylesheet re-skinning Bootstrap 5.
   Sections: fonts, tokens, base, shell, nav, forms, tables, grids, pills, login, print. */

/* ---- Fonts (self-hosted, offline-friendly) ------------------------------- */
/* Self-hosted variable Inter and JetBrains Mono (400-700 axis); no runtime network.
   latin-ext and italic files load only when a glyph needs them. */
@font-face {
  font-family: "Inter"; font-style: normal; font-weight: 400 700;
  font-display: swap; src: url("/fonts/inter-roman-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Inter"; font-style: normal; font-weight: 400 700;
  font-display: swap; src: url("/fonts/inter-roman-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Inter"; font-style: italic; font-weight: 400 700;
  font-display: swap; src: url("/fonts/inter-italic-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "JetBrains Mono"; font-style: normal; font-weight: 400 700;
  font-display: swap; src: url("/fonts/jetbrains-mono-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193,
    U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "JetBrains Mono"; font-style: normal; font-weight: 400 700;
  font-display: swap; src: url("/fonts/jetbrains-mono-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
    U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
    U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ---- Design tokens ------------------------------------------------------- */
/* Palette, geometry and type scale follow the Appcies reference design system.
   Not reproduced: red focused buttons, outline-less focus, `transition: all`. */
:root {
  --side-w: 258px;
  /* Collapsed rail width: one centred 17px icon. */
  --side-w-rail: 64px;
  /* Shell breakpoint = Bootstrap lg (992px); @media can't read vars, so it is duplicated
     in the fold block below and SIDE_BP in js/app.js. Keep them in sync. */

  /* neutrals / surfaces */
  --canvas:  #eceff4;            /* the reference body background            */
  --surface: #ffffff;
  /* the recessed plane: table headers and the popup chrome sit on it */
  --surface-sunken: #e6eaf0;     /* --grid-header-background, a shade down so
                                    it still reads as recessed against canvas */
  --ink:     #080a0c;            /* --main-color                             */
  --ink-soft:#5c666f;            /* .panel-title ink                         */
  --muted:   #6b7a86;            /* the reference's field ink, reused as meta */
  --line:    #d6e2e8;            /* --input-border-color, doubles as hairline */
  --line-strong: #c3d2dc;
  /* .panel-default's rgb(123,136,148): the strong edge a card or dialog draws
     around itself. Distinct from --line, which is an interior rule. */
  --line-card: #7b8894;
  --placeholder: #c3d2dc;        /* reference #d6e2e8 darkened to the ~2:1
                                    placeholder contrast floor */
  /* fill for any field the user cannot type into (readonly / disabled) */
  --field-locked-bg: #eceff4;
  --field-locked-border: #dfe6ea;

  /* The signature band. A card or a dialog names itself with a blue-grey-to-
     white gradient bar rather than with bold text on a rule (.panel-title). */
  --band-top:    #b5c8da;
  --band-bottom: #ffffff;
  --band-ink:    #5c666f;

  /* Navigation rail: the reference button blue, darkened so white text clears AA
     (#3a6595 = 5.97:1). */
  --steel-900: #2f5479;          /* rail gradient foot                       */
  --steel-800: #3a6595;          /* rail gradient head                       */
  --steel-700: #45739f;          /* link hover                               */
  --steel-500: #cfe0f0;          /* group titles, brand sub-line             */
  --steel-100: #eef4fa;          /* link ink                                 */

  /* accent */
  --accent:       #477eb8;       /* --button-background                      */
  --accent-hover: #5ba1eb;       /* the reference hover goes LIGHTER         */
  --accent-600:   #3d6a99;       /* pressed                                  */
  --accent-700:   #2e6e9e;       /* the reference's tab ink                  */
  --accent-tint:  #dfeffc;       /* inactive tab / soft chip                 */
  --accent-line:  #c5dbec;       /* inactive tab border                      */
  --accent-rgb:   71, 126, 184;
  /* --static-text-color: every label, legend and column header in the
     reference is this blue, sentence case, normal weight. */
  --label:        #4a7fb6;
  /* --label fails 4.5:1 on the sunken plane (3.57:1), so small text that sits
     on it — the table headers — uses this darkened twin instead. */
  --label-strong: #3d6a99;
  --link:         #de615e;       /* the reference's coral link               */
  --row-hover:    #ebebeb;       /* --grid-hover-background                  */

  /* Semantics: tints are the reference backgrounds; ink is the matching
     Bootstrap 3 state text. */
  --ok:   #3c763d;   --ok-tint:   #dff0d8;   --ok-line:   #d0e9c6;   --ok-rgb:   60,118,61;
  --warn: #8a6d3b;   --warn-tint: #fcf8e3;   --warn-line: #faf2cc;   --warn-rgb: 138,109,59;
  --bad:  #a94442;   --bad-tint:  #f2dede;   --bad-line:  #ebcccc;   --bad-rgb:  169,68,66;
  --info: #31708f;   --info-tint: #d9edf7;   --info-line: #c4e3f3;

  --radius: 7px;                 /* cards, dialogs, fieldsets                */
  --radius-sm: 4px;              /* every control                            */

  /* Control geometry: fixed heights, roomy on a page and compact in a dialog
     (see the two Forms sections). */
  --h-input:       36px;         /* appciesStyleGeneral input                */
  --h-select:      36px;         /* the reference runs selects at 32px; see
                                    the note on .form-select below           */
  --h-btn:         36px;
  --h-input-sm:    28px;         /* toolbar filters, picker search           */
  --h-input-dense: 24px;         /* .appcies-studio input — dialog measure   */
  --h-btn-dense:   24px;
  --h-grid-cell:   24px;

  /* Row density: every table's row height derives from these three tokens
     (--row-line-h is the cell line box). */
  --row-line-h: 1.35;
  --row-pad-y:  .22rem;
  --row-pad-x:  .55rem;

  --shadow:     0 0 2px 0 rgba(0,0,0,.20);     /* header.headerback          */
  --shadow-btn: 0 1px 3px 0 rgba(2,2,2,.30);   /* --shadow-color / .btn      */
  --shadow-lg:  0 6px 18px rgba(2,2,2,.28);    /* dialogs, drawer, popups    */

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI",
               Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono",
               Menlo, Consolas, monospace;

  /* Type scale: reference sizes in Inter (px at a 16px root); sentence case
     everywhere except the rail's group titles. */
  --fs-page-title:   1.125rem;   /* 18px bold — .panel-title                 */
  --fs-dialog-title: .875rem;    /* 14px bold — .studio .panel-title         */
  --fs-label:        1rem;       /* 16px normal — .appcies-label ≥1024px     */
  --fs-label-sm:     .875rem;    /* 14px — .appcies-label <1024px            */
  --fs-label-dense:  .75rem;     /* 12px — .appcies-studio .appcies-label    */
  --fs-field:        .9375rem;   /* 15px — page input                        */
  --fs-field-dense:  .8125rem;   /* 13px — dialog input, grid cell           */
  --fs-btn:          1rem;       /* 16px normal, 17px line                   */
  --fs-table:        .875rem;    /* 14px — .bootgrid-table                   */
  --fs-meta:         .8125rem;   /* 13px                                     */
  /* Grids and tables run two pixels tighter than the rest: they are pure data,
     scanned by column. */
  --fs-table-cell:   .75rem;     /* 12px — list and fiche table cells        */
  --fs-table-head:   .6875rem;   /* 11px — their column headers              */
  --fs-grid-cell:    .6875rem;   /* 11px — js/grid.js line-grid cells        */
  /* the app's eyebrow, first set on .nav-group-title and reused from here */
  --fs-eyebrow:      .75rem;
  --tracking-eyebrow: .10em;

  /* let Bootstrap 5 inherit our type + accent where it reads its own vars */
  --bs-body-font-family: var(--font-sans);
  /* Bootstrap keeps its own mono chain; without this <code>, <pre>, <kbd>
     and .font-monospace render in the system face, not ours. */
  --bs-font-monospace: var(--font-mono);
  --bs-body-color: var(--ink);
  --bs-secondary-color: var(--muted);        /* .text-muted                  */
  --bs-border-color: var(--line);
  --bs-primary: var(--accent);
  --bs-link-color: var(--link);
  --bs-link-hover-color: var(--link);
  --bs-border-radius: var(--radius);
  /* A control must not inherit the 7px card radius — the reference gives every
     input and button 4px and reserves 7px for the box around them. */
  --bs-border-radius-sm: var(--radius-sm);
}

/* ---- Base ---------------------------------------------------------------- */
body {
  background: var(--canvas);
  color: var(--ink);
  font-family: var(--font-sans);
  /* Inter carries an `opsz` axis: 14px body and 18px titles get spacing and
     stem weights tuned per size instead of one scaled outline. */
  font-optical-sizing: auto;
  font-size: var(--fs-table);   /* 14px — the reference's working size */
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Disable contextual alternates: Inter turns `3x` into `3×`, but `Nx` is a quantity prefix.
   Controls are listed because their UA font shorthand resets font-variant. */
body, input, textarea, select, button, optgroup {
  font-variant-ligatures: no-contextual;
}

.num, .mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

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

::selection { background: var(--accent-tint); }

/* ---- App shell ----------------------------------------------------------- */
.app-shell { display: flex; min-height: 100vh; }

.app-side {
  width: var(--side-w); flex: 0 0 var(--side-w);
  background: linear-gradient(180deg, var(--steel-800) 0%, var(--steel-900) 100%);
  color: var(--steel-100); min-height: 100vh;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  border-right: 1px solid rgba(2,2,2,.22);
}
.app-side::-webkit-scrollbar { width: 9px; }
.app-side::-webkit-scrollbar-thumb { background: rgba(255,255,255,.28); border-radius: 6px; }

.app-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.app-content { padding: 1.5rem 1.75rem; flex: 1 1 auto; }

/* ---- Brand --------------------------------------------------------------- */
.app-side .brand {
  display: flex; align-items: center; gap: .7rem;
  padding: 1.05rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,.14);
  color: #fff;
}
.brand-badge {
  width: 34px; height: 34px; border-radius: 9px; flex: 0 0 34px;
  background-image: url("/img/logo.svg"); background-size: cover;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.16);
}
.brand-word { display: flex; flex-direction: column; line-height: 1.1; }
.brand-word b { font-weight: 600; font-size: 1.06rem; letter-spacing: .2px; }
.brand-word small { color: var(--steel-500); font-size: .62rem;
  text-transform: uppercase; letter-spacing: .16em; }

/* ---- Sidebar nav --------------------------------------------------------- */
.nav-group { padding: .35rem 0 .1rem; }
.nav-group-title {
  font-size: var(--fs-eyebrow); text-transform: uppercase;
  letter-spacing: var(--tracking-eyebrow);
  color: var(--steel-500); padding: .55rem 1.35rem .3rem; font-weight: 600;
}
.app-side .nav-link {
  display: flex; align-items: center; gap: .65rem;
  color: var(--steel-100); padding: .48rem 1.35rem;
  border-radius: 0; font-size: var(--fs-table); font-weight: 400;
  border-left: 3px solid transparent;
  transition: background .12s ease, color .12s ease, border-color .12s ease;
}
.app-side .nav-link .nav-ico {
  width: 17px; height: 17px; flex: 0 0 17px; opacity: .72;
  transition: opacity .12s ease;
}
.app-side .nav-link:hover {
  background: var(--steel-700); color: #fff; text-decoration: none;
}
.app-side .nav-link:hover .nav-ico { opacity: 1; }
.app-side .nav-link.active {
  background: var(--accent);
  color: #fff; border-left-color: #fff;
}
.app-side .nav-link.active .nav-ico { opacity: 1; color: #fff; }

/* ---- Topbar -------------------------------------------------------------- */
.app-topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface); box-shadow: var(--shadow);
  padding: .7rem 1.75rem; display: flex; flex-wrap: wrap; align-items: center;
  gap: .5rem 1rem;
  min-height: 58px;
}
/* The title is the only elastic thing in the bar, so it is what gives: it
   truncates rather than shoving the user chip off the edge. */
.app-topbar h5, .app-topbar #title {
  font-weight: 600; font-size: var(--fs-page-title); color: var(--band-ink);
  letter-spacing: 0;
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-chip { display: inline-flex; align-items: center; gap: .5rem; }
.user-chip .avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: .72rem; font-weight: 600; letter-spacing: .02em;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.25);
}
.user-chip .uid { display: flex; flex-direction: column; line-height: 1.15; }
.user-chip .uname { color: var(--ink-soft); font-size: var(--fs-meta); font-weight: 600; }
.user-chip .ulogin { color: var(--muted); font-size: calc(var(--fs-meta) - 1px); font-weight: 400; }
#btn-logout {
  color: var(--muted); font-size: var(--fs-meta); font-weight: 500;
  padding: .25rem .6rem; border-radius: var(--radius-sm);
  transition: background .12s ease, color .12s ease;
}
#btn-logout:hover { background: var(--bad-tint); color: var(--bad); text-decoration: none; }

/* ---- Tab counts ---------------------------------------------------------- */
/* Tabs show their collection's count; an empty collection shows a rule, not a zero. */
.tab-count {
  margin-left: .4rem; font-size: var(--fs-meta); font-weight: 500;
  color: var(--muted); font-variant-numeric: tabular-nums;
}
.nav-tabs .nav-link.active .tab-count { color: var(--accent); }

/* ---- Pane head ----------------------------------------------------------- */
/* Collection panes: title on the left, add action on the right. The section
   title carries a rule marking where the section starts and ends. */
.pane-head {
  display: flex; flex-wrap: wrap; align-items: center;
  gap: .5rem 1rem;
  padding-bottom: .3rem; margin-bottom: .7rem;
  border-bottom: 1px solid var(--line);
}
/* Section titles: sentence case in the label colour, with a button-blue accent
   mark to tell them apart from field labels. */
.pane-head h2 {
  margin: 0; font-size: var(--fs-label); text-transform: none;
  letter-spacing: 0; color: var(--label); font-weight: 600;
  display: inline-flex; align-items: center; gap: .45rem;
}
.pane-head h2::before {
  content: ""; flex: none;
  width: 3px; height: 1em; border-radius: 1px;
  background: var(--accent);
}
.pane-head .spacer { flex: 1 1 auto; }

/* ---- Toolbar ------------------------------------------------------------- */
/* min-width:0 lets inputs shrink below their ~180px intrinsic width; the inline
   max-width is the ceiling, flex-basis the preferred size. */
.table-toolbar {
  display: flex; flex-wrap: wrap; gap: .6rem;
  align-items: center; margin-bottom: 1rem;
}
.table-toolbar .spacer { flex: 1 1 auto; }
.table-toolbar > .form-control,
.table-toolbar > .form-select { flex: 1 1 200px; min-width: 0; }
/* Once the row has wrapped, a trailing spacer would leave the button stranded
   on a line of its own; collapsing it lets the button sit up with the filters. */
@media (max-width: 575.98px) {
  .table-toolbar .spacer { flex-basis: 0; }
  .table-toolbar > .form-control,
  .table-toolbar > .form-select { max-width: none; }
}

/* ---- Cards --------------------------------------------------------------- */
/* Reference .panel: white box on a strong 7px-radius hairline, no shadow. */
.card {
  background: var(--surface);
  border: 1px solid var(--line-card);
  border-radius: var(--radius);
  box-shadow: none;
}
/* .panel-title signature band: blue-grey-to-white gradient bar (used by .login-card). */
.card > .card-header {
  background: linear-gradient(to bottom, var(--band-top) 0%, var(--band-bottom) 100%);
  border-bottom: 0;
  border-top-left-radius: inherit;
  border-top-right-radius: inherit;
  padding: 11px 15px 6px;
  color: var(--band-ink);
  font-size: var(--fs-page-title);
  font-weight: 600;
  line-height: 1.15;
  text-align: center;
}

/* ---- Tables -------------------------------------------------------------- */
/* Tables scroll inside their box so the thead stays pinned; --grid-max-h is
   measured by fitStickyGrids() in js/app.js. */
.table-responsive, .grid-scroll {
  overflow: auto;
  max-height: var(--grid-max-h, none);
  /* Contain sideways overscroll so a table swipe doesn't drag the page. */
  overscroll-behavior-x: contain;
}
.card > .table-responsive { border-radius: var(--radius); }
.table {
  --bs-table-bg: transparent;
  margin-bottom: 0; color: var(--ink); font-size: var(--fs-table-cell);
  line-height: var(--row-line-h);
  font-variant-numeric: tabular-nums;
}
.table > thead > tr > th {
  position: sticky; top: 0; z-index: 3;
  /* .column-header-anchor: normal-weight blue, sentence case. --label itself
     is only 3.57:1 on the sunken plane, so the darkened twin is used here. */
  background: var(--surface-sunken); color: var(--label-strong);
  font-size: var(--fs-table-head); font-weight: 400; text-transform: none;
  letter-spacing: 0;
  /* border-collapse leaves a sticky cell's own borders behind when it moves,
     so the header rules are painted as inset shadows instead. */
  border-bottom: 0;
  box-shadow: inset 0 -1px 0 var(--line-strong);
  padding: .38rem var(--row-pad-x); white-space: nowrap;
}
/* Bordered tables (the line grids) need the vertical rules drawn the same way. */
.table.table-bordered > thead > tr > th {
  box-shadow: inset -1px -1px 0 var(--line), inset 1px 1px 0 var(--line);
}
.table > tbody > tr > td {
  padding: var(--row-pad-y) var(--row-pad-x); border-top: 1px solid var(--line);
  vertical-align: middle;
}
.table.table-hover > tbody > tr:hover > td { background: var(--row-hover); }
.list-row-click { cursor: pointer; }

/* Sortable headers: chevron via ::after (not a shadow, which the sticky rule uses);
   its space is always reserved so the column width doesn't jump. */
.table > thead > tr > th.sortable { cursor: pointer; padding-right: 1.15rem; }
.table > thead > tr > th.sortable:hover { color: var(--accent-700); }
.table > thead > tr > th.sortable::after {
  content: ""; position: absolute;
  right: var(--row-pad-x); top: 50%; margin-top: -2px;
  width: 0; height: 0;
  border-left: 3.5px solid transparent; border-right: 3.5px solid transparent;
}
.table > thead > tr > th[aria-sort="ascending"]::after  { border-bottom: 4px solid currentColor; }
.table > thead > tr > th[aria-sort="descending"]::after { border-top: 4px solid currentColor; }
.table > thead > tr > th[aria-sort="ascending"],
.table > thead > tr > th[aria-sort="descending"] { color: var(--accent-700); font-weight: 600; }
/* The global focus ring gets clipped by the scroll box; draw it inset. */
.table > thead > tr > th.sortable:focus-visible { outline-offset: -2px; }

/* money / numeric columns align right & use the data face */
.table td.text-end, .table th.text-end { font-variant-numeric: tabular-nums; }

/* Numeric inputs align right like amount columns, in forms and line grids. */
input[type="number"],
input.money,
.grid-cell[type="number"] {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Hide number spinners: they overlap right-aligned digits; arrow keys still work. */
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none; margin: 0;
}

/* Codes and ISO dates get a fixed width and never wrap; the description absorbs the rest. */
/* min-width, not width: under table-layout auto a width is dropped first when squeezed,
   so the table overflows into its scroll box instead. */
.table th.col-date, .table td.col-date {
  width: 108px; min-width: 108px; white-space: nowrap;
}

/* ---- Date field + calendar (js/datepicker.js) -----------------------------
   ISO format in a monospace face, matching .col-date and the API. */

.date-field .date-input { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* The button overlays the field's right edge so narrow columns keep room for ten characters. */
.date-field { position: relative; }
.date-field .date-input { padding-right: 2rem; }
.date-field .date-btn {
  position: absolute; top: 1px; right: 1px; bottom: 1px; width: 1.9rem;
  display: flex; align-items: center; justify-content: center;
  padding: 0; background: transparent; border: 0; border-radius: 0 5px 5px 0;
  color: var(--muted);
}
.date-field .date-btn:hover { color: var(--accent-600); background: var(--accent-tint); }
.date-field .date-btn .nav-ico { width: 15px; height: 15px; }

/* Shift Bootstrap's invalid icon left so it doesn't overlap the calendar button. */
.date-field .date-input.is-invalid {
  padding-right: 3.6rem;
  background-position: right 2.1rem center;
}

/* Grid cells have no button and open on click; the cursor signals it. */
.grid-cell.date-input { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---- Popup ---------------------------------------------------------------
   Fixed, above stacked modals, rendered under <body> to escape clipping overflow. */
.dp-pop {
  display: none; position: fixed; top: 0; left: 0;
  width: 244px; padding: .5rem;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: 8px;
  box-shadow: var(--shadow-lg);
  user-select: none;
}
.dp-pop.is-open { display: block; }

.dp-head { display: flex; align-items: center; gap: .25rem; margin-bottom: .35rem; }
.dp-title {
  flex: 1 1 auto; text-align: center; font-weight: 600; font-size: .85rem;
  text-transform: capitalize; /* month names are lowercase in the constant */
}
.dp-nav {
  flex: 0 0 auto; width: 26px; height: 26px; line-height: 1;
  font-size: 1.1rem; color: var(--ink-soft);
  background: transparent; border: 1px solid transparent; border-radius: 6px;
}
.dp-nav:hover { background: var(--surface-sunken); border-color: var(--line); }

/* Seven fixed columns so weekday headers line up with the days. */
.dp-week, .dp-days { display: grid; grid-template-columns: repeat(7, 1fr); }
.dp-week span {
  text-align: center; font-size: .68rem; font-weight: 600;
  color: var(--muted); padding: .2rem 0;
}
.dp-days { gap: 1px; }

.dp-day {
  height: 28px; padding: 0; font-size: .78rem;
  color: var(--ink); background: transparent;
  border: 1px solid transparent; border-radius: 6px;
}
.dp-day:hover { background: var(--accent-tint); }
/* Adjacent-month days stay clickable but faded. */
.dp-day.is-out { color: var(--muted); opacity: .55; }
/* Today is outlined, the selected day filled, so both show when they coincide. */
.dp-day.is-today { border-color: var(--line-strong); font-weight: 600; }
.dp-day.is-cur { border-color: var(--accent); }
.dp-day.is-sel, .dp-day.is-sel:hover {
  background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600;
}

.dp-foot {
  display: flex; justify-content: space-between;
  margin-top: .4rem; padding-top: .4rem; border-top: 1px solid var(--line);
}
.dp-link {
  font-size: .74rem; color: var(--accent-600);
  background: transparent; border: 0; padding: .1rem .2rem; border-radius: 4px;
}
.dp-link:hover { background: var(--accent-tint); text-decoration: underline; }
.table th.col-code, .table td.col-code {
  width: 124px; min-width: 124px; white-space: nowrap;
}

/* ---- Pagination area ----------------------------------------------------- */
#pager { color: var(--muted); font-size: .85rem; }
#pager .btn { min-width: 2.2rem; }

/* ---- Forms — page measures ----------------------------------------------- */
/* Reference controls: fixed 36px height, 15px text, 4px radius, label above in
   the static text colour (14px, 16px from 1024px). */
.form-label {
  color: var(--label);
  font-size: var(--fs-label-sm);
  font-weight: 400;
  line-height: normal;
  letter-spacing: 0;
  margin: .25em 0 .1em;
}
@media (min-width: 1024px) {
  .form-label { font-size: var(--fs-label); }
}

.form-control, .form-select {
  height: var(--h-input);
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background-color: var(--surface);
  color: var(--ink);
  font-size: var(--fs-field);
  /* Field text at weight 500 (not the reference's bold) keeps the value/label
     contrast without competing with the label. */
  font-weight: 500;
  line-height: calc(var(--h-input) - 2px);
  box-shadow: none;
  /* Not the reference's `transition: all .3s` — only what actually moves. */
  transition: background-color .15s ease, border-color .15s ease,
              color .15s ease, box-shadow .15s ease;
}
/* Bootstrap draws the caret near-black (--bs-form-select-bg-img); after the
   retheme that is the only true black left in the UI. Repaint it muted. */
.form-select {
  height: var(--h-select);
  line-height: calc(var(--h-select) - 2px);
  padding: 0 2rem 0 6px;
  background-position: right .55rem center;
  --bs-form-select-bg-img: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%236b7a86' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}
/* Selects stay at 36px (not the reference's 32px) so they align with inputs
   on mixed rows; set --h-select to 32px to match the reference. */

/* A fixed height is wrong for anything that is not a one-line control. */
textarea.form-control { height: auto; padding: 10px 6px; line-height: 1.75; }
.form-select[size], .form-select[multiple] { height: auto; padding: .3rem 6px; line-height: 1.5; }
.form-control[type="color"] { height: var(--h-input); padding: 3px; }
.form-control[type="file"] { height: auto; padding: .3rem 6px; line-height: 1.5; }

.form-control::placeholder { color: var(--placeholder); font-weight: 400; }

/* Focus: the reference's blue border, plus a ring (it used outline: 0). */
.form-control:focus, .form-select:focus {
  border-color: var(--label);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb),.18);
  outline: none;
}

/* Toolbar-size controls: the list filters, the picker's search box. With a
   fixed height on .form-control these MUST reset it or they inherit 36px. */
.form-control-sm, .form-select-sm {
  height: var(--h-input-sm);
  padding: 0 6px;
  font-size: var(--fs-field-dense);
  line-height: calc(var(--h-input-sm) - 2px);
  border-radius: var(--radius-sm);
}
.form-select-sm { padding-right: 1.75rem; background-position: right .45rem center; }
textarea.form-control-sm { height: auto; padding: 5px 6px; line-height: 1.5; }

/* An add-on must not stretch past the field it annotates. */
.input-group-text {
  height: var(--h-input); padding: 0 .55rem;
  display: inline-flex; align-items: center;
  border-color: var(--line); background: var(--canvas); color: var(--muted);
  font-size: var(--fs-field);
}

/* Read-only and disabled fields look recessed grey with no focus glow; .locked-input
   applies the same to fields unlocked by a "Modifier" action. */
.form-control[readonly],
.form-control:disabled,
.form-select:disabled,
.form-control.locked-input {
  background-color: var(--field-locked-bg);
  color: var(--ink-soft);
  border-color: var(--line);
  cursor: not-allowed;
}
/* A disabled <select> also loses its caret, which Bootstrap draws as a
   background image — repaint it in the muted grey so it reads as inert. */
.form-select:disabled {
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%236b7a86' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}
/* Read-only fields still take focus (they are tabbable and selectable), so the
   blue ring would otherwise suggest an edit is starting. */
.form-control[readonly]:focus,
.form-control.locked-input:focus {
  border-color: var(--line); box-shadow: none;
}
/* In line grids, locked cells are tinted rather than bordered. */
.grid-cell.form-control-sm[readonly],
.grid-cell.form-control-sm:disabled,
.grid-cell.form-select-sm:disabled {
  background-color: var(--field-locked-bg);
  border-color: transparent;
}
/* Add-ons sit flush against the field they annotate, so they darken with it. */
.input-group-text.lock-prefix,
.input-group > .form-control[readonly] ~ .input-group-text,
.input-group > .form-control:disabled ~ .input-group-text {
  background: var(--field-locked-bg); border-color: var(--field-locked-border);
  color: var(--muted);
}
.input-group-text.lock-prefix { padding: 0 .55rem; }
/* Checkboxes and radios have no [readonly] of their own — a locked one is
   :disabled — and Bootstrap only fades them, which reads as "loading". */
.form-check-input:disabled {
  background-color: var(--field-locked-bg);
  border-color: var(--line-strong); opacity: .75; cursor: not-allowed;
}
/* A locked *checked* box carries real information — "this was invoiced" — so it
   stays fully opaque and only loses its accent colour. */
.form-check-input:disabled:checked {
  background-color: var(--muted); border-color: var(--muted); opacity: 1;
}
.form-check-input:disabled ~ .form-check-label { color: var(--muted); cursor: not-allowed; }
.field-hint { font-size: .73rem; color: var(--muted); margin-top: .3rem; }
.field-hint.is-unlocked { color: var(--warn); font-weight: 500; }
/* Inline text action: a real <button> for semantics, rendered as plain text. */
.text-action {
  background: none; border: 0; padding: 0; margin-top: .3rem;
  font-size: .73rem; font-weight: 500; color: var(--accent);
  text-decoration: underline; text-underline-offset: 2px; cursor: pointer;
}
.text-action:hover { color: var(--accent-700); }
.text-action:focus-visible {
  outline: 2px solid rgba(var(--accent-rgb),.45); outline-offset: 2px; border-radius: 2px;
}
.form-check-input:checked { background-color: var(--accent); border-color: var(--accent); }
.form-check-input:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(var(--accent-rgb),.16);
}

/* ---- Forms — dialog measures --------------------------------------------- */
/* Dialog density (FormModal injects the same markup): 24px controls, 13px text, 12px labels.
   Excludes .grid-cell and toolbar .form-*-sm controls; .totals-rate is set explicitly. */
.modal-body .form-label {
  font-size: var(--fs-label-dense);
  font-weight: 400;
  margin: 3px 0 1px;
}
/* textarea excluded: this rule outranks the textarea one below and would pin it to one line. */
.modal-body .form-control:not(.grid-cell):not(.form-control-sm):not(textarea),
.modal-body .form-select:not(.grid-cell):not(.form-select-sm) {
  height: var(--h-input-dense);
  line-height: calc(var(--h-input-dense) - 2px);
  font-size: var(--fs-field-dense);
}
.modal-body .form-select:not(.grid-cell):not(.form-select-sm) {
  padding-right: 1.6rem;
  background-position: right .4rem center; background-size: 12px 9px;
}
.modal-body textarea.form-control:not(.grid-cell) {
  height: auto; padding: 6px; line-height: 16px; font-size: var(--fs-field-dense);
  /* At least two visible lines: 2 x 16px + 12px padding + 2px border. */
  min-height: 46px;
}
/* the totals rate rides with the grid it totals, not with the toolbar */
.modal-body .totals-rate.form-control-sm {
  height: var(--h-input-dense);
  line-height: calc(var(--h-input-dense) - 2px);
}
.modal-body .input-group-text {
  height: var(--h-input-dense); padding: 0 .45rem; font-size: var(--fs-field-dense);
}
.modal-body .form-check-input { width: 1rem; height: 1rem; margin-top: .2rem; }
.modal-body .form-check-label,
.modal-body .field-hint,
.modal-body .text-action { font-size: var(--fs-label-dense); }
/* .studio .input-group-btn > button — 24px, 12px gutters */
.modal-body .btn {
  height: var(--h-btn-dense); padding: 0 12px;
  font-size: var(--fs-field-dense); line-height: calc(var(--h-btn-dense) - 2px);
}
.modal-body .btn-sm { height: var(--h-btn-dense); padding: 0 10px; }
/* In dialogs, section titles keep 13px to stand out from labels; the rule tightens. */
.modal-body .pane-head { padding-bottom: .22rem; margin-bottom: .5rem; }
.modal-body .pane-head h2 { font-size: var(--fs-field-dense); }
.modal-body .statut-select {
  height: var(--h-btn-dense);
  line-height: calc(var(--h-btn-dense) - 2px);
  font-size: var(--fs-field-dense);
}

/* ---- Tabs (the reference's chip tabs) ------------------------------------ */
/* Reference chip tabs: pale blue raised chips on an accent-ruled strip; active is solid. */
.nav-tabs {
  border-bottom: 1px solid var(--accent);
  gap: 4px;
  margin: 2px 0 8px;
  padding: .2em .2em 0;
}
.nav-tabs .nav-link {
  padding: .5em 1em;
  border: 1px solid var(--accent-line);
  border-bottom-color: var(--accent);
  border-radius: 5px 5px 0 0;
  margin-bottom: -1px;
  color: var(--accent-700);
  background: var(--accent-tint);
  font-size: var(--fs-label-sm);
  font-weight: 400;
  transition: background-color .15s ease, color .15s ease, border-color .15s ease;
}
.nav-tabs .nav-link:hover { color: var(--accent-600); background: #eaf5ff; }
.nav-tabs .nav-link.active,
.nav-tabs .nav-link.active:hover {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
.nav-tabs .nav-link.active .tab-count { color: rgba(255,255,255,.85); }
.tab-content.border {
  border-color: var(--accent-line) !important;
  border-radius: 0 0 var(--radius) var(--radius);
  background: var(--surface);
}

/* ---- Buttons ------------------------------------------------------------- */
/* Buttons: 36px tall, 4px radius, soft shadow; inline-flex centres the label vertically. */
.btn {
  height: var(--h-btn);
  padding: 0 20px;
  font-size: var(--fs-btn);
  font-weight: 400;
  line-height: 17px;
  border-radius: var(--radius-sm);
  letter-spacing: 0;
  white-space: normal;
  display: inline-flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-btn);
  transition: background-color .15s ease, border-color .15s ease,
              box-shadow .15s ease, color .15s ease;
}
.btn-sm { height: var(--h-input-sm); padding: 0 12px; font-size: var(--fs-field-dense); }

.btn-primary {
  background: var(--accent); border-color: transparent; color: #fff;
}
/* Hover goes lighter, as in the reference; its red focus background is not reproduced. */
.btn-primary:hover { background: var(--accent-hover); border-color: transparent; color: #fff; }
.btn-primary:active { background: var(--accent-600); border-color: transparent; box-shadow: none; }

.btn-outline-secondary {
  color: var(--ink-soft); border-color: var(--line); background: var(--surface);
}
.btn-outline-secondary:hover {
  background: var(--canvas); color: var(--ink); border-color: var(--line-strong);
}
.btn-outline-primary { color: var(--accent-700); border-color: var(--accent); background: var(--surface); }
.btn-outline-primary:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-outline-danger { color: var(--bad); border-color: var(--bad-line); background: var(--surface); }
.btn-outline-danger:hover { background: var(--bad); border-color: var(--bad); color: #fff; }

/* Preserve typed line breaks in printed description cells. */
.cell-multiline { white-space: pre-line; }

/* ---- Line-item grid (grid.js) ------------------------------------------- */
.table.table-bordered { border-color: var(--line); }
.table.table-bordered > :not(caption) > * > * { border-color: var(--line); }
/* Selects get the same borderless treatment as the text cells — otherwise they
   are the only boxed thing in the grid and the row reads as misaligned. */
.grid-cell.form-control-sm,
.grid-cell.form-select-sm { border-color: transparent; background-color: transparent; }
/* Line-grid rows are inputs: trim cell padding so row height matches a table row. */
.grid-scroll > .table > thead > tr > th { padding: .3rem .5rem; }
.grid-scroll > .table > tbody > tr > td { padding: .12rem .2rem; }
/* ...but restore the .sortable chevron space the trimmed padding removed. */
.grid-scroll > .table > thead > tr > th.sortable { padding-right: 1.15rem; }
/* ...except on centred columns, where one-sided padding would offset the label. */
.grid-scroll > .table > thead > tr > th.sortable.text-center { padding-right: .5rem; }
.grid-cell.form-control-sm,
.grid-cell.form-select-sm {
  padding: 0 .35rem; min-height: 0;
  height: var(--h-grid-cell);
  line-height: calc(var(--h-grid-cell) - 2px);
  font-size: var(--fs-grid-cell);
  border-radius: 0;              /* a cell is not a chip */
}
/* Description cells are auto-growing textareas: the fixed height becomes a minimum
   (set inline by autoSizeGridArea); no resize handle or scrollbar. */
textarea.grid-cell.form-control-sm {
  height: auto;
  min-height: var(--h-grid-cell);
  line-height: 1.35;
  padding: .15rem .35rem;
  resize: none;
  overflow: hidden;
}
/* the caret is repositioned to match the tighter cell it now sits in */
.grid-cell.form-select-sm {
  padding-right: 1.5rem;
  background-position: right .4rem center; background-size: 11px 8px;
}
/* A locked cell is still focusable, so exclude it here — otherwise it would
   turn white on focus and undo the tint that marks it non-editable. */
.grid-cell.form-control-sm:focus:not([readonly]):not(:disabled),
.grid-cell.form-select-sm:focus:not(:disabled) {
  background-color: var(--surface); border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb),.14);
}
/* .btn now carries a fixed 36px, so the in-grid buttons restate their own —
   the reference's .gridbtn is 25x42, and "+ Ligne" is a toolbar-size control. */
.grid-del.btn,
.grid-copy.btn {
  height: 22px; width: 34px; min-width: 0; padding: 0;
  font-size: 1rem; line-height: 1; box-shadow: none;
}
.grid-copy.btn { margin-right: 4px; }
.grid-add.btn {
  height: var(--h-input-sm); padding: 0 14px;
  font-size: var(--fs-field-dense); margin-top: .25rem;
  /* .modal-body and .modal-body > form are flex columns; a bare button child
     would otherwise stretch the full width of the dialog. */
  align-self: flex-start;
}
/* The scroll box wraps only the table: "+ Ligne" stays put underneath it
   instead of riding away with the rows. */
.grid-scroll { margin-bottom: .5rem; border-radius: var(--radius-sm); }
.grid-scroll > .table { margin-bottom: 0; }
/* .grid-fixed: fixed (not max) height so content below doesn't move as rows are added;
   the fallback applies where no measured cap is set. */
.grid-scroll.grid-fixed {
  height: var(--grid-max-h, 320px);
  /* Keep the frame so empty space below the last row still reads as the grid. */
  border: 1px solid var(--line);
}

/* ---- Document form: header on top, items below ---------------------------- */
/* Document form is a column: header at natural height, item grid taking at least the
   bottom half; neither shrinks, the container scrolls. */
.doc-form { display: flex; flex-direction: column; min-height: 0; }
.doc-form > .doc-head { flex: 0 0 auto; }
/* Gap matches the header block spacing. On a page, half means 50vh; in a dialog,
   half the locked box (the next rule wins). */
.doc-form > .doc-pane { flex: 1 0 50vh; min-height: 260px; margin-top: .85rem; }
.modal-body .doc-form > .doc-pane { flex: 1 0 50%; }
.doc-pane { display: flex; flex-direction: column; min-height: 0; }
/* Bottom half: grid on the left, totals on the right; "+ Ligne" sits under the
   grid only, so the totals align with the grid's bottom edge. */
.doc-pane > .doc-body {
  --totals-col-w: calc(25% - 1.125rem);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(min-content, var(--totals-col-w));
  grid-template-rows: minmax(150px, 1fr) auto;
  column-gap: .75rem; row-gap: .5rem;
  flex: 1 1 auto; min-height: 0;
}
/* display: contents makes #items' scroll box and button direct grid cells. */
.doc-body > .doc-items { display: contents; }
/* The scroll box fills its row; the measured cap and bottom margin are dropped. */
.doc-items > .grid-scroll {
  grid-column: 1; grid-row: 1;
  min-height: 0; height: auto; max-height: none;
  margin-bottom: 0;
}
/* Grid items stretch; restore the "+ Ligne" button's natural width. */
.doc-items > .grid-add { grid-column: 1; grid-row: 2; justify-self: start; }
/* Totals column spans the first row, aligned to its bottom; width matches the header's
   col-xl-3 block (25% - 1.125rem), floored at min-content. */
.doc-body > .doc-side {
  grid-column: 2; grid-row: 1;
  display: flex; flex-direction: column; justify-content: flex-end;
  min-height: 0;
}
/* Narrower rate input in the totals column. */
.doc-side .totals-rate.form-control-sm { width: 76px; }
.doc-side > .doc-totals > .totals-table { width: 100%; }
/* The amount column takes only its content width. */
.doc-side .totals-table td:last-child { min-width: 0; }

/* Below xl the totals move back under the grid, right-aligned. */
@media (max-width: 1199.98px) {
  .doc-pane > .doc-body { display: flex; flex-direction: column; gap: .5rem; }
  .doc-items > .grid-scroll { flex: 1 1 auto; }
  .doc-items > .grid-add { align-self: flex-start; }
  .doc-body > .doc-side { align-items: flex-end; }
  .doc-side > .doc-totals > .totals-table { width: auto; }
  /* Restore the amount column's padding at natural width. */
  .doc-side .totals-table td:last-child { min-width: 104px; }
}

/* Standalone page: .doc-page stretches the form to the viewport and scrolls when too short. */
.doc-page { display: flex; flex-direction: column; min-height: 0; overflow-y: auto; }
.doc-page > .doc-form { flex: 1 0 auto; }

/* ---- Document totals ----------------------------------------------------- */
/* The tax rate is entered on its tax line, in a narrow middle column. */
.totals-table > tbody > tr > th,
.totals-table > tr > th { white-space: nowrap; font-weight: 600; }
.totals-rate.form-control-sm {
  width: 92px; padding: .18rem .4rem; min-height: 0; height: auto;
  font-size: .85rem; line-height: var(--row-line-h);
  font-variant-numeric: tabular-nums;
}

/* ---- Status pills -------------------------------------------------------- */
.pill {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .12rem .55rem; border-radius: 999px;
  font-size: .72rem; font-weight: 600; line-height: 1.5;
  border: 1px solid transparent;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-paid   { color: var(--ok);   background: var(--ok-tint);   border-color: var(--ok-line); }
.pill-unpaid { color: var(--warn); background: var(--warn-tint); border-color: var(--warn-line); }
.pill-off    { color: var(--muted);background: var(--canvas);     border-color: var(--line); }
.pill-open   { color: var(--ok);   background: var(--ok-tint);   border-color: var(--ok-line); }
.pill-closed { color: var(--bad);  background: var(--bad-tint);  border-color: var(--bad-line); }

/* ---- Open / closed selector ---------------------------------------------
   Alone at the action bar's left, sized like the buttons, in the status pill colours. */
.statut-switch { display: flex; align-items: center; gap: .45rem; }
.statut-switch > .form-label {
  margin: 0; font-size: var(--fs-label-dense); color: var(--label); white-space: nowrap;
}
.statut-select {
  width: auto; min-width: 8.5rem;
  font-weight: 500; letter-spacing: .1px;
  border-radius: var(--radius-sm);
  transition: background-color .12s ease, border-color .12s ease, color .12s ease;
}
/* The two states: pill ink on a light tint, caret included. */
.statut-select.is-open {
  color: var(--ok); background-color: var(--ok-tint); border-color: var(--ok-line);
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%233c763d' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}
.statut-select.is-closed {
  color: var(--bad); background-color: var(--bad-tint); border-color: var(--bad-line);
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23a94442' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}
.statut-select.is-open:focus   { border-color: var(--ok);  box-shadow: 0 0 0 .2rem rgba(var(--ok-rgb), .18); }
.statut-select.is-closed:focus { border-color: var(--bad); box-shadow: 0 0 0 .2rem rgba(var(--bad-rgb), .18); }
/* Reset <option> colours to text ink in the native dropdown. */
.statut-select > option { color: var(--ink); background: var(--surface); }

/* ---- Alerts / toasts ----------------------------------------------------- */
.alert { border-radius: var(--radius); border: 1px solid transparent; font-size: .9rem; }
.alert-danger { background: var(--bad-tint); border-color: var(--bad-line); color: var(--bad); }
.alert-success{ background: var(--ok-tint);  border-color: var(--ok-line);  color: var(--ok); }
.alert-info   { background: var(--info-tint);border-color: var(--info-line);color: var(--info); }
#toasts .alert { box-shadow: var(--shadow-lg); margin-bottom: .6rem; }

/* ---- Focus visible (accessibility) -------------------------------------- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px; border-radius: 3px;
}
.form-control:focus-visible, .form-select:focus-visible,
.nav-link:focus-visible, .btn:focus-visible { outline: none; }

/* ---- Login (the signature moment) --------------------------------------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 2rem;
  /* The graph-paper blueprint was the old identity. The reference sets its
     login panel on the same flat canvas as every other screen. */
  background: var(--canvas);
}
.login-card {
  width: 380px; max-width: 92vw; border: 1px solid var(--line-card);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); overflow: hidden;
}
/* the signature band, as the card's own title bar */
.login-card::before {
  content: ""; display: block; height: 34px;
  background: linear-gradient(to bottom, var(--band-top) 0%, var(--band-bottom) 100%);
}
.login-badge {
  width: 56px; height: 56px; border-radius: var(--radius); margin: 0 auto .9rem;
  background-image: url("/img/logo.svg"); background-size: cover;
  box-shadow: var(--shadow);
}
.login-title { font-weight: 600; color: var(--ink); font-size: var(--fs-page-title); }
.login-sub { color: var(--muted); font-size: var(--fs-meta); }

/* ---- Sidebar fold: manual rail, automatic drawer ------------------------- */
/* The topbar toggle folds the sidebar: from 992px into a remembered icon rail, below
   into an off-canvas drawer; js/app.js injects the toggle and backdrop. */
.side-backdrop { display: none; }

.side-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; flex: 0 0 38px; margin-left: -.35rem;
  padding: 0; border: 1px solid transparent; border-radius: var(--radius-sm);
  background: transparent; color: var(--ink-soft);
  transition: background .12s ease, color .12s ease;
}
.side-toggle:hover { background: var(--surface-sunken); color: var(--ink); }
.side-toggle:focus-visible { border-color: var(--accent); color: var(--ink); }
.side-toggle svg { width: 20px; height: 20px; }

/* Set by js/app.js while the drawer is open; a class so modal.js overflow
   save/restore can't clobber it. */
body.side-locked { overflow: hidden; }

/* -- Manual fold: the docked panel shrinks to a rail ------------------------ */
/* Only above the breakpoint; below it the panel is a drawer. */
@media (min-width: 992px) {
  .app-side { transition: width .18s ease; }
  .app-shell.side-rail .app-side {
    width: var(--side-w-rail); flex: 0 0 var(--side-w-rail);
  }
  /* Folded: monogram only, icons instead of labels (js/app.js adds tooltips). */
  .app-shell.side-rail .app-side .brand {
    justify-content: center; padding-left: 0; padding-right: 0;
  }
  .app-shell.side-rail .brand-word { display: none; }
  .app-shell.side-rail .nav-group-title { display: none; }
  /* Without group titles, a rule keeps the groups apart. */
  .app-shell.side-rail .nav-group + .nav-group {
    border-top: 1px solid rgba(255,255,255,.14);
    margin-top: .35rem; padding-top: .45rem;
  }
  .app-shell.side-rail .app-side .nav-link {
    justify-content: center; padding-left: 0; padding-right: 0;
    /* No left border so icons stay centred; the accent fill marks the active page. */
    border-left-width: 0;
  }
  .app-shell.side-rail .app-side .nav-link > span { display: none; }
}

/* -- Automatic fold: the panel becomes a drawer ----------------------------- */
@media (max-width: 991.98px) {
  .app-side {
    position: fixed; top: 0; bottom: 0; left: 0;
    width: min(86vw, 300px); flex-basis: auto; height: auto; min-height: 0;
    z-index: 1045;              /* over the sticky topbar (20), under a modal (1055) */
    transform: translateX(-100%);
    transition: transform .18s ease;
    box-shadow: 0 0 0 1px rgba(0,0,0,.04);
  }
  .app-shell.side-open .app-side {
    transform: none; box-shadow: 0 12px 32px rgba(2, 2, 2, .34);
  }

  .side-backdrop {
    display: block; position: fixed; inset: 0; z-index: 1040;
    background: rgba(2, 2, 2, .44);
    opacity: 0; pointer-events: none; transition: opacity .18s ease;
  }
  .app-shell.side-open .side-backdrop { opacity: 1; pointer-events: auto; }

  .app-content { padding: 1.1rem; }
  .app-topbar  { padding: .6rem 1.1rem; }
}

/* A phone is not the target, but the same rules should not fall apart on one. */
@media (max-width: 575.98px) {
  .app-content { padding: .85rem; }
  .app-topbar  { padding: .55rem .85rem; }
}

/* ---- Reduced motion ------------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  html { scroll-behavior: auto; }
}

/* ---- Dialog chrome ------------------------------------------------------- */
/* Dialogs: the reference .studio .panel with a left-aligned gradient title band; padding
   goes through --bs-modal-header-padding-* so .btn-close stays inside the band. */
.modal {
  --bs-modal-bg: var(--surface);
  --bs-modal-color: var(--ink);
  --bs-modal-border-color: var(--line-card);
  --bs-modal-border-radius: var(--radius);
  --bs-modal-inner-border-radius: var(--radius);
  --bs-modal-box-shadow: var(--shadow-lg);
  --bs-modal-padding: .75rem 15px;
  --bs-modal-header-padding: 6px 15px;
  --bs-modal-header-padding-y: 6px;
  --bs-modal-header-padding-x: 15px;
  --bs-modal-header-border-color: transparent;
  --bs-modal-header-border-width: 0;
  --bs-modal-title-line-height: 1.3;
}
.modal-content {
  background: var(--surface);
  border: 1px solid var(--line-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.modal-header {
  background: linear-gradient(to bottom, var(--band-top) 0%, var(--band-bottom) 100%);
  border-top-left-radius: inherit;
  border-top-right-radius: inherit;
}
.modal-header .modal-title {
  margin: 0;
  color: var(--label);
  font-size: var(--fs-dialog-title);
  font-weight: 600;
  letter-spacing: 0;
  /* Reserve two title lines so the dialog doesn't jump when setTitle() lengthens it. */
  display: flex;
  align-items: center;
  min-height: calc(2em * var(--bs-modal-title-line-height));
}
/* No footer, so the close button stays, on a light chip readable against the gradient. */
.modal-header .btn-close {
  --bs-btn-close-opacity: 1;
  --bs-btn-close-hover-opacity: 1;
  --bs-btn-close-focus-opacity: 1;
  --bs-btn-close-bg: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='%235c666f'%3e%3cpath d='M.293.293a1 1 0 0 1 1.414 0L8 6.586 14.293.293a1 1 0 1 1 1.414 1.414L9.414 8l6.293 6.293a1 1 0 0 1-1.414 1.414L8 9.414l-6.293 6.293a1 1 0 0 1-1.414-1.414L6.586 8 .293 1.707a1 1 0 0 1 0-1.414z'/%3e%3c/svg%3e");
  --bs-btn-close-color: var(--band-ink);
  font-size: .75rem;
  border-radius: var(--radius-sm);
  transition: background-color .15s ease;
}
.modal-header .btn-close:hover { background-color: rgba(2,2,2,.07); }
.modal-header .btn-close:focus-visible {
  outline: 2px solid var(--label); outline-offset: 1px;
}

/* ---- Form modals --------------------------------------------------------- */
/* Actions sit bottom-right; the open/closed selector is pushed left by .spacer. */
.form-actions { flex-wrap: wrap; justify-content: flex-end; }

/* Tabbed forms get a locked height so switching tabs never resizes the dialog
   (class set by js/modal.js). */
.modal-fixed-h > .modal-content { height: 100%; }

/* Stretch the injected fragment's wrappers into a flex column so the action row
   lands at the bottom of a locked-height dialog. */
.modal-body {
  display: flex; flex-direction: column;
  padding-bottom: .75rem;
}
.modal-body > form,
.modal-body > .tab-content,
.modal-body > form > .tab-content,
.modal-body .tab-content > .tab-pane.active,
.modal-body .tab-pane.active > form {
  display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto;
}

/* Pin the action row to the bottom of scrolling dialog bodies (modal only). */
.modal-body .form-actions {
  position: sticky;
  bottom: 0;
  z-index: 2;
  padding: .75rem 0 0;
  background: var(--surface);
  border-top: 1px solid var(--line);
}

/* quotations keeps its action row inside a tab pane: an auto margin pushes it
   down and a negative margin covers the pane's padding. */
.modal-body .tab-content > .tab-pane > form > .form-actions {
  margin-top: auto !important;
  margin-bottom: -1rem; /* = .tab-content .p-3 */
}

/* Keep the fragment's own top spacing from doubling up with the modal padding. */
.modal-body > .alert:first-child { margin-top: 0; }

/* ---- Combobox (bindCombo in js/api.js) ------------------------------------ */
/* Search field over a hidden <select>; the list opens below at field width and scrolls. */
.combo { position: relative; }
.combo-input { cursor: text; }
/* The list is a popup like .dp-pop: same edge, shadow and accent-tint highlight,
   with field-sized text instead of Bootstrap's stock dropdown blue. */
.combo-menu {
  --bs-dropdown-min-width: 0;
  --bs-dropdown-padding-y: .25rem;
  --bs-dropdown-font-size: var(--fs-field);
  --bs-dropdown-color: var(--ink);
  --bs-dropdown-bg: var(--surface);
  --bs-dropdown-border-color: var(--line-strong);
  --bs-dropdown-border-radius: var(--radius-sm);
  --bs-dropdown-box-shadow: var(--shadow-lg);
  --bs-dropdown-item-padding-x: 6px;
  --bs-dropdown-item-padding-y: .3rem;
  --bs-dropdown-link-color: var(--ink);
  --bs-dropdown-link-hover-color: var(--ink);
  --bs-dropdown-link-hover-bg: var(--row-hover);
  --bs-dropdown-link-active-color: var(--accent-700);
  --bs-dropdown-link-active-bg: var(--accent-tint);
  width: 100%;
  max-height: 16rem;
  overflow-y: auto;
  top: 100%;
  left: 0;
  margin-top: 2px;
  box-shadow: var(--bs-dropdown-box-shadow);
}
.combo-menu .dropdown-item { font-weight: 500; border-radius: 0; }
.combo-menu .dropdown-item-text { padding: .3rem 6px; font-size: var(--fs-meta); }
/* Open: the field keeps its focus ring and the caret flips. */
.combo-input[aria-expanded="true"] {
  --bs-form-select-bg-img: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23477eb8' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 11 6-6 6 6'/%3e%3c/svg%3e");
}
/* Dialog density: 13px items to match the 24px dense fields. */
.modal-body .combo-menu {
  --bs-dropdown-font-size: var(--fs-field-dense);
  --bs-dropdown-item-padding-y: .2rem;
}

/* ---- Entity picker (pickEntity in js/modal.js) --------------------------- */
/* Fixed-height picker rows so typing never resizes the dialog; not .table-responsive,
   which fitStickyGrids() would resize. */
.pick-scroll { height: 55vh; flex: 0 0 auto; overflow: auto; }
/* Below the shell breakpoint the box goes elastic so the modal fits a tablet. */
@media (max-width: 991.98px) {
  .pick-scroll { height: auto; max-height: 45vh; flex: 1 1 auto; min-height: 0; }
}
/* Two stacked boxes in one dialog (pickPoLines): each takes half the height. */
.pick-scroll.pick-scroll-half { height: 27vh; }
@media (max-width: 991.98px) {
  .pick-scroll.pick-scroll-half { height: auto; max-height: 24vh; }
}

/* Pin the row delete button to the right edge of wide line grids. */
.grid-scroll > .table > thead > tr > th.grid-del-col,
.grid-scroll > .table > tbody > tr > td.grid-del-col {
  position: sticky; right: 0;
  background: var(--surface);
  border-left: 1px solid var(--line);
}
.grid-scroll > .table > thead > tr > th.grid-del-col {
  background: var(--surface-sunken); z-index: 4;
}

/* ---- Party buttons (purchase order form) --------------------------------- */
/* The button that picked the party stays lit (green client, blue supplier),
   since the kind is otherwise invisible. */
.btn-party.is-party-client,
.btn-party.is-party-client:hover,
.btn-party.is-party-client:focus {
  background: var(--ok); border-color: var(--ok); color: #fff;
  box-shadow: 0 1px 2px rgba(var(--ok-rgb), .30);
}
.btn-party.is-party-fournisseur,
.btn-party.is-party-fournisseur:hover,
.btn-party.is-party-fournisseur:focus {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: 0 1px 2px rgba(var(--accent-rgb), .30);
}
/* PO "Reçu" toggle (_RECU suffix): solid green when on, meaning goods arrived. */
.btn-recu.is-recu,
.btn-recu.is-recu:hover,
.btn-recu.is-recu:focus {
  background: var(--ok); border-color: var(--ok); color: #fff;
  box-shadow: 0 1px 2px rgba(var(--ok-rgb), .30);
}

/* ---- Print --------------------------------------------------------------- */
@media print {
  .app-side, .app-topbar, .table-toolbar, .no-print,
  .side-toggle, .side-backdrop { display: none !important; }
  .app-content { padding: 0; }
  body { background: #fff; }
  .table > thead > tr > th {
    position: static;
    border-bottom: 1px solid var(--line-strong); box-shadow: none;
  }
  /* Hide the sort chevron in print; the sorted order still prints. */
  .table > thead > tr > th.sortable::after { display: none; }
  /* Unclip the scroll boxes: on paper every row has to print, and the header
     repeats per page on its own. */
  .table-responsive, .grid-scroll { overflow: visible; max-height: none; }
  .table > thead { display: table-header-group; }
}

/* Multi-line notes keep the newlines typed in their textarea. */
.pre-wrap { white-space: pre-wrap; }
