/*
 * 한일시멘트 단양 공장 가동현황판 PWA
 *
 * 화면 맞춤 원칙 (Round 5)
 * - 화면 높이 = --vh (100dvh, 미지원 브라우저는 JS가 넣는 --app-h, 그다음 100vh).
 * - 대시보드는 세로 스크롤 없이 한 화면: 헤더/매트릭스/계측/하단 표시등을 fr 비율로 나누고,
 *   각 영역(.board-slot)은 size 컨테이너라 안의 셀·글자가 영역의 폭·높이 중 작은 쪽에 맞춰진다.
 * - 설정·알림은 헤더 고정, 목록만 내부 스크롤. 로그인만 페이지 스크롤 허용(키보드 대응).
 * - 노치·홈 인디케이터: env(safe-area-inset-*).
 */

:root {
  color-scheme: light;
  --blue: #0a58bd;
  --blue-2: #347fdf;
  --sky: #55c9e9;
  --panel: #eeeeee;
  --text: #111111;
  --tile-border: #ececec;
  --green: #00cf2a;
  --green-dark: #008b16;
  --red: #ff1515;
  --pink: #f34b9d;
  --orange: #f4a300;
  --cyan: #12c7dd;
  --olive: #63a400;
  --board: #4a4b49;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --vh: var(--app-h, 100vh);
  font-family: Arial, "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", "Noto Sans CJK KR", sans-serif;
}

