:root {
  --background: #f2efe6;
  --ink: #151713;
  --muted: #596255;
  --panel: rgba(255, 255, 255, 0.74);
  --panel-line: rgba(21, 23, 19, 0.13);
  --green: #16a34a;
  --green-dark: #0f7a3b;
  --amber: #f59e0b;
  --amber-dark: #b86d00;
  --red: #dc2626;
  --red-dark: #991b1b;
  --shadow: 0 24px 70px rgba(20, 20, 16, 0.16);
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0)),
    var(--background);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body.critical-flash {
  animation: viewport-pulse 650ms steps(2, end) infinite;
}

body.critical-flash::before {
  position: fixed;
  z-index: 30;
  inset: 0;
  pointer-events: none;
  content: "";
  background: rgba(220, 38, 38, 0.22);
  animation: flash 650ms ease-in-out infinite;
}

.kiosk-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-height: 100vh;
  gap: 18px;
  padding: 34px;
}

.topbar,
.summary-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 700;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 2.45rem;
  font-weight: 850;
  line-height: 1;
}

.status-cluster {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-weight: 700;
}

.test-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.test-button {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--panel-line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 0.94rem;
  font-weight: 850;
  white-space: nowrap;
  box-shadow: 0 10px 26px rgba(20, 20, 16, 0.08);
  transition: transform 160ms ease, box-shadow 160ms ease, opacity 160ms ease;
}

.test-button:hover {
  box-shadow: 0 14px 30px rgba(20, 20, 16, 0.14);
  transform: translateY(-1px);
}

.test-button:focus-visible {
  outline: 3px solid rgba(21, 23, 19, 0.28);
  outline-offset: 3px;
}

.test-button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.test-button--amber {
  border-color: rgba(184, 109, 0, 0.32);
  color: var(--amber-dark);
}

.test-button--red {
  border-color: rgba(153, 27, 27, 0.32);
  color: var(--red-dark);
}

.test-button--baseline {
  border-color: rgba(15, 122, 59, 0.32);
  color: var(--green-dark);
}

.operations-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.22fr) minmax(390px, 0.78fr);
  gap: 18px;
  min-height: 0;
}

.marina-map-panel,
.status-panel {
  min-width: 0;
  min-height: 0;
}

.marina-map-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
}

.map-panel-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  min-width: 0;
}

h2 {
  margin: 0;
  font-size: 1.45rem;
  line-height: 1;
}

.map-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 850;
  text-transform: uppercase;
}

.map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.legend-dot--green {
  background: var(--green);
}

.legend-dot--amber {
  background: var(--amber);
}

.legend-dot--red {
  background: var(--red);
}

.marina-map {
  position: relative;
  min-height: 360px;
  overflow: hidden;
  border: 1px solid rgba(13, 65, 83, 0.2);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.34), rgba(255, 255, 255, 0) 42%),
    linear-gradient(160deg, #cdebf1, #8fc9d8 44%, #5c9eb0);
  box-shadow: var(--shadow);
  isolation: isolate;
}

.marina-map::before {
  position: absolute;
  inset: 0;
  z-index: 0;
  content: "";
  background:
    repeating-linear-gradient(25deg, rgba(255, 255, 255, 0.12) 0 2px, transparent 2px 28px),
    linear-gradient(90deg, rgba(13, 65, 83, 0.18), transparent 48%, rgba(255, 255, 255, 0.12));
}

.map-water-label,
.shoreline,
.main-pier,
.finger,
.fuel-dock,
.map-markers {
  position: absolute;
}

.map-water-label {
  right: 24px;
  bottom: 18px;
  z-index: 1;
  color: rgba(13, 65, 83, 0.52);
  font-size: 0.92rem;
  font-weight: 900;
  text-transform: uppercase;
}

.shoreline {
  z-index: 1;
  display: grid;
  place-items: center;
  color: rgba(44, 54, 39, 0.76);
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.2) 0 10px, transparent 10px 20px),
    #d8d3bf;
  font-size: 0.86rem;
  font-weight: 900;
  text-transform: uppercase;
}

.shoreline--north {
  top: 0;
  right: 0;
  left: 0;
  height: 58px;
  border-bottom: 1px solid rgba(44, 54, 39, 0.22);
}

.shoreline--west {
  top: 58px;
  bottom: 0;
  left: 0;
  width: 74px;
  border-right: 1px solid rgba(44, 54, 39, 0.22);
  writing-mode: vertical-rl;
}

