/* IONTEC IoT 관제 — 브랜드 규격(색·그림자·모션)을 Bootstrap 위에 덮어쓴다.
   색은 아래 토큰만 사용. 상태색(ok/warn/danger)은 상태 표시에만 쓴다. */
:root {
  --navy: #205491;
  --primary: #0058b0;
  --deep: #003399;
  --bright: #0070c0;
  --cyan: #2897d5;
  --cyan-l: #5bb6e8;
  --tint-1: #d6e5f5;
  --tint-2: #eef4fb;
  --tint-3: #f4f8fc;
  --ink-1: #1d2733;
  --ink-2: #2b3440;
  --ink-3: #4a5563;
  --ink-4: #74808f;
  --line: #dde3ea;
  --ok: #2faa5a;
  --warn: #e8a33d;
  --danger: #d64545;
  --muted-bg: #eef1f4;

  --shadow: 0 2px 6px rgba(32, 84, 145, 0.08);
  --shadow-lg: 0 16px 40px rgba(32, 84, 145, 0.18);
  --focus: 0 0 0 3px rgba(40, 151, 213, 0.35);
  --radius: 12px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);

  --bs-body-font-family: 'NanumBarunGothic', '나눔바른고딕', 'Malgun Gothic', 'Apple SD Gothic Neo', system-ui, sans-serif;
  --bs-font-monospace: 'D2Coding', Consolas, 'SFMono-Regular', Menlo, monospace;
  --bs-body-color: var(--ink-2);
  --bs-body-bg: var(--tint-3);
  --bs-border-color: var(--line);
  --bs-primary: var(--primary);
  --bs-primary-rgb: 0, 88, 176;
  --bs-link-color: var(--primary);
  --bs-link-color-rgb: 0, 88, 176;
  --bs-link-hover-color: var(--deep);
  --bs-link-hover-color-rgb: 0, 51, 153;
  --bs-focus-ring-color: rgba(40, 151, 213, 0.35);
}

body {
  background: var(--tint-3);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: var(--bs-font-monospace);
  font-size: 12.5px;
}

.muted {
  color: var(--ink-4);
}

[hidden] {
  display: none !important;
}

/* 조회 전용 계정은 관리 기능 숨김 */
.role-viewer .admin-only {
  display: none !important;
}

/* ---------- 버튼·입력 ---------- */
.btn {
  --bs-btn-border-radius: 8px;
  --bs-btn-font-weight: 700;
  transition: background-color 160ms var(--ease), border-color 160ms var(--ease), color 160ms var(--ease), transform 120ms var(--ease);
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  --bs-btn-bg: var(--primary);
  --bs-btn-border-color: var(--primary);
  --bs-btn-hover-bg: var(--deep);
  --bs-btn-hover-border-color: var(--deep);
  --bs-btn-active-bg: var(--deep);
  --bs-btn-active-border-color: var(--deep);
  --bs-btn-disabled-bg: var(--primary);
  --bs-btn-disabled-border-color: var(--primary);
}

.btn-outline-primary {
  --bs-btn-color: var(--primary);
  --bs-btn-border-color: var(--tint-1);
  --bs-btn-bg: #fff;
  --bs-btn-hover-bg: var(--tint-2);
  --bs-btn-hover-color: var(--deep);
  --bs-btn-hover-border-color: var(--tint-1);
  --bs-btn-active-bg: var(--tint-1);
  --bs-btn-active-color: var(--deep);
  --bs-btn-active-border-color: var(--tint-1);
}

.btn-outline-secondary {
  --bs-btn-color: var(--ink-3);
  --bs-btn-border-color: var(--line);
  --bs-btn-bg: #fff;
  --bs-btn-hover-bg: var(--tint-3);
  --bs-btn-hover-color: var(--ink-1);
  --bs-btn-hover-border-color: var(--line);
  --bs-btn-active-bg: var(--tint-2);
  --bs-btn-active-color: var(--ink-1);
  --bs-btn-active-border-color: var(--line);
  --bs-btn-disabled-color: var(--ink-4);
  --bs-btn-disabled-border-color: var(--line);
}

.btn-outline-danger {
  --bs-btn-color: var(--danger);
  --bs-btn-border-color: rgba(214, 69, 69, 0.35);
  --bs-btn-bg: #fff;
  --bs-btn-hover-bg: var(--danger);
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-border-color: var(--danger);
  --bs-btn-active-bg: #b93a3a;
  --bs-btn-active-border-color: #b93a3a;
}

.btn-danger {
  --bs-btn-bg: var(--danger);
  --bs-btn-border-color: var(--danger);
  --bs-btn-hover-bg: #b93a3a;
  --bs-btn-hover-border-color: #b93a3a;
  --bs-btn-active-bg: #a53333;
}