@supports (height: 100dvh) {
  :root {
    --vh: 100dvh;
  }
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  height: 100%;
  background: #f3f3f3;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body {
  min-height: var(--vh);
  margin: 0;
  color: var(--text);
  background: #f3f3f3;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* Only the login screen may scroll the page (keyboard). */
body[data-screen="main"],
body[data-screen="settings"],
body[data-screen="notifications"] {
  height: var(--vh);
  overflow: hidden;
}

body[data-screen="main"] {
  background: #222222;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 4px solid rgba(0, 207, 42, 0.5);
  outline-offset: 3px;
}

.view[hidden],
.modal-backdrop[hidden],
.toast[hidden],
.push-banner[hidden],
.board-notice[hidden],
.install-sheet[hidden] {
  display: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ───────────────────────── 로그인 ───────────────────────── */

.login-view {
  min-height: var(--vh);
  /* iOS 홈 화면 추가 안내 시트가 떠 있으면 그 높이만큼 비워 로그인 버튼을 가리지 않는다. */
  padding-bottom: var(--install-sheet-h, 0px);
  display: grid;
  grid-template-rows: minmax(calc(var(--vh) * 0.12), 1fr) auto;
  background: #f4f4f4;
}

.login-hero {
  background: var(--blue);
}

.login-panel {
  width: min(100%, 720px);
  margin: 0 auto;
  padding:
    clamp(16px, calc(var(--vh) * 0.05), 56px)
    max(16px, calc(var(--safe-right) + 12px))
    max(16px, calc(var(--safe-bottom) + 12px))
    max(16px, calc(var(--safe-left) + 12px));
  display: grid;
  gap: clamp(10px, calc(var(--vh) * 0.022), 24px);
}

.login-field {
  height: clamp(46px, calc(var(--vh) * 0.085), 82px);
  display: grid;
  grid-template-columns: clamp(58px, 16vw, 86px) minmax(0, 1fr);
  align-items: center;
  background: var(--blue);
  color: #ffffff;
}

.login-field input {
  width: 100%;
  min-width: 0;
  height: 100%;
  border: 0;
  padding: 0 18px 0 0;
  color: #ffffff;
  background: transparent;
  font-size: clamp(1.15rem, calc(var(--vh) * 0.032), 2rem);
  font-weight: 500;
  letter-spacing: 0;
}

.login-field input::placeholder {
  color: rgba(255, 255, 255, 0.95);
}

.field-icon {
  position: relative;
  width: 44px;
  height: 44px;
  justify-self: center;
  transform: scale(clamp(0.7, calc(var(--vh) * 0.0013), 1));
}

.user-icon::before,
.user-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  background: #ffffff;
}

.user-icon::before {
  top: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
}

.user-icon::after {
  bottom: 3px;
  width: 42px;
  height: 18px;
  border-radius: 20px 20px 3px 3px;
}

/* 열쇠: 고리 + 몸통 + 이 2개, 44px 상자 안에 그린다. */
.key-icon::before {
  content: "";
  position: absolute;
  left: 0;
  top: 12px;
  width: 20px;
  height: 20px;
  border: 6px solid #ffffff;
  border-radius: 50%;
}

.key-icon::after {
  content: "";
  position: absolute;
  left: 18px;
  top: 19px;
  width: 26px;
  height: 14px;
  background:
    linear-gradient(#ffffff, #ffffff) left top / 100% 6px no-repeat,
    linear-gradient(#ffffff, #ffffff) 62% bottom / 5px 100% no-repeat,
    linear-gradient(#ffffff, #ffffff) right bottom / 5px 100% no-repeat;
}

.save-id-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1em;
  min-height: clamp(36px, calc(var(--vh) * 0.06), 72px);
  color: #000000;
  font-size: clamp(1.1rem, calc(var(--vh) * 0.03), 2rem);
  font-weight: 600;
}

.save-id-row input {
  width: 1.1em;
  height: 1.1em;
  margin: 0;
  accent-color: #e60065;
}

.login-hint {
  margin: 0;
  color: #555555;
  text-align: center;
  font-size: clamp(0.92rem, calc(var(--vh) * 0.02), 1.05rem);
  font-weight: 800;
}

.login-button {
  justify-self: center;
  width: min(86%, 900px);
  min-height: clamp(48px, calc(var(--vh) * 0.08), 78px);
  color: #ffffff;
  background: var(--blue-2);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.35);
  font-size: clamp(1.4rem, calc(var(--vh) * 0.042), 2.5rem);
  font-weight: 900;
}

.form-error {
  min-height: 1.4em;
  margin: 0;
  color: #c4002d;
  text-align: center;
  font-size: 1rem;
  font-weight: 800;
}

/* ───────────────────────── 대시보드 ───────────────────────── */

.main-view {
  height: var(--vh);
  overflow: hidden;
  background: #222222;
}

.plant-board {
  position: relative;
  width: min(100%, 640px);
  height: 100%;
  margin: 0 auto;
  padding:
    calc(max(var(--safe-top), 6px) + 4px)
    max(clamp(6px, 2.4vw, 16px), var(--safe-right))
    max(var(--safe-bottom), 8px)
    max(clamp(6px, 2.4vw, 16px), var(--safe-left));
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  /* 헤더 / 설비 매트릭스 / 계측 3줄 / 하단 표시등 — 기존 앱 화면 비율 */
  grid-template-rows: minmax(0, 26fr) minmax(0, 108fr) minmax(0, 50fr) minmax(0, 14fr);
  row-gap: calc(var(--vh) * 0.012);
  overflow: hidden;
  background:
    linear-gradient(112deg, rgba(255, 255, 255, 0.32), rgba(255, 255, 255, 0.02) 34%, rgba(0, 0, 0, 0.36) 100%),
    repeating-linear-gradient(68deg, rgba(255, 255, 255, 0.13) 0 2px, transparent 2px 6px),
    var(--board);
}

.board-slot {
  min-width: 0;
  min-height: 0;
  container-type: size;
}

.slot-matrix,
.slot-metrics,
.slot-footer {
  display: grid;
  place-items: center;
  transition: opacity 240ms ease, filter 240ms ease;
}

/* 끊김(OFF-AIR) 동안 마지막 값을 흐리게 유지 */
.plant-board[data-stale="true"] :is(.slot-matrix, .slot-metrics, .slot-footer) {
  opacity: 0.45;
  filter: grayscale(0.7);
}

.board-notice {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 5;
  margin: 0;
  padding: 0.7em 1.3em;
  border: 2px solid rgba(255, 255, 255, 0.75);
  border-radius: 10px;
  color: #ffffff;
  background: rgba(0, 0, 0, 0.78);
  font-size: clamp(1.05rem, 5vw, 1.5rem);
  font-weight: 900;
  white-space: nowrap;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.board-notice[data-kind="reconnecting"] {
  padding: 0.55em 1.1em;
  border-color: #ffd51f;
  color: #ffd51f;
  background: rgba(0, 0, 0, 0.88);
  font-size: clamp(1rem, 4.4vw, 1.3rem);
  animation: noticeBorderBlink 1.4s ease-in-out infinite;
}

@keyframes noticeBorderBlink {
  0%, 100% {
    border-color: #ffd51f;
  }

  50% {
    border-color: rgba(255, 213, 31, 0.25);
  }
}

/* 헤더: 1줄 = 상태·아이콘(오른쪽), 2줄 = 로고·공장 이름 */
.plant-header {
  --icon: min(40cqh, 12.5cqw, 64px);
  display: grid;
  grid-template-rows: minmax(0, 0.92fr) minmax(0, 1.08fr);
  align-items: center;
}

.header-actions {
  grid-row: 1;
  justify-self: end;
  display: flex;
  align-items: center;
  gap: min(2cqw, 12px);
}

.air-status {
  width: calc(var(--icon) * 1.45);
  height: calc(var(--icon) * 0.58);
  display: grid;
  place-items: center;
  border: max(2px, calc(var(--icon) * 0.045)) solid #f03838;
  border-radius: 3px;
  color: #f03838;
  background: rgba(0, 0, 0, 0.55);
  font-size: calc(var(--icon) * 0.25);
  font-weight: 900;
  line-height: 1;
  white-space: nowrap;
  letter-spacing: 0;
}

.air-status[data-state="connected"] {
  color: #ffd51f;
  border-color: #ffd51f;
  animation: airBlink 0.9s ease-in-out infinite;
}

@keyframes airBlink {
  0%, 100% {
    opacity: 1;
  }

  50% {
    opacity: 0.34;
  }
}

.icon-button {
  position: relative;
  width: var(--icon);
  height: var(--icon);
  padding: 0;
  display: grid;
  place-items: center;
  background: transparent;
  line-height: 0;
}

.bell-svg,
.gear-svg,
.exit-svg {
  display: block;
  overflow: visible;
}

.bell-svg {
  width: 86%;
  height: 86%;
  fill: #00b7c7;
  stroke: #006f79;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(3px 3px 1px rgba(0, 0, 0, 0.45));
}

.gear-svg {
  width: 80%;
  height: 80%;
  fill: #2f6fd3;
  stroke: #a8a8a8;
  stroke-width: 7;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(3px 3px 1px rgba(0, 0, 0, 0.55));
}

.gear-svg circle:nth-of-type(2) {
  fill: #1f1f1f;
  stroke: #2f6fd3;
  stroke-width: 4;
}

.exit-button {
  width: calc(var(--icon) * 0.84);
  height: calc(var(--icon) * 0.84);
  border: max(2px, calc(var(--icon) * 0.06)) solid #f0f0f0;
  border-radius: 50%;
  background: #d80b46;
  box-shadow: 3px 4px 0 rgba(0, 0, 0, 0.48);
}

.exit-svg {
  width: 90%;
  height: 90%;
  fill: none;
  stroke: #ffb4ba;
  stroke-width: 6.5;
  stroke-linecap: round;
}

/* New-alert dot on the bell (set by the "09" alert signal). */
.bell-button[data-new-alert="true"]::after {
  content: "";
  position: absolute;
  top: 12%;
  right: 14%;
  width: 22%;
  height: 22%;
  border-radius: 50%;
  background: #ff2d2d;
  box-shadow: 0 0 0 2px #1d1d1d;
}

.brand-title {
  --mark: min(48cqh, 11cqw, 60px);
  grid-row: 2;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: center;
  gap: min(2.4cqw, 14px);
}

.brand-mark {
  position: relative;
  flex: 0 0 auto;
  width: var(--mark);
  height: var(--mark);
  border: max(2px, calc(var(--mark) * 0.065)) solid rgba(255, 255, 255, 0.9);
  border-radius: 50%;
}

.brand-mark::before,
.brand-mark::after {
  content: "";
  position: absolute;
  top: 13%;
  bottom: 13%;
  width: 40%;
  background: #ffffff;
  border-radius: 50%;
  transform: rotate(42deg);
}

.brand-mark::before {
  left: 16%;
}

.brand-mark::after {
  right: 16%;
  opacity: 0.35;
}

.brand-title h1 {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: #ffffff;
  font-size: calc(min(34cqh, 8.2cqw, 44px) * var(--fit, 1));
  line-height: 1.05;
  font-weight: 900;
  letter-spacing: 0;
  white-space: nowrap;
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.28);
}

/* 설비 매트릭스: 라벨 1.55칸 + 셀 6칸, 행 수(--rows)는 JS가 넣는다. 셀은 정사각형 이하. */
.status-matrix {
  --rows: 8;
  --gap: min(1.7cqw, 1.3cqh);
  --cell-w: calc((100cqw - 6 * var(--gap)) / 7.55);
  --cell-h: calc((100cqh - (var(--rows) - 1) * var(--gap)) / var(--rows));
  --cell: min(var(--cell-w), var(--cell-h));
  display: grid;
  grid-template-columns: calc(var(--cell-w) * 1.55) repeat(6, var(--cell-w));
  grid-auto-rows: var(--cell);
  gap: var(--gap);
}

.matrix-row {
  display: contents;
}

.row-label {
  grid-column: 1;
}

.matrix-row > :nth-child(2) {
  grid-column-start: 2;
}

/* C/M 라벨은 기존 앱처럼 두 줄(1~6, 7~10)에 걸친다. */
.matrix-row.is-tall-start .row-label {
  grid-row: span 2;
}

.matrix-row.is-continuation .row-label {
  display: none;
}

.row-label,
.status-cell {
  min-width: 0;
  min-height: 0;
  display: grid;
  place-items: center;
  justify-items: safe center;
  overflow: hidden;
  border: max(1.5px, calc(var(--cell) * 0.045)) solid var(--tile-border);
  border-radius: calc(var(--cell) * 0.12);
  box-shadow: calc(var(--cell) * 0.07) calc(var(--cell) * 0.08) 0 rgba(0, 0, 0, 0.8);
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.row-label {
  color: #f0f0f0;
  background: var(--green-dark);
  font-size: calc(var(--cell) * 0.5 * var(--fit, 1));
}

.matrix-row[data-tone="kl"] .row-label { background: var(--pink); }
.matrix-row[data-tone="com"] .row-label { background: #0400d8; }
.matrix-row[data-tone="cm"] .row-label { background: var(--red); }
.matrix-row[data-tone="rf"] .row-label { background: var(--orange); }
.matrix-row[data-tone="ro"] .row-label { background: var(--cyan); }
.matrix-row[data-tone="gh"] .row-label { background: var(--olive); }

.status-cell {
  color: #666666;
  background: #000000;
  font-size: calc(var(--cell) * 0.6);
}

.status-cell[data-state="on"] {
  color: var(--green);
}

.status-cell-blank {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}

.dot-cell .dot-grid {
  width: calc(var(--cell) * 0.62);
  height: calc(var(--cell) * 0.62);
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16%;
}

.dot-grid i {
  border-radius: 50%;
  background: #666666;
}

.dot-grid i[data-active="true"] {
  background: var(--green);
}

/* 계측값 4칸 × 3줄: 라벨 + 검은 값 칸 */
.metric-panel {
  --col-gap: 4cqw;
  --row-gap: 2.5cqh;
  --mcol: calc((100cqw - 3 * var(--col-gap)) / 4);
  --mrow: min(calc((100cqh - 2 * var(--row-gap)) / 3), calc(var(--mcol) * 0.9));
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: repeat(3, var(--mrow));
  column-gap: var(--col-gap);
  row-gap: var(--row-gap);
}

.metric-item {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 0.42fr) minmax(0, 0.58fr);
  row-gap: 6%;
  color: #ffffff;
  text-align: center;
}

.metric-item h2 {
  align-self: end;
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: rgba(255, 255, 255, 0.88);
  font-size: calc(min(calc(var(--mrow) * 0.3), calc(var(--mcol) * 0.24)) * var(--metric-label-scale, 1) * var(--fit, 1));
  line-height: 1.1;
  font-weight: 900;
  letter-spacing: 0;
  white-space: nowrap;
}

.metric-item strong {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  overflow: hidden;
  padding: 0 6%;
  color: var(--green-dark);
  background: #000000;
  font-size: calc(min(calc(var(--mrow) * 0.38), calc(var(--mcol) * 0.27)) * var(--fit, 1));
  line-height: 1;
  font-weight: 900;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.metric-item span {
  color: rgba(255, 255, 255, 0.78);
  font-size: calc(var(--mrow) * 0.2);
  font-weight: 900;
  white-space: nowrap;
}

/* 하단 표시등: 설정값 + 2치장·3치장·3공장·G/H2 */
.footer-indicators {
  --fsize: min(34cqh, 4.8cqw, 22px);
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  column-gap: 3cqw;
  align-content: center;
  color: #ffffff;
  text-align: center;
}

.footer-indicator {
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto;
  row-gap: 4cqh;
  font-weight: 900;
}

.footer-indicator strong,
.footer-indicator span {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  font-size: calc(var(--fsize) * var(--fit, 1));
  line-height: 1.15;
}

.footer-indicator strong {
  color: rgba(255, 255, 255, 0.72);
}

.footer-indicator span {
  display: flex;
  align-items: center;
  justify-content: safe center;
  gap: 0.45em;
}

.footer-indicator i {
  flex: 0 0 auto;
  width: 0.95em;
  height: 0.95em;
  border-radius: 50%;
  background: #555555;
}

.footer-indicator i[data-state="1"] {
  background: var(--green-dark);
  box-shadow: 0 0 8px rgba(0, 207, 42, 0.75);
}

.footer-indicator i[data-state="0"] {
  background: #e30022;
  box-shadow: 0 0 8px rgba(227, 0, 34, 0.75);
}

/* ───────────────────────── 푸시 알람 설정 ───────────────────────── */

.settings-view,
.notifications-view {
  height: var(--vh);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  background: #eeeeee;
}

.settings-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding:
    calc(var(--safe-top) + clamp(10px, calc(var(--vh) * 0.018), 18px))
    max(clamp(12px, 4vw, 28px), var(--safe-right))
    clamp(10px, calc(var(--vh) * 0.018), 18px)
    max(clamp(12px, 4vw, 28px), var(--safe-left));
  background: var(--sky);
}

.settings-header h1,
.message-header h1 {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: #000000;
  text-align: center;
  line-height: 1.05;
  font-weight: 900;
  letter-spacing: 0;
  white-space: nowrap;
}

.settings-header h1 {
  font-size: clamp(1.6rem, min(8vw, calc(var(--vh) * 0.05)), 2.6rem);
}

.confirm-button {
  min-width: clamp(72px, 22vw, 112px);
  min-height: clamp(42px, calc(var(--vh) * 0.07), 66px);
  padding: 0 0.8em;
  border: 3px solid #111111;
  border-radius: 8px;
  color: #111111;
  background: #ffffff;
  font-size: clamp(1.2rem, 5vw, 1.75rem);
  font-weight: 900;
}

.settings-view {
  grid-template-rows: auto auto minmax(0, 1fr);
}

/* 알림 권한·푸시 등록 상태 한 줄 */
.push-status {
  margin: 0;
  padding: 6px max(clamp(14px, 5vw, 28px), var(--safe-right)) 6px max(clamp(14px, 5vw, 28px), var(--safe-left));
  overflow: hidden;
  color: #4a4b49;
  background: #e2f4fa;
  text-align: center;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: clamp(0.82rem, 3.6vw, 1rem);
  font-weight: 700;
}

.settings-list {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  width: min(100%, 1080px);
  margin: 0 auto;
  padding:
    clamp(10px, calc(var(--vh) * 0.024), 22px)
    max(clamp(14px, 5vw, 28px), var(--safe-right))
    calc(var(--safe-bottom) + 24px)
    max(clamp(14px, 5vw, 28px), var(--safe-left));
  display: grid;
  align-content: start;
  row-gap: clamp(4px, calc(var(--vh) * 0.012), 16px);
}

.setting-row {
  min-height: clamp(42px, calc(var(--vh) * 0.058), 58px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  align-items: center;
  column-gap: clamp(8px, 3.4vw, 24px);
  color: #737373;
  font-size: clamp(1.15rem, 5.4vw, 1.75rem);
  font-weight: 900;
}

.setting-row:first-child {
  margin-bottom: clamp(6px, calc(var(--vh) * 0.024), 28px);
}

.setting-name {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}

.off-label {
  color: #8d8d8d;
}

.on-label {
  color: #00c943;
}

.switch-shell {
  --sw: clamp(60px, 18vw, 104px);
  --sh: calc(var(--sw) * 0.42);
  position: relative;
  width: var(--sw);
  height: var(--sh);
  display: inline-block;
}

.switch-shell input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
}

.switch-shell > span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #bbbbbb;
  pointer-events: none;
  transition: background-color 160ms ease, box-shadow 160ms ease;
}

.switch-shell > span::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 4px;
  width: calc(var(--sh) - 8px);
  height: calc(var(--sh) - 8px);
  border-radius: 50%;
  background: #ffffff;
  transition: transform 160ms ease;
}

.switch-shell input:checked + span {
  background: #00c943;
  box-shadow: inset 0 0 0 2px rgba(0, 112, 32, 0.28), 0 0 10px rgba(0, 201, 67, 0.45);
}

.switch-shell input:checked + span::after {
  transform: translateX(calc(var(--sw) - var(--sh)));
}

/* ───────────────────────── 알림 메시지 ───────────────────────── */

.notifications-view {
  container-type: inline-size;
}

.message-header {
  width: 100%;
  max-width: 1080px;
  margin-inline: auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 2.4fr) minmax(0, 1fr);
  align-items: center;
  gap: clamp(4px, 1.4cqw, 14px);
  padding:
    calc(var(--safe-top) + clamp(6px, calc(var(--vh) * 0.014), 14px))
    max(clamp(4px, 2cqw, 20px), var(--safe-right))
    clamp(6px, calc(var(--vh) * 0.012), 12px)
    max(clamp(4px, 2cqw, 20px), var(--safe-left));
  color: #ffffff;
  background: var(--blue-2);
}

