/* Wooden Ships admin apps: one stylesheet for Inventory Sync (stock) and Image Order Sync (photos).
 *
 * Both apps serve an identical copy of this file (a test compares the two copies byte for byte). They stay two
 * separate apps: this file and the component names are all they share.
 *
 * The page lives in an iframe inside the Shopify admin, which is light, so there is one light theme. One hue carries
 * meaning and nothing else does: red (--urgent) = a piece can sell twice, sales are not copied, photo copying stopped,
 * or the app itself stopped. Everything else is ink and grey. Links are ink and underlined.
 *
 * Contrast (WCAG 2, computed): ink 16.1:1 on white, 14.3:1 on the canvas; ink-2 8.8:1 / 7.8:1; ink-3 6.1:1 / 5.4:1;
 * urgent 6.6:1 / 5.9:1 (5.7:1 on its wash); disabled text 5.2:1 / 4.6:1; control borders 3.5:1 / 3.1:1.
 */

:root {
  color-scheme: light;

  /* surfaces */
  --canvas: #f1f1f1;        /* the admin canvas around the panels */
  --surface: #ffffff;       /* panels: a list of to-dos, a product's sections */
  --sunken: #f6f6f6;        /* the Details fold, table heads */
  --bar: #e8e8e8;           /* the preview bar only */
  --rule: #e3e3e3;          /* hairlines between rows (decorative, never the only signal) */
  --rule-strong: #8a8a8a;   /* input and button borders: 3:1 or more on white and on the canvas */

  /* ink */
  --ink: #1f2124;
  --ink-2: #474b51;
  --ink-3: #5e636a;
  --on-ink: #ffffff;
  --disabled: #686d73;

  /* the one meaning */
  --urgent: #b1271d;
  --urgent-wash: #fcebea;   /* only behind the one app-level notice */

  /* type: the system face, the one the Shopify admin around the page uses */
  --font: system-ui, -apple-system, "Segoe UI", sans-serif; /* slop-ok: the page sits inside the Shopify admin and must read as part of it */
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; /* codes in Details only */
  --fs-meta: 13px;
  --fs-body: 15px;
  --fs-subject: 17px;
  --fs-h2: 17px;
  --fs-h1: 24px;

  /* space: a 4px scale */
  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;

  /* shape: the radius follows the object */
  --r-panel: 12px;
  --r-control: 8px;
  --r-photo: 4px;

  --measure: 68ch;
  --tap: 40px;
  --t1: 120ms;
}
@media (max-width: 700px), (pointer: coarse) { :root { --tap: 44px; } }

* { box-sizing: border-box; }
html { background: var(--canvas); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--canvas); color: var(--ink);
  font: var(--fs-body)/1.5 var(--font); font-synthesis: none; -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}
h1, h2, h3, p, ul, ol, dl, dd, figure { margin: 0; }
h1, h2, h3 { text-wrap: balance; }
p, li, dd { text-wrap: pretty; }
ul, ol { padding: 0; list-style: none; }
a { color: inherit; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 2px; }
strong { font-weight: 600; }
.num, time, table { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
code, .code { font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ PreviewBar (preview only) */
.preview-bar { background: var(--bar); color: var(--ink); font-size: 14px; }
.preview-bar .frame { padding-top: var(--s2); padding-bottom: var(--s2); display: flex; flex-wrap: wrap; gap: var(--s1) var(--s4); align-items: baseline; }
.preview-bar p { flex: 1 1 22rem; }
.preview-bar a { min-height: var(--tap); display: inline-flex; align-items: center; }

/* ------------------------------------------------------------------ AppFrame */
.frame { max-width: 840px; margin: 0 auto; padding: 0 var(--s4); }
@media (min-width: 701px) { .frame { padding: 0 var(--s6); } }
main.frame { padding-bottom: var(--s7); }

/* ------------------------------------------------------------------ AppHeader: app name, nav, SearchBox */
.app-head { padding-top: var(--s4); padding-bottom: var(--s5); display: grid; gap: var(--s3); }
.app-head__row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s2) var(--s4); }
.app-name { font-weight: 600; font-size: var(--fs-body); }
.app-nav { display: flex; gap: var(--s1); }
.app-nav a { display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); padding: 0 var(--s3); border-radius: var(--r-control); text-decoration: none; color: var(--ink-2); }
.app-nav a:hover { background: var(--surface); color: var(--ink); }
.app-nav a[aria-current="page"] { color: var(--ink); font-weight: 600; background: var(--surface); }
.app-nav .count { font-variant-numeric: tabular-nums; }

