/* ==========================================================================
   pmneX · design tokens (final; the values of the chosen look)
   Every colour, space, radius, shadow and font value lives here as a CSS
   custom property. Every name says what the value is FOR (bg, surface, ink,
   line, accent …), never what the look is called, so another look is another
   set of values on the same names. SPEC.md lists each token once with its
   purpose, its light value and its dark value.

   Light is the default, whatever the system setting (owner, 3 Dec). Dark redefines
   the SAME role names under :root[data-mode="dark"], set only by the theme switch.
   The grey ramp is FIXED: it is never redefined in dark, so the app's existing
   dark:*-gray-* utilities keep meaning what they say.
   Font (Google Fonts): Archivo, variable wdth + wght, one family.
   ========================================================================== */

:root {
  color-scheme: light;

  /* ---- Font (one family: Archivo, Google Fonts, variable wdth + wght) -- */
  --font-sans: "Archivo", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-num: var(--font-sans);           /* same family, tabular figures */
  --num-features: "tnum" 1, "lnum" 1;

  /* ---- Type scale (size / line-height / weight) ----------------------
     Bold is rationed: page titles, grand totals and the active hub only.
     Everything else is regular or medium, so the wordmark is never outweighed. */
  --fs-display: 36px;  --lh-display: 42px;  --fw-display: 700;   /* grand totals      */
  --fs-h1: 28px;       --lh-h1: 34px;       --fw-h1: 650;        /* page title        */
  --fs-h2: 18px;       --lh-h2: 24px;       --fw-h2: 600;        /* section title     */
  --fs-h3: 16px;       --lh-h3: 22px;       --fw-h3: 600;        /* hub tab, group    */
  --fs-body: 15px;     --lh-body: 22px;                          /* forms, lists      */
  --fs-grid: 14px;     --lh-grid: 20px;                          /* grid cells        */
  --fs-sm: 13px;       --lh-sm: 18px;                            /* meta, labels      */
  --fs-xs: 12px;       --lh-xs: 16px;                            /* tags, captions    */
  --fw-regular: 400; --fw-medium: 500; --fw-semibold: 600; --fw-bold: 700;
  --tracking-tight: -0.015em;
  --tracking-caps: 0.06em;

  /* ---- Space (4 px base) --------------------------------------------- */
  --s-0: 0; --s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px;
  --s-6: 24px; --s-7: 32px; --s-8: 40px; --s-9: 48px; --s-10: 64px;
  --gutter: 24px;               /* page side padding, desktop */
  --gutter-mobile: 16px;

  /* ---- Sizes / targets ----------------------------------------------- */
  --topbar-h: 64px;             /* the hub bar                            */
  --subbar-h: 48px;             /* the section-pill row                   */
  --control-h: 36px;            /* desktop buttons, toolbar search (>= 32 px) */
  --control-h-sm: 32px;         /* row actions, pills, chips              */
  --control-h-touch: 44px;      /* phone minimum                          */
  --field-h: 40px;              /* a form field (typed, AUTO well, select) */
  --tabbar-h: 62px;             /* phone hub tab bar, without the inset   */
  --tabbar-inset: 18px;         /* room under it for the home indicator: max(18px, env(safe-area-inset-bottom)) */

  /* ---- Radius -------------------------------------------------------- */
  --r-xs: 4px; --r-sm: 6px; --r-md: 8px; --r-lg: 12px; --r-xl: 16px; --r-pill: 999px;

  /* ---- Grey ramp (warm). FIXED in both themes: stands in for Tailwind
          gray / slate / zinc; only the role tokens below change in dark --- */
  --gray-0:   #FFFFFF;
  --gray-25:  #FBFAF7;
  --gray-50:  #F4F1EB;
  --gray-100: #EDE9E1;
  --gray-150: #E6E1D7;
  --gray-200: #DED8CC;
  --gray-300: #CBC3B5;
  --gray-400: #9C9384;
  --gray-500: #6E665A;
  --gray-600: #575046;
  --gray-700: #433D35;
  --gray-800: #2E2A25;
  --gray-900: #1D1A16;
  --gray-950: #12110F;

  /* ---- Brand (mark only) --------------------------------------------- */
  --brand-blue: #00A1FF;        /* the X of the wordmark, nothing else */
  --brand-ink:  #040720;        /* print / marketing near-black */

  /* ---- Colour roles: surfaces ---------------------------------------
     White is where you work (grids, forms). The canvas is where you look (home). */
  --bg:           var(--gray-50);    /* app canvas, overview pages         */
  --surface:      var(--gray-0);     /* bars, grids, forms                 */
  --surface-alt:  var(--gray-25);    /* total row, panel footers           */
  --sunken:       #F1EDE6;           /* AUTO wells on forms (never in grids) */
  --field:        var(--gray-0);     /* typed grid cell (lifted in dark)   */
  --hover:        #EFEBE4;
  --pill-on:      var(--gray-150);   /* active section pill                */
  --line:         #E4DED4;
  --line-strong:  var(--gray-300);   /* input borders, rules that matter   */
  --write-line:   #8F8678;           /* the line a typed value sits on; the edge of an empty checkbox.
                                        3.6:1 on surface, 3.2:1 on bg, 3.0:1 on hover */
  --track:        var(--gray-200);   /* empty part of bars and timelines   */

  /* ---- Colour roles: text ------------------------------------------- */
  --ink:   var(--gray-900);   /* 17.3:1 on surface */
  --ink-2: var(--gray-600);   /*  8.0:1 on surface, 7.1:1 on bg */
  --ink-3: var(--gray-500);   /*  5.7:1 on surface, 5.0:1 on bg, 4.8:1 on hover. Not on pill-on (4.3:1) */
  --ink-inverse: #FFFFFF;

  /* ---- Colour roles: the ONE accent --------------------------------- */
  --accent:        #047857;   /* emerald: primary button, active hub, selection. On-accent text 5.5:1 */
  --accent-hover:  #065F46;
  --accent-ink:    #065F46;   /* accent text on accent-soft, 6.8:1 */
  --accent-soft:   #E6F4EE;
  --accent-line:   #8FD0B4;
  --on-accent:     #FFFFFF;
  --focus:         #0E8F65;   /* the keyboard focus ring, 4.1:1 on surface */
  --focus-ring:    0 0 0 2px var(--surface), 0 0 0 4px var(--focus);
  --scrim:         rgba(20, 18, 15, 0.72);  /* caption over photos, behind a dialog; both themes */
  --on-scrim:      #FFFFFF;

  /* ---- Semantic (status only, never decoration) --------------------- */
  --pos:       #2B6B3B;  --pos-soft:  #E5F1E7;
  --warn:      #7A5500;  --warn-soft: #FAF0D4;  --warn-line: #E9D294;  /* ochre, not orange */
  --neg:       #B0261C;  --neg-soft:  #FBE8E5;
  --info:      var(--ink-2);

  /* ---- Data (one hue in three strengths) ---------------------------- */
  --data-1: #047857;             /* paid                 */
  --data-2: #8CC6DA;             /* committed, not paid  */
  --data-3: var(--track);        /* uncommitted          */

  /* ---- Elevation (flat by default; shadow only for things that float) */
  --e-0: none;
  --e-1: 0 1px 2px rgba(41, 33, 22, 0.06);
  --e-2: 0 10px 28px -6px rgba(41, 33, 22, 0.18), 0 2px 6px rgba(41, 33, 22, 0.06);
  --e-3: 0 18px 48px -8px rgba(41, 33, 22, 0.24), 0 4px 10px rgba(41, 33, 22, 0.08);

  /* ---- Motion -------------------------------------------------------- */
  --ease: cubic-bezier(.2, .7, .2, 1);
  --dur-fast: 120ms; --dur: 200ms;
}

