/* Gate, truck yard, weighbridge and parties. Builds on app.css variables and components. */

/* Identifiers: plates, tokens, codes stay in English letters, bold and readable */
.gate-plate { font-family: var(--mono); font-weight: 600; font-size: 14px; letter-spacing: .02em; color: var(--ink); text-decoration: none; white-space: nowrap; }
a.gate-plate { color: var(--accent); }
a.gate-plate:hover { color: var(--accent-ink); text-decoration: underline; }
.gate-plate-big { display: inline-block; font-size: 22px; padding: 4px 12px; border: 2px solid var(--ink); border-radius: 8px; background: transparent; color: var(--ink); }
.gate-plate-input { font-family: var(--mono); font-weight: 600; letter-spacing: .02em; text-transform: uppercase; }
.gate-code { display: inline-flex; align-items: center; padding: 1px 8px; border-radius: 6px; background: var(--btn-bg, var(--ink)); color: var(--btn-ink, #FFFFFF); font-family: var(--mono); font-weight: 600; font-size: 13px; text-decoration: none; white-space: nowrap; }
a.gate-code:hover { background: var(--ink-2); color: var(--btn-ink, #FFFFFF); }
.gate-title { line-height: 1.2; }
.gate-tags { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.gate-sub { display: block; font-size: 12px; color: var(--muted); margin-top: 2px; }
.gate-note { padding: 10px 12px; border-radius: 10px; background: var(--sunk); color: var(--ink-2); white-space: pre-line; }
.gate-row-off td { color: var(--muted); background: #FAFBF8; }

/* Purpose pills: colour plus the word (never colour alone) */
.gate-purpose-paddy_in { background: #DDF0E5; color: #17643A; }
.gate-purpose-rice_out { background: #DCE8F8; color: #164A96; }
.gate-purpose-government_out { background: #E8E2F5; color: #4B3591; }
.gate-purpose-byproduct_out { background: #F0EDD4; color: #5A5214; }
.gate-purpose-goods_in { background: #EEF0EB; color: #3B453F; }
.gate-purpose-visitor { background: #FBEFD6; color: #6E4600; }
.gate-kind { background: var(--sunk-2); color: var(--ink-2); }
.gate-kind-bepari, .gate-kind-aratdar, .gate-kind-farmer, .gate-kind-broker { background: #DDF0E5; color: #17643A; }
.gate-kind-dealer, .gate-kind-wholesaler { background: #DCE8F8; color: #164A96; }
.gate-kind-government { background: #E8E2F5; color: #4B3591; }
.gate-kind-oil_mill, .gate-kind-brick_kiln { background: #F0EDD4; color: #5A5214; }

/* KPIs (Viz::kpi tiles) */
.gate-kpis { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
/* A toned tile (stuck trucks, held weights) shows its tone on the number and the edge, not only in a delta. */
.gate-kpis .viz-kpi[class*="viz-t-"] .kpi-value { color: var(--vt); }
.gate-kpis .viz-kpi.viz-t-bad, .gate-kpis .viz-kpi.viz-t-warn { box-shadow: inset 4px 0 0 var(--vc); }

/* Yard filters */
.gate-filters { display: flex; flex-wrap: wrap; gap: 8px; }
.gate-filter { display: inline-flex; align-items: center; gap: 8px; min-height: 38px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--sunk); color: var(--ink); font-weight: 600; font-size: 14px; text-decoration: none; }
.gate-filter:hover { border-color: var(--ink-2); color: var(--ink); }
.gate-filter.is-on { background: var(--btn-bg, var(--ink)); border-color: var(--btn-bg, var(--ink)); color: var(--btn-ink, #FFFFFF); }
.gate-filter.is-alert:not(.is-on) { border-color: var(--bad); color: var(--bad); }
.gate-filter-n { font-variant-numeric: tabular-nums; opacity: .8; }

/* Yard table */
.gate-yard td { vertical-align: top; }
.gate-row { cursor: pointer; }
.gate-row td:first-child { border-left: 4px solid transparent; }
.gate-row-stuck td:first-child { border-left-color: #C0392B; }
.gate-row-ready td:first-child { border-left-color: #1E8A4C; }
.gate-step { font-weight: 600; }
.gate-time { font-weight: 700; font-variant-numeric: tabular-nums; }
.gate-time.is-late { color: var(--bad); }
.gate-legend { margin-top: -6px; }

/* New entry: purpose cards */
.gate-purpose-pick { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; }
.gate-purpose-option { position: relative; display: flex; flex-direction: column; gap: 4px; padding: 14px 14px 14px 44px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--sunk); cursor: pointer; }
.gate-purpose-option input { position: absolute; left: 14px; top: 16px; width: 18px; height: 18px; accent-color: var(--accent); }
.gate-purpose-option:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.gate-purpose-name { font-weight: 700; }
.gate-purpose-hint { font-size: 12px; color: var(--muted); line-height: 1.4; }
.gate-purpose-pick.has-error .gate-purpose-option { border-color: var(--bad); }
.gate-own { border: 0; padding: 0; margin: 0; }
.gate-own .check { min-height: 32px; }

/* Entry: the action under the station chain */
.gate-action { border-top: 1px solid var(--line); padding-top: 14px; display: flex; flex-direction: column; gap: 12px; }
.gate-exit { padding: 14px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--ok-bg); gap: 8px; }
.gate-exit h3 { color: var(--ok); }
.gate-reminders { margin: 0; padding-left: 18px; color: var(--ink-2); }
.gate-net { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; padding: 12px 14px; border-radius: var(--radius); background: var(--sunk); }
.gate-net strong { font-size: 22px; font-variant-numeric: tabular-nums; }
.gate-cancel summary { cursor: pointer; font-weight: 600; color: var(--bad); }

/* Weighbridge desk */
.gate-desk { display: grid; grid-template-columns: minmax(250px, 1fr) minmax(0, 2fr); gap: 18px; align-items: start; }
.gate-desk .gate-tare { grid-column: 2; }
.gate-queue-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.gate-queue-item { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border: 1px solid var(--line); border-left: 4px solid var(--line-strong); border-radius: 10px; color: var(--ink); text-decoration: none; }
.gate-queue-item:hover { border-color: #B9C9E6; color: var(--ink); }
.gate-queue-item.is-on { border-color: var(--accent); border-left-color: var(--accent); background: var(--accent-soft); }
.gate-queue-item.is-held { border-left-color: var(--gold); }
.gate-queue-step { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.gate-wcard { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center; padding: 12px 14px; border: 1px solid var(--line-strong); border-radius: var(--radius); }
.gate-wcard.is-done { background: var(--ok-bg); }
.gate-wcard.is-held { border-color: var(--warn); background: var(--warn-bg); }
.gate-wcard.is-rejected { border-color: var(--bad); background: var(--bad-bg); }
.gate-wcard-title { font-weight: 600; }
.gate-wcard-kg { font-size: 20px; font-variant-numeric: tabular-nums; text-align: right; }
.gate-wcard .pill { justify-self: end; }
.gate-weight-box { display: flex; align-items: center; gap: 10px; padding: 8px 16px; border-radius: 14px; background: #0F1A14; }
.gate-weight-box:focus-within { box-shadow: 0 0 0 3px var(--accent-soft); }
input.gate-weight-input { flex: 1; min-width: 0; border: 0; background: transparent; color: #6FDB9C; font-family: var(--mono); font-size: 46px; font-weight: 600; text-align: right; letter-spacing: .03em; padding: 4px 0; }
input.gate-weight-input:focus { outline: none; box-shadow: none; }
input.gate-weight-input::placeholder { color: #2F4A3B; }
.gate-weight-unit { color: #8FA197; font-weight: 600; font-size: 18px; }
.gate-usual { padding: 10px 12px; border-radius: 10px; background: var(--sunk); font-size: 14px; color: var(--ink-2); }
.gate-capture-btn { min-height: 52px; font-size: 16px; }
.gate-hold strong { font-weight: 700; }
.gate-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.gate-chip { position: relative; }
.gate-chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.gate-chip span { display: inline-flex; align-items: center; min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--sunk); font-size: 14px; font-weight: 600; cursor: pointer; }
.gate-chip input:checked + span { background: #6E4600; border-color: #6E4600; color: #FFFFFF; }
.gate-chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.gate-approve { padding: 14px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--warn-bg); }
.gate-result { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.gate-result > div { display: flex; flex-direction: column; gap: 2px; padding: 12px; border-radius: 10px; background: var(--sunk); }
.gate-result span { font-size: 12px; color: var(--muted); font-weight: 600; }
.gate-result strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.gate-result .is-net { background: var(--ok-bg); }
.gate-result .is-net strong { color: var(--ok); font-size: 22px; }
.gate-result small { color: var(--muted); }

/* Ticket and gate pass (printable) */
.gate-ticket { max-width: 720px; padding: 26px; background: var(--surface, #FFFFFF); border: 1px solid var(--line-strong); border-radius: var(--radius); display: flex; flex-direction: column; gap: 18px; }
.gate-ticket-head { display: flex; justify-content: space-between; gap: 16px; padding-bottom: 14px; border-bottom: 2px solid var(--ink); }
.gate-ticket-head > div:first-child { display: flex; flex-direction: column; }
.gate-ticket-head strong { font-size: 18px; }
.gate-ticket-no { text-align: right; display: flex; flex-direction: column; }
.gate-ticket-no strong { font-size: 20px; }
.gate-ticket-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 20px; margin: 0; }
.gate-ticket-facts dt { font-size: 12px; color: var(--muted); font-weight: 600; }
.gate-ticket-facts dd { margin: 0; font-weight: 600; }
.gate-ticket-big { font-size: 20px; }
.gate-ticket-table { width: 100%; border-collapse: collapse; }
.gate-ticket-table th, .gate-ticket-table td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.gate-ticket-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.gate-ticket-table .is-net td { font-weight: 700; font-size: 17px; border-bottom: 2px solid var(--ink); }
.gate-ticket-foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 16px; font-size: 13px; color: var(--muted); }
.gate-sign { min-width: 150px; padding-top: 34px; border-top: 1px solid var(--line-strong); margin-top: 8px; text-align: center; }

@media (max-width: 860px) {
  .gate-desk { grid-template-columns: 1fr; }
  .gate-desk .gate-tare { grid-column: auto; }
  .gate-plate-big { font-size: 18px; }
  input.gate-weight-input { font-size: 36px; }
  .gate-result { grid-template-columns: 1fr; }
}

@media print {
  .gate-ticket { border: 0; padding: 0; max-width: none; background: #FFFFFF; color: #000000; }
  /* Paper is white even when the screen is dark: the slip's own text uses the light colours. */
  .gate-ticket { --ink: #1D1D1F; --ink-2: #3A3F3C; --muted: #545A56; --line: rgba(29, 29, 31, .14); --line-strong: rgba(29, 29, 31, .4); --surface: #FFFFFF; --sunk: rgba(29, 29, 31, .05); }
  .demo-banner { display: none; }
}

/* Small fixes */
.gate-approve fieldset, fieldset.gate-own { border: 0; padding: 0; margin: 0; min-width: 0; }
.gate-wcard-kg, .gate-result strong, .gate-net strong, .facts strong.num { white-space: nowrap; }
.gate-queue-item.is-on { box-shadow: 0 0 0 2px var(--accent); }
.party-code-fixed { align-self: flex-start; font-size: 15px; padding: 4px 10px; }

/* Scannable codes: the token on the truck's page, the ticket and gate pass numbers on paper. */
.gate-token-code,
.gate-ticket-code {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin-top: 12px;
}
.gate-token-code svg,
.gate-ticket-code svg {
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}
.gate-token-code svg { width: 220px; }
.gate-ticket-code svg { width: 260px; }

/* Purpose pills in dark mode: the same hue, darker ground */
:root[data-theme="dark"] .gate-purpose-paddy_in, :root[data-theme="dark"] .gate-kind-bepari, :root[data-theme="dark"] .gate-kind-aratdar, :root[data-theme="dark"] .gate-kind-farmer, :root[data-theme="dark"] .gate-kind-broker { background: #1E3A2A; color: #8FE0B0; }
:root[data-theme="dark"] .gate-purpose-rice_out, :root[data-theme="dark"] .gate-kind-dealer, :root[data-theme="dark"] .gate-kind-wholesaler { background: #1C2C46; color: #9CC0F5; }
:root[data-theme="dark"] .gate-purpose-government_out, :root[data-theme="dark"] .gate-kind-government { background: #2C2446; color: #C7B6F2; }
:root[data-theme="dark"] .gate-purpose-byproduct_out, :root[data-theme="dark"] .gate-kind-oil_mill, :root[data-theme="dark"] .gate-kind-brick_kiln { background: #3A3618; color: #E5DA8A; }
:root[data-theme="dark"] .gate-purpose-goods_in { background: #2A302C; color: #C9D2CC; }
:root[data-theme="dark"] .gate-purpose-visitor { background: #3E2E10; color: #F2C46B; }
:root[data-theme="dark"] .gate-row-off td { background: transparent; }
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] .gate-purpose-paddy_in { background: #1E3A2A; color: #8FE0B0; }
  :root[data-theme="auto"] .gate-purpose-rice_out { background: #1C2C46; color: #9CC0F5; }
  :root[data-theme="auto"] .gate-purpose-government_out { background: #2C2446; color: #C7B6F2; }
  :root[data-theme="auto"] .gate-purpose-byproduct_out { background: #3A3618; color: #E5DA8A; }
  :root[data-theme="auto"] .gate-purpose-goods_in { background: #2A302C; color: #C9D2CC; }
  :root[data-theme="auto"] .gate-purpose-visitor { background: #3E2E10; color: #F2C46B; }
}

/* The yard now: stations left to right, each truck a chip coloured by its wait (viz-t-ok|warn|bad) */
.gate-yardmap .panel-head { flex-wrap: wrap; gap: 8px 16px; }
.gate-lanes { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
.gate-lane { position: relative; display: flex; flex-direction: column; gap: 8px; min-width: 0; padding: 10px; border-radius: var(--radius); background: var(--sunk); border: 1px solid var(--line); }
.gate-lane:not(:last-child)::after { content: '›'; position: absolute; right: -10px; top: 12px; width: 10px; text-align: center; font-weight: 700; color: var(--muted); }
.gate-lane-head { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 14px; }
.gate-lane-icon { display: inline-flex; color: var(--ink-2); }
.gate-lane-icon .icon { width: 18px; height: 18px; }
.gate-lane-name { flex: 1; min-width: 0; line-height: 1.25; }
.gate-lane-n { min-width: 26px; padding: 1px 8px; border-radius: 999px; background: var(--btn-bg, var(--ink)); color: var(--btn-ink, #FFFFFF); text-align: center; font-variant-numeric: tabular-nums; }
.gate-lane.is-empty .gate-lane-n { background: var(--sunk-2); color: var(--muted); }
.gate-lane-none { margin: 0; font-size: 13px; color: var(--muted); }
.gate-lane-trucks { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.gate-truck { position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-areas: "icon text" "min min"; gap: 2px 8px; align-items: center; padding: 7px 8px 7px 12px; border-radius: 10px; background: var(--vb); border: 1px solid var(--vc); color: var(--ink); text-decoration: none; overflow: hidden; }
.gate-truck:hover { color: var(--ink); box-shadow: 0 0 0 2px var(--vc); }
.gate-truck-purpose { position: absolute; left: 0; top: 0; bottom: 0; width: 5px; }
.gate-truck-icon { grid-area: icon; display: inline-flex; color: var(--vc); }
.gate-truck-icon .icon { width: 22px; height: 22px; }
.gate-truck-text { grid-area: text; display: flex; flex-direction: column; min-width: 0; }
.gate-truck-plate { font-family: var(--mono); font-size: 12px; line-height: 1.25; overflow-wrap: anywhere; }
.gate-truck-step { font-size: 11.5px; line-height: 1.3; color: var(--ink-2); }
.gate-truck-min { grid-area: min; justify-self: start; font-weight: 700; font-size: 12.5px; color: var(--vt); font-variant-numeric: tabular-nums; }
.gate-yardmap-legend { margin: 0; }
.gate-charts { align-items: stretch; }

/* Yard table: the chain as dots */
.gate-dots { display: flex; gap: 3px; margin-bottom: 4px; }
.gate-dot { width: 14px; height: 6px; border-radius: 3px; background: var(--line-strong); }
.gate-dot.is-done { background: var(--viz-green); }
.gate-dot.is-now { background: var(--accent); }
.gate-dot.is-now.is-late { background: var(--viz-red); }

/* Find a truck, scan at the desk */
.gate-find .field { max-width: 640px; }
.gate-find-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.gate-find-row input { flex: 1 1 220px; min-width: 0; font-family: var(--mono); }
.gate-desk-scan { display: flex; flex-direction: column; justify-content: center; }

/* New entry: the chain of each purpose as pictures */
.gate-mini-chain { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; margin: 2px 0; color: var(--ink-2); }
.gate-mini-step { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 50%; background: var(--surface, var(--glass-strong)); border: 1px solid var(--line-strong); }
.gate-mini-step .icon { width: 15px; height: 15px; }
.gate-mini-step.is-exit { border-color: var(--viz-green); color: var(--ok); }
.gate-mini-arrow { color: var(--muted); font-weight: 700; font-size: 13px; }

/* Weighbridge: queue tinted by wait, weight bars, empty-weight check */
.gate-queue-item[class*="viz-t-"] { border-left-color: var(--vc); }
.gate-queue-item.is-on { border-left-color: var(--vc); }
.gate-queue-step { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 8px; }
.gate-queue-what { display: inline-flex; align-items: center; gap: 4px; }
.gate-queue-what .icon { width: 15px; height: 15px; }
.gate-queue-min { padding: 0 8px; border-radius: 999px; background: var(--vb); color: var(--vt); font-weight: 700; font-variant-numeric: tabular-nums; }
.gate-weight-bars { margin: 6px 0; }
.gate-tare-meter { padding: 10px 12px; border-radius: 10px; background: var(--sunk); }
.gate-chain { margin-bottom: 6px; }

/* Token slip, ticket and pass: barcode and QR side by side; the exit check as three boxes */
.gate-slip-codes { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px; }
.gate-slip-codes .gate-ticket-code { margin-top: 0; }
.gate-slip-qr canvas, canvas.gate-qr { width: 120px; height: 120px; image-rendering: pixelated; background: #FFFFFF; border-radius: 6px; }
.gate-exit-boxes { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.gate-exit-boxes li { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; padding: 12px; border: 2px solid var(--ink); border-radius: 10px; min-width: 0; }
.gate-exit-boxes .icon { width: 22px; height: 22px; }
.gate-exit-boxes span { font-size: 12px; color: var(--muted); font-weight: 600; }
.gate-exit-boxes strong { font-size: 20px; overflow-wrap: anywhere; }

@media (max-width: 1500px) {
  .gate-lanes { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .gate-lane:nth-child(3n)::after { display: none; }
}
@media (max-width: 600px) {
  .gate-lanes { grid-template-columns: 1fr; gap: 14px; }
  .gate-lane::after { display: none; }
  .gate-lane:not(:last-child)::after { content: '⌄'; display: block; right: auto; left: 50%; top: auto; bottom: -15px; }
  .gate-lane-trucks { flex-direction: row; flex-wrap: wrap; }
  .gate-lane-trucks li { flex: 1 1 150px; min-width: 0; }
  .gate-exit-boxes { grid-template-columns: 1fr; }
  .gate-slip-qr canvas, canvas.gate-qr { width: 100px; height: 100px; }
  /* The yard and desk counts two to a row on a phone, so the yard picture is reached without a long scroll. */
  .gate-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .gate-kpis .viz-kpi { min-height: 0; padding: 14px; }
  .gate-kpis .viz-kpi .kpi-value { font-size: 30px; }
}
@media print {
  .gate-truck, .gate-lane { break-inside: avoid; }
  .gate-exit-boxes li { border-color: #000000; }
  .gate-find, .gate-desk-scan { display: none; }
}