.search { display: flex; gap: var(--s2); }
.search input {
  flex: 1 1 auto; min-width: 0; min-height: var(--tap); padding: 0 var(--s3);
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--rule-strong); border-radius: var(--r-control);
}
.search input::placeholder { color: var(--ink-3); opacity: 1; }

/* ------------------------------------------------------------------ PageHead */
.page-head { display: grid; gap: var(--s2); margin-bottom: var(--s5); }
.page-head h1 { font-size: var(--fs-h1); line-height: 1.25; font-weight: 600; }
.page-head .lede { color: var(--ink-2); max-width: var(--measure); }
.crumb { font-size: 14px; color: var(--ink-2); }

/* ------------------------------------------------------------------ sections and panels */
.section { margin-top: var(--s6); }
.section > h2, .group > h2 { font-size: var(--fs-h2); line-height: 1.3; font-weight: 600; margin-bottom: var(--s3); display: flex; gap: var(--s2); align-items: baseline; }
.section > h2 .n, .group > h2 .n { color: var(--ink-3); font-weight: 400; font-variant-numeric: tabular-nums; }
.section > .lede { color: var(--ink-2); margin: calc(-1 * var(--s2)) 0 var(--s3); max-width: var(--measure); }
.group { margin-top: var(--s5); }
.group:first-of-type { margin-top: 0; }
.group > h2.urgent { color: var(--urgent); }
.panel { background: var(--surface); border-radius: var(--r-panel); }
.panel > * + * { border-top: 1px solid var(--rule); }
.panel-pad { padding: var(--s4) var(--s5); }
@media (max-width: 700px) { .panel-pad { padding: var(--s4); } }
.empty-line { padding: var(--s4) var(--s5); color: var(--ink-2); }

/* ------------------------------------------------------------------ TodoItem */
.todo { padding: var(--s4) var(--s5) var(--s4); display: grid; gap: var(--s2); }
.todo-list > li + li { border-top: 1px solid var(--rule); }
@media (max-width: 700px) { .todo { padding: var(--s4); } }
.todo__top { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px var(--s4); align-items: baseline; }
.kind { font-size: 14px; font-weight: 600; color: var(--ink-2); }
.kind--urgent { color: var(--urgent); }
.kind--urgent::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--urgent); margin-right: 8px; vertical-align: 1px; }
.since { font-size: var(--fs-meta); color: var(--ink-3); }
.subject { font-size: var(--fs-subject); line-height: 1.35; font-weight: 600; }
.subject .sizes { font-weight: 400; color: var(--ink-2); }
.where { color: var(--ink-2); max-width: var(--measure); }
.problem { max-width: var(--measure); }
.fix { max-width: var(--measure); }
.fix strong { font-weight: 600; }
.or { color: var(--ink-2); max-width: var(--measure); }
.act { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s4); margin-top: var(--s1); }
.act > a:not(.btn) { min-height: var(--tap); display: inline-flex; align-items: center; }
.clears { font-size: 14px; color: var(--ink-3); max-width: var(--measure); }
.todo__foot { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 0 var(--s5); font-size: 14px; }
.todo__foot > a { min-height: var(--tap); display: inline-flex; align-items: center; }
.todo__foot details { flex: 0 1 auto; }
.todo__foot details[open] { flex-basis: 100%; }
.preview-note { font-size: 14px; color: var(--ink-3); }
.todo--fold { padding: 0; }
.todo-fold > summary { display: grid; gap: var(--s2); padding: var(--s4) var(--s5) var(--s4) calc(var(--s5) + 20px); position: relative; min-height: var(--tap); }
.todo-fold > summary::before { position: absolute; left: var(--s5); top: calc(var(--s4) + 6px); margin: 0; }
.todo-fold > summary:hover .subject { text-decoration: underline; text-underline-offset: 3px; }
.todo-fold[open] > summary { padding-bottom: var(--s2); }
.todo-body { display: grid; gap: var(--s2); padding: 0 var(--s5) var(--s4) calc(var(--s5) + 20px); }
@media (max-width: 700px) {
  .todo-fold > summary { padding: var(--s4) var(--s4) var(--s4) calc(var(--s4) + 20px); }
  .todo-fold > summary::before { left: var(--s4); }
  .todo-body { padding: 0 var(--s4) var(--s4) calc(var(--s4) + 20px); }
}