.btn-link-sm {
  background: none;
  border: 0;
  padding: 4px 2px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.btn-link-sm:hover {
  color: var(--deep);
  text-decoration: underline;
}

.form-control,
.form-select {
  border-color: var(--line);
  border-radius: 8px;
  color: var(--ink-1);
}

.form-control:focus,
.form-select:focus,
.btn:focus-visible,
.kpi:focus-visible {
  border-color: var(--cyan);
  box-shadow: var(--focus);
  outline: 0;
}

.form-check-input {
  border-color: #b9c4d0;
  cursor: pointer;
}

.form-check-input:checked,
.form-check-input:indeterminate {
  background-color: var(--primary);
  border-color: var(--primary);
}

/* ---------- 상단 바 ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 28px;
  height: 60px;
  padding: 0 24px;
  background: var(--navy);
  color: #fff;
  box-shadow: 0 2px 8px rgba(32, 84, 145, 0.25);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  color: #fff;
  text-decoration: none;
}

.brand img {
  height: 24px;
  width: auto;
}

.brand-divider {
  width: 1px;
  height: 22px;
  background: rgba(255, 255, 255, 0.3);
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.app-nav {
  display: flex;
  gap: 4px;
  height: 100%;
}

.app-nav a {
  display: flex;
  align-items: center;
  padding: 0 14px;
  color: rgba(255, 255, 255, 0.72);
  font-weight: 700;
  text-decoration: none;
  border-bottom: 3px solid transparent;
  transition: color 160ms var(--ease);
}

.app-nav a:hover {
  color: #fff;
}

.app-nav a.active {
  color: #fff;
  border-bottom-color: var(--cyan-l);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-left: auto;
}

.live {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 11px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.85);
  font-size: 12.5px;
}

.live .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn);
  transition: background-color 200ms var(--ease);
}

.live.on .dot {
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(47, 170, 90, 0.25);
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

/* 이름 = 비밀번호 변경 버튼 (관리자) */
button.user-chip {
  padding: 4px 6px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  cursor: pointer;
  transition: background-color 160ms var(--ease);
}

button.user-chip:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.12);
}

button.user-chip:disabled {
  cursor: default;
}

.pw-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
  color: var(--ink-3);
  font-size: 13px;
  font-weight: 700;
}

.pw-form .login-error {
  margin: 4px 0 0;
}

.user-chip .role {
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(91, 182, 232, 0.2);
  color: #d9eefa;
  font-size: 11.5px;
}

.btn-ghost-light {
  padding: 5px 12px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 8px;
  background: transparent;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  transition: background-color 160ms var(--ease);
}

.btn-ghost-light:hover {
  background: rgba(255, 255, 255, 0.12);
}

/* ---------- 페이지 ---------- */
.page {
  padding: 24px;
  max-width: 1680px;
  margin: 0 auto;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.page-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  color: var(--ink-1);
  font-size: 22px;
  font-weight: 700;
}

.page-title::before {
  content: '';
  width: 5px;
  height: 22px;
  border-radius: 3px;
  background: var(--navy);
}

.page-sub {
  margin: 6px 0 0 15px;
  color: var(--ink-4);
  font-size: 13px;
}

.card-box {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-title {
  margin: 0;
  color: var(--ink-1);
  font-size: 15px;
  font-weight: 700;
}

/* ---------- 요약 타일 ---------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.kpi {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 18px;
  text-align: left;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: inherit;
  cursor: pointer;
  transition: transform 180ms var(--ease), box-shadow 180ms var(--ease), border-color 180ms var(--ease);
}

.kpi:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(32, 84, 145, 0.12);
}

.kpi.active {
  border-color: var(--primary);
  box-shadow: inset 0 0 0 1px var(--primary), var(--shadow);
  background: linear-gradient(180deg, var(--tint-2), #fff 60%);
}

.kpi-label {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink-3);
  font-size: 13px;
  font-weight: 700;
}

.mark {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  background: var(--navy);
}

.mark.ok {
  background: var(--ok);
}
.mark.off {
  background: #a9b3bf;
}
.mark.warn {
  background: var(--warn);
}
.mark.info {
  background: var(--cyan);
}

.kpi-value {
  color: var(--ink-1);
  font-size: 30px;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.kpi-value small {
  margin-left: 3px;
  color: var(--ink-4);
  font-size: 14px;
  font-weight: 400;
}

.kpi-sub {
  color: var(--ink-4);
  font-size: 12px;
}

.meter {
  height: 4px;
  border-radius: 999px;
  background: var(--tint-2);
  overflow: hidden;
}

.meter span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--ok);
  transition: width 320ms var(--ease);
}

/* ---------- 필터 ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px 14px;
  padding: 14px 16px;
  margin-bottom: 12px;
}

.search {
  position: relative;
  flex: 1 1 260px;
  min-width: 220px;
}

.search svg {
  position: absolute;
  left: 11px;
  top: 50%;
  width: 16px;
  height: 16px;
  transform: translateY(-50%);
  color: var(--ink-4);
  pointer-events: none;
}

.search input {
  padding-left: 34px;
  height: 36px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  color: var(--ink-4);
  font-size: 12px;
  font-weight: 700;
}

.field .form-select {
  min-width: 130px;
  height: 36px;
  font-size: 13.5px;
  font-weight: 400;
}

.toolbar .btn-link-sm {
  margin-left: auto;
  align-self: center;
}

/* 필터 접기 버튼 — 휴대폰에서만 보임 */
.filter-toggle {
  display: none;
}

.filter-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  margin-left: 6px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 11.5px;
}

