/* Orbit Production — admin interface.
 *
 * Palette and shape borrowed from orbit-os-store's style.css so the two
 * services look like one system. Hand-written, no framework and no build step,
 * matching the store: the whole interface is a handful of pages and a
 * toolchain would cost more than it saves. */

:root {
  --orbit-bg: #0a0a0f;
  --orbit-bg-card: #12121a;
  --orbit-bg-elevated: #16161f;
  --orbit-bg-alt: #0e0e14;
  --orbit-accent: #6c63ff;
  --orbit-accent-2: #a78bfa;
  --orbit-accent-cyan: #22d3ee;
  --orbit-text: #e8e8f0;
  --orbit-muted: #8f8fa8;
  --orbit-border: #252536;
  --orbit-radius: 16px;

  /* Status colours. Used for certificate states and nothing else, so the
   * meaning stays consistent wherever they appear. */
  --ok: #00c853;
  --warn: #ffb300;
  --bad: #ef5350;
  --pending: #22d3ee;

  color-scheme: dark;
  font-family: Roboto, "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--orbit-bg);
  background-image:
    radial-gradient(circle at 15% -8%, rgba(108, 99, 255, .25), transparent 42%),
    radial-gradient(circle at 92% 4%, rgba(34, 211, 238, .12), transparent 38%);
  background-attachment: fixed;
  color: var(--orbit-text);
  font-size: 15px;
  line-height: 1.55;
}

a { color: var(--orbit-accent-2); }

/* ── header ───────────────────────────────────────────────────────────────── */

.top {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--orbit-border);
  background: rgba(10, 10, 15, .8);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: .65rem; color: inherit; text-decoration: none; }
.brand-logo { width: 34px; height: 34px; border-radius: 8px; flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-title { font-weight: 700; font-size: 1.05rem; letter-spacing: .2px; }
.brand-tagline { color: var(--orbit-muted); font-size: .78rem; }

.top-nav { display: flex; gap: .35rem; flex-wrap: wrap; flex: 1; }

.nav-link {
  color: var(--orbit-muted);
  text-decoration: none;
  padding: .4rem .8rem;
  border-radius: 999px;
  font-size: .9rem;
}
.nav-link:hover { color: var(--orbit-text); background: var(--orbit-bg-elevated); }
.nav-link[aria-current="page"] { color: var(--orbit-text); background: var(--orbit-bg-card); }

.session { display: flex; align-items: center; gap: .75rem; font-size: .85rem; }
.session-email { color: var(--orbit-muted); }

.role-badge {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: .15rem .5rem;
  border-radius: 999px;
  border: 1px solid var(--orbit-border);
  color: var(--orbit-muted);
}
.role-badge[data-role="admin"] { color: var(--orbit-accent-2); border-color: var(--orbit-accent); }
.role-badge[data-role="producer"] { color: var(--ok); border-color: var(--ok); }

/* ── layout ───────────────────────────────────────────────────────────────── */

main { max-width: 1180px; margin: 0 auto; padding: 1.75rem 1.25rem 4rem; }

h1 { font-size: 1.45rem; margin: 0 0 .35rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
.subtitle { color: var(--orbit-muted); margin: 0 0 1.5rem; }

.card {
  background: var(--orbit-bg-card);
  border: 1px solid var(--orbit-border);
  border-radius: var(--orbit-radius);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
/* The heading sits on the same line as the controls, so its own bottom margin
 * would push it off centre. */
.card-head h2 { margin: 0; }
/* Filters carry a caption above the control; lining them up by their bottom
 * edge keeps the controls and any buttons on one line. */
.card-head .actions { align-items: flex-end; }

.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 1.25rem; }

.stat { background: var(--orbit-bg-elevated); border-radius: 12px; padding: 1rem; }
.stat-value { font-size: 1.8rem; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--orbit-muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .4px; }

/* ── tables ───────────────────────────────────────────────────────────────── */

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

table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .6rem .7rem; border-bottom: 1px solid var(--orbit-border); }
th { color: var(--orbit-muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .4px; }
tbody tr:hover { background: var(--orbit-bg-elevated); }
td.mono, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
/* Dates, serials and bench names read as one token; breaking them mid-way
 * makes a table harder to scan than letting it scroll. */
td.nowrap { white-space: nowrap; }
th.num { text-align: right; }
td { vertical-align: middle; }
/* The last column holds the row's buttons: kept on one line, with room between them. */
td:last-child { white-space: nowrap; }
td > button + button { margin-left: .4rem; }
td select { min-width: 140px; }

.empty { color: var(--orbit-muted); padding: 1.5rem; text-align: center; }

/* ── status pills ─────────────────────────────────────────────────────────── */

.pill {
  display: inline-block;
  padding: .12rem .55rem;
  border-radius: 999px;
  font-size: .75rem;
  border: 1px solid currentColor;
  white-space: nowrap;
}
.pill[data-status="generated"] { color: var(--ok); }
.pill[data-status="deployed"] { color: var(--ok); }
.pill[data-status="pending"] { color: var(--pending); }
.pill[data-status="failed"] { color: var(--bad); }
.pill[data-status="superseded"] { color: var(--orbit-muted); }
.pill[data-status="revoked"] { color: var(--warn); }
.pill[data-status="approved"] { color: var(--ok); }
.pill[data-status="rejected"] { color: var(--bad); }
.pill[data-state="inactive"] { color: var(--orbit-muted); }
.pill[data-state="active"] { color: var(--ok); }

/* ── forms ────────────────────────────────────────────────────────────────── */

form { display: grid; gap: .9rem; }
/* Fields in a row line up along their tops: label, then input, then any hint.
 * A hint under one field must not push its neighbours' inputs down or make
 * them taller, which is what stretching to the tallest cell used to do. */
.form-row {
  display: grid;
  gap: .9rem;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  align-items: start;
}

label {
  display: grid;
  gap: .3rem;
  align-content: start;
  font-size: .85rem;
  color: var(--orbit-muted);
}

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], input[type="search"], select, textarea {
  background: var(--orbit-bg-alt);
  border: 1px solid var(--orbit-border);
  border-radius: 10px;
  color: var(--orbit-text);
  padding: .55rem .7rem;
  font: inherit;
  width: 100%;
}
/* One height for every single-line control, so a select beside a text input
 * lines up with it; browsers otherwise size selects a few pixels shorter. */
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], input[type="search"], select {
  height: 2.6rem;
  line-height: 1.2;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--orbit-accent);
}
textarea { min-height: 220px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; }