.message-header h1 {
  color: #ffffff;
  font-size: min(8.5cqw, calc(var(--vh) * 0.05), 3.4rem);
}

.query-button,
.message-close {
  min-width: 0;
  display: grid;
  justify-items: center;
  gap: min(1cqw, 6px);
  padding: 0;
  color: #ffffff;
  background: transparent;
  font-size: min(4cqw, calc(var(--vh) * 0.026), 1.55rem);
  font-weight: 900;
  line-height: 1.1;
}

.query-button strong {
  color: #ffffff;
}

.message-close strong {
  color: #ff1f1f;
}

.query-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.search-svg {
  display: block;
  width: min(16cqw, calc(var(--vh) * 0.08), 86px);
  height: auto;
}

.search-svg rect {
  fill: #eeeeee;
}

.search-svg circle,
.search-svg path {
  fill: none;
  stroke: #2f73d3;
  stroke-width: 8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.large-x-icon {
  position: relative;
  width: min(13cqw, calc(var(--vh) * 0.065), 70px);
  height: min(13cqw, calc(var(--vh) * 0.065), 70px);
}

.large-x-icon::before,
.large-x-icon::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 100%;
  height: 22%;
  border-radius: 999px;
  background: #ff4545;
}

.large-x-icon::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

.large-x-icon::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.message-body {
  width: 100%;
  max-width: 1080px;
  min-height: 0;
  margin-inline: auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 4px solid #000000;
  border-top: 0;
  background: #eeeeee;
}