/* ---------- 일괄 처리 바 ---------- */
.bulk-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 10px 16px;
  margin-bottom: 12px;
  border: 1px solid var(--tint-1);
  border-radius: var(--radius);
  background: var(--tint-2);
  animation: fade-in 200ms var(--ease);
}

.bulk-bar .count {
  color: var(--ink-1);
  font-weight: 700;
}

.bulk-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ---------- 장비 표 ---------- */
.table-card {
  overflow: hidden;
}

.table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.table-head .muted {
  margin-left: 8px;
  font-size: 13px;
}

.table-scroll {
  max-height: calc(100vh - 380px);
  min-height: 240px;
  overflow: auto;
}

.dtable {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13.5px;
}

.dtable th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 10px 14px;
  background: var(--tint-3);
  border-bottom: 1px solid var(--line);
  color: var(--ink-3);
  font-size: 12.5px;
  font-weight: 700;
  text-align: left;
  white-space: nowrap;
}

.dtable td {
  padding: 10px 14px;
  border-bottom: 1px solid #edf1f5;
  vertical-align: middle;
  white-space: nowrap;
}

.dtable tbody tr {
  transition: background-color 120ms var(--ease);
}

.dtable tbody tr:hover {
  background: var(--tint-3);
}

.dtable tbody tr.is-selected {
  background: var(--tint-2);
}

/* 측정 기록 정정: 제외한 기록은 흐리게 + 무게에 줄, 정정 메모는 무게 아래 작은 글씨 */
.dtable tr.meas-excluded td {
  color: var(--ink-4);
}

.dtable tr.meas-excluded .meas-w {
  text-decoration: line-through;
}

.meas-w ~ .pill {
  margin-left: 6px;
}

.meas-note {
  max-width: 320px;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink-4);
  font-size: 12px;
}

.dtable tbody tr.is-offline td:not(.keep) {
  color: var(--ink-4);
}

.dtable .col-check {
  width: 44px;
  padding-right: 0;
}

.dtable .sub {
  margin-top: 2px;
  color: var(--ink-4);
  font-size: 12px;
}

.dtable td.memo .sub {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.device-id {
  font-family: var(--bs-font-monospace);
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  text-decoration: none;
}

.device-id:hover {
  color: var(--deep);
  text-decoration: underline;
}

.empty {
  padding: 56px 20px !important;
  text-align: center;
  white-space: normal !important;
}

.empty strong {
  display: block;
  margin-bottom: 6px;
  color: var(--ink-2);
  font-size: 15px;
}

.empty span {
  color: var(--ink-4);
}

.table-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  border-top: 1px solid var(--line);
  color: var(--ink-4);
  font-size: 13px;
}

.pager {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pager .page-num {
  min-width: 64px;
  text-align: center;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}

.table-foot .form-select {
  display: inline-block;
  width: auto;
  height: 30px;
  padding-top: 2px;
  padding-bottom: 2px;
  margin-left: 6px;
  font-size: 13px;
}

/* ---------- 상태 알약 (색은 점이 담당, 글자는 본문색) ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  background: var(--muted-bg);
  color: var(--ink-2);
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.4;
  white-space: nowrap;
}

.pill::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #a9b3bf;
}

.pill.ok {
  background: rgba(47, 170, 90, 0.12);
}
.pill.ok::before {
  background: var(--ok);
}
.pill.warn {
  background: rgba(232, 163, 61, 0.16);
}
.pill.warn::before {
  background: var(--warn);
}
.pill.danger {
  background: rgba(214, 69, 69, 0.12);
}
.pill.danger::before {
  background: var(--danger);
}
.pill.info {
  background: var(--tint-2);
}
.pill.info::before {
  background: var(--primary);
}
.pill.plain {
  background: #fff;
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--ink-3);
}

/* ---------- 확인 창 · 알림 ---------- */
.dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  color: var(--ink-2);
}

.dialog::backdrop {
  background: rgba(29, 39, 51, 0.45);
}

.dialog[open] {
  animation: fade-in 180ms var(--ease);
}