/* ------------------------------------------------------------------ buttons: OpenButton, DoButton, CopyButton */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: var(--tap); padding: 0 var(--s4);
  font: inherit; font-weight: 600; color: var(--ink); text-decoration: none; text-align: center;
  background: var(--surface); border: 1px solid var(--rule-strong); border-radius: var(--r-control);
  cursor: pointer; transition: background-color var(--t1);
}
.btn:hover { background: var(--sunken); }
.btn--do { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.btn--do:hover { background: var(--ink-2); }
.btn[disabled], .btn[aria-disabled="true"] { background: var(--sunken); border-color: var(--rule); color: var(--disabled); cursor: not-allowed; }
.btn--danger { color: var(--urgent); border-color: var(--urgent); }
.btn svg { width: 14px; height: 14px; flex: none; }
@media (max-width: 700px) {
  .act .btn { flex: 1 1 100%; }
  .search .btn { flex: none; }
}
.link-btn { font: inherit; color: inherit; background: none; border: 0; padding: 0; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; min-height: var(--tap); }

/* ------------------------------------------------------------------ DetailsFold (for Denandro) */
details > summary { cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: var(--s2); min-height: var(--tap); }
details > summary::-webkit-details-marker { display: none; }
details > summary::before {
  content: ""; width: 7px; height: 7px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg); transition: transform var(--t1); flex: none; margin-right: 2px;
}
details[open] > summary::before { transform: rotate(45deg); }
.fold > summary { color: var(--ink-2); }
.fold[open] > summary { color: var(--ink); }
.fold-body { background: var(--sunken); border-radius: var(--r-control); padding: var(--s3) var(--s4); margin-top: var(--s1); display: grid; gap: var(--s3); font-size: 14px; }
.kv { display: grid; grid-template-columns: minmax(8rem, 13rem) 1fr; gap: 6px var(--s4); }
.kv dt { color: var(--ink-2); }
.kv dd { min-width: 0; }
@media (max-width: 520px) { .kv { grid-template-columns: 1fr; gap: 0; } .kv dd { margin-bottom: var(--s2); } }
.cmd { display: block; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-control); padding: var(--s2) var(--s3); white-space: pre-wrap; }
.big-fold { margin-top: var(--s6); }
.big-fold > summary { font-size: var(--fs-h2); font-weight: 600; color: var(--ink); }
.big-fold .fold-body { font-size: var(--fs-body); }
.fold-body h3 { font-size: var(--fs-body); font-weight: 600; }

/* ------------------------------------------------------------------ CheckPanel ("All OK?") and DoneToday */
.check { padding: var(--s4) var(--s5); display: grid; gap: var(--s3); }
@media (max-width: 700px) { .check { padding: var(--s4); } }
.verdict { font-size: var(--fs-subject); }
.verdict--no strong { color: var(--urgent); }
.facts { display: grid; gap: var(--s2); }
.facts li { display: grid; grid-template-columns: 1.1rem 1fr; gap: 0 var(--s1); color: var(--ink); }
.facts li::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--ink-3); margin-top: 0.62em; }
.facts .bad { color: var(--urgent); }
.done-list { display: grid; gap: var(--s2); }
.done-list li, .entry { display: grid; grid-template-columns: 4.5rem 1fr; gap: 0 var(--s3); }
.done-list time, .entry time { color: var(--ink-3); font-size: 14px; padding-top: 1px; }