.notification-filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: min(1.6cqw, calc(var(--vh) * 0.012), 14px);
  padding:
    min(3cqw, calc(var(--vh) * 0.018), 24px)
    max(min(2.2cqw, 24px), var(--safe-right))
    min(3cqw, calc(var(--vh) * 0.018), 24px)
    max(min(2.2cqw, 24px), var(--safe-left));
  border-bottom: 6px solid #000000;
}

.filter-chip {
  position: relative;
  min-width: 0;
  min-height: clamp(36px, calc(var(--vh) * 0.062), 64px);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: min(1.2cqw, 10px);
  padding-inline: min(1.6cqw, 14px);
  border: 2px solid #1a1a1a;
  border-radius: 8px;
  background: #f7f7f7;
  font-size: min(3.6cqw, 1.5rem);
  font-weight: 900;
}

.filter-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.filter-box {
  position: relative;
  width: min(6.2cqw, calc(var(--vh) * 0.042), 40px);
  height: min(6.2cqw, calc(var(--vh) * 0.042), 40px);
  border: max(2px, min(1cqw, 5px)) solid #00c62d;
  border-radius: 4px;
  background: #ffffff;
}

.filter-chip input:checked + .filter-box {
  background: #00c62d;
}

.filter-chip input:checked + .filter-box::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 43%;
  width: 34%;
  height: 60%;
  border: solid #ffffff;
  border-width: 0 max(2px, min(0.9cqw, 5px)) max(2px, min(0.9cqw, 5px)) 0;
  transform: translate(-50%, -58%) rotate(45deg);
}

