/* Image Order Sync - admin dashboard.
 *
 * Hand-written rather than Polaris: this project carries zero runtime dependencies on purpose, and pulling in
 * React + Polaris for a read-only page would end that and add a build step. So: the admin's visual language,
 * expressed in ~400 lines of CSS, no framework, no build.
 *
 * Status colours were validated, not chosen by eye (dataviz six-checks, both modes). Two notes for whoever
 * revisits them:
 *   - "Waiting for you" is BLUE, not amber. It is a task, not a warning, and amber-vs-red is the one pair that
 *     red-green colourblind readers genuinely cannot separate (deutan dE 2.5). Blue-vs-red passes.
 *   - "Paused" is deliberately grey and will always fail a chroma floor. Grey IS the meaning. Every badge also
 *     carries a text label and its own icon shape, so colour is never the only signal.
 */

:root {
  color-scheme: light dark;

  --surface: #ffffff;
  --surface-sunken: #f6f6f7;
  --surface-raised: #ffffff;
  --border: #e1e3e5;
  --border-strong: #c9cccf;
  --ink: #1a1c1d;
  --ink-muted: #5b5f63;

  --good: #0b6b45;
  --attention: #2251c9;
  --bad: #c02617;
  --muted: #5b5f63;

  --good-bg: #e7f4ee;
  --attention-bg: #e8eefc;
  --bad-bg: #fdeceb;
  --muted-bg: #f0f1f2;

  --chart: #454b57;
  --chart-soft: #d7dade;

  --focus: #2251c9;
  --radius: 10px;
  --radius-sm: 6px;
  --gutter: 16px;
  --maxw: 1040px;

  --shadow: 0 1px 2px rgb(26 28 29 / 8%), 0 0 0 1px rgb(26 28 29 / 4%);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --surface: #16181a;
    --surface-sunken: #1f2225;
    --surface-raised: #1f2225;
    --border: #2e3235;
    --border-strong: #3d4246;
    --ink: #e9eaeb;
    --ink-muted: #9aa0a6;

    --good: #4fc48f;
    --attention: #7aa2f7;
    --bad: #ff8f84;
    --muted: #9aa0a6;

    --good-bg: #16302554;
    --attention-bg: #1b2a4a54;
    --bad-bg: #3a1e1b54;
    --muted-bg: #2a2e3154;

    --chart: #aab3c0;
    --chart-soft: #32373c;

    --focus: #7aa2f7;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 0 0 1px rgb(255 255 255 / 6%);
  }
}

:root[data-theme="dark"] {
  --surface: #16181a;
  --surface-sunken: #1f2225;
  --surface-raised: #1f2225;
  --border: #2e3235;
  --border-strong: #3d4246;
  --ink: #e9eaeb;
  --ink-muted: #9aa0a6;
  --good: #4fc48f;
  --attention: #7aa2f7;
  --bad: #ff8f84;
  --muted: #9aa0a6;
  --good-bg: #16302554;
  --attention-bg: #1b2a4a54;
  --bad-bg: #3a1e1b54;
  --muted-bg: #2a2e3154;
  --chart: #aab3c0;
  --chart-soft: #32373c;
  --focus: #7aa2f7;
  --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 0 0 1px rgb(255 255 255 / 6%);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--surface-sunken);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0; }

a { color: var(--attention); }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }

/* ---------------------------------------------------------------- masthead & tabs */

.masthead {
  display: flex; align-items: center; gap: 14px;
  max-width: var(--maxw); margin: 0 auto; padding: 20px var(--gutter) 12px;
}
.masthead .mark { height: 26px; width: auto; flex: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .masthead .mark { filter: invert(1) brightness(1.6); } }
:root[data-theme="dark"] .masthead .mark { filter: invert(1) brightness(1.6); }
.sub { color: var(--ink-muted); font-size: 13px; }

