:root {
  --bg: #f3f5f8;
  --panel: #ffffff;
  --text: #111827;
  --muted: #647080;
  --line: #d9e0e8;
  --blue: #2563eb;
  --blue-dark: #123d7a;
  --blue-soft: #eaf2ff;
  --steel: #eef2f6;
  --steel-2: #f8fafc;
  --teal: #5f8f9f;
  --ok: #169b62;
  --warn: #c98200;
  --bad: #c13a3a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

button {
  font: inherit;
}

.app {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 26px 0 40px;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 18px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 42px);
  letter-spacing: 0;
}

h2 {
  font-size: 18px;
}

#refreshButton {
  border: 1px solid var(--blue-dark);
  border-radius: 6px;
  background: var(--blue-dark);
  color: white;
  padding: 11px 16px;
  font-weight: 800;
  cursor: pointer;
}

.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.metric,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metric {
  padding: 14px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 27px;
}

.layout {
  display: grid;
  grid-template-columns: 430px 1fr;
  gap: 14px;
  align-items: start;
}

.panel {
  padding: 14px;
}

.phone-panel {
  padding: 0;
  overflow: hidden;
}

.phone {
  width: 100%;
  height: 760px;
  overflow: auto;
  background: var(--steel-2);
  position: relative;
  padding-bottom: 76px;
}

.appbar {
  height: 52px;
  display: grid;
  grid-template-columns: 52px 1fr 52px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.appbar strong {
  text-align: center;
  font-size: 18px;
}

.hamburger {
  border: 0;
  background: none;
  display: grid;
  gap: 3px;
  place-content: center;
  height: 52px;
}

.hamburger span {
  width: 24px;
  height: 4px;
  border-radius: 1px;
  background: var(--blue-dark);
}

.alert {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  justify-self: center;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  background: var(--blue);
  color: #fff;
  font-size: 22px;
  font-weight: 900;
}

.drawer-scrim {
  position: absolute;
  inset: 52px 0 0;
  z-index: 18;
  background: rgba(255, 255, 255, 0.68);
  opacity: 0;
  transition: opacity 180ms ease;
}

.drawer-scrim.open {
  opacity: 1;
}

.drawer {
  position: absolute;
  top: 52px;
  left: 0;
  bottom: 0;
  z-index: 19;
  width: min(340px, 80%);
  background: #fff;
  box-shadow: 16px 0 26px rgba(17, 24, 39, 0.12);
  transform: translateX(-100%);
  transition: transform 180ms ease;
  padding-top: 12px;
}

.drawer.open {
  transform: translateX(0);
}

.drawer button span {
  display: inline-grid;
  place-items: center;
  width: 28px;
  color: #111;
  font-size: 24px;
  font-weight: 900;
}

.drawer button {
  width: 100%;
  height: 58px;
  border: 0;
  display: grid;
  grid-template-columns: 58px 1fr;
  align-items: center;
  background: #fff;
  color: var(--blue-dark);
  text-align: left;
  font-size: 23px;
  font-weight: 900;
  cursor: pointer;
}

.drawer button:hover {
  background: var(--blue-soft);
}

.drawer hr {
  border: 0;
  border-top: 1px solid #dfe3e7;
  margin: 8px 0 12px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px;
  align-items: start;
}

.empties-view {
  padding: 18px 10px 92px;
}

.empties-view[hidden],
.empty-detail-view[hidden] {
  display: none;
}

.empties-hero {
  text-align: center;
  margin-bottom: 12px;
}

.empties-icon {
  width: 34px;
  height: 34px;
  display: inline-grid;
  place-items: center;
  margin-bottom: 4px;
  border: 3px solid var(--blue-dark);
  border-radius: 4px;
  color: var(--blue-dark);
  font-size: 22px;
  font-weight: 900;
}

.empties-hero h2 {
  display: inline-block;
  margin-left: 8px;
  font-size: 31px;
  vertical-align: 2px;
}

.empties-hero p {
  margin: 7px 0 0;
  font-size: 15px;
}

.empty-list {
  display: grid;
  gap: 14px;
}

.gate-overview,
.gate-terminal-buttons {
  display: grid;
  gap: 14px;
}

.gate-overview .empty-section {
  overflow: hidden;
  border: 1px solid #d7e0ea;
  border-radius: 8px;
  background: #fff;
}

.gate-overview .empty-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 74px;
  background: #fff;
  box-shadow: 1px 0 0 #dce4eb, 8px 0 12px rgba(17, 24, 39, .06);
}

.gate-overview .empty-table .head-row td:first-child {
  z-index: 2;
  background: #fff;
}

