/*
 * The back-office.
 *
 * The admin was stock Bootstrap: three identical stat cards, tables of raw
 * enum values, and — on the NFC screen — three unstyled forms crammed into one
 * table cell. It is an operations console, so the craft here is information
 * design, not typography: what needs attention has to read at a glance, and
 * state is carried by shape as well as by colour.
 *
 * It deliberately does not look like the customer-facing app. A dark rail and
 * a cool ground say "you are in the back office" without a banner saying so.
 */

.adm {
    --adm-rail: #141a21;
    --adm-rail-ink: #93a1b0;
    --adm-rail-ink-strong: #f2f5f8;
    --adm-rail-line: rgba(255, 255, 255, .08);

    --adm-ground: #f6f7f9;
    --adm-surface: #ffffff;
    --adm-sunken: #eef1f4;
    --adm-ink: #151a20;
    --adm-ink-2: #5a6673;
    --adm-ink-3: #8b96a3;
    --adm-line: rgba(21, 26, 32, .11);
    --adm-line-strong: rgba(21, 26, 32, .18);

    --adm-accent: var(--brand-primary, #2563eb);
    --adm-ok: #177a4c;
    --adm-ok-bg: #e4f4ec;
    --adm-warn: #96600f;
    --adm-warn-bg: #fbf0da;
    --adm-danger: #ab2e23;
    --adm-danger-bg: #fbe6e3;
    --adm-info: #1f5fa8;
    --adm-info-bg: #e4eefb;
    --adm-neutral: #5a6673;
    --adm-neutral-bg: #e9edf1;
    --adm-busy: #574bc0;
    --adm-busy-bg: #eae8f9;

    --adm-radius: 12px;
    --adm-shadow: 0 1px 2px rgba(21, 26, 32, .05), 0 12px 28px -22px rgba(21, 26, 32, .5);

    display: grid;
    grid-template-columns: 232px minmax(0, 1fr);
    min-height: calc(100vh - 62px);
    background: var(--adm-ground);
    color: var(--adm-ink);
    font-size: 14px;
}

@media (max-width: 900px) {
    .adm { grid-template-columns: 1fr; }
}

/* ----------------------------------------------------------------- rail */
.adm-rail {
    background: var(--adm-rail);
    color: var(--adm-rail-ink);
    padding: 18px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

@media (max-width: 900px) {
    .adm-rail { flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px; }
}

.adm-rail__title {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 10px 14px;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .14em;
    text-transform: uppercase;
    color: #6d7c8b;
}

@media (max-width: 900px) { .adm-rail__title { padding-bottom: 0; } }

.adm-rail__link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 9px;
    color: var(--adm-rail-ink);
    text-decoration: none;
    font-weight: 500;
    line-height: 1.2;
    transition: background .14s ease, color .14s ease;
}

.adm-rail__link i { width: 17px; text-align: center; font-size: 14px; opacity: .8; }
.adm-rail__link:hover { background: rgba(255, 255, 255, .06); color: var(--adm-rail-ink-strong); }

/* The active item is marked by a bar as well as a fill: colour alone is not a
   state a colour-blind operator can read. */
.adm-rail__link--active {
    background: rgba(255, 255, 255, .09);
    color: var(--adm-rail-ink-strong);
    box-shadow: inset 3px 0 0 var(--adm-accent);
}

.adm-rail__link--active i { opacity: 1; color: var(--adm-accent); }

.adm-rail__out {
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--adm-rail-line);
}

@media (max-width: 900px) { .adm-rail__out { margin-top: 0; border-top: 0; padding-top: 0; } }

/* -------------------------------------------------------------- content */
.adm-main { padding: 26px 28px 64px; min-width: 0; }
@media (max-width: 620px) { .adm-main { padding: 18px 14px 48px; } }

.adm-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 14px;
    padding-bottom: 16px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--adm-line);
}

/* A long, unbroken title (an e-mail, a UUID) forced this flex item past its
   container instead of wrapping, pushing the whole page into horizontal
   scroll on narrow screens -- every /admin/*/show page shares this rule. */
.adm-head > div:not(.adm-head__actions) { min-width: 0; }
.adm-head__title { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.02em; overflow-wrap: anywhere; }
.adm-head__sub { margin: 5px 0 0; font-size: 13px; color: var(--adm-ink-2); max-width: 62ch; overflow-wrap: anywhere; }
.adm-head__actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ------------------------------------------------------------------ kpi */
.adm-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}

.adm-kpi {
    background: var(--adm-surface);
    border: 1px solid var(--adm-line);
    border-radius: var(--adm-radius);
    padding: 15px 16px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.adm-kpi__label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--adm-ink-3);
}

