/* ProperPics components (M13.1) — consume tokens only; no hard-coded values.
   Writing system: active-voice labels, the verb survives into its toast
   ("Approve photo" → "Approved"); sentence case; errors say what went wrong
   and what to do next. */

* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--text-md);
  line-height: var(--leading);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: var(--radius-sm); }

/* --- shell ----------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; gap: var(--sp-5);
  background: var(--bg-card);
  border-bottom: 1px solid var(--line);
  padding: var(--sp-3) var(--sp-6);
  position: sticky; top: 0; z-index: 40;
}
.topbar .wordmark {
  font-family: var(--font-brand); font-size: var(--text-lg); color: var(--ink);
  text-decoration: none;  /* the wordmark links home when signed in */
}
.topbar .wordmark .tld { color: var(--brass); font-style: italic; }
.topbar nav { display: flex; gap: var(--sp-4); align-items: center; }
.topbar nav a { color: var(--ink-soft); font-size: var(--text-sm); font-weight: 500;
                padding: .25rem .6rem; border-radius: var(--radius-md); }
.topbar nav a:hover { color: var(--ink); text-decoration: none; }
.topbar nav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }
.topbar .spacer { flex: 1; }
.topbar .op-flag {
  margin-left: var(--sp-2); font-size: var(--text-xs); font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em; color: var(--accent);
  border: 1px solid var(--accent); border-radius: 999px; padding: .05rem .45rem;
  vertical-align: middle;
}
.logout-form { display: inline; margin: 0; }
.topbar .linkish {
  background: none; border: 0; padding: 0; cursor: pointer; font: inherit;
  color: var(--ink-soft); font-size: var(--text-sm); font-weight: 500;
}
.topbar .linkish:hover { color: var(--accent); }

.breadcrumb {
  display: flex; gap: var(--sp-2); align-items: center;
  font-size: var(--text-sm); color: var(--ink-faint);
  padding: var(--sp-4) var(--sp-6) 0;
}
.breadcrumb a { color: var(--ink-soft); }
.breadcrumb .sep { color: var(--ink-faint); }
.breadcrumb .here { color: var(--ink); font-weight: 500; }

main.page { padding: var(--sp-5) var(--sp-6) var(--sp-8); max-width: 1320px; margin: 0 auto; }
main.page.narrow { max-width: 760px; }
h1, h2, h3 { font-weight: 600; line-height: 1.25; }
h1 { font-size: var(--text-xl); margin: var(--sp-2) 0 var(--sp-5); }
h2 { font-size: var(--text-lg); }
.num { font-feature-settings: var(--tnum); }

/* --- components ------------------------------------------------------ */
.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--sp-5);
  margin-bottom: var(--sp-5);
}
.card.flush { padding: 0; }                       /* edge-to-edge tables/lists (#42) */
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }

