/* Server-rendered tracking results — styled with the design's tokens (site.css :root).
   Layout follows the legacy production page: status header + action buttons, a status table
   with a clickable location, image popups and a branch-details popup. */

/* Slim page header (replaces the photo banner) */
.trk-pagehead {
  background: linear-gradient(120deg, var(--red-900), var(--red));
  color: #fff;
  padding: 44px 0 36px;
}
.trk-pagehead h1 { color: #fff; font-size: clamp(26px, 3vw, 38px); }
.trk-pagehead h1 .hl { color: #FFD9C2; }
.trk-pagehead .lede { margin-top: 10px; color: rgba(255, 255, 255, .9); font-size: 16px; max-width: 620px; }

.track-results { display: grid; gap: 20px; }

.track-result-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px 22px;
}

.track-result-card.not-found { text-align: center; color: var(--muted); }
.trk-msg { color: var(--muted); font-size: 15px; }

/* Header: consignment number + current status on the left, action buttons on the right */
.trk-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 16px;
  padding-bottom: 16px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--line);
}
.trk-no { display: flex; flex-direction: column; gap: 3px; }
.trk-label { font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-family: var(--h); }
.trk-no > b { font-family: var(--h); font-size: 20px; color: var(--ink); letter-spacing: .01em; }
.trk-ref { font-size: 13px; color: var(--muted); }
.trk-current { font-family: var(--h); font-weight: 700; font-size: 13.5px; color: var(--orange-600); margin-top: 2px; }

.trk-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.btn-trk {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--ink); color: #fff;
  border: 0; border-radius: 999px;
  padding: 9px 16px;
  font-family: var(--h); font-weight: 700; font-size: 12.5px;
  cursor: pointer; transition: background .2s ease, transform .2s ease;
}
.btn-trk:hover { background: #000; transform: translateY(-1px); }
.btn-trk svg { opacity: .9; }

/* Status table */
.trk-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; }
.trk-table { width: 100%; border-collapse: collapse; font-size: 13px; background: #fff; }
.trk-table thead { background: var(--orange); color: #fff; }
.trk-table th {
  text-align: left; font-family: var(--h); font-weight: 700; font-size: 12px;
  letter-spacing: .02em; padding: 11px 14px;
}
.trk-table td { padding: 11px 14px; border-top: 1px solid var(--line); color: var(--ink-2); vertical-align: top; }
.trk-table tbody tr:nth-child(even) { background: var(--bg); }
.trk-table tbody tr:first-child td { font-weight: 500; }

.trk-loc {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--orange-600); font: inherit; text-align: left; text-decoration: underline;
  text-underline-offset: 2px;
}
.trk-loc:hover { color: var(--orange); }

.trk-print { margin-top: 16px; text-align: right; }
.trk-print .btn { gap: 7px; }

/* ---------- Modals (branch details + image) ---------- */
.trk-modal {
  border: 0; border-radius: var(--radius); padding: 0;
  width: min(640px, calc(100% - 32px)); max-height: 90vh;
  box-shadow: var(--shadow-lg); color: var(--ink-2);
}
.trk-modal::backdrop { background: rgba(23, 23, 23, .5); backdrop-filter: blur(2px); }
.trk-modal-in { padding: 28px; position: relative; }
.trk-modal-x {
  position: absolute; top: 14px; right: 16px;
  background: none; border: 0; font-size: 26px; line-height: 1;
  color: var(--muted); cursor: pointer;
}
.trk-modal-x:hover { color: var(--ink); }
.trk-modal h2 { font-size: 22px; color: var(--ink); }
.trk-modal-sub { color: var(--muted); font-size: 13.5px; margin: 6px 0 18px; }
.trk-modal-sub b { color: var(--red); display: block; margin-top: 2px; }
.trk-modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }

.trk-modal-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 18px; }
.trk-f { display: flex; flex-direction: column; gap: 3px; }
.trk-f.wide { grid-column: 1 / -1; }
.trk-f span { font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-family: var(--h); }
.trk-f b { font-weight: 500; color: var(--ink); font-size: 14px; word-break: break-word; }
.trk-modal-loading, .trk-modal-err { margin-top: 14px; font-size: 14px; }
.trk-modal-err { color: var(--red); }

.trk-img-box { text-align: center; max-height: 70vh; overflow: auto; }
.trk-img-box img { max-width: 100%; height: auto; display: inline-block; }

@media (max-width: 640px) {
  .trk-modal-grid { grid-template-columns: 1fr; }
  .trk-no > b { font-size: 17px; word-break: break-word; }
  .trk-modal-in { padding: 22px 16px; }
}

/* ---------- Mobile: stop horizontal scroll; stack header and turn the table into cards ---------- */
@media (max-width: 700px) {
  .trk-pagehead { padding: 30px 0 24px; }

  .track-result-card { padding: 16px 14px; }

  /* Header stacks: consignment info, then action buttons full-width */
  .trk-head { flex-direction: column; align-items: stretch; gap: 12px; }
  .trk-current { font-size: 13px; }
  .trk-actions { width: 100%; }
  .btn-trk { flex: 1 1 auto; justify-content: center; }

  /* Table -> stacked cards (one block per scan event). Collapsed by default: Event + Date only.
     Tapping the row reveals Transaction Number and Location. */
  .trk-table-wrap { border: 0; overflow: visible; }
  .trk-table { font-size: 13px; }
  .trk-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); } /* hide header row */
  .trk-table tbody tr {
    display: block;
    position: relative;
    border: 1px solid var(--line);
    border-left: 3px solid var(--orange);
    border-radius: 10px;
    padding: 12px 38px 12px 14px;   /* right padding leaves room for the chevron */
    margin-bottom: 10px;
    background: #fff;
    cursor: pointer;
  }
  .trk-table tbody tr:nth-child(even) { background: #fff; }

  .trk-table tbody td {
    display: block;
    border: 0;
    padding: 0;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  /* Event (col 4) is the headline; Date (col 1) sits under it. Both always visible. */
  .trk-table tbody td[data-label="Event"] {
    font-family: var(--h);
    font-weight: 700;
    font-size: 14px;
    color: var(--ink);
    line-height: 1.35;
  }
  .trk-table tbody tr:first-child td[data-label="Event"] { color: var(--orange-600); }
  .trk-table tbody td[data-label="Date"] {
    font-size: 12px;
    color: var(--muted);
    margin-top: 4px;
  }

  /* Transaction Number + Location: hidden until the row is expanded. */
  .trk-table tbody td[data-label="Transaction No."],
  .trk-table tbody td[data-label="Location"] {
    display: none;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed var(--line);
    font-size: 12.5px;
  }
  .trk-table tbody td[data-label="Transaction No."]::before,
  .trk-table tbody td[data-label="Location"]::before {
    content: attr(data-label);
    display: block;
    font-family: var(--h);
    font-weight: 700;
    font-size: 10.5px;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 2px;
  }
  .trk-table tbody tr.is-open td[data-label="Transaction No."],
  .trk-table tbody tr.is-open td[data-label="Location"] { display: block; }

  /* Chevron affordance */
  .trk-table tbody tr::after {
    content: "";
    position: absolute;
    right: 14px; top: 16px;
    width: 9px; height: 9px;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: rotate(45deg);
    transition: transform .2s ease;
  }
  .trk-table tbody tr.is-open::after { transform: rotate(225deg); top: 20px; }

  .trk-loc { text-align: left; }

  .trk-print { text-align: stretch; }
  .trk-print .btn { width: 100%; justify-content: center; }
}