input[type="file"] {
  width: 100%;
  font: inherit;
  font-size: .85rem;
  color: var(--orbit-text);
  background: var(--orbit-bg-alt);
  border: 1px dashed var(--orbit-border);
  border-radius: 10px;
  padding: .45rem .6rem;
}
input[type="file"]::file-selector-button {
  font: inherit;
  color: var(--orbit-text);
  background: var(--orbit-bg-elevated);
  border: 1px solid var(--orbit-border);
  border-radius: 999px;
  padding: .28rem .8rem;
  margin-right: .8rem;
  cursor: pointer;
}
input[type="checkbox"] { accent-color: var(--orbit-accent); }

/* A checkbox and its caption on one line, where a stacked label would not fit. */
label.inline { display: inline-flex; align-items: center; gap: .45rem; color: var(--orbit-text); }

progress { width: 220px; height: .6rem; accent-color: var(--orbit-accent); }

/* A value edited where it is shown, in a table cell: text or input, then its buttons. */
.inline-edit { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.inline-edit input[type="text"] { width: auto; min-width: 220px; flex: 1; height: 2.1rem; }
td.notes { min-width: 200px; }

.hint { color: var(--orbit-muted); font-size: .78rem; }

button {
  background: var(--orbit-accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: .5rem 1.1rem;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
button:hover { background: var(--orbit-accent-2); }
button:disabled { opacity: .5; cursor: not-allowed; }

button.secondary { background: transparent; border: 1px solid var(--orbit-border); color: var(--orbit-text); }
button.secondary:hover { background: var(--orbit-bg-elevated); }
button.danger { background: transparent; border: 1px solid var(--bad); color: var(--bad); }
button.danger:hover { background: rgba(239, 83, 80, .12); }
button.small { padding: .28rem .7rem; font-size: .82rem; }

.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* ── messages ─────────────────────────────────────────────────────────────── */

.error, .notice {
  border-radius: 10px;
  padding: .7rem .9rem;
  font-size: .88rem;
  margin: 0 0 1rem;
}
.error { color: var(--bad); border: 1px solid var(--bad); background: rgba(239, 83, 80, .08); }
.notice { color: var(--ok); border: 1px solid var(--ok); background: rgba(0, 200, 83, .08); }

/* A generated password is shown once and never again, so it is presented to be
 * copied rather than skimmed past. */
.secret {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.05rem;
  letter-spacing: .5px;
  background: var(--orbit-bg-alt);
  border: 1px dashed var(--orbit-accent);
  border-radius: 10px;
  padding: .6rem .8rem;
  margin: .5rem 0;
  user-select: all;
  word-break: break-all;
}

/* ── sign in ──────────────────────────────────────────────────────────────── */

.auth-wrap { min-height: 80vh; display: grid; place-items: center; padding: 2rem 1rem; }
.auth-card { width: min(400px, 100%); }
.auth-logo { width: 56px; height: 56px; border-radius: 12px; display: block; margin-bottom: .9rem; }

/* ── detail panels ────────────────────────────────────────────────────────── */

.detail { display: grid; gap: 1.25rem; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) { .detail { grid-template-columns: 1.4fr 1fr; } }

/* A descriptor shown read-only: wrapped and scrollable rather than spilling out of its card. */
pre.mono {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  background: var(--orbit-bg-alt);
  border: 1px solid var(--orbit-border);
  border-radius: 10px;
  padding: .7rem .8rem;
  max-height: 420px;
  overflow: auto;
}

#approval-state { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin: 0 0 .5rem; }
#approval-note { margin: 0 0 .5rem; }
#review { display: grid; gap: .6rem; margin-top: .75rem; }

dl.facts { display: grid; grid-template-columns: auto 1fr; gap: .35rem .9rem; margin: 0; font-size: .88rem; }
dl.facts dt { color: var(--orbit-muted); }
dl.facts dd { margin: 0; overflow-wrap: anywhere; }

.checklist { display: grid; gap: .4rem; max-height: 320px; overflow-y: auto; }
.checklist label {
  display: flex;
  align-items: center;
  gap: .6rem;
  color: var(--orbit-text);
  background: var(--orbit-bg-elevated);
  border-radius: 10px;
  padding: .45rem .7rem;
  font-size: .88rem;
}
.checklist input[type="checkbox"] { width: auto; accent-color: var(--orbit-accent); }
.checklist label.unavailable { opacity: .55; }

/* ── reports ──────────────────────────────────────────────────────────────── */

/* The filter bar: presets on one line, the fields beneath. */
.presets { display: flex; gap: .35rem; flex-wrap: wrap; }
.presets button[aria-pressed="true"] { background: var(--orbit-accent); border-color: var(--orbit-accent); color: #fff; }
.filters { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); align-items: end; margin-top: .9rem; }

.stat-note { color: var(--orbit-muted); font-size: .78rem; margin-top: .25rem; }
#kpis { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stat[data-tone="good"] .stat-value { color: var(--ok); }
.stat[data-tone="warn"] .stat-value { color: var(--warn); }
.stat[data-tone="bad"] .stat-value { color: var(--bad); }

.two-col { display: grid; gap: 1.25rem; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 900px) { .two-col { grid-template-columns: 1fr 1fr; } }
.two-col > .card { margin-bottom: 0; }
.two-col + .card, .two-col + .two-col { margin-top: 1.25rem; }

/* Charts are drawn as SVG by the page script; colours come from here so they
 * follow the palette. */
.chart { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--orbit-border); stroke-width: 1; }
.chart .grid-line { stroke: var(--orbit-border); stroke-width: 1; stroke-dasharray: 2 4; }
.chart .tick { fill: var(--orbit-muted); font-size: 11px; }
.chart .bar-produced { fill: var(--orbit-accent); }
.chart .bar-failures { fill: var(--bad); }
.chart .bar-pareto { fill: var(--bad); opacity: .85; }
.chart .cumulative { fill: none; stroke: var(--warn); stroke-width: 2; }
.chart .cumulative-dot { fill: var(--warn); }
.chart .value { fill: var(--orbit-text); font-size: 11px; }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; color: var(--orbit-muted); font-size: .8rem; margin-top: .5rem; }
.legend .swatch { display: inline-block; width: .7rem; height: .7rem; border-radius: 3px; margin-right: .35rem; vertical-align: -1px; }
.swatch.produced { background: var(--orbit-accent); }
.swatch.failures { background: var(--bad); }
.swatch.cumulative { background: var(--warn); }

/* Progress towards an order's quantity. */
.meter { background: var(--orbit-bg-alt); border: 1px solid var(--orbit-border); border-radius: 999px; height: .6rem; min-width: 120px; overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--orbit-accent); }
.meter[data-done="true"] > span { background: var(--ok); }

/* The printable summary: only on paper. */
.print-only { display: none; }

@media print {
  :root { color-scheme: light; }
  body { background: #fff; color: #111; font-size: 11pt; }
  .top, .no-print, .presets, .filters, button { display: none !important; }
  .print-only { display: block; }
  main { max-width: none; padding: 0; }
  .card, .stat { background: #fff; border: 1px solid #ccc; break-inside: avoid; }
  .stat-label, .subtitle, th, .hint, .stat-note, .chart .tick, .legend { color: #555; }
  th, td { border-bottom-color: #ddd; }
  .chart .value { fill: #111; }
  .chart .axis, .chart .grid-line { stroke: #ccc; }
  a { color: #111; text-decoration: none; }
  .meter { background: #eee; border-color: #ccc; }
  tbody tr:hover { background: none; }
}

[hidden] { display: none !important; }

@media (max-width: 640px) {
  .top { gap: .75rem; padding: .75rem 1rem; }
  main { padding: 1.25rem 1rem 3rem; }
}

h2.spaced, .actions.spaced { margin-top: 1.25rem; }
