﻿/* TOUCH PAGE CHROME — the one way a back-office page is hosted on a touch surface.

   The problem it solves. A touch head (the salon's /touch, the cafe's /cafe) shows shared
   back-office pages that were written for a desktop shell with an in-flow app bar. On the
   floor there is no app bar and no browser chrome: the only way out of the screen is a Back
   and Home cluster FIXED to the viewport's top-left corner, so it survives the scroll. That
   cluster lands exactly where the hosted page draws its title, and the two have to be made
   to read as one line rather than as two things that happened to land near each other.

   Every head hit this and every head answered it differently. MapleSPA solved it in
   TouchOfficeLayout.razor.css; MapleCoffee copied the answer into its own app.css and got
   the numbers wrong twice. This file is that answer, promoted, so there is one copy of it.

   HOW TO USE IT. Put `touch-page-chrome` on the element that also carries the fixed cluster,
   beside whatever class the head already uses for its own paint:

       <div class="app-theme touch-office touch-page-chrome">   (MapleSPA)
       <div class="cafe-editor-shell cafe-theme touch-page-chrome has-nav">   (MapleCoffee)

   Then link this sheet in the head's App.razor:

       <link rel="stylesheet" href="_content/SPC.Blazor/css/touch-page-chrome.css" />

   The hosted page needs no changes at all. It keeps form.css's ordinary .form-page /
   .form-page-header / .form-page-title markup, which is the whole point: the same page must
   render correctly under a desktop shell and under this one.

   WHAT THIS FILE OWNS: geometry. Where the title sits relative to the cluster, and how much
   room it reserves.
   WHAT THE HEAD OWNS: paint. Set --tph-ink and --tph-muted to the head's own tokens; the
   defaults fall through to the suite's --ink / --muted.

   FOUR KNOBS, all inherited, all optional:

     --tph-nav-w   How wide the fixed cluster is. Default 100px = 14px inset + 40 + 6 gap + 40,
                   which is Back and Home. One button: 54px. No cluster: 0px. Set it on the
                   shell, not on the header.
     --tph-gutter  How much room the hosted page's own layout ALREADY leaves before the
                   viewport's left edge. Defaulted below for a centred .form-page column; a
                   page with its own width restates it (see below).
     --tph-ink     The title's colour.
     --tph-muted   The subtitle's colour.

   These are the same names TouchPageHeader uses for the salon's native touch pages, and they
   mean the same things. That is deliberate. A page hosted in this chrome and a native touch
   page have to put their Back and Home in the same place, or the corner appears to move as
   the operator walks between them.

   WHY THE GUTTER IS SUBTRACTED RATHER THAN THE INDENT BEING FLAT. The cluster is fixed to the
   VIEWPORT; the padding below is measured from the page's CENTRED COLUMN. A flat indent is
   right only at one window width. On a wide monitor the column already starts hundreds of
   pixels right of the corner, so a flat indent pushed the title further right still, away
   from icons that were nowhere near it. Subtracting the gutter collapses the reserve to
   nothing exactly when the column has already cleared the corner, and brings it back by
   itself as the window narrows. */

/* A page rooted on <MudContainer> rather than .form-page has no title row to put beside the
   cluster, so there is nothing to indent. Push the whole container clear of it instead. */
.touch-page-chrome > .mud-container {
    padding-top: 64px;
}

/* form.css gives .form-page 4.25rem of top padding to clear a desktop app bar. There is no
   app bar here, and that clearance is exactly what pushes the title off the cluster's row.
   14px instead: the cluster's own top inset, so the two rows start together. */
.touch-page-chrome .form-page {
    padding-top: 14px;
    gap: 1rem;
    /* The default gutter, for a page that takes form.css's own centred column: half the
       overflow past the cap, plus the page's own 1rem of padding.

       The cap is a knob because it is NOT the same everywhere: form.css caps .form-page at
       1536px in the salon and the shop but at 1280px in the cafe. Hard-coding one of those
       over-indented every title in the other head on any window between the two numbers. A
       head states its own once, on the shell:
           .my-shell { --tph-page-max: 1280px; }

       A page that narrows the column just states its own cap the same way:
           .my-page { --tph-page-max: 780px; }
       A page whose PADDING also differs writes the whole gutter out instead:
           .my-page { --tph-gutter: calc(max(0px, (100vw - 900px) / 2) + 28px); }
                                                         column      padding
       and if it changes that padding at a breakpoint it must restate it there too, or the
       title keeps reserving room for a corner it has already cleared. */
    --tph-gutter: calc(max(0px, (100vw - var(--tph-page-max, 1536px)) / 2) + 1rem);
}

/* No title row means nothing to sit beside the cluster, so the body would start underneath it
   and the icons would draw over the page's first card. Push it down instead. */
.touch-page-chrome .form-page:not(:has(.form-page-header)) {
    padding-top: 56px;
}

/* Reserve the cluster's width minus what the page's own gutter already leaves, and never less
   than nothing. The 14px is air after the last icon, so the title reads as the next thing
   along the row rather than as a caption stuck to it. */
.touch-page-chrome .form-page-header {
    padding-left: max(0px, calc(var(--tph-nav-w, 100px) + 14px - var(--tph-gutter, 0px)));
    min-height: 40px;
}

