/*
  Saibon ops console.

  Built on the saibon-ui design system rather than a palette of its own: the tokens below are
  copied from saibon-ui/src/index.css so the console reads as part of the product. Same brand font
  (Manrope), same pine and cream, same card and badge shapes, same semantic colours.

  The one thing this page adds is the pipeline spine, because nothing in the product has to show a
  queue backing up at a stage. It is drawn from the same tokens.
*/

:root {
    /* Brand - saibon-ui --color-saibon-* */
    --pine: #1a423d;
    --pine-deep: #0f2c29;
    --amber: #f7ab05;
    --cream: #fafbf6;
    --paper: #ffffff;
    --hairline: #e3e6de;
    --ink-muted: #5f6f6b;

    /* Gray, for the few places the brand scale has no answer */
    --gray-300: #d5d7da;
    --gray-400: #a4a7ae;
    --gray-500: #717680;
    --gray-100: #f5f5f5;

    /* Semantic - saibon-ui error / warning / success scales */
    --error-50: #fef3f2;
    --error-300: #fda29b;
    --error-600: #d92d20;
    --warning-50: #fffaeb;
    --warning-300: #fec84b;
    --warning-600: #dc6803;
    --success-50: #ecfdf3;
    --success-300: #75e0a7;
    --success-600: #079455;

    /* Semantic roles, named as saibon-ui names them */
    --text-primary: var(--pine);
    --text-secondary: var(--ink-muted);
    --text-tertiary: var(--ink-muted);
    --bg-primary: var(--paper);
    --bg-secondary: var(--cream);
    --bg-active: var(--hairline);
    --border-secondary: var(--hairline);

    /* Radius - saibon-ui --radius-* */
    --radius-xs: 4px;
    --radius-md: 8px;
    --radius-xl: 12px;
    --radius-full: 9999px;

    --rail: 14rem;
    --gap: 1.5rem;
}

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

body {
    margin: 0;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: "Manrope", system-ui, -apple-system, sans-serif;
    font-size: 0.875rem;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Digits must line up in every table and figure, or a column cannot be scanned. */
.num,
table td,
table th,
.figure-value,
.stage-count,
.stamp,
.pager-position {
    font-variant-numeric: tabular-nums;
}

/*
  Manrope is the only brand face, so ids and file names use the system mono stack rather than a
  second imported family - the need here is character-level distinction, not another voice.
*/
.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 0.75rem;
}

a {
    color: var(--pine);
    text-decoration-color: var(--hairline);
    text-underline-offset: 2px;
}

a:hover {
    text-decoration-color: currentColor;
}

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

/*
  FocusOnNavigate puts focus on the heading so a screen reader announces the new page. That is not
  a keyboard affordance and should not be drawn: a box around the title on every page load looks
  like a bug. The heading is still focused and still announced.
*/
.page-head h1:focus,
.page-head h1:focus-visible {
    outline: none;
}

/* ---------- boot ---------- */

.boot {
    display: grid;
    place-content: center;
    gap: 0.75rem;
    height: 100vh;
    justify-items: center;
}

.boot-mark {
    width: 1.5rem;
    height: 1.5rem;
    border: 2px solid var(--hairline);
    border-top-color: var(--pine);
    border-radius: var(--radius-full);
    animation: spin 0.8s linear infinite;
}

.boot-text {
    color: var(--text-secondary);
    margin: 0;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .boot-mark {
        animation: none;
    }

    * {
        transition: none !important;
    }
}

/* ---------- shell ---------- */

.shell {
    display: grid;
    grid-template-columns: var(--rail) minmax(0, 1fr);
    min-height: 100vh;
}

.rail {
    background: var(--bg-primary);
    border-right: 1px solid var(--border-secondary);
    padding: 1.5rem 0;
    display: flex;
    flex-direction: column;
}

.rail-brand {
    padding: 0 1.25rem 1.25rem;
}

.rail-brand strong {
    display: block;
    font-size: 1rem;
    font-weight: 800;
    color: var(--pine);
    letter-spacing: -0.01em;
}

.rail-brand span {
    color: var(--text-tertiary);
    font-size: 0.75rem;
}

.rail-nav {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    padding: 0.5rem 0.75rem;
    flex: 1;
}

.rail-nav a {
    padding: 0.5rem 0.75rem;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-md);
    font-weight: 600;
}

.rail-nav a:hover {
    color: var(--pine);
    background: var(--bg-secondary);
}

/* Active nav is the brand solid, as saibon-ui marks a selected item. */
.rail-nav a.active {
    color: #fff;
    background: var(--pine);
}

.rail-foot {
    padding: 1rem 1.25rem 0;
    border-top: 1px solid var(--border-secondary);
    color: var(--text-tertiary);
    font-size: 0.75rem;
    overflow-wrap: anywhere;
}

.rail-foot button {
    margin-top: 0.5rem;
}

.main {
    padding: 2rem;
    max-width: 82rem;
}

