:root {
  --ink: #111827;
  --muted: #647181;
  --line: #d2dce5;
  --surface: #f4f8fb;
  --panel: #ffffff;
  --blue: #2563c9;
  --working: #0f6e60;
  --standby: #cf9723;
  --alarm: #b23d37;
}

* {
  box-sizing: border-box;
}

html {
  overflow-y: scroll;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #edf2f6;
  color: var(--ink);
  font-family: "Segoe UI", "Malgun Gothic", system-ui, sans-serif;
}

.hidden {
  display: none !important;
}

.scroll-top-button {
  position: fixed;
  z-index: 60;
  left: 16px;
  bottom: 18px;
  width: 76px;
  height: 74px;
  display: grid;
  place-content: center;
  gap: 5px;
  transform: none;
  border: 0;
  border-radius: 7px;
  background: rgba(72, 72, 72, 0.82);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 5px 16px rgba(15, 23, 42, 0.16);
}

.scroll-top-button span {
  font-size: 11px;
  line-height: 1;
}

.scroll-top-button strong {
  font-size: 13px;
}

.scroll-top-button:hover {
  background: rgba(47, 47, 47, 0.9);
}

.scroll-top-button:focus-visible {
  outline: 3px solid rgba(90, 174, 241, 0.55);
  outline-offset: 2px;
}

.monitor-page {
  width: 100%;
  margin: 0;
  padding: 26px;
}

.monitor-topbar,
.monitor-heading,
.monitor-device {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.monitor-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-radius: 8px 8px 0 0;
  box-shadow: 0 2px 8px rgba(17, 24, 39, 0.04);
}

.monitor-brand {
  min-width: 0;
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  column-gap: 18px;
}

.monitor-brand img {
  width: 174px;
  height: auto;
}

.monitor-brand p,
.monitor-brand h1,
.monitor-heading h2,
.monitor-heading p {
  margin: 0;
}

.monitor-brand p {
  color: #0f766e;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.monitor-brand h1 {
  margin-top: 3px;
  font-size: 28px;
}

.monitor-user {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas:
    "user actions"
    "last-seen last-seen";
  gap: 6px 12px;
  align-items: center;
  justify-items: end;
  text-align: right;
}

.monitor-user > strong {
  grid-area: user;
  align-self: center;
}

.monitor-nav {
  grid-area: actions;
  display: flex;
  align-items: center;
  gap: 7px;
}

.page-icon-link {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: #fff;
  text-decoration: none;
  transition: background 120ms ease, color 120ms ease;
}

.page-icon-link:hover {
  background: transparent;
}

.page-icon-link.active {
  background: transparent;
  box-shadow: none;
}

.nav-glyph {
  width: 35px;
  height: 35px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: #5aaef1;
  font-family: "Segoe MDL2 Assets", "Segoe UI Symbol", sans-serif;
  font-size: 19px;
  line-height: 1;
  transition: background 120ms ease;
}

.page-icon-link:hover .nav-glyph {
  background: #429ee5;
}

.home-glyph::before {
  content: "\E80F";
}

.monitor-glyph::before {
  content: "\E7F4";
}

.monitor-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin: 0 0 18px;
  min-height: 64px;
  border-top: 0;
  border-radius: 0 0 8px 8px;
  padding: 10px 20px;
  background: #eaf0f4;
  box-shadow: 0 8px 24px rgba(17, 24, 39, 0.06);
}

.monitor-heading h2 {
  font-size: 16px;
}

.monitor-heading p,
#monitorUpdatedAt {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

#monitorUpdatedAt {
  grid-area: last-seen;
  margin-top: 0;
}

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

.monitor-device {
  --state-color: var(--alarm);
  display: grid;
  grid-template-columns: 210px 230px 260px minmax(480px, 1fr);
  gap: 10px;
  min-height: 300px;
  padding: 12px;
}

.monitor-device.state-working {
  --state-color: var(--working);
}

.monitor-device.state-standby {
  --state-color: var(--standby);
}

.monitor-machine,
.monitor-info,
.type-summary {
  border: 1px solid #d8e2ea;
  border-radius: 7px;
  background: #fff;
}

