/* The approval console's design system - mobile-first, phone-legible, light and dark.
 *
 * Served same-origin and UNAUTHENTICATED from `/app.css`: an external stylesheet, never an
 * inline <style>, because the strict CSP `style-src 'self'` (security.py) forbids inline style.
 * It imports nothing and fetches nothing, so no rule here reaches a cross-origin asset.
 *
 * THE TOKENS ARE THE ONLY PLACE A COLOUR IS SPELLED. Every colour literal lives in the light
 * `:root` block or its dark twin below; every rule reads `var(--color-...)`. The dark block
 * redefines EVERY colour token, so no light value survives onto a dark page. Text and each
 * severity's word meet WCAG AA (4.5:1) in both schemes. All of this is a CI floor:
 * tests/unit/test_design_system_ph1.py reads this file off the served route.
 *
 * The accent is Zoestra's navy (the manifest's theme colour). Severity is never colour alone:
 * the badge always prints its word beside the colour.
 *
 * Mobile-first: base rules target a 375 px phone; the one min-width query widens buttons on a
 * larger screen. Tap targets stay >= 44 px tall for a thumb (`--tap`).
 */

:root {
  color-scheme: light dark;

  /* colour - light */
  --color-bg: #f6f6f9;
  --color-surface: #ffffff;
  --color-text: #1a1a2e;
  --color-muted: #50506a;
  --color-border: #c9c9d6;
  --color-accent: #1a1a2e;
  --color-accent-text: #ffffff;
  --color-link: #2b3a8c;
  --color-focus: #3d5afe;
  --color-disabled-bg: #e3e3ea;
  --color-disabled-text: #5c5c70;
  --color-rights-fg: #8a1c1c;
  --color-rights-bg: #fdecec;
  --color-rights-border: #c62828;
  --color-schema-fg: #6b3f00;
  --color-schema-bg: #fff3dc;
  --color-schema-border: #b26a00;
  --color-data-fg: #33334a;
  --color-data-bg: #ececf2;
  --color-data-border: #8a8a9c;

  /* type */
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --text-sm: 0.875rem;
  --text-base: 1.0625rem; /* readable on a phone without zoom */
  --text-lg: 1.2rem;
  --text-xl: 1.375rem;
  --leading: 1.5;

  /* space and shape */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --radius: 0.375rem;
  --gap: var(--space-4);
  --tap: 2.75rem; /* 44 px minimum comfortable tap target */
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #12121f;
    --color-surface: #1c1c2e;
    --color-text: #ececf4;
    --color-muted: #a9a9bf;
    --color-border: #3b3b55;
    --color-accent: #2a2a4d;
    --color-accent-text: #ffffff;
    --color-link: #a3b3ff;
    --color-focus: #a3b3ff;
    --color-disabled-bg: #2a2a3c;
    --color-disabled-text: #a0a0b4;
    --color-rights-fg: #ffb8b8;
    --color-rights-bg: #3d1414;
    --color-rights-border: #e57373;
    --color-schema-fg: #ffd591;
    --color-schema-bg: #3a2a0c;
    --color-schema-border: #e0a030;
    --color-data-fg: #d8d8e6;
    --color-data-bg: #26263a;
    --color-data-border: #6c6c86;
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%; /* keep phone text at the author-set size */
  background: var(--color-bg);
  color: var(--color-text);
}

body {
  margin: 0;
  padding: var(--gap);
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading);
  max-width: 44rem;
  margin-inline: auto;
}

header h1 {
  font-size: var(--text-xl);
  margin: 0 0 var(--space-3);
}

main {
  display: block;
}

h2 {
  font-size: var(--text-lg);
}

h3 {
  font-size: 1.05rem;
}

/* Width safety: nothing a page carries may push it wider than the phone it is read on. */
img,
svg,
video,
canvas {
  max-width: 100%;
  height: auto;
}

pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: var(--font-mono);
}

code,
h1,
h2,
h3,
h4,
dd {
  overflow-wrap: anywhere; /* a digest or a long name never forces a horizontal scroll */
}

