/* Tiphaine de Bodman — the design system.
 *
 * The palette is taken from the Birds Carpet, measured off the photograph
 * rather than guessed: the rug was sampled by hue, giving ink #22242B from the
 * border and the birds, sienna #A15018 from the large leaves, gold #BF943D
 * from the small ones, and a wool ground that reads #DCDBDC under the
 * photographer's light.
 *
 * Two of those are adjusted for screen and the reason is worth writing down.
 * A photograph of wool under warm light desaturates: the ground is warm cream
 * in the room and neutral grey in the file, and the gold leaves are brighter
 * than a camera records them. So `--paper` is warmed back to #F4F0E8 and the
 * gold lifted to #D9A33A. The ink and the sienna are used as measured.
 *
 * One brand, so one theme — but the mechanism that carried three for Naturabuy
 * is kept, because four apps are coming and a per-app accent is then a
 * one-line change rather than a second stylesheet.
 *
 * Public Sans is served from static/fonts as a @font-face rather than from a
 * CDN: these apps sit behind an authenticating ingress, and a webfont request
 * that leaves the network leaks which app an authenticated user is looking at.
 */

:root {
  /* The carpet. Measured, then tuned for screen — see the header. */
  --ink-deep:    #22242B;   /* border and birds   */
  --ink-mid:     #3A3D4C;
  --sienna:      #A15018;   /* the large leaves   */
  --sienna-mid:  #B3601F;
  /* FILL ONLY, never text: #D9A33A on the cream ground is 2.00:1, which fails
   * at any size. The gold THEME below uses #8A6318 instead (4.76:1, AA). */
  --gold:        #D9A33A;   /* the small leaves   */
  --cream:       #F4F0E8;   /* the wool ground    */
  --cream-deep:  #E7E0D3;

  /* Semantic colours are separate from the brand families on purpose: "this
   * failed" must not change meaning because an app switched theme. */
  --ok:    #1f7a4d;
  --warn:  #9a6b12;
  --bad:   #a03027;

  /* Chart series. A fixed order, assigned to an entity and never cycled, so a
   * filter that drops a series does not repaint the survivors.
   *
   * NOT the brand families. Those are three near-blacks and three pale tints —
   * right for chrome, indistinguishable as five adjacent series. These are
   * stepped to mid-lightness and validated rather than chosen by eye: every
   * adjacent pair clears the colour-vision-deficiency threshold (worst ΔE 9.3
   * protan) and the normal-vision floor (worst 19.0), at 3:1 against the
   * surface, in both light and dark. Changing one means re-running
   * scripts/validate_palette.js, not squinting at it.
   *
   * Distinct from --ok/--warn/--bad by construction: a status colour means a
   * state and must never also mean "the third app". */
  --series-1: #3a6fb5;   /* blue       */
  --series-2: #b8791a;   /* ochre      */
  --series-3: #0f8f74;   /* green      */
  --series-4: #8b4fb0;   /* violet     */
  --series-5: #a8543a;   /* terracotta */

  /* Spacing and radius, on a scale rather than ad hoc. */
  --s1: .25rem; --s2: .5rem; --s3: .75rem; --s4: 1rem;
  --s5: 1.5rem; --s6: 2rem; --s7: 3rem;
  --r:  10px; --r-sm: 6px; --r-pill: 999px;
}

/* The theme maps a family onto roles. Every component below reads the roles,
 * never a family directly — which is what makes a theme a one-line change. */
:root, [data-theme="studio"] {
  --deep: var(--ink-deep);   --mid: var(--ink-mid);
  --tint: var(--cream-deep);
  --paper: var(--cream);  --surface: #fffdf9;  --line: #e3dccd;
  --ink: var(--ink-deep);  --ink-soft: #6a6355;
  --accent: var(--sienna); --accent-ink: #fffdf9;
}
/* Per-app accents. The carpet has exactly two warm hues, so an app is sienna
 * or gold and never a colour the rug does not contain. */