.adm-kpi__value {
    font-size: 30px;
    font-weight: 700;
    line-height: 1.05;
    letter-spacing: -.03em;
    font-variant-numeric: tabular-nums;
}

.adm-kpi__foot { font-size: 12px; color: var(--adm-ink-2); }

/* The tile that reports a problem is lifted, not recoloured wholesale: the
   page must not turn red because two cards are defective. */
.adm-kpi--alert { border-color: var(--adm-danger); box-shadow: inset 3px 0 0 var(--adm-danger); }
.adm-kpi--alert .adm-kpi__value { color: var(--adm-danger); }

/* ---------------------------------------------------------------- panel */
.adm-panel {
    background: var(--adm-surface);
    border: 1px solid var(--adm-line);
    border-radius: var(--adm-radius);
    box-shadow: var(--adm-shadow);
    overflow: hidden;
    margin-bottom: 20px;
}

/* The "Ações" drawer (.adm-drawer, position: absolute) escaped .adm-scroll's
   own clipping already, but this panel's overflow: hidden -- there for the
   table's square corners under the panel's rounded ones -- clipped it too
   whenever a row sat near the panel's bottom edge. Only lift the clip while
   a drawer in this panel is actually open. */
.adm-panel:has(.adm-actions[open]) { overflow: visible; }

.adm-panel__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 13px 16px;
    border-bottom: 1px solid var(--adm-line);
}

.adm-panel__title { margin: 0; font-size: 14.5px; font-weight: 700; letter-spacing: -.01em; }
.adm-panel__note { font-size: 12.5px; color: var(--adm-ink-2); font-variant-numeric: tabular-nums; }
.adm-panel__body { padding: 16px; }

/* ---------------------------------------------------------------- table */
.adm-scroll { overflow-x: auto; }

.adm-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

.adm-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--adm-sunken);
    text-align: left;
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--adm-ink-3);
    padding: 9px 14px;
    white-space: nowrap;
    border-bottom: 1px solid var(--adm-line);
}

/* A long unbroken value (e-mail, slug, UUID) wraps inside its column
   instead of forcing the whole table wider than the panel. */
.adm-table td { padding: 11px 14px; border-bottom: 1px solid var(--adm-line); vertical-align: middle; overflow-wrap: anywhere; }
.adm-table tbody tr:last-child td { border-bottom: 0; }
.adm-table tbody tr:hover td { background: rgba(21, 26, 32, .022); }

.adm-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.adm-table .actions { text-align: right; white-space: nowrap; }
.adm-table__strong { font-weight: 600; color: var(--adm-ink); }

/* An e-mail is long and rarely the reason someone scans this table: it is
   truncated rather than allowed to push the row's actions off screen. */
.adm-table .ellipsis { max-width: 22ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.adm-mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12.5px;
    color: var(--adm-ink-2);
}

/* ----------------------------------------------------------------- pill */
.adm-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
}

/* A dot as well as a fill: the state survives being printed in grey. */
.adm-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.adm-pill--ok { background: var(--adm-ok-bg); color: var(--adm-ok); }
.adm-pill--warn { background: var(--adm-warn-bg); color: var(--adm-warn); }
.adm-pill--danger { background: var(--adm-danger-bg); color: var(--adm-danger); }
.adm-pill--info { background: var(--adm-info-bg); color: var(--adm-info); }
.adm-pill--neutral { background: var(--adm-neutral-bg); color: var(--adm-neutral); }
.adm-pill--busy { background: var(--adm-busy-bg); color: var(--adm-busy); }

.adm-chip {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    padding: 3px 8px;
    border: 1px solid var(--adm-line);
    border-radius: 7px;
    background: var(--adm-surface);
    font-size: 12.5px;
    max-width: 100%;
    /* A short label like "Manual" must stay one word, even inside a table
       cell narrow enough that overflow-wrap: anywhere would otherwise break
       it letter by letter. */
    white-space: nowrap;
}

.adm-chip + .adm-chip { margin-top: 4px; }
.adm-chip code { font-size: 11.5px; color: var(--adm-ink-3); background: none; padding: 0; }
.adm-muted { color: var(--adm-ink-3); }

/* ---------------------------------------------------------- stock bar */
/* The stock as one line, so its shape is the answer: mostly blue is healthy,
   a wide amber band means cards are sitting in transit. */
.adm-bar {
    display: flex;
    height: 12px;
    border-radius: 999px;
    overflow: hidden;
    background: var(--adm-sunken);
    margin-bottom: 14px;
}