/* Dark, chosen with the theme switch */
:root[data-mode="dark"] {
    color-scheme: dark;

    --bg:           #171614;               /* app canvas                           */
    --surface:      #272521;               /* panels, bars, grid                   */
    --surface-alt:  #2C2925;               /* total row, panel footers             */
    --sunken:       #141311;               /* AUTO wells: 1.21:1 below surface     */
    --field:        #312E29;               /* typed grid cells sit LIFTED in dark  */
    --hover:        #322F2A;
    --pill-on:      #3A3631;
    --line:         #36322D;
    --line-strong:  #4D473F;
    --write-line:   #8A8174;               /* 3.99:1 on surface, 3.52:1 on field   */
    --track:        #48433C;               /* empty part of bars                   */

    --ink:   #F2EEE7;   /* 13.2:1 on surface */
    --ink-2: #C3BBAE;   /*  8.0:1 */
    --ink-3: #A49B8D;   /*  5.6:1 on surface, 4.9:1 on hover and field */
    --ink-inverse: #12110F;

    --accent:        #34D399;   /* 9.4:1 on surface */
    --accent-hover:  #6EE7B7;
    --accent-ink:    #A7F3D0;   /* 11.1:1 on accent-soft */
    --accent-soft:   #0F3026;
    --accent-line:   #1F6049;
    --on-accent:     #022C1E;   /* 7.9:1 on accent: the filled button is light with a DARK label */
    --focus:         #34D399;

    --pos:  #85CF96;  --pos-soft:  #1A2E1F;
    --warn: #E4BC63;  --warn-soft: #33290F;  --warn-line: #66511E;
    --neg:  #F28F84;  --neg-soft:  #3A1C18;

    --data-1: #45BFDF;
    --data-2: #2A6F84;
    --data-3: var(--track);

    --e-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --e-2: 0 12px 32px -6px rgba(0, 0, 0, 0.6), 0 2px 6px rgba(0, 0, 0, 0.4);
    --e-3: 0 20px 52px -8px rgba(0, 0, 0, 0.7), 0 4px 10px rgba(0, 0, 0, 0.45);
}