.main-pier,
.finger,
.fuel-dock {
  z-index: 2;
  border: 1px solid rgba(84, 69, 48, 0.38);
  border-radius: 4px;
  background: linear-gradient(180deg, #b99a64, #8f744d);
  box-shadow: 0 12px 24px rgba(48, 59, 45, 0.2);
}

.main-pier {
  top: 55%;
  left: 74px;
  width: 74%;
  height: 24px;
  transform: translateY(-50%) rotate(-21deg);
  transform-origin: left center;
}

.finger {
  width: 132px;
  height: 16px;
  transform-origin: left center;
}

.finger--one {
  top: 66%;
  left: 19%;
  transform: rotate(-21deg);
}

.finger--two {
  top: 53%;
  left: 37%;
  transform: rotate(-21deg);
}

.finger--three {
  top: 40%;
  left: 55%;
  transform: rotate(-21deg);
}

.finger--four {
  top: 27%;
  left: 73%;
  transform: rotate(-21deg);
}

.fuel-dock {
  right: 22px;
  top: 76px;
  display: grid;
  place-items: center;
  width: 92px;
  height: 42px;
  color: #ffffff;
  font-size: 0.82rem;
  font-weight: 900;
  text-transform: uppercase;
}

.map-markers {
  z-index: 5;
  inset: 0;
}

.map-marker {
  position: absolute;
  left: var(--x);
  top: var(--y);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 190px;
  min-width: 0;
  transform: translate(-14px, -50%);
}

.map-marker--reverse {
  flex-direction: row-reverse;
  transform: translate(calc(-100% + 14px), -50%);
}

.map-dot {
  position: relative;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border: 4px solid rgba(255, 255, 255, 0.94);
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 10px 20px rgba(13, 65, 83, 0.25);
}

.map-tag {
  display: grid;
  min-width: 94px;
  max-width: 150px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.62);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  box-shadow: 0 12px 24px rgba(13, 65, 83, 0.16);
}

.map-tag strong,
.map-tag span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.map-tag strong {
  font-size: 1rem;
  line-height: 1.05;
}

.map-tag span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.map-marker--amber .map-dot {
  background: var(--amber);
}

.map-marker--red .map-dot {
  background: var(--red);
  animation: map-danger 680ms ease-in-out infinite alternate;
}

.map-marker--red .map-dot::after {
  position: absolute;
  inset: -12px;
  border: 2px solid rgba(220, 38, 38, 0.6);
  border-radius: 50%;
  content: "";
  animation: map-ripple 900ms ease-out infinite;
}

.map-marker--red .map-tag {
  border-color: rgba(153, 27, 27, 0.34);
  background: rgba(255, 235, 235, 0.94);
  color: var(--red-dark);
}

.status-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
}

.connection-pill,
time {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--panel-line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.68);
}

.connection-pill {
  gap: 9px;
}

.connection-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 0 4px rgba(245, 158, 11, 0.15);
}

.connection-pill[data-state="online"] .connection-dot {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(22, 163, 74, 0.16);
}

.connection-pill[data-state="offline"] .connection-dot {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.16);
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  min-height: 82px;
  gap: 10px;
}

.summary-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-width: 0;
  padding: 16px 18px;
  border: 1px solid var(--panel-line);
  border-left: 8px solid currentColor;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 32px rgba(20, 20, 16, 0.08);
}

.summary-item strong {
  font-size: 2rem;
  line-height: 1;
}

.summary-item span {
  overflow: hidden;
  font-size: 0.92rem;
  font-weight: 800;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.summary-green {
  color: var(--green-dark);
}

.summary-amber {
  color: var(--amber-dark);
}

.summary-red {
  color: var(--red-dark);
}

.berth-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: minmax(150px, 1fr);
  gap: 12px;
  min-height: 0;
}

.berth-card {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-width: 0;
  min-height: 150px;
  padding: 18px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.42);
  border-radius: 8px;
  color: #ffffff;
  box-shadow: var(--shadow);
  transform: translateZ(0);
  transition: transform 180ms ease, filter 180ms ease;
}

.berth-card::after {
  position: absolute;
  inset: 0;
  pointer-events: none;
  content: "";
  background: linear-gradient(155deg, rgba(255, 255, 255, 0.24), rgba(255, 255, 255, 0) 46%);
}

.berth-card__header,
.status-pill {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
}

.berth-card__header {
  justify-content: space-between;
  gap: 14px;
}