/* THE line that makes the row work. line-height 40px is the cluster's button height, so the
   title's first line and the icons share a centre. form.css's page title is a 2.45rem display
   heading with a 1.05 line height, far too tall to share a row with a 40px button — no amount
   of padding will line those up, which is the trap this file exists to close. */
.touch-page-chrome .form-page-title {
    font-size: 1.5rem;
    font-weight: 800;
    line-height: 40px;
    color: var(--tph-ink, var(--ink));
}

/* Tucked under the title rather than spaced off it: on a touch screen the pair is read as one
   block, and form.css's desktop margin breaks it into two. */
.touch-page-chrome .form-page-subtitle {
    margin-top: 0;
    font-size: 0.9rem;
    color: var(--tph-muted, var(--muted));
}

/* ── TouchPage ──────────────────────────────────────────────────────────────────────────────
   The component that renders all of the above for you (SPC.Blazor/Components/Touch/TouchPage).
   Its rules live here rather than in a TouchPage.razor.css because scoped CSS in a referenced
   project never reaches a head's bundle — only a head's OWN components do — so a .razor.css
   here would render the page as bare text in every app that consumes it. */

/* Deliberately almost nothing. The scroll box belongs to whatever is hosting the page — a head's
   shell class (.cafe-editor-shell sets height and overflow) or the layout the page routes under.
   Forcing height/overflow here nested a second scroller inside layouts that already scroll the
   document, which is how a page ends up with two scrollbars and a title that will not stay put. */
.tpage {
    box-sizing: border-box;
}

/* Fixed to the VIEWPORT, not to the page's column: on a tablet there is no browser chrome, so
   the way out must not scroll away. 14px from each edge, 6px apart — the numbers --tph-nav-w
   is counted from, which is why TouchPage counts its own buttons rather than being told. */
.tpage__nav {
    position: fixed;
    top: 14px;
    left: 14px;
    z-index: 20;
    display: flex;
    gap: 6px;
}

/* 40px square: the height the title's line box is matched to, so the icons and the page's name
   share a centre. Changing this size means changing --tph-nav-w's arithmetic with it. */
.tpage__btn {
    -webkit-appearance: none;
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: none;
    background: none;
    border-radius: 12px;
    flex-shrink: 0;
    color: var(--tph-ink, var(--touch-ink, var(--ink)));
    text-decoration: none;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s ease, color 0.15s ease, transform 0.06s ease;
}
.tpage__btn:hover {
    background: var(--touch-accent-soft, rgba(94, 60, 40, 0.08));
    color: var(--touch-accent, var(--accent));
}
.tpage__btn:active { transform: scale(0.94); }
.tpage__btn:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--touch-accent, var(--accent)) 55%, transparent);
    outline-offset: 2px;
}

/* The command slot. Wraps under the title on a narrow tablet rather than squeezing it. */
.tpage__cmds {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

@media (max-width: 640px) {
    .tpage__cmds { flex-basis: 100%; justify-content: flex-start; }
    /* On a phone the commands go UNDER the title: the header becomes a one-column grid (a
       wrapping flex row kept a basis-100% command on the title's line in Chrome), and nothing
       may grow the column past the screen. Without this a fixed-width command (a 420px search
       box) plus the cluster reserve pushed the whole page ~130px wider than a 420px phone. */
    .touch-page-chrome .form-page { grid-template-columns: minmax(0, 1fr); }
    .touch-page-chrome .form-page-header { display: grid; grid-template-columns: minmax(0, 1fr); row-gap: 0.6rem; }
    .tpage__cmds { min-width: 0; max-width: 100%; }
}

/* ── TouchSwitch ────────────────────────────────────────────────────────────────────────────────
   The one on/off control for the touch surface (SPC.Blazor/Components/Touch/TouchSwitch). Its
   rules live here rather than in a TouchSwitch.razor.css for the reason given above: scoped CSS in
   a referenced project never reaches a head's bundle, so it would render as a bare button.

   ON SWAPS THE ENDS BY REVERSING THE ROW, and that is the whole trick. The version this replaces
   did it twice — `order: -1` on the caption AND `translateX(calc(100% - 4px))` on the knob — which
   moved the knob a second time and pushed it out past the pill's own edge. One move, one property,
   and the knob cannot leave the track it lives in.

   Colour comes from the head: --touch-accent (or --accent), so a salon's pink and a cafe's brown
   are the same control in two paints. */
.tsw {
    -webkit-appearance: none;
    appearance: none;
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 72px;
    height: 44px;
    /* Symmetric, because either end may hold the knob. The old asymmetric padding was written for
       a knob that only ever sat on the left. */
    padding: 0 5px;
    border-radius: 999px;
    border: 1px solid var(--touch-line, var(--line, #e3e1e8));
    background: var(--touch-switch-off, #f2f2f5);
    color: var(--touch-muted, var(--muted, #6b6f76));
    font: inherit;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.tsw__knob {
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.22);
}

/* Only present when the caller gave captions; a captionless switch is just the pill and the knob. */
.tsw__txt { padding: 0 9px; }

.tsw.is-on {
    flex-direction: row-reverse;
    background: var(--touch-accent, var(--accent, #c2185b));
    border-color: var(--touch-accent, var(--accent, #c2185b));
    color: #fff;
}

.tsw:disabled { opacity: 0.6; cursor: default; }

.tsw:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--touch-accent, var(--accent, #c2185b)) 55%, transparent);
    outline-offset: 2px;
}
