/* =====================================================================
   Jewel Box — back-office stylesheet (stage 1)
   =====================================================================
   Hand-written CSS, no framework (TECHNICAL_DESIGN.md section 15).

   This file styles the back office and the pre-sign-in pages only. The
   storefront's design system ("The Cabinet", PLAN.md section 7) is built
   in stage 3 with the final palette; the colours here are the company's
   black and gold on warm paper, kept deliberately plain.

   Rules that already hold and must keep holding:
   - Logical properties only (margin-inline, padding-block, inset-inline,
     text-align: start), so the Arabic right-to-left layout in stage 3
     needs no second stylesheet.
   - Works at 360px and at desktop width alike (decision 51). Tables
     marked .table--cards turn into stacked cards on a narrow screen.
   - Zero radius, no shadows, hairline rules (the Cabinet's vocabulary).
   - Tap targets at least 44px high; visible focus (WCAG 2.2 AA).
   ===================================================================== */

:root {
    --paper: #f7f2e8;
    --tile: #ede6d8;
    --ink: #111111;
    --muted: #5c5248;
    --hairline: #d9cfbd;
    --gold: #7a5c1e;
    --garnet: #7a1f2b;
    --success: #1f5f3a;
    --warning: #7a4b00;
    --info: #1f4a7a;
    --white: #ffffff;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
}

h1 { font-size: 1.75rem; line-height: 1.2; margin-block: 0 1rem; font-weight: 600; }
h2 { font-size: 1.25rem; line-height: 1.3; margin-block: 0 0.75rem; font-weight: 600; }
p { margin-block: 0 1rem; }
a { color: var(--ink); text-underline-offset: 3px; }
a:hover { color: var(--garnet); }
code { font-family: ui-monospace, Consolas, monospace; font-size: 0.9em; overflow-wrap: anywhere; }

:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

.muted { color: var(--muted); font-size: 0.9375rem; }
.visually-hidden { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip-link { position: absolute; inset-inline-start: -999px; }
.skip-link:focus { inset-inline-start: 8px; inset-block-start: 8px; background: var(--white); padding: 8px; z-index: 10; }

/* ---- Back-office frame ---------------------------------------------- */
.bo-header { background: var(--ink); color: var(--paper); }
.bo-header a { color: var(--paper); }
.bo-header__bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 10px 16px; max-inline-size: 1200px; margin-inline: auto; }
.bo-brand { font-size: 1.25rem; font-weight: 600; text-decoration: none; letter-spacing: 0.02em; }
.bo-user { display: flex; align-items: center; gap: 10px; margin-inline-start: auto; flex-wrap: wrap; }
.bo-user__name { font-size: 0.9375rem; }
.bo-user form { margin: 0; }
.bo-header .button--quiet { color: var(--paper); border-color: var(--muted); min-block-size: 36px; padding-block: 4px; }
.bo-nav { display: flex; flex-wrap: wrap; gap: 4px 4px; padding: 0 12px 8px; max-inline-size: 1200px; margin-inline: auto; }
.bo-nav a { padding: 10px 10px; text-decoration: none; border-block-end: 2px solid transparent; }
.bo-nav a:hover { border-block-end-color: var(--gold); color: var(--paper); }
/* Decision 76: the Dev menu. A details element: it opens on a tap or a click with
   no script, and its panel floats over the page instead of pushing it down. */
