/* frame.css -- the four boxes.

   #cs-app holds #cs-top, #cs-body and #cs-foot. #cs-body holds the layer rail,
   the panel and the stage. That is the whole structure; everything else in the
   engine lives inside one of those.

   THE GEOMETRY VARIABLES ARE DECLARED ONCE, ON #cs-app, AND NOWHERE ELSE.
   A custom property flows down and never sideways, so every row can read them
   from the frame. What is not allowed is a second declaration further down to
   fix a scope problem: that is how one number becomes two that agree today. If
   a rule cannot see a variable, the rule is in the wrong place -- move the rule,
   never re-declare the number.
*/

#cs-app {
    /* ---- the frame's own geometry ------------------------------------
       Measured on the live page, not remembered. 57 is the navbar's OUTER
       height. 78 is the flush rail. 54 is the footer. */
    --cs-topbar:    57px;
    --cs-footbar:   54px;
    --cs-rail:      78px;

    /* THE PANEL FLOOR IS 429 AND IT IS A FLOOR, NOT A WIDTH.
       It was 384 for most of the old build's life, and the consequence was that
       the canvas jumped 45px sideways when you switched from a tool that wanted
       a catalogue to one that did not -- because two tools were allowed to be
       different widths. Raising the floor to the widest ask means no tool is
       narrower than another and the canvas stops moving. */
    --cs-panel-min: 429px;

    /* The gap between catalogue columns. THE TILE WIDTH IS NOT HERE, and that
       is deliberate. The old build stated both, with a comment warning that
       changing one without the other breaks the grid -- a warning is what you
       write when the structure lets the mistake happen. Here the grid is two
       equal columns of whatever is left, so the tile is an OUTCOME. The design
       says 185 at this panel width; the harness measures whether it is, rather
       than the stylesheet asserting it twice. */
    --cs-grid-gap:  12px;

    /* The panel's inside edge, one value used on both sides. 18 a side is the
       36 the old drawer had; it is written once here rather than as a shorthand
       in the panel rule so the catalogue can ask what it is without measuring. */
    --cs-panel-pad: 18px;

    position: fixed;
    inset: 0;
    z-index: 9000;
    display: flex;
    flex-direction: column;
    background: var(--cs-white);
    overflow: hidden;
}

/* ---- the navbar ---------------------------------------------------
   Three columns: burger and wordmark left, the model chip centred, language and
   help right.

   THE CHIP IS CENTRED OVER THE CANVAS, NOT OVER THE WINDOW, which is the reason
   the geometry variables have to live on the frame -- the chip's rule needs to
   know the rail and the panel to find the canvas centre. Below 1100 that
   alignment gives way to three ordinary columns, because the arithmetic stops
   producing a sensible position long before it stops producing a number. */
#cs-top {
    flex: 0 0 auto;
    height: var(--cs-topbar);
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    border-bottom: 1px solid var(--cs-hairline);
    background: var(--cs-white);
}

/* ---- the body ------------------------------------------------------ */
#cs-body {
    flex: 1 1 auto;
    min-height: 0;          /* or the stage's content sets the floor and the
                               footer is pushed off the bottom of the window */
    display: flex;
    align-items: stretch;
    /* THE ADD MENU'S CONTAINING BLOCK, and that is the only reason this is
       here. The menu is anchored to the rail -- left: 90px is the 78px rail
       plus a 12px gap -- and it must be measured from the BODY's top-left, not
       the stage's and not the window's.

       It was mounted in the stage until 29 Aug, when the first live walk found
       what that costs: the menu opened at the stage's left edge instead of
       beside the Add button, and the stage's width became its max-width, so it
       came out 711px wide and dropped from four columns to three. Both faults
       were one wrong parent. */
    position: relative;
}

/* ---- the layer rail ------------------------------------------------
   Flush at the left edge. Holds the Add button, sticky as its first child, and
   the layer stack under it. */
#cs-rail {
    flex: 0 0 auto;
    width: var(--cs-rail);
    min-width: 0;
    border-right: 1px solid var(--cs-hairline);
    background: var(--cs-white);
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-gutter: stable;
}

/* ---- the panel -----------------------------------------------------
   What is selected decides what this holds. With nothing selected there is
   nothing to inspect, so it holds what you can add.

   scrollbar-gutter: stable IS DOING REAL WORK HERE. The old build had to know
   the scrollbar was 11px wide, because it granted a width and then divided it
   into columns by hand -- and the container it was tested in renders OVERLAY
   scrollbars, which take no layout width at all, so the fixture and Chris's
   Chrome disagreed by 11px about a number the design depended on. Reserving the
   gutter means the content box is the same with and without a scrollbar, and
   the columns are whatever fits. Nothing has to know how wide a scrollbar is. */
#cs-panel {
    flex: 0 0 auto;
    width: var(--cs-panel-min);
    min-width: 0;
    padding: var(--cs-panel-pad);
    border-right: 1px solid var(--cs-hairline);
    background: var(--cs-white);
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-gutter: stable;
}

/* ---- the stage -----------------------------------------------------
   The canvas and its surround. min-width:0 because a flex item will not shrink
   below its min-content size otherwise, and neither a max-width nor an ellipsis
   on a child changes that -- which is a sentence nothing in a stylesheet says
   out loud and eight measured widths had to establish. */
#cs-stage {
    flex: 1 1 auto;
    min-width: 0;
    position: relative;
    background: var(--cs-surround);
}