code {
  font-family: var(--font-mono);
  font-size: 0.9375rem;
}

/* Lists and rows: full-width, generously spaced for a thumb. */
ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

li {
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-border);
}

section {
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-border);
}

/* The navigation bar: on every signed-in page, never on the signed-out landing. */
.site-nav {
  margin: 0 0 var(--space-3);
  padding: 0 var(--space-2);
  background: var(--color-accent);
  color: var(--color-accent-text);
  border-radius: var(--radius);
}

.site-nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0 var(--space-3);
}

.site-nav li {
  padding: 0;
  border: 0;
}

.site-nav a {
  padding: 0 var(--space-1);
  color: var(--color-accent-text);
  text-decoration: none;
}

.site-nav a[aria-current="page"] {
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 0.3em;
}

.session-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0 var(--space-3);
  margin: 0 0 var(--space-3);
  color: var(--color-muted);
  font-size: var(--text-sm);
}

.signed-in-as {
  margin: 0;
  overflow-wrap: anywhere;
}

.signout-form {
  margin: 0;
}

.signout-form button {
  width: auto;
  margin-top: 0;
}

/* Forms: stacked, full-width fields and tall tap targets (sign-in, approve, reject). */
form {
  margin: var(--gap) 0;
}

label {
  display: block;
  margin-bottom: var(--space-2);
}

input[type="email"],
input[type="text"],
input[type="date"],
input[type="number"],
select {
  display: block;
  width: 100%;
  min-height: var(--tap);
  margin-top: var(--space-1);
  padding: 0 var(--space-3);
  font-size: var(--text-base);
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

button {
  display: block;
  width: 100%;
  min-height: var(--tap);
  margin-top: var(--space-3);
  padding: 0 var(--space-4);
  font-size: var(--text-base);
  background: var(--color-accent);
  color: var(--color-accent-text);
  border: 1px solid var(--color-accent);
  border-radius: var(--radius);
  cursor: pointer;
}

/* A DISABLED button must LOOK disabled: the card script disables it on submit so a second tap
   cannot double-post, and a button that kept its normal look read as a dead tap on a phone.
   Matched on BOTH forms because a UA may reflect the property or the attribute. */
button:disabled,
button[disabled] {
  background: var(--color-disabled-bg);
  color: var(--color-disabled-text);
  border-color: var(--color-border);
  cursor: not-allowed;
}

a {
  display: inline-block;
  min-height: var(--tap);
  line-height: var(--tap);
  overflow-wrap: anywhere;
  color: var(--color-link);
}

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

/* Panels, rows and badges: the shapes every page composes from. */
.panel {
  padding: var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.badge,
.pending-badge {
  display: inline-block;
  min-width: 1.75rem;
  padding: 0 var(--space-2);
  border-radius: var(--radius);
  background: var(--color-accent);
  color: var(--color-accent-text);
  text-align: center;
  font-weight: 700;
}

/* An error a person reaches: the refusal in the rights palette, with its word, and a way back. */
[role="alert"] {
  padding: var(--space-3);
  color: var(--color-rights-fg);
  background: var(--color-rights-bg);
  border: 1px solid var(--color-rights-border);
  border-radius: var(--radius);
}

.way-back {
  font-weight: 600;
}

[role="status"] {
  padding: var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

/* A person's screens (/screens, /screens/<id>): console pages, this one sheet, the same CSP.
   A table may be wider than the phone, so it scrolls inside its block, not the page. */
.screen-block {
  border-top: 1px solid var(--color-border);
  padding-top: var(--space-3);
  margin-top: var(--space-4);
  overflow-x: auto;
}

table.screen-table {
  border-collapse: collapse;
}

table.screen-table th,
table.screen-table td {
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-1) var(--space-3) var(--space-1) 0;
  text-align: left;
}

.screen-figure-label {
  color: var(--color-muted);
}

.screen-figure-value {
  font-size: var(--text-xl);
  font-weight: 600;
}

dl.screen-record dt {
  font-weight: 600;
}

.screen-unavailable,
.screen-empty,
.screen-made {
  color: var(--color-muted);
}

/* On a wider screen the buttons need not span the full column. */
@media (min-width: 40rem) {
  button {
    width: auto;
    min-width: 12rem;
  }
}

/* The card and queue SHAPE - the fold and the hierarchy (label lighter than value). */

/* The row's leading word ("Field:" / "Value:") reads lighter than the value after it. */
.row-label {
  color: var(--color-muted);
  font-weight: normal;
}

/* The bundle's aggregate shape line and the per-entity group header: a quiet break. */
.shape-line {
  font-weight: 600;
}

.entity-group {
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--color-border);
}

.entity-group h4 {
  font-size: 1rem;
  margin: 0 0 var(--space-1);
  display: inline; /* the heading sits on its summary's line, beside the fold marker */
}

.entity-group summary {
  cursor: pointer;
  min-height: var(--tap); /* one record's fold is a thumb-sized tap target */
}

/* The staged id: one long unbroken token, so it may break anywhere rather than scroll. */
.staged-id {
  overflow-wrap: anywhere;
  word-break: break-all;
}

/* The staged id and digest fold: closed by default, one tap to open - off the main reading
   path without deleting either (display-what-you-sign). */
details {
  margin: var(--gap) 0;
}

details summary {
  cursor: pointer;
  min-height: var(--tap);
  line-height: var(--tap);
  color: var(--color-muted);
}

/* The settled fold: decided / expired / withdrawn / failed writes sit one tap away, recessed,
   so a dead write stops competing with the work awaiting a decision. Folded, never deleted. */
.settled-fold {
  border-top: 1px solid var(--color-border);
}

.settled-cause {
  margin: 0.15rem 0 0;
  font-size: 0.9rem;
  color: var(--color-muted);
}

/* Progress on an action that waits. `.working-line` is the card's sentence, hidden until the
   external card script reveals it on submit; `.progress` is the moving bar beside any waiting
   action, and `.busy` / `aria-busy` mark the control that is waiting. The `hidden` attribute
   does the hiding; these rules only style the shown state. */
.working-line {
  margin: var(--gap) 0;
  min-height: var(--tap);
  line-height: var(--tap);
  color: var(--color-muted);
}

.working-line[hidden],
.progress[hidden] {
  display: none;
}

.progress {
  display: block;
  height: 0.3rem;
  margin: var(--space-2) 0;
  border-radius: var(--radius);
  background: linear-gradient(90deg, var(--color-border) 0 30%, var(--color-accent) 30% 60%,
    var(--color-border) 60% 100%);
  background-size: 300% 100%;
  animation: progress-slide 1.2s linear infinite;
}

.busy,
[aria-busy="true"] {
  cursor: progress;
}

@keyframes progress-slide {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: 0 0;
  }
}