/* ------------------------------------------------------------------ AppNotice (app-level, red) */
.notice { background: var(--urgent-wash); border-radius: var(--r-panel); padding: var(--s4) var(--s5); display: grid; gap: var(--s2); margin-bottom: var(--s5); }
.notice h2 { color: var(--urgent); font-size: var(--fs-subject); font-weight: 600; }
.notice h2::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--urgent); margin-right: 8px; vertical-align: 2px; }
.notice p { max-width: var(--measure); }

/* ------------------------------------------------------------------ ResultList (Find) */
.result { padding: var(--s4) var(--s5); display: grid; grid-template-columns: auto 1fr; gap: 2px var(--s4); align-items: start; }
.result.no-thumb { grid-template-columns: 1fr; }
@media (max-width: 700px) { .result { padding: var(--s4); } }
.result .name { font-size: var(--fs-subject); font-weight: 600; }
.result .name a { text-decoration-thickness: 1px; }
.result .why, .result .meta { color: var(--ink-2); }
.result .todo-count { font-weight: 600; }
.result .todo-count.urgent { color: var(--urgent); }

/* ------------------------------------------------------------------ ProductHead, PageList, OtherAppLink */
.facts-line { color: var(--ink-2); }
.pages-list .page { padding: var(--s3) var(--s5); display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--s1) var(--s4); align-items: center; }
@media (max-width: 700px) { .pages-list .page { padding: var(--s3) var(--s4); } }
.page .p-name { font-weight: 600; }
.page .p-meta { color: var(--ink-2); font-size: 14px; }
.page .p-links { display: flex; gap: var(--s4); font-size: 14px; }
.page .p-links a { min-height: var(--tap); display: inline-flex; align-items: center; }
.other-app { padding: var(--s4) var(--s5); display: flex; flex-wrap: wrap; gap: var(--s3) var(--s4); align-items: center; justify-content: space-between; }
@media (max-width: 700px) { .other-app { padding: var(--s4); } .other-app .btn { flex: 1 1 100%; } }

/* ------------------------------------------------------------------ StockTable (stock app) */
.color-block { padding: var(--s4) var(--s5); display: grid; gap: var(--s3); }
@media (max-width: 700px) { .color-block { padding: var(--s4); } }
.color-block h3 { font-size: var(--fs-subject); font-weight: 600; }
.color-block .c-line { color: var(--ink-2); max-width: var(--measure); }
.table-wrap { overflow-x: auto; }
table.stock { border-collapse: collapse; width: 100%; max-width: 560px; font-size: var(--fs-body); }
table.stock th, table.stock td { text-align: right; padding: 6px var(--s3); border-bottom: 1px solid var(--rule); white-space: nowrap; }
table.stock th:first-child, table.stock td:first-child { text-align: left; padding-left: 0; }
table.stock thead th { font-weight: 600; color: var(--ink-2); font-size: 14px; white-space: normal; vertical-align: bottom; }
table.stock tfoot td { font-weight: 600; border-bottom: 0; }
table.stock td.dash { color: var(--ink-3); }

/* ------------------------------------------------------------------ PhotoStrip and OrderChoice (photo app) */
.strip { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: flex-start; }
.ph { display: grid; gap: 2px; justify-items: center; width: 64px; }
.ph img { width: 64px; height: 80px; object-fit: cover; border-radius: var(--r-photo); background: var(--sunken); display: block; }
.ph figcaption { font-size: var(--fs-meta); color: var(--ink-3); font-variant-numeric: tabular-nums; }
.ph.moved img { outline: 2px solid var(--ink); outline-offset: 2px; }
.ph.moved figcaption { color: var(--ink); font-weight: 600; }
.strip .rest { font-size: 14px; color: var(--ink-3); align-self: center; max-width: 9rem; }
@media (max-width: 700px) { .ph { width: 52px; } .ph img { width: 52px; height: 65px; } }