.monitor-machine {
  position: relative;
  min-height: 274px;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.monitor-machine::before {
  content: "";
  position: absolute;
  top: 13px;
  left: 12px;
  right: 12px;
  height: 7px;
  border-radius: 999px;
  background: var(--state-color);
}

.monitor-machine img {
  width: 88%;
  max-height: 230px;
  object-fit: contain;
  margin-top: 22px;
}

.tool-life-alert {
  position: absolute;
  top: 72px;
  left: 12px;
  right: 12px;
  z-index: 1;
  color: #16212b;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.45;
  text-align: center;
}

.monitor-info {
  padding: 15px 12px;
}

.monitor-info h3 {
  margin: 0;
  font-size: 20px;
}

.device-subtitle {
  margin: 6px 0 13px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

.device-progress {
  margin-bottom: 13px;
  color: #46596b;
  font-size: 12px;
  font-weight: 800;
}

.compact-metric {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 8px;
  align-items: center;
  min-height: 58px;
  margin-top: 8px;
  border: 1px solid #dbe4eb;
  border-radius: 7px;
  background: #f8fafc;
  padding: 8px;
}

.compact-icon,
.type-marker {
  display: grid;
  place-items: center;
  color: var(--blue);
}

.compact-icon {
  position: relative;
  width: 26px;
  height: 26px;
}

.icon-program::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 5px;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 6px 0 currentColor, 0 12px 0 currentColor;
}

.icon-program::after {
  content: "";
  position: absolute;
  left: 9px;
  top: 5px;
  width: 15px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  box-shadow: 0 6px 0 currentColor, 0 12px 0 currentColor;
}

.icon-connection::before,
.icon-connection::after {
  content: "";
  position: absolute;
  clip-path: polygon(50% 0, 93% 25%, 93% 75%, 50% 100%, 7% 75%, 7% 25%);
}

.icon-connection::before {
  inset: 1px;
  background: currentColor;
}

.icon-connection::after {
  inset: 4px;
  background: #f8fafc;
}

.icon-quantity::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 5px;
  width: 18px;
  height: 15px;
  border: 2px solid currentColor;
  border-radius: 2px;
}

.icon-quantity::after {
  content: "";
  position: absolute;
  left: 8px;
  top: 1px;
  width: 10px;
  height: 10px;
  border-top: 2px solid currentColor;
  border-right: 2px solid currentColor;
  transform: rotate(-45deg);
}

.icon-time::before {
  content: "";
  position: absolute;
  inset: 2px;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.icon-time::after {
  content: "";
  position: absolute;
  left: 12px;
  top: 7px;
  width: 5px;
  height: 7px;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
}

.compact-metric span,
.compact-metric strong {
  display: block;
}

.compact-metric span {
  color: var(--muted);
  font-size: 10px;
}

.compact-metric strong {
  margin-top: 3px;
  font-size: 12px;
  word-break: break-word;
}

/* Keep long NC file names readable in the program card. */
.compact-metric-program {
  align-items: start;
  min-height: 78px;
}

.compact-metric-program .compact-icon {
  margin-top: 4px;
}

.compact-metric-program strong {
  font-size: 10.8px;
  line-height: 1.35;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.metric-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.metric-pair .compact-metric {
  grid-template-columns: 1fr;
  text-align: center;
}

.type-summary {
  padding: 13px 12px 8px;
}

.type-summary h4 {
  margin: 0 0 8px;
  font-size: 12px;
}

.type-list {
  display: grid;
}

.type-row {
  min-height: 29px;
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr) auto;
  gap: 7px;
  align-items: center;
  border-bottom: 1px solid #e4ebf0;
  font-size: 11px;
  font-weight: 800;
}

.type-row:last-child {
  border-bottom: 0;
}

.type-marker {
  position: relative;
  width: 15px;
  height: 15px;
  background: transparent;
}

.type-marker::before,
.type-marker::after {
  content: "";
  position: absolute;
  clip-path: polygon(50% 0, 93% 25%, 93% 75%, 50% 100%, 7% 75%, 7% 25%);
}

.type-marker::before {
  inset: 0;
  background: currentColor;
}

.type-marker::after {
  inset: 2px;
  background: #fff;
}

.type-row em {
  color: currentColor;
  font-style: normal;
}

.connection-chart {
  min-width: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: 18px 10px 0;
}

.connection-chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 2px 4px;
}

.connection-chart-head h4,
.connection-chart-head p {
  margin: 0;
}

.connection-chart-head h4 {
  font-size: 15px;
}

.connection-chart-head p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 10px;
}

.connection-period {
  width: 76px;
  height: 32px;
  border: 1px solid #b9cbd7;
  border-radius: 6px;
  background: #fff;
  padding: 0 9px;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
}

.connection-chart-body {
  width: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: flex-end;
  overflow: hidden;
}

.connection-chart-svg {
  display: block;
  width: 100%;
  min-width: 0;
  height: auto;
  max-height: 100%;
}

.connection-grid {
  stroke: #d7e1e8;
  stroke-width: 1;
}

.connection-axis {
  fill: #657485;
  font-size: 11px;
}