[data-theme="gold"] {
  --deep: var(--ink-deep);   --mid: var(--ink-mid);
  --tint: var(--cream-deep);
  --paper: var(--cream);  --surface: #fffdf9;  --line: #e3dccd;
  --ink: var(--ink-deep);  --ink-soft: #6a6355;
  --accent: #8A6318;       --accent-ink: #fffdf9;
}

/* Dark: the deep brand colour becomes the ground and the light tint becomes the
 * ink, so the palette stays the brand's rather than becoming grey. Handles all
 * three viewer states — explicit light, explicit dark, and the default where
 * only prefers-color-scheme speaks. */
@media (prefers-color-scheme: dark) {
  :root:not([data-mode="light"]) {
    --paper: var(--deep);
    --surface: color-mix(in srgb, var(--deep) 88%, white);
    --line: color-mix(in srgb, var(--deep) 72%, white);
    --ink: #f4f2ee;
    --ink-soft: var(--tint);
    --accent: var(--tint);
    --accent-ink: var(--deep);
    /* Re-stepped for the dark surface, not flipped: the same hues, validated
     * again against it. */
    --series-1: #5f93d8;
    --series-2: #bd8629;
    --series-3: #1f9779;
    --series-4: #ad73d0;
    --series-5: #cc7259;
  }
}
[data-mode="dark"] {
  /* Re-stepped for the dark surface, not flipped: the same hues, validated
   * again against it. */
  --series-1: #5f93d8;
  --series-2: #bd8629;
  --series-3: #1f9779;
  --series-4: #ad73d0;
  --series-5: #cc7259;
  --paper: var(--deep);
  --surface: color-mix(in srgb, var(--deep) 88%, white);
  --line: color-mix(in srgb, var(--deep) 72%, white);
  --ink: #f4f2ee;
  --ink-soft: var(--tint);
  --accent: var(--tint);
  --accent-ink: var(--deep);
}

/* ── Type ─────────────────────────────────────────────────────────────────── */
@font-face {
  font-family: "Public Sans";
  /* The variable TTF straight from Google Fonts' OFL release, served from here
   * rather than from their CDN. It is ~100 KB and compresses again over the
   * wire; a woff2 would be smaller, so if you have woff2_compress to hand,
   * convert it and add the url() above this one. */
  src: url("/static/fonts/PublicSans-Variable.ttf") format("truetype-variations");
  font-weight: 100 900;
  font-display: swap;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Public Sans", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  font-size: 16px; line-height: 1.55;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3 { margin: 0 0 var(--s2); line-height: 1.2; letter-spacing: -.015em;
             font-weight: 620; text-wrap: balance; }
h1 { font-size: clamp(1.5rem, 3.2vw, 2rem); }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p  { margin: 0 0 var(--s4); max-width: 68ch; }
a  { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2px; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88em; }
.muted { color: var(--ink-soft); }
.small { font-size: .85rem; }
.eyebrow { font-size: .7rem; letter-spacing: .12em; text-transform: uppercase;
           color: var(--ink-soft); font-weight: 600; }