/* ---------- page header ---------- */

.page-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--gap);
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.page-head h1 {
    font-size: 1.25rem;
    font-weight: 800;
    margin: 0;
    color: var(--pine);
    letter-spacing: -0.015em;
}

.page-head p {
    margin: 0.25rem 0 0;
    color: var(--text-tertiary);
    font-size: 0.75rem;
}

.stamp {
    color: var(--text-tertiary);
    font-size: 0.75rem;
}

/* ---------- card ---------- */

/* saibon-ui Card: bg-bg-primary, border-border-secondary, rounded-xl, p-6. No shadow. */
.panel {
    background: var(--bg-primary);
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-xl);
    padding: 1.5rem;
}

/* CardTitle: text-sm font-semibold, text-primary. */
.panel > .legend {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.panel-grid {
    display: grid;
    gap: var(--gap);
    grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
    margin-top: var(--gap);
}

@media (max-width: 60rem) {
    .panel-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .shell {
        grid-template-columns: minmax(0, 1fr);
    }

    .rail {
        border-right: 0;
        border-bottom: 1px solid var(--border-secondary);
    }

    .main {
        padding: 1.25rem 1rem 3rem;
    }
}

/* ---------- the pipeline spine ---------- */

.spine {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 0;
}

.stage {
    padding: 0 0.875rem 0 0;
    position: relative;
}

.stage:not(:last-child)::after {
    content: "";
    position: absolute;
    right: 0.3125rem;
    top: 1.9rem;
    width: 0.375rem;
    height: 0.375rem;
    border-top: 1.5px solid var(--gray-300);
    border-right: 1.5px solid var(--gray-300);
    transform: rotate(45deg);
}

.stage-name {
    color: var(--text-tertiary);
    font-size: 0.75rem;
    font-weight: 600;
}

.stage-count {
    font-size: 2.25rem;
    font-weight: 800;
    line-height: 1.15;
    letter-spacing: -0.025em;
    display: block;
    color: var(--pine);
}

/* Width is the stage's share of the pipeline, so a pile-up shows as a bulge. */
.stage-bar {
    height: 0.25rem;
    background: var(--hairline);
    border-radius: var(--radius-full);
    margin-top: 0.625rem;
    margin-right: 0.875rem;
    overflow: hidden;
}

.stage-bar span {
    display: block;
    height: 100%;
    border-radius: var(--radius-full);
    background: var(--gray-400);
}

.stage[data-tone="ok"] .stage-bar span {
    background: var(--success-600);
}

.stage[data-tone="wait"] .stage-bar span {
    background: var(--warning-600);
}

.stage[data-tone="stuck"] .stage-bar span {
    background: var(--error-600);
}

.stage[data-tone="wait"] .stage-count {
    color: var(--warning-600);
}

.stage[data-tone="stuck"] .stage-count {
    color: var(--error-600);
}

/* ---------- figures ---------- */

.figures {
    display: grid;
    gap: 0.875rem;
}

.figure {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    border-bottom: 1px solid var(--border-secondary);
    padding-bottom: 0.625rem;
}

.figure:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.figure-label {
    color: var(--text-secondary);
}

.figure-label.indent {
    padding-left: 0.875rem;
}

.figure-value {
    font-size: 1.5rem;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -0.02em;
    color: var(--pine);
}

.figure-value.small {
    font-size: 1.125rem;
    font-weight: 600;
}

/* ---------- verdict ---------- */

/* "Nothing is stuck" has to read as clearly as a problem does, so the healthy state is stated. */
.verdict {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    padding: 0.875rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-secondary);
}

.verdict[data-tone="ok"] {
    background: var(--success-50);
}

.verdict[data-tone="stuck"] {
    background: var(--error-50);
}

/* Something to look at, but not broken: profiles below the publish threshold, say. */
.verdict[data-tone="wait"] {
    background: var(--warning-50);
}

.verdict-mark {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: var(--radius-full);
    margin-top: 0.4375rem;
    flex: none;
}

.verdict[data-tone="ok"] .verdict-mark {
    background: var(--success-600);
}

.verdict[data-tone="stuck"] .verdict-mark {
    background: var(--error-600);
}

.verdict[data-tone="wait"] .verdict-mark {
    background: var(--warning-600);
}

.verdict strong {
    display: block;
    font-weight: 600;
}

.verdict[data-tone="ok"] strong {
    color: var(--success-600);
}

.verdict[data-tone="stuck"] strong {
    color: var(--error-600);
}

.verdict[data-tone="wait"] strong {
    color: var(--warning-600);
}

.verdict p {
    margin: 0.125rem 0 0;
    color: var(--text-secondary);
}

/* ---------- tables ---------- */

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    text-align: left;
    font-weight: 600;
    color: var(--text-tertiary);
    font-size: 0.75rem;
    padding: 0 0.75rem 0.625rem;
    border-bottom: 1px solid var(--border-secondary);
    white-space: nowrap;
}