/* Not sticky: inside the admin's iframe the app is sized to its content and the ADMIN does the scrolling, so
 * a sticky bar either never sticks or floats over the content. Plain flow is predictable. */
.tabs {
  display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none;
  max-width: var(--maxw); margin: 0 auto; padding: 0 var(--gutter);
  background: var(--surface-sunken); border-bottom: 1px solid var(--border);
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  flex: none; appearance: none; background: none; border: 0; cursor: pointer;
  padding: 10px 12px; font: inherit; font-weight: 550; color: var(--ink-muted);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }

main { max-width: var(--maxw); margin: 0 auto; padding: var(--gutter) var(--gutter) 48px; }
.loading { color: var(--ink-muted); padding: 32px 0; }

/* ---------------------------------------------------------------- cards */

.card {
  background: var(--surface-raised); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px;
}
.card > header { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card .hint { color: var(--ink-muted); font-size: 13px; }

.headline { display: flex; gap: 14px; align-items: flex-start; padding: 18px; }
.headline .dot { width: 12px; height: 12px; border-radius: 50%; margin-top: 5px; flex: none; }
.headline h2 { font-size: 18px; margin-bottom: 2px; }
.headline p { color: var(--ink-muted); }
.tone-good .dot { background: var(--good); }
.tone-attention .dot { background: var(--attention); }
.tone-bad .dot { background: var(--bad); }
.tone-muted .dot { background: var(--muted); }
.tone-info .dot { background: var(--attention); }

/* ---------------------------------------------------------------- stat tiles */

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 12px; }
.tile { background: var(--surface-raised); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.tile .n { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile .k { color: var(--ink-muted); font-size: 13px; margin-top: 2px; }
.tile.is-good .n { color: var(--good); }
.tile.is-attention .n { color: var(--attention); }
.tile.is-bad .n { color: var(--bad); }

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

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px 2px 6px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge svg { width: 12px; height: 12px; flex: none; }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.attention { background: var(--attention-bg); color: var(--attention); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.muted { background: var(--muted-bg); color: var(--muted); }
.badge.info { background: var(--attention-bg); color: var(--attention); }

/* ---------------------------------------------------------------- history */

.event { background: var(--surface-raised); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.event > header { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px; margin-bottom: 4px; }
.event .colour { font-weight: 650; font-size: 15px; }
.event .style { color: var(--ink-muted); font-family: var(--mono); font-size: 12px; }
.event .when { margin-left: auto; color: var(--ink-muted); font-size: 13px; white-space: nowrap; }
.event .why { color: var(--ink-muted); font-size: 13px; margin-bottom: 12px; }
.event .why strong { color: var(--ink); font-weight: 600; }

.strip { display: grid; grid-template-columns: 64px 1fr; gap: 10px; align-items: center; margin-bottom: 8px; }
.strip .lbl { color: var(--ink-muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.shots { display: flex; gap: 6px; flex-wrap: wrap; }

.shot { position: relative; width: 52px; height: 66px; border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-sunken); border: 1px solid var(--border); }
.shot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.shot .pos {
  position: absolute; left: 3px; top: 3px; min-width: 16px; height: 16px; padding: 0 3px;
  border-radius: 4px; background: rgb(0 0 0 / 66%); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 16px; text-align: center; font-variant-numeric: tabular-nums;
}
.shot.moved { border-color: var(--attention); box-shadow: 0 0 0 2px var(--attention); }
.shot.lead::after {
  content: "1st"; position: absolute; right: 0; bottom: 0;
  background: var(--ink); color: var(--surface); font-size: 9px; font-weight: 700;
  padding: 1px 4px; border-top-left-radius: 5px; letter-spacing: 0.02em;
}
.shot.gone { opacity: 0.45; }
.shot.unknown { display: grid; place-items: center; color: var(--ink-muted); font-size: 11px; font-variant-numeric: tabular-nums; }

.followed { border-top: 1px solid var(--border); margin-top: 12px; padding-top: 10px; font-size: 13px; color: var(--ink-muted); }
.followed ul { margin: 6px 0 0; padding-left: 18px; }
.followed li { margin: 1px 0; }

/* ---------------------------------------------------------------- activity chart */

.chart { display: block; width: 100%; height: 88px; overflow: visible; }
.chart .bar { fill: var(--chart); }
.chart .bar-hit { fill: transparent; cursor: default; }
.chart .bar-hit:hover + .bar, .chart .bar-hit:focus-visible + .bar { fill: var(--attention); }
.chart .base { stroke: var(--border-strong); stroke-width: 1; }
.chart-x { display: flex; justify-content: space-between; color: var(--ink-muted); font-size: 11px; margin-top: 4px; }

/* ---------------------------------------------------------------- tables & lists */

.rows { display: flex; flex-direction: column; gap: 1px; background: var(--border); border-radius: var(--radius); overflow: hidden; }
.row {
  display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center;
  background: var(--surface-raised); padding: 10px 14px; text-align: left;
  border: 0; font: inherit; color: inherit; width: 100%; cursor: pointer;
}
.row:hover { background: var(--surface-sunken); }
.row .name { font-weight: 600; }
.row .meta { color: var(--ink-muted); font-size: 12px; }

.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  appearance: none; border: 1px solid var(--border-strong); background: var(--surface-raised);
  color: var(--ink-muted); border-radius: 999px; padding: 4px 11px; font: inherit; font-size: 13px;
  font-weight: 550; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--ink); color: var(--surface); border-color: var(--ink); }

dl.kv { display: grid; grid-template-columns: minmax(140px, auto) 1fr; gap: 6px 16px; margin: 0; }
dl.kv dt { color: var(--ink-muted); }
dl.kv dd { margin: 0; }
dl.kv dd.mono { font-family: var(--mono); font-size: 12px; word-break: break-all; }

details.faq { border-top: 1px solid var(--border); padding: 12px 0; }
details.faq:first-of-type { border-top: 0; }
details.faq summary { cursor: pointer; font-weight: 600; list-style-position: outside; }
details.faq p { color: var(--ink-muted); margin-top: 8px; }

.note { background: var(--attention-bg); color: var(--ink); border-radius: var(--radius-sm); padding: 12px 14px; font-size: 13px; }
.note.bad { background: var(--bad-bg); }

.empty { color: var(--ink-muted); padding: 28px 0; text-align: center; }

.foot {
  max-width: var(--maxw); margin: 0 auto; padding: 0 var(--gutter) 28px;
  display: flex; justify-content: space-between; gap: 12px;
  color: var(--ink-muted); font-size: 12px;
}
.link { appearance: none; background: none; border: 0; padding: 0; font: inherit; color: var(--attention); cursor: pointer; text-decoration: underline; }

@media (max-width: 560px) {
  .strip { grid-template-columns: 1fr; gap: 4px; }
  .event .when { margin-left: 0; width: 100%; }
  dl.kv { grid-template-columns: 1fr; gap: 2px 0; }
  dl.kv dd { margin-bottom: 8px; }
}

@media (prefers-reduced-motion: no-preference) {
  .row, .chip, .tabs button { transition: background-color 120ms ease, color 120ms ease; }
}

.section-title { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-muted); }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar .filters { margin-bottom: 0; }
.search {
  flex: 1 1 200px; min-width: 160px; appearance: none;
  border: 1px solid var(--border-strong); background: var(--surface-raised); color: var(--ink);
  border-radius: var(--radius-sm); padding: 6px 10px; font: inherit; font-size: 13px;
}
.search::placeholder { color: var(--ink-muted); }
.more { margin-top: 12px; text-align: center; }

/* the label glossary: each badge needs air above it and its explanation close beneath */
.faq .badge { margin-bottom: 6px; }
.faq + .faq { margin-top: 14px; }