.adm-bar__seg { min-width: 3px; }
.adm-bar__seg--ok { background: var(--adm-ok); }
.adm-bar__seg--warn { background: var(--adm-warn); }
.adm-bar__seg--danger { background: var(--adm-danger); }
.adm-bar__seg--info { background: var(--adm-info); }
.adm-bar__seg--neutral { background: var(--adm-neutral); }
.adm-bar__seg--busy { background: var(--adm-busy); }

/* A hairline between segments, so two adjacent bands of close colours still
   read as two. */
.adm-bar__seg + .adm-bar__seg { box-shadow: inset 1px 0 0 var(--adm-surface); }

.adm-legend { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px 16px; }

.adm-legend__item {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-size: 12.5px;
    color: var(--adm-ink-2);
}

.adm-legend__dot { width: 8px; height: 8px; border-radius: 2px; flex: none; align-self: center; }
.adm-legend__value { margin-left: auto; font-weight: 700; color: var(--adm-ink); font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------------- toolbar */
.adm-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--adm-line);
    background: var(--adm-surface);
}

.adm-toolbar__spacer { flex: 1 1 auto; }

.adm-input, .adm-select {
    height: 36px;
    padding: 0 11px;
    border: 1px solid var(--adm-line-strong);
    border-radius: 8px;
    background: var(--adm-surface);
    color: var(--adm-ink);
    font-size: 13.5px;
    min-width: 0;
}

.adm-input:focus, .adm-select:focus { outline: 2px solid var(--adm-accent); outline-offset: 1px; border-color: transparent; }
.adm-input--search { min-width: 260px; }
.adm-input--sm { height: 32px; font-size: 13px; }
.adm-label { display: block; font-size: 12px; font-weight: 600; color: var(--adm-ink-2); margin-bottom: 4px; }

/* --------------------------------------------------------------- buttons */
.adm-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    height: 36px;
    padding: 0 14px;
    border: 1px solid var(--adm-line-strong);
    border-radius: 8px;
    background: var(--adm-surface);
    color: var(--adm-ink);
    font-size: 13.5px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}