.choice { border: 0; padding: 0; margin: var(--s1) 0 0; display: grid; gap: var(--s2); min-width: 0; }
.choice .opt { display: grid; grid-template-columns: auto auto auto 1fr; gap: var(--s1) var(--s3); align-items: center; padding: var(--s2) var(--s3); border: 1px solid var(--rule); border-radius: var(--r-control); cursor: pointer; }
.choice .opt:has(input:checked) { border-color: var(--ink); outline: 1px solid var(--ink); outline-offset: -2px; }
.choice .opt input { width: 20px; height: 20px; margin: 0; accent-color: var(--ink); }
.choice .o-letter { font-weight: 600; min-width: 1ch; }
.choice .o-pages { color: var(--ink-2); font-size: 14px; }
.choice .o-same { font-size: 14px; color: var(--ink-3); }
@media (max-width: 700px) {
  .choice .opt { grid-template-columns: auto auto 1fr; }
  .choice .opt .strip { grid-column: 3; }
  .choice .opt .o-pages { grid-column: 1 / -1; }
}
.strip--small .ph { width: 48px; }
.strip--small .ph img { width: 48px; height: 60px; }
@media (max-width: 700px) { .strip--small .ph { width: 44px; } .strip--small .ph img { width: 44px; height: 55px; } }
.group-note { color: var(--ink-2); margin: calc(-1 * var(--s1)) 0 var(--s3); max-width: var(--measure); }

.photo-row { display: grid; grid-template-columns: auto 1fr; gap: var(--s1) var(--s3); align-items: start; padding: var(--s3) 0; }
.photo-row + .photo-row { border-top: 1px solid var(--rule); }
.photo-row img { width: 48px; height: 60px; object-fit: cover; border-radius: var(--r-photo); background: var(--sunken); }
.photo-row .r-text { display: grid; gap: 2px; }
.photo-row .r-state { font-weight: 600; }
.photo-row .r-pages { color: var(--ink-2); font-size: 14px; }

/* ------------------------------------------------------------------ History */
.filters { display: flex; flex-wrap: wrap; gap: var(--s2); margin-bottom: var(--s4); }
.filters a { min-height: var(--tap); display: inline-flex; align-items: center; padding: 0 var(--s3); border: 1px solid var(--rule-strong); border-radius: var(--r-control); text-decoration: none; background: var(--surface); }
.filters a[aria-current="true"] { background: var(--ink); border-color: var(--ink); color: var(--on-ink); font-weight: 600; }
.day { margin-top: var(--s5); }
.day > h2 { font-size: var(--fs-h2); font-weight: 600; margin-bottom: var(--s3); }
.entries .entry { padding: var(--s3) var(--s5); }
@media (max-width: 700px) { .entries .entry { padding: var(--s3) var(--s4); grid-template-columns: 3.6rem 1fr; } }
.entry .e-text { display: grid; gap: var(--s2); }
.entries--dated .entry { grid-template-columns: 6.5rem 1fr; }
@media (max-width: 700px) { .entries--dated .entry { grid-template-columns: 5.2rem 1fr; } }
.entry .e-note { color: var(--ink-2); font-size: 14px; }
.entry .e-todo { font-size: 14px; font-weight: 600; }
.entry .e-todo.urgent { color: var(--urgent); }
.before-after { display: grid; gap: var(--s2); }
.before-after .ba-label { font-size: 14px; color: var(--ink-2); }
.more { margin-top: var(--s4); }

/* ------------------------------------------------------------------ StateBlock */
.state { padding: var(--s5); display: grid; gap: var(--s2); justify-items: start; }
@media (max-width: 700px) { .state { padding: var(--s4); } }
.state h2 { font-size: var(--fs-subject); font-weight: 600; }
.state p { color: var(--ink-2); max-width: var(--measure); }
.loading-line { color: var(--ink-2); padding: var(--s5); }
.dimmed { opacity: .6; }

/* ------------------------------------------------------------------ mock-only caption (not part of the design) */
.mock-note { max-width: 840px; margin: var(--s6) auto 0; padding: var(--s4) var(--s4) var(--s6); font-size: 13px; color: var(--ink-3); border-top: 1px dashed var(--rule-strong); }
@media (min-width: 701px) { .mock-note { padding-left: var(--s6); padding-right: var(--s6); } }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
