:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --line: #d9e1e5;
  --text: #111111;
  --muted: #5f6670;
  --accent: #f2d051;
  --accent-ink: #111111;
  --online: #1f7a4d;
  --offline: #a23a2a;
  --state-green: #1f7a4d;
  --state-orange: #b95000;
  --state-red: #b42318;
  --state-purple: #6d28d9;
  --state-grey: #dce2e7;
}

* {
  box-sizing: border-box;
}

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

button {
  min-height: 40px;
  border: 1px solid var(--accent);
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 0 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 28px;
}

.login-panel h1 {
  margin: 0 0 8px;
  font-size: 38px;
  line-height: 1;
  letter-spacing: 0;
}

.login-panel label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.login-panel input {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  color: var(--text);
  font: inherit;
  font-size: 17px;
  text-transform: uppercase;
}

.login-panel input[type="password"] {
  text-transform: none;
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: var(--offline);
  font-weight: 700;
}

.login-hint {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.login-secondary-button {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
}

.simple-topbar {
  min-height: 112px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  padding: 18px 24px;
  background: #000000;
}

.topbar-brand {
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 16px;
  color: #fff;
}

.topbar-logo {
  width: 76px;
  height: 76px;
  display: block;
  object-fit: contain;
}

.topbar-brand-text {
  display: grid;
  gap: 2px;
}

.topbar-brand-text strong {
  color: #fff;
  font-size: 36px;
  line-height: 1;
  letter-spacing: 0;
}

.topbar-brand-text span {
  color: var(--accent);
  font-size: 13px;
  line-height: 1.2;
  letter-spacing: 0;
  font-weight: 700;
}

.topbar-bobrudd-logo {
  justify-self: center;
  width: 95px;
  height: auto;
  display: block;
  object-fit: contain;
}

.logout-button {
  justify-self: end;
}

.site-view {
  width: 90vw;
  margin: 0 auto;
  padding: 34px 0;
}

.site-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin: 0 0 28px;
}

#siteTitle {
  margin: 0;
  font-size: clamp(36px, 6vw, 76px);
  line-height: 0.98;
  letter-spacing: 0;
}

.bdm-panel {
  min-width: 260px;
  max-width: 34%;
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: 12px;
  row-gap: 4px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 10px 14px 10px 10px;
  text-align: right;
  box-shadow: 0 12px 30px rgba(23, 32, 38, 0.08);
}