.bo-menu { position: relative; }
.bo-menu summary { padding: 10px 10px; cursor: pointer; border-block-end: 2px solid transparent; }
.bo-menu summary:hover, .bo-menu[open] summary { border-block-end-color: var(--gold); color: var(--paper); }
.bo-menu__panel { position: absolute; inset-block-start: 100%; inset-inline-start: 0; z-index: 10; min-inline-size: 220px; display: flex; flex-direction: column; background: var(--ink); border: 1px solid var(--muted); padding: 6px; }
.bo-menu__form { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 6px 0 0; padding: 8px 10px 4px; border-block-start: 1px solid var(--muted); }
.bo-menu__label { font-size: 0.8125rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); inline-size: 100%; }
/* The bar shown while Dev views as another role: loud on purpose, it must not be missed. */
.bo-viewing { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px 16px; padding: 8px 12px; background: #ffd27a; color: #1a1a1a; font-size: 0.9375rem; }
.bo-viewing form { margin: 0; }
.bo-viewing .button--quiet { color: #1a1a1a; border-color: #1a1a1a; }
.bo-main { max-inline-size: 1200px; margin-inline: auto; padding: 24px 16px 64px; }

/* ---- Pre-sign-in pages ---------------------------------------------- */
.bare { display: grid; min-block-size: 100vh; place-items: start center; padding: 8vh 16px 32px; }
.bare__card { inline-size: 100%; max-inline-size: 440px; background: var(--white); border: 1px solid var(--hairline); padding: 28px 24px; }
.bare__brand { font-size: 0.75rem; letter-spacing: 0.14em; text-transform: uppercase; color: var(--gold); margin-block-end: 1.25rem; }

/* ---- Building blocks ------------------------------------------------ */
.card { background: var(--white); border: 1px solid var(--hairline); padding: 20px 16px; margin-block-end: 20px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-block-end: 1rem; }
.page-head h1 { margin: 0; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin-block: 1.5rem; }
.tile { display: block; background: var(--white); border: 1px solid var(--hairline); padding: 16px; text-decoration: none; }
.tile:hover { border-color: var(--gold); color: var(--ink); }
.tile strong { display: block; margin-block-end: 4px; }
.tile span { color: var(--muted); font-size: 0.9375rem; }

.button {
    display: inline-flex; align-items: center; justify-content: center;
    min-block-size: 44px; padding: 8px 18px;
    background: var(--ink); color: var(--white);
    border: 1px solid var(--ink); border-radius: 0;
    font: inherit; font-weight: 500; text-decoration: none; cursor: pointer;
}
.button:hover { background: var(--gold); border-color: var(--gold); color: var(--white); }
.button--wide { inline-size: 100%; }
.button--quiet { background: transparent; color: var(--ink); border-color: var(--hairline); }
.button--quiet:hover { background: var(--tile); color: var(--ink); border-color: var(--ink); }
.button--danger { color: var(--garnet); }
.button--success { background: var(--success); border-color: var(--success); }
.button--warning { background: var(--warning); border-color: var(--warning); }

.chip { display: inline-block; padding: 2px 8px; border: 1px solid var(--hairline); background: var(--tile); font-size: 0.8125rem; line-height: 1.5; }
.chip--success, .chip--verified { border-color: var(--success); color: var(--success); background: var(--white); }
.chip--warning, .chip--partly { border-color: var(--warning); color: var(--warning); background: var(--white); }
.chip--danger, .chip--unconfirmed { border-color: var(--garnet); color: var(--garnet); background: var(--white); }
.chip--info, .chip--needs { border-color: var(--info); color: var(--info); background: var(--white); }
.chip--decided { border-color: var(--ink); background: var(--white); }
.bo-header .chip { background: transparent; color: var(--paper); border-color: var(--muted); }
.bo-header .chip--warning { color: #ffd27a; border-color: #ffd27a; background: transparent; }

.flash { padding: 12px 14px; border: 1px solid; border-inline-start-width: 4px; background: var(--white); margin-block-end: 1rem; }
.flash--success { border-color: var(--success); }
.flash--error { border-color: var(--garnet); }
.flash ul { margin: 0; padding-inline-start: 1.2rem; }
.flash:empty, .validation-summary-valid { display: none; }

/* ---- Forms ---------------------------------------------------------- */
/* minmax(0, 1fr): without it the one column is as wide as its widest item
   wants to be, and a long option or a row that cannot wrap widens the page. */
.form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.form--narrow { max-inline-size: 480px; }
.form label { font-weight: 500; margin-block-start: 10px; }
.form button { margin-block-start: 16px; }
.form__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-block-start: 16px; }
.form__actions button { margin-block-start: 0; }
/* Three short number boxes side by side (packed length, width, height) at any width. */
.inline-form.inline-form--three { flex-wrap: nowrap; }
.inline-form.inline-form--three input { flex: 1 1 0; min-inline-size: 0; }
input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="datetime-local"], input[type="date"], input:not([type]), select, textarea {
    inline-size: 100%; min-block-size: 44px; padding: 8px 10px;
    border: 1px solid var(--muted); border-radius: 0; background: var(--white);
    font: inherit; color: var(--ink);
}
.field-error, .field-validation-error { color: var(--garnet); font-size: 0.9375rem; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-block-end: 1rem; }
.inline-form select, .inline-form input { inline-size: auto; flex: 1 1 160px; }
td .inline-form { margin: 0; }

/* min-inline-size: 0 matters: a fieldset is by default at least as wide as its
   widest content, so one long option in a select pushed the whole item page wider
   than a phone screen (found by the journey test's phone-width check). */
.checks { border: 0; padding: 0; margin: 0 0 1rem; min-inline-size: 0; }
select { max-inline-size: 100%; }
.checks legend { font-weight: 600; padding: 0; margin-block-end: 4px; }
.check { display: flex; gap: 10px; align-items: flex-start; padding-block: 8px; font-weight: 400 !important; margin: 0 !important; }
.check input { inline-size: 20px; block-size: 20px; margin-block-start: 2px; flex: none; }
.check--never { color: var(--muted); }
.check--never em { margin-inline-start: auto; font-size: 0.8125rem; }

.steps { padding-inline-start: 1.25rem; }
.steps li { margin-block-end: 0.75rem; }
.qr { margin-block: 12px; max-inline-size: 220px; }
.qr svg { inline-size: 100%; block-size: auto; display: block; }
/* The "can't scan it?" block on the two-factor setup page: closed by default so the
   setup key is not mistaken for the code to type. */
.steps__alt { margin-block-start: 8px; }
.steps__alt summary { cursor: pointer; text-decoration: underline; }
.steps__alt p { margin-block: 8px 0; }
.key { display: block; padding: 8px; background: var(--tile); margin-block-start: 6px; letter-spacing: 0.05em; }
.codes { list-style: none; padding: 12px; margin: 0 0 1rem; background: var(--tile); display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }

/* ---- Tables --------------------------------------------------------- */
.table { inline-size: 100%; border-collapse: collapse; background: var(--white); margin-block-end: 1rem; }
.table th, .table td { text-align: start; vertical-align: top; padding: 10px 12px; border-block-end: 1px solid var(--hairline); }
.table th { font-size: 0.8125rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
/* The cell stays a table cell (a flex cell loses its row border); the forms flow inline. */
.table .actions form { display: inline-block; margin: 0; margin-inline-end: 6px; margin-block-end: 6px; }
.table :target, tr:target { background: #fff6d6; }

.facts { display: grid; grid-template-columns: minmax(120px, 220px) 1fr; gap: 8px 16px; margin: 0 0 1rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }

.tabs { display: flex; flex-wrap: wrap; gap: 4px; border-block-end: 1px solid var(--ink); margin-block-end: 1.25rem; }
.tabs a { padding: 10px 14px; text-decoration: none; border: 1px solid transparent; border-block-end: 0; }
.tabs a[aria-current="page"] { background: var(--ink); color: var(--paper); }

.pager { display: flex; gap: 12px; align-items: center; }

.prose p:last-child { margin-block-end: 0; }
.prose--document { background: var(--white); border: 1px solid var(--hairline); padding: 20px 16px; overflow-x: auto; }
.prose--document table { border-collapse: collapse; margin-block-end: 1rem; }
.prose--document th, .prose--document td { text-align: start; vertical-align: top; padding: 8px 10px; border: 1px solid var(--hairline); }
.prose--document h1 { font-size: 1.5rem; }
.prose--document h2 { margin-block-start: 1.5rem; }
.prose--document pre { overflow-x: auto; background: var(--tile); padding: 12px; }

/* ---- Photos on an item's page: a grid of 4:5 thumbnails with their actions. */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; margin-block-end: 1rem; }
.photo { margin: 0; display: grid; gap: 8px; align-content: start; }
.photo img { display: block; inline-size: 100%; block-size: auto; aspect-ratio: 4 / 5; object-fit: cover; border: 1px solid var(--hairline); background: var(--tile); }
.photo__placeholder { aspect-ratio: 4 / 5; display: grid; place-items: center; padding: 12px; text-align: center; background: var(--tile); border: 1px dashed var(--muted); color: var(--muted); font-size: 0.875rem; }
.photo__placeholder--failed { border-color: var(--garnet); color: var(--garnet); }
.photo figcaption { display: grid; gap: 6px; justify-items: start; }
.photo figcaption form { margin: 0; }

.dialog { border: 1px solid var(--ink); border-radius: 0; padding: 20px; max-inline-size: min(440px, 92vw); }
.dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.dialog__actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---- Page-loading indicator (site.js creates the element) ------------
   One indicator for the whole app: a gold bar across the top and a small
   "Loading" label. Shown while the browser waits for the next page after
   a link click or a form submit, so a slow answer never looks like a
   click that was ignored. Above the dialog's backdrop is not possible
   (the top layer wins), which is fine: a dialog closes before its form
   submits. The label alone carries the message when motion is reduced. */
.page-loading { position: fixed; inset-block-start: 0; inset-inline: 0; z-index: 100; pointer-events: none; }
.page-loading[hidden] { display: none; }
/* direction: ltr pins the sliding piece to one edge so the keyframes below
   cross the whole bar on the Arabic layout as well. */
.page-loading__bar { block-size: 4px; background: var(--hairline); overflow: hidden; direction: ltr; }
.page-loading__bar::before { content: ""; display: block; block-size: 100%; inline-size: 40%; background: var(--gold); }
.page-loading__label {
    position: absolute; inset-block-start: 10px; inset-inline-end: 10px;
    display: flex; align-items: center; gap: 8px;
    background: var(--ink); color: var(--white); padding: 6px 12px; font-size: 0.875rem;
}
.page-loading__label::before {
    content: ""; inline-size: 14px; block-size: 14px;
    border: 2px solid var(--muted); border-block-start-color: var(--white); border-radius: 50%;
}
/* The button that was pressed says so too; it is what the eye is on. */
.button[aria-busy="true"] { opacity: 0.65; cursor: progress; }

/* ---- Narrow screens: tables become cards (decision 51) --------------- */
@media (max-width: 720px) {
    .table--cards thead { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip-path: inset(50%); }
    .table--cards, .table--cards tbody, .table--cards tr, .table--cards td { display: block; inline-size: 100%; }
    .table--cards tr { border: 1px solid var(--hairline); margin-block-end: 12px; padding-block: 6px; }
    .table--cards td { border: 0; padding: 6px 12px; }
    .table--cards td[data-label]:not([data-label=""])::before {
        content: attr(data-label);
        display: block; font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
    }
    .facts { grid-template-columns: 1fr; gap: 2px 0; }
    .facts dd { margin-block-end: 10px; }
    .codes { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: no-preference) {
    .button, .tile, .bo-nav a { transition: background-color 150ms, border-color 150ms, color 150ms; }
    .page-loading__bar::before { animation: page-loading-slide 1.1s ease-in-out infinite; }
    .page-loading__label::before { animation: page-loading-spin 0.8s linear infinite; }
}

/* Translate percentages are of the piece's own width (40% of the bar), so
   -100% to 250% carries it from just off one edge to just off the other. */
@keyframes page-loading-slide {
    from { transform: translateX(-100%); }
    to { transform: translateX(250%); }
}
@keyframes page-loading-spin { to { transform: rotate(360deg); } }