tbody td {
    padding: 0.625rem 0.75rem;
    border-bottom: 1px solid var(--border-secondary);
    vertical-align: top;
}

tbody tr:last-child td {
    border-bottom: 0;
}

tbody tr:hover {
    background: var(--bg-secondary);
}

th.right,
td.right {
    text-align: right;
}

td.zero {
    color: var(--gray-400);
}

.row-name {
    font-weight: 600;
    color: var(--text-primary);
}

/* For a span inside a cell: block so the id or slug sits on its own line. */
.row-sub {
    display: block;
    color: var(--text-tertiary);
    font-size: 0.75rem;
}

/*
  For the cell itself. Deliberately not .row-sub: display:block on a <td> removes it from the table
  layout, so the cell stops sharing the row's height and its bottom border drifts away from the
  others - which is exactly how this was spotted.
*/
td.muted {
    color: var(--text-tertiary);
    font-size: 0.75rem;
}

td.flag {
    color: var(--error-600);
    font-weight: 600;
}

/* ---------- badges ---------- */

/*
  saibon-ui Badge: rounded-md, a NEUTRAL hairline border whatever the variant, with only the fill
  and the text carrying the status. Copied rather than re-invented so a pill here looks like a
  pill in the product.
*/
.pill {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.625rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.25rem;
    white-space: nowrap;
}

.pill[data-tone="ok"] {
    background: var(--success-50);
    color: var(--success-600);
}

.pill[data-tone="wait"] {
    background: var(--warning-50);
    color: var(--warning-600);
}

.pill[data-tone="stuck"] {
    background: var(--error-50);
    color: var(--error-600);
}

.pill[data-tone="idle"] {
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

/* ---------- controls ---------- */

/* saibon-ui Button, outline variant: bg-bg-primary, text-text-secondary, px-3 py-2. */
button {
    font: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-secondary);
    background: var(--bg-primary);
    color: var(--text-secondary);
    border-radius: var(--radius-md);
    cursor: pointer;
}

button:hover:not(:disabled) {
    background: var(--bg-secondary);
    color: var(--pine);
}

button:disabled {
    color: var(--gray-400);
    background: var(--bg-primary);
    cursor: default;
}

/* Default variant: bg-bg-brand-solid, text-text-white. */
button.primary {
    background: var(--pine);
    color: #fff;
    border-color: var(--pine);
}

button.primary:hover:not(:disabled) {
    background: var(--pine-deep);
    border-color: var(--pine-deep);
    color: #fff;
}

button.link {
    border: 0;
    background: none;
    padding: 0;
    font-weight: inherit;
    color: inherit;
    text-decoration: underline;
    text-decoration-color: var(--hairline);
    text-underline-offset: 2px;
}

button.link:hover:not(:disabled) {
    background: none;
    text-decoration-color: currentColor;
}

input {
    font: inherit;
    font-size: 0.875rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-md);
    background: var(--bg-primary);
    color: var(--text-primary);
    width: 100%;
}

input::placeholder {
    color: var(--text-tertiary);
}

input:focus-visible {
    outline: 2px solid var(--pine);
    outline-offset: -1px;
    border-color: var(--pine);
}

/* ---------- pager ---------- */

.pager {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-secondary);
}

.pager-position {
    color: var(--text-tertiary);
    font-size: 0.75rem;
    font-weight: 600;
}

/* ---------- sign in ---------- */

.signin {
    display: grid;
    place-content: center;
    min-height: 100vh;
    padding: 1.5rem;
}

.signin-panel {
    width: min(24rem, 100%);
}

.signin h1 {
    font-size: 1.25rem;
    font-weight: 800;
    margin: 0 0 0.375rem;
    color: var(--pine);
    letter-spacing: -0.015em;
}

.signin .intro {
    color: var(--text-tertiary);
    margin: 0 0 1.5rem;
    font-size: 0.75rem;
}

.field {
    display: grid;
    gap: 0.375rem;
    margin-bottom: 1rem;
}

.field label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* ---------- messages ---------- */

.notice {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-secondary);
    background: var(--bg-secondary);
    color: var(--text-secondary);
}

.notice[data-tone="stuck"] {
    color: var(--error-600);
    background: var(--error-50);
}

.empty {
    color: var(--text-tertiary);
    padding: 1.25rem 0;
}

.rail-build {
    display: block;
    margin-top: 0.625rem;
    color: var(--gray-400);
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
}

#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--error-50);
    border-top: 1px solid var(--error-300);
    color: var(--error-600);
    padding: 0.875rem 1.5rem;
    font-weight: 600;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    float: right;
}

/* ---------- page header actions ---------- */

.head-actions {
    display: flex;
    align-items: center;
    gap: 0.875rem;
}

button.refresh {
    display: inline-flex;
    align-items: center;
    gap: 0.4375rem;
}

/* The glyph turns only while a read is in flight, which is the one thing it has to say. */
button.refresh:disabled svg {
    animation: spin 0.9s linear infinite;
}