.bdm-panel span {
  grid-column: 2;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.bdm-panel strong {
  grid-column: 2;
  color: var(--text);
  font-size: 22px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.bdm-panel.has-error strong {
  color: var(--offline);
}

.bdm-identity {
  display: contents;
}

.bdm-contact-button {
  grid-column: 1;
  grid-row: 1 / 3;
  align-self: stretch;
  width: 58px;
  min-width: 58px;
  min-height: 70px;
  display: grid;
  place-items: center;
  padding: 0;
}

.bdm-contact-button svg {
  width: 29px;
  height: 29px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.bdm-contact-button:disabled {
  border-color: var(--line);
  background: #c6d0d6;
  color: #4c5a64;
  cursor: not-allowed;
}

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

.machine-sections {
  display: grid;
  gap: 30px;
}

.machine-site-section {
  display: grid;
  gap: 14px;
}

.machine-site-heading {
  margin: 0;
  color: var(--text);
  font-size: clamp(26px, 3.2vw, 42px);
  line-height: 1.05;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.machine-section-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.machine-tile {
  --state-bg: var(--state-grey);
  --state-text: var(--text);
  --state-muted: rgba(23, 32, 38, 0.72);
  --state-line: rgba(23, 32, 38, 0.16);
  min-height: 150px;
  display: grid;
  align-content: start;
  gap: 18px;
  border: 1px solid var(--state-line);
  border-radius: 8px;
  background: var(--state-bg);
  color: var(--state-text);
  padding: 18px;
  box-shadow: 0 14px 34px rgba(23, 32, 38, 0.08);
  cursor: pointer;
  transition: transform 140ms ease, box-shadow 140ms ease;
}

.machine-tile:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 40px rgba(23, 32, 38, 0.14);
}

.machine-tile:focus-visible {
  outline: 3px solid var(--text);
  outline-offset: 4px;
}

.machine-state-green {
  --state-bg: var(--state-green);
  --state-text: #ffffff;
  --state-muted: rgba(255, 255, 255, 0.78);
  --state-line: rgba(255, 255, 255, 0.24);
}

.machine-state-orange {
  --state-bg: var(--state-orange);
  --state-text: #ffffff;
  --state-muted: rgba(255, 255, 255, 0.8);
  --state-line: rgba(255, 255, 255, 0.24);
}

.machine-state-red {
  --state-bg: var(--state-red);
  --state-text: #ffffff;
  --state-muted: rgba(255, 255, 255, 0.8);
  --state-line: rgba(255, 255, 255, 0.24);
  animation: red-alert 1s ease-in-out infinite;
}

.machine-state-purple {
  --state-bg: var(--state-purple);
  --state-text: #ffffff;
  --state-muted: rgba(255, 255, 255, 0.82);
  --state-line: rgba(255, 255, 255, 0.28);
  animation: purple-alert 1s ease-in-out infinite;
}

.machine-state-grey {
  --state-bg: var(--state-grey);
  --state-text: var(--text);
  --state-muted: rgba(23, 32, 38, 0.72);
  --state-line: rgba(23, 32, 38, 0.16);
}

.machine-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.machine-presence {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.machine-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  color: var(--state-muted);
  font-weight: 800;
  text-transform: uppercase;
  font-size: 13px;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 3px var(--state-line);
}

body.popup-open {
  overflow: hidden;
}

.entry-popup {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
}

.entry-popup-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(23, 32, 38, 0.58);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.entry-popup-panel {
  position: relative;
  z-index: 1;
  width: 70vw;
  height: 80vh;
  display: flex;
  flex-direction: column;
  border-radius: 8px;
  border: 1px solid rgba(217, 225, 229, 0.9);
  background: #fbfcfd;
  color: var(--text);
  padding: 28px;
  box-shadow: 0 28px 70px rgba(23, 32, 38, 0.32);
}

.entry-popup-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 40px;
  min-height: 40px;
  display: grid;
  place-items: center;
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  font-size: 28px;
  line-height: 1;
}

.entry-popup-close:hover {
  border-color: var(--text);
}

.entry-popup-status {
  width: fit-content;
  margin: 0 48px 14px 0;
  border-radius: 999px;
  background: var(--state-bg);
  color: var(--state-text);
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.entry-popup-panel h2 {
  margin: 0 48px 14px 0;
  font-size: 32px;
  line-height: 1.1;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.entry-popup-reason {
  margin: 0 0 16px;
  border: 1px solid rgba(242, 208, 81, 0.55);
  border-left: 5px solid var(--accent);
  border-radius: 8px;
  background: #fff9df;
  color: var(--text);
  padding: 13px 16px;
  font-size: 16px;
  line-height: 1.35;
  font-weight: 800;
}

.entry-popup-details {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  gap: 12px;
  margin: 0;
  padding: 2px 2px 8px;
  overflow: auto;
  scrollbar-color: #8fa0aa transparent;
  scrollbar-width: thin;
}

.entry-popup-details::-webkit-scrollbar {
  width: 10px;
}

.entry-popup-details::-webkit-scrollbar-thumb {
  border: 3px solid #fbfcfd;
  border-radius: 999px;
  background: #8fa0aa;
}

.entry-popup-details div {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  min-height: 82px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 13px 14px;
}

.entry-popup-details dt {
  color: var(--muted);
  line-height: 1.2;
}

.entry-popup-details dd {
  margin: 0;
  color: var(--text);
  text-align: left;
  font-size: 19px;
  line-height: 1.2;
}

.entry-popup-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 14px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.entry-popup-help {
  min-width: 150px;
}

.entry-popup-help:disabled {
  cursor: wait;
  opacity: 0.74;
}

.entry-popup-help-status {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  text-align: right;
}

.entry-help-panel {
  display: grid;
  grid-template-columns: minmax(190px, 0.35fr) minmax(0, 1fr);
  gap: 18px;
  margin-top: 14px;
  border: 1px solid rgba(242, 208, 81, 0.6);
  border-radius: 8px;
  background: #fff9df;
  padding: 16px;
}

.entry-help-copy {
  display: grid;
  align-content: start;
  gap: 8px;
}

.entry-help-copy h3 {
  margin: 0;
  font-size: 17px;
  line-height: 1.2;
  letter-spacing: 0;
}

.entry-help-copy p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
  font-weight: 700;
}

.entry-help-tips {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.entry-help-tips li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  border: 1px solid rgba(242, 208, 81, 0.45);
  border-radius: 8px;
  background: var(--surface);
  padding: 10px;
}

.entry-help-tips span {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 900;
}

.entry-help-tips p {
  margin: 0;
  color: var(--text);
  font-size: 14px;
  line-height: 1.35;
  font-weight: 700;
}

.contact-popup {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
}

.contact-popup-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(23, 32, 38, 0.58);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.contact-popup-panel {
  position: relative;
  z-index: 1;
  width: min(640px, 90vw);
  max-height: 80vh;
  display: grid;
  gap: 18px;
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 24px;
  box-shadow: 0 28px 70px rgba(23, 32, 38, 0.32);
}

.contact-popup-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 40px;
  min-height: 40px;
  display: grid;
  place-items: center;
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
  padding: 0;
  font-size: 28px;
  line-height: 1;
}

.contact-popup-panel h2 {
  margin: 0 48px 0 0;
  font-size: 28px;
  line-height: 1.1;
  letter-spacing: 0;
}

.contact-form {
  display: grid;
  gap: 12px;
}

.contact-form label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-transform: uppercase;
}

.contact-form textarea {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  padding: 12px;
  font: inherit;
  line-height: 1.45;
}

.contact-form textarea:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(242, 208, 81, 0.28);
}