.adm-btn:hover { background: var(--adm-sunken); color: var(--adm-ink); }
.adm-btn:focus-visible { outline: 2px solid var(--adm-accent); outline-offset: 2px; }
.adm-btn--primary { background: var(--adm-accent); border-color: transparent; color: #fff; }
.adm-btn--primary:hover { background: var(--adm-accent); color: #fff; filter: brightness(1.08); }
.adm-btn--sm { height: 31px; padding: 0 10px; font-size: 12.5px; }
.adm-btn--danger { color: var(--adm-danger); border-color: rgba(171, 46, 35, .35); }
.adm-btn--danger:hover { background: var(--adm-danger-bg); color: var(--adm-danger); }
.adm-btn--ghost { border-color: transparent; background: none; color: var(--adm-ink-2); }
.adm-btn--ghost:hover { background: var(--adm-sunken); color: var(--adm-ink); }

/* ------------------------------------------------------------ row actions */
/* Three inline forms used to sit side by side in one cell. They live in a
   drawer now: the table stays a table, and each action gets room to be a
   labelled form instead of a naked input next to a naked button. */
.adm-actions { position: relative; }
.adm-actions > summary { list-style: none; cursor: pointer; display: inline-flex; }
.adm-actions > summary::-webkit-details-marker { display: none; }
.adm-actions[open] > summary .adm-btn { background: var(--adm-sunken); }

.adm-drawer {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    z-index: 30;
    width: min(300px, 78vw);
    padding: 12px;
    background: var(--adm-surface);
    border: 1px solid var(--adm-line-strong);
    border-radius: 11px;
    box-shadow: 0 18px 40px -18px rgba(21, 26, 32, .55);
    text-align: left;
    white-space: normal;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.adm-drawer__form { display: flex; flex-direction: column; gap: 6px; }
.adm-drawer__form + .adm-drawer__form { padding-top: 12px; border-top: 1px solid var(--adm-line); }
.adm-drawer__form .adm-input { width: 100%; }

/* This used to be an unconditional `overflow: visible` on every .adm-scroll,
   which stopped ANY wide table (not just ones with a drawer) from
   scrolling — the table would just overflow past the scroll container and
   get clipped by .adm-panel's own overflow: hidden instead (STK-08). Scope
   it to only when a drawer inside is actually open, matching the
   .adm-panel rule above. */
.adm-scroll:has(.adm-actions[open]) { overflow: visible; }

/* ---------------------------------------------------------- empty & flash */
.adm-empty { padding: 34px 20px; text-align: center; color: var(--adm-ink-2); }
.adm-empty__icon { font-size: 22px; color: var(--adm-ink-3); margin-bottom: 8px; }
.adm-empty__title { font-weight: 700; color: var(--adm-ink); margin-bottom: 3px; }

.adm-flash {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 11px 14px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-size: 13.5px;
    border: 1px solid transparent;
}

.adm-flash--success { background: var(--adm-ok-bg); color: var(--adm-ok); border-color: rgba(23, 122, 76, .22); }
.adm-flash--danger { background: var(--adm-danger-bg); color: var(--adm-danger); border-color: rgba(171, 46, 35, .22); }
.adm-flash--warning { background: var(--adm-warn-bg); color: var(--adm-warn); border-color: rgba(150, 96, 15, .22); }

/* ------------------------------------------------------------- pagination */
.adm-pages { display: flex; flex-wrap: wrap; gap: 4px; padding: 12px 16px; border-top: 1px solid var(--adm-line); }

.adm-pages a {
    min-width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 9px;
    border: 1px solid var(--adm-line);
    border-radius: 7px;
    color: var(--adm-ink-2);
    text-decoration: none;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

.adm-pages a:hover { background: var(--adm-sunken); color: var(--adm-ink); }
.adm-pages a[aria-current="page"] { background: var(--adm-accent); border-color: transparent; color: #fff; font-weight: 700; }

/* ------------------------------------------------------------------ forms */
.adm-form { max-width: 520px; display: flex; flex-direction: column; gap: 14px; }
.adm-form .form-control, .adm-form .form-select, .adm-form .adm-input, .adm-form .adm-select { width: 100%; }
.adm-form .form-control, .adm-form .form-select {
    border-radius: 8px;
    border-color: var(--adm-line-strong);
    font-size: 13.5px;
    min-height: 36px;
}
.adm-form .form-label { font-size: 12px; font-weight: 600; color: var(--adm-ink-2); margin-bottom: 4px; }
.adm-form .form-check-label { font-size: 13.5px; }
.adm-form .invalid-feedback, .adm-form .form-error-message { font-size: 12.5px; color: var(--adm-danger); }

@media (prefers-reduced-motion: reduce) {
    .adm-rail__link { transition: none; }
}

/* ----------------------------------------------------------------- tabs */
.adm-tabs { display: flex; flex-wrap: wrap; gap: 4px; padding: 10px 12px 0; border-bottom: 1px solid var(--adm-line); }
.adm-tab {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 9px 12px; margin-bottom: -1px;
    border: 1px solid transparent; border-bottom: 2px solid transparent; border-radius: 8px 8px 0 0;
    font-size: 13px; font-weight: 600; color: var(--adm-ink-2); text-decoration: none;
}
.adm-tab:hover { background: var(--adm-sunken); color: var(--adm-ink); }
.adm-tab--active { color: var(--adm-ink); border-bottom-color: var(--adm-accent); }
.adm-tab__count { min-width: 22px; padding: 1px 7px; border-radius: 999px; background: var(--adm-sunken); font-size: 12px; text-align: center; font-variant-numeric: tabular-nums; }
.adm-tab--active .adm-tab__count { background: var(--adm-accent); color: #fff; }
.adm-table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------- timeline */
.adm-timeline { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
.adm-timeline li { font-size: 13px; color: var(--adm-ink-3); padding-top: 12px; position: relative; }
.adm-timeline li::before { content: ''; position: absolute; top: 0; left: 0; width: 9px; height: 9px; border-radius: 50%; background: var(--adm-line-strong); }
.adm-timeline li.done { color: var(--adm-ink); }
.adm-timeline li.done::before { background: var(--adm-ok, #177a4c); }
.adm-timeline strong { display: block; }
.adm-grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.adm-dl { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 13.5px; }
.adm-dl dt { color: var(--adm-ink-3); }
.adm-dl dd { margin: 0; }
.adm-thumb { width: 40px; height: 30px; object-fit: cover; border-radius: 6px; display: inline-grid; place-items: center; background: var(--adm-sunken); color: var(--adm-ink-3); }

/* MCP-03: the install page of the MCP server. */
.adm-mcp__block { padding: 18px 20px; margin-bottom: 16px; }
.adm-mcp__title { font-size: 15px; font-weight: 700; margin: 0 0 6px; }
.adm-mcp__sub { font-size: 13px; font-weight: 700; margin: 16px 0 4px; }
.adm-mcp__form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 12px; }
.adm-mcp__form .adm-input { flex: 1 1 280px; }
.adm-mcp__form .adm-label { flex: 1 1 100%; margin: 0; }
.adm-mcp__examples { margin: 0 0 8px; padding-left: 20px; font-size: 13.5px; line-height: 1.7; }
.adm-code { margin: 6px 0; padding: 12px 14px; background: #0f172a; color: #e2e8f0; border-radius: 8px; font-size: 12.5px; line-height: 1.5; white-space: pre-wrap; word-break: break-all; }