/* ==========================================================================
   AG Grid 32 Enterprise · legacy theme · .ag-theme-quartz variable sheet
   (no v33 Theming API). Every --ag-* name below exists in
   @ag-grid-community/styles 32.3.9 (ag-grid.css + ag-theme-quartz.css).
   Density matches today's app: 4 px grid size, 36 px rows. The values point
   at the role tokens above, so dark mode needs no second sheet.
   ========================================================================== */
.ag-theme-quartz {
  --ag-font-family: var(--font-sans);
  --ag-font-size: var(--fs-grid);
  --ag-grid-size: 4px;
  --ag-row-height: 36px;
  --ag-header-height: 48px;               /* two fixed lines: kicker (Σ / ✎ / planned) + one-line label */
  --ag-list-item-height: 32px;
  --ag-cell-horizontal-padding: 10px;              /* as drawn: figures and headers sit 10 px from the column edge */
  --ag-cell-widget-spacing: 8px;
  --ag-row-group-indent-size: 20px;
  --ag-icon-size: 16px;
  --ag-border-radius: var(--r-md);
  --ag-wrapper-border-radius: var(--r-lg);
  --ag-card-radius: var(--r-md);

  --ag-foreground-color: var(--ink);
  --ag-data-color: var(--ink);
  --ag-secondary-foreground-color: var(--ink-3);
  --ag-disabled-foreground-color: var(--ink-3);
  --ag-background-color: var(--surface);
  --ag-odd-row-background-color: var(--surface);      /* no zebra: lines do the work */
  --ag-header-background-color: var(--surface);       /* header untinted */
  --ag-header-foreground-color: var(--ink-2);
  --ag-header-cell-hover-background-color: var(--hover);
  --ag-header-cell-moving-background-color: var(--hover);
  --ag-subheader-background-color: var(--surface-alt);
  --ag-control-panel-background-color: var(--surface);
  --ag-side-bar-panel-width: 232px;
  --ag-panel-background-color: var(--surface);
  --ag-menu-background-color: var(--surface);
  --ag-tooltip-background-color: var(--ink);
  --ag-popup-shadow: var(--e-2);
  --ag-card-shadow: var(--e-2);

  --ag-border-color: var(--line);
  --ag-secondary-border-color: var(--line);
  --ag-row-border-color: var(--line);
  --ag-row-border-width: 1px;
  --ag-header-column-separator-display: none;
  --ag-header-column-resize-handle-display: block;
  --ag-header-column-resize-handle-color: var(--line);
  --ag-header-column-resize-handle-height: 36%;

  --ag-row-hover-color: var(--hover);
  --ag-column-hover-color: transparent;
  --ag-selected-row-background-color: var(--accent-soft);
  --ag-range-selection-border-color: var(--accent);
  --ag-range-selection-background-color: color-mix(in srgb, var(--accent) 10%, transparent);
  --ag-active-color: var(--accent);
  --ag-input-focus-border-color: var(--accent);
  --ag-input-border-color: var(--line-strong);
  --ag-checkbox-checked-color: var(--accent);
  --ag-checkbox-unchecked-color: var(--write-line);   /* an empty box is seen by its edge: 3:1 */
  --ag-checkbox-background-color: var(--surface);
  --ag-chip-background-color: var(--hover);
  --ag-invalid-color: var(--neg);
  --ag-value-change-value-highlight-background-color: var(--accent-soft);
}
/* AG paints tooltip text with --ag-foreground-color; on an ink tooltip it must be inverse. */
.ag-theme-quartz .ag-tooltip { color: var(--ink-inverse); border-color: transparent; }

/* ---- Header: two fixed lines. A kicker (✎ typed / Σ calculated / PLANNED) over a
   one-line label at 88% width. The kicker is the KickerHeader component; these are
   its classes. A typed column's header also carries the write line along its top. */