.filter-chip strong {
  min-width: 0;
  overflow: hidden;
  color: #000000;
  text-align: center;
  font-size: calc(1em * var(--fit, 1));
  white-space: nowrap;
}

.message-list {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-bottom: var(--safe-bottom);
}

.message-row {
  display: grid;
  gap: 4px;
  padding:
    clamp(8px, calc(var(--vh) * 0.013), 12px)
    max(clamp(14px, 4cqw, 34px), var(--safe-right))
    clamp(8px, calc(var(--vh) * 0.013), 12px)
    max(clamp(14px, 4cqw, 34px), var(--safe-left));
  border-bottom: 2px solid #d1d1d1;
  color: #252525;
  background: #eeeeee;
  font-size: clamp(1rem, 4.4cqw, 1.45rem);
  line-height: 1.22;
  font-weight: 500;
  content-visibility: auto;
  contain-intrinsic-size: auto 4.2em;
}

.message-time,
.message-text,
.empty-message {
  margin: 0;
  overflow-wrap: anywhere;
}

.empty-message {
  padding: calc(var(--vh) * 0.12) 16px 0;
  color: #777777;
  text-align: center;
  font-size: clamp(1.05rem, 4.4cqw, 1.3rem);
}

/* ───────────────────────── 종료 확인창 ───────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding:
    max(16px, var(--safe-top))
    max(16px, var(--safe-right))
    max(16px, var(--safe-bottom))
    max(16px, var(--safe-left));
  background: rgba(0, 0, 0, 0.62);
}

.exit-dialog {
  width: min(560px, 100%);
  max-height: calc(var(--vh) - 32px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  background: #ffffff;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.55);
}

.exit-dialog header {
  min-height: clamp(48px, calc(var(--vh) * 0.09), 86px);
  display: grid;
  place-items: center;
  color: #ffffff;
  background: var(--blue-2);
  font-size: clamp(1.3rem, 5.5vw, 2rem);
  font-weight: 900;
}

.exit-dialog-body {
  min-height: clamp(100px, calc(var(--vh) * 0.26), 270px);
  display: grid;
  place-items: center;
  overflow: auto;
  padding: clamp(16px, 4vw, 28px);
  color: #6f6f6f;
  text-align: center;
  font-size: clamp(1.15rem, 5.4vw, 2.05rem);
  line-height: 1.42;
  font-weight: 900;
}

.exit-dialog footer {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.exit-dialog footer button {
  min-height: clamp(48px, calc(var(--vh) * 0.08), 84px);
  color: #ffffff;
  font-size: clamp(1.15rem, 4.8vw, 1.85rem);
  font-weight: 900;
}

.dialog-cancel {
  background: #bfbfbf;
}

.dialog-confirm {
  background: var(--blue-2);
}

/* ───────────────────────── 공통 오버레이 ───────────────────────── */