/* Reduced motion: nothing moves, but a waiting action still SHOWS it is waiting - the bar
   becomes a static solid busy state rather than disappearing. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }

  .progress {
    background: var(--color-accent);
  }
}

/* A print form's uploaded logo on the approval card: a thumbnail beside the asset name, small
   enough that a phone card still reads as a list. Served same-origin, so `img-src 'self'`. */
.asset-thumb {
  display: block;
  max-width: 8rem;
  max-height: 4rem;
  margin: var(--space-1) 0;
  object-fit: contain;
}

/* The severity badge on every card and queue row: each level has its own foreground,
   background and border token, and the WORD is always printed beside the colour. */
.severity-badge {
  display: inline-block;
  padding: 0.1rem var(--space-2);
  border: 2px solid;
  border-radius: var(--radius);
  font-size: var(--text-sm);
}

.severity-rights {
  color: var(--color-rights-fg);
  background: var(--color-rights-bg);
  border-color: var(--color-rights-border);
  font-weight: 700;
}

.severity-schema {
  color: var(--color-schema-fg);
  background: var(--color-schema-bg);
  border-color: var(--color-schema-border);
  font-weight: 600;
}

.severity-data {
  color: var(--color-data-fg);
  background: var(--color-data-bg);
  border-color: var(--color-data-border);
  font-weight: normal;
}