.dialog-body {
  padding: 24px 24px 8px;
}

.dialog-title {
  margin: 0 0 10px;
  color: var(--ink-1);
  font-size: 18px;
  font-weight: 700;
}

.dialog-text {
  margin: 0;
  color: var(--ink-3);
  line-height: 1.6;
  white-space: pre-line;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 18px 24px 22px;
}

.toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast-msg {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 240px;
  max-width: 380px;
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--ink-1);
  color: #fff;
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  animation: fade-in 200ms var(--ease);
  transition: opacity 240ms var(--ease);
}

.toast-msg::before {
  content: '';
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
}

.toast-msg.error::before {
  background: var(--danger);
}

.toast-msg.hide {
  opacity: 0;
}

/* ---------- 장비 상세 ---------- */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--ink-3);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.back-link:hover {
  color: var(--primary);
}

.detail-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  padding: 20px 22px;
  margin-bottom: 16px;
}

.detail-head h1 {
  margin: 0;
  color: var(--ink-1);
  font-family: var(--bs-font-monospace);
  font-size: 22px;
  font-weight: 700;
}

.detail-head .meta {
  flex-basis: 100%;
  color: var(--ink-4);
  font-size: 13px;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(300px, 1fr);
  gap: 16px;
  align-items: start;
}

.section {
  padding: 18px 22px;
}

.section + .section {
  margin-top: 16px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.facts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 28px;
  margin: 0;
}

.facts div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid #edf1f5;
}

.facts dt {
  flex: none;
  color: var(--ink-4);
  font-weight: 400;
  white-space: nowrap;
}

.facts dd {
  margin: 0;
  color: var(--ink-1);
  text-align: right;
  word-break: break-all;
}

.action-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.action-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid #edf1f5;
}

.action-item:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.action-item strong {
  display: block;
  color: var(--ink-1);
  font-size: 13.5px;
}

.action-item span {
  color: var(--ink-4);
  font-size: 12px;
  line-height: 1.5;
}

.action-item .btn {
  flex: none;
  min-width: 92px;
}

.timeline {
  position: relative;
  margin: 0;
  padding: 0;
  list-style: none;
}

.timeline li {
  position: relative;
  display: grid;
  grid-template-columns: 150px 120px minmax(0, 1fr);
  gap: 12px;
  padding: 10px 0 10px 22px;
  border-bottom: 1px solid #edf1f5;
}

.timeline li::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 16px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #a9b3bf;
  box-shadow: 0 0 0 3px #fff;
}

.timeline li.ok::before {
  background: var(--ok);
}
.timeline li.info::before {
  background: var(--primary);
}
.timeline li.cyan::before {
  background: var(--cyan);
}
.timeline li.warn::before {
  background: var(--warn);
}
.timeline li.danger::before {
  background: var(--danger);
}

.timeline .t-time {
  color: var(--ink-4);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}

.timeline .t-type {
  color: var(--ink-1);
  font-weight: 700;
}

.timeline .t-detail {
  color: var(--ink-3);
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 이력 더 보기·접기 — 접을 때 칸 머리로 스크롤하므로 고정 상단 바(휴대폰은 두 줄) 만큼 띄운다 */
.events-more {
  width: 100%;
  margin-top: 6px;
  text-align: center;
}

.sec-events {
  scroll-margin-top: 120px;
}

.alert-box {
  padding: 12px 16px;
  margin-bottom: 16px;
  border-radius: 10px;
  background: rgba(214, 69, 69, 0.08);
  color: var(--ink-1);
  box-shadow: inset 3px 0 0 var(--danger);
}

/* ---------- 로그인 ---------- */
.login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 440px);
  align-items: center;
  gap: 48px;
  padding: 48px max(48px, 7vw);
  background: var(--navy) url('/img/login-bg.jpg') center / cover no-repeat;
}

.login-brand {
  color: #fff;
}

.login-brand img {
  height: 40px;
  width: auto;
  margin-bottom: 36px;
}

.login-eyebrow {
  margin: 0 0 14px;
  color: var(--cyan-l);
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.22em;
}

.login-brand h1 {
  margin: 0 0 16px;
  font-size: 40px;
  font-weight: 300;
  line-height: 1.25;
}

.login-brand h1 b {
  font-weight: 700;
}

.login-brand p {
  max-width: 440px;
  margin: 0;
  color: rgba(255, 255, 255, 0.8);
  font-size: 16px;
  line-height: 1.6;
}

.login-card {
  padding: 36px 34px 32px;
  border-radius: 16px;
  background: #fff;
  box-shadow: var(--shadow-lg);
}

.login-card .logo {
  height: 30px;
  width: auto;
  margin-bottom: 22px;
}