/* ---- the footer ----------------------------------------------------
   1fr auto 1fr. The left column is EMPTY ON PURPOSE: the mock draws an autosave
   status and there is no autosave, so drawing one would be a claim the engine
   cannot keep. The pill is centred over the WINDOW, which means it and the model
   chip are not on one vertical line -- that is what Chris drew, and it is the
   first thing that looks like a bug to anyone who has not read this. */
#cs-foot {
    flex: 0 0 auto;
    height: var(--cs-footbar);
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    border-top: 1px solid var(--cs-hairline);
    background: var(--cs-white);
}

/* ---- the catalogue grid -------------------------------------------
   Two equal columns of whatever the panel leaves. See --cs-grid-gap above for
   why the tile width is not stated. */
.cs-cat-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--cs-grid-gap);
}

/* ════════════════════════════════════════════════════════════════════
   THE FOOTER, AND SAVING
   ════════════════════════════════════════════════════════════════════ */

#cs-foot {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 0 18px;
    border-top: 1px solid var(--cs-hairline);
    background: var(--cs-white);
}

.cs-foot-save {
    padding: 9px 20px;
    border: 0;
    border-radius: 10px;
    background: var(--cs-accent);
    color: var(--cs-white);
    font-family: inherit;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
}

.cs-foot-save:hover { filter: brightness(1.08); }

/* THE DIALOGUE IS A <dialog>, so the focus trap, Escape and the inert
   background come from the browser rather than from JS that works until
   somebody tabs. ::backdrop is the browser's too — the Add menu deliberately
   has none, because it closes on an outside click; this one is modal, because
   a half-finished save behind a customer still dragging stickers is a save
   nobody finishes. */
#cs-save {
    width: min(420px, calc(100vw - 32px));
    padding: 0;
    border: 0;
    border-radius: var(--cs-r-menu);
    box-shadow: 0 18px 48px rgba(15, 23, 42, 0.22);
}

#cs-save::backdrop { background: rgba(15, 23, 42, 0.32); }

.cs-save-body { padding: 22px 22px 18px; }

.cs-save-title { margin: 0; font-size: 17px; font-weight: 800; color: var(--cs-ink); }

.cs-save-lead {
    margin: 6px 0 16px;
    font-size: 12.5px;
    line-height: 1.45;
    color: var(--cs-muted);
}

.cs-save-label {
    display: block;
    margin: 0 0 5px;
    font-size: 11.5px;
    font-weight: 700;
    color: var(--cs-muted);
}

.cs-save-email {
    width: 100%;
    box-sizing: border-box;
    padding: 9px 11px;
    border: 1px solid var(--cs-line);
    border-radius: 9px;
    font: inherit;
    font-size: 13px;
    color: var(--cs-ink);
}

.cs-save-email:focus-visible {
    outline: 2px solid var(--cs-accent);
    outline-offset: 1px;
}

.cs-save-check {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin: 14px 0 0;
    font-size: 12.5px;
    line-height: 1.4;
    color: var(--cs-ink);
    cursor: pointer;
}

.cs-save-ack { margin: 2px 0 0; flex: 0 0 auto; }

/* THE MESSAGE IS ONE NODE, and it is empty until there is something to say —
   an empty box holding space for an error that has not happened reads as a
   layout fault. */
.cs-save-msg {
    margin: 12px 0 0;
    font-size: 12.5px;
    line-height: 1.45;
    color: var(--cs-ink);
    overflow-wrap: anywhere;
}

.cs-save-msg:empty { display: none; }

/* The refusal states colour the message; the done state makes it the loudest
   thing in the box, because the CODE is the one thing the customer must not
   miss. Keyed off the dialogue's state attribute, which is the claim — a class
   on the message would be a second description of the same fact. */
#cs-save[data-cs-save="refused"] .cs-save-msg,
#cs-save[data-cs-save="failed"] .cs-save-msg,
#cs-save[data-cs-save="empty"] .cs-save-msg { color: var(--cs-danger); }

#cs-save[data-cs-save="done"] .cs-save-msg {
    font-size: 15px;
    font-weight: 800;
    color: var(--cs-ink);
}

/* Once it is saved there is nothing left to fill in. The form stays in the
   document — removing it would move the message and the buttons under the
   customer's cursor mid-read. */
#cs-save[data-cs-save="done"] .cs-save-label,
#cs-save[data-cs-save="done"] .cs-save-email,
#cs-save[data-cs-save="done"] .cs-save-check,
#cs-save[data-cs-save="done"] .cs-save-go,
#cs-save[data-cs-save="empty"] .cs-save-label,
#cs-save[data-cs-save="empty"] .cs-save-email,
#cs-save[data-cs-save="empty"] .cs-save-check,
#cs-save[data-cs-save="empty"] .cs-save-go { display: none; }

.cs-save-acts {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin: 18px 0 0;
}

.cs-save-go,
.cs-save-cancel {
    padding: 9px 16px;
    border-radius: 9px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

.cs-save-go {
    border: 0;
    background: var(--cs-accent);
    color: var(--cs-white);
}

/* IT MUST LOOK DISABLED, AND STILL LOOK LIKE A CONTROL — the rail's lesson,
   applied where it matters more: this is the button a customer presses twice
   when a save is slow. */
.cs-save-go:disabled {
    opacity: 1;
    background: color-mix(in srgb, var(--cs-accent) 38%, var(--cs-white));
    cursor: progress;
}

.cs-save-cancel {
    border: 1px solid var(--cs-line);
    background: var(--cs-white);
    color: var(--cs-ink);
}

.cs-save-cancel:hover { border-color: var(--cs-accent); color: var(--cs-accent); }