.ag-theme-quartz .ag-header { border-bottom-color: var(--line-strong); }
.ag-theme-quartz .ag-header-cell-text { font-size: 12.5px; line-height: 16px; font-weight: 600; font-stretch: 88%; letter-spacing: .005em; }
.ag-theme-quartz .kicker-head { display: flex; flex-direction: column; justify-content: center; gap: 3px; width: 100%; min-width: 0; }
.ag-theme-quartz .ag-right-aligned-header .kicker-head { align-items: flex-end; text-align: right; }
.ag-theme-quartz .kicker { display: flex; align-items: center; gap: 5px; height: 14px; }
.ag-theme-quartz .kicker .pl { font-size: 10px; line-height: 14px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); border-bottom: 1px dashed var(--ink-3); }
.ag-theme-quartz .kicker svg { width: 12px; height: 12px; flex: none; color: var(--ink-3); stroke-width: 2.4; }
.ag-theme-quartz .h-write .ag-header-cell-text { color: var(--ink); }
.ag-theme-quartz .h-write .kicker svg { color: var(--ink-2); }
.ag-theme-quartz .h-write::after { content: ""; position: absolute; left: 10px; right: 10px; top: 0; height: 2px; border-radius: 0 0 1px 1px; background: var(--write-line); }

/* ---- Typed versus calculated: ONE cellClassRules entry, keyed on the flag every
   column already has (colDef.editable), so no column is annotated by hand and
   group and pinned rows follow automatically. Shared grid defaults:
     defaultColDef: {
       cellClassRules: {
         'cell-write': p => !p.node.group && !p.node.rowPinned &&
           (typeof p.colDef.editable === 'function' ? p.colDef.editable(p) : !!p.colDef.editable),
       },
     }
   A calculated cell gets NO class: plain ink on the surface is the default.
   A typed value sits on a WRITE LINE: the fill-in rule of the owner's
   notebook, drawn 6 px above the row line. In dark the cell is also lifted.
   The two value marks below are about the number, not about typed/calculated;
   they belong to the 'money' column type (AG Grid merges a type's rules with the default's):
     columnTypes: { money: { cellClass: 'cell-num', headerClass: 'ag-right-aligned-header', valueFormatter: money,
       cellClassRules: { 'cell-empty': p => p.value == null || p.value === 0,     // money() prints these as "–"
                         'cell-neg':   p => typeof p.value === 'number' && p.value < 0 } } }
     rowClassRules: { 'row-total': p => !!p.node.rowPinned }
     getRowHeight:  p => p.node.rowPinned ? 42 : undefined                       */
.ag-theme-quartz .cell-write { background-color: var(--field); color: var(--ink); }
.ag-theme-quartz .cell-write::after {
  content: ""; position: absolute; left: 10px; right: 10px; bottom: 6px; height: 2px;
  border-radius: 1px; background: var(--write-line); pointer-events: none;
}
.ag-theme-quartz .ag-cell-inline-editing.cell-write::after { display: none; }   /* the editor shows its own edge */
.ag-theme-quartz .cell-empty { color: var(--ink-3); }
.ag-theme-quartz .cell-num   { text-align: right; font-feature-settings: var(--num-features); font-variant-numeric: tabular-nums; }
.ag-theme-quartz .cell-neg   { color: var(--neg); }

/* ---- Hierarchy and totals -------------------------------------------------- */
.ag-theme-quartz .ag-row-group.ag-row-level-0 { font-weight: 600; }             /* level 1 */
.ag-theme-quartz .ag-row-group:not(.ag-row-level-0) { font-weight: 500; }       /* deeper parents; leaves stay 400 */
.ag-theme-quartz .ag-floating-bottom { border-top: 2px solid var(--line-strong); }
.ag-theme-quartz .row-total  { font-weight: 700; background: var(--surface-alt); }
.ag-theme-quartz .row-total .ag-cell { font-size: 14.5px; }
.ag-theme-quartz .row-total .cell-caption { font-size: 13px; font-weight: 400; color: var(--ink-3); }   /* "13 lines shown · EUR" */

/* ---- The trace line under a grid (GridTrace, our own component: the enterprise
   status-bar module is not installed). It sits under <AgGridReact> inside the
   themed frame, so the frame carries the border and AG's wrapper gives it up. */
.ag-theme-quartz.grid-frame { border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; background: var(--surface); }
.ag-theme-quartz.grid-frame .ag-root-wrapper { border: 0; border-radius: 0; }
.ag-theme-quartz .grid-trace { color: var(--ink-2); background: var(--surface-alt); }