.login-card h2 {
  margin: 0 0 4px;
  color: var(--ink-1);
  font-size: 20px;
  font-weight: 700;
}

.login-card .lead-text {
  margin: 0 0 24px;
  color: var(--ink-4);
  font-size: 13px;
}

.login-card .form-label {
  color: var(--ink-3);
  font-size: 13px;
  font-weight: 700;
}

.login-card .form-control {
  height: 44px;
}

.login-card .btn {
  height: 46px;
  margin-top: 6px;
  font-size: 15px;
}

.login-error {
  padding: 10px 12px;
  margin-bottom: 12px;
  border-radius: 8px;
  background: rgba(214, 69, 69, 0.08);
  color: var(--ink-1);
  font-size: 13px;
  box-shadow: inset 3px 0 0 var(--danger);
}

.login-foot {
  position: fixed;
  left: max(48px, 7vw);
  bottom: 24px;
  color: rgba(255, 255, 255, 0.6);
  font-size: 12.5px;
}

/* ---------- 반응형 ---------- */
@media (max-width: 1200px) {
  .detail-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  /* 한 줄 배치: 두 열을 풀고, 길어지는 이력(최대 100건)은 업데이트·메모·관리 뒤로 */
  .detail-grid > div {
    display: contents;
  }
  .detail-grid .section + .section {
    margin-top: 0;
  }
  .sec-info {
    order: 1;
  }
  .sec-uptime {
    order: 2;
  }
  .sec-meas {
    order: 3;
  }
  .sec-update {
    order: 4;
  }
  .sec-memo {
    order: 5;
  }
  .sec-manage {
    order: 6;
  }
  .sec-events {
    order: 7;
  }
}

@media (max-width: 860px) {
  /* 상단 바 2줄: 로고·연결 표시·로그아웃 / 메뉴 탭 (메뉴를 숨기지 않는다) */
  .app-header {
    flex-wrap: wrap;
    height: auto;
    gap: 0 12px;
    padding: 0 14px;
  }
  .brand {
    height: 52px;
  }
  .app-nav {
    order: 3;
    flex: 0 0 calc(100% + 28px);
    height: 44px;
    margin: 0 -14px;
    border-top: 1px solid rgba(255, 255, 255, 0.14);
  }
  .app-nav a {
    flex: 1;
    justify-content: center;
    padding: 0 8px;
  }
  .header-right {
    gap: 10px;
    min-width: 0;
  }
  .live {
    padding: 6px;
  }
  .live .live-text,
  .user-chip .role,
  .brand-divider,
  .brand-title {
    display: none;
  }
  .user-chip {
    display: block;
    max-width: 30vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .page {
    padding: 16px;
  }
  .facts {
    grid-template-columns: minmax(0, 1fr);
  }
  .timeline li {
    grid-template-columns: minmax(0, 1fr);
    gap: 2px;
  }
  .login-page {
    grid-template-columns: minmax(0, 1fr);
    padding: 32px 16px;
    gap: 24px;
  }
  .login-brand h1 {
    font-size: 28px;
  }
  .login-brand img {
    margin-bottom: 20px;
  }
  .login-foot {
    position: static;
    text-align: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before {
    animation: none !important;
    transition: none !important;
  }
}

/* ---------- 메뉴 경고 점 (서버 상태에 주의 항목) ---------- */
.app-nav a.has-warning::after {
  content: '';
  width: 7px;
  height: 7px;
  margin-left: 6px;
  border-radius: 50%;
  background: var(--danger);
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.25);
}

/* ---------- 그래프 ---------- */
.chart-box {
  position: relative;
  height: 240px;
  margin-top: 8px;
}

.chart-note {
  margin: 6px 0 0;
  color: var(--ink-4);
  font-size: 12px;
}

/* ---------- 가동률 숫자 ---------- */
.stat-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 32px;
}

.stat-row .stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-row .stat-label {
  color: var(--ink-4);
  font-size: 12.5px;
  font-weight: 700;
}

.stat-row .stat-value {
  color: var(--ink-1);
  font-size: 24px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ---------- 기간 선택 ---------- */
.range-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  margin-bottom: 6px;
}

.range-bar .btn-group .btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.range-bar input[type='date'] {
  width: 150px;
  height: 31px;
  font-size: 13px;
}

/* ---------- 운전 기록 표 (공기 재순환) — 열이 많아 가로로 넘기고, 머리글 두 줄과 시각 칸은 고정 ---------- */
.air-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
}

.air-table thead th {
  position: static;
  padding: 7px 12px;
  text-align: center;
}

.air-table th .unit {
  display: block;
  margin-top: 1px;
  color: var(--ink-4);
  font-size: 11.5px;
  font-weight: 500;
}

.air-table td {
  padding: 7px 12px;
}

.air-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.air-table .gs {
  border-left: 1px solid var(--line);
}