.berth-id {
  overflow-wrap: anywhere;
  font-size: 2rem;
  font-weight: 900;
  line-height: 1;
}

.status-pill {
  justify-content: center;
  min-width: 78px;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.16);
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
  white-space: nowrap;
}

.vessel-name,
.reason {
  position: relative;
  z-index: 1;
  margin: 0;
}

.vessel-name {
  overflow-wrap: anywhere;
  font-size: 1.18rem;
  line-height: 1.08;
}

.reason {
  max-width: 100%;
  min-height: 1.35em;
  color: rgba(255, 255, 255, 0.9);
  font-size: 0.92rem;
  font-weight: 750;
  line-height: 1.35;
}

.reason[hidden] {
  display: block;
  visibility: hidden;
}

.bg-green-500 {
  background: linear-gradient(145deg, var(--green), var(--green-dark));
}

.bg-amber-500 {
  background: linear-gradient(145deg, var(--amber), var(--amber-dark));
}

.bg-red-500 {
  background: linear-gradient(145deg, var(--red), var(--red-dark));
  animation: tile-danger 850ms ease-in-out infinite alternate;
}

.critical-alert {
  position: fixed;
  z-index: 40;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.critical-alert[hidden] {
  display: none;
}

.alert-marquee {
  width: 100%;
  overflow: hidden;
  border-block: 8px solid var(--red-dark);
  background: rgba(255, 255, 255, 0.94);
  color: var(--red-dark);
  box-shadow: 0 28px 80px rgba(153, 27, 27, 0.28);
  white-space: nowrap;
}

.alert-marquee span {
  display: inline-block;
  min-width: 100%;
  padding: 22px 0;
  font-size: 4.2rem;
  font-weight: 950;
  line-height: 1;
  text-align: center;
  text-transform: uppercase;
  animation: marquee 5.5s linear infinite;
}

#criticalReason {
  position: absolute;
  bottom: 22%;
  max-width: min(880px, calc(100vw - 48px));
  margin: 0;
  padding: 14px 20px;
  border-radius: 8px;
  background: rgba(153, 27, 27, 0.92);
  color: #ffffff;
  font-size: 1.3rem;
  font-weight: 850;
  text-align: center;
}

@keyframes flash {
  0%,
  100% {
    opacity: 0.15;
  }
  50% {
    opacity: 0.88;
  }
}

@keyframes viewport-pulse {
  0%,
  100% {
    background-color: var(--background);
  }
  50% {
    background-color: #fee2e2;
  }
}

@keyframes tile-danger {
  from {
    filter: saturate(1);
  }
  to {
    filter: saturate(1.4) brightness(1.08);
  }
}

@keyframes map-danger {
  from {
    box-shadow: 0 10px 20px rgba(13, 65, 83, 0.25), 0 0 0 0 rgba(220, 38, 38, 0.3);
    transform: scale(1);
  }
  to {
    box-shadow: 0 12px 24px rgba(13, 65, 83, 0.28), 0 0 0 10px rgba(220, 38, 38, 0.2);
    transform: scale(1.12);
  }
}

@keyframes map-ripple {
  0% {
    opacity: 0.85;
    transform: scale(0.76);
  }
  100% {
    opacity: 0;
    transform: scale(1.28);
  }
}

@keyframes marquee {
  0% {
    transform: translateX(18%);
  }
  100% {
    transform: translateX(-18%);
  }
}

@media (max-width: 780px) {
  body {
    overflow: auto;
  }

  .kiosk-shell {
    min-height: 100vh;
    padding: 18px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  h1 {
    font-size: 2rem;
  }

  .status-cluster {
    width: 100%;
    justify-content: space-between;
  }

  .test-controls {
    display: grid;
    grid-template-columns: 1fr;
  }

  .test-button {
    width: 100%;
  }

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

  .map-panel-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .map-legend {
    justify-content: flex-start;
  }

  .marina-map {
    min-height: 360px;
  }

  .map-tag {
    max-width: 124px;
  }

  .summary-strip {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .berth-grid {
    grid-template-columns: 1fr;
    grid-auto-rows: minmax(190px, auto);
  }

  .berth-id {
    font-size: 2.25rem;
  }

  .vessel-name {
    font-size: 1.45rem;
  }

  .alert-marquee span {
    font-size: 2.3rem;
  }

  #criticalReason {
    bottom: 16%;
    font-size: 1rem;
  }
}