/* 앱이 열려 있을 때 받은 푸시 (안드로이드·데스크톱). 누르면 알림 화면으로. */
.push-banner {
  position: fixed;
  top: max(10px, calc(var(--safe-top) + 6px));
  left: 12px;
  right: 12px;
  z-index: 90;
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 16px;
  display: grid;
  gap: 2px;
  border: 0;
  border-radius: 12px;
  color: #ffffff;
  background: rgba(20, 20, 20, 0.94);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.4);
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.push-banner strong {
  font-size: 0.95rem;
  font-weight: 900;
  color: #8fd3ff;
}

.push-banner span {
  font-size: 1.05rem;
  line-height: 1.35;
  word-break: keep-all;
}

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: max(18px, calc(var(--safe-bottom) + 12px));
  z-index: 80;
  max-width: 720px;
  margin: 0 auto;
  padding: 14px 18px;
  border-radius: 8px;
  color: #ffffff;
  background: rgba(0, 0, 0, 0.86);
  text-align: center;
  font-weight: 900;
}

.toast[data-tone="warn"] {
  background: #6f5200;
}

/* iOS 홈 화면 추가 안내 (iOS Safari, 비 standalone) */
.install-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 120;
  max-width: 560px;
  margin: 0 auto;
  padding: 18px max(20px, var(--safe-right)) calc(16px + var(--safe-bottom)) max(20px, var(--safe-left));
  display: grid;
  gap: 10px;
  border-radius: 16px 16px 0 0;
  color: #222222;
  background: #ffffff;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.35);
}