/* ── Chrome ───────────────────────────────────────────────────────────────── */
.topbar {
  background: var(--deep); color: #fff;
  padding: var(--s3) var(--s4);
  display: flex; align-items: center; gap: var(--s4); flex-wrap: wrap;
}
.topbar a { color: #fff; text-decoration: none; opacity: .82; font-size: .92rem; }
.topbar a:hover, .topbar a.on { opacity: 1; }
.topbar .brand { font-weight: 700; letter-spacing: -.01em; opacity: 1; }
.topbar .spacer { margin-left: auto; }
/* ── The menu ───────────────────────────────────────────────────────────────
 *
 * One bar. A section with sub-pages opens a dropdown rather than revealing a
 * second bar underneath, so the page never shifts down when you move into a
 * section — which is what the two-bar version did.
 *
 * No JavaScript. The dropdowns open on :hover and on :focus-within, so they work
 * with a keyboard; the small-screen drawer is a checkbox and its label, so it
 * works with neither JS nor hover. A menu that needs a script is a menu that is
 * missing when the script fails.
 */
.menu { position: relative; }
.menu > a { display: inline-flex; align-items: center; gap: .3rem; }
.menu > a::after {
  content: ""; width: .34em; height: .34em; margin-top: -.18em;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg); opacity: .65;
}
.menu-panel {
  /* Wider than the labels need and tighter than the page: a dropdown is read in
     one glance, so the lines want to be short and close together rather than
     spaced out like body text. min-width sets the shape, nowrap keeps the long
     labels ("Rapprochements", "Le squelette") on one line each. */
  position: absolute; top: 100%; left: 0; z-index: 30; min-width: 14rem;
  display: none; flex-direction: column; padding: var(--s1);
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  box-shadow: 0 6px 24px rgba(0, 0, 0, .14);
}
.menu-panel.right { left: auto; right: 0; }
.menu:hover > .menu-panel,
.menu:focus-within > .menu-panel { display: flex; }
.menu-panel a, .menu-panel button {
  /* `font: inherit` first, and only then the size. The shorthand resets
     font-size, so written after it — as it was — it silently cancelled it, and
     the panel never used the size it declared. */
  font: inherit; font-size: .82rem; line-height: 1.45;
  display: block; width: 100%; text-align: left; white-space: nowrap;
  padding: .28rem var(--s2); border-radius: var(--r-sm);
  color: var(--ink); text-decoration: none;
  background: none; border: 0; cursor: pointer; opacity: 1;
}
.menu-panel a:hover, .menu-panel button:hover {
  background: color-mix(in srgb, var(--ink) 8%, transparent);
}
.menu-panel a.on { font-weight: 600; }
.menu-panel a.on::before {
  content: ""; display: inline-block; width: 3px; height: .8em;
  background: var(--accent); border-radius: 2px;
  margin-right: .4rem; vertical-align: -.06em;
}
.menu-panel hr { border: 0; border-top: 1px solid var(--line);
                 margin: var(--s1) var(--s2); }
.menu-panel .who { padding: var(--s1) var(--s2);
                   font-size: .7rem; color: var(--ink-soft);
                   text-transform: uppercase; letter-spacing: .04em; }

/* The drawer. Hidden checkbox, visible label: no script, and the panel comes
 * from the left because that is the thumb that is free while the other holds the
 * phone. */
.drawer-toggle { position: absolute; opacity: 0; pointer-events: none; }
.drawer-open {
  display: none; align-items: center; justify-content: center;
  width: 40px; height: 40px; margin-left: -.4rem; border-radius: var(--r-sm);
  cursor: pointer; color: #fff;
}
.drawer-open:hover { background: rgba(255, 255, 255, .12); }
.drawer-open svg { width: 20px; height: 20px; }
.drawer-scrim { display: none; position: fixed; inset: 0; z-index: 40;
                background: rgba(0, 0, 0, .45); }
.drawer {
  display: none; position: fixed; top: 0; left: 0; bottom: 0; z-index: 41;
  width: min(19rem, 86vw); overflow-y: auto;
  padding: calc(var(--s4) + env(safe-area-inset-top, 0px)) var(--s4) var(--s5);
  background: var(--surface); border-right: 1px solid var(--line);
  box-shadow: 4px 0 24px rgba(0, 0, 0, .18);
}
.drawer .group { margin-bottom: var(--s4); }
.drawer .group > span { display: block; font-size: .7rem; letter-spacing: .12em;
                        text-transform: uppercase; color: var(--ink-soft);
                        font-weight: 700; margin-bottom: var(--s1); }