.btn {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  font: 500 var(--text-sm) var(--font-ui);
  border-radius: var(--radius-md);
  padding: var(--sp-2) var(--sp-4);
  border: 1px solid transparent;
  cursor: pointer; text-decoration: none;
  background: var(--accent); color: var(--on-accent);
}
.btn:hover { background: var(--accent-strong); text-decoration: none; }
.btn.quiet { background: transparent; color: var(--ink-soft); border-color: var(--line); }
.btn.quiet:hover { color: var(--ink); border-color: var(--ink-faint); background: transparent; }
.btn.danger { background: transparent; color: var(--regen); border-color: var(--regen); }
.btn.danger:hover { background: var(--regen-bg); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.selected { background: var(--accent-soft); color: var(--accent-strong); border-color: var(--accent); }
[data-surface="dark"] .btn.selected { color: var(--accent-strong); }
/* success-FILL (operator Approve on the dark canvas): green fill + surface-coloured text
   (dark-on-bright on dark, light-on-deep-green on light — AA either way). */
.btn.pass, button.pass { background: var(--pass); color: var(--bg); border-color: transparent; }
.btn.pass:hover, button.pass:hover { background: var(--pass); filter: brightness(1.06); }

.badge {
  display: inline-flex; align-items: center;
  font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.04em;
  padding: 0.15rem 0.55rem; border-radius: 999px;
}
.badge.PASS, .badge.done { color: var(--pass); background: var(--pass-bg); }
.badge.HUMAN_REVIEW, .badge.review, .badge.queued, .badge.running, .badge.classifying { color: var(--review); background: var(--review-bg); }
  .badge.planning { color: var(--accent); background: var(--accent-soft); }
.badge.REGENERATE, .badge.failed { color: var(--regen); background: var(--regen-bg); }
.badge.UNJUDGED, .badge.expired, .badge.neutral { color: var(--neutral-badge); background: var(--neutral-badge-bg); }
/* agent public-status slugs (AgentJobView.status_kind) — the customer's primary
   signal, keyed off a stable slug so colours don't break on the display text. */
.badge.ready { color: var(--pass); background: var(--pass-bg); }
.badge.in_review, .badge.submitted { color: var(--review); background: var(--review-bg); }
.badge.action { color: var(--accent); background: var(--accent-soft); }

table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td {
  text-align: left; padding: var(--sp-3) var(--sp-3);
  border-bottom: 1px solid var(--line); font-size: var(--text-sm);
}
table.list th { color: var(--ink-faint); font-weight: 500; font-size: var(--text-xs); }
table.list tr.rowlink { cursor: pointer; }
table.list tr.rowlink:hover td { background: var(--bg-inset); }

label { display: block; font-size: var(--text-sm); font-weight: 500;
        color: var(--ink-soft); margin: var(--sp-4) 0 var(--sp-1); }
label.inline { display: flex; align-items: center; gap: var(--sp-2); font-weight: 400; }
input[type=text], input[type=password], input[type=email], input[type=number],
select, textarea {
  width: 100%; max-width: 30rem;
  background: var(--bg-card); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--radius-md);
  padding: var(--sp-2) var(--sp-3); font: inherit;
}
textarea { max-width: 100%; }
input[type=checkbox], input[type=radio] { width: auto; }  /* not the 100% text-field width */
input:focus-visible, select:focus-visible, textarea:focus-visible {
  border-color: var(--accent); box-shadow: var(--focus-ring);
}
.field-hint { font-size: var(--text-xs); color: var(--ink-faint); margin-top: var(--sp-1); }

.flash, .callout {
  border: 1px solid var(--review); background: var(--review-bg); color: var(--review);
  border-radius: var(--radius-md); padding: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-4); font-size: var(--text-sm);
}
/* one banner component, four intents (bare / .review default is amber caution). */
.callout.info  {
  /* A quiet annotation, not a loud blue block (the account hub stacks several of these).
     A thin accent rule on the left + a soft tint + normal readable ink — restrained. */
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  color: var(--ink);
  padding: var(--sp-2) var(--sp-3);
}
.callout.pass  { border-color: var(--pass);   background: var(--pass-bg);     color: var(--pass); }
.callout.regen { border-color: var(--regen);  background: var(--regen-bg);    color: var(--regen); }

.empty-state {
  text-align: center; color: var(--ink-soft); padding: var(--sp-8) var(--sp-5);
}
.empty-state .hint { font-size: var(--text-sm); color: var(--ink-faint); }

