/* ============================================================
   Order tracker demo. Uses the same colour tokens as site.css.
   Opens full screen on phones, as a large panel on desktop.
   ============================================================ */

html.tk-lock, html.tk-lock body { overflow: hidden; }

.tk {
  width: 100%; max-width: 100%;
  height: 100%; max-height: 100%;
  height: 100dvh; max-height: 100dvh;
  margin: 0; padding: 0; border: 0;
  background: var(--paper);
  color: var(--text);
}
.tk::backdrop { background: rgba(0, 0, 0, .55); }
.tk[open] { display: block; }

.tk-shell { position: relative; height: 100%; display: flex; flex-direction: column; }

/* ---------- top bar ---------- */
.tk-bar {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) 16px 12px;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
}
.tk-title { font-size: 1.35rem; line-height: 1.2; }
.tk-sub { font-size: .82rem; color: var(--muted); margin-top: 2px; }
.tk-close {
  flex: none; width: 44px; height: 44px; margin: -4px -6px 0 0;
  display: grid; place-items: center;
  background: transparent; border: 0; color: var(--ink); cursor: pointer; border-radius: 2px;
}
.tk-close svg { width: 22px; height: 22px; }

.tk-scroll {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 16px 16px max(28px, env(safe-area-inset-bottom));
}

/* ---------- pipeline: how many orders sit at each stage ---------- */
.tk-pipe {
  display: grid; grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--rule); border-radius: 2px; overflow: hidden;
}
.tk-pipe-stage {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  min-height: 64px; padding: 10px 10px 9px;
  background: var(--paper); color: var(--ink);
  border: 0; border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule);
  font: inherit; text-align: left; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tk-pipe-stage:nth-child(3n) { border-right: 0; }