.contact-popup-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.secondary-button {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
}

.contact-popup-status {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.machine-tile h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.15;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.machine-site {
  color: var(--state-muted);
  font-size: 13px;
  font-weight: 700;
}

dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

dt {
  color: var(--state-muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

dd {
  margin: 4px 0 0;
  font-size: 20px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

@keyframes purple-alert {
  0%,
  100% {
    background: #5b21b6;
    box-shadow: 0 14px 34px rgba(91, 33, 182, 0.24);
  }

  50% {
    background: #8b5cf6;
    box-shadow: 0 18px 44px rgba(109, 40, 217, 0.38);
  }
}

@keyframes red-alert {
  0%,
  100% {
    background: #991b1b;
    box-shadow: 0 14px 34px rgba(153, 27, 27, 0.24);
  }

  50% {
    background: #ef4444;
    box-shadow: 0 18px 44px rgba(180, 35, 24, 0.38);
  }
}

.loading-state,
.empty-state,
.error-state {
  min-height: 240px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  padding: 24px;
  text-align: center;
}

.error-state {
  color: var(--offline);
}

[hidden] {
  display: none !important;
}

@media (max-width: 640px) {
  .simple-topbar {
    min-height: 128px;
    grid-template-columns: 1fr auto;
    gap: 14px;
    padding: 14px;
  }

  .topbar-brand {
    justify-self: start;
    gap: 10px;
  }

  .topbar-logo {
    width: 58px;
    height: 58px;
  }

  .topbar-brand-text strong {
    font-size: 28px;
  }

  .topbar-brand-text span {
    max-width: 170px;
    font-size: 11px;
  }

  .topbar-bobrudd-logo {
    grid-column: 1 / -1;
    grid-row: 2;
    width: 79px;
  }

  .site-view {
    width: 90vw;
    padding-top: 24px;
  }

  .machine-grid {
    grid-template-columns: 1fr;
  }

  .machine-section-grid {
    grid-template-columns: 1fr;
  }

  .site-heading {
    display: grid;
    gap: 14px;
  }

  .bdm-panel {
    max-width: none;
    min-width: 0;
    grid-template-columns: 54px minmax(0, 1fr);
    text-align: left;
  }

  .bdm-panel span,
  .bdm-panel strong {
    grid-column: 2;
  }

  .bdm-contact-button {
    width: 54px;
    min-width: 54px;
    min-height: 64px;
  }

  dl {
    grid-template-columns: 1fr;
  }

  .entry-popup {
    padding: 14px;
  }

  .entry-popup-panel {
    width: 90vw;
    height: 84vh;
    padding: 20px;
  }

  .entry-popup-details {
    grid-template-columns: 1fr;
  }

  .entry-popup-details div {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .entry-popup-details dd {
    text-align: left;
  }

  .entry-popup-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .entry-popup-help-status {
    text-align: left;
  }

  .entry-help-panel,
  .entry-help-tips {
    grid-template-columns: 1fr;
  }

  .contact-popup {
    padding: 14px;
  }

  .contact-popup-panel {
    width: 90vw;
    padding: 20px;
  }

  .contact-popup-actions {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (min-width: 641px) and (max-width: 980px) {
  .machine-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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