.skeleton {
  background: linear-gradient(90deg, var(--bg-inset) 25%, var(--bg-card) 50%, var(--bg-inset) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
  min-height: 1.1em;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* --- toasts ----------------------------------------------------------- */
#toasts {
  position: fixed; top: var(--sp-4); right: var(--sp-4); z-index: 100;
  display: flex; flex-direction: column; gap: var(--sp-2);
}
.toast {
  background: var(--ink); color: var(--bg);
  border-radius: var(--radius-sm); padding: var(--sp-2) var(--sp-4);
  font-size: var(--text-sm); box-shadow: var(--shadow-pop);
  animation: toast-in 160ms ease-out; cursor: pointer; max-width: 22rem;
}
[data-surface="dark"] .toast { background: var(--bg-card); color: var(--ink); border: 1px solid var(--line); }
@keyframes toast-in { from { transform: translateY(-6px); opacity: 0; } }

/* --- dialog ------------------------------------------------------------ */
dialog.pp {
  border: none; border-radius: var(--radius-lg); padding: 0;
  background: var(--bg-card); color: var(--ink);
  box-shadow: var(--shadow-pop);
  max-width: min(96vw, 1500px);
}
dialog.pp::backdrop { background: rgb(0 0 0 / 0.62); }

.kbd {
  font: 500 var(--text-xs) var(--font-ui);
  border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: var(--radius-sm); padding: 0 var(--sp-2);
  color: var(--ink-soft); background: var(--bg-inset);
}

progress.pp { accent-color: var(--accent); width: 100%; height: 6px; }

/* --- bare elements (pages may use <button> directly with quiet/danger) --- */
button { font: 500 var(--text-sm) var(--font-ui); border-radius: var(--radius-md);
         padding: var(--sp-2) var(--sp-4); border: 1px solid transparent;
         cursor: pointer; background: var(--accent); color: var(--on-accent); }
button:hover { background: var(--accent-strong); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.quiet { background: transparent; color: var(--ink-soft); border-color: var(--line); }
button.quiet:hover { color: var(--ink); background: transparent; }
button.danger { background: transparent; color: var(--regen); border-color: var(--regen); }
img { max-width: 100%; border-radius: var(--radius-sm); display: block; }
details summary { cursor: pointer; color: var(--ink-soft); font-size: var(--text-sm); }

/* --- contextual help tooltip (ui.info) ------------------------------- */
/* Scoped to span.info: ui.info() renders <span class="info">, but ui.callout('info')
   renders <div class="callout info"> — an UNscoped .info clobbered the callout into a
   1.05rem circle (the "blue circle" bug). span.info keeps the tooltip icon styling off
   the callout banner. */
span.info {
  display: inline-grid; place-items: center; width: 1.05rem; height: 1.05rem;
  border-radius: 50%; border: 1px solid var(--line); color: var(--ink-faint);
  font-size: .68rem; font-weight: 700; font-style: italic; line-height: 1;
  cursor: help; vertical-align: middle; position: relative; user-select: none;
}
span.info:hover, span.info:focus-visible { color: var(--accent); border-color: var(--accent); }
span.info::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%;
  transform: translateX(-50%); width: max-content; max-width: 16rem;
  background: var(--ink); color: var(--bg-card);
  padding: .4rem .6rem; border-radius: var(--radius-sm);
  font: 400 var(--text-xs)/1.35 var(--font-ui); font-style: normal;
  text-align: left; white-space: normal; box-shadow: var(--shadow-card);
  opacity: 0; visibility: hidden; transition: opacity .12s; z-index: 50; pointer-events: none;
}
span.info:hover::after, span.info:focus-visible::after { opacity: 1; visibility: visible; }

/* --- stat card (ui.stat: landing credibility strip + admin metrics KPIs) ------ */
.stat { display: flex; flex-direction: column; gap: var(--sp-1); }
.stat-value { font-family: var(--font-brand-display); font-weight: 500; line-height: 1.05;
              font-size: var(--text-3xl); color: var(--accent); font-feature-settings: var(--tnum); }
.stat-label { color: var(--ink); font-size: var(--text-sm); }
.stat-source { color: var(--ink-faint-2); font-size: var(--text-xs); margin-top: auto; }

/* --- stepper (ui.steps: agent job-status Submitted → Classifying → In review → Ready) --- */
.steps { list-style: none; display: flex; margin: var(--sp-4) 0; padding: 0; }
.steps .step { flex: 1; display: flex; flex-direction: column; align-items: center; gap: var(--sp-2);
               position: relative; font-size: var(--text-xs); color: var(--ink-faint); text-align: center; }
.steps .step::before { content: ""; position: absolute; top: .5rem; right: 50%; width: 100%; height: 2px;
                       background: var(--line); z-index: 0; }
.steps .step:first-child::before { display: none; }
.steps .step-dot { width: 1.1rem; height: 1.1rem; border-radius: 50%; z-index: 1;
                   background: var(--bg-card); border: 2px solid var(--line); }
.steps .step.done { color: var(--ink-soft); }
.steps .step.done::before { background: var(--accent); }
.steps .step.done .step-dot { background: var(--accent); border-color: var(--accent); }
.steps .step.current { color: var(--accent); font-weight: 600; }
.steps .step.current .step-dot { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* --- before/after results (ui.ba_results: client page + operator preview) --- */
.results-grid { display: grid; gap: var(--sp-4);
                grid-template-columns: repeat(auto-fill, minmax(min(100%, 26rem), 1fr)); }
/* Drag the divider (it IS the handle). No pan/zoom. */
.ba-slider { position: relative; aspect-ratio: 4/3; overflow: hidden; --ba-pos: 50%;
             border-radius: var(--radius-sm); background: var(--bg-inset);
             touch-action: none; cursor: ew-resize; user-select: none; }
.ba-slider:focus-visible { outline: none; box-shadow: var(--focus-ring); }
/* contain (not cover): show the WHOLE photo with no aspect-ratio crop — the inset bg fills
   any letterbox; before+after share the box so the slider overlay still lines up. */
.ba-slider img { position: absolute; inset: 0; width: 100%; height: 100%;
                 object-fit: contain; pointer-events: none; -webkit-user-drag: none; }
.ba-after { clip-path: inset(0 0 0 var(--ba-pos)); }   /* right of the divider = staged */
.ba-divider { position: absolute; top: 0; bottom: 0; left: var(--ba-pos); width: 2px;
              margin-left: -1px; background: #fff; box-shadow: 0 0 0 1px rgb(0 0 0 / .35);
              pointer-events: none; }
.ba-knob { position: absolute; top: 50%; left: 50%; width: 2.1rem; height: 2.1rem;
           transform: translate(-50%, -50%); border-radius: 50%; background: #fff;
           box-shadow: 0 1px 5px rgb(0 0 0 / .45); display: grid; place-items: center;
           color: #333; font-size: .85rem; }
.ba-tag { position: absolute; top: var(--sp-2); font-size: var(--text-xs); font-weight: 600;
          letter-spacing: .03em; background: rgb(0 0 0 / .55); color: #fff;
          padding: .1rem .5rem; border-radius: 999px; pointer-events: none; }
.ba-tag-before { left: var(--sp-2); }
.ba-tag-after { right: var(--sp-2); }
.ba-cap { margin-top: var(--sp-2); }

/* --- accessibility ---------------------------------------------------- */
/* off-screen but in the accessibility tree + tab order (NOT display:none) */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
/* skip-to-content: hidden until focused, then the first stop on every page */
.skip-link {
  position: absolute; left: var(--sp-3); top: -3.5rem; z-index: 200;
  background: var(--bg-card); color: var(--ink);
  padding: var(--sp-2) var(--sp-4); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-pop); transition: top .12s;
}
.skip-link:focus { top: var(--sp-3); outline: none; box-shadow: var(--focus-ring); }
main:focus { outline: none; }
/* keyboard focus on the (visually-hidden) file input shows on the drop label */
#drop:focus-within { border-color: var(--accent) !important; box-shadow: var(--focus-ring); }

/* --- responsive (post-M17 UX pass) ----------------------------------- */
@media (max-width: 640px) {
  main.page { padding: var(--sp-4) var(--sp-4) var(--sp-6); }
  .topbar { gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); flex-wrap: wrap; }
  .topbar nav { gap: var(--sp-3); }
  .topbar .wordmark { font-size: var(--text-md); }
  /* dense, many-column tables scroll instead of breaking the layout */
  table.list { display: block; max-width: 100%; overflow-x: auto; white-space: nowrap; }
  /* the agent jobs list is a PROSE layout table — give it the same scroll safety net
     but let its cells keep wrapping (nowrap here would force horizontal scroll). */
  .joblist { display: block; max-width: 100%; overflow-x: auto; }
  .topbar .spacer { display: none; }              /* no lopsided gap on a wrapped header (#41) */
  .breadcrumb { padding: var(--sp-2) var(--sp-4) 0; }
}
@media (pointer: coarse) {
  .ba-knob { width: 2.75rem; height: 2.75rem; }   /* comfier touch target (#41) */
  /* the agent often taps the box itself, not the label — give checkboxes and
     radios (incl. the money-committing treatment-plan consent boxes) and their
     rows a comfortable hit area on touch devices (M13.x test-run, mobile audit) */
  input[type=checkbox], input[type=radio] { width: 1.4rem; height: 1.4rem; }
  label.inline, .treatment { min-height: 2.75rem; }
}