.empty-button {
  width: 100%;
  min-height: 58px;
  border: 1px solid #cbd7e5;
  border-radius: 8px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  background: #fff;
  color: var(--blue-dark);
  box-shadow: 0 1px 0 rgba(17, 24, 39, .04);
  cursor: pointer;
}

.empty-button.warn {
  border-color: #b6c6dc;
  background: var(--steel);
  color: #26364b;
}

.empty-button.bad {
  border-color: #d4dae2;
  background: #f1f3f6;
  color: #687384;
}

.empty-button span {
  text-align: center;
  font-size: 17px;
  font-weight: 800;
}

.empty-button small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.yard-terminal-list {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.yard-terminal-button {
  width: 100%;
  min-height: 76px;
  border: 1px solid #cbd7e5;
  border-radius: 8px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 5px;
  padding: 10px 8px;
  background: #fff;
  color: var(--blue-dark);
  box-shadow: 0 1px 0 rgba(17, 24, 39, .04);
  cursor: pointer;
}

.yard-terminal-button.ok {
  border-color: #b7c9e2;
  background: linear-gradient(180deg, #ffffff 0%, #edf4ff 100%);
}

.yard-terminal-button.warn {
  border-color: #b6c6dc;
  background: var(--steel);
  color: #26364b;
}

.yard-terminal-button.bad {
  border-color: #d4dae2;
  background: #f1f3f6;
  color: #5c6672;
}

.yard-terminal-button span {
  max-width: 100%;
  color: inherit;
  font-size: 17px;
  font-weight: 900;
  line-height: 1.05;
  text-align: center;
  overflow-wrap: anywhere;
}

.yard-terminal-button small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.yard-map-card {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr);
  gap: 3px 10px;
  align-items: center;
  min-height: 74px;
  padding: 11px 12px;
  border: 1px solid #dfe6ed;
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  text-decoration: none;
}

.yard-map-card.official {
  border-color: #bfdcf4;
  background: #f3f9ff;
}

.yard-map-card span {
  grid-row: span 3;
  min-height: 38px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: #24395a;
  color: #fff;
  font-weight: 900;
  font-size: 14px;
}

.yard-map-card strong,
.yard-map-card small,
.yard-map-card p {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.yard-map-card strong {
  font-size: 15px;
}

.yard-map-card small {
  color: #1672b8;
  font-size: 11px;
  font-weight: 900;
}

.yard-map-card p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.yard-map-card.missing {
  background: #f8fafc;
}

.yard-map-group {
  display: grid;
  gap: 8px;
  padding-bottom: 4px;
}

.yard-map-group h3 {
  margin: 4px 2px 0;
  font-size: 16px;
}

.yard-map-file {
  overflow: hidden;
  border: 1px solid #dfe6ed;
  border-radius: 8px;
  background: #fff;
}

.yard-map-file-head {
  display: grid;
  gap: 2px;
  padding: 9px 10px;
  border-bottom: 1px solid #e5ebf0;
}

.yard-map-file-head strong {
  font-size: 14px;
}

.yard-map-file-head small,
.yard-map-file p,
.yard-map-file a {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.yard-map-file img {
  display: block;
  width: 100%;
  min-height: 260px;
  border: 0;
  background: #eef3f6;
}

.yard-map-file p,
.yard-map-file a {
  display: block;
  margin: 0;
  padding: 7px 10px;
  overflow-wrap: anywhere;
}

.yard-map-file a {
  color: var(--blue);
  border-top: 1px solid #edf1f4;
}

.yard-map-pdf-link {
  min-height: 120px;
  display: grid !important;
  place-items: center;
  margin: 0;
  border: 0;
  background: var(--blue-soft);
  color: var(--blue-dark) !important;
  text-align: center;
  font-size: 15px !important;
  font-weight: 900 !important;
}

.empty-detail-view {
  position: absolute;
  inset: 0;
  z-index: 4;
  overflow: auto;
  background: #fff;
  padding-bottom: 92px;
}

.empty-detail {
  padding-bottom: 92px;
}

.empty-source {
  padding: 10px 12px;
  background: #f5f7f9;
  border-bottom: 1px solid #dce4eb;
}

.empty-source strong,
.empty-source span,
.empty-source a,
.empty-source p {
  display: block;
  margin: 3px 0;
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.empty-source span,
.empty-source p {
  color: var(--muted);
}

.empty-source a {
  color: var(--blue);
}

.empty-section h3 {
  margin: 0;
  padding: 12px 10px 8px;
  font-size: 16px;
}

.empty-table-wrap {
  overflow-x: auto;
  border-top: 1px solid #dce4eb;
  border-bottom: 1px solid #dce4eb;
}

.empty-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.empty-table td {
  padding: 7px 8px;
  border-bottom: 1px solid #e3e8ee;
  white-space: nowrap;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  width: 108px;
  min-width: 108px;
  max-width: 108px;
  background: #fff;
  box-shadow: 1px 0 0 #dce4eb, 8px 0 12px rgba(17, 24, 39, .06);
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.25;
}

.empty-table .head-row td {
  color: #20262d;
  font-weight: 900;
  background: #fff;
}

.empty-table .head-row td:first-child {
  z-index: 2;
  background: #fff;
}

.empty-image-wrap {
  overflow-x: auto;
  border-top: 1px solid #dce4eb;
  border-bottom: 1px solid #dce4eb;
  background: #fff;
}

.empty-image-wrap img {
  display: block;
  width: 100%;
  min-width: 360px;
  height: auto;
}

.empty-state {
  padding: 22px 14px;
  color: var(--muted);
  font-weight: 800;
}

.bottom-nav {
  position: absolute;
  left: 21px;
  right: 21px;
  bottom: 10px;
  z-index: 6;
  width: auto;
  min-height: 64px;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 2px;
  align-items: center;
  margin: 0;
  padding: 6px;
  border-radius: 28px;
  border: 1px solid rgba(203, 213, 225, .8);
  background: rgba(255, 255, 255, .96);
  box-shadow: 0 8px 24px rgba(17, 24, 39, .14);
  backdrop-filter: blur(10px);
}

.bottom-nav button {
  min-width: 0;
  height: 52px;
  border: 0;
  border-radius: 24px;
  background: transparent;
  color: #273244;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 1px;
  font-size: 10px;
  font-weight: 900;
  cursor: pointer;
}

.bottom-nav button.active {
  background: var(--blue-soft);
  color: var(--blue);
}

.bottom-nav span {
  font-size: 20px;
  line-height: 1;
}

.match-view {
  gap: 10px;
}

.match-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.match-summary div {
  min-height: 64px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 10px;
  border: 1px solid #cbd7e5;
  border-radius: 8px;
  background: linear-gradient(180deg, #ffffff 0%, #edf4ff 100%);
}

.match-summary span,
.match-note,
.match-table small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.match-summary strong {
  color: var(--blue-dark);
  font-size: 24px;
  line-height: 1;
}

.match-note {
  padding: 10px 12px;
  border: 1px solid #d7e0ea;
  border-radius: 8px;
  background: #fff;
}

.match-table-wrap {
  overflow-x: auto;
  border: 1px solid #d7e0ea;
  border-radius: 8px;
  background: #fff;
}

.match-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.match-table td {
  padding: 8px 9px;
  border-bottom: 1px solid #e3e8ee;
  white-space: nowrap;
}

.match-table .head-row td {
  color: var(--blue-dark);
  font-weight: 900;
  background: #f6f9fd;
}

.match-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 132px;
  background: #fff;
  box-shadow: 1px 0 0 #dce4eb, 8px 0 12px rgba(17, 24, 39, .06);
}

.match-table .head-row td:first-child {
  z-index: 2;
  background: #f6f9fd;
}

.match-table strong,
.match-table small {
  display: block;
}

.match-pill {
  display: inline-block;
  min-width: 76px;
  padding: 5px 7px;
  border-radius: 999px;
  text-align: center;
  font-size: 11px;
  font-weight: 900;
}

.match-pill.ok {
  background: #e7f7ef;
  color: var(--ok);
}

.match-pill.warn {
  background: #fff4dd;
  color: var(--warn);
}

.match-pill.bad {
  background: #fdecec;
  color: var(--bad);
}

.terminal-group {
  background: #fff;
  border: 1px solid var(--blue-dark);
  border-radius: 7px;
  overflow: hidden;
  min-width: 0;
}

.terminal-group-head {
  height: 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 4px 3px 2px;
  border-top: 0;
  background: #fff;
}

.terminal-group-head h2 {
  font-size: 18px;
  line-height: 1.05;
  font-weight: 800;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.group-pill {
  border-radius: 4px;
  padding: 4px 6px;
  color: #fff;
  font-size: 11px;
  font-weight: 900;
}

.group-pill.ok {
  background: var(--ok);
}

.group-pill.bad {
  background: var(--bad);
}

.terminal {
  min-width: 0;
  background: #fff;
  display: block;
  width: 100%;
  border: 0;
  padding: 0;
  color: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
}

.terminal:focus-visible {
  outline: 3px solid rgba(37, 99, 235, .35);
  outline-offset: -3px;
}

.terminal-group:has(.terminal:active),
.terminal-group:has(.terminal.previewing) {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, .16);
}

.terminal.previewing .status-copy {
  background: var(--blue);
}

.camera {
  aspect-ratio: 1.1 / 1;
  height: auto;
  position: relative;
  overflow: hidden;
  background: #111820;
}

.camera img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
}

.camera-fallback {
  height: 100%;
  display: grid;
  place-items: center;
  padding: 10px;
  background: #2b3138;
  color: #fff;
  text-align: center;
  font-size: 12px;
  font-weight: 800;
}

.status-copy {
  min-height: 0;
  padding: 6px;
  background: var(--blue-dark);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.25;
  overflow-wrap: anywhere;
  border-radius: 0 0 8px 8px;
}

.status-copy div {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.meta {
  height: 30px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 6px;
  padding: 0 6px;
  font-weight: 900;
  font-size: 15px;
}

.age {
  color: #898989;
  font-size: 15px;
  font-weight: 700;
}

.badge {
  min-width: 21px;
  height: 22px;
  display: grid;
  place-items: center;
  background: #ffc21b;
}

.history-view {
  position: absolute;
  inset: 0;
  z-index: 5;
  overflow: auto;
  background: #fff;
  padding-bottom: 92px;
}

.history-view[hidden] {
  display: none;
}

.history-head {
  position: sticky;
  top: 0;
  z-index: 2;
  min-height: 58px;
  display: grid;
  grid-template-columns: 48px 1fr;
  align-items: center;
  gap: 4px;
  padding-right: 12px;
  background: rgba(255, 255, 255, .96);
  border-bottom: 1px solid #e4e9ee;
}

.history-head button {
  border: 0;
  background: none;
  color: #222;
  font-size: 42px;
  line-height: 1;
  cursor: pointer;
}

.history-head strong,
.history-head span {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-head strong {
  font-size: 17px;
}

.history-head span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.history-list {
  padding-bottom: 92px;
}

.camera-switcher {
  position: sticky;
  top: 58px;
  z-index: 1;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 10px;
  background: rgba(255, 255, 255, .96);
  border-bottom: 1px solid #e3e8ee;
}

.camera-switcher button {
  flex: 0 0 auto;
  min-height: 30px;
  border: 1px solid #d5dde5;
  border-radius: 16px;
  background: #fff;
  color: #27323b;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
}

.camera-switcher button.active {
  border-color: #1b8fe5;
  background: #e8f4ff;
  color: #0868b2;
}

.history-item img {
  width: 100%;
  display: block;
  background: #d8dee3;
  touch-action: pinch-zoom pan-x pan-y;
}

.history-separator {
  padding: 9px 10px;
  background: #eef3f6;
  border-top: 1px solid #d9e1e8;
  border-bottom: 1px solid #d9e1e8;
  color: #34404a;
  font-size: 13px;
  font-weight: 900;
}

.history-empty {
  padding: 22px 14px;
  color: var(--muted);
  font-weight: 800;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.section-head span {
  color: var(--muted);
  font-size: 12px;
}

.source-list {
  display: grid;
  gap: 10px;
}

.source-group {
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
}

.source-group-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  background: #eef3f6;
  border-bottom: 1px solid var(--line);
}

.source-group-head h3 {
  margin: 0;
  font-size: 16px;
}

.source-group-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.source-group-list {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.source {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px;
}

.source-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.source h3 {
  margin: 0;
  font-size: 16px;
}

.pill {
  border-radius: 999px;
  padding: 3px 9px;
  color: #fff;
  font-size: 12px;
  font-weight: 800;
}

.pill.ok { background: var(--ok); }
.pill.warn { background: var(--warn); }
.pill.bad { background: var(--bad); }

.source p {
  margin: 4px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.source a {
  color: var(--blue);
  overflow-wrap: anywhere;
}

.raw-panel {
  margin-top: 14px;
}

pre {
  margin: 0;
  min-height: 160px;
  max-height: 360px;
  overflow: auto;
  padding: 12px;
  background: #111820;
  color: #d7e4ed;
  border-radius: 7px;
  font-size: 12px;
  line-height: 1.45;
}

@media (max-width: 900px) {
  .app {
    width: 100vw;
    padding: 0;
  }

  .top,
  .summary,
  .layout > .panel:not(.phone-panel),
  .raw-panel {
    display: none;
  }

  .layout {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .phone-panel {
    border: 0;
    border-radius: 0;
  }

  .phone {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .bottom-nav {
    position: fixed;
    left: 21px;
    right: 21px;
    bottom: calc(10px + env(safe-area-inset-bottom));
  }

  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