.drawer a, .drawer button {
  /* Body size on purpose here, unlike the dropdown: this one is touched, not
     scanned. (It declared .95rem and rendered 16px — `font: inherit` after
     `font-size` resets it — so the size below is the one it always had.) */
  font: inherit;
  display: block; width: 100%; text-align: left; padding: var(--s2) var(--s2);
  color: var(--ink); text-decoration: none;
  border-radius: var(--r-sm); background: none; border: 0;
  cursor: pointer;
}
.drawer a.sub { padding-left: var(--s5); font-size: .9rem; color: var(--ink-soft); }
.drawer a.on { font-weight: 650; background: color-mix(in srgb, var(--ink) 7%, transparent); }
.drawer-close { position: absolute; top: calc(var(--s3) + env(safe-area-inset-top, 0px));
                right: var(--s3); width: 36px; height: 36px; display: grid;
                place-items: center; border-radius: var(--r-sm); cursor: pointer;
                color: var(--ink-soft); font-size: 1.3rem; line-height: 1; }
#drawer:checked ~ .drawer-scrim,
#drawer:checked ~ .drawer { display: block; }

/* Below this width the bar keeps only the brand and the two controls, and
 * everything else moves into the drawer. */
@media (max-width: 860px) {
  .topbar .menu, .topbar > a.l1 { display: none; }
  .drawer-open { display: inline-flex; }
}
@media (min-width: 861px) {
  .drawer-scrim, .drawer { display: none !important; }
}

/* Every page's heading, from base.html. One format, so a page cannot invent its
 * own spacing above the first thing it has to say. */
.page { margin-bottom: var(--s5); }
.page h1 { font-size: clamp(1.5rem, 4vw, 2rem); font-weight: 750;
           letter-spacing: -.025em; margin: 0 0 var(--s2); }
.page .eyebrow { margin-bottom: .2rem; }
.page .lede { font-size: 1.02rem; color: var(--ink-soft); max-width: 62ch;
              margin: 0; }

.shell { max-width: 72rem; margin: 0 auto; padding: var(--s5) var(--s4) var(--s7); }
/* 72rem is a measure for reading, and it is the right default: prose past it is
 * hard to track from the end of one line to the start of the next. A wide table
 * is not read that way, it is scanned across, and inside a 72rem column it
 * scrolls sideways while the screen next to it sits empty. Such a page asks for
 * `shell wide` and gets the screen it is actually on. Reach for it only when the
 * content really is a wide table — on prose it is the wrong measure. */
.shell.wide { max-width: 100rem; }

/* ── Components ───────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r); padding: var(--s4);
}
.stack { display: flex; flex-direction: column; gap: var(--s3); }
.row   { display: flex; gap: var(--s3); align-items: center; flex-wrap: wrap; }
.grid  { display: grid; gap: var(--s3);
         grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 44px; padding: var(--s2) var(--s4);
  background: var(--accent); color: var(--accent-ink);
  border: 1px solid transparent; border-radius: var(--r-sm);
  font: inherit; font-weight: 600; font-size: .95rem;
  cursor: pointer; text-decoration: none;
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
/* On the top bar a ghost button is white on the brand's deep colour. Scoped to
 * .topbar (three classes) so it beats .btn.ghost (two) — the first version was a
 * single .topbar-btn class, which lost the cascade and left near-black text on a
 * near-black bar. It had worked only because the same declarations used to be
 * inline on the element, where nothing can outrank them. */
.topbar .btn.ghost {
  min-height: 32px; padding: 0 .6rem; font-size: .85rem;
  color: #fff; border-color: rgba(255, 255, 255, .35);
}
.topbar .btn.ghost:hover { background: rgba(255, 255, 255, .12); }
.btn.wide  { width: 100%; }
.btn[disabled] { opacity: .5; cursor: default; }

label { display: block; font-size: .85rem; color: var(--ink-soft);
        margin-bottom: var(--s1); font-weight: 500; }