.air-table .col-time {
  position: sticky;
  left: 0;
  z-index: 1;
  background: #fff;
}

.air-table thead .col-time {
  z-index: 3;
  background: var(--tint-3);
}

.air-table tbody tr:hover .col-time {
  background: var(--tint-3);
}

.section-head .head-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ---------- 원격 진단 (규격 없는 JSON 을 항목별로) ---------- */
.diag-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  margin-top: 10px;
  overflow: hidden;
}

.diag-item > summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 10px 14px;
  background: var(--tint-3);
  cursor: pointer;
  list-style: none;
}

.diag-item > summary::-webkit-details-marker {
  display: none;
}

.diag-item > summary::before {
  content: '▸';
  color: var(--ink-4);
  transition: transform 160ms var(--ease);
}

.diag-item[open] > summary::before {
  transform: rotate(90deg);
}

.diag-item .diag-body {
  padding: 12px 14px;
}

.jtree {
  display: grid;
  grid-template-columns: minmax(110px, max-content) minmax(0, 1fr);
  gap: 4px 16px;
  margin: 0;
  font-size: 13px;
}

.jtree > dt {
  color: var(--ink-4);
  font-weight: 400;
  white-space: nowrap;
}

.jtree > dd {
  margin: 0;
  min-width: 0;
  word-break: break-word;
}

.jtree .jtree {
  padding: 6px 0 6px 12px;
  border-left: 2px solid var(--tint-1);
}

.jv-num {
  color: var(--deep);
  font-variant-numeric: tabular-nums;
}

.jv-bool,
.jv-null {
  color: var(--ink-4);
}

.jv-str {
  color: var(--ink-1);
}

.jv-err {
  color: var(--danger);
}

.jlog {
  max-height: 260px;
  margin: 0;
  padding: 10px 12px;
  overflow: auto;
  border-radius: 8px;
  background: #1d2733;
  color: #e6edf5;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

/* 서버 로그 */
.log-tools .form-select {
  width: auto;
}

.log-tools .form-check-label {
  display: inline-flex;
  align-items: center;
  color: var(--ink-3);
  white-space: nowrap;
  cursor: pointer;
}

.logview {
  max-height: 60vh;
  min-height: 160px;
  word-break: break-all;
}

.logview .log-error {
  color: #ff9d9d;
}

.logview .log-warn {
  color: #f6cd7d;
}

.logview .log-empty {
  color: #9fb0c2;
}

.diag-raw summary {
  margin-top: 10px;
  color: var(--primary);
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}

/* ---------- 서버 상태 ---------- */
.sys-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr));
  gap: 16px;
}

.sys-grid .facts {
  grid-template-columns: minmax(0, 1fr);
}

.ok-box {
  padding: 12px 16px;
  margin-bottom: 16px;
  border-radius: 10px;
  background: rgba(47, 170, 90, 0.08);
  color: var(--ink-1);
  box-shadow: inset 3px 0 0 var(--ok);
}

.alert-box ul {
  margin: 4px 0 0;
  padding-left: 18px;
}

.disk-meter {
  height: 6px;
  margin-top: 4px;
  border-radius: 999px;
  background: var(--tint-2);
  overflow: hidden;
}

.disk-meter span {
  display: block;
  height: 100%;
  background: var(--primary);
}

/* 원격 업데이트 진행 */
.up-active {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--tint-3);
  box-shadow: inset 3px 0 0 var(--cyan);
}

.up-active-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.up-active-head .btn-link-sm {
  margin-left: auto;
}

.up-meter {
  height: 6px;
  margin-bottom: 6px;
  border-radius: 999px;
  background: var(--tint-1);
  overflow: hidden;
}

.up-meter span {
  display: block;
  height: 100%;
  background: var(--primary);
  transition: width 0.4s var(--ease);
}

.up-meter span.indeterminate {
  width: 35%;
  animation: up-slide 1.4s var(--ease) infinite;
}