.install-sheet h2 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 900;
}

.install-sheet p {
  margin: 0;
  word-break: keep-all;
  font-size: 1rem;
  line-height: 1.5;
}

.share-glyph {
  width: 1.15em;
  height: 1.15em;
  vertical-align: -0.2em;
  fill: none;
  stroke: #1677ff;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.install-sheet-close {
  justify-self: end;
  min-width: 96px;
  min-height: 44px;
  border-radius: 8px;
  color: #ffffff;
  background: var(--blue-2);
  font-size: 1.05rem;
  font-weight: 900;
}

/* 가로 모드: 설치 앱은 manifest로 세로 고정. 고정이 안 되는 브라우저/iOS에서는 안내로 덮는다. */
.rotate-notice {
  display: none;
}

@media (orientation: landscape) and (max-height: 540px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  #app,
  .toast,
  .install-sheet,
  .modal-backdrop {
    visibility: hidden;
  }

  .rotate-notice {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 18px;
    color: #ffffff;
    background: #1d1d1d;
    text-align: center;
  }

  .rotate-notice p {
    margin: 0;
    font-size: clamp(1.2rem, 5vh, 1.6rem);
    font-weight: 900;
  }

  .rotate-phone {
    width: 34px;
    height: 58px;
    border: 4px solid #ffffff;
    border-radius: 8px;
    animation: rotateHint 1.8s ease-in-out infinite;
  }
}

@keyframes rotateHint {
  0%, 25% {
    transform: rotate(-90deg);
  }

  60%, 100% {
    transform: rotate(0deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .air-status[data-state="connected"],
  .board-notice[data-kind="reconnecting"],
  .rotate-phone {
    animation: none;
  }
}

/* 큰 화면(태블릿·PC): 가운데 정렬, 과하게 커지지 않게 */
@media (min-width: 900px) {
  body[data-screen="main"] {
    background: #181818;
  }

  .login-view,
  .settings-view,
  .notifications-view {
    width: min(100%, 1080px);
    margin: 0 auto;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08), 0 18px 70px rgba(0, 0, 0, 0.22);
  }
}