.tk-pipe-stage:nth-child(n+4) { border-bottom: 0; }
.tk-pipe-n { font-family: var(--serif); font-weight: 600; font-size: 1.5rem; line-height: 1; font-variant-numeric: tabular-nums; }
.tk-pipe-name { font-size: .78rem; color: var(--muted); line-height: 1.2; }
.tk-pipe-stage.is-on { background: var(--ink); color: var(--paper); }
.tk-pipe-stage.is-on .tk-pipe-name { color: #d8d5cf; }

/* ---------- filters ---------- */
.tk-filters { margin-top: 14px; display: grid; gap: 10px; }
.tk-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.tk-chip {
  min-height: 40px; padding: 8px 14px;
  border: 1.5px solid var(--rule); border-radius: 999px;
  background: var(--paper); color: var(--ink);
  font: 500 .88rem/1.2 var(--sans); cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tk-chip.is-on { border-color: var(--ink); background: var(--ink); color: var(--paper); }
.tk-select select {
  width: 100%; min-height: 44px; padding: 8px 12px;
  border: 1.5px solid var(--rule); border-radius: 2px;
  background: var(--paper); color: var(--ink);
  font: 400 1rem/1.2 var(--sans);   /* 16px stops iPhones zooming in on tap */
}

.tk-count { margin-top: 16px; font-size: .88rem; color: var(--muted); }

/* ---------- order list ---------- */
.tk-list { list-style: none; margin: 8px 0 0; padding: 0; }
.tk-row {
  display: grid; gap: 4px; width: 100%;
  padding: 14px 0; border: 0; border-bottom: 1px solid var(--rule);
  background: transparent; color: inherit; text-align: left; font: inherit; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
@media (hover: hover) {
  .tk-row:hover .tk-row-item { text-decoration: underline; text-underline-offset: 3px; }
}
.tk-row-top { display: flex; justify-content: space-between; gap: 12px; font-size: .82rem; color: var(--muted); }
.tk-row-value { color: var(--ink); font-weight: 500; font-variant-numeric: tabular-nums; }
.tk-row-item { font-family: var(--serif); font-weight: 600; font-size: 1.05rem; color: var(--ink); line-height: 1.3; }
.tk-row-meta { font-size: .86rem; color: var(--muted); line-height: 1.35; }
.tk-row-bottom { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.tk-row-stage { font-size: .84rem; color: var(--text); }
.tk-row-flags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }

/* six small bars: filled = stage done */
.tk-steps { display: inline-flex; gap: 3px; }
.tk-step { width: 14px; height: 5px; background: var(--rule); border-radius: 1px; }
.tk-step.is-done { background: var(--ink); }

/* flags */
.tk-flag {
  display: inline-block; padding: 3px 8px; border-radius: 2px;
  font-size: .78rem; font-weight: 500; line-height: 1.3;
}
.tk-flag-late { background: var(--orange); color: #fff; }
.tk-flag-risk { border: 1.5px solid var(--orange); color: var(--orange-ink); padding: 2px 7px; }
.tk-flag-exception { background: var(--ink); color: #fff; }

.tk-empty { padding: 28px 0; color: var(--muted); }
.tk-link { margin-top: 8px; padding: 8px 0; background: none; border: 0; color: var(--ink); font: 500 1rem var(--sans); text-decoration: underline; cursor: pointer; }

/* ---------- order detail: slides over the list ---------- */
.tk-detail {
  position: absolute; inset: 0; z-index: 2;
  display: flex; flex-direction: column;
  background: var(--paper);
  animation: tk-in .2s ease-out;
}
.tk-detail[hidden] { display: none; }
@keyframes tk-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }

.tk-detail-head {
  padding: max(10px, env(safe-area-inset-top)) 8px 8px;
  border-bottom: 1px solid var(--rule);
}
.tk-back {
  min-height: 44px; padding: 8px 10px 8px 26px; position: relative;
  background: none; border: 0; color: var(--ink); font: 500 .95rem var(--sans); cursor: pointer;
}
.tk-back::before {
  content: ""; position: absolute; left: 12px; top: 50%;
  width: 9px; height: 9px; border-left: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: translateY(-50%) rotate(45deg);
}
.tk-detail-body {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  padding: 18px 16px max(32px, env(safe-area-inset-bottom));
}
.tk-d-id { font-size: .82rem; color: var(--muted); white-space: pre; }
.tk-d-item { font-size: 1.5rem; line-height: 1.2; margin-top: 4px; }
.tk-d-meta { margin-top: 6px; color: var(--muted); }
.tk-d-flags { margin-top: 12px; }

.tk-issue { margin-top: 16px; padding: 12px 14px; background: var(--stone); border-left: 3px solid var(--ink); }
.tk-issue-title { font-weight: 600; color: var(--ink); margin-bottom: 4px; }

.tk-facts { margin: 20px 0 0; border-top: 1px solid var(--rule); }
.tk-facts > div { display: grid; grid-template-columns: 9.5rem 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--rule); }
.tk-facts dt { color: var(--muted); font-size: .9rem; }
.tk-facts dd { margin: 0; color: var(--ink); font-variant-numeric: tabular-nums; }

/* trail: same idea as the line on the main page */
.tk-trail-title { margin-top: 26px; font-family: var(--serif); font-size: 1.15rem; }
.tk-trail { list-style: none; margin: 14px 0 0; padding: 0 0 0 22px; position: relative; }
.tk-trail::before { content: ""; position: absolute; left: 5px; top: 6px; bottom: 6px; width: 2px; background: var(--rule); }
.tk-trail li { position: relative; padding: 0 0 16px; display: grid; gap: 2px; }
.tk-trail li:last-child { padding-bottom: 0; }
.tk-trail li::before {
  content: ""; position: absolute; left: -22px; top: 4px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--paper); border: 2px solid var(--rule); box-sizing: border-box;
}
.tk-trail li.is-done::before { background: var(--orange); border-color: var(--orange); }
.tk-trail li.is-next::before { border-color: var(--orange); }
.tk-trail-name { font-weight: 500; color: var(--ink); }
.tk-trail li:not(.is-done):not(.is-next) .tk-trail-name { color: var(--muted); }
.tk-trail-note { font-size: .88rem; color: var(--muted); }

/* ---------- preview card on the main page ---------- */
button.system-frame.tk-preview {
  display: block; width: 100%; padding: 14px; cursor: pointer; text-align: left;
  aspect-ratio: auto; min-height: 0;
  font: inherit; color: inherit; background: var(--paper);
  -webkit-tap-highlight-color: transparent;
}
button.system-frame.tk-preview:disabled { cursor: default; }
button.system-frame.tk-preview:not(:disabled):hover { border-color: var(--ink); }
.tk-preview-inner { display: flex; flex-direction: column; height: 100%; gap: 10px; }
.pv-pipe { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.pv-stage { background: var(--stone); padding: 6px 4px 6px 6px; display: grid; gap: 2px; min-width: 0; overflow: hidden; }
.pv-n { font-family: var(--serif); font-weight: 600; font-size: 1.05rem; color: var(--ink); line-height: 1; }
.pv-name { font-size: clamp(.54rem, 2.6vw, .66rem); color: var(--muted); line-height: 1.15; }
.pv-rows { display: grid; gap: 0; }
.pv-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 1px solid var(--rule); }
.pv-item { font-size: .82rem; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.pv-row .tk-flag { flex: none; font-size: .68rem; padding: 2px 6px; }
.pv-row .tk-flag-risk { padding: 1px 5px; }
.pv-foot { margin-top: 4px; font-size: .75rem; color: var(--muted); }

/* ---------- wider screens ---------- */
@media (min-width: 600px) {
  .tk-pipe { grid-template-columns: repeat(6, 1fr); }
  .tk-pipe-stage { border-bottom: 0; }
  .tk-pipe-stage:nth-child(3n) { border-right: 1px solid var(--rule); }
  .tk-pipe-stage:last-child { border-right: 0; }
  .tk-filters { grid-template-columns: 1fr 14rem; align-items: center; }
}

@media (min-width: 900px) {
  .tk {
    width: min(960px, calc(100% - 64px)); height: min(820px, calc(100dvh - 64px));
    margin: auto; border-radius: 4px; overflow: hidden;
  }
  .tk-bar { padding: 18px 24px 14px; }
  .tk-scroll { padding: 20px 24px 32px; }
  .tk-detail-body { padding: 22px 24px 36px; }
  .tk-detail-body > * { max-width: 40rem; }
}

@media (prefers-reduced-motion: reduce) {
  .tk-detail { animation: none; }
}