@keyframes up-slide {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(300%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .up-meter span.indeterminate {
    animation: none;
    width: 100%;
    opacity: 0.4;
  }
}

/* ---------- 휴대폰 (640px 이하) ---------- */
@media (max-width: 640px) {
  /* iOS 는 16px 미만 입력란을 누르면 화면을 확대한다 */
  .form-control,
  .form-select {
    font-size: 16px;
  }
  .btn-link-sm {
    padding: 8px 4px;
  }

  .page-head {
    flex-wrap: wrap;
    align-items: flex-start;
  }
  .page-title {
    font-size: 19px;
  }

  /* 요약 타일: 3칸 작게 */
  .kpis {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }
  .kpi {
    gap: 4px;
    padding: 10px 12px;
  }
  .kpi:hover {
    transform: none;
  }
  .kpi-label {
    gap: 6px;
    font-size: 12px;
  }
  .kpi-value {
    font-size: 22px;
  }
  .kpi-sub {
    display: none;
  }

  /* 필터: 검색 + [필터] 버튼 한 줄, 누르면 선택 상자가 두 개씩 펼쳐짐 */
  .toolbar {
    gap: 10px;
    padding: 12px;
  }
  .search {
    /* 검색 + [필터] 버튼이 항상 한 줄을 차지 → 펼친 선택 상자는 다음 줄부터 */
    flex: 1 1 calc(100% - 110px);
    min-width: 0;
  }
  .search input {
    height: 40px;
  }
  .filter-toggle {
    display: inline-flex;
    align-items: center;
    flex: none;
    height: 40px;
  }
  .toolbar:not(.filters-open) .field,
  .toolbar:not(.filters-open) #f-reset {
    display: none;
  }
  .field {
    flex: 1 1 calc(50% - 5px);
    min-width: 0;
  }
  .field .form-select {
    min-width: 0;
    width: 100%;
  }

  .table-head,
  .table-foot {
    flex-wrap: wrap;
    padding: 12px 14px;
  }
  .table-foot {
    justify-content: center;
  }
  .table-scroll {
    max-height: 70vh;
    min-height: 0;
  }

  /* 장비 목록 카드: 표 대신 장비마다 카드 한 장. 칸 이름은 td 의 data-label (app.js) */
  .table-card .table-scroll {
    max-height: none;
    min-height: 0;
    overflow: visible;
  }
  .device-table thead {
    display: none;
  }
  .device-table,
  .device-table tbody {
    display: block;
  }
  .device-table tbody tr {
    position: relative;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px 10px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
  }
  .device-table td {
    display: block;
    min-width: 0;
    padding: 0;
    border: 0;
    white-space: normal;
  }
  .device-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    color: var(--ink-4);
    font-size: 11.5px;
    font-weight: 700;
  }
  .device-table td.col-check {
    position: absolute;
    top: 12px;
    right: 14px;
    width: auto;
  }
  .device-table td.col-check .form-check-input {
    width: 1.3em;
    height: 1.3em;
  }
  .device-table td.memo {
    grid-column: 1 / -1;
    padding-right: 36px;
  }
  .device-table td.memo .sub {
    max-width: none;
  }
  .device-table .device-id {
    font-size: 14px;
    word-break: break-all;
  }
  .device-table .pill {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .device-table td.c-pill {
    order: 1;
  }
  .device-table td.c-type,
  .device-table td.c-ver,
  .device-table td.c-uptime {
    order: 2;
  }
  .device-table td.c-seen {
    order: 3;
    grid-column: 1 / -1;
  }
  .device-table td.c-seen::before {
    display: inline;
    margin-right: 8px;
  }
  .device-table td.c-net {
    display: none;
  }
  .device-table td.empty {
    grid-column: 1 / -1;
    padding: 40px 12px !important;
  }

  .bulk-bar {
    position: sticky;
    top: 104px; /* 2줄 상단 바(52 + 44px) 아래 */
    z-index: 5;
    box-shadow: var(--shadow);
  }

  /* 장비 상세 */
  .detail-head {
    padding: 16px;
  }
  .detail-head h1 {
    font-size: 18px;
    word-break: break-all;
  }
  .section {
    padding: 14px;
  }
  .section-head {
    flex-wrap: wrap;
    gap: 8px;
  }
  .section-head .head-actions {
    flex-wrap: wrap;
  }
  .range-bar input[type='date'] {
    flex: 1 1 120px;
    width: auto;
    height: auto;
  }
  .timeline .t-detail {
    white-space: normal;
    word-break: break-word;
  }
  .stat-row {
    gap: 10px 24px;
  }
  .stat-row .stat-value {
    font-size: 20px;
  }
  .chart-box {
    height: 200px;
  }
  .jtree {
    grid-template-columns: minmax(0, 38%) minmax(0, 1fr);
    gap: 4px 10px;
  }
  .jtree > dt {
    white-space: normal;
    word-break: break-word;
  }
  .action-item .btn {
    min-width: 76px;
  }

  .toasts {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }
  .toast-msg {
    min-width: 0;
    max-width: none;
  }
}

/* ---------- 홈 화면 앱(PWA) ---------- */
/* iOS 홈 화면 앱은 상태 표시줄까지 화면을 쓴다(black-translucent) → 상단 바를 그 아래로 */
.app-header {
  padding-top: env(safe-area-inset-top);
}

@media (min-width: 861px) {
  .app-header {
    height: calc(60px + env(safe-area-inset-top));
  }
}