input[type=text], input[type=email], input[type=password], input[type=number],
select, textarea {
  width: 100%; min-height: 44px; padding: var(--s2) var(--s3);
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  /* 16px so iOS does not zoom the page on focus. */
  font: inherit; font-size: 16px;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
/* The login code: wide, spaced, and big enough to read back while typing. */
/* The one-time code. The first version was 1.6rem with .35em of tracking and a
 * fixed padding, which on a 360px screen pushed six digits past the right edge —
 * the field was unusable on exactly the device most people read the mail on.
 * Both the size and the tracking scale with the viewport now, and the padding is
 * asymmetric because tracking is applied after the last character too and would
 * otherwise sit the text off-centre. */
.code-input {
  font-family: ui-monospace, Menlo, monospace;
  font-size: clamp(1.15rem, 7vw, 1.6rem);
  letter-spacing: clamp(.12em, 3vw, .3em);
  text-align: center;
  padding: var(--s3) var(--s2) var(--s3) calc(var(--s2) + .3em);
  min-height: 56px; width: 100%;
}

.pill { display: inline-block; font-size: .72rem; padding: .12rem .5rem;
        border-radius: var(--r-pill); border: 1px solid var(--line);
        color: var(--ink-soft); }
.pill.ok   { color: var(--ok);   border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.pill.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.pill.bad  { color: var(--bad);  border-color: color-mix(in srgb, var(--bad) 40%, transparent); }

.flash { padding: var(--s3) var(--s4); border-radius: var(--r-sm);
         border-left: 3px solid var(--accent); background: var(--surface);
         margin-bottom: var(--s3); font-size: .92rem; }
.flash.error { border-left-color: var(--bad); }
.flash.ok    { border-left-color: var(--ok); }

/* A stat tile: one number, its label, and nothing competing with it. Used where
 * a chart would be a worse answer than a figure. */
.stat { display: flex; flex-direction: column; gap: .15rem; }
.stat b { font-size: clamp(1.5rem, 4vw, 2rem); font-weight: 650; line-height: 1;
          letter-spacing: -.02em; }
.stat span { font-size: .78rem; color: var(--ink-soft); }
.stat.bad b  { color: var(--bad); }
.stat.warn b { color: var(--warn); }
.stat.ok b   { color: var(--ok); }

/* A meter. Thin, with the fill anchored to the start and rounded only at the
 * data end, so the bar's length is the only thing carrying the value. */
.bar { height: 6px; border-radius: var(--r-pill); background: var(--line);
       overflow: hidden; min-width: 3rem; }
.bar > i { display: block; height: 100%; background: var(--accent);
           border-radius: 0 var(--r-pill) var(--r-pill) 0; }
.bar > i.hot  { background: var(--warn); }
.bar > i.crit { background: var(--bad); }

/* A standing banner, not a flash: a flash says what just happened and goes away
 * on the next request; a banner says something true about the whole page. */
.banner { padding: var(--s2) var(--s4); display: flex; flex-wrap: wrap;
          gap: var(--s2); align-items: baseline; font-size: .88rem;
          border-radius: var(--r-sm); margin-bottom: var(--s3);
          background: color-mix(in srgb, var(--ink-soft) 10%, var(--surface));
          border: 1px solid var(--line); }
.banner.warn { background: color-mix(in srgb, var(--warn) 14%, var(--surface));
               border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.banner.bad  { background: color-mix(in srgb, var(--bad) 13%, var(--surface));
               border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
.banner.ok   { background: color-mix(in srgb, var(--ok) 12%, var(--surface));
               border-color: color-mix(in srgb, var(--ok) 40%, transparent); }

.scroller { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; font-size: .9rem; }
th, td { text-align: left; padding: var(--s2) var(--s3);
         border-bottom: 1px solid var(--line); }
th { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em;
     color: var(--ink-soft); font-weight: 600; }
td.num, th.num { text-align: right; }

/* The topographic pattern is part of the brand's graphic territory; used here
 * as a restrained texture on the sign-in panel only. */
/* min-height, not height: a keyboard opening on a phone shrinks the viewport and
 * a fixed height would scroll the card under it. */
.auth-wrap { min-height: 80svh; display: grid; place-items: center;
             padding: var(--s5) var(--s4); }
.auth-card { width: 100%; max-width: 25rem; }
@media (max-width: 420px) {
  .auth-wrap { padding: var(--s4) var(--s3); align-items: start; }
  .auth-card .card { padding: var(--s3); }
}
.auth-mark { height: 2.25rem; margin-bottom: var(--s4); color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