.monitor-empty {
  border: 1px dashed #aebdca;
  border-radius: 8px;
  background: #fff;
  padding: 30px;
  color: var(--muted);
  text-align: center;
}

/*
 * FHD monitoring view
 * Use medium density for three devices and compact density for four or more.
 */
@media (min-width: 1440px) and (min-height: 900px) {
  body.monitor-compact .monitor-page {
    padding: 12px 18px 14px;
  }

  body.monitor-compact .monitor-topbar {
    min-height: 66px;
    padding: 8px 16px;
  }

  body.monitor-compact .monitor-brand {
    column-gap: 14px;
  }

  body.monitor-compact .monitor-brand img {
    width: 142px;
  }

  body.monitor-compact .monitor-brand p {
    font-size: 10px;
  }

  body.monitor-compact .monitor-brand h1 {
    margin-top: 1px;
    font-size: 22px;
  }

  body.monitor-compact .monitor-user {
    gap: 2px 9px;
  }

  body.monitor-compact #monitorUpdatedAt {
    font-size: 10px;
  }

  body.monitor-compact .monitor-heading {
    min-height: 44px;
    margin-bottom: 7px;
    padding: 5px 16px;
  }

  body.monitor-compact .monitor-heading h2 {
    font-size: 13px;
  }

  body.monitor-compact .monitor-heading p {
    margin-top: 2px;
    font-size: 9px;
  }

  body.monitor-compact .monitor-device-list {
    gap: 7px;
  }

  body.monitor-compact .monitor-device {
    grid-template-columns: 180px 230px 245px minmax(420px, 1fr);
    grid-template-rows: minmax(0, 1fr);
    gap: 7px;
    height: clamp(140px, calc((100dvh - 171px) / 5), 154px);
    min-height: 140px;
    padding: 6px;
    overflow: hidden;
  }

  body.monitor-compact .monitor-machine,
  body.monitor-compact .monitor-info,
  body.monitor-compact .type-summary {
    min-height: 0;
    height: 100%;
    align-self: stretch;
  }

  body.monitor-compact .monitor-machine::before {
    top: 7px;
    left: 8px;
    right: 8px;
    height: 5px;
  }

  body.monitor-compact .monitor-machine img {
    width: 78%;
    max-height: calc(100% - 20px);
    margin-top: 13px;
  }

  body.monitor-compact .tool-life-alert {
    top: 46px;
    left: 8px;
    right: 8px;
    font-size: 11px;
  }

  body.monitor-compact .monitor-info {
    display: grid;
    grid-template-rows: auto auto auto repeat(3, minmax(0, 1fr));
    gap: 2px;
    padding: 6px 8px;
    overflow: hidden;
  }

  body.monitor-compact .monitor-info h3 {
    font-size: 15px;
    line-height: 1.1;
  }

  body.monitor-compact .device-subtitle {
    margin: 0;
    font-size: 8px;
    line-height: 1.25;
    white-space: nowrap;
  }

  body.monitor-compact .device-progress {
    margin: 0;
    font-size: 9px;
    line-height: 1.15;
  }

  body.monitor-compact .compact-metric {
    grid-template-columns: 20px minmax(0, 1fr);
    gap: 5px;
    min-height: 0;
    height: 100%;
    margin-top: 0;
    padding: 2px 5px;
  }

  body.monitor-compact .compact-icon {
    width: 19px;
    height: 19px;
    transform: scale(0.7);
  }

  body.monitor-compact .compact-metric span {
    font-size: 8px;
    line-height: 1;
  }

  body.monitor-compact .compact-metric strong {
    margin-top: 1px;
    font-size: 9px;
    line-height: 1.05;
  }

  body.monitor-compact .metric-pair {
    gap: 4px;
    min-height: 0;
  }

  body.monitor-compact .metric-pair .compact-metric {
    grid-template-columns: 18px minmax(0, 1fr);
    gap: 3px;
    text-align: left;
  }

  body.monitor-compact .type-summary {
    padding: 7px 8px 4px;
    overflow: hidden;
  }

  body.monitor-compact .type-summary h4 {
    margin-bottom: 2px;
    font-size: 9px;
  }

  body.monitor-compact .type-row {
    min-height: 14px;
    grid-template-columns: 12px minmax(0, 1fr) auto;
    gap: 4px;
    font-size: 8px;
    line-height: 1;
  }

  body.monitor-compact .type-marker {
    width: 10px;
    height: 10px;
  }

  body.monitor-compact .connection-chart {
    min-height: 0;
    height: 100%;
    padding: 6px 5px 0;
    overflow: hidden;
  }

  body.monitor-compact .connection-chart-head {
    gap: 8px;
    padding-bottom: 1px;
  }

  body.monitor-compact .connection-chart-head h4 {
    font-size: 11px;
  }

  body.monitor-compact .connection-chart-head p {
    margin-top: 1px;
    font-size: 8px;
  }

  body.monitor-compact .connection-period {
    width: 58px;
    height: 24px;
    padding: 0 6px;
    font-size: 9px;
  }

  body.monitor-compact .connection-chart-svg {
    width: 100%;
    height: 100%;
    max-height: 100%;
  }

  body.monitor-compact .connection-axis {
    font-size: 9px;
  }

  body.monitor-medium .monitor-device-list {
    gap: 9px;
  }

  body.monitor-medium .monitor-device {
    grid-template-columns: 190px 220px 250px minmax(420px, 1fr);
    grid-template-rows: minmax(0, 1fr);
    gap: 8px;
    height: clamp(220px, calc((100dvh - 210px) / 3), 245px);
    min-height: 220px;
    padding: 8px;
    overflow: hidden;
  }

  body.monitor-medium .monitor-machine,
  body.monitor-medium .monitor-info,
  body.monitor-medium .type-summary {
    min-height: 0;
    height: 100%;
    align-self: stretch;
  }

  body.monitor-medium .monitor-machine::before {
    top: 9px;
    left: 9px;
    right: 9px;
    height: 6px;
  }

  body.monitor-medium .monitor-machine img {
    width: 82%;
    max-height: calc(100% - 24px);
    margin-top: 16px;
  }

  body.monitor-medium .tool-life-alert {
    top: 54px;
    left: 9px;
    right: 9px;
    font-size: 12px;
  }

  body.monitor-medium .monitor-info {
    padding: 9px 10px;
    overflow: hidden;
  }

  body.monitor-medium .monitor-info h3 {
    font-size: 17px;
  }

  body.monitor-medium .device-subtitle {
    margin: 3px 0 6px;
    font-size: 9px;
    line-height: 1.3;
    white-space: nowrap;
  }

  body.monitor-medium .device-progress {
    margin-bottom: 5px;
    font-size: 10px;
  }

  body.monitor-medium .compact-metric {
    grid-template-columns: 24px minmax(0, 1fr);
    gap: 6px;
    min-height: 35px;
    margin-top: 5px;
    padding: 4px 6px;
  }

  body.monitor-medium .compact-icon {
    width: 22px;
    height: 22px;
    transform: scale(0.84);
  }

  body.monitor-medium .compact-metric span {
    font-size: 9px;
  }

  body.monitor-medium .compact-metric strong {
    margin-top: 1px;
    font-size: 10px;
  }

  body.monitor-medium .metric-pair {
    gap: 5px;
  }

  body.monitor-medium .metric-pair .compact-metric {
    grid-template-columns: 22px minmax(0, 1fr);
    gap: 4px;
    text-align: left;
  }

  body.monitor-medium .type-summary {
    padding: 9px 10px 5px;
    overflow: hidden;
  }

  body.monitor-medium .type-summary h4 {
    margin-bottom: 4px;
    font-size: 10px;
  }

  body.monitor-medium .type-row {
    min-height: 23px;
    grid-template-columns: 15px minmax(0, 1fr) auto;
    gap: 5px;
    font-size: 9px;
  }

  body.monitor-medium .type-marker {
    width: 12px;
    height: 12px;
  }

  body.monitor-medium .connection-chart {
    min-height: 0;
    height: 100%;
    padding: 10px 7px 0;
    overflow: hidden;
  }

  body.monitor-medium .connection-chart-head {
    gap: 10px;
    padding-bottom: 2px;
  }

  body.monitor-medium .connection-chart-head h4 {
    font-size: 13px;
  }

  body.monitor-medium .connection-chart-head p {
    margin-top: 1px;
    font-size: 9px;
  }

  body.monitor-medium .connection-period {
    width: 66px;
    height: 28px;
    padding: 0 7px;
    font-size: 10px;
  }

  body.monitor-medium .connection-chart-svg {
    width: 100%;
    height: 100%;
    max-height: 100%;
  }

  body.monitor-medium .connection-axis {
    font-size: 10px;
  }
}

@media (max-width: 1200px) {
  .monitor-device {
    grid-template-columns: 190px 220px minmax(240px, 1fr);
  }

  .connection-chart {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .monitor-page {
    width: 100%;
    margin-top: 0;
    padding: 0;
  }

  .monitor-topbar,
  .monitor-heading {
    border-radius: 0;
  }

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

  .monitor-brand img {
    width: 120px;
  }

  .monitor-device {
    grid-template-columns: 1fr;
    border-radius: 0;
  }

  .connection-chart {
    grid-column: auto;
  }
}