@media (max-width: 860px) {
  .app-header {
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }
  .page {
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
  .login-page {
    padding-top: max(32px, calc(env(safe-area-inset-top) + 16px));
  }
}

@media (max-width: 640px) {
  .bulk-bar {
    top: calc(104px + env(safe-area-inset-top));
  }
  .toasts {
    bottom: calc(12px + env(safe-area-inset-bottom));
  }
}

/* 연결 안 됨 화면 (offline.html) */
.offline-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 16px 24px;
  background: var(--navy);
}

.offline-card {
  width: min(420px, 100%);
  padding: 32px 28px;
  text-align: center;
}

.offline-card img {
  margin-bottom: 18px;
  border-radius: 16px;
}

.offline-card h1 {
  margin: 0 0 10px;
  color: var(--ink-1);
  font-size: 19px;
  font-weight: 700;
}

.offline-card p {
  margin: 0 0 22px;
  color: var(--ink-3);
  line-height: 1.6;
}

/* ---------- 외부 연동 API 키 (서버 상태, 관리자만) ---------- */
.keys-scroll {
  max-height: none;
  min-height: 0;
}

/* 발급·사용 기록(둘째 줄)은 좁으면 줄바꿈 — 키·버튼만 한 줄 유지 */
.keys-table td {
  white-space: normal;
}

.keys-table td:nth-child(2),
.keys-table td:last-child {
  white-space: nowrap;
}

.dialog-wide {
  width: min(560px, calc(100vw - 32px));
}

.pick-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.pick-tools .form-control {
  flex: 1 1 auto;
  min-width: 0;
}

.pick-tools .btn-link-sm {
  flex: none;
}

.pick-list {
  max-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.pick-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid #edf1f5;
  cursor: pointer;
}

.pick-item:last-child {
  border-bottom: 0;
}

.pick-item:hover {
  background: var(--tint-3);
}

.pick-item .form-check-input {
  flex: none;
  margin-top: 3px;
}

.pick-id {
  display: block;
  color: var(--ink-1);
  font-family: var(--bs-font-monospace);
  font-size: 13px;
  font-weight: 700;
  word-break: break-all;
}

.pick-sub {
  display: block;
  color: var(--ink-4);
  font-size: 12px;
}

.key-field {
  font-family: var(--bs-font-monospace);
  font-size: 13px;
}

@media (max-width: 640px) {
  /* 휴대폰: 키마다 카드 한 장 (칸 이름은 td 의 data-label) */
  .keys-scroll {
    overflow: visible;
  }
  .keys-table thead {
    display: none;
  }
  .keys-table,
  .keys-table tbody {
    display: block;
  }
  .keys-table tbody tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
  }
  .keys-table td {
    display: block;
    min-width: 0;
    padding: 0;
    border: 0;
  }
  .keys-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    color: var(--ink-4);
    font-size: 11.5px;
    font-weight: 700;
  }
  .keys-table td:last-child {
    grid-column: 1 / -1;
  }
  .keys-table td:empty {
    display: none;
  }
  .pick-tools {
    flex-wrap: wrap;
  }
  .pick-list {
    max-height: 45vh;
  }
}

/* 장비 상세: 현재 설정 카드 */
.cfg-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.cfg-grid > :nth-child(-n + 2) {
  grid-column: 1 / -1;
}
.cfg-title {
  font-size: 0.85rem;
  font-weight: 600;
  margin: 0 0 6px;
}
.cfg-rev {
  width: auto;
  max-width: 240px;
}
@media (max-width: 860px) {
  .cfg-grid {
    grid-template-columns: minmax(0, 1fr);
  }
  .cfg-rev {
    max-width: 100%;
  }
}

/* 장비 상세: 메타닉스 방문 기록 · 교정 이력 · 경보 이력 */
.rec-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: start;
}
.rec-grid > .section + .section {
  margin-top: 0;
}
.rec-grid > .rec-wide {
  grid-column: 1 / -1;
}
.rec-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.rec-thumbs {
  display: flex;
  align-items: center;
  gap: 4px;
}
.rec-thumbs a {
  display: block;
  line-height: 0;
}
.rec-thumbs img {
  width: 48px;
  height: 36px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--tint-3);
}
.rec-thumbs .more {
  color: var(--ink-4);
  font-size: 12px;
}
/* 장비 상태 · 원시값 카드의 한 줄 요약: 좁은 화면에서는 줄을 바꿔 가로로 넘치지 않게 */
.rec-facts {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 16px;
  margin-bottom: 8px;
  font-size: 13.5px;
}
.rec-facts:empty {
  display: none;
}
.rec-facts .fact {
  min-width: 0;
  overflow-wrap: anywhere;
}
.rec-facts .fact > .muted {
  margin-right: 6px;
}
.rec-facts .pill {
  white-space: normal;
}
/* 두 칸 배치(detail-grid)와 같은 폭에서 한 칸으로 */
@media (max-width: 1200px) {
  .rec-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}
